lib/hqmf-parser/1.0/document.rb in hqmf-parser-1.0.6 vs lib/hqmf-parser/1.0/document.rb in hqmf-parser-1.1.0

- old
+ new

@@ -7,23 +7,29 @@ attr_reader :hqmf_id, :hqmf_set_id, :hqmf_version_number # Create a new HQMF1::Document instance by parsing the supplied contents # @param [String] hqmf_contents the contents of an HQMF v1.0 document 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) + 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 @@ -151,11 +157,11 @@ 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}_#{@@ids.next}" => criteria_json.values.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] = {} @@ -190,20 +196,8 @@ private def find(collection, attribute, value) collection.find {|e| e.send(attribute)==value} end - - # Simple class to issue monotonically increasing integer identifiers - class Counter - def initialize - @count = 0 - end - - def next - @count+=1 - end - end - @@ids = Counter.new end end \ No newline at end of file