Skip to content

Commit

Permalink
Merge branch 'master' into POC-613
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Mutai authored Jan 19, 2024
2 parents 70d71d1 + 342a720 commit 83ab5c3
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 95 deletions.
4 changes: 3 additions & 1 deletion app/otz/cohort-module.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class CohortModuleService {
0) AS suppression_rate_percentage
FROM
amrs.cohort c
LEFT JOIN
amrs.location l ON l.location_id = c.location_id
INNER JOIN
amrs.cohort_member cm ON c.cohort_id = cm.cohort_id
LEFT JOIN
Expand All @@ -34,7 +36,7 @@ export class CohortModuleService {
etl.flat_labs_and_imaging fl ON latest_tests.person_id = fl.person_id
AND latest_tests.latest_test_datetime = fl.test_datetime
WHERE
c.uuid in (${uuids})
l.uuid = '${cohortUuids}'
GROUP BY c.cohort_id;
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
},
{
"table": "(SELECT MAX(am.encounter_datetime) AS max_encounter_datetime, am.encounter_datetime, am.encounter_type, am.patient_id, fd.person_id , fd.rtc_date FROM etl.flat_defaulters fd INNER JOIN amrs.encounter am on (am.patient_id = fd.person_id) WHERE am.encounter_type = 21 group by am.patient_id)",
"table": "(SELECT MAX(am.encounter_datetime) AS max_encounter_datetime, am.encounter_datetime, am.encounter_type, am.patient_id, fd.person_id , fd.rtc_date FROM etl.flat_defaulters fd INNER JOIN amrs.encounter am on (am.patient_id = fd.person_id) group by am.patient_id)",
"alias": "am",
"join": {
"type": "INNER",
Expand Down
239 changes: 147 additions & 92 deletions reports/DQA/dqa-chart-abstraction-report-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,116 +14,171 @@ 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();

const limitOffSetDefinition =
limit === 'all' ? '' : `limit ` + limit + ` offset ` + offset;
let sqlQuery =
`
SELECT
h.person_uuid as uuid,
cc.identifier as ccc_number,
np.identifier as upi_number,
ov.identifier 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',
e.height,
e.weight,
DATE_FORMAT(h.birthdate,'%Y-%m-%d') AS birthdate,
h.encounter_id,
DATE_FORMAT(h.encounter_date,'%Y-%m-%d') as last_appointment_date,
h.rtc_date,
h.location_id,
h.cur_arv_meds,
h.tb_screen,
h.tb_screening_datetime,
e.hiv_start_date,
h.arv_start_date,
e.cd4_1,
ls.encounter_datetime AS last_clinical_encounter,
DATE_FORMAT(h.rtc_date,'%Y-%m-%d') 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,
h.cur_arv_meds_names AS drugs_given,
case
when e.height is not null and e.weight is not null then 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,
case
when e.on_ipt = 1 then 'CONTINUING'
when e.ipt_completion_date is null and e.ipt_stop_date is not null then 'DISCONTINUED'
when e.ipt_completion_date is not null
then 'COMPLETED'
else 'NA'
end as tpt_status,
h.ipt_stop_date,
h.ipt_completion_date,
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
FROM
etl.hiv_monthly_report_dataset_frozen 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 fv.person_id,
fv.systolic_bp,
fv.diastolic_bp,
MAX(fv.encounter_datetime) AS max_date
FROM etl.flat_vitals fv where diastolic_bp is not null
GROUP BY fv.person_id,fv.encounter_datetime order by fv.encounter_datetime desc limit 1) fv ON e.person_id = fv.person_id
INNER JOIN
amrs.person t1 ON (h.person_id = t1.person_id)
INNER JOIN
amrs.person_name person_name ON (t1.person_id = person_name.person_id AND (person_name.voided = 0 || person_name.voided = 0))
LEFT JOIN
amrs.patient_identifier id ON (t1.person_id = id.patient_id AND id.voided = 0)
LEFT JOIN
amrs.patient_identifier cc ON (t1.person_id = cc.patient_id and cc.identifier_type in (28) AND cc.voided = 0)
LEFT JOIN
amrs.patient_identifier ov ON (t1.person_id = ov.patient_id and ov.identifier_type in (43) AND ov.voided = 0)
LEFT JOIN
amrs.patient_identifier np ON (t1.person_id = np.patient_id and np.identifier_type in (45) AND np.voided = 0)
left join amrs.patient_program p on (p.patient_id = h.person_id and p.program_id in (4,9) and p.date_completed is null and p.voided = 0)
WHERE h.status = "active" and visit_this_month=1
AND h.endDate >= '` +
SELECT
h.person_uuid AS uuid,
fpiv.ccc AS ccc_number,
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 'No'
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, '%d/%m/%Y') AS birthdate,
h.encounter_id,
DATE_FORMAT(h.encounter_date, '%d/%m/%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,
DATE_FORMAT(h.tb_screening_datetime,'%d/%m/%Y') as tb_screening_datetime,
CASE
WHEN (e.hiv_start_date <= '1900-01-01') THEN ''
ELSE DATE_FORMAT(e.hiv_start_date,'%d/%m/%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/%m/%Y')
END as arv_first_regimen_start_date,
e.cd4_1,
IF((e.cd4_1 IS NOT NULL), 'Yes', 'No') as has_cd4_1,
DATE_FORMAT(e.encounter_datetime, '%d/%m/%Y') AS last_clinical_encounter,
DATE_FORMAT(h.rtc_date, '%d/%m/%Y') AS next_appointment,
h.vl_1,
CASE
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
e.height IS NOT NULL
AND e.weight IS NOT NULL
THEN
e.weight / ((e.height / 100) * (e.height / 100))
ELSE NULL
END AS BMI,
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, '%d/%m/%Y') AS last_ipt_start_date,
CASE
WHEN h.on_ipt_this_month = 1 THEN 'Continuing'
WHEN
h.ipt_completion_date IS NULL
AND h.ipt_stop_date IS NOT NULL
THEN
'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,
DATE_FORMAT(h.ipt_stop_date,'%d/%m/%Y') as ipt_stop_date,
DATE_FORMAT(h.ipt_completion_date, '%d/%m/%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,
h.status,
IF((o.value_coded IS NULL), 'No', 'Yes') AS is_crag_screened,
CASE
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 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 'Paeds (0-14yrs)'
WHEN (TIMESTAMPDIFF(YEAR, h.birthdate, '` +
endDate +
`') >= 15) THEN 'Adults (>15 yrs)'
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_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)
LEFT JOIN
amrs.patient_program p ON (p.patient_id = h.person_id
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 in (9812)
AND o.voided = 0
)
WHERE
h.status = "active" AND
h.endDate >= '` +
startDate +
`'
AND h.endDate <= '` +
AND h.endDate <= '` +
endDate +
`'
AND h.location_id IN (` +
AND h.location_id IN (` +
locations +
`) AND ` +
`)
AND ` +
where +
`
GROUP BY h.person_id
ORDER BY RAND() DESC ` +
`
GROUP BY
h.person_id
` +
limitOffSetDefinition;

return new Promise((resolve, reject) => {
Expand Down
9 changes: 8 additions & 1 deletion service/surge-reports/surge-report.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ export class SurgeService extends SurgeMultiDatasetPatientlistReport {

determineSurgeReportSourceTables(yearWeek) {
const self = this;
if (yearWeek >= moment().year() + '' + moment().week() - 1) {
var currentYear = moment().year();
var currentWeek = moment().week() - 1;
if (currentWeek < 10) {
currentWeek = '0' + currentWeek;
}

const diffWeek = currentYear + '' + currentWeek;
if (yearWeek >= diffWeek) {
return (self.params.surgeWeeklyDatasetSource =
'etl.surge_weekly_report_dataset_2022');
} else {
Expand Down

0 comments on commit 83ab5c3

Please sign in to comment.