Skip to content

Commit

Permalink
Merge pull request #1360 from henrykorir/POC-610
Browse files Browse the repository at this point in the history
POC-610: Modified DQA Query to suit indicators requested
  • Loading branch information
Alfred-Mutai authored Jan 15, 2024
2 parents b1e7019 + 1b28b3f commit 55bb533
Showing 1 changed file with 79 additions and 68 deletions.
147 changes: 79 additions & 68 deletions reports/DQA/dqa-chart-abstraction-report-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export class DQAChartAbstractionDAO {
let where = '';
switch (patientType) {
case 'PEADS':
where = `EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), h.birthdate)))) < 15`;
where = `TIMESTAMPDIFF(YEAR, h.birthdate, '` + endDate + `') < 15`;
break;
case 'PMTCT':
where = `p.program_id = 4`;
break;
default:
where = `EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), h.birthdate)))) >= 15`;
where = `TIMESTAMPDIFF(YEAR, h.birthdate, '` + endDate + `') >= 15`;
}
let runner = this.getSqlRunner();

Expand All @@ -31,42 +31,56 @@ export class DQAChartAbstractionDAO {
SELECT
h.person_uuid AS uuid,
fpiv.ccc AS ccc_number,
fpiv.nupi AS upi_number,
fpiv.ovcid AS ovcid_id,
EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(), h.birthdate)))) AS age,
IF(DATE(h.tb_screening_datetime) > DATE_SUB(h.endDate, INTERVAL 6 MONTH),
'YES',
'NO') AS tb_screened_this_visit,
h.gender AS 'sex_gender',
IF((fpiv.nupi IS NOT NULL), fpiv.nupi, 'missing') AS NUPI,
TIMESTAMPDIFF(year,h.birthdate,'` +
endDate +
`') AS age,
CASE
WHEN e.tb_screen = 1 then 'Yes'
WHEN e.tb_screen = 0 then 'No'
ELSE 'Not documented'
END AS 'tb_screened_this_visit',
CASE
WHEN (h.gender = 'F') then 'Female'
WHEN (h.gender = 'M') then 'Male'
ELSE 'missing'
END AS 'sex_gender',
e.height,
e.weight,
DATE_FORMAT(h.birthdate, '%Y-%m-%d') AS birthdate,
DATE_FORMAT(h.birthdate, "%d-%b-%Y") AS birthdate,
h.encounter_id,
DATE_FORMAT(h.encounter_date, '%Y-%m-%d') AS last_appointment_date,
DATE_FORMAT(h.encounter_date, "%d-%b-%Y") AS last_appointment_date,
h.rtc_date,
h.location_id,
h.cur_arv_meds,
CASE
WHEN (h.cur_arv_meds_names regexp '[[:<:]]DTG[[:>:]]') THEN 'DTG-based'
WHEN (h.cur_arv_meds_names NOT regexp '[[:<:]]DTG[[:>:]]') THEN 'Non-DTG-based'
ELSE 'NON DTG'
END as cur_arv_med_basis,
h.tb_screen,
h.tb_screening_datetime,
e.hiv_start_date,
DATE_FORMAT(h.tb_screening_datetime,"%d-%b-%Y") as tb_screening_datetime,
CASE
WHEN (e.hiv_start_date <= '1900-01-01') THEN ''
ELSE DATE_FORMAT(e.hiv_start_date,"%d-%b-%Y")
END as hiv_start_date,
h.arv_start_date,
CASE
WHEN (h.arv_first_regimen_start_date <= '1900-01-01') THEN ''
ELSE DATE_FORMAT(h.arv_first_regimen_start_date,"%d-%b-%Y")
END as arv_first_regimen_start_date,
e.cd4_1,
e.encounter_datetime AS last_clinical_encounter,
DATE_FORMAT(h.rtc_date, '%Y-%m-%d') AS next_appointment,
IF((e.cd4_1 IS NOT NULL), 'Yes', 'No') as has_cd4_1,
DATE_FORMAT(e.encounter_datetime, "%d-%b-%Y") AS last_clinical_encounter,
DATE_FORMAT(h.rtc_date, "%d-%b-%Y") AS next_appointment,
h.vl_1,
CASE
WHEN
e.weight IS NOT NULL
AND e.height IS NOT NULL
THEN
'YES'
ELSE 'NO'
END AS nutrition,
CASE
WHEN e.visit_type IN (37 , 58) THEN 'CARG'
WHEN e.visit_type IN (43 , 80, 104, 118, 120, 123) THEN 'Treatment Supporter'
ELSE 'Self'
END AS visit_type,
WHEN (TIMESTAMPDIFF(MONTH,h.arv_start_date,'` +
endDate +
`') < 6 ) THEN 'NA'
WHEN (h.vl_1 is NOT NULL) THEN 'Yes'
ELSE 'missing'
END AS viral_load_validity,
h.cur_arv_meds_names AS drugs_given,
CASE
WHEN
Expand All @@ -76,83 +90,80 @@ export class DQAChartAbstractionDAO {
e.weight / ((e.height / 100) * (e.height / 100))
ELSE NULL
END AS BMI,
IF(p.program_id = 9, 'DC', 'Standard') AS DSD,
TIMESTAMPDIFF(DAY,
h.encounter_date,
h.rtc_date) AS drugs_duration,
IF(h.ipt_start_date = h.encounter_date,
1,
0) AS ipt_started_this_visit,
DATE_FORMAT(h.ipt_start_date, '%Y-%m-%d') AS last_ipt_start_date,
DATE_FORMAT(h.ipt_start_date, "%d-%b-%Y") AS last_ipt_start_date,
CASE
WHEN e.on_ipt = 1 THEN 'CONTINUING'
WHEN h.on_ipt_this_month = 1 THEN 'continuing'
WHEN
e.ipt_completion_date IS NULL
AND e.ipt_stop_date IS NOT NULL
h.ipt_completion_date IS NULL
AND h.ipt_stop_date IS NOT NULL
THEN
'DISCONTINUED'
WHEN e.ipt_completion_date IS NOT NULL THEN 'COMPLETED'
'Discontinued'
WHEN h.ipt_completion_date IS NOT NULL THEN 'INH Completed'
WHEN (h.on_ipt_this_month = 0 AND h.on_tb_tx_this_month = 0) THEN 'Missing'
WHEN ((TIMESTAMPDIFF(MONTH,h.ipt_start_date,'` +
endDate +
`') < 3) AND h.on_ipt_this_month = 1) THEN 'Defaulted'
ELSE 'NA'
END AS tpt_status,
h.ipt_stop_date,
h.ipt_completion_date,
e.cur_who_stage,
e.cd4_1,
fv.muac,
DATE_FORMAT(h.ipt_stop_date,"%d-%b-%Y") as ipt_stop_date,
DATE_FORMAT(h.ipt_completion_date, "%d-%b-%Y") as ipt_completion_date,
fv.muac as muac,
IF(h.ipt_stop_date = h.encounter_date
OR h.ipt_completion_date = h.encounter_date,
1,
0) AS ipt_ended_this_visit,
fv.systolic_bp AS sysBP,
fv.diastolic_bp AS dysBP,
h.status,
IF((o.value_coded IS NULL), 'NO', 'YES') AS is_crag_screened,
IF((o.value_coded IS NULL), 'No', 'Yes') AS is_crag_screened,
CASE
WHEN (h.vl_1 < 200) THEN 'suppressed'
WHEN (h.vl_1 >= 200) THEN 'unsuppressed'
WHEN (h.vl_1 < 200) THEN 'Yes'
WHEN (h.vl_1 >= 200) THEN 'No'
ELSE 'Missing'
END AS vl_suppression,
CASE
WHEN (e.tb_screening_result = 6971) THEN 'Pr TB'
WHEN (e.tb_screening_result = 6137) THEN 'Confirmed'
WHEN (e.tb_screening_result IN (1107 , 10678)) THEN 'No TB'
WHEN (e.tb_screening_result = 10767) THEN 'TB Rx'
WHEN (e.tb_screening_result = 10974) THEN 'INH'
END AS tb_screening_result
WHEN (e.tb_screening_result IN (6621,1118)) THEN 'TB Screening not done'
WHEN (e.tb_screening_result = 6971) THEN 'Presumed TB'
WHEN (e.tb_screening_result IN (6137, 6176, 10767)) THEN 'TB confirmed'
WHEN (e.tb_screening_result IN (1107 , 10678)) THEN 'No TB signs'
ELSE 'Missing'
END AS tb_screening_result,
CASE
WHEN (p.program_id = 4) THEN 'PMTCT'
WHEN (TIMESTAMPDIFF(YEAR, h.birthdate, '` +
endDate +
`') < 15) THEN 'PEAD'
WHEN (TIMESTAMPDIFF(YEAR, h.birthdate, '` +
endDate +
`') >= 15) THEN 'ADULT'
END AS category
FROM
etl.hiv_monthly_report_dataset_v1_2 h
LEFT JOIN
etl.flat_hiv_summary_v15b e ON (h.encounter_id = e.encounter_id)
LEFT JOIN
-- etl.flat_hiv_summary_v15b ls ON (ls.next_clinical_datetime_hiv IS NULL
-- AND ls.person_id = e.person_id)
-- LEFT JOIN
-- (SELECT
-- *, MAX(encounter_datetime) AS max_date
-- FROM
-- etl.flat_vitals
-- WHERE
-- encounter_datetime <= '` +
endDate +
`'
-- GROUP BY person_id , encounter_datetime
-- ORDER BY encounter_datetime)
etl.flat_vitals fv ON (e.person_id = fv.person_id)
INNER JOIN
amrs.person t1 ON (h.person_id = t1.person_id)
inner JOIN
etl.flat_patient_identifiers_v1 fpiv ON (t1.person_id = fpiv.patient_id and fpiv.ccc is not null)
etl.flat_patient_identifiers_v1 fpiv ON (t1.person_id = fpiv.patient_id)
LEFT JOIN
amrs.patient_program p ON (p.patient_id = h.person_id
AND p.program_id IN (4 , 9)
AND p.program_id IN (4)
AND p.date_completed IS NULL
AND p.voided = 0)
LEFT JOIN
amrs.obs o ON (o.encounter_id = e.encounter_id
AND o.person_id = h.person_id
AND o.concept_id = 9812
AND o.voided = 0 and e.is_clinical_encounter = 1)
AND o.concept_id in (9812)
AND o.voided = 0
)
WHERE
e.encounter_datetime >= "2022-01-01" AND (e.weight is not null) AND
h.status = "active" AND
h.endDate >= '` +
startDate +
`'
Expand Down

0 comments on commit 55bb533

Please sign in to comment.