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, #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 52 53 54 55 56 57 58 59 60 |
# 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 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 |attr| PopulationCriteria.new(attr, self) end observations = @doc.xpath('//cda:section[cda:code/@code="57027-5"]/cda:entry').collect do |attr| Observation.new(attr, self) end @population_criteria.concat(observations) @stratification = @doc.xpath('//cda:section[cda:code/@code="69669-0"]/cda:entry').collect do |attr| PopulationCriteria.new(attr, self) end if (@stratification and !@stratification.empty?) initial_populations = @population_criteria.select {|pc| pc.code.starts_with? 'IPP'} initial_populations.each do |population| @stratification.each do |stratification| new_population = HQMF1::PopulationCriteria.new(population.entry, population.doc) new_population.hqmf_id = new_population.id new_population.stratification_id = stratification.id new_population.id = "#{new_population.id}_#{stratification.id}" ids = stratification.preconditions.map(&:id) new_population.preconditions.delete_if {|precondition| ids.include? precondition.id} new_population.preconditions.concat(stratification.preconditions) new_population.preconditions.rotate!(-1*stratification.preconditions.size) @population_criteria << new_population end 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
133 134 135 136 137 |
# File 'lib/hqmf-parser/1.0/document.rb', line 133 def self.parse(hqmf_contents) doc = 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
76 77 78 |
# File 'lib/hqmf-parser/1.0/document.rb', line 76 def all_attributes @attributes end |
#all_data_criteria ⇒ Array
Get all the data criteria defined by the measure
120 121 122 |
# File 'lib/hqmf-parser/1.0/document.rb', line 120 def all_data_criteria @data_criteria end |
#all_population_criteria ⇒ Array
Get all the population criteria defined by the measure
96 97 98 |
# File 'lib/hqmf-parser/1.0/document.rb', line 96 def all_population_criteria @population_criteria end |
#attribute(id) ⇒ HQMF1::Attribute
Get a specific attribute by id.
83 84 85 |
# File 'lib/hqmf-parser/1.0/document.rb', line 83 def attribute(id) find(@attributes, :id, id) end |
#attribute_for_code(code) ⇒ HQMF1::Attribute
Get a specific attribute by code.
90 91 92 |
# File 'lib/hqmf-parser/1.0/document.rb', line 90 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
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/hqmf-parser/1.0/document.rb', line 141 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.
127 128 129 |
# File 'lib/hqmf-parser/1.0/document.rb', line 127 def data_criteria(id) val = find(@data_criteria, :id, id) || raise("unknown data criteria #{id}") end |
#description ⇒ String
Get the description of the measure
70 71 72 |
# File 'lib/hqmf-parser/1.0/document.rb', line 70 def description @doc.at_xpath('cda:QualityMeasureDocument/cda:text').inner_text end |
#population_criteria(id) ⇒ HQMF1::PopulationCriteria
Get a specific population criteria by id.
107 108 109 |
# File 'lib/hqmf-parser/1.0/document.rb', line 107 def population_criteria(id) find(@population_criteria, :id, id) end |
#population_criteria_for_code(code) ⇒ HQMF1::PopulationCriteria
Get a specific population criteria by code.
114 115 116 |
# File 'lib/hqmf-parser/1.0/document.rb', line 114 def population_criteria_for_code(code) find(@population_criteria, :code, code) end |
#stratification ⇒ Object
100 101 102 |
# File 'lib/hqmf-parser/1.0/document.rb', line 100 def stratification @stratification end |
#title ⇒ String
Get the title of the measure
64 65 66 |
# File 'lib/hqmf-parser/1.0/document.rb', line 64 def title @doc.at_xpath('cda:QualityMeasureDocument/cda:title').inner_text end |
#to_json ⇒ Object
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 187 188 189 190 191 192 193 194 |
# File 'lib/hqmf-parser/1.0/document.rb', line 154 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 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 |