Searching for FHIR Resources
In the previous lesson, we saw how to list all patients from a FHIR server. But that’s just scratching the surface, FHIR’s search functionality lets you filter, sort, and combine queries to find exactly the patients you’re looking for.
Let’s go through some key search techniques using the Patient resource.
Where to Find Search Parameters
Every FHIR resource has its own set of supported search parameters. If you open the Patient resource page in the FHIR specification and scroll down, you’ll find a full list of search parameters.
These parameters allow you to filter patients by attributes such as name, birth date, gender, address, and more.
Basic Search Examples
Search by Name
GET [base]/Patient?name=Sidharth
This returns only patients with the name “Sidharth.”
Search by Birth Date
GET [base]/Patient?birthdate=1997
This gives you all patients born in 1997.
Note: The parameter is birthdate
(all lowercase), even though the field in the resource is birthDate
with a capital “D”. Search parameters don’t always match the field names exactly.
Using Comparators with Dates
Since birthdate
is a date type, you can use comparison operators:
eq
→ equal tone
→ not equal tolt
→ less thangt
→ greater than
Example:
GET [base]/Patient?birthdate=lt1997
This returns all patients born before 1997.
Filtering by Gender
GET [base]/Patient?gender=female
This query fetches all female patients on the FHIR server.
Sorting Results
FHIR also allows sorting using the _sort
parameter.
Example:
GET [base]/Patient?gender=female&_sort=birthdate
This gives you all female patients, sorted by their birth date. The first result will be the oldest female patient on the server.
You can also sort by metadata fields such as _lastUpdated
:
GET [base]/Patient?gender=female&_sort=-_lastUpdated
Adding a minus sign (-) sorts in descending order, so you’ll get the most recently updated patient record first.
Combining Multiple Parameters
You can combine search parameters using &
.
Example:
GET [base]/Patient?gender=female&name=jane
This fetches all female patients named Jane.
Common Search Parameters
In addition to resource-specific parameters, FHIR defines common parameters available across all resources, such as:
_id
→ search by resource ID_lastUpdated
→ filter by last update timestamp_tag
,_profile
,_security
→ search based on metadata
These parameters provide consistency across different FHIR resources.
This is just the tip of the iceberg. The FHIR search specification is extensive and worth exploring if you want to go deeper.