FHIR API
Searching
Find exactly the resources you need with search parameters, modifiers, prefixes and result controls.
Search is a GET on a resource type with query parameters. The result is a Bundle of type: searchset.
curl -s "$FHIR/Patient?family=hammes&gender=female" | jq '.total, [.entry[].resource.id]'How parameters combine#
| You write | It means |
|---|---|
?a=1&b=2 |
a AND b |
?code=x,y |
code x OR y (comma) |
?date=ge2020&date=lt2021 |
the same parameter twice is AND, which gives you a range |
To see which parameters a type supports, look in the CapabilityStatement (rest.resource.searchParam) or in the spec page's Search Parameters table.
Parameter types#
String#
Matches names and text. By default it's case-insensitive, ignores accents and matches the start of a word.
Patient?family=ham # Hammes, Hamilton ...
Patient?family:exact=Hammes # exact, case-sensitive
Patient?name:contains=amm # anywhere in the string
Patient?name=linh # any part of the name (given, family, text)Token#
Matches codes and identifiers. Use the system|code form.
Observation?code=http://loinc.org|8867-4 # system and code
Observation?code=8867-4 # any system (avoid in production)
Patient?identifier=https://fhirdrill.dev/mrn|DRILL-0001
Condition?clinical-status=active
Observation?code:text=heart # matches the display text
Observation?status:not=finalReference#
Observation?subject=Patient/1234
Observation?patient=1234 # same thing, the type is implied
Encounter?participant:Practitioner=55Date#
Dates take a prefix:
| Prefix | Means |
|---|---|
eq (default) |
within the precision given (2024 matches the whole year) |
ne |
not equal |
gt / lt |
after / before |
ge / le |
on or after / on or before |
sa / eb |
starts after / ends before (for periods) |
ap |
approximately |
Patient?birthdate=lt1950-01-01
Encounter?date=ge2024-01-01&date=lt2025-01-01
Observation?date=ge2025-06-01T00:00:00+10:00Number and quantity#
Observation?value-quantity=gt100|http://unitsofmeasure.org|mg/dL
RiskAssessment?probability=gt0.8Missing values#
Patient?telecom:missing=true # patients with no telecomControlling the results#
| Parameter | Effect |
|---|---|
_count=50 |
Page size (HAPI's maximum is 200 by default) |
_sort=-date |
Sort, with - for descending. Combine keys: _sort=family,-birthdate |
_summary=count |
Return the total only |
_summary=true |
Return only the summary elements of each resource |
_elements=name,birthDate |
Return only these fields |
_total=accurate |
Make HAPI compute an exact total |
_id=1,2,3 |
Fetch several resources by id |
_lastUpdated=gt2026-11-01 |
Only resources changed since a date |
_tag, _profile, _security |
Search on meta fields |
Debug a search
Check .link[] | select(.relation=="self") in the response. It shows the search as the server understood it. If a parameter is missing from that link, the server ignored it, usually because of a typo.
POST search#
URLs have length limits, and they can end up in logs. You can send the same search as a form body:
curl -s -X POST "$FHIR/Patient/_search" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "family=hammes" --data-urlencode "birthdate=lt1980"