From d7948f6ff72f7fc3c160caafe14d4a9a39e2da00 Mon Sep 17 00:00:00 2001 From: kantush Date: Tue, 3 Jun 2025 12:16:00 +0300 Subject: [PATCH 1/3] fix: Continuing DC clients does not show the correct visit after the introduction of the new dc models --- programs/scope-builder.service.js | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/programs/scope-builder.service.js b/programs/scope-builder.service.js index 1c0b1b287..a11505f5b 100755 --- a/programs/scope-builder.service.js +++ b/programs/scope-builder.service.js @@ -431,15 +431,21 @@ function validateMedicationRefillEligibility(validateMedicationRefill) { const icadAnswerUuid = '7e5e7759-e9f7-4b16-b904-041fcdddb390'; + // Version 2.0 cutoff date + const VERSION_2_CUTOFF_DATE = new Date('2025-05-02'); + let isEligibleForMedicationRefill = false; let isEligibleForCommunityVisit = false; + let hasMedicationRefillConcept = false; + // Check if the new concepts exist in observations for (const obs of validateMedicationRefill.obs) { const conceptUuid = obs.concept?.uuid; if (!conceptUuid) continue; if (conceptUuid === conceptMap.medicationRefillEligibility) { + hasMedicationRefillConcept = true; isEligibleForMedicationRefill = true; } @@ -451,9 +457,34 @@ function validateMedicationRefillEligibility(validateMedicationRefill) { } } + // Backwards compatibility logic for medicationRefillEligibility + if (!hasMedicationRefillConcept) { + const encounterDate = new Date(validateMedicationRefill.encounterDatetime); + + // For encounters before version 2.0, default to eligible for medication refill + // This maintains the previous workflow where this validation didn't exist + if (encounterDate < VERSION_2_CUTOFF_DATE) { + isEligibleForMedicationRefill = true; + console.log( + 'Legacy encounter detected - defaulting medicationRefill eligibility to true' + ); + } + // For newer encounters without the concept + else { + console.warn( + 'Recent encounter missing medicationRefillEligibility concept' + ); + isEligibleForMedicationRefill = false; + } + } + return { medicationRefill: isEligibleForMedicationRefill, - communityVisit: isEligibleForCommunityVisit + communityVisit: isEligibleForCommunityVisit, + isLegacyEncounter: + !hasMedicationRefillConcept && + new Date(validateMedicationRefill.encounterDatetime) < + VERSION_2_CUTOFF_DATE }; } From 6c35d38c2b029fdde5d2058718cd1a94e7564e31 Mon Sep 17 00:00:00 2001 From: kantush Date: Tue, 3 Jun 2025 13:30:37 +0300 Subject: [PATCH 2/3] Fix: Add requested changes --- programs/patient-program-config.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/programs/patient-program-config.json b/programs/patient-program-config.json index 5c25e815d..24aef3dfd 100755 --- a/programs/patient-program-config.json +++ b/programs/patient-program-config.json @@ -2980,8 +2980,8 @@ "visitTypes": [ { "uuid": "0becf5b9-0522-47c8-960c-c9d660c56501", - "name": "Facilty Medication Delivery Visit", - "allowedIf": "qualifiesMedicationRefillVisit && isEligibleForMedicationRefill", + "name": "Facility Medication Refill Visit", + "allowedIf": "programLocation === intendedVisitLocationUuid && qualifiesMedicationRefillVisit && isEligibleForMedicationRefill", "message": "Patient has to be in the location he enrolled into the HIV Care and Treatment program ", "encounterTypes": [ { @@ -3309,7 +3309,7 @@ { "uuid": "3c1906a1-6d85-4184-9a43-0912cbac3d74", "name": "Community Medication Delivery Visit", - "allowedIf": "qualifiesMedicationRefillVisit && isEligibleForCommunityVisit", + "allowedIf": "programLocation === intendedVisitLocationUuid && qualifiesMedicationRefillVisit && isEligibleForCommunityVisit", "message": "Patient has to be in the location he enrolled into the HIV Care and Treatment program ", "encounterTypes": [ { @@ -3320,7 +3320,7 @@ }, { "uuid": "a2a265dc-508d-4f31-94ee-0bf8a58049d7", - "name": "HCW-Peer Delivery Visit", + "name": "HCW/Peer Delivery Visit", "allowedIf": "!isEligibleForCommunityVisit", "encounterTypes": [ { From 640884205bb488f7c9764af0dee0d378613e546f Mon Sep 17 00:00:00 2001 From: kantush Date: Wed, 4 Jun 2025 19:07:48 +0300 Subject: [PATCH 3/3] Fix: Include Youth Return on the validation --- programs/patient-data-resolver.service.js | 7 +++++-- programs/patient-program-config.json | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/programs/patient-data-resolver.service.js b/programs/patient-data-resolver.service.js index 5bb7fa37f..8a04056cc 100755 --- a/programs/patient-data-resolver.service.js +++ b/programs/patient-data-resolver.service.js @@ -119,7 +119,10 @@ function checkTransferOut(patientUuid, params) { } function getMedicationRefillVisits(patientUuid) { - const expectedAdultReturnEncounter = '8d5b2be0-c2cc-11de-8d13-0010c6dffd0f'; + const expectedEncounters = [ + '8d5b2be0-c2cc-11de-8d13-0010c6dffd0f', + '4e7553b4-373d-452f-bc89-3f4ad9a01ce7' + ]; const patientEncounters = encounterService.getPatientEncounters({ patientUuid, @@ -134,7 +137,7 @@ function getMedicationRefillVisits(patientUuid) { .filter( (encounter) => encounter.encounterType && - encounter.encounterType.uuid === expectedAdultReturnEncounter + expectedEncounters.includes(encounter.encounterType.uuid) ) .sort( (a, b) => diff --git a/programs/patient-program-config.json b/programs/patient-program-config.json index 24aef3dfd..93955e2cc 100755 --- a/programs/patient-program-config.json +++ b/programs/patient-program-config.json @@ -736,8 +736,8 @@ }, { "uuid": "a2a265dc-508d-4f31-94ee-0bf8a58049d7", - "name": "HCW-Peer Delivery Visit", - "allowedIf": "!isEligibleForCommunityVisit", + "name": "HCW/Peer Delivery Visit", + "allowedIf": "!isEligibleForCommunityVisit && !isFirstAMPATHHIVVisit", "encounterTypes": [ { "uuid": "987009c6-6f24-43f7-9640-c285d6553c63", @@ -3321,7 +3321,7 @@ { "uuid": "a2a265dc-508d-4f31-94ee-0bf8a58049d7", "name": "HCW/Peer Delivery Visit", - "allowedIf": "!isEligibleForCommunityVisit", + "allowedIf": "!isEligibleForCommunityVisit && !isFirstAMPATHHIVVisit", "encounterTypes": [ { "uuid": "987009c6-6f24-43f7-9640-c285d6553c63",