Class: HealthDataStandards::CQM::Measure

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/health-data-standards/models/cqm/measure.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.calculate_smoking_gun_data(bundle_id, hqmf_id, patient_cache_filter = {}) ⇒ Object

Calculate the smoking gun data for the given hqmf_id with the given patient_cache_filter The filter will allow us to segment the cache by things like test_id required for Cypress.



79
80
81
82
83
84
85
86
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
120
121
122
123
# File 'lib/health-data-standards/models/cqm/measure.rb', line 79

def self.calculate_smoking_gun_data(bundle_id, hqmf_id, patient_cache_filter={})
  population_keys = ('a'..'zz').to_a
  values = {}
  measure = Measure.top_level.where({hqmf_id: hqmf_id, bundle_id: bundle_id}).first
  sub_ids = []
  hqmf_measure = measure.as_hqmf_model
  population_codes = []
  if  hqmf_measure.populations.length == 1
    sub_ids = nil
    population = hqmf_measure.populations[0]
    HQMF::PopulationCriteria::ALL_POPULATION_CODES.each do |code|
          population_codes <<  population[code] if population[code]
    end
  else 
    #Do not bother with populaions that contain stratifications
    hqmf_measure.populations.each_with_index do |population,index|
      if population["stratification"].nil?
        sub_ids << population_keys[index] 
        HQMF::PopulationCriteria::ALL_POPULATION_CODES.each do |code|
          population_codes <<  population[code] if population[code]
        end
      end
    end
  end

  population_codes.uniq!

  rationals = PatientCache.smoking_gun_rational(measure.hqmf_id,sub_ids,patient_cache_filter)
  rationals.each_pair do |mrn,rash|
    values[mrn] = []
    population_codes.each do |pop_code|
     # if (population[pop_code])
        population_criteria = hqmf_measure.population_criteria(pop_code)
        if population_criteria.preconditions
          array = []
         
          parent = population_criteria.preconditions[0]
          values[mrn].concat self.loop_preconditions(hqmf_measure, parent, rash)
        end # end  population_criteria.preconditions
      #end # end (population[pop_code])
    end # population_codes
    values[mrn].uniq!
  end
  values
end

.categoriesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/health-data-standards/models/cqm/measure.rb', line 43

def self.categories
  pipeline = []
  pipeline << {'$group' => {_id: "$id", 
                            name: {"$first" => "$name"},
                            description: {"$first" => "$description"},
                            sub_ids: {'$push' => "$sub_id"},
                            subs: {'$push' => {"sub_id" => "$sub_id", "short_subtitle" => "$short_subtitle"}},
                            category: {'$first' => "$category"}}}

  pipeline << {'$group' => {_id: "$category",
                            measures: {'$push' => {"id" => "$_id", 
                                       'name' => "$name",
                                       'description' => "$description",
                                       'subs' => "$subs",
                                       'sub_ids' => "$sub_ids"
                                      }}}}

  pipeline << {'$project' => {'category' => '$_id', 'measures' => 1, '_id' => 0}}
  
  pipeline << {'$sort' => {"category" => 1}}
  Mongoid.default_session.command(aggregate: 'measures', pipeline: pipeline)['result']
end

Instance Method Details

#as_hqmf_modelObject

Returns the hqmf-parser’s ruby implementation of an HQMF document. Rebuild from population_criteria, data_criteria, and measure_period JSON



69
70
71
# File 'lib/health-data-standards/models/cqm/measure.rb', line 69

def as_hqmf_model
  @hqmf ||=  HQMF::Document.from_json(self.hqmf_document)
end

#smoking_gun_data(patient_cache_filter = {}) ⇒ Object



73
74
75
# File 'lib/health-data-standards/models/cqm/measure.rb', line 73

def smoking_gun_data(patient_cache_filter={})
  ::Measure.calculate_smoking_gun_data(self["bundle_id"], self.hqmf_id, patient_cache_filter)
end