Skip to content

Commit

Permalink
KH-392: Improve Disbursement report indicators (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruhanga authored Jan 30, 2024
1 parent 42404f9 commit 3bc48b6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ INNER JOIN
person p ON e.patient_id = p.person_id
WHERE
e.location_id in (:locationList)
AND e.encounter_datetime > :startDate
AND e.encounter_datetime < :endDate
AND DATE(e.encounter_datetime) >= :startDate
AND DATE(e.encounter_datetime) <= :endDate
AND e.encounter_type = (
SELECT encounter_type_id
FROM encounter_type s_et
Expand All @@ -24,7 +24,7 @@ WHERE
FROM encounter_type ss_et
WHERE ss_et.uuid LIKE '422b7e0c-b8f3-4748-8e60-d6684315f141'
)
AND s_e.encounter_datetime <= :startDate
AND DATE(s_e.encounter_datetime) <= :startDate
)

UNION ALL
Expand All @@ -39,8 +39,8 @@ INNER JOIN
person p ON e.patient_id = p.person_id
WHERE
e.location_id in (:locationList)
AND e.encounter_datetime > :startDate
AND e.encounter_datetime < :endDate
AND DATE(e.encounter_datetime) >= :startDate
AND DATE(e.encounter_datetime) <= :endDate
AND e.encounter_type = (
SELECT encounter_type_id
FROM encounter_type s_et
Expand All @@ -55,7 +55,7 @@ WHERE
FROM encounter_type ss_et
WHERE ss_et.uuid LIKE '3fd606b6-4c9d-4077-a532-c1ac58644ad2'
)
AND s_e.encounter_datetime <= :startDate
AND DATE(s_e.encounter_datetime) <= :startDate
)

UNION ALL
Expand All @@ -73,7 +73,7 @@ SELECT
AND o_f.concept_id = (
SELECT concept_id
FROM concept
WHERE uuid LIKE '758b9dd8-b6d0-4ac2-b245-0e7bffb4693a'
WHERE uuid LIKE 'c158e3b2-edf9-4e0e-9e95-d36de1a51527'
) THEN 1
ELSE 0
END) >= 0.8 * COUNT(*) THEN 'Yes'
Expand All @@ -100,12 +100,17 @@ LEFT OUTER JOIN
AND o_f.concept_id = (
SELECT concept_id
FROM concept
WHERE uuid LIKE '758b9dd8-b6d0-4ac2-b245-0e7bffb4693a'
WHERE uuid LIKE 'c158e3b2-edf9-4e0e-9e95-d36de1a51527'
)
AND o_f.value_coded IN (
SELECT concept_id
FROM concept
WHERE uuid LIKE '7d469a03-a56b-4c51-a421-0e5787556630' OR uuid LIKE 'fc3909e3-9ddb-46e3-b4f7-6905732d977b'
)
WHERE
e.location_id in (:locationList)
AND e.encounter_datetime > :startDate
AND e.encounter_datetime < :endDate
AND DATE(e.encounter_datetime) >= :startDate
AND DATE(e.encounter_datetime) <= :endDate
AND e.encounter_type = (
SELECT encounter_type_id
FROM encounter_type s_et
Expand All @@ -120,14 +125,14 @@ WHERE
FROM encounter_type ss_et
WHERE ss_et.uuid LIKE '3fd606b6-4c9d-4077-a532-c1ac58644ad2'
)
AND s_e.encounter_datetime <= :startDate
AND DATE(s_e.encounter_datetime) <= :startDate
)

UNION ALL

-- 80% have a Follow-up date and were given medication at least 4 weeks ago
-- 80% (of registered patients with a Follow-up date and diagnosed with Hypertension & Diabetes) were given medication with at least a 4 weeks prescription
SELECT
'80% (of registered patients with a Follow-up date) were given medication with at least a 4 weeks prescription' AS 'Indicator',
'80% (of registered patients with a Follow-up date and diagnosed with Hypertension & Diabetes) were given medication with at least a 4 weeks prescription' AS 'Indicator',
CASE
WHEN SUM(CASE
WHEN medication_table.medication_duration_in_weeks >= 4 THEN 1
Expand All @@ -139,6 +144,18 @@ FROM
patient p
INNER JOIN
encounter e ON p.patient_id = e.patient_id
INNER JOIN
obs o_diagnosis ON e.encounter_id = o_diagnosis.encounter_id
AND o_diagnosis.concept_id = (
SELECT concept_id
FROM concept
WHERE uuid LIKE '45583478-f703-46e3-b63a-54b0a95c25f0'
)
AND o_diagnosis.value_coded IN (
SELECT concept_id
FROM concept
WHERE uuid LIKE '105903f4-7b6d-496a-b613-37ab9d0f5450' OR uuid LIKE '8b26ecd3-8726-4c8e-b042-cbe71e44a863' OR uuid LIKE '117399AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
)
INNER JOIN
obs o_f ON e.encounter_id = o_f.encounter_id
AND o_f.concept_id = (
Expand Down Expand Up @@ -166,5 +183,5 @@ LEFT OUTER JOIN
concept c ON d_o.duration_units = c.concept_id
) medication_table ON medication_table.encounter_id = e.encounter_id
WHERE
e.location_id in (:locationList)
e.location_id IN (:locationList)
AND o_f.value_datetime BETWEEN :startDate AND :endDate
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testReport() throws Exception {
assertEquals("Yes", row.getColumnValue("Value"));
indicator3 = true;
}
if (row.getColumnValue("Indicator").equals("80% (of registered patients with a Follow-up date) were given medication with at least a 4 weeks prescription")) {
if (row.getColumnValue("Indicator").equals("80% (of registered patients with a Follow-up date and diagnosed with Hypertension & Diabetes) were given medication with at least a 4 weeks prescription")) {
assertEquals("Yes", row.getColumnValue("Value"));
indicator4 = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,32 @@
<concept concept_id="2381" retired="false" datatype_id="2" class_id="11" is_set="false" creator="1" date_created="2023-07-26 16:19:26.0" changed_by="1" date_changed="2023-12-13 14:15:38.0" uuid="27912a31-4b1e-40d4-a3a0-947e0eb2e588"/>
<concept concept_id="55" retired="false" datatype_id="4" class_id="5" is_set="false" creator="1" date_created="2023-07-26 16:16:31.0" changed_by="1" date_changed="2023-09-22 09:03:53.0" uuid="664AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept concept_id="45" retired="false" datatype_id="4" class_id="5" is_set="false" creator="1" date_created="2023-07-26 16:16:30.0" changed_by="1" date_changed="2023-09-22 09:03:53.0" uuid="703AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept concept_id="2163" retired="false" datatype_id="2" class_id="7" is_set="false" creator="1" date_created="2023-07-26 16:19:13.0" changed_by="1" date_changed="2023-12-13 14:15:33.0" uuid="758b9dd8-b6d0-4ac2-b245-0e7bffb4693a"/>
<concept concept_id="2163" retired="false" datatype_id="2" class_id="7" is_set="false" creator="1" date_created="2023-07-26 16:19:13.0" changed_by="1" date_changed="2023-12-13 14:15:33.0" uuid="c158e3b2-edf9-4e0e-9e95-d36de1a51527"/>
<concept concept_id="716" retired="false" datatype_id="2" class_id="7" is_set="false" creator="1" date_created="2023-07-26 16:18:20.0" changed_by="1" date_changed="2023-12-13 14:15:33.0" uuid="805c3a0b-cd38-4ed6-b4f8-f3af0fc118ad"/>
<concept concept_id="874" retired="false" datatype_id="4" class_id="11" is_set="false" creator="1" date_created="2023-07-26 16:18:27.0" changed_by="1" date_changed="2023-12-13 14:13:45.0" uuid="98f853f9-75e4-466a-845a-db7ae958d1a0"/>
<concept concept_id="874" retired="false" datatype_id="4" class_id="11" is_set="false" creator="1" date_created="2023-07-26 16:18:27.0" changed_by="1" date_changed="2023-12-13 14:13:45.0" uuid="7d469a03-a56b-4c51-a421-0e5787556630"/>
<concept concept_id="2379" retired="false" datatype_id="4" class_id="11" is_set="false" creator="1" date_created="2023-07-26 16:19:26.0" changed_by="1" date_changed="2023-12-13 14:15:38.0" uuid="da15c40f-e24b-4771-9986-d3ce5ca56b94"/>
<concept concept_id="732" retired="false" datatype_id="6" class_id="11" is_set="false" creator="1" date_created="2023-07-26 16:18:20.0" changed_by="1" date_changed="2023-09-22 09:04:33.0" uuid="e9c145c1-f4e9-4c34-b237-da069939dc38"/>
<concept concept_id="337" retired="false" datatype_id="4" class_id="11" is_set="false" creator="1" date_created="2023-07-26 16:17:29.0" changed_by="2" date_changed="2023-07-26 16:17:29.0" uuid="1072AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept concept_id="336" retired="false" datatype_id="4" class_id="11" is_set="false" creator="1" date_created="2023-07-26 16:17:29.0" changed_by="2" date_changed="2023-07-26 16:17:29.0" uuid="1073AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>

<concept concept_id="649" retired="false" datatype_id="4" class_id="4" is_set="false" creator="1" date_created="2023-07-26 16:18:16.0" changed_by="1" date_changed="2023-08-16 04:28:20.0" uuid="105903f4-7b6d-496a-b613-37ab9d0f5450"/>
<concept concept_id="228" retired="false" datatype_id="4" class_id="4" is_set="false" creator="1" date_created="2023-07-26 16:17:15.0" changed_by="1" date_changed="2023-12-13 14:13:19.0" uuid="117399AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
<concept concept_id="705" retired="false" datatype_id="2" class_id="7" is_set="false" creator="1" date_created="2023-07-26 16:18:19.0" changed_by="1" date_changed="2023-12-13 14:15:34.0" uuid="45583478-f703-46e3-b63a-54b0a95c25f0"/>
<concept concept_id="650" retired="false" datatype_id="4" class_id="4" is_set="false" creator="1" date_created="2023-07-26 16:18:16.0" changed_by="1" date_changed="2023-08-16 04:28:21.0" uuid="8b26ecd3-8726-4c8e-b042-cbe71e44a863"/>

<concept_name concept_name_id="2965" concept_id="649" name="Type 1 diabetes (E10)" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:16.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="e3e480ae-a483-361a-9928-f0c1f0e73784"/>
<concept_name concept_name_id="1404" concept_id="228" name="Hypertension" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:17:15.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="17788BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"/>
<concept_name concept_name_id="3189" concept_id="705" name="Diagnosis 1" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:19.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="b5b86307-5e86-361b-9352-fc7f38a60c3a"/>
<concept_name concept_name_id="2969" concept_id="650" name="Type 2 diabetes (E11)" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:16.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="4808d397-b61b-3cf8-b821-fd69d20570a8"/>
<concept_name concept_name_id="1839" concept_id="337" name="Days" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:17:29.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="1146BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"/>
<concept_name concept_name_id="1835" concept_id="336" name="Weeks" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:17:29.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="1147BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"/>
<concept_name concept_name_id="1316" concept_id="211" name="Yes" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:17:11.0" concept_name_type="FULLY_SPECIFIED" voided="false" date_voided="2023-09-22 09:03:53.0" uuid="1136BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"/>
<concept_name concept_name_id="3418" concept_id="210" name="No" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:22.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="e89934f3-dab4-3016-a2d4-746aee18722c"/>
<concept_name concept_name_id="9989" concept_id="2381" name="VIA test results" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:19:26.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="684047e0-f128-3231-a7f4-c2bd0e025661"/>
<concept_name concept_name_id="3392" concept_id="55" name="Negative" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:22.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="20dcc37f-db04-3b0e-be54-e4cb740c28e4"/>
<concept_name concept_name_id="3388" concept_id="45" name="Positive" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:21.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="827ba84e-9b64-3996-bb6c-e3fe2ab52bb3"/>
<concept_name concept_name_id="9101" concept_id="2163" name="Facility" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:19:13.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="84b9bf31-9829-3291-99e9-29701d6f511c"/>
<concept_name concept_name_id="9101" concept_id="2163" name="Cervical cancer reason for referral" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:19:13.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="84b9bf31-9829-3291-99e9-29701d6f511c"/>
<concept_name concept_name_id="3233" concept_id="716" name="Started on medicine" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:20.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="d8fb91d3-b276-3de2-b903-9c7fac9ff8b3"/>
<concept_name concept_name_id="11310" concept_id="874" name="Demo/Test Referral Facility" locale="en" locale_preferred="true" creator="1" date_created="2023-12-13 14:13:45.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="b9acccbc-b681-31c7-805c-fae4a316a15e"/>
<concept_name concept_name_id="11310" concept_id="874" name="Suspected Cancer" locale="en" locale_preferred="true" creator="1" date_created="2023-12-13 14:13:45.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="b9acccbc-b681-31c7-805c-fae4a316a15e"/>
<concept_name concept_name_id="10521" concept_id="2379" name="Unclear result" locale="en" locale_preferred="true" creator="1" date_created="2023-09-22 09:04:11.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="238f8fd7-9ae4-3c48-b8ba-1d09131f81c9"/>
<concept_name concept_name_id="3297" concept_id="732" name="Follow-up date" locale="en" locale_preferred="true" creator="1" date_created="2023-07-26 16:18:20.0" concept_name_type="FULLY_SPECIFIED" voided="false" uuid="aefa0ccc-2fb6-3cdf-b23c-c17956cad60e"/>

Expand Down Expand Up @@ -112,13 +120,21 @@

<obs obs_id="73007" person_id="3382" concept_id="716" encounter_id="2683" obs_datetime="2023-12-26 02:16:35.0" location_id="1" value_coded="210" creator="1" date_created="2023-12-26 02:16:37.0" voided="false" uuid="2d8890d0-8a3f-41fe-82b5-e25f7532a647" form_namespace_and_path="O3^medicinePrescribed~152"/>
<obs obs_id="73039" person_id="3382" concept_id="732" encounter_id="2683" obs_datetime="2023-12-26 02:16:35.0" location_id="1" value_datetime="2023-12-26 00:00:00.0" creator="1" date_created="2023-12-26 02:16:37.0" voided="false" uuid="10b888f2-d834-4fb6-aa0b-2e5cd8dbcd6a" form_namespace_and_path="O3^followUpDate~147"/>
<obs obs_id="73040" person_id="3382" concept_id="705" encounter_id="2683" obs_datetime="2023-12-26 02:16:35.0" location_id="1" value_coded="649" creator="1" date_created="2023-12-26 02:16:37.0" voided="false" uuid="f685e03f-02d5-4546-9edd-eef67ce86fd7" form_namespace_and_path="O3^Diagnosis1~146"/>

<obs obs_id="73064" person_id="3390" concept_id="716" encounter_id="2684" obs_datetime="2023-12-27 08:02:58.0" location_id="1" value_coded="210" creator="1" date_created="2023-12-27 08:03:00.0" voided="false" uuid="fe17c9b8-1b5c-42fa-a5d2-6a9ca068232e" form_namespace_and_path="O3^medicinePrescribed~92"/>
<obs obs_id="73083" person_id="3390" concept_id="732" encounter_id="2684" obs_datetime="2023-12-27 08:02:58.0" location_id="1" value_datetime="2024-03-27 00:00:00.0" creator="1" date_created="2023-12-27 08:03:00.0" voided="false" uuid="412c3ab0-e676-4195-9249-ac7151c82782" form_namespace_and_path="O3^followUpDate~90"/>
<obs obs_id="73084" person_id="3390" concept_id="705" encounter_id="2684" obs_datetime="2023-12-27 08:02:58.0" location_id="1" value_coded="228" creator="1" date_created="2023-12-27 08:03:00.0" voided="false" uuid="48ab13e1-e41e-4395-9186-0662cc840c42" form_namespace_and_path="O3^Diagnosis1~146"/>

<obs obs_id="73485" person_id="3496" concept_id="716" encounter_id="2738" obs_datetime="2023-12-28 10:10:43.0" location_id="1" value_coded="210" creator="1" date_created="2023-12-28 10:10:43.0" voided="false" uuid="68c5577f-e918-4d31-8681-c432bd4a0260" form_namespace_and_path="O3^medicinePrescribed~152"/>
<obs obs_id="73524" person_id="3496" concept_id="732" encounter_id="2738" obs_datetime="2023-12-28 10:10:43.0" location_id="1" value_datetime="2024-01-04 00:00:00.0" creator="1" date_created="2023-12-28 10:10:43.0" voided="false" uuid="4a32dbcd-c826-465d-9c99-915ae8d4cadf" form_namespace_and_path="O3^followUpDate~147"/>
<obs obs_id="73525" person_id="3496" concept_id="705" encounter_id="2738" obs_datetime="2023-12-28 10:10:43.0" location_id="1" value_coded="649" creator="1" date_created="2023-12-28 10:10:43.0" voided="false" uuid="6bcbb7ea-8d1f-4b4f-8491-54ec507f26a4" form_namespace_and_path="O3^Diagnosis1~146"/>

<obs obs_id="73883" person_id="3580" concept_id="716" encounter_id="2786" obs_datetime="2023-12-29 09:09:41.0" location_id="1" value_coded="210" creator="1" date_created="2023-12-29 09:09:43.0" voided="false" uuid="9d4e0a8a-b510-4a3c-bcb9-241352f9b39c" form_namespace_and_path="O3^medicinePrescribed~134"/>
<obs obs_id="73927" person_id="3568" concept_id="716" encounter_id="2787" obs_datetime="2023-12-29 09:10:13.0" location_id="1" value_coded="210" creator="1" date_created="2023-12-29 09:10:13.0" voided="false" uuid="c83d3d90-fde0-4858-9dff-479d1843aa17" form_namespace_and_path="O3^medicinePrescribed~137"/>
<obs obs_id="73946" person_id="3568" concept_id="732" encounter_id="2787" obs_datetime="2023-12-29 09:10:13.0" location_id="1" value_datetime="2023-12-29 00:00:00.0" creator="1" date_created="2023-12-29 09:10:13.0" voided="false" uuid="daf2842b-70e0-44ee-bcbd-feb37f3618bc" form_namespace_and_path="O3^followUpDate~135"/>
<obs obs_id="73947" person_id="3568" concept_id="705" encounter_id="2787" obs_datetime="2023-12-29 09:10:13.0" location_id="1" value_coded="650" creator="1" date_created="2023-12-29 09:10:13.0" voided="false" uuid="5434470a-1c0e-46bb-b4cc-fae218463af7" form_namespace_and_path="O3^Diagnosis1~146"/>

<obs obs_id="72989" person_id="3374" concept_id="2381" encounter_id="2682" obs_datetime="2023-12-25 01:56:28.0" location_id="1" value_coded="45" creator="1" date_created="2023-12-25 01:56:28.0" voided="false" uuid="94d8c442-6b06-4479-82c0-6c045077ae52" form_namespace_and_path="O3^VIATestResults~105"/>
<obs obs_id="72990" person_id="3374" concept_id="2163" encounter_id="2682" obs_datetime="2023-12-25 01:56:28.0" location_id="1" value_coded="874" creator="1" date_created="2023-12-25 01:56:28.0" voided="false" uuid="55e54341-d59a-499f-a69f-7731c9350990" form_namespace_and_path="O3^referralSite~119"/>

Expand All @@ -139,6 +155,7 @@
<obs obs_id="74989" person_id="3640" concept_id="2163" encounter_id="2816" obs_datetime="2024-01-05 08:10:37.0" location_id="1" value_coded="874" creator="1" date_created="2024-01-03 07:16:14.0" voided="false" uuid="5e544531-d59a-499f-a69f-107373990c95" form_namespace_and_path="O3^referralSite~119"/>

<obs obs_id="75040" person_id="3646" concept_id="2381" encounter_id="2817" obs_datetime="2024-01-06 14:48:50.0" location_id="1" value_coded="2379" creator="1" date_created="2024-01-06 14:48:50.0" voided="false" uuid="91e8917d-0031-4ad4-8302-8aee35189809" form_namespace_and_path="O3^VIATestResults~97"/>

<obs obs_id="75262" person_id="3659" concept_id="2381" encounter_id="2824" obs_datetime="2024-01-08 13:44:19.0" location_id="1" value_coded="45" creator="1" date_created="2024-01-08 13:44:19.0" voided="false" uuid="be029360-8553-42f0-9a11-1881556dbf4f" form_namespace_and_path="O3^VIATestResults~81"/>
<obs obs_id="75263" person_id="3659" concept_id="2163" encounter_id="2824" obs_datetime="2024-01-03 07:16:14.0" location_id="1" value_coded="874" creator="1" date_created="2024-01-08 13:44:19.0" voided="false" uuid="3415e545-d59a-499f-a69f-1c5077399930" form_namespace_and_path="O3^referralSite~119"/>

Expand Down

0 comments on commit 3bc48b6

Please sign in to comment.