Class: HQMF1::Document
- Inherits:
-
Object
- Object
- HQMF1::Document
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/1.0/document.rb
Overview
Class representing an HQMF document
Instance Attribute Summary collapse
-
#hqmf_id ⇒ Object
readonly
Returns the value of attribute hqmf_id.
-
#hqmf_set_id ⇒ Object
readonly
Returns the value of attribute hqmf_set_id.
-
#hqmf_version_number ⇒ Object
readonly
Returns the value of attribute hqmf_version_number.
Class Method Summary collapse
-
.parse(hqmf_contents) ⇒ Nokogiri::XML::Document
Parse an XML document from the supplied contents.
Instance Method Summary collapse
-
#all_attributes ⇒ Array
Get all the attributes defined by the measure.
-
#all_data_criteria ⇒ Array
Get all the data criteria defined by the measure.
-
#all_population_criteria ⇒ Array
Get all the population criteria defined by the measure.
-
#attribute(id) ⇒ HQMF1::Attribute
Get a specific attribute by id.
-
#attribute_for_code(code) ⇒ HQMF1::Attribute
Get a specific attribute by code.
-
#backfill_derived_code_lists ⇒ Object
if the data criteria is derived from another criteria, then we want to grab the properties from the derived criteria this is typically the case with Occurrence A, Occurrence B type data criteria.
-
#data_criteria(id) ⇒ HQMF1::DataCriteria
Get a specific data criteria by id.
-
#description ⇒ String
Get the description of the measure.
-
#initialize(hqmf_contents) ⇒ Document
constructor
Create a new HQMF1::Document instance by parsing the supplied contents.
-
#population_criteria(id) ⇒ HQMF1::PopulationCriteria
Get a specific population criteria by id.
-
#population_criteria_for_code(code) ⇒ HQMF1::PopulationCriteria
Get a specific population criteria by code.
- #stratification ⇒ Object
-
#title ⇒ String
Get the title of the measure.
- #to_json ⇒ Object
Methods included from Utilities
#attr_val, #check_nil_conjunction_on_child, #clean_json, #clean_json_recursive
Methods included from HQMF::Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Constructor Details
#initialize(hqmf_contents) ⇒ Document
Create a new HQMF1::Document instance by parsing the supplied contents
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 49 50 51 |
# File 'lib/hqmf-parser/1.0/document.rb', line 11 def initialize(hqmf_contents) @doc = Document.parse(hqmf_contents) occurrence_counters = {} @data_criteria = @doc.xpath('//cda:section[cda:code/@code="57025-9"]/cda:entry').collect do |entry| DataCriteria.new(entry, occurrence_counters) end @supplemental= @doc.xpath('//cda:section[cda:code/@code="69670-8"]/cda:entry').collect do |entry| DataCriteria.new(entry, occurrence_counters) end @data_criteria.concat @supplemental backfill_derived_code_lists @attributes = @doc.xpath('//cda:subjectOf/cda:measureAttribute').collect do |attr| Attribute.new(attr) end @population_criteria = @doc.xpath('//cda:section[cda:code/@code="57026-7"]/cda:entry').collect do |criteria| PopulationCriteria.new(criteria, self) end observations = @doc.xpath('//cda:section[cda:code/@code="57027-5"]/cda:entry').collect do |observation| Observation.new(observation, self) end @population_criteria.concat(observations) @stratification = @doc.xpath('//cda:section[cda:code/@code="69669-0"]/cda:entry').collect do |strat| PopulationCriteria.new(strat, self) end if (@stratification and !@stratification.empty?) @stratification.each do |stratification| @population_criteria << stratification end end @hqmf_set_id = @doc.at_xpath('//cda:setId/@root').value.upcase @hqmf_id = @doc.at_xpath('//cda:id/@root').value.upcase @hqmf_version_number = @doc.at_xpath('//cda:versionNumber/@value').value.to_i end |
Instance Attribute Details
#hqmf_id ⇒ Object (readonly)
Returns the value of attribute hqmf_id.
7 8 9 |
# File 'lib/hqmf-parser/1.0/document.rb', line 7 def hqmf_id @hqmf_id end |
#hqmf_set_id ⇒ Object (readonly)
Returns the value of attribute hqmf_set_id.
7 8 9 |
# File 'lib/hqmf-parser/1.0/document.rb', line 7 def hqmf_set_id @hqmf_set_id end |
#hqmf_version_number ⇒ Object (readonly)
Returns the value of attribute hqmf_version_number.
7 8 9 |
# File 'lib/hqmf-parser/1.0/document.rb', line 7 def hqmf_version_number @hqmf_version_number end |
Class Method Details
.parse(hqmf_contents) ⇒ Nokogiri::XML::Document
Parse an XML document from the supplied contents
124 125 126 127 128 |
# File 'lib/hqmf-parser/1.0/document.rb', line 124 def self.parse(hqmf_contents) doc = hqmf_contents.kind_of?(Nokogiri::XML::Document) ? hqmf_contents : Nokogiri::XML(hqmf_contents) doc.root.add_namespace_definition('cda', 'urn:hl7-org:v3') doc end |
Instance Method Details
#all_attributes ⇒ Array
Get all the attributes defined by the measure
67 68 69 |
# File 'lib/hqmf-parser/1.0/document.rb', line 67 def all_attributes @attributes end |
#all_data_criteria ⇒ Array
Get all the data criteria defined by the measure
111 112 113 |
# File 'lib/hqmf-parser/1.0/document.rb', line 111 def all_data_criteria @data_criteria end |
#all_population_criteria ⇒ Array
Get all the population criteria defined by the measure
87 88 89 |
# File 'lib/hqmf-parser/1.0/document.rb', line 87 def all_population_criteria @population_criteria end |
#attribute(id) ⇒ HQMF1::Attribute
Get a specific attribute by id.
74 75 76 |
# File 'lib/hqmf-parser/1.0/document.rb', line 74 def attribute(id) find(@attributes, :id, id) end |
#attribute_for_code(code) ⇒ HQMF1::Attribute
Get a specific attribute by code.
81 82 83 |
# File 'lib/hqmf-parser/1.0/document.rb', line 81 def attribute_for_code(code) find(@attributes, :code, code) end |
#backfill_derived_code_lists ⇒ Object
if the data criteria is derived from another criteria, then we want to grab the properties from the derived criteria this is typically the case with Occurrence A, Occurrence B type data criteria
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/hqmf-parser/1.0/document.rb', line 132 def backfill_derived_code_lists data_criteria_by_id = {} @data_criteria.each {|criteria| data_criteria_by_id[criteria.id] = criteria} @data_criteria.each do |criteria| if (criteria.derived_from) derived_from = data_criteria_by_id[criteria.derived_from] criteria.definition = derived_from.definition criteria.status = derived_from.status criteria.code_list_id = derived_from.code_list_id end end end |
#data_criteria(id) ⇒ HQMF1::DataCriteria
Get a specific data criteria by id.
118 119 120 |
# File 'lib/hqmf-parser/1.0/document.rb', line 118 def data_criteria(id) val = find(@data_criteria, :id, id) || raise("unknown data criteria #{id}") end |
#description ⇒ String
Get the description of the measure
61 62 63 |
# File 'lib/hqmf-parser/1.0/document.rb', line 61 def description @doc.at_xpath('cda:QualityMeasureDocument/cda:text').inner_text end |
#population_criteria(id) ⇒ HQMF1::PopulationCriteria
Get a specific population criteria by id.
98 99 100 |
# File 'lib/hqmf-parser/1.0/document.rb', line 98 def population_criteria(id) find(@population_criteria, :id, id) end |
#population_criteria_for_code(code) ⇒ HQMF1::PopulationCriteria
Get a specific population criteria by code.
105 106 107 |
# File 'lib/hqmf-parser/1.0/document.rb', line 105 def population_criteria_for_code(code) find(@population_criteria, :code, code) end |
#stratification ⇒ Object
91 92 93 |
# File 'lib/hqmf-parser/1.0/document.rb', line 91 def stratification @stratification end |
#title ⇒ String
Get the title of the measure
55 56 57 |
# File 'lib/hqmf-parser/1.0/document.rb', line 55 def title @doc.at_xpath('cda:QualityMeasureDocument/cda:title').inner_text end |
#to_json ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/hqmf-parser/1.0/document.rb', line 145 def to_json json = build_hash(self, [:title, :description, :hqmf_id, :hqmf_set_id, :hqmf_version_number]) json[:data_criteria] = {} @data_criteria.each do |criteria| criteria_json = criteria.to_json # check if the key already exists... if it does redefine the key if (json[:data_criteria][criteria_json.keys.first]) criteria_json = {"#{criteria_json.keys.first}_#{HQMF::Counter.instance.next}" => criteria_json.values.first} end json[:data_criteria].merge! criteria_json end # TODO: Investigate why we never use json[:attributes] in the model json[:metadata] = {} json[:attributes] = {} @attributes.each do |attribute| if (attribute.id) json[:attributes].merge! attribute.to_json else json[:metadata].merge! attribute.to_json end end json[:logic] = {} counters = {} @population_criteria.each do |population| population_json = population.to_json key = population_json.keys.first if json[:logic][key] counters[key] ||= 0 counters[key] += 1 population_json["#{key}_#{counters[key]}"] = population_json[key] population_json.delete(key) end json[:logic].merge! population_json end clean_json_recursive(json) json end |