Skip to content

Commit

Permalink
avni-client#1257 - applied logic to filter out already scheduled enco…
Browse files Browse the repository at this point in the history
…unter for program enrolment, program encounter cancel also.
  • Loading branch information
petmongrels committed Dec 28, 2023
1 parent 3d4168d commit 0b7ccf7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/openchs-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"lodash": "4.17.21",
"moment": "2.29.4",
"native-base": "3.4.9",
"openchs-models": "1.31.11",
"openchs-models": "1.31.12",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-native": "0.72.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ProgramEncounterCancelState extends AbstractDataEntryState {
}

getNextScheduledVisits(ruleService, context) {
const nextScheduledVisits = ruleService.getNextScheduledVisits(this.getEntity(), this.getEntityType());
const nextScheduledVisits = ruleService.getNextScheduledVisits(this.getEntity(), this.getEntityType()).filter((x) => this.isAlreadyScheduled(this.programEncounter.programEnrolment, x));
return context.get(IndividualService).validateAndInjectOtherSubjectForScheduledVisit(this.getEntity().individual, nextScheduledVisits);
}

Expand Down
9 changes: 9 additions & 0 deletions packages/openchs-android/src/state/AbstractDataEntryState.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ class AbstractDataEntryState {
getEntityResultSetByType(context) {
return []
}

isAlreadyScheduled(programEnrolment, newlyScheduledEncounter) {
//paranoid code
if (_.isNil(programEnrolment) || _.isNil(programEnrolment.everScheduledEncountersOfType)) return false;

return _.some(programEnrolment.everScheduledEncountersOfType(newlyScheduledEncounter.encounterType), (alreadyScheduledEncounter) => {
return General.datesAreSame(newlyScheduledEncounter.earliestDate, alreadyScheduledEncounter.earliestVisitDateTime) && General.datesAreSame(newlyScheduledEncounter.maxDate, alreadyScheduledEncounter.maxVisitDateTime) && newlyScheduledEncounter.name === alreadyScheduledEncounter.name;
});
}
}

export default AbstractDataEntryState;
6 changes: 1 addition & 5 deletions packages/openchs-android/src/state/ProgramEncounterState.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ class ProgramEncounterState extends AbstractDataEntryState {

getNextScheduledVisits(ruleService, context) {
const nextScheduledVisits = ruleService.getNextScheduledVisits(this.programEncounter, ProgramEncounter.schema.name, [])
.filter((x) => {
return !_.some(this.programEncounter.programEnrolment.everScheduledEncountersOfType(x.encounterType), (y) => {
return General.datesAreSame(x.earliestDate, y.earliestVisitDateTime) && General.datesAreSame(x.maxDate, y.maxVisitDateTime) && x.name === y.name;
});
})
.filter((x) => !this.isAlreadyScheduled(this.programEncounter.programEnrolment, x))
.map(k => _.assignIn({}, k));
return context.get(IndividualService).validateAndInjectOtherSubjectForScheduledVisit(this.programEncounter.individual, nextScheduledVisits);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/openchs-android/src/state/ProgramEnrolmentState.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ class ProgramEnrolmentState extends AbstractDataEntryState {

getNextScheduledVisits(ruleService, context) {
if (this.usage === ProgramEnrolmentState.UsageKeys.Enrol) {
const nextScheduledVisits = ruleService.getNextScheduledVisits(this.enrolment, ProgramEnrolment.schema.name, []);
const nextScheduledVisits = ruleService.getNextScheduledVisits(this.enrolment, ProgramEnrolment.schema.name, [])
.filter((x) => !this.isAlreadyScheduled(this.enrolment, x));
return context.get(IndividualService).validateAndInjectOtherSubjectForScheduledVisit(this.enrolment.individual, nextScheduledVisits);
} else {
return null;
}

}

static isInitialised(programEnrolmentState) {
Expand Down

0 comments on commit 0b7ccf7

Please sign in to comment.