From d77b4b6bce752eb4413f8e83cb95766aae166cd3 Mon Sep 17 00:00:00 2001 From: Saningo Lekalantula Date: Mon, 11 Sep 2023 12:42:52 +0300 Subject: [PATCH] Error loading retention visit (#1326) Co-authored-by: kantush --- programs/scope-builder.service.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/programs/scope-builder.service.js b/programs/scope-builder.service.js index 938c977a6..bf5bfaa3f 100755 --- a/programs/scope-builder.service.js +++ b/programs/scope-builder.service.js @@ -34,13 +34,6 @@ function buildScope(dataDictionary) { buildPatientScopeMembers(scope, dataDictionary.patient); } - if (dataDictionary.patient) { - const result = conditionalDCVisits(dataDictionary); - if (result) { - isStandardDcVisit = true; - } - } - if (dataDictionary.enrollment) { buildProgramScopeMembers(scope, dataDictionary.enrollment); } @@ -70,6 +63,10 @@ function buildScope(dataDictionary) { } if (dataDictionary.dcQualifedVisits) { + const result = conditionalDCVisits(dataDictionary); + if (result) { + isStandardDcVisit = true; + } if ( dataDictionary.dcQualifedVisits.qualifies_for_standard_visit === 1 || isStandardDcVisit @@ -169,8 +166,11 @@ function conditionalDCVisits(patient) { const latestEncounter = getLatestEncounter(patientEncounters); const expectedEncounterToBeDrugPickup = '987009c6-6f24-43f7-9640-c285d6553c63'; - // return true if the latest encounter is a drug pickup - return latestEncounter.encounterType.uuid === expectedEncounterToBeDrugPickup; + if (latestEncounter) { + return ( + latestEncounter.encounterType.uuid === expectedEncounterToBeDrugPickup + ); + } } function buildPatientScopeMembers(scope, patient) {