Skip to content

Add fhirServerUrl support to enable FHIRPath resolve() function #1806

@not-in-stock

Description

@not-in-stock

Add fhirServerUrl support to enable FHIRPath resolve() function

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

The @aehrc/sdc-populate package doesn't support the FHIRPath resolve() function. When using expressions like %order.requester.resolve().name.first().family in a questionnaire's initialExpression, the population fails silently and returns empty values.

This is frustrating because resolve() is a standard FHIRPath function that allows questionnaires to populate fields from referenced resources (e.g., getting a Practitioner's name from a ServiceRequest's requester reference) without requiring the calling application to pre-resolve all references manually.

Describe the solution you'd like

Pass fhirServerUrl option to fhirpath.evaluate() calls. According to fhirpath.js documentation, the resolve() function requires this option:

options.fhirServerUrl - a URL pointing to a FHIR RESTful API server that
is used to `resolve()` resources.

The value should come from fetchResourceRequestConfig.sourceServerUrl, which is already available in the codebase. This would require:

  1. Threading fetchResourceRequestConfig through functions that call fhirpath.evaluate()
  2. Adding fhirServerUrl: sourceServerUrl to the fhirpath options object
  3. Updating fhirpath.js dependency to version 4.5.0+ (where resolve() was implemented)

Describe alternatives you've considered (if applicable)

The current workaround is to pre-resolve all referenced resources in the calling application before passing them as separate launch contexts. For example, instead of using %order.requester.resolve(), the application must:

  1. Fetch the ServiceRequest
  2. Extract the requester reference
  3. Fetch the Practitioner
  4. Pass it as a separate %practitioner context

This works but requires each application to implement custom pre-resolution logic and questionnaires to be designed around this limitation rather than using standard FHIRPath patterns.

Additional context

  • The resolve() function was added to fhirpath.js in version 4.5.0 (2025-07-01)
  • Current @aehrc/sdc-populate depends on fhirpath 3.15.2, which doesn't have resolve()
  • The change is backwards compatible - if sourceServerUrl is not provided, resolve() simply won't work (same as current behavior)
  • I have a working patch implementation and would be happy to submit a PR if this approach is acceptable

Example questionnaire expression that would work after this change:

{
  "linkId": "ordering-physician-name",
  "type": "string",
  "extension": [{
    "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
    "valueExpression": {
      "language": "text/fhirpath",
      "expression": "%order.requester.resolve().name.first().given.first() & ' ' & %order.requester.resolve().name.first().family"
    }
  }]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions