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

initialExpression extension for advanced form behaviour #1033

Closed
fredhersch opened this issue Jan 13, 2022 · 9 comments · Fixed by #1228
Closed

initialExpression extension for advanced form behaviour #1033

fredhersch opened this issue Jan 13, 2022 · 9 comments · Fixed by #1228
Assignees
Labels
effort:medium Medium effort - 3 to 5 days P1 High priority issue

Comments

@fredhersch
Copy link
Collaborator

fredhersch commented Jan 13, 2022

Is your feature request related to a problem? Please describe.
When rendering a Questionnaire via the data capture library, I need to be able to use an expression to set an initial value - see SDC Expressions

Describe the solution you'd like
SDC Library support for initialExpression extension using FHIRPath

For example:

  • Set a value to current date - %today()
  • Set name of the first patient - %patient.name.where(use='official').given.first()
  • Set the gender of the patient - %patient.gender

For other examples, see sample questionnaire

Describe alternatives you've considered
CQL or Questionnaire population

@RaaziaTarique
Copy link
Contributor

RaaziaTarique commented Mar 14, 2022

In order to implement this issue, the approach that I am going to use will be as follows.

  1. Check if the expression starts with today(), then inside this will check if days are being added to or subtracted from today() if yes then perform the operation else return current date.
  2. Try to fetch answer based on provided resource and expression if not succeeded then fetch answer using definition if provided.
  3. Use FhirPath to evaluate expressions.

Currently, FHIRLexer is only able to recognize expressions without where() and any function call.
I have one question should I handle every possible expressions mentioned here http://hl7.org/fhirpath on SDK side?

CC: @f-odhiambo @ndegwamartin @maimoonak @jingtang10 @Tarun-Bhardwaj

@RaaziaTarique
Copy link
Contributor

In order to implement this issue, the approach that I am going to use will be as follows.

  1. Check if the expression starts with today(), then inside this will check if days are being added to or subtracted from today() if yes then perform the operation else return current date.
  2. Try to fetch answer based on provided resource and expression if not succeeded then fetch answer using definition if provided.
  3. Use FhirPath to evaluate expressions.

Currently, FHIRLexer is only able to recognize expressions without where() and any function call. I have one question should I handle every possible expressions mentioned here http://hl7.org/fhirpath on SDK side?

CC: @f-odhiambo @ndegwamartin @maimoonak @jingtang10 @Tarun-Bhardwaj

After Exploring the FhirPathEngine further, I came to know that it has multiple overloaded methods for evaluating FhirPath expressions. So, I modified the approach that I proposed before as follows,

  1. Get answers using FhirPathEngine evaluate method List<Base> evaluate(Base base, String path) throws FHIRException
  2. If above method is not able to evaluate expression then will evaluate expression using List<Base> evaluate(Base base, ExpressionNode ExpressionNode) throws FHIRException
  3. If unable to evaluate to expressions using above mentioned methods then fetch answer using definition if provided.

@jingtang10 CC: @f-odhiambo

@jingtang10
Copy link
Collaborator

Looking through the code of FHIRPathEngine https://github.com/hapifhir/org.hl7.fhir.core/blob/b075c5695ffa7267ef7010f8e560731d20a90383/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/FHIRPathEngine.java#L502 the code for evalute(Base,String) and evaluate(Base,ExpressionNode) are pretty similar - are you sure your step 1 and 2 will generate different results?

@RaaziaTarique
Copy link
Contributor

@jingtang10 I checked the methods, they are actually almost identical and doing the same job. I can modify step one to use only this method List<Base> evaluate(Base base, String path) throws FHIRException and pass resource from provided resources if any and then use definition if there's no answer found using expression.

@RaaziaTarique
Copy link
Contributor

Related to the expressions that are not currently supported, I posted a query here https://chat.fhir.org/login/#narrow/stream/179255-questionnaire/topic/FHIRPATH.20SDC.20implementation
Screenshot 2022-03-18 at 2 21 32 PM
@jingtang10 CC: @f-odhiambo @shoaibmushtaq25

@delcroip
Copy link
Collaborator

delcroip commented Apr 13, 2022

Dear,

I just realized that initialExpression is part of the populate questionnaire and not a extension to be managed by the form filler, if this is not supported, then does the SDK support Observation-based Population or StructureMap based population ?

thanks again for your work

best regards

@fredhersch
Copy link
Collaborator Author

fredhersch commented Apr 17, 2022

Dear,

I just realized that initialExpression is part of the populate questionnaire and not a extension to be managed by the form filler, if this is not supported, then does the SDK support Observation-based Population or StructureMap based population ?

thanks again for your work

best regards

We currently support Expression Based population - https://github.com/google/android-fhir/wiki/Structured-Data-Capture-Library#questionnaire-population

This extension allows for adding an expression as part of the population e.g. time.now() versus setting the value of a field that was previously collected

cc: @delcroip @jingtang10

@delcroip
Copy link
Collaborator

@fredhersch does it means that this issue can be closed ?

(all the related work will be usefull for other expressions)

@jingtang10
Copy link
Collaborator

this issue can be closed after two things:

  • the issue Raazia is fixing. which is that in some cases we're not providing the context to fhir path engine correctly, causing it unable to evaluate expressions such as today().
  • we will also need a follow up PR to handle the population context properly using the launch context and population context extensions.

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 P1 High priority issue
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants