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

[DEA] Handle Async fetch of related entities during Rule Evaluation #1205

Open
Tracked by #1507 ...
himeshr opened this issue Apr 24, 2024 · 0 comments
Open
Tracked by #1507 ...

[DEA] Handle Async fetch of related entities during Rule Evaluation #1205

himeshr opened this issue Apr 24, 2024 · 0 comments
Labels
DEA Data Entry App

Comments

@himeshr
Copy link
Contributor

himeshr commented Apr 24, 2024

Motivation

As part of Epic avniproject/avni-product#1507 and Story #1171, we encountered an issue while evaluating rules for Goonj organisation, for creation of Distribution.
We are linking Activities to a distribution, by doing a search and select of Subject. This is then used within FormElement rule to initialize certain fields. For this purpose, we make use of individualService.getSubjectByUUID() call in the rules.

RuleEvaluationService in webapp has a problem while fetching a different individual using its uuid.
The rule written for client, assumes that individualServiceFacade will always be able to fetch the individual in a synchronous manner, which works fine there as its connected to the realm DB. But on the web-app, we need to fetch the individual from the backendServer asynchronously as a remote call.

This results in 2 Major behaviourial changes:

  1. Within any rule, whenever we need to fetch the Subject, we would need to figure out a way to handle the Promise returned by the async facade service fetch calls on the webapp, while simultaneously working correctly on the client in a synchronous manner.
  2. Provide ability to invoke RuleEvaluationService in an asynchronous manner, to be able to invoke an async call and resolve it.

Acceptance Criteria

We are able to run the same FormElement rule which uses following services methods in both webapp and client.

Service Methods

individualService.getSubjectByUUID
individualService.getSubjectsInLocation
addressLevelService.findAddressLevelByUUID

Tech Approach

Needs more Technical evaluation.
Current solutions for each of the above problem:

  1. In this scenario, we could run a string replace query on the rule content to replace all "individualService.getSubjectByUUID(" with "await individualService.getSubjectByUUID(" in webapp at runtime.
    Also, we need to make the rule function async by prefixing the keyword "async" only in webapp.

  2. For this, we would prefer to only make the RuleEvaluation related entities data init, update and rule execution to be encapsulated within the FormWizard and run in Asynchronous manner, while rest of the Webapp working as is in a synchronous manner.

Additional Information

The list of impacted Orgs and Elements with rules that need asynchronous api calls is as per below attached file.
InstancesOfRuleInDB.txt

@himeshr himeshr added the DEA Data Entry App label Apr 24, 2024
@mahalakshme mahalakshme changed the title Handle Async fetch of related entities during Rule Evaluation in DEA [DEA] Handle Async fetch of related entities during Rule Evaluation Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEA Data Entry App
Projects
Status: Focus Items
Development

No branches or pull requests

1 participant