Module: HQMF2::DataCriteriaTypeAndDefinitionExtraction
- Defined in:
- lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb
Overview
Extracts the type, and modifies the data criteria, based on the template id or definition
Constant Summary collapse
- VARIABLE_TEMPLATE =
'0.1.2.3.4.5.6.7.8.9.1'
- SATISFIES_ANY_TEMPLATE =
'2.16.840.1.113883.10.20.28.3.108'
- SATISFIES_ALL_TEMPLATE =
'2.16.840.1.113883.10.20.28.3.109'
Instance Method Summary collapse
-
#definition_for_demographic ⇒ Object
Return the definition for a known subset of patient characteristics.
-
#definition_for_nil_entry ⇒ Object
If there is no entry type, extract the entry type from what it references, and extract additional information for specific occurrences.
-
#extract_definition_from_entry_type(entry_type) ⇒ Object
Given an entry type (which describes the criteria’s purpose) return the appropriate defintino.
-
#extract_definition_from_template_id ⇒ Object
Given a template id, derive (if available) the definition for the template.
- #extract_definition_from_template_or_type ⇒ Object
-
#extract_definition_from_type ⇒ Object
Extract the definition (sometimes status, sometimes other elements) of the data criteria based on the type.
-
#extract_information_for_specific_variable ⇒ Object
Extracts information from a reference for a specific.
-
#handle_entry_type(entry_type) ⇒ Object
Generate the definition and/or status from the entry type in most cases.
-
#handle_known_template_id(template_id) ⇒ Object
Given a template id, modify the variables inside this data criteria to reflect the template.
-
#handle_specific_variable_ref(reference_criteria) ⇒ Object
Apply additional information to a specific occurrence’s elements from the criteria it references.
Instance Method Details
#definition_for_demographic ⇒ Object
Return the definition for a known subset of patient characteristics
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 184 def definition_for_demographic demographic_type = attr_val('./cda:observationCriteria/cda:code/@code') demographic_translation = { '21112-8' => 'patient_characteristic_birthdate', '424144002' => 'patient_characteristic_age', '263495000' => 'patient_characteristic_gender', '102902016' => 'patient_characteristic_languages', '125680007' => 'patient_characteristic_marital_status', '103579009' => 'patient_characteristic_race' } if demographic_translation[demographic_type] demographic_translation[demographic_type] else fail "Unknown demographic identifier [#{demographic_type}]" end end |
#definition_for_nil_entry ⇒ Object
If there is no entry type, extract the entry type from what it references, and extract additional information for specific occurrences. If there are no outbound references, print an error and mark it as variable.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 132 def definition_for_nil_entry reference = @entry.at_xpath('./*/cda:outboundRelationship/cda:criteriaReference', HQMF2::Document::NAMESPACES) ref_id = nil unless reference.nil? ref_id = "#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}" end reference_criteria = @data_criteria_references[strip_tokens(ref_id)] unless ref_id.nil? if reference_criteria # we only want to copy the reference criteria definition, status, and code_list_id if this is this is not a grouping criteria (i.e., there are no children) if @children_criteria.blank? @definition = reference_criteria.definition @status = reference_criteria.status if @specific_occurrence @title = reference_criteria.title @description = reference_criteria.description @code_list_id = reference_criteria.code_list_id end else # if this is a grouping data criteria (has children) mark it as derived and only pull title and description from the reference criteria @definition = 'derived' if @specific_occurrence @title = reference_criteria.title @description = reference_criteria.description end end else puts "MISSING_DC_REF: #{ref_id}" unless @variable @definition = 'variable' end end |
#extract_definition_from_entry_type(entry_type) ⇒ Object
Given an entry type (which describes the criteria’s purpose) return the appropriate defintino
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 164 def extract_definition_from_entry_type(entry_type) case entry_type when 'Problem', 'Problems' 'diagnosis' when 'Encounter', 'Encounters' 'encounter' when 'LabResults', 'Results' 'laboratory_test' when 'Procedure', 'Procedures' 'procedure' when 'Demographics' definition_for_demographic when 'Derived' 'derived' else fail "Unknown data criteria template identifier [#{entry_type}]" end end |
#extract_definition_from_template_id ⇒ Object
Given a template id, derive (if available) the definition for the template.
The definitions are stored in hqmf-model/data_criteria.json.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 18 def extract_definition_from_template_id found = false @template_ids.each do |template_id| defs = HQMF::DataCriteria.definition_for_template_id(template_id, 'r2') if defs @definition = defs['definition'] @status = defs['status'].length > 0 ? defs['status'] : nil found ||= true else found ||= handle_known_template_id(template_id) end end found end |
#extract_definition_from_template_or_type ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 7 def extract_definition_from_template_or_type # Try to determine what kind of data criteria we are dealing with # First we look for a template id and if we find one just use the definition # status and negation associated with that # If no template id or not one we recognize then try to determine type from # the definition element extract_definition_from_type unless extract_definition_from_template_id end |
#extract_definition_from_type ⇒ Object
Extract the definition (sometimes status, sometimes other elements) of the data criteria based on the type
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 57 def extract_definition_from_type # If we have a specific occurrence of a variable, pull attributes from the reference. # IDEA set this up to be called from dc_specific_and_source_extract, the number of # fields changed by handle_specific_variable_ref may pose an issue. extract_information_for_specific_variable if @variable && @specific_occurrence if @entry.at_xpath('./cda:grouperCriteria') @definition ||= 'derived' return end # See if we can find a match for the entry definition value and status. entry_type = attr_val('./*/cda:definition/*/cda:id/@extension') handle_entry_type(entry_type) end |
#extract_information_for_specific_variable ⇒ Object
Extracts information from a reference for a specific
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 73 def extract_information_for_specific_variable reference = @entry.at_xpath('./*/cda:outboundRelationship/cda:criteriaReference', HQMF2::Document::NAMESPACES) if reference ref_id = strip_tokens( "#{HQMF2::Utilities.attr_val(reference, 'cda:id/@extension')}_#{HQMF2::Utilities.attr_val(reference, 'cda:id/@root')}") end reference_criteria = @data_criteria_references[ref_id] if ref_id # if the reference is derived, pull from the original variable if reference_criteria && reference_criteria.definition == 'derived' reference_criteria = @data_criteria_references["GROUP_#{ref_id}"] end return unless reference_criteria handle_specific_variable_ref(reference_criteria) end |
#handle_entry_type(entry_type) ⇒ Object
Generate the definition and/or status from the entry type in most cases. If the entry type is nil, and the value is a specific occurrence, more parsing may be necessary.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 110 def handle_entry_type(entry_type) # settings is required to trigger exceptions, which set the definition HQMF::DataCriteria.get_settings_for_definition(entry_type, @status) @definition = entry_type rescue # if no exact match then try a string match just using entry definition value case entry_type when 'Medication', 'Medications' @definition = 'medication' @status = 'active' unless @status when 'RX' @definition = 'medication' @status = 'dispensed' unless @status when nil definition_for_nil_entry else @definition = extract_definition_from_entry_type(entry_type) end end |
#handle_known_template_id(template_id) ⇒ Object
Given a template id, modify the variables inside this data criteria to reflect the template
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 36 def handle_known_template_id(template_id) case template_id when VARIABLE_TEMPLATE @derivation_operator = HQMF::DataCriteria::INTERSECT if @derivation_operator == HQMF::DataCriteria::XPRODUCT @definition ||= 'derived' @variable = true @negation = false when SATISFIES_ANY_TEMPLATE @definition = HQMF::DataCriteria::SATISFIES_ANY @negation = false when SATISFIES_ALL_TEMPLATE @definition = HQMF::DataCriteria::SATISFIES_ALL @derivation_operator = HQMF::DataCriteria::INTERSECT @negation = false else return false end true end |
#handle_specific_variable_ref(reference_criteria) ⇒ Object
Apply additional information to a specific occurrence’s elements from the criteria it references.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_definition_from_template_or_type_extract.rb', line 90 def handle_specific_variable_ref(reference_criteria) # if there are no referenced children, then it's a variable representing # a single data criteria, so just reference it if reference_criteria.children_criteria.empty? @children_criteria = [reference_criteria.id] # otherwise pull all the data criteria info from the reference else @field_values = reference_criteria.field_values @temporal_references = reference_criteria.temporal_references @subset_operators = reference_criteria.subset_operators @derivation_operator = reference_criteria.derivation_operator @definition = reference_criteria.definition @description = reference_criteria.description @status = reference_criteria.status @children_criteria = reference_criteria.children_criteria end end |