Class: HQMF2::DataCriteria

Inherits:
Object
  • Object
show all
Includes:
DataCriteriaPostProcessing, DataCriteriaTypeAndDefinitionExtraction, Utilities
Defined in:
lib/hqmf-parser/2.0/data_criteria.rb

Overview

Represents a data criteria specification

Direct Known Subclasses

HQMF2CQL::DataCriteria

Constant Summary collapse

CRITERIA_GLOB =
"*[substring(name(),string-length(name())-7) = \'Criteria\']"

Constants included from DataCriteriaTypeAndDefinitionExtraction

HQMF2::DataCriteriaTypeAndDefinitionExtraction::SATISFIES_ALL_TEMPLATE, HQMF2::DataCriteriaTypeAndDefinitionExtraction::SATISFIES_ANY_TEMPLATE, HQMF2::DataCriteriaTypeAndDefinitionExtraction::VARIABLE_TEMPLATE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#attr_val, attr_val, #strip_tokens, #to_xml

Methods included from HQMF::Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Methods included from DataCriteriaTypeAndDefinitionExtraction

#definition_for_demographic, #definition_for_nil_entry, #extract_definition_from_entry_type, #extract_definition_from_template_id, #extract_definition_from_template_or_type, #extract_definition_from_type, #extract_information_for_specific_variable, #handle_entry_type, #handle_known_template_id, #handle_specific_variable_ref

Methods included from DataCriteriaPostProcessing

#change_xproduct_to_intersection, #extract_code_list_path_and_result_value, #handle_derived_specific_occurrences, #handle_mapping_template, #post_processing

Constructor Details

#initialize(entry, data_criteria_references = {}, occurrences_map = {}) ⇒ DataCriteria

Create a new instance based on the supplied HQMF entry

Parameters:

  • entry (Nokogiri::XML::Element)

    the parsed HQMF entry



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 19

def initialize(entry, data_criteria_references = {}, occurrences_map = {})
  @entry = entry
  @data_criteria_references = data_criteria_references
  @occurrences_map = occurrences_map
  basic_setup
  @variable = DataCriteriaMethods.extract_variable(@local_variable_name, @id)
  @field_values = DataCriteriaMethods.extract_field_values(@entry, @negation)
  @description = extract_description
  obtain_specific_and_source = SpecificOccurrenceAndSource.new(@entry, @id, @local_variable_name,
                                                               @data_criteria_references, @occurrences_map)
  # Pulling these 5 variables out via destructing
  @source_data_criteria,
    @source_data_criteria_root,
    @source_data_criteria_extension,
    @specific_occurrence,
    @specific_occurrence_const = obtain_specific_and_source.extract_specific_occurrences_and_source_data_criteria
  extract_definition_from_template_or_type
  post_processing
end

Instance Attribute Details

#children_criteriaObject (readonly)

Returns the value of attribute children_criteria.



9
10
11
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 9

def children_criteria
  @children_criteria
end

#commentsObject (readonly)

Returns the value of attribute comments.



12
13
14
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 12

def comments
  @comments
end

#definitionObject (readonly)

Returns the value of attribute definition.



13
14
15
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 13

def definition
  @definition
end

#derivation_operatorObject (readonly)

Returns the value of attribute derivation_operator.



10
11
12
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 10

def derivation_operator
  @derivation_operator
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 10

def description
  @description
end

#effective_timeObject (readonly)

Returns the value of attribute effective_time.



8
9
10
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 8

def effective_time
  @effective_time
end

#entryObject (readonly)

Returns the value of attribute entry.



13
14
15
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 13

def entry
  @entry
end

#field_valuesObject (readonly)

Returns the value of attribute field_values.



11
12
13
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 11

def field_values
  @field_values
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 6

def id
  @id
end

#is_derived_specific_occurrence_variableObject (readonly)

Returns the value of attribute is_derived_specific_occurrence_variable.



12
13
14
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 12

def is_derived_specific_occurrence_variable
  @is_derived_specific_occurrence_variable
end

#local_variable_nameObject (readonly)

Returns the value of attribute local_variable_name.



13
14
15
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 13

def local_variable_name
  @local_variable_name
end

#negationObject (readonly)

Returns the value of attribute negation.



10
11
12
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 10

def negation
  @negation
end

#negation_code_list_idObject (readonly)

Returns the value of attribute negation_code_list_id.



10
11
12
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 10

def negation_code_list_id
  @negation_code_list_id
end

#original_idObject

Returns the value of attribute original_id.



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

def original_id
  @original_id
end

#propertyObject (readonly)

Returns the value of attribute property.



8
9
10
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 8

def property
  @property
end

#sectionObject (readonly)

Returns the value of attribute section.



8
9
10
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 8

def section
  @section
end

#source_data_criteriaObject (readonly)

Returns the value of attribute source_data_criteria.



11
12
13
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 11

def source_data_criteria
  @source_data_criteria
end

#specific_occurrenceObject (readonly)

Returns the value of attribute specific_occurrence.



12
13
14
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 12

def specific_occurrence
  @specific_occurrence
end

#specific_occurrence_constObject (readonly)

Returns the value of attribute specific_occurrence_const.



11
12
13
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 11

def specific_occurrence_const
  @specific_occurrence_const
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 8

def status
  @status
end

#subset_operatorsObject (readonly)

Returns the value of attribute subset_operators.



9
10
11
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 9

def subset_operators
  @subset_operators
end

#temporal_referencesObject (readonly)

Returns the value of attribute temporal_references.



9
10
11
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 9

def temporal_references
  @temporal_references
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 8

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 8

def value
  @value
end

#variableObject (readonly)

Returns the value of attribute variable.



13
14
15
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 13

def variable
  @variable
end

Instance Method Details

#cloneObject

clone method. This is needed because we need to extract a new source data criteria for variables typically “cloning” is done by re-parsing the xml entry, however with post processing that does not give us the correct SDC data when we are trying to recreate since we are looping back through the same data criteria before it has finished processing: See: DocUtilities.extract_source_data_criteria



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 150

def clone
  # Using 'self.class.new' in order to allow this DataCriteria class as
  # well as any future new extending DataCriteria classes to use this clone
  # function.
  other = self.class.new(@entry, @data_criteria_references, @occurrences_map)
  other.instance_variable_set(:@id, @id)
  other.instance_variable_set(:@original_id, @original_id)
  other.instance_variable_set(:@property, @property)
  other.instance_variable_set(:@type, @type)
  other.instance_variable_set(:@status, @status)
  other.instance_variable_set(:@code_list_id, @code_list_id)
  other.instance_variable_set(:@value, @value)
  other.instance_variable_set(:@effective_time, @effective_time)
  other.instance_variable_set(:@section, @section)
  other.instance_variable_set(:@temporal_references, @temporal_references)
  other.instance_variable_set(:@subset_operators, @subset_operators)
  other.instance_variable_set(:@children_criteria, @children_criteria)
  other.instance_variable_set(:@derivation_operator, @derivation_operator)
  other.instance_variable_set(:@negation, @negation)
  other.instance_variable_set(:@negation_code_list_id, @negation_code_list_id)
  other.instance_variable_set(:@description, @description)
  other.instance_variable_set(:@field_values, @field_values)
  other.instance_variable_set(:@source_data_criteria, @source_data_criteria)
  other.instance_variable_set(:@specific_occurrence_const, @specific_occurrence_const)
  other.instance_variable_set(:@specific_occurrence, @specific_occurrence)
  other.instance_variable_set(:@comments, @comments)
  other.instance_variable_set(:@is_derived_specific_occurrence_variable, @is_derived_specific_occurrence_variable)
  other.instance_variable_set(:@entry, @entry)
  other.instance_variable_set(:@definition, @definition)
  other.instance_variable_set(:@variable, @variable)
  other.instance_variable_set(:@local_variable_name, @local_variable_name)
  other
end

#code_list_idString

Get the code list OID of the criteria, used as an index to the code list database

Returns:

  • (String)

    the code list identifier of this data criteria



65
66
67
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 65

def code_list_id
  @code_list_id || attr_val("#{@code_list_xpath}/@valueSet")
end

#extract_as_grouperObject

Extract this data criteria as a grouper data criteria SHOULD only be called on a variable data criteria instance



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 117

def extract_as_grouper
  @field_values = {}
  @temporal_references = []
  @subset_operators = []
  @derivation_operator = HQMF::DataCriteria::UNION
  @definition = 'derived'
  @status = nil
  @children_criteria = ["GROUP_#{@id}"]
  @source_data_criteria = @id
  self
end

#extract_variable_grouperObject

Return a new DataCriteria instance with only grouper attributes set. A grouper criteria allows multiple data criteria events to be contained in a single logical set (a union or intersection of these multiple events - i.e. A during (B or C or D)). Grouper criteria also provide a way to combine multiple criteria that reference a specific occurrence of an event.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 96

def extract_variable_grouper
  return unless @variable
  @variable = false
  @id = "GROUP_#{@id}"
  if @children_criteria.length == 1 && @children_criteria[0] =~ /GROUP_/
    reference_criteria = @data_criteria_references[@children_criteria.first]
    return if reference_criteria.nil?
    duplicate_child_info(reference_criteria)
    @definition = reference_criteria.definition
    @status = reference_criteria.status
    @children_criteria = []
  end
  @specific_occurrence = nil
  @specific_occurrence_const = nil
  # set the source data criteria id to the id for variables
  @source_data_criteria = @id
  DataCriteria.new(@entry, @data_criteria_references, @occurrences_map).extract_as_grouper
end

#handle_derived_specific_occurrence_variableObject

Handle elements that are marked as variable groupers that should not be turned into a “holding element” (defined as a data criteria that encapsulates the calculation material for other data criteria elements, where the other data criteria elements reference the holding element as a child element)



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 132

def handle_derived_specific_occurrence_variable
  # If the first child is all the exists, and it has been marked as a "group" element, switch this over to map to
  # the new element.
  if !@data_criteria_references["GROUP_#{@children_criteria.first}"].nil? && @children_criteria.length == 1
    @children_criteria[0] = "GROUP_#{@children_criteria.first}"
  # If the group element is not found, extract the information from the child and force it into the variable.
  elsif @children_criteria.length == 1 && @children_criteria.first.present?
    reference_criteria = @data_criteria_references[@children_criteria.first]
    return if reference_criteria.nil?
    duplicate_child_info(reference_criteria)
    @children_criteria = reference_criteria.children_criteria
  end
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
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 58

def title
  disp_value = attr_val("#{@code_list_xpath}/cda:displayName/@value")
  @title || disp_value || @description || id # allow defined titles to take precedence
end

#to_modelObject

Generates this classes hqmf-model equivalent



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 70

def to_model
  mv = value.try(:to_model)
  met = effective_time.try(:to_model)
  mtr = temporal_references.collect(&:to_model)
  mso = subset_operators.collect(&:to_model)
  field_values = retrieve_field_values_model_for_model

  retrieve_title_and_description_for_model unless @variable || @derivation_operator

  @code_list_id = nil if @derivation_operator

  # prevent json model generation of empty children and comments
  cc = children_criteria.present? ? children_criteria : nil
  comments = @comments.present? ? @comments : nil

  HQMF::DataCriteria.new(id, title, nil, description, @code_list_id, cc, derivation_operator, @definition, status,
                         mv, field_values, met, retrieve_code_system_for_model, @negation, @negation_code_list_id,
                         mtr, mso, @specific_occurrence, @specific_occurrence_const, @source_data_criteria,
                         comments, @variable)
end

#to_sObject



39
40
41
42
43
44
45
46
47
# File 'lib/hqmf-parser/2.0/data_criteria.rb', line 39

def to_s
  props = {
    property: property,
    type: type,
    status: status,
    section: section
  }
  "DataCriteria#{props}"
end