This repository was archived by the owner on Apr 22, 2020. It is now read-only.
forked from pophealth/quality-measure-engine
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathquality_report_test.rb
More file actions
171 lines (144 loc) · 5.42 KB
/
Copy pathquality_report_test.rb
File metadata and controls
171 lines (144 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
require 'test_helper'
class QualityReportTest < MiniTest::Unit::TestCase
include QME::DatabaseAccess
def setup
load_system_js
collection_fixtures(get_db(), 'bundles')
collection_fixtures(get_db(), 'records')
collection_fixtures(get_db(), 'measures')
get_db()['query_cache'].drop()
get_db()['patient_cache'].drop()
get_db()['query_cache'].insert_one({
"measure_id" => "test2",
"sub_id" => "b",
"status" =>{"state" => "completed"},
"initialPopulation" => 4,
"result" => {
QME::QualityReport::NUMERATOR => 1,
QME::QualityReport::DENOMINATOR => 2,
QME::QualityReport::EXCLUSIONS => 1},
"effective_date" => Time.gm(2010, 9, 19).to_i}
)
get_db()['patient_cache'].insert_one({
"value" => {
QME::QualityReport::POPULATION => 0,
QME::QualityReport::DENOMINATOR => 0,
QME::QualityReport::NUMERATOR => 0,
QME::QualityReport::EXCLUSIONS => 0,
QME::QualityReport::ANTINUMERATOR => 0,
"medical_record_id" => "0616911582",
"first" => "Mary",
"last" => "Edwards",
"gender" => "F",
"birthdate" => Time.gm(1940, 9, 19).to_i,
"test_id" => nil,
"provider_performances" => nil,
"race" => {
"code" => "2106-3",
"code_set" => "CDC-RE"
},
"ethnicity" => {
"code" => "2135-2",
"code_set" => "CDC-RE"
},
"measure_id" => "test2",
"sub_id" => "b",
"effective_date" => Time.gm(2010, 9, 19).to_i,
"expired_at" => nil
}}
)
collection_fixtures(get_db(), 'delayed_backend_mongoid_jobs', '_id')
end
def test_calculated
qr = QME::QualityReport.find_or_create('test2', 'b', "effective_date" => Time.gm(2010, 9, 19).to_i)
assert qr.calculated?
qr = QME::QualityReport.find_or_create('test2', 'b', "effective_date" => Time.gm(2010, 9, 20).to_i)
assert !qr.calculated?
end
def test_result
qr = QME::QualityReport.find_or_create('test2', 'b', "effective_date" => Time.gm(2010, 9, 19).to_i)
result = qr.result
assert_equal 1, result[QME::QualityReport::NUMERATOR]
end
def test_destroy_all
QME::QualityReport.destroy_all
qr = QME::QualityReport.find_or_create('test2', 'b', "effective_date" => Time.gm(2010, 9, 19).to_i)
assert !qr.calculated?
end
def test_update_patient_results
qr = QME::QualityReport.find_or_create('test2', 'b', "effective_date" => Time.gm(2010, 9, 19).to_i)
assert qr.calculated?
assert qr.patients_cached?
QME::QualityReport.update_patient_results("0616911582")
qr = QME::QualityReport.find_or_create('test2', 'b', "effective_date" => Time.gm(2010, 9, 19).to_i)
assert !qr.calculated?
assert !qr.patients_cached?
end
def test_status
status = QME::MapReduce::MeasureCalculationJob.status('not really a job id')
assert_equal :complete, status
status = QME::MapReduce::MeasureCalculationJob.status("508aeff07042f9f88900000d")
assert_equal :queued, status
end
def test_rollup_buffering
Delayed::Worker.delay_jobs=true
assert Delayed::Worker.delay_jobs
Delayed::Job.destroy_all
QME::QualityReport.destroy_all
Mongoid.default_client["rollup_buffer"].delete_many({})
qr = QME::QualityReport.find_or_create('2E679CD2-3FEC-4A75-A75A-61403E5EFEE8', nil, "effective_date" => Time.gm(2011, 9, 19).to_i)
qr2 = QME::QualityReport.find_or_create('2E679CD2-3FEC-4A75-A75A-61403E5EFEE8', nil, {"effective_date" => Time.gm(2011, 9, 19).to_i,:filters=>{"providers"=>["a"]}})
assert !qr.calculated?
assert !qr2.calculated?
assert_equal 0, Delayed::Job.count()
assert !qr.patients_cached?
assert !qr2.patients_cached?
assert !qr.calculation_queued_or_running?
assert !qr2.calculation_queued_or_running?
qr.calculate({"oid_dictionary"=>{}},true)
assert qr.calculation_queued_or_running?
assert qr2.calculation_queued_or_running?
assert_equal 0, Mongoid.default_client["rollup_buffer"].count({})
qr2.calculate({"oid_dictionary"=>{}},true)
assert_equal 1, Mongoid.default_client["rollup_buffer"].count({})
assert_equal 1, Delayed::Job.count()
job = Delayed::Job.where({}).first
assert_equal "calculation", job.queue
job.invoke_job
job.delete
assert_equal 1, Delayed::Job.count()
job = Delayed::Job.where({}).first
assert_equal "rollup", job.queue
assert_equal 0, Mongoid.default_client["rollup_buffer"].count({})
end
def test_expire_patient_results
qr = QME::QualityReport.find_or_create(
'test2',
'b',
'effective_date' => Time.gm(2010, 9, 19).to_i
)
assert_equal 1, qr.patient_results.count
qr.expire_patient_results
assert_equal 0, qr.patient_results.count
end
def test_patient_cache_matcher
effective_date = Time.gm(2010, 9, 19).to_i
qr = QME::QualityReport.find_or_create(
'test2',
'b',
'effective_date' => effective_date
)
expected_results = {
'value.measure_id' => 'test2',
'value.sub_id' => 'b',
'value.effective_date' => effective_date,
'value.test_id' => nil,
'value.facility_id' => nil,
'value.expired_at' => nil,
'value.manual_exclusion' => {
'$in' => [nil, false]
}
}
assert_equal expected_results, qr.patient_cache_matcher
end
end