Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get affiliatedGroups for Individual #48

Closed
Tracked by #1021
himeshr opened this issue Aug 4, 2023 · 3 comments
Closed
Tracked by #1021

Unable to get affiliatedGroups for Individual #48

himeshr opened this issue Aug 4, 2023 · 3 comments
Assignees
Labels
bug Something isn't working user reported

Comments

@himeshr
Copy link
Contributor

himeshr commented Aug 4, 2023

Background info

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

  • We determine the Phulwari to be associated based on village name
  • AffiliationGroups are set for the Individual using the GroupAffiliation FormElement
  • in the EnrolmentId FormElement, we have a rule that fetches the affiliatedGroups. It then uses the villageName, PhulwariName(extracted from affiliatedGroups) and GeneratedID (From IdSource) to come up with final Enrolment ID.

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

  • 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:

  • Subject registration summary has GroupAffiliation msg (Phulwari org, Individual subject registration)
  • Enrolment to program has Enrolment ID auto generated based on GroupAffiliation (JSS SIngrauli org, Child enrolment)

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

@nupoorkhandelwal nupoorkhandelwal added bug Something isn't working user reported labels Aug 4, 2023
@himeshr himeshr self-assigned this Aug 4, 2023
himeshr added a commit to avniproject/avni-client that referenced this issue Aug 4, 2023
himeshr added a commit to avniproject/avni-webapp that referenced this issue Aug 4, 2023
himeshr added a commit to avniproject/rules-server that referenced this issue Aug 4, 2023
himeshr added a commit to avniproject/avni-client that referenced this issue Aug 4, 2023
himeshr added a commit to avniproject/rules-server that referenced this issue Aug 4, 2023
himeshr added a commit to avniproject/avni-webapp that referenced this issue Aug 4, 2023
himeshr added a commit that referenced this issue Aug 4, 2023
himeshr added a commit to avniproject/avni-client that referenced this issue Aug 10, 2023
himeshr added a commit to avniproject/avni-client that referenced this issue Aug 10, 2023
…ationView.js from Person and Subject Register views
@himeshr
Copy link
Contributor Author

himeshr commented Aug 11, 2023

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
Copy link
Member

@himeshr added to release card - avniproject/avni-client#1021

himeshr added a commit to avniproject/avni-client that referenced this issue Aug 11, 2023
himeshr added a commit to avniproject/avni-client that referenced this issue Aug 11, 2023
@himeshr
Copy link
Contributor Author

himeshr commented Aug 11, 2023

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

himeshr added a commit to avniproject/rules-server that referenced this issue Aug 11, 2023
himeshr added a commit to avniproject/avni-webapp that referenced this issue Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working user reported
Projects
Archived in project
Development

No branches or pull requests

3 participants