Skip to content

fix(fhirpath): keep resolve() to the evaluated record's contained resources - #2969

Open
angela-helios wants to merge 1 commit into
mainfrom
fix/fhirpath-resolve-contained-owner
Open

angela-helios wants to merge 1 commit into
mainfrom
fix/fhirpath-resolve-contained-owner

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Stacked on #2901. This branch starts from #2901's branch so that Test FHIRPath passes against the current fhir-test-cases master; its commit leaves this diff once #2901 merges.

Closes #2968

Summary

In SQL-on-FHIR's pooled scope (a bundle, or HFS's InProcessSofRunner scan batch), resolve() took the first candidate that matched across every record and every record's contained resources:

  • a #id matched a resource contained in another record;
  • a Type/id matched another record's contained resource ahead of the real top-level one.

Changes

  • EvaluationContext.resolution_root. When set_resolution_scope widens resources to a pool, it first records the (resourceType, id) of the record the context was built for. SOF's forEach/repeat contexts take it from their parent with the new inherit_resolution_root. Clones and child contexts carry it.
  • resolve_function:
    • Each contained candidate carries the identity of its top-level container.
    • A #id or bare id matches only resources contained in the root record. Without a root, in a single-resource context, it matches any contained resource, as before.
    • A Type/id, and the trailing-id fallback, match only top-level resources. A contained resource is addressed by #id.
    • Type/id/_history/v is read as Type/id instead of matching any candidate whose id is v.

Not changed

  • Absolute URLs to another server are still matched locally by their last two segments. Restricting that to the local base belongs with the remote resolver configuration.
  • Records without an id share the identity (type, None), so two id-less records of the same type in one bundle still share contained ids.

Tests

crates/sof/tests/resolve_tests.rs:

Test What it checks
a_fragment_resolves_within_its_own_record_only Two Observations each contain Patient #p; each row gets its own Patient's family name.
a_typed_reference_never_resolves_to_another_records_contained_resource Patient/other resolves to the top-level Patient "Real", not to "Planted", which an earlier record contains.

With the three source files stashed, both fail: obs-b reports "First", and the typed reference resolves to "Planted".

Runs:

  • helios-fhirpath: 796 passed.
  • helios-sof: the lib and the 26 test files that use resolve(), forEach or repeat, 519 passed, the existing contained, bundle-scope and absolute-URL resolve tests included. The rest are left to CI: building all 58 binaries fills the local disk.

Clippy on helios-fhirpath and helios-sof (--lib --tests) is clean.

…ources

In SQL-on-FHIR's pooled scope, resolve() took the first match across every
record and its contained resources, so a #id could resolve to a resource
contained in another record, and a Type/id to another record's contained
resource ahead of the real one. The context now remembers the record it was
built for when the pool is set (forEach/repeat contexts inherit it); #id
matches only that record's contained resources, Type/id only top-level
ones, and Type/id/_history/v is read as Type/id.

Closes #2968

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FHIRPath resolve() in SQL-on-FHIR's pooled scope can return another record's contained resource

1 participant