Skip to content

Commit

Permalink
#1454 - check for matching program encounter visit before scheduling.…
Browse files Browse the repository at this point in the history
… match dates by considering server dates timezone.
  • Loading branch information
petmongrels committed Dec 27, 2023
1 parent d2cfbed commit 3d4168d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
14 changes: 7 additions & 7 deletions packages/openchs-android/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.8",
"openchs-models": "1.31.11",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-native": "0.72.3",
Expand Down
13 changes: 7 additions & 6 deletions packages/openchs-android/src/state/ProgramEncounterState.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 7 additions & 1 deletion packages/openchs-android/src/utility/General.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -93,6 +94,10 @@ class DevSettingsView extends AbstractComponent {
<Text>Server URL:</Text>
<TextInput value={settings.serverURL} onChangeText={(text) => this.dispatchAction(Actions.ON_SERVER_URL_CHANGE, {value: text})}/>
</View>
<View style={{marginBottom: 20}}>
<Text>Current App Time:</Text>
<Text>{moment().format("DD MMM YYYY hh:mm a")}</Text>
</View>
</View>);
}
}
Expand Down

0 comments on commit 3d4168d

Please sign in to comment.