Skip to content

search_to_column rejects Observation?value-quantity with InvalidSearchParameterException (SampledData) #2913

Done

Description

@piotrszul

Summary

search_to_column raises on the standard value-quantity search parameter of Observation, so no filter column is produced. The error is about the SampledData branch of the parameter's expression, which the FHIR specification marks as not used in search.

Environment

  • Pathling 10.0.0 (PyPI; Python 3.11, PySpark 4.0.5) and current main (11.0.0-SNAPSHOT build; Python 3.9)
  • FHIR R4, Python library API

How it was found

Reproduced while reviewing this issue.

Steps to reproduce

from pathling import PathlingContext

pc = PathlingContext.create(enable_terminology=False)
pc.search_to_column("Observation", "value-quantity=5.4")

Actual behaviour (observed)

The call raises before any data is read:

py4j.protocol.Py4JJavaError: An error occurred while calling o87.searchToColumn.
: au.csiro.pathling.search.InvalidSearchParameterException: FHIR type 'SampledData' is not valid for search parameter type 'QUANTITY'. Allowed types: [QUANTITY]
Stack trace (10.0.0)
Traceback (most recent call last):
  File "repro.py", line 5, in <module>
    pc.search_to_column("Observation", "value-quantity=5.4")
  File ".../pathling/context.py", line 865, in search
    jcolumn = self._jpc.searchToColumn(resource_type, search_expression)
  ...
py4j.protocol.Py4JJavaError: An error occurred while calling o87.searchToColumn.
: au.csiro.pathling.search.InvalidSearchParameterException: FHIR type 'SampledData' is not valid for search parameter type 'QUANTITY'. Allowed types: [QUANTITY]
	at au.csiro.pathling.search.SearchColumnBuilder.getFilterForType(SearchColumnBuilder.java:361)
	at au.csiro.pathling.search.SearchColumnBuilder.buildExpressionFilter(SearchColumnBuilder.java:336)
	at au.csiro.pathling.search.SearchColumnBuilder.lambda$buildCriterionFilter$2(SearchColumnBuilder.java:273)
	... (java.util.stream frames)
	at au.csiro.pathling.search.SearchColumnBuilder.buildCriterionFilter(SearchColumnBuilder.java:274)
	at au.csiro.pathling.search.SearchColumnBuilder.lambda$fromSearch$0(SearchColumnBuilder.java:175)
	... (java.util.stream frames)
	at au.csiro.pathling.search.SearchColumnBuilder.fromSearch(SearchColumnBuilder.java:176)
	at au.csiro.pathling.search.SearchColumnBuilder.fromQueryString(SearchColumnBuilder.java:195)
	at au.csiro.pathling.library.PathlingContext.searchToColumn(PathlingContext.java:951)
	... (reflection and py4j frames)

On main the exception and frames are the same, with the SearchColumnBuilder line numbers shifted (363, 338, 275, 276) and PathlingContext.java:959.

Expected behaviour (from the specification, not verified end to end because the failure occurs first)

The call returns a filter column. Per the FHIR R4 quantity search rules:

  • The parameter's expression is (Observation.value as Quantity) | (Observation.value as SampledData), and the specification lists SampledData as "Not used in search".
  • An Observation with a valueQuantity of 5.4 should match.
  • An Observation whose value is a SampledData should never match and should not cause an error.

Example that should match:

{
  "resourceType": "Observation",
  "id": "example",
  "status": "final",
  "code": { "text": "dose" },
  "valueQuantity": { "value": 5.4, "system": "http://unitsofmeasure.org", "code": "mg" }
}

Optional

  • Suspected cause (hypothesis, from reading the source): The search validates every type in the union expression against the parameter type, and SampledData has no search semantics, so it is rejected. A type the specification marks as not used in search should contribute no matches, not an error.
  • Scope: Not investigated.
  • Workaround: Not investigated.
  • Suggested acceptance tests:
    1. value-quantity=5.4 returns a column without raising.
    2. Applied to the example above, it selects that Observation.
    3. Applied to an Observation whose value is a SampledData, it excludes it without error.

Related: #1986 (Support for FHIR Search API queries)

Activity

  1. added
    bug
    PoF_line
    Bunsen_line
    on Nov 16, 2026
  2. moved this to Planned in Pathlingon Nov 17, 2026
  3. added theissue type on Nov 23, 2026
  4. changed the title [-]Quantity search fails on SampledData for value-quantity[/-] [+]search_to_column rejects Observation?value-quantity with InvalidSearchParameterException (SampledData)[/+] on Nov 24, 2026
  5. piotrszul commented on Nov 24, 2026

    @piotrszul
    CollaboratorAuthor

    I checked the fix from #2953 (Skip search expressions of a type the parameter does not allow), on release/11.0.0 at 4de8ad6 (11.0.0-SNAPSHOT, Python 3.11.13, Java 21.0.3, Spark 4.0.5).

    Fixed: the snippet in this issue no longer fails, and Observation?value-quantity matches valueQuantity values. The SampledData expression is skipped, which is correct: R4 marks SampledData as not used in search. A sweep of the bundled R4 registry found 30 parameters that mix an allowed expression with a disallowed one fixed in the same way, and none newly broken.

    Two things this fix does not cover, now tracked separately:

  6. moved this from Planned to Done in Pathlingon Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bunsen_linePoF_linebug

    Type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions