class HQMF2::DataCriteriaMethods
Holds methods not tied to the data criteria's instance variables
Public Class Methods
extract_description_for_variable(encoded_name)
click to toggle source
Use the new MAT feature to extract the human generated (or computer generated) variable names from the xml.
# File lib/hqmf-parser/2.0/data_criteria.rb, line 318 def self.extract_description_for_variable(encoded_name) if encoded_name.match(/^qdm_var_/) # Strip out initial qdm_var_ string, trailing _*, and possible occurrence reference encoded_name.gsub!(/^qdm_var_|/, '') encoded_name.gsub!(/Occurrence[A-Z]of/, '') # This code needs to handle measures created before the MAT added variable name hints; for those, don't strip # the final identifier unless encoded_name.match(/^(SATISFIES ALL|SATISFIES ANY|UNION|INTERSECTION)/) encoded_name.gsub!(/_[^_]+$/, '') end encoded_name elsif encoded_name.match(/^localVar_/) encoded_name.gsub!(/^localVar_/, '') encoded_name end end
extract_field_values(entry, negation)
click to toggle source
Given an entry, and whether or not it's negated, extract out the proper field values for the data criteria.
# File lib/hqmf-parser/2.0/data_criteria.rb, line 287 def self.extract_field_values(entry, negation) fields = {} # extract most fields which use the same structure entry.xpath('./*/cda:outboundRelationship[*/cda:code]', HQMF2::Document::NAMESPACES).each do |field| code = HQMF2::Utilities.attr_val(field, './*/cda:code/@code') code_id = HQMF::DataCriteria::VALUE_FIELDS[code] # No need to run if there is no code id next if (negation && code_id == 'REASON') || code_id.nil? value = DataCriteriaMethods.parse_value(field, './*/cda:value') value ||= DataCriteriaMethods.parse_value(field, './*/cda:effectiveTime') fields[code_id] = value end # special case for facility location which uses a very different structure entry.xpath('./*/cda:outboundRelationship[*/cda:participation]', HQMF2::Document::NAMESPACES).each do |field| code = HQMF2::Utilities.attr_val(field, './*/cda:participation/cda:role/@classCode') code_id = HQMF::DataCriteria::VALUE_FIELDS[code] next if code_id.nil? value = Coded.new(field.at_xpath('./*/cda:participation/cda:role/cda:code', HQMF2::Document::NAMESPACES)) fields[code_id] = value end fields.merge! HQMF2::FieldValueHelper.parse_field_values(entry) # special case for fulfills operator. assuming there is only a possibility of having one of these fulfills = entry.at_xpath('./*/cda:outboundRelationship[@typeCode="FLFS"]/cda:criteriaReference', HQMF2::Document::NAMESPACES) # grab the child element if we don't have a reference fields['FLFS'] = TypedReference.new(fulfills) if fulfills fields end
extract_variable(local_variable_name, id)
click to toggle source
Determine if this instance is a qdm variable
# File lib/hqmf-parser/2.0/data_criteria.rb, line 366 def self.extract_variable(local_variable_name, id) variable = (local_variable_name =~ /.*qdm_var_/).present? unless local_variable_name.blank? variable ||= (id =~ /.*qdm_var_/).present? unless id.blank? variable end
handle_value_type(value_type_def, value_def)
click to toggle source
Derives the type associated with a specific value
# File lib/hqmf-parser/2.0/data_criteria.rb, line 346 def self.handle_value_type(value_type_def, value_def) value_type = value_type_def.value case value_type when 'PQ' Value.new(value_def, 'PQ', true) when 'TS' Value.new(value_def) when 'IVL_PQ', 'IVL_INT' Range.new(value_def) when 'CD' Coded.new(value_def) when 'ANY', 'IVL_TS' # FIXME: (10/26/2015) IVL_TS should be able to handle other values, not just AnyValue AnyValue.new else fail "Unknown value type [#{value_type}]" end end
parse_value(node, xpath)
click to toggle source
Parses the value for a given xpath
# File lib/hqmf-parser/2.0/data_criteria.rb, line 336 def self.parse_value(node, xpath) value_def = node.at_xpath(xpath, HQMF2::Document::NAMESPACES) if value_def return AnyValue.new if value_def.at_xpath('@flavorId') == 'ANY.NONNULL' value_type_def = value_def.at_xpath('@xsi:type', HQMF2::Document::NAMESPACES) return handle_value_type(value_type_def, value_def) if value_type_def end end