From 3d4168d8000b914e3dfe0d0f245afc509a6fcbdd Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Wed, 27 Dec 2023 15:42:53 +0530 Subject: [PATCH 1/4] #1454 - check for matching program encounter visit before scheduling. match dates by considering server dates timezone. --- packages/openchs-android/package-lock.json | 14 +++++++------- packages/openchs-android/package.json | 2 +- .../src/state/ProgramEncounterState.js | 13 +++++++------ packages/openchs-android/src/utility/General.js | 8 +++++++- .../src/views/settings/DevSettingsView.js | 5 +++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/openchs-android/package-lock.json b/packages/openchs-android/package-lock.json index a38bfc6e7..2583ff915 100644 --- a/packages/openchs-android/package-lock.json +++ b/packages/openchs-android/package-lock.json @@ -33,7 +33,7 @@ "lodash": "4.17.21", "moment": "2.29.4", "native-base": "3.4.9", - "openchs-models": "1.31.8", + "openchs-models": "1.31.11", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", @@ -16433,9 +16433,9 @@ } }, "node_modules/openchs-models": { - "version": "1.31.8", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.8.tgz", - "integrity": "sha512-mXI4Q6ZqPICFyaiuCdwKl75lm2fpbVA/KXhs4dfcbCzjzh/28HOVIYqidGM2NvPMvitZ2p7r8vwHfTtrxasZcA==", + "version": "1.31.11", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.11.tgz", + "integrity": "sha512-KvjdfsdDucFeb6ufC8xlyHVwtfp8poVhGFfUF4U/zGT8CSYgsB+BxA8u7h7Lop0hI9Qvgzsc0fF1Ja6zjEJs6w==", "dependencies": { "uuid": "^9.0.1" }, @@ -35159,9 +35159,9 @@ } }, "openchs-models": { - "version": "1.31.8", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.8.tgz", - "integrity": "sha512-mXI4Q6ZqPICFyaiuCdwKl75lm2fpbVA/KXhs4dfcbCzjzh/28HOVIYqidGM2NvPMvitZ2p7r8vwHfTtrxasZcA==", + "version": "1.31.11", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.11.tgz", + "integrity": "sha512-KvjdfsdDucFeb6ufC8xlyHVwtfp8poVhGFfUF4U/zGT8CSYgsB+BxA8u7h7Lop0hI9Qvgzsc0fF1Ja6zjEJs6w==", "requires": { "uuid": "^9.0.1" } diff --git a/packages/openchs-android/package.json b/packages/openchs-android/package.json index be90dfddd..5a3348059 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.8", + "openchs-models": "1.31.11", "prop-types": "15.8.1", "react": "18.2.0", "react-native": "0.72.3", diff --git a/packages/openchs-android/src/state/ProgramEncounterState.js b/packages/openchs-android/src/state/ProgramEncounterState.js index 83f145cdc..bc35a7150 100644 --- a/packages/openchs-android/src/state/ProgramEncounterState.js +++ b/packages/openchs-android/src/state/ProgramEncounterState.js @@ -1,17 +1,13 @@ import AbstractDataEntryState from "./AbstractDataEntryState"; import Wizard from "./Wizard"; -import { - AbstractEncounter, - ObservationsHolder, - ProgramEncounter, - StaticFormElementGroup -} from "avni-models"; +import {AbstractEncounter, ObservationsHolder, ProgramEncounter, StaticFormElementGroup} from "avni-models"; import ConceptService from "../service/ConceptService"; import _ from 'lodash'; import IndividualService from "../service/IndividualService"; import EntityService from "../service/EntityService"; import ObservationHolderActions from "../action/common/ObservationsHolderActions"; import TimerState from "./TimerState"; +import General from "../utility/General"; class ProgramEncounterState extends AbstractDataEntryState { constructor(formElementGroup, wizard, isNewEntity, programEncounter, filteredFormElements, workLists, messageDisplayed, timerState, isFirstFlow) { @@ -109,6 +105,11 @@ 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; + }); + }) .map(k => _.assignIn({}, k)); return context.get(IndividualService).validateAndInjectOtherSubjectForScheduledVisit(this.programEncounter.individual, nextScheduledVisits); } diff --git a/packages/openchs-android/src/utility/General.js b/packages/openchs-android/src/utility/General.js index a1c2637cc..91845a234 100644 --- a/packages/openchs-android/src/utility/General.js +++ b/packages/openchs-android/src/utility/General.js @@ -200,8 +200,14 @@ class General { return new Date(date.getFullYear(), date.getMonth(), date.getDate()); } + static toISTDate(x) { + if (x.toString().includes("18:30:00")) + return moment(x).add(330, "m").toDate(); + return x; + } + static datesAreSame(a, b) { - return moment(a).isSame(moment(b), 'day'); + return moment(General.toISTDate(a)).isSame(moment(General.toISTDate(b)), 'day'); } static dateAIsAfterB(a, b) { diff --git a/packages/openchs-android/src/views/settings/DevSettingsView.js b/packages/openchs-android/src/views/settings/DevSettingsView.js index 15e39b25b..2bedc8b85 100644 --- a/packages/openchs-android/src/views/settings/DevSettingsView.js +++ b/packages/openchs-android/src/views/settings/DevSettingsView.js @@ -18,6 +18,7 @@ import RuleEvaluationService from "../../service/RuleEvaluationService"; import {Rule} from 'openchs-models'; import SelectableItemGroup from "../primitives/SelectableItemGroup"; import UserInfoService from "../../service/UserInfoService"; +import moment from "moment"; @Path('/devSettingsView') class DevSettingsView extends AbstractComponent { @@ -93,6 +94,10 @@ class DevSettingsView extends AbstractComponent { Server URL: this.dispatchAction(Actions.ON_SERVER_URL_CHANGE, {value: text})}/> + + Current App Time: + {moment().format("DD MMM YYYY hh:mm a")} + ); } } From 0b7ccf7bc7318f991be1fb7e9bbf0921b2ce0a4d Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 28 Dec 2023 11:48:30 +0530 Subject: [PATCH 2/4] avni-client#1257 - applied logic to filter out already scheduled encounter for program enrolment, program encounter cancel also. --- packages/openchs-android/package.json | 2 +- .../src/action/program/ProgramEncounterCancelState.js | 2 +- .../openchs-android/src/state/AbstractDataEntryState.js | 9 +++++++++ .../openchs-android/src/state/ProgramEncounterState.js | 6 +----- .../openchs-android/src/state/ProgramEnrolmentState.js | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) 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) { From 253f851ef99c59e325d2edf95ec5523fc1b07098 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 28 Dec 2023 11:55:53 +0530 Subject: [PATCH 3/4] avni-client#1257 - package lock --- packages/openchs-android/package-lock.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/openchs-android/package-lock.json b/packages/openchs-android/package-lock.json index 2583ff915..7bcc1e88b 100644 --- a/packages/openchs-android/package-lock.json +++ b/packages/openchs-android/package-lock.json @@ -33,7 +33,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", @@ -16433,9 +16433,9 @@ } }, "node_modules/openchs-models": { - "version": "1.31.11", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.11.tgz", - "integrity": "sha512-KvjdfsdDucFeb6ufC8xlyHVwtfp8poVhGFfUF4U/zGT8CSYgsB+BxA8u7h7Lop0hI9Qvgzsc0fF1Ja6zjEJs6w==", + "version": "1.31.12", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.12.tgz", + "integrity": "sha512-hgh6YD4IDX5pnotERIXSM5w99T+A5ly3odBut1laMWjfNkbDgeCDkdbrT+yHNHQwjcXCgxTy2OyN3BoZ1zlChg==", "dependencies": { "uuid": "^9.0.1" }, @@ -35159,9 +35159,9 @@ } }, "openchs-models": { - "version": "1.31.11", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.11.tgz", - "integrity": "sha512-KvjdfsdDucFeb6ufC8xlyHVwtfp8poVhGFfUF4U/zGT8CSYgsB+BxA8u7h7Lop0hI9Qvgzsc0fF1Ja6zjEJs6w==", + "version": "1.31.12", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.12.tgz", + "integrity": "sha512-hgh6YD4IDX5pnotERIXSM5w99T+A5ly3odBut1laMWjfNkbDgeCDkdbrT+yHNHQwjcXCgxTy2OyN3BoZ1zlChg==", "requires": { "uuid": "^9.0.1" } From 51f037a8777a219653622dbc1b9c28d2eaa0651a Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 28 Dec 2023 16:40:24 +0530 Subject: [PATCH 4/4] avni-client#1257 - ! in cancel as well --- .../src/action/program/ProgramEncounterCancelState.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/openchs-android/src/action/program/ProgramEncounterCancelState.js b/packages/openchs-android/src/action/program/ProgramEncounterCancelState.js index 78311898f..e6b9ff5f2 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()).filter((x) => this.isAlreadyScheduled(this.programEncounter.programEnrolment, x)); + 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); }