Skip to content

Search each alternative of a choice element - #2950

Merged
johngrimes merged 1 commit into
release/11.0.0from
issue/2914
Nov 23, 2026
Merged

johngrimes merged 1 commit into
release/11.0.0from
issue/2914

Conversation

@johngrimes

Copy link
Copy Markdown
Member

This change makes a search parameter whose expression is a choice element, such as Observation.effective in the date parameter, search each alternative of the choice that the parameter type allows, and combine the results with OR. Previously the search failed with Cannot determine FHIR type for expression: Observation.effective, because the column builder requires a single FHIR type and an unresolved choice has none.

Each allowed alternative is selected with ofType and goes through the same path as any other expression, so Observation?date=2020 now searches effectiveDateTime, effectiveInstant and effectivePeriod. With the :not modifier the negated filters of the alternatives are combined with AND, so that a resource matches only if no alternative holds the value.

The same applies to every parameter in the default registry whose expression is a bare choice element. Besides the date parameter of Observation, DiagnosticReport, Immunization and Procedure, the following no longer fail:

  • ChargeItem?occurrence, ServiceRequest?occurrence, MedicationStatement?effective and MedicationAdministration?effective-time
  • CarePlan?activity-date, Specimen?collected, Media?created and DetectedIssue?identified
  • MessageHeader?event and MessageDefinition?event (token, Coding or uri)
  • Consent?source-reference (the Attachment alternative is skipped)
  • RiskAssessment?probability (the Range alternative is skipped)

This assumes the rule for #2913 is to skip a type that the parameter type does not allow, rather than fail. An alternative of that kind is skipped, for example Timing for Observation.effective, string for Immunization.occurrence, and string, Age and Range for Procedure.performed. A resource that holds only such an alternative does not match. If no alternative of a choice is allowed, the search fails with an InvalidSearchParameterException; PlanDefinition?definition (canonical or uri, against a reference parameter) now fails in this way. Failing on a disallowed alternative instead would make every Observation?date search fail on Timing, so I don't think that rule is workable here. This change does not alter how disallowed types are handled outside of choice elements, which is the subject of #2913.

Some gaps remain:

  • Searching a Timing is not supported, although R4 lists it as a target of date search.
  • The system|code syntax cannot be used on MessageHeader?event and MessageDefinition?event, because the uri alternative rejects it. This failed before this change as well.
  • A parameter with more than one expression still combines the negated filters of its expressions with OR, so :not on such a parameter (for example Observation?combo-code:not) matches resources that hold the value in one of the expressions. This predates this change, and I have left it alone because it overlaps with search_to_column rejects Observation?value-quantity with InvalidSearchParameterException (SampledData) #2913.

The tests search Observation, DiagnosticReport, Immunization, Procedure, MessageHeader and CarePlan through the default registry, with a resource for each alternative.

Resolves #2914.

A search parameter whose expression is a choice element, such as
Observation.effective, failed because the choice has no single type.
Each alternative the parameter type allows is now searched, and those
it does not allow, such as Timing for a date, are skipped.
@johngrimes johngrimes added bug Something isn't working fhirpath Related to fhirpath reference implementation labels Nov 23, 2026
@sonarqubecloud

Copy link
Copy Markdown

@johngrimes johngrimes changed the title fix: Search each alternative of a choice element Search each alternative of a choice element Nov 23, 2026
@johngrimes
johngrimes marked this pull request as ready for review November 23, 2026 03:01
@johngrimes
johngrimes merged commit 22c49bd into release/11.0.0 Nov 23, 2026
16 checks passed
@johngrimes
johngrimes deleted the issue/2914 branch November 23, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fhirpath Related to fhirpath reference implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant