core.medplumclient | Medplum

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.

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
(constructor)(options) Constructs a new instance of the MedplumClient class

Properties

Property Modifiers Type Description
isInitialized readonly boolean
keyValue readonly MedplumKeyValueClient Returns the key value client.
requestCache protected
readonly
LRUCache < RequestCacheEntry \ undefined

Methods

Method Modifiers Description
bulkExport(exportLevel, resourceTypes, since, options) Performs Bulk Data Export operation request flow.
callCdsService(id, body, options) Calls a CDS service by ID.
clear() Clears all auth state including local storage and session storage.
clearActiveLogin() Clears the active login from local storage. Does not clear all local storage (such as other logins).
createAttachment(createBinaryOptions, requestOptions) Creates a FHIR Attachment with the provided data content.
createResource(resource, options) Creates a new FHIR resource.
deleteResource(resourceType, id, options) Deletes a FHIR resource by resource type and ID.
search(resourceType, query, options) Sends a FHIR search request.
updateResource(resource, options) Updates a FHIR resource.
graphql(query, operationName, variables, options) Executes a GraphQL query.