Skip to content

Commit

Permalink
POC-473 (#1322)
Browse files Browse the repository at this point in the history
* Add conditional DC visits

* Fix typo

---------

Co-authored-by: kantush <sainingo>
Co-authored-by: Drizzentic <[email protected]>
  • Loading branch information
sainingo and drizzentic authored Sep 7, 2023
1 parent 96fb7bd commit 807886e
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions programs/scope-builder.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function buildScope(dataDictionary) {
retroSpective: false,
screenedForCovidToday: false
};
let isStandardDcVisit = false;

// Restrict to Pilot locations
scope.MlLocations = [
'08feb8ae-1352-11df-a1f1-0026b9348838',
Expand All @@ -32,6 +34,13 @@ 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);
}
Expand Down Expand Up @@ -61,10 +70,16 @@ function buildScope(dataDictionary) {
}

if (dataDictionary.dcQualifedVisits) {
if (dataDictionary.dcQualifedVisits.qualifies_for_standard_visit === 1) {
if (
dataDictionary.dcQualifedVisits.qualifies_for_standard_visit === 1 ||
isStandardDcVisit
) {
scope.qualifiesForStandardVisit = true;
}
if (dataDictionary.dcQualifedVisits.qualifies_for_medication_refill === 1) {
if (
dataDictionary.dcQualifedVisits.qualifies_for_medication_refill === 1 &&
!isStandardDcVisit
) {
scope.qualifiesMedicationRefillVisit = true;
}
}
Expand Down Expand Up @@ -148,6 +163,16 @@ function buildScope(dataDictionary) {
return scope;
}

function conditionalDCVisits(patient) {
// get the latest encounter by sorting the encounters by date
const patientEncounters = patient.patientEncounters;
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;
}

function buildPatientScopeMembers(scope, patient) {
scope.age = patient.person.age;
scope.gender = patient.person.gender;
Expand Down

0 comments on commit 807886e

Please sign in to comment.