You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TLDR: I'm trying to make fhirpath.js compatible with jotai, a React state manager, to implement calculatedExpressions from the FHIR Structured Data Capturing IG. But some adaptations to fhirpath.js are needed.
Context
I'm trying to implement calculated expressions to enable real-time calculations in my form library. The challenges to implement such reactive calculations are:
keeping track of the dependencies (the environment variables that are being used) in a specific FHIRPath expression
automatic re-evaluation of the FHIRPath expressions when one of the dependency variables has changed.
Luckily, libraries like Jotai, Angular Signals, or Solid.js have already solved the reactivity part. The remaining challenge is integrating this with fhirpath.js.
Desired API
A common pattern in reactivity libraries is that you need a getter function to resolve the current value of a variable. So, to make fhirpath.js compatible, we would need to inject that getter function somehow.
Below is an example of how the API could look like using Jotai: [update] In the end, no API changes were necessary
a=atom(0)// variables defined as Jotai Atoms to make them reactive.b=atom(0)c=atom((get)=>// a 'derived' atom consuming the variablesevaluate(undefined,// Resource is not necessary "%a + %b",// Expression{a, b},// Environment variablesmodel,{variableGetter: get}// getter to resolve the variables ))
After some experimentation, I found a solution that doesn't need any changes to the signature of evaluate()#162
The modifications in the PR introduce one new assumption for the context object. Variables are only read when they are consumed. This allows for lazy evaluation of the variables.
TLDR: I'm trying to make fhirpath.js compatible with jotai, a React state manager, to implement calculatedExpressions from the FHIR Structured Data Capturing IG. But some adaptations to fhirpath.js are needed.
Context
I'm trying to implement calculated expressions to enable real-time calculations in my form library. The challenges to implement such reactive calculations are:
Luckily, libraries like Jotai, Angular Signals, or Solid.js have already solved the reactivity part. The remaining challenge is integrating this with fhirpath.js.
Desired API
A common pattern in reactivity libraries is that you need a getter function to resolve the current value of a variable. So, to make fhirpath.js compatible, we would need to inject that getter function somehow.
Below is an example of how the API could look like using Jotai:[update] In the end, no API changes were necessary
I have a prototype of this library with a modified version of fhirpath.js here: https://github.com/Tiro-health/fhirpath-jotai. The current implementation uses a Proxy to sneak in the getter function.
The text was updated successfully, but these errors were encountered: