Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC-341: Revise Patient Requiring Viral Order report to Generate the … #1304

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"alias": "needs_vl_coded",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "CASE WHEN (ls.cur_arv_meds IS NULL) THEN 0 WHEN (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) > 3) AND ls.vl_1 > 1000 AND ls.arv_start_date < ls.vl_1_date THEN 1 WHEN ls.vl_1 > 200 AND (TIMESTAMPDIFF(MONTH,ls.vl_1_date,DATE('{referenceDate}')) > 3) THEN 2 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') >= 12) AND (ls.vl_2 IS NULL) THEN 3 WHEN (ls.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 6) THEN 4 WHEN (t1.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND ls.vl_1 >= 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 3) THEN 5 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') = 3) AND (ls.vl_1_date IS NULL) THEN 6 WHEN (ls.cur_arv_meds <> ls.prev_arv_meds) AND ls.prev_arv_meds IS NOT NULL THEN 7 WHEN ls.vl_1 < 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) >= 12) THEN 8 ELSE 0 END"
"expression": "CASE WHEN (ls.cur_arv_meds IS NULL) THEN 0 WHEN (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) > 3) AND ls.vl_1 > 1000 AND ls.arv_start_date < ls.vl_1_date THEN 1 WHEN ls.vl_1 > 200 AND (TIMESTAMPDIFF(MONTH,ls.vl_1_date,DATE('{referenceDate}')) > 3) THEN 2 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') >= 12) AND (ls.vl_2 IS NULL) THEN 3 WHEN (ls.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 6) THEN 4 WHEN (t1.is_pregnant OR (t6.relationship = 2 AND TIMESTAMPDIFF(MONTH, t6.date_created, '{referenceDate}') BETWEEN 0 AND 24)) AND ls.vl_1 >= 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, '{referenceDate}') >= 3) THEN 5 WHEN (TIMESTAMPDIFF(MONTH, ls.arv_start_date, '{referenceDate}') = 3) AND (ls.vl_1_date IS NULL) THEN 6 WHEN (ls.cur_arv_meds <> ls.prev_arv_meds) AND ls.prev_arv_meds IS NOT NULL AND TIMESTAMPDIFF(MONTH, ls.encounter_datetime, DATE('{referenceDate}')) >= 3 THEN 7 WHEN ls.vl_1 < 200 AND (TIMESTAMPDIFF(MONTH, ls.vl_1_date, DATE('{referenceDate}')) >= 12) THEN 8 ELSE 0 END"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@
},
{
"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 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.hiv_viral_load is not null)",
"alias": "fli_latest_vl",
"alias": "fli1",
"join": {
"type": "LEFT",
"joinCondition": "fli_latest_vl.person_id = dcr.person_id"
}
},
{
"table": "etl.flat_patient_identifiers_v1",
"alias": "flat_identifiers",
"join": {
"type": "LEFT",
"joinCondition": "dcr.person_id = flat_identifiers.patient_id"
"joinCondition": "fli1.person_id = dcr.person_id"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{
"filterType": "tableColumns",
"conditionExpression": "(t1.next_clinical_datetime_hiv is null or date(t1.next_clinical_datetime_hiv) > ?)",
"parameterName": "endDate"
"parameterName": "reportMonth"
},
{
"filterType": "tableColumns",
Expand Down
98 changes: 28 additions & 70 deletions app/reporting-framework/json-reports/labs-report-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,46 @@
"sources": [
{
"table": "etl.flat_hiv_summary_v15b",
"alias": "t2"
"alias": "fhs"
},
{
"table": "etl.flat_patient_identifiers_v1",
"alias": "flat_identifiers",
"join": {
"type": "LEFT",
"joinCondition": "t2.person_id = flat_identifiers.patient_id"
}
},
{
"table": "amrs.location",
"alias": "l",
"table": "(SELECT a.person_id, MAX(encounter_id) AS max_encounter_id FROM etl.flat_hiv_summary_v15b a LEFT JOIN amrs.person p ON p.person_id = a.person_id WHERE p.dead = 0 and p.birthdate is not null GROUP BY a.person_id)",
"alias": "max_encounters",
"join": {
"type": "INNER",
"joinCondition": "t2.location_uuid = l.uuid"
"joinCondition": "fhs.person_id = max_encounters.person_id AND fhs.encounter_id = max_encounters.max_encounter_id"
}
},
{
"table": "amrs.person",
"alias": "t3",
"alias": "p",
"join": {
"type": "INNER",
"joinCondition": "t3.person_id = t2.person_id"
"joinCondition": "p.person_id = fhs.person_id"
}
},
{
"table": "amrs.person_attribute",
"alias": "contacts",
"join": {
"type": "LEFT",
"joinCondition": "t2.person_id = contacts.person_id AND (contacts.voided IS NULL || contacts.voided = 0) AND contacts.person_attribute_type_id in (10, 48)"
}
},
{
"table": "amrs.encounter_type",
"alias": "et",
"table": "etl.flat_patient_identifiers_v1",
"alias": "flat_identifiers",
"join": {
"type": "LEFT",
"joinCondition": "t2.encounter_type = et.encounter_type_id"
"joinCondition": "fhs.person_id = flat_identifiers.patient_id"
}
},
{
"table": "amrs.person_address",
"alias": "pa",
"table": "amrs.location",
"alias": "l",
"join": {
"type": "LEFT",
"joinCondition": "t2.person_id = pa.person_id"
"type": "INNER",
"joinCondition": "fhs.location_uuid = l.uuid"
}
}
],
"columns": [
{
"type": "simple_column",
"alias": "person_id",
"column": "t2.person_id"
},
{
"type": "derived_column",
"alias": "needs_vl_in_period",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "if(case when (t2.cur_arv_meds is not null and t2.vl_1 > 1000) and (timestampdiff(day,t2.vl_1_date, '{endDate}') >= 90) then true when (timestampdiff(month,t2.arv_start_date, '{endDate}') <= 12) and (t2.vl_1_date is null or timestampdiff(month,t2.vl_1_date, '{endDate}') >= 6) and (timestampdiff(month,t2.arv_start_date, '{endDate}')>=6) then true when (timestampdiff(month,t2.arv_start_date, '{endDate}') >= 12) and (t2.vl_1_date is null or timestampdiff(month,t2.vl_1_date, '{endDate}') >= 12) then true else false end,1,0)"
}
"column": "fhs.person_id"
},
{
"type": "simple_column",
Expand All @@ -89,80 +65,62 @@
},
{
"type": "simple_column",
"alias": "location",
"column": "l.name"
"alias": "location_id",
"column": "fhs.location_id"
},
{
"type": "simple_column",
"alias": "location_id",
"column": "t2.location_id"
"alias": "location",
"column": "l.name"
},
{
"type": "simple_column",
"alias": "location_uuid",
"column": "t2.location_uuid"
"column": "fhs.location_uuid"
},
{
"type": "simple_column",
"alias": "encounter_datetime",
"column": "t2.encounter_datetime"
"column": "fhs.encounter_datetime"
},
{
"type": "simple_column",
"alias": "month",
"column": "MONTH(t2.encounter_datetime)"
"column": "MONTH(fhs.encounter_datetime)"
},
{
"type": "simple_column",
"alias": "reporting_month",
"column": "date_format(t2.encounter_datetime, '%m/%Y')"
"column": "date_format(fhs.encounter_datetime, '%m/%Y')"
},
{
"type": "simple_column",
"alias": "year",
"column": "YEAR(t2.encounter_datetime)"
},
{
"type": "derived_column",
"alias": "phone_number",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": " GROUP_CONCAT(DISTINCT contacts.value SEPARATOR ', ')"
}
"column": "YEAR(fhs.encounter_datetime)"
},
{
"type": "simple_column",
"alias": "latest_rtc_date",
"column": "date_format(t2.rtc_date, '%Y-%m-%d')"
},
{
"type": "simple_column",
"alias": "last_appointment",
"column": "CONCAT(COALESCE(DATE_FORMAT(t2.encounter_datetime, '%Y-%m-%d'),''),' ',COALESCE(et.name, ''))"
"column": "date_format(fhs.rtc_date, '%Y-%m-%d')"
},
{
"type": "simple_column",
"alias": "cur_meds",
"column": "t2.cur_arv_meds"
"column": "fhs.cur_arv_meds"
}
],
"filters": {
"conditionJoinOperator": "and",
"conditions": [
{
"filterType": "tableColumns",
"conditionExpression": "(t2.next_clinical_datetime_hiv is null or date(t2.next_clinical_datetime_hiv) > ?)",
"parameterName": "endDate"
},
{
"filterType": "tableColumns",
"conditionExpression": "t2.location_uuid in ?",
"conditionExpression": "fhs.location_uuid in ? AND fhs.transfer_out is null AND fhs.out_of_care is null",
"parameterName": "locationUuids"
},
{
"filterType": "tableColumns",
"conditionExpression": "coalesce(t2.death_date, t2.out_of_care) is null",
"parameterName": ""
"conditionExpression": "(TIMESTAMPDIFF(YEAR, p.birthdate, DATE('{reportMonth}')) BETWEEN 0 AND 24 AND ((TIMESTAMPDIFF(MONTH, fhs.arv_start_date, DATE('{reportMonth}')) >= 3 AND fhs.vl_1 IS NULL AND fhs.arv_start_date) OR (TIMESTAMPDIFF(MONTH, fhs.vl_1_date, '{reportMonth}') >= 6 AND fhs.vl_1 IS NOT NULL AND fhs.vl_1_date IS NOT NULL))) OR (TIMESTAMPDIFF(YEAR, p.birthdate, DATE('{reportMonth}')) >= 25 AND ((TIMESTAMPDIFF(MONTH, fhs.arv_start_date, DATE('{reportMonth}')) >= 3 AND fhs.arv_start_date IS NOT NULL AND fhs.vl_1 IS NULL) OR (TIMESTAMPDIFF(MONTH, fhs.arv_start_date, DATE('{reportMonth}')) >= 12 AND fhs.arv_start_date IS NOT NULL AND fhs.vl_1 IS NOT NULL AND fhs.vl_2 IS NULL) OR (TIMESTAMPDIFF(MONTH, fhs.vl_1_date, DATE('{reportMonth}')) >= 12 AND fhs.vl_1 IS NOT NULL AND fhs.vl_2 IS NOT NULL AND fhs.vl_1_date IS NOT NULL AND fhs.vl_1 < 200) OR (TIMESTAMPDIFF(MONTH, fhs.vl_1_date, DATE('{reportMonth}')) >= 3 AND fhs.vl_1 IS NOT NULL AND fhs.vl_2 IS NOT NULL AND fhs.vl_1_date IS NOT NULL AND fhs.vl_1 >= 200) OR ((fhs.is_pregnant = 1 OR fhs.is_mother_breastfeeding = 1) AND TIMESTAMPDIFF(MONTH, fhs.vl_1_date, DATE('{reportMonth}')) >= 6 AND fhs.vl_1_date IS NOT NULL))) OR (fhs.prev_arv_meds <> fhs.cur_arv_meds AND TIMESTAMPDIFF(MONTH, fhs.encounter_datetime, DATE('{reportMonth}')) >= 3)",
"parameterName": "reportMonth"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"table": "amrs.person_name",
"alias": "person_name",
"join": {
"type": "INNER",
"type": "LEFT",
"joinCondition": "t1.person_id = person_name.person_id AND (person_name.voided IS NULL || person_name.voided = 0) AND person_name.preferred = 1"
}
},
Expand All @@ -32,20 +32,12 @@
"joinCondition": "t1.person_id = contact.person_id AND (contact.voided IS NULL || contact.voided = 0) AND contact.person_attribute_type_id in (10, 48)"
}
},
{
"table": "etl.flat_hiv_summary_v15b",
"alias": "fhsh",
"join": {
"type": "LEFT",
"joinCondition": "t1.person_id = fhsh.person_id AND fhsh.next_clinical_location_id IS NULL AND fhsh.encounter_type NOT IN (99999) "
}
},
{
"table": "amrs.encounter_type",
"alias": "ety",
"join": {
"type": "LEFT",
"joinCondition": "fhsh.encounter_type = ety.encounter_type_id"
"joinCondition": "fhs.encounter_type = ety.encounter_type_id"
}
},
{
Expand Down Expand Up @@ -107,39 +99,39 @@
"alias": "has_pending_vl_test",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "case when (timestampdiff(day,t2.vl_order_date,now()) between 0 and 14) and (t2.vl_1_date is null or t2.vl_order_date > t2.vl_1_date) then true else false end"
"expression": "case when (timestampdiff(day,fhs.vl_order_date,now()) between 0 and 14) and (fhs.vl_1_date is null or fhs.vl_order_date > fhs.vl_1_date) then true else false end"
}
},
{
"type": "derived_column",
"alias": "current_vl",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "t2.vl_1 "
"expression": "fhs.vl_1 "
}
},
{
"type": "derived_column",
"alias": "current_vl_date",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "date_format(t2.vl_1_date,'%d-%m-%Y')"
"expression": "date_format(fhs.vl_1_date,'%d-%m-%Y')"
}
},
{
"type": "derived_column",
"alias": "last_vl_order_date",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "date_format(t2.vl_order_date,'%d-%m-%Y')"
"expression": "date_format(fhs.vl_order_date,'%d-%m-%Y')"
}
},
{
"type": "derived_column",
"alias": "days_since_last_order",
"expressionType": "simple_expression",
"expressionOptions": {
"expression": "timestampdiff(day, t2.vl_order_date, now())"
"expression": "timestampdiff(day, fhs.vl_order_date, now())"
}
},
{
Expand All @@ -153,12 +145,12 @@
{
"type": "simple_column",
"alias": "latest_rtc_date",
"column": "date_format(fhsh.rtc_date, '%Y-%m-%d')"
"column": "date_format(fhs.rtc_date, '%Y-%m-%d')"
},
{
"type": "simple_column",
"alias": "latest_vl",
"column": "fhsh.vl_1"
"column": "fhs.vl_1"
},
{
"type": "derived_column",
Expand All @@ -167,19 +159,19 @@
"expressionOptions": {
"caseOptions": [
{
"condition": "fhsh.vl_1 < 50",
"condition": "fhs.vl_1 < 50",
"value": "LDL"
},
{
"condition": "(fhsh.vl_1 >= 50 and fhsh.vl_1 < 200)",
"condition": "(fhs.vl_1 >= 50 and fhs.vl_1 < 200)",
"value": "Low Risk Low Level Viremia"
},
{
"condition": "(fhsh.vl_1 >= 200 and fhsh.vl_1 < 1000)",
"condition": "(fhs.vl_1 >= 200 and fhs.vl_1 < 1000)",
"value": "High Risk Low Level Viremia"
},
{
"condition": "(fhsh.vl_1 > 1000)",
"condition": "(fhs.vl_1 > 1000)",
"value": "Suspected Treatment Failure"
}
]
Expand All @@ -188,27 +180,27 @@
{
"type": "simple_column",
"alias": "latest_vl_date",
"column": "date_format(fhsh.vl_1_date, '%Y-%m-%d')"
"column": "date_format(fhs.vl_1_date, '%Y-%m-%d')"
},
{
"type": "simple_column",
"alias": "last_appointment",
"column": "CONCAT(COALESCE(DATE_FORMAT(fhsh.encounter_datetime, '%Y-%m-%d'),''),' ',COALESCE(ety.name, ''))"
"column": "CONCAT(COALESCE(DATE_FORMAT(fhs.encounter_datetime, '%Y-%m-%d'),''),' ',COALESCE(ety.name, ''))"
},
{
"type": "simple_column",
"alias": "cur_meds",
"column": "fhsh.cur_arv_meds"
"column": "fhs.cur_arv_meds"
},
{
"type": "simple_column",
"alias": "previous_vl",
"column": "fhsh.vl_2"
"column": "fhs.vl_2"
},
{
"type": "simple_column",
"alias": "previous_vl_date",
"column": "date_format(fhsh.vl_2_date, '%Y-%m-%d')"
"column": "date_format(fhs.vl_2_date, '%Y-%m-%d')"
},
{
"type": "simple_column",
Expand Down
3 changes: 3 additions & 0 deletions etl-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4375,6 +4375,9 @@ module.exports = (function () {
endDate: Joi.string()
.optional()
.description('The end date to filter by'),
reportMonth: Joi.string()
.required()
.description('The report month in the format "YYYY-MM-DD"'),
startIndex: Joi.number()
.required()
.description('The startIndex to control pagination'),
Expand Down
Loading