Skip to content

Support for FHIR Search API queries #1986

Open

Description

@johngrimes

This issue covers an expansion of the Search API implementation within the Pathling server, and supporting functions within the library API.

The implementation will translate FHIR search parameters into FHIRPath expressions that can be evaluated using the existing FHIRPath engine.

Core concepts

  1. Search parameter to FHIRPath translation: Convert any search parameter defined within the FHIR specification into a FHIRPath expression. The FHIR spec already defines FHIRPath expressions for each search parameter, which we can leverage directly. Note that this will require implementation of Support union operator #2398, Support type operators and functions #2383, Support limited resolve() function for reference type checking #2522 and verification that the FHIR search expression tests are passing.

  2. Search value to FHIRPath literal translation: Convert search parameter values into FHIRPath literals appropriate for the parameter type (token, date, quantity, string, etc.).

  3. Prefix to operator mapping: Support the standard FHIR search prefixes and map them to FHIRPath operators.

By combining a search parameter expression with a value expression using the appropriate operator, we produce a boolean FHIRPath expression that filters search results.

In scope

Search parameter types

The following search parameter types will be supported:

  • Token
  • Date
  • Quantity
  • String
  • Reference
  • URI
  • Number

These types cover the core use cases for cohort building: coded values (Token), temporal filtering (Date), numeric comparisons (Quantity, Number), text matching (String, URI), resource relationships (Reference), and combined criteria like code-value pairs (Composite).

Prefixes

The following prefixes will be supported:

  • eq (equality)
  • ne (not equal)
  • lt (less than)
  • le (less than or equal)
  • gt (greater than)
  • ge (greater than or equal)

These prefixes enable date range queries (e.g., birthdate=ge1990-01-01&birthdate=lt2000-01-01) and numeric comparisons for lab values (e.g., value-quantity=gt10). The ap (approximately) prefix is excluded as it has limited use cases.

Modifiers

The following modifiers will be supported:

  • :not (negation)
  • :exact (case-sensitive exact match, string only)

The :not modifier enables exclusion criteria. The :exact modifier supports precise identifier matching. Other modifiers like :missing, :contains, :below, and :above are excluded to limit initial scope.

Boolean logic

The following will be supported:

  • AND (repeated parameters)
  • OR (comma-separated values)

These operators enable complex cohort definitions combining inclusion and exclusion criteria across multiple conditions.

FHIRPath filter parameter

The existing fhirPath named query (activated via _query=fhirPath) will continue to be supported. When activated, the filter parameter accepts arbitrary FHIRPath expressions. These can be combined with standard search parameters, allowing mixed queries such as:

GET /Patient?_query=fhirPath&filter=name.given.first()='John'&gender=male

If the fhirPath named query is not activated, any filter parameters should be ignored.

Search control parameters

The following search control parameters are already supported via HAPI FHIR:

  • _count (pagination)
  • _offset (pagination)
  • _total (Bundle.total)
  • _summary (including _summary=count)
  • _elements (element filtering)
  • _format (response format)
  • _pretty (pretty printing)

Out of scope

  • Chained parameters (e.g., subject.name=peter)
  • Common parameters (_id, _lastUpdated, _tag, _profile, _security)
  • _text / _content (full-text search)
  • _list
  • _sort
  • _include / _revinclude
  • _contained / _containedType
  • _filter parameter
  • Geospatial search (near)
  • Reverse chaining (_has)
  • Composite search parameters

Library API additions

The following methods will be added to the Java library API and exposed in the Python and R libraries.

Search expression to column

A method that takes a FHIR search expression (URL query string) and returns a Spark column representing the boolean filter condition.

// Java
Column searchToColumn(String resourceType, String searchExpression)
# Python
pc.search_to_column("Patient", "gender=male&birthdate=ge1990-01-01")
# R
pc %>% search_to_column("Patient", "gender=male&birthdate=ge1990-01-01")

FHIRPath expression to column

A method that takes a FHIRPath expression and returns a Spark column. This provides direct access to the FHIRPath engine for use in DataFrame operations.

// Java
Column fhirPathToColumn(String resourceType, String fhirPathExpression)
# Python
pc.fhirpath_to_column("Patient", "name.given.first() = 'John'")
# R
pc %>% fhirpath_to_column("Patient", "name.given.first() = 'John'")

These columns can be used with standard Spark DataFrame operations such as filter(), where(), or select().

Initial use case

The intent is for us to be able to implement the _typeFilter parameter within the server using the Library API exclusively.

Activity

  1. added
    new feature
    on Jun 13, 2024
  2. johngrimes commented on Jun 13, 2024

    @johngrimes
    MemberAuthor

    One way of implementing part of this could be to leverage the FHIRPath definitions used to define search parameters within the FHIR specification.

    We should be able to translate these expressions into queries using the existing FHIRPath engine.

  3. added
    server
    on Jun 4, 2025
  4. johngrimes commented on Jun 4, 2025

    @johngrimes
    MemberAuthor

    It would be good to also surface this support within the Bulk Export API (#1987) through the _typeFilter parameter.

  5. moved this from Backlog to Planned in Pathlingon Aug 30, 2025
  6. moved this from Planned to In progress in Pathlingon Jan 7, 2026
  7. piotrszul commented on Feb 5, 2026

    @piotrszul
    Collaborator

    Left to do:

    • R API for search_to_column
    • Reference search parameter type
    • URI search parameter type
    • Caching of the search parameter registry parased from JSON spec (PRIORITY 2: Design Improvements)
    • Java, Pyton, R API for fhirpath_to_column (possibly to be moved to a separate ticket)
    • Pre-parsing of search expressions in the registry (PRIORITY 5: Performance Considerations)
    • Other improvement suggested in the attached review
    • Design improvement: Consider a complete typed object model for FHIR search expression evaluation to separate parsing of the expression from the evaluation (clearer design, early detection of invalid expressions).

    fhir-search-implementation-review.md

  8. moved this from In progress to Done in Pathlingon Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

new featureserver

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions