Class: HQMF2::DataCriteriaMethods

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

Overview

Holds methods not tied to the data criteria’s instance variables

Class Method Summary collapse

Class Method Details

.extract_description_for_variable(encoded_name) ⇒ Object

Use the new MAT feature to extract the human generated (or computer generated) variable names from the xml.



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# 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) ⇒ Object

Given an entry, and whether or not it’s negated, extract out the proper field values for the data criteria.



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# 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) ⇒ Object

Determine if this instance is a qdm variable



366
367
368
369
370
# 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) ⇒ Object

Derives the type associated with a specific value



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# 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) ⇒ Object

Parses the value for a given xpath



336
337
338
339
340
341
342
343
# 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