lib/hqmf-parser/1.0/data_criteria.rb in hqmf-parser-1.0.6 vs lib/hqmf-parser/1.0/data_criteria.rb in hqmf-parser-1.1.0
- old
+ new
@@ -2,15 +2,15 @@
# Represents a data criteria specification
class DataCriteria
include HQMF1::Utilities
- attr_accessor :code_list_id, :derived_from, :definition, :status, :negation, :specific_occurrence, :specific_occurrence_const
+ attr_accessor :code_list_id, :derived_from, :definition, :status, :negation, :specific_occurrence
# Create a new instance based on the supplied HQMF entry
# @param [Nokogiri::XML::Element] entry the parsed HQMF entry
- def initialize(entry)
+ def initialize(entry, occurrence_counters)
@entry = entry
template_map = HQMF::DataCriteria.get_template_id_map()
oid_xpath_file = File.expand_path('../data_criteria_oid_xpath.json', __FILE__)
oid_xpath_map = JSON.parse(File.read(oid_xpath_file))
@@ -19,12 +19,12 @@
# 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
- @@occurrences[@derived_from] ||= Counter.new
- @occurrence_key = @@occurrences[@derived_from].next
+ 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
@@ -72,34 +72,21 @@
# Get a JS friendly constant name for this measure attribute
def const_name
components = title.gsub(/\W/,' ').split.collect {|word| word.strip.upcase }
if @derived_from
- components << @@id.next
- @specific_occurrence_const = (description.gsub(/\W/,' ').split.collect {|word| word.strip.upcase }).join '_'
+ components << HQMF::Counter.instance.next
end
components.join '_'
end
def to_json
- json = build_hash(self, [:id,:title,:code_list_id,:derived_from,:description, :definition, :status, :negation, :specific_occurrence,:specific_occurrence_const])
+ json = build_hash(self, [:id,:title,:code_list_id,:derived_from,:description, :definition, :status, :negation, :specific_occurrence])
{
self.const_name => json
}
end
- # Simple class to issue monotonically increasing integer identifiers
- class Counter
- def initialize
- @count = -1
- end
-
- def next
- @count+=1
- end
- end
- @@id = Counter.new
- @@occurrences = {}
end
end
\ No newline at end of file