Closed himeshr closed 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%';
-|----|---|--- 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
const phulwariName = _.get(_.find(programEnrolment.individual.affiliatedGroups, ({voided}) => !voided), ['groupSubject', 'firstName'], '');
const phulwariName = _.get(_.find(params.entityContext.affiliatedGroups, ({voided}) => !voided), ['groupSubject', 'firstName'], '');
@himeshr added to release card - https://github.com/avniproject/avni-client/issues/1021
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
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
We do not like the approach of using temporary variables for storing the affiliatedGroups information. All such details should be passed to the ruleEvaluationService as part of the entityContext object.
Also, in the Subject/ Person summary view, pass the required affiliatedGroups separately from state during invocation and dont expect it to be a temp variable in Individual.
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
New Rule snippet
Support ticket
https://avni.freshdesk.com/a/tickets/2925