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-473 #1322

Merged
merged 3 commits into from
Sep 7, 2023
Merged

POC-473 #1322

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
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
Loading