From 613237fd94deb3ce64d3d10fc205d52bff672cd0 Mon Sep 17 00:00:00 2001 From: himeshr Date: Mon, 16 Oct 2023 15:04:31 +0530 Subject: [PATCH] #1119 | If a memberSubjectType individual is voided, remove it from the membership list of all its groupSubjects --- .../IndividualRegistrationDetailsActions.js | 12 +++++++++--- .../src/service/GroupSubjectService.js | 8 ++++++++ .../src/service/IndividualService.js | 14 ++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js b/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js index 32c0dc38f..edb2c1bf1 100644 --- a/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js +++ b/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js @@ -9,13 +9,15 @@ import _ from 'lodash'; import SubjectProgramEligibilityService from "../../service/program/SubjectProgramEligibilityService"; import EntityService from "../../service/EntityService"; import FormMappingService from "../../service/FormMappingService"; +import GroupAffiliationState from '../../state/GroupAffiliationState'; class IndividualRegistrationDetailsActions { static getInitialState() { return { expand: false, subjectProgramEligibilityStatuses: [], - displayIndicator: false + displayIndicator: false, + groupAffiliationState: new GroupAffiliationState() }; } @@ -26,6 +28,9 @@ class IndividualRegistrationDetailsActions { const groupSubjects = context.get(GroupSubjectService).getGroupSubjects(individual); const subjectSummary = context.get(RuleEvaluationService).getSubjectSummary(individual, Individual.schema.name, context); const subjectProgramEligibilityStatuses = IndividualRegistrationDetailsActions.getSubjectProgramEligibilityStatuses(individual, context); + const groupAffiliationState = new GroupAffiliationState(); + context.get(GroupSubjectService).populateGroupsThatTheIndividualIsAMemberOf(individual, groupAffiliationState); + return { ...state, individual, @@ -36,7 +41,8 @@ class IndividualRegistrationDetailsActions { expandMembers: false, subjectSummary, isRelationshipTypePresent: individualRelationGenderMappings.length > 0, - subjectProgramEligibilityStatuses + subjectProgramEligibilityStatuses, + groupAffiliation: groupAffiliationState }; } @@ -53,7 +59,7 @@ class IndividualRegistrationDetailsActions { static voidUnVoidIndividual(state, action, beans) { const individualService = beans.get(IndividualService); - individualService.voidUnVoidIndividual(action.individualUUID, action.setVoided); + individualService.voidUnVoidIndividual(action.individualUUID, action.setVoided, state.groupAffiliation); action.cb(); return IndividualRegistrationDetailsActions.onLoad(state, action, beans); } diff --git a/packages/openchs-android/src/service/GroupSubjectService.js b/packages/openchs-android/src/service/GroupSubjectService.js index 5396f9f0c..059693984 100644 --- a/packages/openchs-android/src/service/GroupSubjectService.js +++ b/packages/openchs-android/src/service/GroupSubjectService.js @@ -66,6 +66,14 @@ class GroupSubjectService extends BaseService { .filtered('TRUEPREDICATE DISTINCT(groupSubject.uuid)') } + populateGroupsThatTheIndividualIsAMemberOf(memberSubject, groupAffiliationState) { + _.forEach(this.getAllGroups(memberSubject), groupSubject => { + if (!_.isNil(groupSubject)) { + groupAffiliationState.groupSubjectObservations.push({groupSubject}) + } + }) + } + getFirstGroupForMember(memberSubjectUUID, groupSubjectTypeUUID, groupSubjectRoleUUID) { const groupSubject = this.getAllNonVoided() .filtered('memberSubject.uuid = $0 and groupSubject.subjectType.uuid = $1 and groupRole.uuid = $2', memberSubjectUUID, groupSubjectTypeUUID, groupSubjectRoleUUID).map(_.identity); diff --git a/packages/openchs-android/src/service/IndividualService.js b/packages/openchs-android/src/service/IndividualService.js index 2c054c015..f57b8fe81 100644 --- a/packages/openchs-android/src/service/IndividualService.js +++ b/packages/openchs-android/src/service/IndividualService.js @@ -620,11 +620,21 @@ class IndividualService extends BaseService { } - voidUnVoidIndividual(individualUUID, setVoided) { + voidUnVoidIndividual(individualUUID, setVoided, groupAffiliation) { const individual = this.findByUUID(individualUUID); let individualClone = individual.cloneForEdit(); individualClone.voided = setVoided; - this.register(individualClone); + const groupSubjectObservations = this.updateGroupSubjectVoidedStatus(groupAffiliation, setVoided); + this.register(individualClone, [], undefined, groupSubjectObservations); + } + + updateGroupSubjectVoidedStatus(groupAffiliation, setVoided) { + const groupSubjectObservations = groupAffiliation.groupSubjectObservations.map(grpSubject => { + const clonedGrpSubject = {groupSubject: grpSubject.groupSubject.cloneForEdit()}; + clonedGrpSubject.groupSubject.voided = setVoided; + return clonedGrpSubject; + }) || []; + return groupSubjectObservations; } determineSubjectForVisitToBeScheduled(individual, nextScheduledVisit) {