core.medplumclient
Home > @medplum/core > MedplumClient
MedplumClient class
The MedplumClient class provides a client for the Medplum FHIR server.
The client can be used in the browser, in a Node.js application, or in a Medplum Bot.
The client provides helpful methods for common operations such as: 1. Authenticating 2. Creating resources 3. Reading resources 4. Updating resources 5. Deleting resources 6. Searching 7. Making GraphQL queries
The client can also be used to integrate with other FHIR servers. For an example, see the Epic Connection Demo Bot [here](https://github.com/medplum/medplum/tree/main/examples/medplum-demo-bots/src/epic).
Signature:
export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMap>
Extends: TypedEventTarget<MedplumClientEventMap>
Example 1
Here is a quick example of how to use the client:
import { MedplumClient } from '@medplum/core';
const medplum = new MedplumClient();
Example 2
Create a Patient
:
const patient = await medplum.createResource({
resourceType: 'Patient',
name: [{
given: ['Alice'],
family: 'Smith'
}]
});
Example 3
Read a Patient
by ID:
const patient = await medplum.readResource('Patient', '123');
console.log(patient.name[0].given[0]);
Example 4
Search for a Patient
by name:
const bundle = await medplum.search('Patient', 'name=Alice');
console.log(bundle.total);
Constructors
Constructor | Modifiers | Description |
---|---|---|
Constructs a new instance of the |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
| boolean | ||
| Returns the key value client. |
Methods
Method | Modifiers | Description |
---|---|---|
Performs Bulk Data Export operation request flow. See The FHIR "Bulk Data Export" for full details: https://build.fhir.org/ig/HL7/bulk-data/export.html\#bulk-data-export | ||
Clears all auth state including local storage and session storage. | ||
Clears the active login from local storage. Does not clear all local storage (such as other logins). | ||
Creates a FHIR This is a convenience method for creating a The A | ||
createAttachment(data, filename, contentType, onProgress, options) | ||
Creates a FHIR The return value is the newly created resource, including the ID and meta. The A | ||
createBinary(data, filename, contentType, onProgress, options) | ||
Creates a FHIR This is a convenience method to handle commmon cases where a | ||
Creates a FHIR Media resource with the provided data content. | ||
Creates a PDF as a FHIR The return value is the newly created resource, including the ID and meta. The | ||
Creates a new FHIR resource. The return value is the newly created resource, including the ID and meta. | ||
Conditionally create a new FHIR resource only if some equivalent resource does not already exist on the server. The return value is the existing resource or the newly created resource, including the ID and meta. | ||
Makes an HTTP DELETE request to the specified URL. This is a lower level method for custom requests. For common operations, we recommend using higher level methods such as | ||
Deletes a FHIR resource by resource type and ID. | ||
Downloads the URL as a blob. Can accept binary URLs in the form of | ||
Returns the PKCE code challenge and method. If the login request already includes a code challenge, it is returned. Otherwise, a new PKCE code challenge is generated. | ||
Exchange an external access token for a Medplum access token. | ||
Executes a batch or transaction of FHIR operations. | ||
Executes a bot by ID or Identifier. | ||
Connects to a | ||
Gets the current context of the given FHIRcast | ||
Publishes a new context to a given topic for a specified event type. | ||
Subscribes to a specified topic, listening for a list of specified events. Once you have the | ||
Unsubscribes from the specified topic. | ||
Builds a FHIR search URL from a search query or structured query object. | ||
Builds a FHIR URL from a collection of URL path components. For example, | ||
Makes an HTTP GET request to the specified URL. This is a lower level method for custom requests. For common operations, we recommend using higher level methods such as | ||
Returns the current user access policy if available. | ||
Returns the current access token. | ||
Returns the current authorize URL. By default, this is set to | ||
Returns the current base URL for all API requests. By default, this is set to | ||
Returns a cached resource if it is available. | ||
Returns a cached resource if it is available. | ||
getExternalAuthRedirectUri(authorizeUrl, clientId, redirectUri, loginRequest, pkceEnabled) | Builds the external identity provider redirect URI. | |
Gets a Promise that resolves when async initialization is complete. This is particularly useful for waiting for an async | ||
Returns the list of available logins. | ||
Returns the current logout URL. By default, this is set to | ||
Get the master The master It can also be used to listen for ------ | ||
Returns the current user profile resource if available. This method does not wait for loading promises. | ||
Returns the current user profile resource, retrieving form the server if necessary. This method waits for loading promises. | ||
Returns the current project if available. | ||
Returns the current project membership if available. | ||
Gets the | ||
Returns the current token URL. By default, this is set to | ||
Returns the current user configuration if available. | ||
Executes a GraphQL query. | ||
Invalidates all cached values and flushes the cache. | ||
Invalidates all cached search results or cached requests for the given resourceType. | ||
Invalidates any cached values or cached requests for the given URL. | ||
Invite a user to a project. | ||
Returns true if the client is waiting for authentication. | ||
Returns true if the current user is authenticated as a project admin. | ||
Returns true if the current user is authenticated as a super admin. | ||
Makes an HTTP PATCH request to the specified URL. This is a lower level method for custom requests. For common operations, we recommend using higher level methods such as | ||
Updates a FHIR resource using JSONPatch operations. The return value is the updated resource, including the ID and meta. | ||
Makes an HTTP POST request to the specified URL. This is a lower level method for custom requests. For common operations, we recommend using higher level methods such as | ||
Processes an OAuth authorization code. See: https://openid.net/specs/openid-connect-core-1\_0.html\#TokenRequest | ||
pushToAgent(agent, destination, body, contentType, waitForResponse, options) | Pushes a message to an agent. | |
Makes an HTTP PUT request to the specified URL. This is a lower level method for custom requests. For common operations, we recommend using higher level methods such as | ||
Reads resource history by resource type and ID. The return value is a bundle of all versions of the resource. | ||
Executes the Patient "everything" operation for a patient. | ||
Reads a resource by This is a convenience method for | ||
Reads a resource by resource type and ID. | ||
Executes the $graph operation on this resource to fetch a Bundle of resources linked to the target resource according to a graph definition | ||
Reads a specific version of a resource by resource type, ID, and version ID. | ||
Refreshes the access token using the refresh token if available. | ||
Requests the schema for a profile. If the schema is already cached, the promise is resolved immediately. | ||
Requests the schema for a resource type. If the schema is already cached, the promise is resolved immediately. | ||
Sends a FHIR search request. | ||
Sends a FHIR search request for a single resource. This is a convenience method for | ||
Creates an [async generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/AsyncGenerator) over a series of FHIR search requests for paginated search results. Each iteration of the generator yields the array of resources on each page. | ||
Sends a FHIR search request for an array of resources. This is a convenience method for | ||
Searches a ValueSet resource using the "expand" operation. See: https://www.hl7.org/fhir/operation-valueset-expand.html | ||
Sends an email using the Medplum Email API. Builds the email using nodemailer MailComposer. Examples: | ||
Sets the current access token. | ||
Sets the active login. | ||
Sets the client ID and secret for basic auth. | ||
signInWithExternalAuth(authorizeUrl, clientId, redirectUri, baseLogin, pkceEnabled) | Initiates sign in with an external identity provider. | |
Tries to sign in the user. Returns true if the user is signed in. This may result in navigating away to the sign in page. | ||
Signs out locally. Does not invalidate tokens with the server. | ||
Tries to sign out the user. See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html | ||
Starts an async request following the FHIR "Asynchronous Request Pattern". See: https://hl7.org/fhir/r4/async.html | ||
Starts a new OAuth2 client credentials flow. | ||
Tries to sign in with Google authentication. The response parameter is the result of a Google authentication. See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions | ||
Starts a new OAuth2 JWT assertion flow. See: https://datatracker.ietf.org/doc/html/rfc7523\#section-2.2 | ||
Starts a new OAuth2 JWT bearer flow. | ||
Initiates a user login flow. | ||
Initiates a new patient flow. This requires a partial login from | ||
Initiates a new project flow. This requires a partial login from | ||
Initiates a new user flow. This method is part of the two different user registration flows: 1) New Practitioner and new Project 2) New Patient registration | ||
Starts a new PKCE flow. These PKCE values are stateful, and must survive redirects and page refreshes. | ||
Subscribes to a given criteria, listening to notifications over WebSockets. This uses Medplum's A When subscribing to the same criteria multiple times, the same ----- | ||
Unsubscribes from the given criteria. When called the same amount of times as proceeding calls to | ||
Updates a FHIR resource. The return value is the updated resource, including the ID and meta. | ||
uploadMedia(contents, contentType, filename, additionalFields, options) | Upload media to the server and create a Media instance for the uploaded content. | |
uploadwithProgress(url, data, contentType, onProgress, options) | ||
Upsert a resource: update it in place if it exists, otherwise create it. This is done in a single, transactional request to guarantee data consistency. | ||
Executes the validate operation with the provided resource. | ||
Searches a ValueSet resource using the "expand" operation. See: https://www.hl7.org/fhir/operation-valueset-expand.html |