15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/health-data-standards/models/cqm/patient_cache.rb', line 15
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_session.command(:aggregate => 'patient_cache', :pipeline => [{"$match" =>match},group])
merged = {}
aggregate["result"].each do |agg|
mrn = agg["_id"]
rational = {}
merged[mrn] = rational
agg["rational"].each do |r|
rational.merge! r
end
end
merged
end
|