Class: HQMF::DataCriteriaConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/hqmf-parser/converter/pass1/data_criteria_converter.rb

Overview

Class representing an HQMF document

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, measure_period) ⇒ DataCriteriaConverter

Returns a new instance of DataCriteriaConverter.



7
8
9
10
11
12
13
14
15
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 7

def initialize(doc, measure_period)
  @doc = doc
  @v1_data_criteria_by_id = {}
  @v2_data_criteria = []
  @v2_data_criteria_to_delete = {}
  @specific_occurrences = {}
  @measure_period = measure_period
  parse()
end

Instance Attribute Details

#measure_period_criteriaObject (readonly)

Returns the value of attribute measure_period_criteria.



5
6
7
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 5

def measure_period_criteria
  @measure_period_criteria
end

#measure_period_v1_keysObject (readonly)

Returns the value of attribute measure_period_v1_keys.



5
6
7
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 5

def measure_period_v1_keys
  @measure_period_v1_keys
end

#specific_occurrencesObject (readonly)

Returns the value of attribute specific_occurrences.



5
6
7
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 5

def specific_occurrences
  @specific_occurrences
end

#v1_data_criteria_by_idObject (readonly)

Returns the value of attribute v1_data_criteria_by_id.



5
6
7
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 5

def v1_data_criteria_by_id
  @v1_data_criteria_by_id
end

#v2_data_criteriaObject (readonly)

Returns the value of attribute v2_data_criteria.



5
6
7
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 5

def v2_data_criteria
  @v2_data_criteria
end

#v2_data_criteria_to_deleteObject (readonly)

Returns the value of attribute v2_data_criteria_to_delete.



5
6
7
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 5

def v2_data_criteria_to_delete
  @v2_data_criteria_to_delete
end

Class Method Details

.extract_data_criteria(preconditions, data_criteria_converter) ⇒ Object

pull the children data criteria out of a set of preconditions



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 110

def self.extract_data_criteria(preconditions, data_criteria_converter)
  flattened = []
  preconditions.each do |precondition|
    if (precondition.comparison?) 
      if (precondition.reference.id == HQMF::Document::MEASURE_PERIOD_ID)
        flattened << data_criteria_converter.measure_period_criteria
      else
        flattened << data_criteria_converter.v2_data_criteria_by_id[precondition.reference.id]
      end
    else
      flattened.concat(extract_data_criteria(precondition.preconditions,data_criteria_converter))
    end
  end
  flattened
end

Instance Method Details

#build_group_data_criteria(children, section, parent_id, derivation_operator) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 50

def build_group_data_criteria(children, section, parent_id, derivation_operator)

  criteria_ids = children.map(&:id)
  # make sure nobody else is going to delete the criteria we've grouped
  criteria_ids.each {|target| validate_not_deleted(target)}

  id = "#{parent_id}_#{section}_#{HQMF::Counter.instance.next}"
  title = "#{id}"
  description = ""
  definition = 'derived'
  _display_name,_code_list_id,_status,_value,_field_values,_effective_time,_inline_code_list,_negation_code_list_id, = nil
  _negation = false
  
  group_criteria = HQMF::DataCriteria.new(id, title, _display_name, description, _code_list_id, criteria_ids, derivation_operator, definition, _status,
                                          _value, _field_values, _effective_time, _inline_code_list,_negation,_negation_code_list_id,nil,nil,nil,nil)
  
  @v2_data_criteria << group_criteria
  
  group_criteria
  
end

#convert_grouping_conjunction(conjunction) ⇒ Object



98
99
100
101
102
103
104
105
106
107
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 98

def convert_grouping_conjunction(conjunction)
  case conjunction
  when HQMF::Precondition::AT_LEAST_ONE_TRUE
    HQMF::DataCriteria::UNION
  when HQMF::Precondition::ALL_TRUE
    HQMF::DataCriteria::XPRODUCT
  else
    'unknown'
  end
end

#create_group_data_criteria(preconditions, type, value, parent_id, id, standard_category, qds_data_type) ⇒ Object

grouping data criteria are used to allow a single reference off of a temporal reference or subset operator grouping data criteria can reference either regular data criteria as children, or other grouping data criteria



46
47
48
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 46

def create_group_data_criteria(preconditions, type, value, parent_id, id, standard_category, qds_data_type)
  extract_group_data_criteria_tree(HQMF::DataCriteria::UNION,preconditions, type, parent_id)
end

#duplicate_data_criteria(data_criteria, parent_id) ⇒ Object

duplicates a data criteria. This is important because we may be modifying source data criteria like patient characteristic birthdate to add restrictions the restrictions added may be different for the numerator, denominator, different IPP_1, IPP_2, etc.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 23

def duplicate_data_criteria(data_criteria, parent_id)
  
  if (data_criteria.is_a? HQMF::Converter::SimpleDataCriteria and data_criteria.precondition_id == parent_id)
    new_data_criteria = data_criteria
  else
    new_data_criteria = HQMF::Converter::SimpleDataCriteria.from_data_criteria(data_criteria)
    new_data_criteria.assign_precondition(parent_id)
    @v2_data_criteria << new_data_criteria
    # we want to delete the original for data criteria that have been duplicated
    @v2_data_criteria_to_delete[data_criteria.id] = true if !@v2_data_criteria_to_delete.keys.include? data_criteria.id
  end
  
  new_data_criteria
end

#extract_group_data_criteria_tree(conjunction, preconditions, type, parent_id) ⇒ Object

pull the children data criteria out of a set of preconditions



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 73

def extract_group_data_criteria_tree(conjunction, preconditions, type, parent_id)
  
  children = []
  preconditions.each do |precondition|
    if (precondition.comparison?) 
      if (precondition.reference.id == HQMF::Document::MEASURE_PERIOD_ID)
        children << measure_period_criteria
      else
        children << v2_data_criteria_by_id[precondition.reference.id]
      end
    else
      converted_conjunction = convert_grouping_conjunction(precondition.conjunction_code) 
      children << extract_group_data_criteria_tree(converted_conjunction, precondition.preconditions, type, parent_id)
    end
  end
  
  # if we have just one child element, just return it.  An AND or OR of a single item is not useful.
  if (children.size > 1)
    build_group_data_criteria(children, type, parent_id, conjunction)
  else
    children.first
  end
  
end

#final_v2_data_criteriaObject



17
18
19
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 17

def final_v2_data_criteria
  @v2_data_criteria.delete_if {|criteria| @v2_data_criteria_to_delete[criteria.id] }
end

#v2_data_criteria_by_idObject



126
127
128
129
130
131
132
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 126

def v2_data_criteria_by_id
  criteria_by_id = {}
  @v2_data_criteria.each do |criteria|
    criteria_by_id[criteria.id] = criteria
  end
  criteria_by_id
end

#validate_not_deleted(target) ⇒ Object

make sure that if a data criteria is used as a target, that it is not deleted by someone else. this is required for birthdate in NQF0106



40
41
42
# File 'lib/hqmf-parser/converter/pass1/data_criteria_converter.rb', line 40

def validate_not_deleted(target)
  @v2_data_criteria_to_delete[target] = false
end