Class: HQMF1::DataCriteria

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/hqmf-parser/1.0/data_criteria.rb

Overview

Represents a data criteria specification

Instance Attribute Summary collapse

Instance Method Summary collapse

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(entry, occurrence_counters) ⇒ DataCriteria

Create a new instance based on the supplied HQMF entry

Parameters:

  • entry (Nokogiri::XML::Element)

    the parsed HQMF entry



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
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 11

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))
  template_id = attr_val('cda:act/cda:templateId/@root') || attr_val('cda:observation/cda:templateId/@root')
  
  # 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
    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
    @negation=template["negation"]
    @definition=template["definition"]
    @status=template["status"]
    @key=@definition+(@status.empty? ? '' : "_#{@status}")
  else
    raise "Unknown data criteria template identifier [#{template_id}]"
  end
  
  # Get the code list OID of the criteria, used as an index to the code list database
  @code_list_id = attr_val(oid_xpath_map[@key]['oid_xpath'])
  unless @code_list_id
    puts "\tcode list id not found, getting default" if !@derived_from
    @code_list_id = attr_val('cda:act/cda:sourceOf//cda:code/@code')
  end
  
  puts "\tno oid defined for data criteria: #{@key}" if !@code_list_id and !@derived_from
  
end

Instance Attribute Details

#code_list_idObject

Returns the value of attribute code_list_id.



7
8
9
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7

def code_list_id
  @code_list_id
end

#definitionObject

Returns the value of attribute definition.



7
8
9
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7

def definition
  @definition
end

#derived_fromObject

Returns the value of attribute derived_from.



7
8
9
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7

def derived_from
  @derived_from
end

#negationObject

Returns the value of attribute negation.



7
8
9
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7

def negation
  @negation
end

#specific_occurrenceObject

Returns the value of attribute specific_occurrence.



7
8
9
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7

def specific_occurrence
  @specific_occurrence
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 7

def status
  @status
end

Instance Method Details

#const_nameObject

Get a JS friendly constant name for this measure attribute



74
75
76
77
78
79
80
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 74

def const_name
  components = title.gsub(/\W/,' ').split.collect {|word| word.strip.upcase }
  if @derived_from
    components << HQMF::Counter.instance.next
  end
  components.join '_'
end

#descriptionObject



64
65
66
67
68
69
70
71
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 64

def description
  if (@entry.at_xpath('.//cda:title'))
    description = @entry.at_xpath('.//cda:title').inner_text
  else
    description = @entry.at_xpath('.//cda:localVariableName').inner_text
  end
  description
end

#idString

Get the identifier of the criteria, used elsewhere within the document for referencing

Returns:

  • (String)

    the identifier of this data criteria



52
53
54
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 52

def id
  attr_val('cda:act/cda:id/@root') || attr_val('cda:observation/cda:id/@root')
end

#titleString

Get the title of the criteria, provides a human readable description

Returns:

  • (String)

    the title of this data criteria



58
59
60
61
62
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 58

def title
  title = description
  title = "Occurrence #{@specific_occurrence}: #{title}" if @derived_from
  title
end

#to_jsonObject



82
83
84
85
86
87
# File 'lib/hqmf-parser/1.0/data_criteria.rb', line 82

def to_json
  json = build_hash(self, [:id,:title,:code_list_id,:derived_from,:description, :definition, :status, :negation, :specific_occurrence])
  {
    self.const_name => json
  }
end