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

Support calculatedExpression #971

Closed
jingtang10 opened this issue Dec 15, 2021 · 12 comments · Fixed by #1380 · May be fixed by opensrp/android-fhir#5
Closed

Support calculatedExpression #971

jingtang10 opened this issue Dec 15, 2021 · 12 comments · Fixed by #1380 · May be fixed by opensrp/android-fhir#5
Assignees
Labels
effort:medium Medium effort - 3 to 5 days P2 Medium priority issue type:enhancement New feature or request

Comments

@jingtang10
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
See #803

See example of calculatedExpression and variable: http://build.fhir.org/ig/HL7/sdc/examples.html#using-calculatedexpression-and-variable

@maimoonak provided this example where we want to take age OR birthdate as input and calculate the other from one which was input: https://github.com/google/android-fhir/blob/mssng-quest-feat/datacapturegallery/src/main/assets/sample_family_member_registration_calculatedexpression.json

Describe the solution you'd like
Probably use FHIRPath

Describe alternatives you've considered
NA

Additional context
NA

Would you like to work on the issue?
NA

@jingtang10
Copy link
Collaborator Author

@maimoonak @f-odhiambo can you please comment on the priority of this issue and if you have any bandwidth to take this on? thanks!

@maimoonak
Copy link
Collaborator

Rightnow this issue is not a blocker for us. However, many of the forms we have seen in previous apps included the calculated expressions to make forms concise and self dependent and also accommodate simple decisions for Health workers. A very common example is deriving risk factor for patient OR calculate next followup date. I would rate this 4/5 on priority.
This issue seems complex and might need a lot of input on design hence before committing on this we would need to have a discussion on the approach and design.

@fredhersch
Copy link
Collaborator

@maimoonak is 4/5 high or low priority? Thanks for the comments!

@Tarun-Bhardwaj Tarun-Bhardwaj added effort:medium Medium effort - 3 to 5 days P2 Medium priority issue and removed Triage labels Jan 31, 2022
@delcroip
Copy link
Collaborator

Hello,
as discuss in the dev call, i'd like to say that this feature is a must have for the EmCare project because the business wants to have calculation result display on the questionnaire

@fredhersch
Copy link
Collaborator

Thanks @delcroip

@kunjan8794 Is this something that the Argusoft team could potentially work on?

cc: @jingtang10

@Tarun-Bhardwaj
Copy link

@kunjan8794 , did you get a chance to work on this?

@Tarun-Bhardwaj
Copy link

@f-odhiambo , can someone from your team pick this up as part of Sprint 2?
CC: @fredhersch

@fredhersch
Copy link
Collaborator

@f-odhiambo I noticed @maimoonak's comment about design. Let's make sure we spend some time on this before we dive into the implementation.

@f-odhiambo
Copy link
Collaborator

@Tarun-Bhardwaj Kindly assign this ticket to @maimoonak

@maimoonak
Copy link
Collaborator

maimoonak commented May 10, 2022

The method questionnaireResponseItemChangedCallback in QuestionnaireViewModel is one which runs after every answer changes. So far the extensions implementations we had were running only once, either on start or after submission and hence those were run only once. This items which has this extension would need to run everytime any answer changes. The work for this ticket would also take inspiration from Variable support work by @shoaibmushtaq25 .

Each time an answer changes the code will find all items which have calculated-expression extension and would use FhirPathEngine to evaluate and set the value (incase it has changed).

@maimoonak
Copy link
Collaborator

The draft PR for current issue has basic implementation.

  • The app runs calculated-expression for fields having extension
  • It update the fields and returns correct value in questionnaireResponse
  • App has an implementation in 'catalog' as well

Issues

  • Still figuring out why app is not updating the value on UI (despite that value is updated and exists in questionnaireResponse and maps of linkId-Item)
  • The cyclic dependency between two variables can lead to unexpected results and since it is expression we do not have any way determining what variables are dependent on other. For. e.g. in example where birthdate updates age and age updates birthdate, the evaluation of expression can lead to setting both fields null or update both values which completely depends on sequence app loops over link-id map. It means that user should be aware that they should avoid cyclic dependencies over such extensions. If two fields or more are responsible for maintaining a value a thrid field should be used keep most recent value.
  • Using variables would be possible as soon as Add variable Extension support #1328 is merged and the data is passed into the evaluator running calculated-expression

@maimoonak
Copy link
Collaborator

maimoonak commented May 12, 2022

PR for issue is ready for review

  • working feature
  • added component in catalog module as well
  • cyclic dependency detection on load
  • on load and on update item value detection and reflection on UI.

@f-odhiambo @fredhersch

@jingtang10 jingtang10 moved this from In Progress to PR under Review in Android FHIR SDK Sep 30, 2022
Repository owner moved this from PR under Review to Complete in Android FHIR SDK Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort:medium Medium effort - 3 to 5 days P2 Medium priority issue type:enhancement New feature or request
Projects
Status: Complete
6 participants