beda-software / FHIRPathMappingLanguage

MIT License
12 stars 1 forks source link

Add support for interpolating fhirpath expression into string #8

Closed ruscoder closed 6 months ago

ruscoder commented 6 months ago

Currently string might be constructed using only one expression in curly braces, e.g. Patient/{{ id }}.

It will be good to have this behaviour extended to using multiple fhirpath expressions, e.g. Patient/{{ id }}/_history/{{ hid }}.

ruscoder commented 6 months ago

The open question is how it should work in case one of the expressions resolves as empty array.

There're three possible solutions:

  1. Use null, e.g. /Patient/null/_history/null
  2. Use empty string, e.g. Patient//_history/ - I really don't like it, because it leads to some issues while using in GET /Patient?_id={{ id }}
  3. Resolve the whole value as null - it matches the fhirpath behaviour, e.g. {{ '/Patient/' + id }} turns into null

@ir4y please share your thoughts

ruscoder commented 6 months ago

In case when expression resulted in the empty collection {}:

{{- expression -}} - the value of the expression should be undefined {{ expression }} - the value of the expression should be null

ruscoder commented 6 months ago

I reverted the behavior of {{ }} to be backward compatible with the previous implementation. There's a flag called dropNulls that is passed for /parse-template and /r4/parse-templates endpoints.

For /aidbox/parse-template this flag is not passed.

In my opinion, if a key is specified it should be set to null instead of implicitly dropping. But there's an issue with FHIR union types, e.g. valueBoolean: null is a wrong notation, while value: null in Aidbox works fine.

ruscoder commented 6 months ago

It looks like there's a bug in Aidbox /fhir implementation,

POST /fhir/Patient

deceasedBoolean: null

fails with

resourceType: OperationOutcome
text:
  status: generated
  div: Invalid resource
issue:
  - severity: fatal
    code: invalid
    expression:
      - Patient.deceased.boolean
    diagnostics: Expected type of 'boolean, got 'nil
ruscoder commented 6 months ago

We had a discussion with @ir4y and decided to leave the behavior of dropping nullable keys by default.

And instead of {{- -}} we added explicit preserve-null construction: {{+ expr +}} - in case if expr returns an empty collection, null will be preserved.

Moreover, if directive also drops key in case when else branch is not specified, to explicitly return null, {% else %}: null or {% else %}: {{+ {} +}} are needed to be passed, the second one is empty collection