3.2.18 • Published 11 months ago

@medplum/core v3.2.18

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

Medplum JS Client Library

The Medplum JS Client Library is a pure TypeScript library for calling a FHIR server from the browser.

Key Features

  • FHIR validation and operations
  • FHIR client to create, read, update, delete, patch, and search
  • WebSockets for realtime communication
  • Evaluation of FhirPath
  • No external dependencies

Installation

Add as a dependency:

npm install @medplum/core

Basic Usage

Create a new MedplumClient:

import { MedplumClient } from '@medplum/core';

const medplum = new MedplumClient();

Create a MedplumClient with additional configuration options:

import { MedplumClient } from '@medplum/core';

const medplum = new MedplumClient({
  baseUrl: 'https://www.example.com/fhir/R4/',
  clientId: 'MY_CLIENT_ID',
});

Authenticate with client credentials

const medplum = new MedplumClient();
await medplum.startClientLogin(MY_CLIENT_ID, MY_CLIENT_SECRET);

Authenticating with Medplum

If you are using Medplum as your FHIR server, you can use a direct sign-in API to authenticate email and password.

Before you begin

  1. Create a project in the Medplum App
  2. Enable Email/Password

After that, you can use the startLogin() method:

const loginResult = await medplum.startLogin({ email, password, remember });
const profile = await medplum.processCode(loginResult.code);
console.log(profile);

Authenticating with OAuth

Authenticate with a FHIR server via OAuth2 redirect:

medplum.signInWithRedirect().then((user) => console.log(user));

Search

Search for any resource using a FHIR search string:

search<K extends ResourceType>(
  resourceType: K,
  query?: URLSearchParams | string,
  options: RequestInit = {}
): ReadablePromise<Bundle<ExtractResource<K>>>

Example:

const bundle = await medplum.search('Patient', 'given=eve');
bundle.entry.forEach((entry) => console.log(entry.resource));

Create

Create resource:

createResource<T extends Resource>(resource: T): Promise<T>

Example:

medplum.createResource({
  resourceType: 'Observation',
  subject: {
    reference: 'Patient/123',
  },
  valueQuantity: {
    // ...
  },
  // ...
});

Read a resource

Read a resource by ID:

readResource<T extends Resource>(resourceType: string, id: string): Promise<T>

Example:

const patient = await medplum.readResource('Patient', '123');

Read resource history

Read resource history:

readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>

Example:

const historyBundle = await medplum.readHistory('Patient', '123');

Read resource version

Read a specific version:

readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>

Example:

const version = await medplum.readVersion('Patient', '123', '456');

Update a resource

Update a resource:

updateResource<T extends Resource>(resource: T): Promise<T>

Example:

const result = await medplum.updateResource({
  resourceType: 'Patient',
  id: '123',
  name: [
    {
      family: 'Smith',
      given: ['John'],
    },
  ],
});
console.log(result.meta.versionId);

Delete a resource

Delete a resource:

deleteResource(resourceType: string, id: string): Promise<any>

Example:

await medplum.deleteResource('Patient', '123');

Patch a resource

Patch a resource:

patchResource<T extends Resource>(resourceType: string, id: string, operations: Operation[]): Promise<T>

Example:

const result = await medplum.patchResource('Patient', '123', [
  { op: 'replace', path: '/name/0/family', value: 'Smith' },
]);
console.log(result.meta.versionId);

GraphQL

Execute a GraphQL query:

graphql(query: string, options?: RequestInit): Promise<any>

Example:

const result = await graphql(`
  {
    PatientList(name: "Alice") {
      name {
        given
        family
      }
    }
  }
`);

About Medplum

Medplum is a healthcare platform that helps you quickly develop high-quality compliant applications. Medplum includes a FHIR server, React component library, and developer app.

License

Apache 2.0. Copyright © Medplum 2024

3.2.18

11 months ago

3.2.17

11 months ago

3.2.16

12 months ago

3.2.9

1 year ago

3.2.8

1 year ago

3.2.13

12 months ago

3.2.12

12 months ago

3.2.15

12 months ago

3.2.14

12 months ago

3.2.11

12 months ago

3.2.10

1 year ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.2.6

1 year ago

3.2.5

1 year ago

3.2.4

1 year ago

3.2.3

1 year ago

3.2.7

1 year ago

3.1.7

1 year ago

3.1.6

1 year ago

3.1.11

1 year ago

3.1.10

1 year ago

3.1.9

1 year ago

3.1.8

1 year ago

3.1.5

1 year ago

3.1.4

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.13

1 year ago

3.0.12

1 year ago

3.0.11

1 year ago

3.0.10

1 year ago

3.0.9

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.2.10

2 years ago

2.2.7

2 years ago

2.2.6

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.25

2 years ago

2.1.24

2 years ago

2.1.23

2 years ago

2.1.22

2 years ago

2.0.28

2 years ago

2.0.29

2 years ago

2.0.31

2 years ago

2.0.32

2 years ago

2.0.30

2 years ago

2.1.9

2 years ago

2.1.16

2 years ago

2.1.17

2 years ago

2.1.14

2 years ago

2.1.15

2 years ago

2.1.12

2 years ago

2.1.13

2 years ago

2.1.10

2 years ago

2.1.11

2 years ago

2.1.18

2 years ago

2.1.19

2 years ago

2.1.21

2 years ago

2.1.20

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.0

2 years ago

2.0.26

2 years ago

2.0.27

2 years ago

2.0.25

2 years ago

2.0.19

2 years ago

2.0.18

2 years ago

2.0.24

2 years ago

2.0.22

2 years ago

2.0.23

2 years ago

2.0.20

2 years ago

2.0.21

2 years ago

2.0.5

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.9

2 years ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.0.17

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago

0.10.1

3 years ago

0.10.2

3 years ago

0.10.0

3 years ago

0.9.34

3 years ago

0.9.35

3 years ago

0.9.36

3 years ago

0.9.37

3 years ago

0.9.32

3 years ago

0.9.33

3 years ago

0.9.38

3 years ago

0.9.12

3 years ago

0.9.13

3 years ago

0.9.14

3 years ago

0.9.15

3 years ago

0.9.16

3 years ago

0.9.17

3 years ago

0.9.18

3 years ago

0.9.19

3 years ago

0.9.30

3 years ago

0.9.31

3 years ago

0.9.23

3 years ago

0.9.24

3 years ago

0.9.25

3 years ago

0.9.26

3 years ago

0.9.20

3 years ago

0.9.21

3 years ago

0.9.22

3 years ago

0.9.27

3 years ago

0.9.28

3 years ago

0.9.29

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.9

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.10

3 years ago

0.9.6

3 years ago

0.9.11

3 years ago

0.9.5

3 years ago

0.9.2

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.5.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.6

4 years ago

0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.30

4 years ago

0.0.28

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago