From 9ac30916b2d2b6891b7706027f079506c4ed1953 Mon Sep 17 00:00:00 2001 From: Denzel Kipkemoi Date: Fri, 30 May 2025 09:51:11 +0300 Subject: [PATCH] POC-1008: Update surge reporting indicators to reference the start of the financial year --- .../json-reports/surge-report-base.json | 36 ++++++++++++---- service/surge-reports/surge-report.json | 42 +++++++++---------- service/surge-reports/surge-report.service.js | 12 +++++- service/surge-reports/surge-service.js | 11 ++++- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/app/reporting-framework/json-reports/surge-report-base.json b/app/reporting-framework/json-reports/surge-report-base.json index 83e1fca61..3079d3d7c 100644 --- a/app/reporting-framework/json-reports/surge-report-base.json +++ b/app/reporting-framework/json-reports/surge-report-base.json @@ -32,6 +32,14 @@ "type": "INNER", "joinCondition": "l.location_id = srb.location_id" } + }, + { + "table": "etl.flat_defaulters", + "alias": "d", + "join": { + "type": "INNER", + "joinCondition": "d.encounter_id = srb.encounter_id" + } } ], "columns": [ @@ -565,19 +573,28 @@ "column": "srb.ltfu_death_this_week" }, { - "type": "simple_column", + "type": "derived_column", "alias": "ltfu_active_this_week", - "column": "srb.ltfu_active_this_week" + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "CASE WHEN d.encounter_datetime >= '2024-10-01' and d.days_since_rtc >= 28 THEN old_ltfus_to_active_this_week ELSE 0 END" + } }, { - "type": "simple_column", + "type": "derived_column", "alias": "is_ltfu_after_may", - "column": "srb.is_ltfu_after_may" + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "CASE WHEN d.encounter_datetime >= '2024-10-01' and d.days_since_rtc >= 28 THEN is_ltfu_after_may ELSE 0 END" + } }, { - "type": "simple_column", + "type": "derived_column", "alias": "old_ltfus_to_active", - "column": "srb.old_ltfus_to_active" + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "CASE WHEN d.encounter_datetime >= '2024-10-01' and d.days_since_rtc >= 28 THEN old_ltfus_to_active ELSE 0 END" + } }, { "type": "simple_column", @@ -640,9 +657,12 @@ "column": "srb.not_elligible_and_on_dc" }, { - "type": "simple_column", + "type": "derived_column", "alias": "is_ltfu_after_may_total", - "column": "srb.is_ltfu_after_may_total" + "expressionType": "simple_expression", + "expressionOptions": { + "expression": "CASE WHEN d.encounter_datetime >= '2024-10-01' and d.days_since_rtc >= 28 THEN is_ltfu_after_may_total ELSE 0 END" + } }, { "type": "simple_column", diff --git a/service/surge-reports/surge-report.json b/service/surge-reports/surge-report.json index 67cef6e31..aaeb2be39 100644 --- a/service/surge-reports/surge-report.json +++ b/service/surge-reports/surge-report.json @@ -52,27 +52,27 @@ "sectionTitle": "Client Disengagements", "indicators": [ { - "label": "Cumulative LTFUs (All LTFUs)", + "label": "Cumulative IITs (All IITs)", "description": "All patients who have missed their rtc more than 28 days", "indicator": "all_ltfus" }, { - "label": "Cumulative Surge LTFUs (LTFUs as from October 2020)", - "description": "All patients who became LTFUs as from October 2020 including those who have been resolved", + "label": "Cumulative Surge IITs (IITs as from October {{YEAR}})", + "description": "All patients who became IITs as from October {{YEAR}} including those who have been resolved", "indicator": "is_ltfu_after_may_total" }, { - "label": "Target to bring back this week (LTFUs as from October 2020 not yet resolved)", - "description": "All patients who became LTFUs as from October 2020 and have not been resolved", + "label": "Target to bring back this week (IITs as from October {{YEAR}} not yet resolved)", + "description": "All patients who became IITs as from October {{YEAR}} and have not been resolved", "indicator": "is_ltfu_after_may" }, { - "label": "Cumulative Medication refill LTFUs(Missed medication pickup rtc for more that 28 days)", + "label": "Cumulative Medication refill IITs(Missed medication pickup rtc for more that 28 days)", "description": "All patients who have missed their medication pickup rtc for more that 28 days as from October 2020 to now, including those with outcomes already", "indicator": "med_surge_ltfus_cumulative" }, { - "label": "Medication refill LTFUs not yet resolved", + "label": "Medication refill IITs not yet resolved", "description": "All patients who have missed their medication pickup rtc for more that 28 days as from October 2020 to now and have not been resolved yet", "indicator": "med_surge_ltfu_and_med_ltfu_after_may" }, @@ -102,12 +102,12 @@ "indicator": "med_defaulters" }, { - "label": "LTFUs this week (patients who became LTFU this week)", - "description": "Patients who became LTFU this week", + "label": "IITs this week (patients who became IIT this week)", + "description": "Patients who became IIT this week", "indicator": "newly_ltfu_this_week" }, { - "label": "Medication refill LTFUs this week(Missed medication pickup rtc date more than 28 days this week)", + "label": "Medication refill IITs this week(Missed medication pickup rtc date more than 28 days this week)", "description": "Patients who have missed their medication pickup rtc date for more than 28 days this week", "indicator": "newly_med_ltfu_this_week" }, @@ -124,7 +124,7 @@ ] }, { - "sectionTitle": "LTFU Outcomes this week(Surge LTFUs)", + "sectionTitle": "IIT Outcomes this week(Surge IITs)", "indicators": [ { "label": "Brought back to care", @@ -143,52 +143,52 @@ }, { "label": "Medication refill brought back this week", - "description": "Medication refill LTFUs that have been brought back this week", + "description": "Medication refill IITs that have been brought back this week", "indicator": "med_surge_ltfus_outcomes_this_week" } ] }, { - "sectionTitle": "LTFU cumulative outcome(Surge LTFUs)", + "sectionTitle": "IIT cumulative outcome(Surge IITs)", "indicators": [ { "label": "Cumulative Outcomes (brought back, self transfers and dead)", - "description": "surge LTFUs brought back, transfered out or those who are confirmed dead", + "description": "surge IITs brought back, transfered out or those who are confirmed dead", "indicator": "ltfu_cumulative_outcomes_total" }, { "label": "Brought back to care cumulative", - "description": "Total Surge LTFUs who were brought back to care", + "description": "Total Surge IITs who were brought back to care", "indicator": "ltfu_cumulative_outcomes_active" }, { "label": "Reported self transfered cumulative", - "description": "Total Surge LTFUs that have been reported self transfered", + "description": "Total Surge IITs that have been reported self transfered", "indicator": "ltfu_cumulative_outcomes_transfer_out" }, { "label": "Reported dead cumulative", - "description": "Total Surge LTFUs that have been confirmed dead", + "description": "Total Surge IITs that have been confirmed dead", "indicator": "ltfu_cumulative_outcomes_death" }, { "label": "Cumulative medication refill brought back", - "description": "All medication refill LTFUs that have been brought back", + "description": "All medication refill IITs that have been brought back", "indicator": "med_surge_ltfus_outcomes" } ] }, { - "sectionTitle": "LTFU Outcomes (clients lost before october 2019)", + "sectionTitle": "IIT Outcomes (clients lost before october {{YEAR}})", "indicators": [ { "label": "Returnees cumulative", - "description": "Patients who were LTFU before october 2019 and have returned", + "description": "Patients who were IIT before october {{YEAR}} and have returned", "indicator": "old_ltfus_to_active" }, { "label": "Returnees this week", - "description": "Patients who were LTFU before october 2019 and have returned this week", + "description": "Patients who were IIT before october {{YEAR}} and have returned this week", "indicator": "old_ltfus_to_active_this_week" } ] diff --git a/service/surge-reports/surge-report.service.js b/service/surge-reports/surge-report.service.js index 1aa800ff4..a20cffc26 100644 --- a/service/surge-reports/surge-report.service.js +++ b/service/surge-reports/surge-report.service.js @@ -3,11 +3,21 @@ import { SurgeMultiDatasetPatientlistReport } from './surge-multi-dataset-patien import { PatientlistMysqlReport } from '../../app/reporting-framework/patientlist-mysql.report'; const patientListCols = require('./surge-report-patientlist.json'); import moment from 'moment'; +const path = require('path'); +const fs = require('fs'); const helpers = require('../../etl-helpers'); const Promise = require('bluebird'); const _ = require('lodash'); -const surgeSectionDefinitions = require('./surge-report.json'); + +const filePath = path.join(__dirname, 'surge-report.json'); +const raw = fs.readFileSync(filePath, 'utf-8'); +const previousYear = new Date().getFullYear() - 1; + +// Replace all occurrences of {{YEAR}} with previous year +const replaced = raw.replace(/{{YEAR}}/g, previousYear); + +const surgeSectionDefinitions = JSON.parse(replaced); const surgeSchemaReportMap = require('./surge-indicators-config.json'); export class SurgeService extends SurgeMultiDatasetPatientlistReport { diff --git a/service/surge-reports/surge-service.js b/service/surge-reports/surge-service.js index 1a17bd0ea..b41d824f3 100644 --- a/service/surge-reports/surge-service.js +++ b/service/surge-reports/surge-service.js @@ -1,8 +1,17 @@ import { Promise } from 'bluebird'; +const path = require('path'); +const fs = require('fs'); import { MultiDatasetPatientlistReport } from '../../app/reporting-framework/multi-dataset-patientlist.report'; import ReportProcessorHelpersService from '../../app/reporting-framework/report-processor-helpers.service'; -const surgeDefs = require('./surge-report.json'); +const filePath = path.join(__dirname, 'surge-report.json'); +const raw = fs.readFileSync(filePath, 'utf-8'); +const previousYear = new Date().getFullYear() - 1; + +// Replace all occurrences of {{YEAR}} with previous year +const replaced = raw.replace(/{{YEAR}}/g, previousYear); + +const surgeDefs = JSON.parse(replaced); const dao = require('../../etl-dao'); export class SurgeReportService extends MultiDatasetPatientlistReport {