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

enable when expression can access variable #2132

Merged

Conversation

FikriMilano
Copy link
Collaborator

@FikriMilano FikriMilano commented Aug 14, 2023

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #2096 #2094

Description
Provide proper contextMap when evaluating the following:

  • enableWhenExpression can access variablesMap and launchContextMap
  • variableExpression can access launchContextMap

Alternative(s) considered
N/A

Type
Feature

Video

Demo.webm

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project.
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally.
  • I have built and run the demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

- enableWhenExpression can access variablesMap and launchContextMap
- variableExpression can access launchContextMap
@FikriMilano
Copy link
Collaborator Author

hello this is ready for review

@FikriMilano
Copy link
Collaborator Author

Copy link
Collaborator

@MJ1998 MJ1998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have too many parameter dependencies in functions. Lot of parameters are constant for a specific questionnaire session, for example, questionnaire, questionnaireItemParentMap, questionnaireLaunchContextMap.

What we can do is create a constructor based EnablementEvaluator & ExpressionEvaluator which takes in the above parameters. And maintain an object of these in the QuestionnaireViewModel. Then for each APIs in EnablementEvaluator & ExpressionEvaluator we won't need to pass those parameters. Think about this.

ndegwamartin added a commit to opensrp/android-fhir that referenced this pull request Aug 23, 2023
- With unmerged PR google#2032
- With unmerged PR #1
- With unmerged PR google#1669
- With unmerged PR google#2132
- With unmerged PR #9
ndegwamartin added a commit to opensrp/android-fhir that referenced this pull request Aug 23, 2023
- With unmerged PR google#2032
- With unmerged PR #1
- With unmerged PR google#1669
- With unmerged PR google#2132
ndegwamartin added a commit to opensrp/android-fhir that referenced this pull request Aug 28, 2023
    - With unmerged PR google#2032
    - With unmerged PR #1
    - With unmerged PR google#1669
    - With unmerged PR google#2132
    - With unmerged PR #9
    - With unmerged PR google#2076
    - With unmerged PR #10
@FikriMilano
Copy link
Collaborator Author

@MJ1998 I like the idea, makes sense 👍

- ExpressionEvaluator, EnablementEvaluator, EnabledAnswerOptionsEvaluator.

- Moving the params from method to class constructor for easier use of methods by having less params.
Out of topic, my hands can't resist fixing this issue.
@jingtang10
Copy link
Collaborator

is this ready for review fikri?

@FikriMilano
Copy link
Collaborator Author

@jingtang10 updating the kotlin doc is the only thing left

@jingtang10
Copy link
Collaborator

Some small changes I've just applied - and ran spotless. Thanks again @FikriMilano for this great PR!

@jingtang10 jingtang10 enabled auto-merge (squash) September 11, 2023 14:51
@jingtang10
Copy link
Collaborator

Thanks @FikriMilano expressionEvaluator.API() or enablementEvaluator.API() invocations look really good. ExpressionEvaluator having questionnaireLaunchContextMap makes perfect sense because then EnablementEvaluator can use expressionEvaluator without having the knowledge of questionnaireLaunchContextMap. Great work with refactoring.

But I think all these APIs should have questionnaireResponse and it should not be a part of ExpressionEvaluator constructor parameters. This is how I think: In a Questionnaire session whenever an answer is changed and we calculate an expression we need to provide it the expression (obviously), the questionnaireItem it's part of, the questionnaireResponse (as it changes after every user input) and all the other static variables you have rightfully put as constructor parameters (questionnaire, launchContext, itemParentMap). Hence questionnaireResponse should go in API invocations for example evaluateExpression(expression, questionnaireItem, questionnaireResponse)

these have been addressed.

@jingtang10
Copy link
Collaborator

jingtang10 commented Sep 11, 2023

Jajoo - I'm satisfied that your review comments have been addressed and I've approved this PR. So I've "dismissed" your review to unblock merge. But if you have any further comments please add them and/or create another issue.

@jingtang10 jingtang10 merged commit 3da3bef into google:master Sep 11, 2023
2 of 3 checks passed
@jingtang10 jingtang10 deleted the 2096-variable-for-enable-when-expression branch September 11, 2023 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
5 participants