Class: HealthDataStandards::CQM::Measure
- Inherits:
-
Object
- Object
- HealthDataStandards::CQM::Measure
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/health-data-standards/models/cqm/measure.rb
Constant Summary collapse
- MSRPOPL =
'MSRPOPL'
Class Method Summary collapse
-
.all_by_measure ⇒ Object
Finds all measures and groups the sub measures.
- .categories(measure_properties = []) ⇒ Object
- .installed ⇒ Object
Instance Method Summary collapse
- #all_data_criteria ⇒ Object
-
#as_hqmf_model ⇒ Object
Returns the hqmf-parser’s ruby implementation of an HQMF document.
- #build_pre_filters! ⇒ Object
- #continuous? ⇒ Boolean
- #display_name ⇒ Object
-
#ipp_id ⇒ Object
For submeasures, this will return something like IPP_1.
- #is_cv? ⇒ Boolean
- #key ⇒ Object
- #measure_id ⇒ Object
-
#prefilter_query!(effective_time) ⇒ Object
Builds the query hash to pass to MongoDB Calling this method will create Prefilters if they do not exist on the measure.
- #set_id ⇒ Object
- #title ⇒ Object
Class Method Details
.all_by_measure ⇒ Object
Finds all measures and groups the sub measures
116 117 118 119 120 121 122 123 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 116 def self.all_by_measure reduce = 'function(obj,prev) { if (obj.sub_id != null) prev.subs.push({id : obj.id + obj.sub_id, name : obj.subtitle}); }' self.moped_session.command( :group=> {:ns=>"measures", :key => {:id=>1, :name=>1, :category=>1}, :initial => {:subs => []}, "$reduce" => reduce})["retval"] end |
.categories(measure_properties = []) ⇒ Object
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 86 87 88 89 90 91 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 55 def self.categories(measure_properties = []) measure_properties = Array(measure_properties).map(&:to_s) | %w( name description nqf_id cms_id hqmf_id continuous_variable episode_of_care ) pipeline = [] pipeline << {'$group' => measure_properties.inject({ '_id' => "$id", 'subs' => {'$push' => {"sub_id" => "$sub_id", "short_subtitle" => "$short_subtitle"}}, 'sub_ids' => {'$push' => "$sub_id"}, 'category' => {'$first' => "$category"} }) do |h, prop| h[prop] = {"$first" => "$#{prop}"} h end } pipeline << {'$group' => { _id: "$category", measures: { '$push' => measure_properties.inject({ 'id' => "$_id", 'hqmf_id' => "$_id", 'subs' => "$subs", 'sub_ids' => "$sub_ids" }) do |h, prop| h[prop] = "$#{prop}" h end } }} pipeline << {'$project' => {'category' => '$_id', 'measures' => 1, '_id' => 0}} pipeline << {'$sort' => {"category" => 1}} Mongoid.default_session.command(aggregate: 'measures', pipeline: pipeline)['result'] end |
.installed ⇒ Object
108 109 110 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 108 def self.installed Measure.order_by([["id", :asc],["sub_id", :asc]]).to_a end |
Instance Method Details
#all_data_criteria ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 146 def all_data_criteria return @crit if @crit @crit = [] self.data_criteria.each do |dc| dc.each_pair do |k,v| @crit << HQMF::DataCriteria.from_json(k,v) end end @crit end |
#as_hqmf_model ⇒ Object
Returns the hqmf-parser’s ruby implementation of an HQMF document. Rebuild from population_criteria, data_criteria, and measure_period JSON
96 97 98 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 96 def as_hqmf_model @hqmf ||= HQMF::Document.from_json(self.hqmf_document) end |
#build_pre_filters! ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 183 def build_pre_filters! dc = self.data_criteria.inject({}) do |all_dc, single_dc| key = single_dc.keys.first value = single_dc.values.first all_dc[key] = value all_dc end dc.each_pair do |criteria_name, data_criteria| if data_criteria['definition'] == 'patient_characteristic_birthdate' if data_criteria_in_population?(self.ipp_id, criteria_name) prefilter = Prefilter.new(record_field: 'birthdate', effective_time_based: true) if data_criteria['temporal_references'] data_criteria['temporal_references'].each do |tr| if tr['type'] == 'SBS' && tr['reference'] == 'MeasurePeriod' years = nil if tr['range']['high'] prefilter.comparison = '$gte' years = tr['range']['high']['value'].to_i elsif tr['range']['low'] prefilter.comparison = '$lte' years = tr['range']['low']['value'].to_i end prefilter.effective_time_offset = 1 + years self.prefilters << prefilter end end end end end end end |
#continuous? ⇒ Boolean
138 139 140 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 138 def continuous? population_ids[MSRPOPL] end |
#display_name ⇒ Object
125 126 127 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 125 def display_name "#{self['cms_id']}/#{self['nqf_id']} - #{name}" end |
#ipp_id ⇒ Object
For submeasures, this will return something like IPP_1
175 176 177 178 179 180 181 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 175 def ipp_id ipp_hqmf_id = self.population_ids['IPP'] pop_id, pop_criteria = hqmf_document['population_criteria'].find do |population_id, population_criteria| population_criteria['hqmf_id'] == ipp_hqmf_id end pop_id end |
#is_cv? ⇒ Boolean
104 105 106 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 104 def is_cv? ! population_ids[MSRPOPL].nil? end |
#key ⇒ Object
100 101 102 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 100 def key "#{self['id']}#{sub_id}" end |
#measure_id ⇒ Object
134 135 136 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 134 def measure_id self['id'] end |
#prefilter_query!(effective_time) ⇒ Object
Builds the query hash to pass to MongoDB Calling this method will create Prefilters if they do not exist on the measure
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 160 def prefilter_query!(effective_time) self.build_pre_filters! if self.prefilters.empty? if self.prefilters.count == 1 self.prefilters.first.build_query_hash(effective_time) else self.prefilters.inject({}) do |query, pf| query.merge(pf.build_query_hash(effective_time)) do |key, new_val, old_val| new_val.merge(old_val) end end end end |
#set_id ⇒ Object
130 131 132 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 130 def set_id self.hqmf_set_id end |
#title ⇒ Object
142 143 144 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 142 def title self.name end |