Concise client for Medplum's FHIR API.
Build a Medplum.Client, then pass it to the resource helpers in this module for
authenticated FHIR requests. Public operations return {:ok, map()} for decoded
response bodies or {:error, %Medplum.Error{}} for transport, auth, or API failures.
Clients reuse cached OAuth tokens by default, accept shared Req options, and expose
both resource helpers and lower-level request functions for unsupported endpoints.
Example
client =
Medplum.new(
base_url: "https://api.medplum.com",
client_id: System.fetch_env!("MEDPLUM_CLIENT_ID"),
client_secret: System.fetch_env!("MEDPLUM_CLIENT_SECRET")
)
{:ok, patient} = Medplum.read(client, "Patient", "123")
{:ok, patients} = Medplum.search(client, "Patient", %{"family" => "Smith"})
Summary
Functions
Executes a FHIR batch bundle against the base endpoint.
Creates a FHIR resource and fills in "resourceType" when it is omitted.
Uploads raw bytes to the Binary endpoint.
Deletes a FHIR resource by resource type and id.
Downloads raw bytes from a Binary resource.
Sends a GraphQL request to the FHIR GraphQL endpoint.
Builds a reusable Medplum client from base URL and client credentials.
Builds a reusable Medplum client and raises on invalid configuration.
Invokes a FHIR operation on the system, type, or instance level.
Applies a JSON Patch document to a resource by type and id.
Polls an async status URL until a final response is available.
Fetches one FHIR resource by resource type and id.
Sends an authenticated request to any FHIR-relative path or absolute Medplum URL.
Searches a FHIR resource type with query parameters encoded from the given map.
Streams Bundle entries across paginated search results.
Executes a FHIR transaction bundle against the base endpoint.
Replaces a FHIR resource by type and id, forcing the outgoing body to match both.
Performs an official Medplum conditional upsert using a query embedded in attrs.
Types
Functions
@spec batch(Medplum.Client.t(), [map()] | map()) :: result() | {:ok, async_result()}
Executes a FHIR batch bundle against the base endpoint.
@spec create(Medplum.Client.t(), String.t(), map()) :: result()
Creates a FHIR resource and fills in "resourceType" when it is omitted.
@spec create_binary(Medplum.Client.t(), binary(), keyword()) :: result()
Uploads raw bytes to the Binary endpoint.
@spec delete(Medplum.Client.t(), String.t(), String.t()) :: result()
Deletes a FHIR resource by resource type and id.
@spec get_binary(Medplum.Client.t(), String.t()) :: {:ok, binary_result()} | {:error, Medplum.Error.t()}
Downloads raw bytes from a Binary resource.
@spec graphql(Medplum.Client.t(), String.t(), keyword()) :: result()
Sends a GraphQL request to the FHIR GraphQL endpoint.
@spec new(keyword() | map()) :: Medplum.Client.t()
Builds a reusable Medplum client from base URL and client credentials.
@spec new!(keyword() | map()) :: Medplum.Client.t()
Builds a reusable Medplum client and raises on invalid configuration.
@spec operation( Medplum.Client.t(), :system | String.t() | {String.t(), String.t()}, String.t(), map(), keyword() ) :: result() | {:ok, async_result()}
Invokes a FHIR operation on the system, type, or instance level.
@spec patch(Medplum.Client.t(), String.t(), String.t(), [map()]) :: result()
Applies a JSON Patch document to a resource by type and id.
@spec poll_async(Medplum.Client.t(), String.t(), keyword()) :: result() | {:ok, async_result()}
Polls an async status URL until a final response is available.
@spec read(Medplum.Client.t(), String.t(), String.t()) :: result()
Fetches one FHIR resource by resource type and id.
@spec request(Medplum.Client.t(), atom(), String.t(), keyword()) :: result()
Sends an authenticated request to any FHIR-relative path or absolute Medplum URL.
@spec search(Medplum.Client.t(), String.t(), map()) :: result()
Searches a FHIR resource type with query parameters encoded from the given map.
@spec stream_search(Medplum.Client.t(), String.t(), map()) :: Enumerable.t()
Streams Bundle entries across paginated search results.
The stream yields each Bundle entry map and raises Medplum.Error if a later page fails.
@spec transaction(Medplum.Client.t(), [map()] | map()) :: result() | {:ok, async_result()}
Executes a FHIR transaction bundle against the base endpoint.
@spec update(Medplum.Client.t(), String.t(), String.t(), map()) :: result()
Replaces a FHIR resource by type and id, forcing the outgoing body to match both.
@spec upsert(Medplum.Client.t(), String.t(), map()) :: result()
Performs an official Medplum conditional upsert using a query embedded in attrs.