Skip to main content

Basic Search in FHIR on Medplum

This is an introductory post to searching in FHIR on Medplum. It will introduce the basic concepts and provide some sample code on how to execute basic searches. We won't cover all the FHIR search scenarios, for in depth reference material on FHIR search, this document is a good place to start.

There are two high level concepts that is is useful to understand when learning about Search in FHIR:

Using these two basic concepts, let's walk through an example where you want to query all the Patient resources with a name like "Alex".

To execute this search as via API, here's how you would do it using curl. In this example, we are using the _count parameter to limit to the first 20 results, sorted in descending order by _lastUpdated.

Learning all of the FHIR objects and search parameters can be intimidating, but you can use Medplum as a tool to learn how to construct searches.

FHIR Search Tutorial Video

Medplum has advanced Search built in, which we will use here to illustrate. The tool allows you to view all the searchable fields. To use this example effectively, you need to be using Google Chrome.

  • To get started navigate to a page that shows all of the FHIR objects of a certain type, for example the Patient page.
  • Add fields by clicking on the Fields button on the top nav, it will show you all the fields for this object. Add whichever ones you like to view them in the tool.
  • Add filters on search parameters by clicking on the Filters button on the top nav, it will allow you to filter results, for example search for patients with a name like 'Alex'.
  • Once you have set up your fields and filters, open the Developer Tools in chrome, open the Network tab and refresh. You will be able to copy the search request as curl instructions.
  • Of note: make sure to copy the requests of type fetch, requests marked type preflight are permissions checks and will not return data.

Using this technique, hopefully that will make it straightforward to learn and construct FHIR searches.

Searching Linked Objects

FHIR also allows you to search across objects, a common use case. For example, if you want to find all of the DiagnosticReports has a reference to a particular Patient, you can pass in a reference to the patient to the search parameter.

FHIR supports this by allowing you to pass in FHIR objects as Search parameters.

Here's an example that requests all DiagnosticReports for a given Patient are referenced by their id