Class: HQMF2CQL::Document

Inherits:
HQMF2::Document show all
Defined in:
lib/hqmf-parser/cql/document.rb

Overview

Class representing a HQMF v2 document that uses CQL for measure logic.

Constant Summary

Constants inherited from HQMF2::Document

HQMF2::Document::NAMESPACES

Instance Attribute Summary

Attributes inherited from HQMF2::Document

#attributes, #hqmf_set_id, #hqmf_version_number, #id, #measure_period, #populations, #source_data_criteria

Instance Method Summary collapse

Methods inherited from HQMF2::Document

#add_data_criteria, #add_reference_id, #all_data_criteria, #all_population_criteria, #all_reference_ids, #data_criteria, #description, #find, #find_criteria_by_lvn, parse, #population_criteria, #title

Methods included from HQMF2::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 HQMF2::DocumentUtilities

#complex_coverage, #criteria_covered_by_criteria?, #detect_criteria_covered_by_criteria, #extract_source_data_criteria, #handle_variable, #same_field_values_check

Constructor Details

#initialize(hqmf_contents, use_default_measure_period = true) ⇒ Document

Create a new HQMF2CQL::Document instance by parsing the given HQMF contents.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hqmf-parser/cql/document.rb', line 7

def initialize(hqmf_contents, use_default_measure_period = true)
  # Set up basic measure values
  setup_default_values(hqmf_contents, use_default_measure_period)

  # Extract data criteria
  extract_criteria

  # Extract the population criteria and population collections
  pop_helper = HQMF2CQL::DocumentPopulationHelper.new(@entry, @doc, self, @id_generator, @reference_ids)
  # @populations_cql_map and @observations are needed by the frontend
  @populations, @population_criteria, @populations_cql_map, @observations = pop_helper.extract_populations
  @cql_measure_library = pop_helper.extract_main_library
end

Instance Method Details

#extract_criteriaObject

Extracts data criteria from the HQMF document.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hqmf-parser/cql/document.rb', line 33

def extract_criteria
  # Grab each data criteria entry from the HQMF
  extracted_data_criteria = []
  @doc.xpath('cda:QualityMeasureDocument/cda:component/cda:dataCriteriaSection/cda:entry', NAMESPACES).each do |entry|
    extracted_data_criteria << entry
    dc = HQMF2CQL::DataCriteria.new(entry) # Create new data criteria
    sdc = dc.clone # Clone data criteria
    sdc.id += '_source' # Make it a source

    @data_criteria << dc
    @source_data_criteria << sdc
  end
  make_positive_entry
end

#make_positive_entryObject

This method is needed for situations when there is a only a negated version of a data criteria. Bonnie will only show the affirmative version of data criteria. This method will create an affirmative version of a data criteria when there is only the negative one in the HQMF.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/hqmf-parser/cql/document.rb', line 53

def make_positive_entry
  negated_criteria = []
  data_criteria_index_lookup = []
  # Find the criteria that are negated
  # At the same time build a hash of all criteria and their code_list_id, definition, status, and negation status
  @data_criteria.each_with_index do |criterion, source_index|
    negated_criteria << criterion if criterion.negation
    data_criteria_index_lookup << [criterion.code_list_id, criterion.definition, criterion.status, criterion.negation]
  end

  negated_criteria.each do |criterion|
    # Check if there is a criterion with the same OID, definition and status BUT that isn't negated
    unless data_criteria_index_lookup.include?([criterion.code_list_id, criterion.definition, criterion.status, false])
      spoofed_positive_instance = criterion.clone
      spoofed_positive_instance.make_criterion_positive
      @data_criteria << spoofed_positive_instance
      sdc = spoofed_positive_instance.clone
      sdc.id += '_source'
      @source_data_criteria << sdc
    end
  end

end

#to_modelObject

Generates this classes hqmf-model equivalent.



22
23
24
25
26
27
28
29
30
# File 'lib/hqmf-parser/cql/document.rb', line 22

def to_model
  dcs = all_data_criteria.compact.collect(&:to_model)
  sdc = source_data_criteria.compact.collect(&:to_model)
  pcs = all_population_criteria.compact.collect(&:to_model)
  HQMF::Document.new(@id, @id, @hqmf_set_id, @hqmf_version_number, @cms_id,
                     title, description, pcs, dcs, sdc,
                     @attributes, @measure_period, @populations,
                     populations_cql_map=@populations_cql_map, cql_measure_library=@cql_measure_library, observations=@observations)
end