Skip to content

Support date search against Timing values #2973

Backlog

Description

@piotrszul

Summary

Date search parameters match date, dateTime, instant and Period values but not Timing values. R4 lists Timing as a type that date parameters search, so a resource whose searched element is a Timing should be found. Today it is silently left out.

This is a documented limitation, not a defect. #2950 (Search each alternative of a choice element) fixed #2914 (Date search on Observation fails: cannot determine FHIR type of Observation.effective) by searching each alternative of a choice element that the parameter type allows. The date type allows date, dateTime, instant and Period (SearchParameterType), so a Timing alternative is skipped. The library search docs say that Observation?date=2020 does not match an Observation "whose effective is a Timing". #2914 noted this as a gap.

Current behaviour (observed)

On 11.0.0-SNAPSHOT, built from release/11.0.0 at 4de8ad6 (Python 3.11.13, Java 21.0.3, Spark 4.0.5, FHIR R4):

import json

from pathling import PathlingContext

pc = PathlingContext.create(enable_terminology=False)


def observation(id, effective):
    return dict({"resourceType": "Observation", "id": id, "status": "final", "code": {"text": "x"}}, **effective)


resources = [
    observation("datetime", {"effectiveDateTime": "2020-04-01"}),
    observation("timing-event", {"effectiveTiming": {"event": ["2020-04-01T10:00:00Z"]}}),
    observation("timing-bounds", {"effectiveTiming": {"repeat": {
        "boundsPeriod": {"start": "2020-01-01", "end": "2020-12-31"},
        "frequency": 1, "period": 1, "periodUnit": "d"}}}),
]
observations = pc.encode(pc.spark.createDataFrame([(json.dumps(r),) for r in resources], ["value"]), "Observation")
for query in ["date=2020", "date=2020-04-01"]:
    ids = sorted(r.id for r in observations.filter(pc.search_to_column("Observation", query)).select("id").collect())
    print(f"{query} -> {ids}")

Output:

date=2020 -> ['datetime']
date=2020-04-01 -> ['datetime']

Neither Timing Observation is returned, and no error is raised. The same happens for a Timing event in 2020 with ServiceRequest?occurrence=2020, ChargeItem?occurrence=2020 and CarePlan?activity-date=2020.

Requested behaviour (from the specification, not verified end to end)

R4 lists Timing as a type that date parameters search (the cross-map of search parameter types and data types on the R4 search page). It treats a Timing target as an explicit range (prefixes: "If the target value is a Range, a Period, or a Timing, then the target is explicitly a range"), and says how that range is taken (date):

the specified scheduling details are ignored and only the outer limits matter. For instance, a schedule that specifies every second day between 31-Jan 2013 and 24-Mar 2013 includes 1-Feb 2013, even though that is on an odd day that is not specified by the period.

So a Timing should be searched as the range from its earliest to its latest limit, with the same prefix rules as a Period. For the snippet above:

Query Expected
date=2020 datetime, timing-event, timing-bounds
date=2020-04-01 datetime, timing-event (the year-long bounds are not contained in one day)

Notes

  • Open questions for the design: what the outer limits of a Timing are when it has several events, only repeat.bounds[x], both, or neither; how to handle boundsDuration and boundsRange, which are not dates; and whether a Timing with no limits matches nothing.
  • Scope: in the bundled R4 registry, the date parameters that reach a Timing are those over Observation.effective[x] (date, also through the shared clinical-date), ServiceRequest.occurrence[x] (occurrence), ChargeItem.occurrence[x] (occurrence) and CarePlan.activity.detail.scheduled[x] (activity-date). All four were run. Some parameters over an element that allows a Timing, such as DeviceRequest event-date, already exclude it in their expression with as(dateTime) | as(Period), so they are not affected. Custom search parameters over a Timing would need the same support.
  • When this is implemented, the sentence about Timing in the library search docs needs to be removed.

Related: #2914, #2950, #2971

Activity

  1. added
    PoF_line
    and removed
    PoF_line
    on 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

    Type

    No type

    Projects

    • Status
      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions