diff --git a/app/reporting-framework/json-reports/clinical-reminder-report.json b/app/reporting-framework/json-reports/clinical-reminder-report.json index 08606feac..b98e6c1f3 100644 --- a/app/reporting-framework/json-reports/clinical-reminder-report.json +++ b/app/reporting-framework/json-reports/clinical-reminder-report.json @@ -150,7 +150,7 @@ "alias": "qualifies_differenciated_care", "expressionType": "simple_expression", "expressionOptions": { - "expression": "case when vl_1 < 401 and (timestampdiff(year,birthdate, date('{referenceDate}')) >= 20) and (timestampdiff(month,ipt_start_date,if(ipt_completion_date,ipt_completion_date,'{referenceDate}')) >= 6 ) and (timestampdiff(month,vl_1_date,now()) <= 11 ) and (timestampdiff(month,arv_start_date, '{referenceDate}') >= 12) AND p.program_id IS NULL and t10.program_id is null and DATE(t1.prev_rtc_date) = DATE(t1.encounter_datetime) then 1 else 0 end" + "expression": "case when vl_1 < 401 and (timestampdiff(year,birthdate, date('{referenceDate}')) >= 20) and ((timestampdiff(month,ipt_start_date,if(ipt_completion_date is not null and (tb_prophylaxis_duration = 6 or tb_prophylaxis_duration is null),ipt_completion_date,'{referenceDate}')) >= 6) or (timestampdiff(month,ipt_start_date,if(ipt_completion_date is not null and tb_prophylaxis_duration = 3,ipt_completion_date,'{referenceDate}')) >= 3)) and (timestampdiff(month,vl_1_date,now()) <= 11 ) and (timestampdiff(month,arv_start_date, '{referenceDate}') >= 12) AND p.program_id IS NULL and t10.program_id is null and DATE(t1.prev_rtc_date) = DATE(t1.encounter_datetime) then 1 else 0 end" } }, { @@ -233,7 +233,7 @@ "alias": "ipt_completion_date", "expressionType": "simple_expression", "expressionOptions": { - "expression": "DATE_ADD(t1.ipt_start_date, INTERVAL 180 DAY)" + "expression": "case when t1.tb_prophylaxis_duration = 3 then DATE_ADD(t1.ipt_start_date, INTERVAL 90 DAY) else DATE_ADD(t1.ipt_start_date, INTERVAL 180 DAY) end" } }, { @@ -246,7 +246,7 @@ "alias": "inh_treatment_days_remaining", "expressionType": "simple_expression", "expressionOptions": { - "expression": "DATEDIFF(DATE_ADD(t1.ipt_start_date, INTERVAL 180 DAY), now())" + "expression": "case when t1.tb_prophylaxis_duration = 3 then DATEDIFF(DATE_ADD(t1.ipt_start_date, INTERVAL 90 DAY), now()) else DATEDIFF(DATE_ADD(t1.ipt_start_date, INTERVAL 180 DAY), now()) end" } }, { @@ -307,12 +307,17 @@ }, { "type": "derived_column", - "alias": "not_completed_ipt", + "alias": "needs_ipt_completion", "expressionType": "simple_expression", "expressionOptions": { - "expression": "case when (timestampdiff(day,t1.ipt_start_date,curdate()) > 180) and t1.ipt_completion_date is null and t1.ipt_stop_date is null then 1 else 0 end" + "expression": "case when ((t1.tb_prophylaxis_duration = 3 and TIMESTAMPDIFF(DAY,t1.ipt_start_date,CURDATE()) > 90) or (TIMESTAMPDIFF(DAY,t1.ipt_start_date,CURDATE()) > 180)) and t1.ipt_completion_date is null and t1.ipt_stop_date is null then 1 else 0 end" } }, + { + "type": "simple_column", + "alias": "tb_prophylaxis_duration", + "column": "t1.tb_prophylaxis_duration" + }, { "type": "simple_column", "alias": "transfer_out_date", @@ -395,7 +400,7 @@ "conditions": [ { "filterType": "tableColumns", - "conditionExpression": "t1.uuid = ?", + "conditionExpression": "t1.uuid = ? and t1.is_clinical_encounter = 1", "parameterName": "patientUuid" }, { diff --git a/reports/clinical-reminder-report.json b/reports/clinical-reminder-report.json index 2a763f8b8..bf0982ec4 100755 --- a/reports/clinical-reminder-report.json +++ b/reports/clinical-reminder-report.json @@ -84,8 +84,8 @@ "sql": "$expression" }, { - "label": "not_completed_ipt", - "expression": "not_completed_ipt", + "label": "needs_ipt_completion", + "expression": "needs_ipt_completion", "sql": "$expression" } ], diff --git a/service/patient-reminder.service.js b/service/patient-reminder.service.js index 2030ce543..f83e709dc 100755 --- a/service/patient-reminder.service.js +++ b/service/patient-reminder.service.js @@ -188,15 +188,34 @@ function qualifiesDifferenciatedReminders(data) { function inhReminders(data) { let reminders = []; + let months = 6; + let showReminder = false; + if (data.tb_prophylaxis_duration == 3) { + months = 3; + } + if ( + data.tb_prophylaxis_duration == 3 && + data.is_on_inh_treatment && + data.inh_treatment_days_remaining > 0 && + data.inh_treatment_days_remaining < 60 + ) { + showReminder = true; + } else if ( + data.tb_prophylaxis_duration != 3 && + data.is_on_inh_treatment && + data.inh_treatment_days_remaining > 30 && + data.inh_treatment_days_remaining < 150 + ) { + showReminder = true; + } + // INH Treatment Reminder - last month try { - if ( - data.is_on_inh_treatment && - data.inh_treatment_days_remaining > 30 && - data.inh_treatment_days_remaining < 150 - ) { + if (showReminder) { reminders.push({ message: - 'Patient started INH treatment on (' + + 'Patient started ' + + months + + ' months INH treatment on (' + Moment(data.ipt_start_date).format('DD-MM-YYYY') + '). ' + 'Expected to end on (' + @@ -215,7 +234,7 @@ function inhReminders(data) { } catch (e) { console.log(e); } - // INH Treatment Reminder - last mont + // INH Treatment Reminder - last month if ( data.is_on_inh_treatment && data.inh_treatment_days_remaining <= 30 && @@ -223,7 +242,11 @@ function inhReminders(data) { ) { reminders.push({ message: - 'Patient has been on INH treatment for the last 5 months. Expected to end on (' + + 'Patient has been on ' + + months + + ' month INH treatment since (' + + Moment(data.ipt_start_date).format('DD-MM-YYYY') + + '). Expected to end on (' + Moment(data.ipt_completion_date).format('DD-MM-YYYY') + ') ', title: 'INH Treatment Reminder', @@ -489,16 +512,22 @@ function geneXpertReminders(data) { function getIptCompletionReminder(data) { let reminders = []; + let months = 6; + if (data.tb_prophylaxis_duration == 3) { + months = 3; + } - if (data.not_completed_ipt) { + if (data.needs_ipt_completion) { reminders.push({ message: - 'Patient started IPT on ' + + 'Patient started ' + + months + + ' month IPT on ' + Moment(data.ipt_start_date).format('DD-MM-YYYY') + ' and was supposed to be completed on ' + - Moment(data.ipt_start_date).add(6, 'months').format('DD-MM-YYYY'), + Moment(data.ipt_start_date).add(months, 'months').format('DD-MM-YYYY'), title: 'IPT Completion Reminder', - type: 'warning', + type: 'danger', display: { banner: true, toast: true