Class: HQMF2::Document

Inherits:
Object
  • Object
show all
Includes:
DocumentUtilities, Utilities
Defined in:
lib/hqmf-parser/2.0/document.rb

Overview

Class representing an HQMF document

Direct Known Subclasses

HQMF2CQL::Document

Constant Summary collapse

NAMESPACES =
{ 'cda' => 'urn:hl7-org:v3',
'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'qdm' => 'urn:hhs-qdm:hqmf-r2-extensions:v1' }

Instance Attribute Summary collapse

Class Method Summary collapse

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

Methods included from 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 HQMF2::Document instance by parsing the given HQMF contents

Parameters:

  • containing (String)

    the HQMF contents to be parsed



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hqmf-parser/2.0/document.rb', line 14

def initialize(hqmf_contents, use_default_measure_period = true)
  setup_default_values(hqmf_contents, use_default_measure_period)

  extract_criteria

  # Extract the population criteria and population collections
  pop_helper = HQMF2::DocumentPopulationHelper.new(@entry, @doc, self, @id_generator, @reference_ids)
  @populations, @population_criteria = pop_helper.extract_populations_and_criteria

  # Remove any data criteria from the main data criteria list that already has an equivalent member
  #  and no references to it. The goal of this is to remove any data criteria that should not
  #  be purely a source.
  @data_criteria.reject! do |dc|
    criteria_covered_by_criteria?(dc)
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/hqmf-parser/2.0/document.rb', line 9

def attributes
  @attributes
end

#hqmf_set_idObject (readonly)

Returns the value of attribute hqmf_set_id.



9
10
11
# File 'lib/hqmf-parser/2.0/document.rb', line 9

def hqmf_set_id
  @hqmf_set_id
end

#hqmf_version_numberObject (readonly)

Returns the value of attribute hqmf_version_number.



9
10
11
# File 'lib/hqmf-parser/2.0/document.rb', line 9

def hqmf_version_number
  @hqmf_version_number
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/hqmf-parser/2.0/document.rb', line 9

def id
  @id
end

#measure_periodObject (readonly)

Returns the value of attribute measure_period.



9
10
11
# File 'lib/hqmf-parser/2.0/document.rb', line 9

def measure_period
  @measure_period
end

#populationsObject (readonly)

Returns the value of attribute populations.



9
10
11
# File 'lib/hqmf-parser/2.0/document.rb', line 9

def populations
  @populations
end

#source_data_criteriaObject (readonly)

Returns the value of attribute source_data_criteria.



9
10
11
# File 'lib/hqmf-parser/2.0/document.rb', line 9

def source_data_criteria
  @source_data_criteria
end

Class Method Details

.parse(hqmf_contents) ⇒ Nokogiri::XML::Document

Parse an XML document from the supplied contents

Returns:

  • (Nokogiri::XML::Document)


94
95
96
97
98
# File 'lib/hqmf-parser/2.0/document.rb', line 94

def self.parse(hqmf_contents)
  doc = hqmf_contents.is_a?(Nokogiri::XML::Document) ? hqmf_contents : Nokogiri::XML(hqmf_contents)
  doc.root.add_namespace_definition('cda', 'urn:hl7-org:v3')
  doc
end

Instance Method Details

#add_data_criteria(dc) ⇒ Object

Adds data criteria to the Document’s criteria list needed so data criteria can be added to a document from other objects



72
73
74
# File 'lib/hqmf-parser/2.0/document.rb', line 72

def add_data_criteria(dc)
  @data_criteria << dc
end

#add_reference_id(id) ⇒ Object

Adds id of a data criteria to the list of reference ids



88
89
90
# File 'lib/hqmf-parser/2.0/document.rb', line 88

def add_reference_id(id)
  @reference_ids << id
end

#all_data_criteriaArray

Get all the data criteria defined by the measure

Returns:

  • (Array)

    an array of HQMF2::DataCriteria describing the data elements used by the measure



59
60
61
# File 'lib/hqmf-parser/2.0/document.rb', line 59

def all_data_criteria
  @data_criteria
end

#all_population_criteriaArray

Get all the population criteria defined by the measure

Returns:

  • (Array)

    an array of HQMF2::PopulationCriteria



46
47
48
# File 'lib/hqmf-parser/2.0/document.rb', line 46

def all_population_criteria
  @population_criteria
end

#all_reference_idsArray

Get ids of data criteria directly referenced by others

Returns:

  • (Array)

    an array of ids of directly referenced data criteria



83
84
85
# File 'lib/hqmf-parser/2.0/document.rb', line 83

def all_reference_ids
  @reference_ids
end

#data_criteria(id) ⇒ HQMF2::DataCriteria

Get a specific data criteria by id.

Parameters:

  • id (String)

    the data criteria identifier

Returns:



66
67
68
# File 'lib/hqmf-parser/2.0/document.rb', line 66

def data_criteria(id)
  find(@data_criteria, :id, id)
end

#descriptionString

Get the description of the measure

Returns:

  • (String)

    the description



39
40
41
42
# File 'lib/hqmf-parser/2.0/document.rb', line 39

def description
  description = @doc.at_xpath('cda:QualityMeasureDocument/cda:text/@value', NAMESPACES)
  description.nil? ? '' : description.inner_text
end

#find(collection, attribute, value) ⇒ Object

Finds an element within the collection given that has an instance variable or method of “attribute” with a value of “value”



112
113
114
# File 'lib/hqmf-parser/2.0/document.rb', line 112

def find(collection, attribute, value)
  collection.find { |e| e.send(attribute) == value }
end

#find_criteria_by_lvn(local_variable_name) ⇒ Object

Finds a data criteria by it’s local variable name



77
78
79
# File 'lib/hqmf-parser/2.0/document.rb', line 77

def find_criteria_by_lvn(local_variable_name)
  find(@data_criteria, :local_variable_name, local_variable_name)
end

#population_criteria(id) ⇒ HQMF2::PopulationCriteria

Get a specific population criteria by id.

Parameters:

  • id (String)

    the population identifier

Returns:



53
54
55
# File 'lib/hqmf-parser/2.0/document.rb', line 53

def population_criteria(id)
  find(@population_criteria, :id, id)
end

#titleString

Get the title of the measure

Returns:



33
34
35
# File 'lib/hqmf-parser/2.0/document.rb', line 33

def title
  @doc.at_xpath('cda:QualityMeasureDocument/cda:title/@value', NAMESPACES).inner_text
end

#to_modelObject

Generates this classes hqmf-model equivalent



101
102
103
104
105
106
107
108
# File 'lib/hqmf-parser/2.0/document.rb', line 101

def to_model
  dcs = all_data_criteria.collect(&:to_model)
  pcs = all_population_criteria.collect(&:to_model)
  sdc = source_data_criteria.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)
end