Class: SimpleXml::Document
- Inherits:
-
Object
- Object
- SimpleXml::Document
- Includes:
- Utilities
- Defined in:
- lib/model/document.rb
Overview
Class representing an HQMF document
Constant Summary collapse
- MEASURE_PERIOD_TITLES =
{'Measurement Period'=>:measure_period, 'Measurement Start Date'=>:measure_period_start, 'Measurement End Date'=>:measure_period_end}
- UNDEFINED_OID =
'1.1.1.1'
Constants included from Utilities
Utilities::MEASURE_ATTRIBUTES_MAP
Instance Attribute Summary collapse
-
#attribute_map ⇒ Object
readonly
Returns the value of attribute attribute_map.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#cms_id ⇒ Object
readonly
Returns the value of attribute cms_id.
-
#criteria_map ⇒ Object
readonly
Returns the value of attribute criteria_map.
-
#derived_data_criteria ⇒ Object
readonly
Returns the value of attribute derived_data_criteria.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#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.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#measure_period ⇒ Object
readonly
Returns the value of attribute measure_period.
-
#measure_period_map ⇒ Object
readonly
Returns the value of attribute measure_period_map.
-
#nqf_id ⇒ Object
readonly
Returns the value of attribute nqf_id.
-
#populations ⇒ Object
readonly
Returns the value of attribute populations.
-
#source_data_criteria ⇒ Object
readonly
Returns the value of attribute source_data_criteria.
-
#sub_tree_map ⇒ Object
readonly
Returns the value of attribute sub_tree_map.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.parse(xml_contents) ⇒ Nokogiri::XML::Document
Parse an XML document at the supplied path.
Instance Method Summary collapse
-
#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.
-
#data_criteria(id) ⇒ SimpleXml::DataCriteria
Get a specific data criteria by id.
-
#initialize(xml_contents) ⇒ Document
constructor
Create a new SimpleXml::Document instance by parsing at file at the supplied path.
-
#population_criteria(id) ⇒ SimpleXml::PopulationCriteria
Get a specific population criteria by id.
- #register_source_data_criteria(criteria) ⇒ Object
- #rewrite_observ(observ) ⇒ Object
- #to_model ⇒ Object
Methods included from Utilities
#attr_val, attr_val, build_value, #children_of, #comments_on, #create_age_timing, #create_birthdate_criteria
Constructor Details
#initialize(xml_contents) ⇒ Document
Create a new SimpleXml::Document instance by parsing at file at the supplied path
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 |
# File 'lib/model/document.rb', line 13 def initialize(xml_contents) @doc = @entry = Document.parse(xml_contents) details = @doc.at_xpath('measure/measureDetails') @id = details.at_xpath('uuid').text.upcase @hqmf_set_id = details.at_xpath('guid').text.upcase @hqmf_version_number = details.at_xpath('version').text.to_i @title = details.at_xpath('title').text @description = details.at_xpath('description').try(:text) @cms_id = "CMS#{details.at_xpath('emeasureid').try(:text)}v#{@hqmf_version_number}" @nqf_id = details.at_xpath('nqfid/@extension').try(:value) @attributes = [] children_of(details).each do |attribute| attribute_data = Utilities::MEASURE_ATTRIBUTES_MAP[attribute.name.to_sym] if (attribute_data) attribute_data['value'] = attribute.at_xpath('@extension').try(:value) || attribute.text @attributes << HQMF::Attribute.from_json(attribute_data) end end @criteria_map = {} mps = details.at_xpath('period/startDate/@uuid').value rescue nil mpe = details.at_xpath('period/stopDate/@uuid').value rescue nil @measure_period_map = { details.at_xpath('period/@uuid').value => :measure_period, mps => :measure_period_start, mpe => :measure_period_end } @measure_period_map.keys.each do |key| @criteria_map[key] = OpenStruct.new(id: HQMF::Document::MEASURE_PERIOD_ID, hqmf_id: key) end # Extract the data criteria extract_data_criteria # Extract race, ethnicity, etc extract_supplemental_data # extract all the logic and set up populations handle_populations end |
Instance Attribute Details
#attribute_map ⇒ Object (readonly)
Returns the value of attribute attribute_map.
5 6 7 |
# File 'lib/model/document.rb', line 5 def attribute_map @attribute_map end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/model/document.rb', line 5 def attributes @attributes end |
#cms_id ⇒ Object (readonly)
Returns the value of attribute cms_id.
5 6 7 |
# File 'lib/model/document.rb', line 5 def cms_id @cms_id end |
#criteria_map ⇒ Object (readonly)
Returns the value of attribute criteria_map.
5 6 7 |
# File 'lib/model/document.rb', line 5 def criteria_map @criteria_map end |
#derived_data_criteria ⇒ Object (readonly)
Returns the value of attribute derived_data_criteria.
5 6 7 |
# File 'lib/model/document.rb', line 5 def derived_data_criteria @derived_data_criteria end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/model/document.rb', line 5 def description @description end |
#hqmf_set_id ⇒ Object (readonly)
Returns the value of attribute hqmf_set_id.
5 6 7 |
# File 'lib/model/document.rb', line 5 def hqmf_set_id @hqmf_set_id end |
#hqmf_version_number ⇒ Object (readonly)
Returns the value of attribute hqmf_version_number.
5 6 7 |
# File 'lib/model/document.rb', line 5 def hqmf_version_number @hqmf_version_number end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/model/document.rb', line 5 def id @id end |
#measure_period ⇒ Object (readonly)
Returns the value of attribute measure_period.
5 6 7 |
# File 'lib/model/document.rb', line 5 def measure_period @measure_period end |
#measure_period_map ⇒ Object (readonly)
Returns the value of attribute measure_period_map.
5 6 7 |
# File 'lib/model/document.rb', line 5 def measure_period_map @measure_period_map end |
#nqf_id ⇒ Object (readonly)
Returns the value of attribute nqf_id.
5 6 7 |
# File 'lib/model/document.rb', line 5 def nqf_id @nqf_id end |
#populations ⇒ Object (readonly)
Returns the value of attribute populations.
5 6 7 |
# File 'lib/model/document.rb', line 5 def populations @populations end |
#source_data_criteria ⇒ Object (readonly)
Returns the value of attribute source_data_criteria.
5 6 7 |
# File 'lib/model/document.rb', line 5 def source_data_criteria @source_data_criteria end |
#sub_tree_map ⇒ Object (readonly)
Returns the value of attribute sub_tree_map.
5 6 7 |
# File 'lib/model/document.rb', line 5 def sub_tree_map @sub_tree_map end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/model/document.rb', line 5 def title @title end |
Class Method Details
.parse(xml_contents) ⇒ Nokogiri::XML::Document
Parse an XML document at the supplied path
85 86 87 |
# File 'lib/model/document.rb', line 85 def self.parse(xml_contents) xml_contents.kind_of?(Nokogiri::XML::Document) ? xml_contents : Nokogiri::XML(xml_contents) end |
Instance Method Details
#all_data_criteria ⇒ Array
Get all the data criteria defined by the measure
72 73 74 |
# File 'lib/model/document.rb', line 72 def all_data_criteria @derived_data_criteria end |
#all_population_criteria ⇒ Array
Get all the population criteria defined by the measure
59 60 61 |
# File 'lib/model/document.rb', line 59 def all_population_criteria @population_criteria end |
#data_criteria(id) ⇒ SimpleXml::DataCriteria
Get a specific data criteria by id.
79 80 81 |
# File 'lib/model/document.rb', line 79 def data_criteria(id) find(all_data_criteria, :id, id) end |
#population_criteria(id) ⇒ SimpleXml::PopulationCriteria
Get a specific population criteria by id.
66 67 68 |
# File 'lib/model/document.rb', line 66 def population_criteria(id) find(@population_criteria, :id, id) end |
#register_source_data_criteria(criteria) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/model/document.rb', line 127 def register_source_data_criteria(criteria) sdc = criteria.dup sdc.subset_operators = nil if sdc.subset_operators sdc.temporal_references = nil if sdc.temporal_references @source_data_criteria << sdc @criteria_map[criteria.hqmf_id] = criteria end |
#rewrite_observ(observ) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/model/document.rb', line 105 def rewrite_observ(observ) # we want to use the first leaf to calcualculate the value for the observation first_leaf = observ.get_logic_leaves.first unless first_leaf puts "\t NO DATA IN MEASURE OBSERVATION" return observ end # we want to pull the aggregation function off of the top level comparison first_criteria = data_criteria(first_leaf.reference.id) # pop the last subset operator which should be the closest to the root of the logic tree. Add that aggregation function to the observation as the aggregator observ.aggregator = first_criteria.subset_operators.pop.type first_criteria.subset_operators = nil if first_criteria.subset_operators.empty? # # we want to get rid of any AND statements at the top level. This is calculating a numeric value, not evaluating boolean logic observ.preconditions.clear observ.preconditions << first_leaf observ end |
#to_model ⇒ Object
89 90 91 92 93 94 |
# File 'lib/model/document.rb', line 89 def to_model dcs = all_data_criteria.collect {|dc| dc.to_model} pcs = all_population_criteria.collect {|pc| pc.to_model} sdc = source_data_criteria.collect{|dc| dc.to_model} HQMF::Document.new(nqf_id, id, hqmf_set_id, hqmf_version_number, cms_id, title, description, pcs, dcs, sdc, attributes, measure_period, populations) end |