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
117 118 119 120 121 122 123 124 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 117 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 92 |
# 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_client.command(aggregate: 'measures', pipeline: pipeline).documents[0]["result"] end |
.installed ⇒ Object
109 110 111 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 109 def self.installed Measure.order_by([["id", :asc],["sub_id", :asc]]).to_a end |
Instance Method Details
#all_data_criteria ⇒ Object
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 147 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
97 98 99 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 97 def as_hqmf_model @hqmf ||= HQMF::Document.from_json(self.hqmf_document) end |
#build_pre_filters! ⇒ Object
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 216 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 184 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
139 140 141 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 139 def continuous? population_ids[MSRPOPL] end |
#display_name ⇒ Object
126 127 128 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 126 def display_name "#{self['cms_id']}/#{self['nqf_id']} - #{name}" end |
#ipp_id ⇒ Object
For submeasures, this will return something like IPP_1
176 177 178 179 180 181 182 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 176 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
105 106 107 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 105 def is_cv? ! population_ids[MSRPOPL].nil? end |
#key ⇒ Object
101 102 103 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 101 def key "#{self['id']}#{sub_id}" end |
#measure_id ⇒ Object
135 136 137 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 135 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
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 161 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
131 132 133 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 131 def set_id self.hqmf_set_id end |
#title ⇒ Object
143 144 145 |
# File 'lib/health-data-standards/models/cqm/measure.rb', line 143 def title self.name end |