Class: HQMF1::DataCriteria
- Inherits:
-
Object
- Object
- HQMF1::DataCriteria
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/1.0/data_criteria.rb
Overview
Represents a data criteria specification
Instance Attribute Summary collapse
-
#code_list_id ⇒ Object
Returns the value of attribute code_list_id.
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#derived_from ⇒ Object
Returns the value of attribute derived_from.
-
#negation ⇒ Object
Returns the value of attribute negation.
-
#specific_occurrence ⇒ Object
Returns the value of attribute specific_occurrence.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#const_name ⇒ Object
Get a JS friendly constant name for this measure attribute.
- #description ⇒ Object
-
#id ⇒ String
Get the identifier of the criteria, used elsewhere within the document for referencing.
-
#initialize(entry, occurrence_counters) ⇒ DataCriteria
constructor
Create a new instance based on the supplied HQMF entry.
-
#title ⇒ String
Get the title of the criteria, provides a human readable description.
- #to_json ⇒ Object
Methods included from Utilities
#attr_val, #clean_json, #clean_json_recursive
Methods included from HQMF::Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Constructor Details
#initialize(entry, occurrence_counters) ⇒ DataCriteria
Create a new instance based on the supplied HQMF entry
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 11 def initialize(entry, occurrence_counters) @entry = entry template_map = HQMF::DataCriteria.get_template_id_map() oid_xpath_file = File.('../data_criteria_oid_xpath.json', __FILE__) oid_xpath_map = JSON.parse(File.read(oid_xpath_file)) template_id = attr_val('cda:act/cda:templateId/@root') || attr_val('cda:observation/cda:templateId/@root') # check to see if this is a derived data criteria. These are used for multiple occurrences. derived_entry = @entry.at_xpath('./*/cda:sourceOf[@typeCode="DRIV"]') if derived_entry derived = derived_entry.at_xpath('cda:act/cda:id/@root') || derived_entry.at_xpath('cda:observation/cda:id/@root') @derived_from = derived.value occurrence_counters[@derived_from] ||= HQMF::InstanceCounter.new @occurrence_key = occurrence_counters[@derived_from].next-1 @specific_occurrence = "#{('A'..'ZZ').to_a[@occurrence_key]}" end template = template_map[template_id] if template @negation=template["negation"] @definition=template["definition"] @status=template["status"] @key=@definition+(@status.empty? ? '' : "_#{@status}") else raise "Unknown data criteria template identifier [#{template_id}]" end # Get the code list OID of the criteria, used as an index to the code list database @code_list_id = attr_val(oid_xpath_map[@key]['oid_xpath']) unless @code_list_id puts "\tcode list id not found, getting default" if !@derived_from @code_list_id = attr_val('cda:act/cda:sourceOf//cda:code/@code') end puts "\tno oid defined for data criteria: #{@key}" if !@code_list_id and !@derived_from end |
Instance Attribute Details
#code_list_id ⇒ Object
Returns the value of attribute code_list_id.
7 8 9 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7 def code_list_id @code_list_id end |
#definition ⇒ Object
Returns the value of attribute definition.
7 8 9 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7 def definition @definition end |
#derived_from ⇒ Object
Returns the value of attribute derived_from.
7 8 9 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7 def derived_from @derived_from end |
#negation ⇒ Object
Returns the value of attribute negation.
7 8 9 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7 def negation @negation end |
#specific_occurrence ⇒ Object
Returns the value of attribute specific_occurrence.
7 8 9 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7 def specific_occurrence @specific_occurrence end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7 def status @status end |
Instance Method Details
#const_name ⇒ Object
Get a JS friendly constant name for this measure attribute
74 75 76 77 78 79 80 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 74 def const_name components = title.gsub(/\W/,' ').split.collect {|word| word.strip.upcase } if @derived_from components << HQMF::Counter.instance.next end components.join '_' end |
#description ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 64 def description if (@entry.at_xpath('.//cda:title')) description = @entry.at_xpath('.//cda:title').inner_text else description = @entry.at_xpath('.//cda:localVariableName').inner_text end description end |
#id ⇒ String
Get the identifier of the criteria, used elsewhere within the document for referencing
52 53 54 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 52 def id attr_val('cda:act/cda:id/@root') || attr_val('cda:observation/cda:id/@root') end |
#title ⇒ String
Get the title of the criteria, provides a human readable description
58 59 60 61 62 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 58 def title title = description title = "Occurrence #{@specific_occurrence}: #{title}" if @derived_from title end |
#to_json ⇒ Object
82 83 84 85 86 87 |
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 82 def to_json json = build_hash(self, [:id,:title,:code_list_id,:derived_from,:description, :definition, :status, :negation, :specific_occurrence]) { self.const_name => json } end |