On this page ⌄
Extract search parameters
Using the generated search-parameter extractors to pull indexable values from resources, and what they cover.
Goal and scope
Every FHIR search parameter is defined by a FHIRPath expression. Kotlin FHIR resolves those expressions at code-generation time and emits them as native Kotlin extraction functions, so you can pull search values out of a resource with no expression engine at runtime. This page covers the generated API and its coverage boundary.
The generated objects
For each resource type there is a SearchParams object in the search subpackage, such as dev.ohs.fhir.model.r4.search.PatientSearchParams. Each parameter knows its name, type, original FHIRPath expression, and target resource types, and can extract typed values.
import dev.ohs.fhir.model.r4.search.PatientSearchParams
val birthDates: List<Date> = PatientSearchParams.birthdate.extractFrom(patient)
A fluent extension reads the other way around.
import dev.ohs.fhir.model.r4.search.extract
val birthDates: List<Date> = patient.extract(PatientSearchParams.birthdate)
The all and unsupported lists
Not every search parameter's FHIRPath pattern is supported by the code generator. Each SearchParams object therefore exposes two lists.
-
allholds the parameters whose extraction is implemented and is safe to iterate.PatientSearchParams.all.forEach { searchParam ->val values = searchParam.extractFrom(patient)// index the values} -
unsupportedholds the parameters whoseextractFrom()throwsNotImplementedError. They are listed so the gap is visible, not so you call them.
Coverage boundaries
- The repository documents which FHIRPath patterns the generator supports and which parameters fall outside them. Consult it when a parameter you need is in
unsupported. For those parameters, theexpressionmetadata still carries the original FHIRPath string, so you can evaluate it with Kotlin FHIRPath instead. - In the current release candidate, parameters whose expression is a union of several paths extract only the first branch. Verify extraction against your own data for parameters your application depends on.
Where this sits in the stack
Kotlin FHIR Engine does not use these extractors. It evaluates search-parameter expressions with the FHIRPath engine for broader coverage. Use generated extraction when you control the parameter set and want no interpretation overhead, and a FHIRPath engine when you need arbitrary expressions.