avniproject / avni-models

Avni data model to be used by front end clients
https://avniproject.org
GNU Affero General Public License v3.0
1 stars 4 forks source link

Unable to get affiliatedGroups for Individual #48

Closed himeshr closed 1 year ago

himeshr commented 1 year ago

Background info

In Jss Phulwari programs, "Child enrolment" form, ..

Issue

During EnrolmentId FormElement rule execution, we fail to fetch affiliatedGroups, resulting in "Enrolment ID" not being set.

Rule snippet

const phulwariName = _.get(_.find(programEnrolment.individual.affiliatedGroups, ({voided}) => !voided), ['groupSubject', 'firstName'], '');

Root Cause

After ReactNative upgrade, we are not able to access temp property affiliatedGroups in Individual from enrolment during ProgramEnrolment Create / edit. This is due to the fact that, individual returned for enrolment.individual is the realmDb object, which is fetched fresh from db.

Therefore the rule fails to fetch affiliatedGroups on individual of an enrolment, and therefore "Enrolment ID" generation fails.

Possible fix

~We cannot convert temp property affiliatedGroups to persistent value of individual, as the individual does not get saved duing enrolment form filling. Therefore the only solution is to switch to using Enrolment to store the temp property affiliatedGroups and modify the Rules suitably. This has already been tested to work in dev environment.~

Final solution after pairing with Vinay

Code changes impact following scenarios, which should be verified during testing:

Post release steps

After the release, Support team would need to modify all rules that refer to "individual.affiliatedGroups" to instead use "params.entityContext.affiliatedGroups".

Old Rule snippet

const phulwariName = _.get(_.find(programEnrolment.individual.affiliatedGroups, ({voided}) => !voided), ['groupSubject', 'firstName'], '');

New Rule snippet

const phulwariName = _.get(_.find(params.entityContext.affiliatedGroups, ({voided}) => !voided), ['groupSubject', 'firstName'], '');

Support ticket

https://avni.freshdesk.com/a/tickets/2925

himeshr commented 1 year ago

This code change would require change in rules for following FormElements across multiple organisations:

select o.name, form_element.name, form_element.uuid from form_element join organisation o on form_element.organisation_id = o.id where rule like '%nrolment.individual.affiliatedGroups%';

|name|name|uuid

-|----|---|--- 1|JSSCP UAT|Enrolment ID|a2628836-c7cb-4557-ad21-eb2172f07f2d 2|JSS Singrauli UAT|Enrolment ID|cb2328f2-8245-446e-89ca-b6e2f58ea700 3|JSSCP|Enrolment ID|a2628836-c7cb-4557-ad21-eb2172f07f2d 4|JSS|Enrolment ID|cb2328f2-8245-446e-89ca-b6e2f58ea700 5|JSSCP Support|Enrolment ID|a2628836-c7cb-4557-ad21-eb2172f07f2d 6|Achala Test|Enrolment ID|a2628836-c7cb-4557-ad21-eb2172f07f2d 7|JSSCP UAT NEW|Enrolment ID|a2628836-c7cb-4557-ad21-eb2172f07f2d 8|Mobile creches|Enrolment ID|cb2328f2-8245-446e-89ca-b6e2f58ea700

Old Rule snippet

const phulwariName = _.get(_.find(programEnrolment.individual.affiliatedGroups, ({voided}) => !voided), ['groupSubject', 'firstName'], '');

New Rule snippet

const phulwariName = _.get(_.find(params.entityContext.affiliatedGroups, ({voided}) => !voided), ['groupSubject', 'firstName'], '');

Support ticket

https://avni.freshdesk.com/a/tickets/2925

vinayvenu commented 1 year ago

@himeshr added to release card - https://github.com/avniproject/avni-client/issues/1021

himeshr commented 1 year ago

Dev testing done on staging environment for :

  1. Subject registration summary has GroupAffiliation msg (Phulwari org)
  2. Enrolment to program has Enrolment ID auto generated based on GroupAffiliation (JSS SIngrauli org)

Attached screen shots for the same:

EnrolmentIdAutoGenerationBasedOnGroup SubjectRegistrationSummaryGroupAffiliationMsg