Skip to content

Commit

Permalink
Merge branch 'AMPATH:master' into POC-341
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Mutai authored Jan 19, 2024
2 parents 312ecee + 342a720 commit da02f2d
Show file tree
Hide file tree
Showing 99 changed files with 107,759 additions and 507 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "none",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
54 changes: 54 additions & 0 deletions app/otz/cohort-module.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var db = require('../../etl-db');

export class CohortModuleService {
getCohortSummary = (cohortUuids) => {
const uuids = cohortUuids
.split(',')
.map((s) => {
return `"${s}"`;
})
.join(',');
return new Promise((resolve, reject) => {
let queryParts = {};
const sql = `SELECT
c.uuid,
COUNT(DISTINCT cm.patient_id) AS total_patients,
IFNULL(SUM(CASE
WHEN fl.hiv_viral_load < 200 THEN 1
ELSE 0
END) / NULLIF(COUNT(DISTINCT cm.patient_id), 0) * 100,
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
(SELECT
person_id, MAX(test_datetime) AS latest_test_datetime
FROM
etl.flat_labs_and_imaging
WHERE
hiv_viral_load IS NOT NULL
GROUP BY person_id) AS latest_tests ON cm.patient_id = latest_tests.person_id
LEFT JOIN
etl.flat_labs_and_imaging fl ON latest_tests.person_id = fl.person_id
AND latest_tests.latest_test_datetime = fl.test_datetime
WHERE
l.uuid = '${cohortUuids}'
GROUP BY c.cohort_id;
`;

queryParts = {
sql: sql
};

return db.queryServer(queryParts, function (result) {
result.sql = sql;
resolve(result);
});
});
};
}
344 changes: 340 additions & 4 deletions app/reporting-framework/base-mysql.report.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/reporting-framework/hiv/moh-731.report.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Moh731Report extends MultiDatasetPatientlistReport {
}
params.hivMonthlyDatasetSource = 'etl.hiv_monthly_report_dataset_frozen'; // defaults to frozen
params.hivVlDataSource =
'(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)';
'(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)';
console.log('creating new moh 731 report service');
super(reportName, params);
}
Expand Down
52 changes: 50 additions & 2 deletions app/reporting-framework/json-reports/clinical-reminder-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"alias": "t1"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down Expand Up @@ -79,6 +79,14 @@
"joinCondition": "mwl.person_id = t1.person_id"
}
},
{
"table": "etl.pre_appointment_summary",
"alias": "pre_s",
"join": {
"type": "left",
"joinCondition": "mwl.person_id = pre_s.person_id "
}
},
{
"table": "amrs.relationship",
"alias": "t6",
Expand Down Expand Up @@ -222,13 +230,43 @@
{
"type": "simple_column",
"alias": "last_encounter_date",
"column": "ls.encounter_datetime"
"column": "t1.encounter_datetime"
},
{
"type": "simple_column",
"alias": "latest_CD4_Date",
"column": "ls.cd4_1_date"
},
{
"type": "simple_column",
"alias": "ipt_start_date",
"column": "ls.ipt_start_date"
},
{
"type": "simple_column",
"alias": "ipt_stop_date",
"column": "ls.ipt_stop_date"
},
{
"type": "simple_column",
"alias": "on_ipt",
"column": "ls.on_ipt"
},
{
"type": "simple_column",
"alias": "ipt_completion_date",
"column": "ls.ipt_completion_date"
},
{
"type": "simple_column",
"alias": "tb_tx_start_date",
"column": "ls.tb_tx_start_date"
},
{
"type": "simple_column",
"alias": "tb_tx_end_date",
"column": "ls.tb_tx_end_date"
},
{
"type": "simple_column",
"alias": "on_tb_tx",
Expand Down Expand Up @@ -305,6 +343,16 @@
"alias": "prediction_generated_date",
"column": "mwl.prediction_generated_date"
},
{
"type": "simple_column",
"alias": "reschedule_appointment",
"column": "pre_s.reschedule_appointment"
},
{
"type": "simple_column",
"alias": "rescheduled_date",
"column": "pre_s.rescheduled_date"
},
{
"type": "simple_column",
"alias": "test_date",
Expand Down
18 changes: 17 additions & 1 deletion app/reporting-framework/json-reports/defaulter-list-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
"alias": "de",
"join": {
"type": "LEFT",
"joinCondition": "de.encounter_id = fd.encounter_id"
"joinCondition": "de.encounter_id = fd.encounter_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",
"joinCondition": "am.patient_id = fd.person_id"
}
},
{
Expand Down Expand Up @@ -82,6 +90,14 @@
"type": "simple_column",
"alias": "rtc_date",
"column": "DATE_FORMAT(fd.rtc_date,'%Y-%m-%d')"
},
{
"type": "derived_column",
"alias": "outreach_follow_up",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "case when max_encounter_datetime >= fd.rtc_date then 'Yes' else 'No' end"
}
}
],
"filters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,23 @@
"alias": "pre",
"join": {
"type": "LEFT",
"joinCondition": "pre.person_id = ml.person_id"
"joinCondition": "pre.person_id = ml.person_id and(DATEDIFF(ml.start_date, pre.encounter_datetime) <= 7)"
}
},
{
"table": "( select max(is_successful_phone_follow_up) as latest_phone_follow_up, person_id, follow_up_type from etl.pre_appointment_summary group by person_id )",
"alias": "s",
"join": {
"type": "LEFT",
"joinCondition": "pre.person_id = s.person_id"
}
},
{
"table": "(SELECT et.person_id, SUM(CASE WHEN et.is_successful_phone_follow_up = 'YES' THEN 0 WHEN et.is_successful_phone_follow_up = 'NO' THEN 1 ELSE 0 END) AS counter FROM etl.pre_appointment_summary et left join predictions.ml_weekly_predictions mwl on et.person_id = mwl.person_id WHERE et.encounter_datetime BETWEEN mwl.prediction_generated_date AND DATE_ADD(mwl.prediction_generated_date, INTERVAL 14 DAY) GROUP BY et.person_id)",
"alias": "etc",
"join": {
"type": "LEFT",
"joinCondition": "ml.person_id = etc.person_id"
}
}
],
Expand Down Expand Up @@ -156,9 +172,14 @@
"alias": "was_follow_up_successful",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "if((pre.is_successful_phone_follow_up = 'YES' OR (pre.attempted_home_visit = 'YES' AND pre.was_client_found = 'YES')), 1, 0)"
"expression": "if((latest_phone_follow_up = 'YES' OR (pre.attempted_home_visit = 'YES' AND pre.was_client_found = 'YES')), 1, 0)"
}
},
{
"type": "simple_column",
"alias": "number_of_failed_phone_attempts",
"column": "etc.counter"
},
{
"type": "simple_column",
"alias": "comments",
Expand All @@ -180,14 +201,19 @@
},
{
"filterType": "tableColumns",
"conditionExpression": "(if((pre.is_successful_phone_follow_up = 'YES' OR (pre.attempted_home_visit = 'YES' AND pre.was_client_found = 'YES')), 1, 0)) = ?",
"conditionExpression": "(if((latest_phone_follow_up = 'YES' OR (pre.attempted_home_visit = 'YES' AND pre.was_client_found = 'YES')), 1, 0)) = ?",
"parameterName": "successfulOutcome"
},
{
"filterType": "tableColumns",
"conditionExpression": "(if((pre.is_successful_phone_follow_up = 'NO' OR (pre.attempted_home_visit = 'YES' AND pre.was_client_found = 'NO')), 1, 0)) = ?",
"conditionExpression": "(if((latest_phone_follow_up = 'NO' OR (pre.attempted_home_visit = 'YES' AND pre.was_client_found = 'NO')), 1, 0)) = ?",
"parameterName": "failedOutcome"
},
{
"filterType": "tableColumns",
"conditionExpression": "(if((pre.is_successful_phone_follow_up IS NULL AND pre.attempted_home_visit IS NULL AND pre.was_client_found IS NULL), 0, 1)) = ?",
"parameterName": "unknownOutcome"
},
{
"filterType": "tableColumns",
"conditionExpression": "ml.predicted_risk is not null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"alias": "t1"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"alias": "t1"
},
{
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.encounter_id = max_dates.encounter_id)",
"table": "(SELECT fli.person_id, fli.hiv_viral_load as vl_1, fli.test_datetime as vl_1_date FROM etl.flat_labs_and_imaging fli INNER JOIN (SELECT person_id, MAX(test_datetime) AS max_vl_1_date,max(encounter_id) as encounter_id FROM etl.flat_labs_and_imaging fli where fli.hiv_viral_load is not null GROUP BY person_id) max_dates ON fli.person_id = max_dates.person_id AND fli.test_datetime = max_dates.max_vl_1_date AND fli.encounter_id = max_dates.encounter_id)",
"alias": "fli",
"join": {
"type": "LEFT",
Expand Down Expand Up @@ -103,6 +103,14 @@
"type": "LEFT",
"joinCondition": "delivery_report.person_id = t1.person_id and DATE_FORMAT(delivery_report.date_created, '%Y-%m-%d')='{startDate}'"
}
},
{
"table": "etl.flat_prep_summary_v1_1",
"alias": "fps",
"join": {
"type": "LEFT",
"joinCondition": "t1.person_id = fps.person_id AND fps.next_encounter_datetime IS NULL AND fps.encounter_type NOT IN (99999)"
}
}
],
"columns": [
Expand Down Expand Up @@ -142,6 +150,112 @@
"expression": "extract(year from (from_days(datediff(now(),t1.birthdate))))"
}
},
{
"type": "simple_column",
"alias": "prev_rtc_date",
"column": "date_format(fps.prev_rtc_date, '%Y-%m-%d')"
},
{
"type": "simple_column",
"alias": "cur_prep_meds_names",
"column": "fps.cur_prep_meds_names"
},
{
"type": "simple_column",
"alias": "rapid_test_date",
"column": "date_format(fps.hiv_rapid_test_date, '%Y-%m-%d')"
},
{
"type": "derived_column",
"alias": "hiv_rapid_test",
"expressionType": "case_statement",
"expressionOptions": {
"caseOptions": [
{
"condition": "fps.hiv_rapid_test_result = 703",
"value": "Positive"
},
{
"condition": "fps.hiv_rapid_test_result = 664",
"value": "Negative"
},
{
"condition": "fps.hiv_rapid_test_result = 1138",
"value": "Indeterminate"
},
{
"condition": "fps.hiv_rapid_test_result = 1304",
"value": "Poor sample quality"
},
{
"condition": "fps.hiv_rapid_test_result = 1067",
"value": "Unknown"
}
]
}
},
{
"type": "derived_column",
"alias": "population_type_category",
"expressionType": "case_statement",
"expressionOptions": {
"caseOptions": [
{
"condition": "fps.sub_population_type = 1",
"value": "MSM"
},
{
"condition": "fps.sub_population_type = 2",
"value": "MSW"
},
{
"condition": "fps.sub_population_type = 3",
"value": "FSW"
},
{
"condition": "fps.sub_population_type = 4",
"value": "IDU"
},
{
"condition": "fps.sub_population_type = 5",
"value": "TRANS WOMAN"
},
{
"condition": "fps.sub_population_type = 6",
"value": "TRANS MAN"
},
{
"condition": "fps.sub_population_type = 7",
"value": "FISHER FOLK"
},
{
"condition": "fps.sub_population_type = 8",
"value": "CSW"
},
{
"condition": "fps.sub_population_type = 9",
"value": "DISPLACED PERSONS"
},
{
"condition": "fps.sub_population_type = 10",
"value": "Military and other"
},
{
"condition": "fps.sub_population_type = 12",
"value": "TRUCK/LORRY DRIVER"
},
{
"condition": "fps.sub_population_type = 13",
"value": "NIDU"
}
]
}
},
{
"type": "simple_column",
"alias": "enrollment_date",
"column": "date_format(fps.enrollment_date, '%Y-%m-%d')"
},
{
"type": "derived_column",
"alias": "person_name",
Expand Down
Loading

0 comments on commit da02f2d

Please sign in to comment.