Class: HQMF2::DataCriteriaBaseExtractions

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb

Overview

Contains extraction methods which are self-contained (rely only on the xml and an xpath, no other instance variables)

Constant Summary collapse

CONJUNCTION_CODE_TO_DERIVATION_OP =
{
  'OR' => 'UNION',
  'AND' => 'XPRODUCT'
}

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

Constructor Details

#initialize(entry) ⇒ DataCriteriaBaseExtractions

Returns a new instance of DataCriteriaBaseExtractions.



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

def initialize(entry)
  @entry = entry
end

Instance Method Details

#all_subset_operatorsObject

Extracts all subset operators contained in the entry xml



56
57
58
59
60
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 56

def all_subset_operators
  @entry.xpath('./*/cda:excerpt', HQMF2::Document::NAMESPACES).collect do |subset_operator|
    SubsetOperator.new(subset_operator)
  end
end

#extract_child_criteriaObject

Generate a list of child criterias



22
23
24
25
26
27
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 22

def extract_child_criteria
  @entry.xpath("./*/cda:outboundRelationship[@typeCode='COMP']/cda:criteriaReference/cda:id",
               HQMF2::Document::NAMESPACES).collect do |ref|
    Reference.new(ref).id
  end.compact
end

#extract_derivation_operatorObject

Extracts the derivation operator to be used by the data criteria, and fails out if it finds more than one (should not be valid)



31
32
33
34
35
36
37
38
39
40
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 31

def extract_derivation_operator
  codes = @entry.xpath("./*/cda:outboundRelationship[@typeCode='COMP']/cda:conjunctionCode/@code",
                       HQMF2::Document::NAMESPACES)
  codes.inject(nil) do |d_op, code|
    if d_op && d_op != CONJUNCTION_CODE_TO_DERIVATION_OP[code.value]
      fail 'More than one derivation operator in data criteria'
    end
    CONJUNCTION_CODE_TO_DERIVATION_OP[code.value]
  end
end

#extract_local_variable_nameObject

Extract the local variable name (held in the value of the localVariableName element)



16
17
18
19
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 16

def extract_local_variable_name
  lvn = @entry.at_xpath('./cda:localVariableName')
  lvn['value'] if lvn
end

#extract_negationObject

Extract the negation (and the negation_code_list_id if appropriate)



69
70
71
72
73
74
75
76
77
78
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 69

def extract_negation
  negation = (attr_val('./*/@actionNegationInd').to_s.downcase == 'true')
  negation_code_list_id = nil
  if negation
    res = @entry.at_xpath('./*/cda:outboundRelationship/*/cda:code[@code="410666004"]/../cda:value/@valueSet',
                          HQMF2::Document::NAMESPACES)
    negation_code_list_id = res.value if res
  end
  [negation, negation_code_list_id]
end

#extract_subset_operatorsObject

Filters all the subset operators to only include the ones of type ‘UNION’ and ‘XPRODUCT’



49
50
51
52
53
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 49

def extract_subset_operators
  all_subset_operators.select do |operator|
    operator.type != 'UNION' && operator.type != 'XPRODUCT'
  end
end

#extract_template_idsObject



62
63
64
65
66
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 62

def extract_template_ids
  @entry.xpath('./*/cda:templateId/cda:item', HQMF2::Document::NAMESPACES).collect do |template_def|
    HQMF2::Utilities.attr_val(template_def, '@root')
  end
end

#extract_temporal_referencesObject



42
43
44
45
46
# File 'lib/hqmf-parser/2.0/data_criteria_helpers/dc_base_extract.rb', line 42

def extract_temporal_references
  @entry.xpath('./*/cda:temporallyRelatedInformation', HQMF2::Document::NAMESPACES).collect do |temporal_reference|
    TemporalReference.new(temporal_reference)
  end
end