diff --git a/packages/openchs-android/package.json b/packages/openchs-android/package.json index 5a3348059..5dc3674f1 100644 --- a/packages/openchs-android/package.json +++ b/packages/openchs-android/package.json @@ -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", diff --git a/packages/openchs-android/src/action/program/ProgramEncounterCancelState.js b/packages/openchs-android/src/action/program/ProgramEncounterCancelState.js index 66bde03ec..78311898f 100644 --- a/packages/openchs-android/src/action/program/ProgramEncounterCancelState.js +++ b/packages/openchs-android/src/action/program/ProgramEncounterCancelState.js @@ -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); } diff --git a/packages/openchs-android/src/state/AbstractDataEntryState.js b/packages/openchs-android/src/state/AbstractDataEntryState.js index 183f05e04..85cccd08e 100644 --- a/packages/openchs-android/src/state/AbstractDataEntryState.js +++ b/packages/openchs-android/src/state/AbstractDataEntryState.js @@ -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; diff --git a/packages/openchs-android/src/state/ProgramEncounterState.js b/packages/openchs-android/src/state/ProgramEncounterState.js index bc35a7150..71c785350 100644 --- a/packages/openchs-android/src/state/ProgramEncounterState.js +++ b/packages/openchs-android/src/state/ProgramEncounterState.js @@ -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); } diff --git a/packages/openchs-android/src/state/ProgramEnrolmentState.js b/packages/openchs-android/src/state/ProgramEnrolmentState.js index 382404d56..57a24bbd8 100644 --- a/packages/openchs-android/src/state/ProgramEnrolmentState.js +++ b/packages/openchs-android/src/state/ProgramEnrolmentState.js @@ -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) {