Class: HealthDataStandards::CQM::PatientCache

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.smoking_gun_rational(hqmf_id, sub_ids = nil, filter = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/health-data-standards/models/cqm/patient_cache.rb', line 16

def self.smoking_gun_rational(hqmf_id, sub_ids=nil, filter ={})

  match = {"value.IPP" => {"$gt" => 0},
           "value.measure_id" => hqmf_id
  }.merge filter

  if sub_ids
    match["value.sub_id"] = {"$in" => sub_ids}
  end

  group = {"$group" => {"_id" => "$value.medical_record_id", "rational" => {"$push"=> "$value.rationale"}}}
  aggregate = self.mongo_client.command(:aggregate => 'patient_cache', :pipeline => [{"$match" =>match},group])
  aggregate_document = aggregate.documents[0]
  merged = {}
  aggregate_document["result"].each do |agg|
    mrn = agg["_id"]
    rational = {}
    merged[mrn] = rational
    agg["rational"].each do |r|
      rational.merge! r
    end
  end

  merged
end

Instance Method Details

#recordObject



12
13
14
# File 'lib/health-data-standards/models/cqm/patient_cache.rb', line 12

def record
  Record.where(:medical_record_number => value['medical_record_id'], :test_id => value["test_id"]).first
end