Skip to content

Commit

Permalink
Merge branch 'master' into pep-visit
Browse files Browse the repository at this point in the history
  • Loading branch information
jecihjoy authored Apr 12, 2022
2 parents 80c0965 + 752b26c commit 21f48a8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
17 changes: 11 additions & 6 deletions app/reporting-framework/json-reports/clinical-reminder-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down Expand Up @@ -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"
}
},
{
Expand All @@ -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"
}
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -395,7 +400,7 @@
"conditions": [
{
"filterType": "tableColumns",
"conditionExpression": "t1.uuid = ?",
"conditionExpression": "t1.uuid = ? and t1.is_clinical_encounter = 1",
"parameterName": "patientUuid"
},
{
Expand Down
4 changes: 2 additions & 2 deletions reports/clinical-reminder-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"sql": "$expression"
},
{
"label": "not_completed_ipt",
"expression": "not_completed_ipt",
"label": "needs_ipt_completion",
"expression": "needs_ipt_completion",
"sql": "$expression"
}
],
Expand Down
53 changes: 41 additions & 12 deletions service/patient-reminder.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (' +
Expand All @@ -215,15 +234,19 @@ 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 &&
data.inh_treatment_days_remaining > 0
) {
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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21f48a8

Please sign in to comment.