diff --git a/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js b/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js index 30819b4e6..55d604650 100644 --- a/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js +++ b/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js @@ -44,8 +44,7 @@ class IndividualRegistrationDetailsActions { subjectSummary, isRelationshipTypePresent: individualRelationGenderMappings.length > 0, subjectProgramEligibilityStatuses, - groupAffiliation: groupAffiliationState, - editFormRuleResponse: EditFormRuleResponse.createEditAllowedResponse() + groupAffiliation: groupAffiliationState }; } @@ -54,7 +53,7 @@ class IndividualRegistrationDetailsActions { const editFormRuleResponse = context.get(RuleEvaluationService).runEditFormRule(registrationForm, state.individual, 'Individual'); const newState = {...state}; if (editFormRuleResponse.isEditAllowed()) - action.formEditAllowed(); + action.continueRegistrationEdit(); else newState.editFormRuleResponse = editFormRuleResponse; return newState; diff --git a/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js b/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js index 58f2c7120..fa5bb7fed 100644 --- a/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js +++ b/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js @@ -1,13 +1,5 @@ import EntityService from "../../service/EntityService"; -import { - Encounter, - NullProgramEnrolment, - ProgramEncounter, - ProgramEnrolment, - WorkItem, - WorkList, - WorkLists -} from 'avni-models'; +import {Encounter, NullProgramEnrolment, ProgramEncounter, ProgramEnrolment, WorkItem, WorkList, WorkLists} from 'avni-models'; import _ from 'lodash'; import EntityTypeChoiceState from "../common/EntityTypeChoiceState"; import FormMappingService from "../../service/FormMappingService"; @@ -22,6 +14,7 @@ import UserInfoService from "../../service/UserInfoService"; import ProgramEnrolmentService from "../../service/ProgramEnrolmentService"; import IndividualService from "../../service/IndividualService"; import {firebaseEvents, logEvent} from "../../utility/Analytics"; +import {EditFormRuleResponse} from "rules-config"; class ProgramEnrolmentDashboardActions { static setEncounterType(encounterType) { @@ -41,7 +34,8 @@ class ProgramEnrolmentDashboardActions { encounterTypes: [], displayActionSelector: false, expandEnrolmentInfo: false, - completedEncounters: [] + completedEncounters: [], + editFormRuleResponse: EditFormRuleResponse.createEditAllowedResponse() }; } @@ -78,19 +72,10 @@ class ProgramEnrolmentDashboardActions { static clone(state) { return { + ...state, programEncounterTypeState: state.programEncounterTypeState.clone(), - enrolment: state.enrolment, encounter: state.encounter.cloneForEdit(), - encounterTypes: state.encounterTypes.slice(), - displayActionSelector: state.displayActionSelector, - programsAvailable: state.programsAvailable, - showCount: state.showCount, - dashboardButtons: state.dashboardButtons, - enrolmentSummary: state.enrolmentSummary, - hideExit: state.hideExit, - hideEnrol: state.hideEnrol, - expandEnrolmentInfo: state.expandEnrolmentInfo, - completedEncounters: state.completedEncounters, + encounterTypes: state.encounterTypes.slice() }; } @@ -106,9 +91,7 @@ class ProgramEnrolmentDashboardActions { const enrolment = ProgramEnrolmentDashboardActions._getEnrolment(newState, context, individualUUID, enrolmentUUID); newState.completedEncounters = _.filter(enrolment.nonVoidedEncounters(), (encounter) => encounter.encounterDateTime || encounter.cancelDateTime) .map(encounter => ({encounter, expand: false})); - let onEnrolmentChange = ProgramEnrolmentDashboardActions._onEnrolmentChange(newState, context, enrolment); - - return onEnrolmentChange; + return ProgramEnrolmentDashboardActions._onEnrolmentChange(newState, context, enrolment); } static onLanding(state, action, context) { @@ -166,9 +149,6 @@ class ProgramEnrolmentDashboardActions { return newState; } - //Program Encounter Type - - //Encounter Type static launchChooseEncounterType(state, action, context) { const newState = ProgramEnrolmentDashboardActions.clone(state); newState.encounterTypeState.launchChooseEntityType(); @@ -193,12 +173,20 @@ class ProgramEnrolmentDashboardActions { return newState; } - //Encounter Type - static onEditEnrolment(state, action, context) { logEvent(firebaseEvents.EDIT_ENROLMENT); const enrolment = context.get(EntityService).findByUUID(state.enrolment.uuid, ProgramEnrolment.schema.name); - let workLists = new WorkLists( + + const form = context.get(FormMappingService).findFormForProgramEnrolment(enrolment.program, enrolment.individual.subjectType); + const editFormRuleResponse = context.get(RuleEvaluationService).runEditFormRule(form, enrolment, 'ProgramEnrolment'); + + if (!editFormRuleResponse.isEditAllowed()) { + const newState = {...state}; + newState.editFormRuleResponse = editFormRuleResponse; + return newState; + } + + const workLists = new WorkLists( new WorkList('Enrolment', [new WorkItem(General.randomUUID(), WorkItem.type.PROGRAM_ENROLMENT, @@ -207,13 +195,22 @@ class ProgramEnrolmentDashboardActions { programName: enrolment.program.name, }) ])); - action.cb(enrolment, workLists); + action.continueEnrolmentEdit(enrolment, workLists); return state; } static onEditEnrolmentExit(state, action, context) { logEvent(firebaseEvents.EDIT_PROGRAM_EXIT); const enrolment = context.get(EntityService).findByUUID(state.enrolment.uuid, ProgramEnrolment.schema.name); + + const form = context.get(FormMappingService).findFormForProgramExit(enrolment.program, enrolment.individual.subjectType); + const editFormRuleResponse = context.get(RuleEvaluationService).runEditFormRule(form, enrolment, 'ProgramEnrolment'); + if (!editFormRuleResponse.isEditAllowed()) { + const newState = {...state}; + newState.editFormRuleResponse = editFormRuleResponse; + return newState; + } + const workLists = new WorkLists( new WorkList('Exit', [new WorkItem(General.randomUUID(), @@ -223,7 +220,7 @@ class ProgramEnrolmentDashboardActions { programName: enrolment.program.name, }) ])); - action.cb(enrolment, workLists); + action.continueEditExit(enrolment, workLists); return state; } diff --git a/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js b/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js index 4c746d756..d57e48673 100644 --- a/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js +++ b/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js @@ -128,7 +128,7 @@ class SubjectDashboardProfileTab extends AbstractComponent { editProfile() { logEvent(firebaseEvents.EDIT_SUBJECT); this.dispatchAction(Actions.ON_EDIT_START, { - formEditAllowed: () => { + continueRegistrationEdit: () => { CHSNavigator.navigateToRegisterView(this, { workLists: new WorkLists( new WorkList(`${this.state.individual.subjectType.name} `, diff --git a/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js b/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js index de917dd02..780f98901 100644 --- a/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js +++ b/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js @@ -1,4 +1,4 @@ -import {Alert, ScrollView, TouchableOpacity, View} from "react-native"; +import {Alert, ScrollView, ToastAndroid, TouchableOpacity, View} from "react-native"; import PropTypes from 'prop-types'; import React from "react"; import AbstractComponent from "../../framework/view/AbstractComponent"; @@ -67,13 +67,13 @@ class SubjectDashboardProgramsTab extends AbstractComponent { editEnrolment(pageNumber) { this.dispatchAction(Actions.ON_EDIT_ENROLMENT, { - cb: (enrolment, workLists) => CHSNavigator.navigateToProgramEnrolmentView(this, enrolment, workLists, true, pageNumber) + continueEnrolmentEdit: (enrolment, workLists) => CHSNavigator.navigateToProgramEnrolmentView(this, enrolment, workLists, true, pageNumber) }); } editExit(pageNumber) { this.dispatchAction(Actions.ON_EDIT_ENROLMENT_EXIT, { - cb: (enrolment, workLists) => CHSNavigator.navigateToExitProgram(this, enrolment, workLists, true, pageNumber) + continueEditExit: (enrolment, workLists) => CHSNavigator.navigateToExitProgram(this, enrolment, workLists, true, pageNumber) }); } @@ -256,6 +256,7 @@ class SubjectDashboardProgramsTab extends AbstractComponent { primaryAction={this.getPrimaryEnrolmentContextAction(hasExitPrivilege)}/> + {this.state.editFormRuleResponse.isEditDisallowed() && ToastAndroid.show(this.state.editFormRuleResponse.getMessageKey(), ToastAndroid.SHORT)} ); }