|
7 | 7 | "sources": [
|
8 | 8 | {
|
9 | 9 | "table": "etl.flat_hiv_summary_v15b",
|
10 |
| - "alias": "t2" |
| 10 | + "alias": "fhs" |
11 | 11 | },
|
12 | 12 | {
|
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", |
23 | 15 | "join": {
|
24 | 16 | "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" |
26 | 18 | }
|
27 | 19 | },
|
28 | 20 | {
|
29 | 21 | "table": "amrs.person",
|
30 |
| - "alias": "t3", |
| 22 | + "alias": "p", |
31 | 23 | "join": {
|
32 | 24 | "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" |
42 | 26 | }
|
43 | 27 | },
|
44 | 28 | {
|
45 |
| - "table": "amrs.encounter_type", |
46 |
| - "alias": "et", |
| 29 | + "table": "etl.flat_patient_identifiers_v1", |
| 30 | + "alias": "flat_identifiers", |
47 | 31 | "join": {
|
48 | 32 | "type": "LEFT",
|
49 |
| - "joinCondition": "t2.encounter_type = et.encounter_type_id" |
| 33 | + "joinCondition": "fhs.person_id = flat_identifiers.patient_id" |
50 | 34 | }
|
51 | 35 | },
|
52 | 36 | {
|
53 |
| - "table": "amrs.person_address", |
54 |
| - "alias": "pa", |
| 37 | + "table": "amrs.location", |
| 38 | + "alias": "l", |
55 | 39 | "join": {
|
56 |
| - "type": "LEFT", |
57 |
| - "joinCondition": "t2.person_id = pa.person_id" |
| 40 | + "type": "INNER", |
| 41 | + "joinCondition": "fhs.location_uuid = l.uuid" |
58 | 42 | }
|
59 | 43 | }
|
60 | 44 | ],
|
61 | 45 | "columns": [
|
62 | 46 | {
|
63 | 47 | "type": "simple_column",
|
64 | 48 | "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" |
74 | 50 | },
|
75 | 51 | {
|
76 | 52 | "type": "simple_column",
|
|
89 | 65 | },
|
90 | 66 | {
|
91 | 67 | "type": "simple_column",
|
92 |
| - "alias": "location", |
93 |
| - "column": "l.name" |
| 68 | + "alias": "location_id", |
| 69 | + "column": "fhs.location_id" |
94 | 70 | },
|
95 | 71 | {
|
96 | 72 | "type": "simple_column",
|
97 |
| - "alias": "location_id", |
98 |
| - "column": "t2.location_id" |
| 73 | + "alias": "location", |
| 74 | + "column": "l.name" |
99 | 75 | },
|
100 | 76 | {
|
101 | 77 | "type": "simple_column",
|
102 | 78 | "alias": "location_uuid",
|
103 |
| - "column": "t2.location_uuid" |
| 79 | + "column": "fhs.location_uuid" |
104 | 80 | },
|
105 | 81 | {
|
106 | 82 | "type": "simple_column",
|
107 | 83 | "alias": "encounter_datetime",
|
108 |
| - "column": "t2.encounter_datetime" |
| 84 | + "column": "fhs.encounter_datetime" |
109 | 85 | },
|
110 | 86 | {
|
111 | 87 | "type": "simple_column",
|
112 | 88 | "alias": "month",
|
113 |
| - "column": "MONTH(t2.encounter_datetime)" |
| 89 | + "column": "MONTH(fhs.encounter_datetime)" |
114 | 90 | },
|
115 | 91 | {
|
116 | 92 | "type": "simple_column",
|
117 | 93 | "alias": "reporting_month",
|
118 |
| - "column": "date_format(t2.encounter_datetime, '%m/%Y')" |
| 94 | + "column": "date_format(fhs.encounter_datetime, '%m/%Y')" |
119 | 95 | },
|
120 | 96 | {
|
121 | 97 | "type": "simple_column",
|
122 | 98 | "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)" |
132 | 100 | },
|
133 | 101 | {
|
134 | 102 | "type": "simple_column",
|
135 | 103 | "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')" |
142 | 105 | },
|
143 | 106 | {
|
144 | 107 | "type": "simple_column",
|
145 | 108 | "alias": "cur_meds",
|
146 |
| - "column": "t2.cur_arv_meds" |
| 109 | + "column": "fhs.cur_arv_meds" |
147 | 110 | }
|
148 | 111 | ],
|
149 | 112 | "filters": {
|
150 | 113 | "conditionJoinOperator": "and",
|
151 | 114 | "conditions": [
|
152 | 115 | {
|
153 | 116 | "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", |
160 | 118 | "parameterName": "locationUuids"
|
161 | 119 | },
|
162 | 120 | {
|
163 | 121 | "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" |
166 | 124 | }
|
167 | 125 | ]
|
168 | 126 | }
|
|
0 commit comments