diff --git a/service/cervical-cancer-screening-service.js b/service/cervical-cancer-screening-service.js index 27d6cd2da..e24a9de5a 100644 --- a/service/cervical-cancer-screening-service.js +++ b/service/cervical-cancer-screening-service.js @@ -7,21 +7,32 @@ const defs = { function getPatientLatestCericalScreeningResult(personId) { return new Promise((resolve, reject) => { - const sql = `SELECT - person_id, - test_datetime, - via_or_via_vili, - TIMESTAMPDIFF(YEAR,test_datetime,now()) AS 'years_since_last_via_or_via_vili_test', - CASE - WHEN TIMESTAMPDIFF(YEAR,test_datetime,now()) >= 1 THEN 1 - ELSE NULL - END AS 'qualifies_for_via_or_via_vili_retest' - FROM - etl.flat_labs_and_imaging - WHERE - via_or_via_vili IS NOT NULL AND person_id = ${personId} - ORDER BY test_datetime DESC LIMIT 1;`; - + const sql = `SELECT fli.person_id, + test_datetime, + via_or_via_vili, + TIMESTAMPDIFF(YEAR, test_datetime, NOW()) AS 'years_since_last_via_or_via_vili_test', + CASE + WHEN TIMESTAMPDIFF(YEAR, test_datetime, NOW()) >= 1 THEN 1 + ELSE NULL + END AS 'qualifies_for_via_or_via_vili_retest', + CASE + WHEN value_coded = 5276 THEN 1 + ELSE NULL + END AS 'has_hysterectomy_done' +FROM etl.flat_labs_and_imaging fli +LEFT JOIN +(SELECT person_id, + value_coded, + max(obs_datetime) latest_steralization_dt +FROM amrs.obs +WHERE value_coded = 5276 + AND person_id = ${personId} + AND voided = 0 +LIMIT 1) fs ON (fli.person_id = fs.person_id) +WHERE via_or_via_vili IS NOT NULL +AND fli.person_id = ${personId} +ORDER BY test_datetime DESC +LIMIT 1;`; const queryParts = { sql: sql }; diff --git a/service/patient-reminder.service.js b/service/patient-reminder.service.js index caa1530af..f8aa8b0d9 100755 --- a/service/patient-reminder.service.js +++ b/service/patient-reminder.service.js @@ -1147,7 +1147,10 @@ function getCerivalScreeningReminder(personId) { function generateCervicalScreeningReminder(data) { let reminders = []; - if (data.qualifies_for_via_or_via_vili_retest === 1) { + if ( + data.has_hysterectomy_done !== 1 && + data.qualifies_for_via_or_via_vili_retest === 1 + ) { reminders.push({ message: 'Patient is due for a repeat cervical cancer screening test. Last test result was Normal on ' +