diff --git a/departments/department-programs-config.json b/departments/department-programs-config.json index 69208766e..09fcbc9e6 100755 --- a/departments/department-programs-config.json +++ b/departments/department-programs-config.json @@ -186,6 +186,14 @@ { "uuid": "52aeb285-fb18-455b-893e-3e53ccc77ceb", "name": "ANTENATAL CARE PROGRAM" + }, + { + "uuid": "d2552058-d7bd-47c6-aed1-480a4308027a", + "name": "POSTNATAL CARE PROGRAM" + }, + { + "uuid": "01948855-8491-4164-b54f-9b16d174d93e", + "name": "MATERNITY CARE PROGRAM" } ] } diff --git a/programs/patient-program-config.json b/programs/patient-program-config.json index 1c28551ea..f907ab0bb 100755 --- a/programs/patient-program-config.json +++ b/programs/patient-program-config.json @@ -5341,5 +5341,70 @@ ] } ] + }, + "d2552058-d7bd-47c6-aed1-480a4308027a": { + "name": "POSTNATAL CARE PROGRAM", + "dataDependencies": [ + "patient", + "enrollment", + "patientEncounters", + "patientEnrollment" + ], + "incompatibleWith": [], + "visitTypes": [ + { + "uuid": "b1a978ca-9315-4ba2-ac2b-84efb9a68c5c", + "name": "PMTCT Postnatal Initial Visit", + "allowedIf": "programLocation === intendedVisitLocationUuid && isFirstPNCVisit && gender==='F'", + "encounterTypes": [ + { + "uuid": "ded4ecf7-8129-4a9e-8aa3-a21a7adb7759", + "display": "PNCADULTINITIAL" + }, + { + "uuid": "a44ad5e2-b3ec-42e7-8cfa-8ba3dbcf5ed7", + "display": "HIVTRIAGE" + } + ] + }, + { + "uuid": "0b1b6194-d2d5-4e4b-9f7c-c3b778ccc354", + "name": "PMTCT Postnatal Return Visit", + "allowedIf": "programLocation === intendedVisitLocationUuid && !isFirstPNCVisit && gender==='F'", + "encounterTypes": [ + { + "uuid": "ded4ecf7-8129-4a9e-8aa3-a21a7adb7759", + "display": "PNCADULTRETURN" + }, + { + "uuid": "db215741-de99-424a-a109-1f23eb3b680b", + "display": "HIVTRIAGE" + } + ] + } + ] + }, + "01948855-8491-4164-b54f-9b16d174d93e": { + "name": "MATERNITY PROGRAM", + "dataDependencies": [ + "patient", + "enrollment", + "patientEncounters", + "patientEnrollment" + ], + "incompatibleWith": [], + "visitTypes": [ + { + "uuid": "5dd2b2c7-66cc-4cd8-b1ce-ca8fc0189a12", + "name": "Maternity Visit", + "allowedIf": "programLocation === intendedVisitLocationUuid && gender==='F'", + "encounterTypes": [ + { + "uuid": "2b928d9b-84ce-4777-9658-3fba6248b3bc", + "display": "LABORANDDELIVERY" + } + ] + } + ] } } diff --git a/programs/scope-builder.service.js b/programs/scope-builder.service.js index 42c200684..35053914a 100755 --- a/programs/scope-builder.service.js +++ b/programs/scope-builder.service.js @@ -76,7 +76,7 @@ function buildScope(dataDictionary) { dataDictionary.patientEncounters, dataDictionary.programUuid ); - buildANCScopeMembers( + buildMNCHScopeMembers( scope, dataDictionary.patientEncounters, dataDictionary.patientEnrollment @@ -269,30 +269,34 @@ function isInitialPMTCTVisit(patientEncounters) { return initialPMTCTEncounters.length === 0; } -function isInitialANCVisit(patientEncounters, patientEnrollment) { - const initialANCEncounterUuid = 'f5702679-6a16-43bd-8629-4b44c7a78ff1'; // ANC Initial - let initialANCEncounters = _.filter(patientEncounters, (encounter) => { - return initialANCEncounterUuid === encounter.encounterType.uuid; +function isInitialVisit( + patientEncounters, + patientEnrollment, + programUuid, + encounterUuid +) { + let initialEncounters = _.filter(patientEncounters, (encounter) => { + return encounterUuid === encounter.encounterType.uuid; }); const activeEnrollments = _.filter(patientEnrollment, { dateCompleted: null }); - let isEnrolledinANC = false; + let isEnrolled = false; let dateEnrolled = ''; activeEnrollments.forEach((item) => { - if (item.program.uuid === '52aeb285-fb18-455b-893e-3e53ccc77ceb') { - isEnrolledinANC = true; + if (item.program.uuid === programUuid) { + isEnrolled = true; dateEnrolled = item.dateEnrolled; } }); - // get latest initial encounter and compare with dateenrolled to check wether it's a new enrollment - let latestEnc = initialANCEncounters[initialANCEncounters.length - 1]; + // get latest initial encounter and compare with dateenrolled to check whether it's a new enrollment + let latestEnc = initialEncounters[initialEncounters.length - 1]; if ( - initialANCEncounters.length > 0 && + initialEncounters.length > 0 && dateEnrolled > latestEnc.encounterDatetime ) { return true; - } else if (initialANCEncounters.length === 0) { + } else if (initialEncounters.length === 0) { return true; } else { return false; @@ -386,16 +390,20 @@ function buildOncologyScopeMembers(scope, patientEncounters, programUuid) { programUuid ); } -function buildANCScopeMembers(scope, patientEncounters, programEnrollment) { +function buildMNCHScopeMembers(scope, patientEncounters, programEnrollment) { // If the client has not exited the antenatal program show return visit if they have an initial encounter - scope.isFirstANCVisit = isInitialANCVisit( + scope.isFirstANCVisit = isInitialVisit( patientEncounters, - programEnrollment + programEnrollment, + '52aeb285-fb18-455b-893e-3e53ccc77ceb', + 'f5702679-6a16-43bd-8629-4b44c7a78ff1' ); - console.log( - 'Output', - isInitialANCVisit(patientEncounters, programEnrollment) + scope.isFirstPNCVisit = isInitialVisit( + patientEncounters, + programEnrollment, + 'd2552058-d7bd-47c6-aed1-480a4308027a', + 'ded4ecf7-8129-4a9e-8aa3-a21a7adb7759' ); } function isInitialHivVisit(patientEncounters) {