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

Dynamic answerExpression not working #2052

Closed
FikriMilano opened this issue Jun 29, 2023 · 12 comments · Fixed by #2066
Closed

Dynamic answerExpression not working #2052

FikriMilano opened this issue Jun 29, 2023 · 12 comments · Fixed by #2066

Comments

@FikriMilano
Copy link
Collaborator

FikriMilano commented Jun 29, 2023

Describe the bug
answerExpression doesn’t support accessing context from variable expression, it only can for launch context. This makes it not possible to have dynamic answer options.

So basically, the answer options within the dropdown widget is static once the app render the questionnaire.

Component
SDC library

To Reproduce
Steps to reproduce the behavior:

  1. Paste the downloaded sample Questionnaire into demo app assets folder
  2. Replace the file name in the following line of code to 'dynamic-answer-expression.json'
    https://github.com/google/android-fhir/blob/master/demo/src/main/java/com/google/android/fhir/demo/EditPatientViewModel.kt#L48
  3. Run demo app, and wait for sync
  4. Click a patient
  5. Click edit icon (top-right corner)
  6. In the first dropdown, select the "NAIROBI" city
  7. Open the second dropdown
  8. It still shows nothing

Expected behavior
answerExpression should be able to access other context including variable expression, therefore making the answer options dynamic, every time the variable updates.

Screenshots

device-2023-06-30-181824.webm

Smartphone (please complete the following information):

  • Device: [e.g. Pixel4a emulator]
  • Android version: [e.g. Settings -> About phone -> Android version]
  • Build number: [e.g. Settings -> About phone -> Build number]
  • Version [e.g. 22]

Additional context

Would you like to work on the issue?
N/A

@MJ1998
Copy link
Collaborator

MJ1998 commented Jun 30, 2023

Hey @FikriMilano Could you give an example ?

@FikriMilano
Copy link
Collaborator Author

FikriMilano commented Jun 30, 2023

@MJ1998 thank you so much for the interest!
I added the sample questionnaire, demo video, and more details in the ticket description.

@FikriMilano
Copy link
Collaborator Author

Hi @MJ1998
Kindly let me know if you have any follow up questions

@FikriMilano
Copy link
Collaborator Author

@f-odhiambo @pld

@MJ1998
Copy link
Collaborator

MJ1998 commented Jul 4, 2023

Hi @FikriMilano
Sure. Thanks for adding a detailed description.

@FikriMilano
Copy link
Collaborator Author

@MJ1998 just to make sure, I would like to inquire whether you are currently working on this task. If not, I would be happy to pick this up, as it holds high priority for our team.

@MJ1998
Copy link
Collaborator

MJ1998 commented Jul 6, 2023

Yes @FikriMilano, I am working on this. I hope a solution by tomorrow should be good ? If its urgent then please feel free to take this up.

@FikriMilano
Copy link
Collaborator Author

FikriMilano commented Jul 6, 2023

That's great news! thank you @MJ1998 :D

Tomorrow is fine, please continue. It would be a shame if your 1 week of efforts is not getting merged. Looking forward for your code, thanks :D

@MJ1998
Copy link
Collaborator

MJ1998 commented Jul 7, 2023

Alright I have a crude working solution. There are 2 errors:

  1. answerExpressionMap stores initial expression and does not re-evaluate
  2. variables in x-fhir-query are not supported, only launchContext

Crude solution is to bypass 1 and replace variables in fhir-query expression with values evaluated.

But from the other PR's comment you tagged me, it seems its better to modify the QuestionnaireViewItem API with enabledAnswerOptionList .

@FikriMilano
Copy link
Collaborator Author

@MJ1998 thanks for the update.

Can you create a PR for the crude solution? I would like to review the code and test it on my end to determine if it can serve as a temporary solution. However, it is not necessary to merge it into the master branch. If we find it suitable, my team can pull the branch to our fork and proceed with our own release.

For the better solution, we can create a separate branch for it, as I agree with @jingtang10's suggestion. Since FHIR provides multiple methods for adding answer options to an item, do you have an estimate for how long it will take to implement the better solution?

@MJ1998
Copy link
Collaborator

MJ1998 commented Jul 7, 2023

@FikriMilano There you go!
Will fix the tests soon.

@FikriMilano
Copy link
Collaborator Author

Thanks @MJ1998 :D
I'll review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.

2 participants