Skip to content

Skip search expressions of a type the parameter does not allow - #2953

Merged
johngrimes merged 3 commits into
release/11.0.0from
issue/2913
Nov 23, 2026
Merged

johngrimes merged 3 commits into
release/11.0.0from
issue/2913

Conversation

@johngrimes

Copy link
Copy Markdown
Member

This change fixes Observation?value-quantity=..., which failed with FHIR type 'SampledData' is not valid for search parameter type 'QUANTITY'. The (Observation.value as SampledData) expression of the parameter was rejected, so the whole search failed even though the Quantity expression is valid.

The rule for an expression of a type that the search parameter type does not allow is now:

  • The expression is skipped, so it contributes no match, as long as at least one other expression of the parameter is of an allowed type.
  • If no expression of the parameter is of an allowed type, the search fails with InvalidSearchParameterException, naming the parameter, the types found and the allowed types.
  • An expression whose type cannot be determined still fails, as before.

For #2914 this means that a choice alternative of a type the parameter does not allow is skipped in the same way, once each alternative is evaluated as an expression of its own. With that change in place, Observation.effective as Timing would be skipped while the dateTime, instant and Period alternatives are searched. This change does not do that splitting: Observation?date=2020 still fails with Cannot determine FHIR type for expression: Observation.effective.

I built a filter for every parameter in the bundled R4 registry to see what the rule changes. 30 parameters that failed now build a filter: value-quantity, component-value-quantity and combo-value-quantity on Observation (skipping SampledData), and context-quantity on 27 conformance resources (skipping Range). Only value-quantity is tested against data here. The other 29 return correct results when a resource has at most one component or useContext, but fail with Expecting a collection with a single element but it has many when it has more. That is a separate defect, which ValueSet?context=... shows too without any skipped type. 147 parameters still fail because none of their expressions is of an allowed type, as they did before: composite and special parameters, reference parameters over canonical or uri, and quantity parameters over Money, Age, Duration and Age | Range.

Skipping is not the same as support. R4 defines quantity search against a Range (https://hl7.org/fhir/R4/search.html#prefix), so context-quantity now ignores range values, in the same way that #2914 would ignore Timing. The documentation for both the library and the server now states that elements of an unsupported type are not matched, naming these two cases.

The tests cover value-quantity through the default registry, including a SampledData whose origin and data carry the searched value, the order of the expressions, the failure when no expression is of an allowed type, and string search on a filtered HumanName expression, since the sub-fields are now evaluated within the collection that the expression selects.

Resolves #2913.

A search parameter whose expressions include one of a type its parameter
type does not allow, such as the SampledData alternative of value-quantity,
failed outright. Such an expression is now skipped, and the search fails only
when no expression of the parameter is of an allowed type.
Also name the Range values of context-quantity in the documentation of
types that are not matched.
# Conflicts:
#	fhirpath/src/main/java/au/csiro/pathling/search/SearchColumnBuilder.java
#	site/docs/libraries/search.md
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant