Class: HQMF::Document

Inherits:
Object
  • Object
show all
Includes:
Conversion::Utilities
Defined in:
lib/hqmf-model/document.rb

Overview

Class representing an HQMF document

Constant Summary collapse

MEASURE_PERIOD_ID =
"MeasurePeriod"
STRATIFIED_POPULATION_TEMPLATE_ID =
'2.16.840.1.113883.3.100.1.2'
STRATIFIED_POPULATION_TEMPLATE_TITLE =
'Stratified'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(id, hqmf_id, hqmf_set_id, hqmf_version_number, cms_id, title, description, population_criteria, data_criteria, source_data_criteria, attributes, measure_period, populations = nil, populations_cql_map = nil, cql_measure_library = nil, observations = nil) ⇒ Document

Create a new HQMF::Document which can be converted to JavaScript

Parameters:

  • id (String)
  • hqmf_id (String)
  • hqmf_set_id (String)
  • hqmf_version_number (String)
  • title (String)
  • description (String)
  • population_criteria (Array#PopulationCritera)
  • data_criteria (Array#DataCriteria)
  • source_data_criteria (Array#DataCriteria)
  • attributes (Array#Attribute)
  • populations (Array#Hash) (defaults to: nil)
  • measure_period (Range)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hqmf-model/document.rb', line 27

def initialize(id, hqmf_id, hqmf_set_id, hqmf_version_number, cms_id, title, description, population_criteria, data_criteria, source_data_criteria, attributes, measure_period, populations=nil, populations_cql_map=nil, cql_measure_library=nil, observations=nil)
  @id = id
  @hqmf_id = hqmf_id
  @hqmf_set_id = hqmf_set_id
  @hqmf_version_number = hqmf_version_number
  @cms_id = cms_id
  @title = title
  @description = description
  @population_criteria = population_criteria
  @data_criteria = data_criteria
  @source_data_criteria = source_data_criteria
  @attributes = attributes
  @populations = populations || [
    {
      HQMF::PopulationCriteria::IPP => HQMF::PopulationCriteria::IPP,
      HQMF::PopulationCriteria::DENOM => HQMF::PopulationCriteria::DENOM,
      HQMF::PopulationCriteria::NUMER => HQMF::PopulationCriteria::NUMER,
      HQMF::PopulationCriteria::DENEXCEP => HQMF::PopulationCriteria::DENEXCEP,
      HQMF::PopulationCriteria::DENEX => HQMF::PopulationCriteria::DENEX
    }
  ]
  @measure_period = measure_period
  @populations_cql_map = populations_cql_map
  @cql_measure_library = cql_measure_library
  @observations = observations
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def attributes
  @attributes
end

#cms_idObject (readonly)

Returns the value of attribute cms_id.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def cms_id
  @cms_id
end

#cql_measure_libraryObject (readonly)

Returns the value of attribute cql_measure_library.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def cql_measure_library
  @cql_measure_library
end

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def description
  @description
end

#hqmf_idObject (readonly)

Returns the value of attribute hqmf_id.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def hqmf_id
  @hqmf_id
end

#hqmf_set_idObject (readonly)

Returns the value of attribute hqmf_set_id.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def hqmf_set_id
  @hqmf_set_id
end

#hqmf_version_numberObject (readonly)

Returns the value of attribute hqmf_version_number.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def hqmf_version_number
  @hqmf_version_number
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def id
  @id
end

#measure_periodObject (readonly)

Returns the value of attribute measure_period.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def measure_period
  @measure_period
end

#observationsObject (readonly)

Returns the value of attribute observations.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def observations
  @observations
end

#populationsObject (readonly)

Returns the value of attribute populations.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def populations
  @populations
end

#populations_cql_mapObject (readonly)

Returns the value of attribute populations_cql_map.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def populations_cql_map
  @populations_cql_map
end

#source_data_criteriaObject (readonly)

Returns the value of attribute source_data_criteria.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def source_data_criteria
  @source_data_criteria
end

#titleObject (readonly)

Returns the value of attribute title.



12
13
14
# File 'lib/hqmf-model/document.rb', line 12

def title
  @title
end

Class Method Details

.from_json(json) ⇒ Object

Create a new HQMF::Document from a JSON hash keyed with symbols



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/hqmf-model/document.rb', line 55

def self.from_json(json)
  id = json["id"]
  hqmf_id = json["hqmf_id"]
  hqmf_set_id = json["hqmf_set_id"]
  hqmf_version_number = json["hqmf_version_number"]
  title = json["title"]
  description = json["description"]
  cms_id = json["cms_id"]
  
  population_criterias = []
  json["population_criteria"].each do |key, population_criteria|
    population_criterias << HQMF::PopulationCriteria.from_json(key.to_s, population_criteria)
  end if json['population_criteria']

  data_criterias = []
  json["data_criteria"].each do |key, data_criteria|
    data_criterias << HQMF::DataCriteria.from_json(key.to_s, data_criteria)
  end

  source_data_criterias = []
  json["source_data_criteria"].each do |key, data_criteria|
    source_data_criterias << HQMF::DataCriteria.from_json(key.to_s, data_criteria)
  end
  
  populations = json["populations"] if json["populations"]

  attributes = json["attributes"].map {|attribute| HQMF::Attribute.from_json(attribute)} if json["attributes"]

  measure_period = HQMF::Range.from_json(json["measure_period"]) if json["measure_period"]
  HQMF::Document.new(id, hqmf_id, hqmf_set_id, hqmf_version_number, cms_id, title, description, population_criterias, data_criterias, source_data_criterias, attributes, measure_period,populations)
end

Instance Method Details

#all_code_set_oidsObject



149
150
151
# File 'lib/hqmf-model/document.rb', line 149

def all_code_set_oids
  (@data_criteria.map {|d| d.all_code_set_oids }).flatten.compact.uniq
end

#all_data_criteriaArray

Get all the data criteria defined by the measure

Returns:

  • (Array)

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



145
146
147
# File 'lib/hqmf-model/document.rb', line 145

def all_data_criteria
  @data_criteria
end

#all_population_criteriaArray

Get all the population criteria defined by the measure

Returns:

  • (Array)

    an array of HQMF::PopulationCriteria



124
125
126
# File 'lib/hqmf-model/document.rb', line 124

def all_population_criteria
  @population_criteria
end

#attributes_for_code(code, code_system) ⇒ Array#Attribute

Get specific attributes by code.

Parameters:

  • code (String)

    the attribute code

  • code_system (String)

    the attribute code system

Returns:

  • (Array#Attribute)

    the matching attributes, raises an Exception if not found



192
193
194
# File 'lib/hqmf-model/document.rb', line 192

def attributes_for_code(code, code_system)
  @attributes.find_all { |e| e.send(:code) == code && e.send(:code_obj).send(:system) == code_system }
end

#backfill_patient_characteristics_with_codes(codes) ⇒ Object

patient characteristics data criteria such as GENDER require looking at the codes to determine if the measure is interested in Males or Females. This process is awkward, and thus is done as a separate step after the document has been converted.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/hqmf-model/document.rb', line 206

def backfill_patient_characteristics_with_codes(codes)
  
  [].concat(self.all_data_criteria).concat(self.source_data_criteria).each do |data_criteria|
    if (data_criteria.type == :characteristic and !data_criteria.property.nil?)
      if (codes)
        value_set = codes[data_criteria.code_list_id]
        puts "\tno value set for unknown patient characteristic: #{data_criteria.id}" unless value_set
      else
        puts "\tno code set to back fill: #{data_criteria.title}"
        next
      end
      
      if (data_criteria.property == :gender)
        next if value_set.nil?
        key = value_set.keys[0]
        data_criteria.value = HQMF::Coded.new('CD','Administrative Sex',value_set[key].first)
      else
        data_criteria.inline_code_list = value_set
      end
      
    elsif (data_criteria.type == :characteristic)
      if (codes)
        value_set = codes[data_criteria.code_list_id]
        if (value_set)
          # this is looking for a birthdate characteristic that is set as a generic characteristic but points to a loinc code set
          if (value_set['LOINC'] and value_set['LOINC'].first == '21112-8')
            data_criteria.definition = 'patient_characteristic_birthdate'
          end
          # this is looking for a gender characteristic that is set as a generic characteristic
          gender_key = (value_set.keys.select {|set| set == 'Administrative Sex' || set == 'AdministrativeSex'}).first
          if (gender_key and ['M','F'].include? value_set[gender_key].first)
            data_criteria.definition = 'patient_characteristic_gender'
            data_criteria.value = HQMF::Coded.new('CD','Gender',value_set[gender_key].first)
          end
        end
      end

    end
  end
end

#data_criteria(id) ⇒ HQMF::DataCriteria

Get a specific data criteria by id.

Parameters:

  • id (String)

    the data criteria identifier

Returns:



199
200
201
# File 'lib/hqmf-model/document.rb', line 199

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

#find_population_by_type(type) ⇒ Object



139
140
141
# File 'lib/hqmf-model/document.rb', line 139

def find_population_by_type(type)
  find(@population_criteria, :type, type)
end

#is_cv?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/hqmf-model/document.rb', line 135

def is_cv?
  find(@population_criteria, :type, HQMF::PopulationCriteria::MSRPOPL)
end

#population_criteria(id) ⇒ HQMF::PopulationCriteria

Get a specific population criteria by id.

Parameters:

  • id (String)

    the population identifier

Returns:



131
132
133
# File 'lib/hqmf-model/document.rb', line 131

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

#referenced_data_criteriaArray

Returns an array of HQMF::DataCriteria ids that are actually used in the measure.

Returns:

  • (Array)

    an array of HQMF::DataCriteria ids that are actually used in the measure



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/hqmf-model/document.rb', line 169

def referenced_data_criteria
  data_criteria_ids = []
  @population_criteria.each do |population|
    data_criteria_ids.concat(population.referenced_data_criteria)
  end
  references = []
  data_criteria_ids.each do |id|
    dc = data_criteria(id)
    references << id
    from_dc = dc.referenced_data_criteria(self)
    references.concat(from_dc)
  end
  used_dc = []
  references.uniq.each do |id|
    used_dc << data_criteria(id)
  end
  used_dc
end

#specific_occurrence_source_data_criteria(force_sources = nil) ⇒ Array

Get the source data criteria that are specific occurrences

Returns:

  • (Array)

    an array of HQMF::DataCriteria describing the data elements used by the measure that are specific occurrences



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/hqmf-model/document.rb', line 155

def specific_occurrence_source_data_criteria(force_sources=nil)
  return [] if @source_data_criteria.nil?
  matching = @source_data_criteria.select {|dc| !dc.specific_occurrence.nil?}

  if force_sources
    existing = matching.map(&:id)
    matching.concat @source_data_criteria.select {|dc| !existing.include?(dc.id) && force_sources.include?(dc.id)} 
  end

  matching
end

#to_jsonObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/hqmf-model/document.rb', line 87

def to_json
  json = build_hash(self, [:id, :hqmf_id, :hqmf_set_id, :hqmf_version_number, :title, :description, :cms_id])

  json[:population_criteria] = {}
  @population_criteria.each do |population|
    json[:population_criteria].merge! population.to_json
  end

  json[:data_criteria] = {}
  @data_criteria.each do |data|
    json[:data_criteria].merge! data.to_json
  end

  json[:source_data_criteria] = {}
  @source_data_criteria.each do |data|
    json[:source_data_criteria].merge! data.to_json
  end
  
  x = nil
  json[:attributes] = x if x = json_array(@attributes)
  
  json[:populations] = @populations
  
  json[:populations_cql_map] = @populations_cql_map

  json[:observations] = @observations

  json[:cql_measure_library] = @cql_measure_library

  json[:measure_period] = @measure_period.to_json

  json
end