Skip to content

Commit bafcf05

Browse files
committed
POC-341: Patients requiring VL
1 parent 737cfd2 commit bafcf05

File tree

3 files changed

+47
-97
lines changed

3 files changed

+47
-97
lines changed

app/reporting-framework/json-reports/clinical-reminder-report.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"alias": "needs_vl_coded",
127127
"expressionType": "simple_expression",
128128
"expressionOptions": {
129-
"expression": "CASE WHEN (ls.cur_arv_meds IS NULL) THEN 0 WHEN (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) > 3) AND ls.vl_1 > 1000 AND ls.arv_start_date < ls.vl_1_date THEN 1 WHEN ls.vl_1 > 200 AND (TIMESTAMPDIFF(MONTH,ls.vl_1_date,DATE('{referenceDate}')) > 3) THEN 2 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') >= 12) AND (ls.vl_2 IS NULL) THEN 3 WHEN (ls.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 6) THEN 4 WHEN (t1.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND ls.vl_1 >= 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 3) THEN 5 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') = 3) AND (ls.vl_1_date IS NULL) THEN 6 WHEN (ls.cur_arv_meds <> ls.prev_arv_meds) AND ls.prev_arv_meds IS NOT NULL THEN 7 WHEN ls.vl_1 < 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) >= 12) THEN 8 ELSE 0 END"
129+
"expression": "CASE WHEN (ls.cur_arv_meds IS NULL) THEN 0 WHEN (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) > 3) AND ls.vl_1 > 1000 AND ls.arv_start_date < ls.vl_1_date THEN 1 WHEN ls.vl_1 > 200 AND (TIMESTAMPDIFF(MONTH,ls.vl_1_date,DATE('{referenceDate}')) > 3) THEN 2 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') >= 12) AND (ls.vl_2 IS NULL) THEN 3 WHEN (ls.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 6) THEN 4 WHEN (t1.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND ls.vl_1 >= 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 3) THEN 5 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') = 3) AND (ls.vl_1_date IS NULL) THEN 6 WHEN (ls.cur_arv_meds <> ls.prev_arv_meds) AND ls.prev_arv_meds IS NOT NULL AND TIMESTAMPDIFF(MONTH, ls.encounter_datetime, DATE('{referenceDate}')) >= 3 THEN 7 WHEN ls.vl_1 < 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) >= 12) THEN 8 ELSE 0 END"
130130
}
131131
},
132132
{

app/reporting-framework/json-reports/labs-report-base.json

+28-70
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,46 @@
77
"sources": [
88
{
99
"table": "etl.flat_hiv_summary_v15b",
10-
"alias": "t2"
10+
"alias": "fhs"
1111
},
1212
{
13-
"table": "etl.flat_patient_identifiers_v1",
14-
"alias": "flat_identifiers",
15-
"join": {
16-
"type": "LEFT",
17-
"joinCondition": "t2.person_id = flat_identifiers.patient_id"
18-
}
19-
},
20-
{
21-
"table": "amrs.location",
22-
"alias": "l",
13+
"table": "(SELECT a.person_id, MAX(encounter_id) AS max_encounter_id FROM etl.flat_hiv_summary_v15b a LEFT JOIN amrs.person p ON p.person_id = a.person_id WHERE p.dead = 0 and p.birthdate is not null GROUP BY a.person_id)",
14+
"alias": "max_encounters",
2315
"join": {
2416
"type": "INNER",
25-
"joinCondition": "t2.location_uuid = l.uuid"
17+
"joinCondition": "fhs.person_id = max_encounters.person_id AND fhs.encounter_id = max_encounters.max_encounter_id"
2618
}
2719
},
2820
{
2921
"table": "amrs.person",
30-
"alias": "t3",
22+
"alias": "p",
3123
"join": {
3224
"type": "INNER",
33-
"joinCondition": "t3.person_id = t2.person_id"
34-
}
35-
},
36-
{
37-
"table": "amrs.person_attribute",
38-
"alias": "contacts",
39-
"join": {
40-
"type": "LEFT",
41-
"joinCondition": "t2.person_id = contacts.person_id AND (contacts.voided IS NULL || contacts.voided = 0) AND contacts.person_attribute_type_id in (10, 48)"
25+
"joinCondition": "p.person_id = fhs.person_id"
4226
}
4327
},
4428
{
45-
"table": "amrs.encounter_type",
46-
"alias": "et",
29+
"table": "etl.flat_patient_identifiers_v1",
30+
"alias": "flat_identifiers",
4731
"join": {
4832
"type": "LEFT",
49-
"joinCondition": "t2.encounter_type = et.encounter_type_id"
33+
"joinCondition": "fhs.person_id = flat_identifiers.patient_id"
5034
}
5135
},
5236
{
53-
"table": "amrs.person_address",
54-
"alias": "pa",
37+
"table": "amrs.location",
38+
"alias": "l",
5539
"join": {
56-
"type": "LEFT",
57-
"joinCondition": "t2.person_id = pa.person_id"
40+
"type": "INNER",
41+
"joinCondition": "fhs.location_uuid = l.uuid"
5842
}
5943
}
6044
],
6145
"columns": [
6246
{
6347
"type": "simple_column",
6448
"alias": "person_id",
65-
"column": "t2.person_id"
66-
},
67-
{
68-
"type": "derived_column",
69-
"alias": "needs_vl_in_period",
70-
"expressionType": "simple_expression",
71-
"expressionOptions": {
72-
"expression": "if(case when (t2.cur_arv_meds is not null and t2.vl_1 > 1000) and (timestampdiff(day,t2.vl_1_date, '{reportMonth}') >= 90) then true when (timestampdiff(month,t2.arv_start_date, '{reportMonth}') <= 12) and (t2.vl_1_date is null or timestampdiff(month,t2.vl_1_date, '{reportMonth}') >= 6) and (timestampdiff(month,t2.arv_start_date, '{reportMonth}')>=6) then true when (timestampdiff(month,t2.arv_start_date, '{reportMonth}') >= 12) and (t2.vl_1_date is null or timestampdiff(month,t2.vl_1_date, '{reportMonth}') >= 12) then true else false end,1,0)"
73-
}
49+
"column": "fhs.person_id"
7450
},
7551
{
7652
"type": "simple_column",
@@ -89,80 +65,62 @@
8965
},
9066
{
9167
"type": "simple_column",
92-
"alias": "location",
93-
"column": "l.name"
68+
"alias": "location_id",
69+
"column": "fhs.location_id"
9470
},
9571
{
9672
"type": "simple_column",
97-
"alias": "location_id",
98-
"column": "t2.location_id"
73+
"alias": "location",
74+
"column": "l.name"
9975
},
10076
{
10177
"type": "simple_column",
10278
"alias": "location_uuid",
103-
"column": "t2.location_uuid"
79+
"column": "fhs.location_uuid"
10480
},
10581
{
10682
"type": "simple_column",
10783
"alias": "encounter_datetime",
108-
"column": "t2.encounter_datetime"
84+
"column": "fhs.encounter_datetime"
10985
},
11086
{
11187
"type": "simple_column",
11288
"alias": "month",
113-
"column": "MONTH(t2.encounter_datetime)"
89+
"column": "MONTH(fhs.encounter_datetime)"
11490
},
11591
{
11692
"type": "simple_column",
11793
"alias": "reporting_month",
118-
"column": "date_format(t2.encounter_datetime, '%m/%Y')"
94+
"column": "date_format(fhs.encounter_datetime, '%m/%Y')"
11995
},
12096
{
12197
"type": "simple_column",
12298
"alias": "year",
123-
"column": "YEAR(t2.encounter_datetime)"
124-
},
125-
{
126-
"type": "derived_column",
127-
"alias": "phone_number",
128-
"expressionType": "simple_expression",
129-
"expressionOptions": {
130-
"expression": " GROUP_CONCAT(DISTINCT contacts.value SEPARATOR ', ')"
131-
}
99+
"column": "YEAR(fhs.encounter_datetime)"
132100
},
133101
{
134102
"type": "simple_column",
135103
"alias": "latest_rtc_date",
136-
"column": "date_format(t2.rtc_date, '%Y-%m-%d')"
137-
},
138-
{
139-
"type": "simple_column",
140-
"alias": "last_appointment",
141-
"column": "CONCAT(COALESCE(DATE_FORMAT(t2.encounter_datetime, '%Y-%m-%d'),''),' ',COALESCE(et.name, ''))"
104+
"column": "date_format(fhs.rtc_date, '%Y-%m-%d')"
142105
},
143106
{
144107
"type": "simple_column",
145108
"alias": "cur_meds",
146-
"column": "t2.cur_arv_meds"
109+
"column": "fhs.cur_arv_meds"
147110
}
148111
],
149112
"filters": {
150113
"conditionJoinOperator": "and",
151114
"conditions": [
152115
{
153116
"filterType": "tableColumns",
154-
"conditionExpression": "(t2.next_clinical_datetime_hiv is null or date(t2.next_clinical_datetime_hiv) > ?)",
155-
"parameterName": "reportMonth"
156-
},
157-
{
158-
"filterType": "tableColumns",
159-
"conditionExpression": "t2.location_uuid in ?",
117+
"conditionExpression": "fhs.location_uuid in ? AND fhs.transfer_out is null AND fhs.out_of_care is null",
160118
"parameterName": "locationUuids"
161119
},
162120
{
163121
"filterType": "tableColumns",
164-
"conditionExpression": "coalesce(t2.death_date, t2.out_of_care) is null",
165-
"parameterName": ""
122+
"conditionExpression": "(TIMESTAMPDIFF(YEAR, p.birthdate, DATE('{reportMonth}')) BETWEEN 0 AND 24 AND ((TIMESTAMPDIFF(MONTH, fhs.arv_start_date, DATE('{reportMonth}')) >= 3 AND fhs.vl_1 IS NULL AND fhs.arv_start_date) OR (TIMESTAMPDIFF(MONTH, fhs.vl_1_date, '{reportMonth}') >= 6 AND fhs.vl_1 IS NOT NULL AND fhs.vl_1_date IS NOT NULL))) OR (TIMESTAMPDIFF(YEAR, p.birthdate, DATE('{reportMonth}')) >= 25 AND ((TIMESTAMPDIFF(MONTH, fhs.arv_start_date, DATE('{reportMonth}')) >= 3 AND fhs.arv_start_date IS NOT NULL AND fhs.vl_1 IS NULL) OR (TIMESTAMPDIFF(MONTH, fhs.arv_start_date, DATE('{reportMonth}')) >= 12 AND fhs.arv_start_date IS NOT NULL AND fhs.vl_1 IS NOT NULL AND fhs.vl_2 IS NULL) OR (TIMESTAMPDIFF(MONTH, fhs.vl_1_date, DATE('{reportMonth}')) >= 12 AND fhs.vl_1 IS NOT NULL AND fhs.vl_2 IS NOT NULL AND fhs.vl_1_date IS NOT NULL AND fhs.vl_1 < 200) OR (TIMESTAMPDIFF(MONTH, fhs.vl_1_date, DATE('{reportMonth}')) >= 3 AND fhs.vl_1 IS NOT NULL AND fhs.vl_2 IS NOT NULL AND fhs.vl_1_date IS NOT NULL AND fhs.vl_1 >= 200) OR ((fhs.is_pregnant = 1 OR fhs.is_mother_breastfeeding = 1) AND TIMESTAMPDIFF(MONTH, fhs.vl_1_date, DATE('{reportMonth}')) >= 6 AND fhs.vl_1_date IS NOT NULL))) OR (fhs.prev_arv_meds <> fhs.cur_arv_meds AND TIMESTAMPDIFF(MONTH, fhs.encounter_datetime, DATE('{reportMonth}')) >= 3)",
123+
"parameterName": "reportMonth"
166124
}
167125
]
168126
}

app/reporting-framework/json-reports/patients-requiring-viral-load-template.json

+18-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"table": "amrs.person_name",
1313
"alias": "person_name",
1414
"join": {
15-
"type": "INNER",
15+
"type": "LEFT",
1616
"joinCondition": "t1.person_id = person_name.person_id AND (person_name.voided IS NULL || person_name.voided = 0) AND person_name.preferred = 1"
1717
}
1818
},
@@ -32,20 +32,12 @@
3232
"joinCondition": "t1.person_id = contact.person_id AND (contact.voided IS NULL || contact.voided = 0) AND contact.person_attribute_type_id in (10, 48)"
3333
}
3434
},
35-
{
36-
"table": "etl.flat_hiv_summary_v15b",
37-
"alias": "fhsh",
38-
"join": {
39-
"type": "LEFT",
40-
"joinCondition": "t1.person_id = fhsh.person_id AND fhsh.next_clinical_location_id IS NULL AND fhsh.encounter_type NOT IN (99999) "
41-
}
42-
},
4335
{
4436
"table": "amrs.encounter_type",
4537
"alias": "ety",
4638
"join": {
4739
"type": "LEFT",
48-
"joinCondition": "fhsh.encounter_type = ety.encounter_type_id"
40+
"joinCondition": "fhs.encounter_type = ety.encounter_type_id"
4941
}
5042
},
5143
{
@@ -107,39 +99,39 @@
10799
"alias": "has_pending_vl_test",
108100
"expressionType": "simple_expression",
109101
"expressionOptions": {
110-
"expression": "case when (timestampdiff(day,t2.vl_order_date,now()) between 0 and 14) and (t2.vl_1_date is null or t2.vl_order_date > t2.vl_1_date) then true else false end"
102+
"expression": "case when (timestampdiff(day,fhs.vl_order_date,now()) between 0 and 14) and (fhs.vl_1_date is null or fhs.vl_order_date > fhs.vl_1_date) then true else false end"
111103
}
112104
},
113105
{
114106
"type": "derived_column",
115107
"alias": "current_vl",
116108
"expressionType": "simple_expression",
117109
"expressionOptions": {
118-
"expression": "t2.vl_1 "
110+
"expression": "fhs.vl_1 "
119111
}
120112
},
121113
{
122114
"type": "derived_column",
123115
"alias": "current_vl_date",
124116
"expressionType": "simple_expression",
125117
"expressionOptions": {
126-
"expression": "date_format(t2.vl_1_date,'%d-%m-%Y')"
118+
"expression": "date_format(fhs.vl_1_date,'%d-%m-%Y')"
127119
}
128120
},
129121
{
130122
"type": "derived_column",
131123
"alias": "last_vl_order_date",
132124
"expressionType": "simple_expression",
133125
"expressionOptions": {
134-
"expression": "date_format(t2.vl_order_date,'%d-%m-%Y')"
126+
"expression": "date_format(fhs.vl_order_date,'%d-%m-%Y')"
135127
}
136128
},
137129
{
138130
"type": "derived_column",
139131
"alias": "days_since_last_order",
140132
"expressionType": "simple_expression",
141133
"expressionOptions": {
142-
"expression": "timestampdiff(day, t2.vl_order_date, now())"
134+
"expression": "timestampdiff(day, fhs.vl_order_date, now())"
143135
}
144136
},
145137
{
@@ -153,12 +145,12 @@
153145
{
154146
"type": "simple_column",
155147
"alias": "latest_rtc_date",
156-
"column": "date_format(fhsh.rtc_date, '%Y-%m-%d')"
148+
"column": "date_format(fhs.rtc_date, '%Y-%m-%d')"
157149
},
158150
{
159151
"type": "simple_column",
160152
"alias": "latest_vl",
161-
"column": "fhsh.vl_1"
153+
"column": "fhs.vl_1"
162154
},
163155
{
164156
"type": "derived_column",
@@ -167,19 +159,19 @@
167159
"expressionOptions": {
168160
"caseOptions": [
169161
{
170-
"condition": "fhsh.vl_1 < 50",
162+
"condition": "fhs.vl_1 < 50",
171163
"value": "LDL"
172164
},
173165
{
174-
"condition": "(fhsh.vl_1 >= 50 and fhsh.vl_1 < 200)",
166+
"condition": "(fhs.vl_1 >= 50 and fhs.vl_1 < 200)",
175167
"value": "Low Risk Low Level Viremia"
176168
},
177169
{
178-
"condition": "(fhsh.vl_1 >= 200 and fhsh.vl_1 < 1000)",
170+
"condition": "(fhs.vl_1 >= 200 and fhs.vl_1 < 1000)",
179171
"value": "High Risk Low Level Viremia"
180172
},
181173
{
182-
"condition": "(fhsh.vl_1 > 1000)",
174+
"condition": "(fhs.vl_1 > 1000)",
183175
"value": "Suspected Treatment Failure"
184176
}
185177
]
@@ -188,27 +180,27 @@
188180
{
189181
"type": "simple_column",
190182
"alias": "latest_vl_date",
191-
"column": "date_format(fhsh.vl_1_date, '%Y-%m-%d')"
183+
"column": "date_format(fhs.vl_1_date, '%Y-%m-%d')"
192184
},
193185
{
194186
"type": "simple_column",
195187
"alias": "last_appointment",
196-
"column": "CONCAT(COALESCE(DATE_FORMAT(fhsh.encounter_datetime, '%Y-%m-%d'),''),' ',COALESCE(ety.name, ''))"
188+
"column": "CONCAT(COALESCE(DATE_FORMAT(fhs.encounter_datetime, '%Y-%m-%d'),''),' ',COALESCE(ety.name, ''))"
197189
},
198190
{
199191
"type": "simple_column",
200192
"alias": "cur_meds",
201-
"column": "fhsh.cur_arv_meds"
193+
"column": "fhs.cur_arv_meds"
202194
},
203195
{
204196
"type": "simple_column",
205197
"alias": "previous_vl",
206-
"column": "fhsh.vl_2"
198+
"column": "fhs.vl_2"
207199
},
208200
{
209201
"type": "simple_column",
210202
"alias": "previous_vl_date",
211-
"column": "date_format(fhsh.vl_2_date, '%Y-%m-%d')"
203+
"column": "date_format(fhs.vl_2_date, '%Y-%m-%d')"
212204
},
213205
{
214206
"type": "simple_column",

0 commit comments

Comments
 (0)