Skip to main content

Getting Started

Download our TypeScript client to get started.

Installation

To install the Plasma FHIR Client into your project

npm install @plasmahealth/plasma-fhir-client --save

We also recommend installing the FHIR types

npm install @types/fhir --save

Initialize the Plasma FHIR Client

The Plasma FHIR Client is a module that helps you to communicate with a FHIR server. To initialize the client, we need two pieces of information:

  • Location of the FHIR server
  • Information about how to authenticate requests

There are multiple ways to initialize the client depending on your use case.


Initialization via Plasma

Using Plasma to connect and initialize the Plasma FHIR Client is the recommended way to use the library, as it will provide you access to the Plasma engine and all of the cross-platform and convenient configuration management capabilities.

Initializing After OAuth2

import { PlasmaPlatformClient } from "@plasmahealth/plasma-fhir-client";

const plasmaBaseUrl = "https://plasma.smart-on-fhir.com";
const state = "state-123";
const plasma: PlasmaFHIRClient = PlasmaPlatformClient.fromState(plasmaBaseUrl, state);

Initializing for Backend Application

import { PlasmaPlatformClient } from "@plasmahealth/plasma-fhir-client";

const plasmaBaseUrl = "https://plasma.smart-on-fhir.com";
const projectId = "my-project-id";
const environmentId = "my-evironment-id-for-example-epic";
const projectSecret = "my-project-secret";
const plasma: PlasmaFHIRClient = await PlasmaPlatformClient.forBackend(plasmaBaseUrl, projectId, environmentId, projectSecret);

Initialization via FHIR Server

You can also use the Plasma FHIR Client to connect to a FHIR server without using Plasma. A few different methods are described below.

Initializing for Open Server (No Authentication)

If you are working with an open server that does not require authentication (such as the SMART Health IT Sandbox):

import { PlasmaFHIRClient } from "@plasmahealth/plasma-fhir-client";

const fhirUrl = "http://.../r4";
const plasma: PlasmaFHIRClient = PlasmaFHIRClient.forNoAuth(fhirUrl);

Initializing for Basic Auth

import { PlasmaFHIRClient } from "@plasmahealth/plasma-fhir-client";

const fhirUrl = "http://.../r4";
const plasma: PlasmaFHIRClient = PlasmaFHIRClient.forBasicAuth(fhirUrl, "my-user", "my-password");

Initializing for OAuth2 (with existing token)

If you are using OAuth2 and already have an existing token, you can initialize the client with the code below. We describe additional modules that can help with requesting a token in a later section.

import { PlasmaFHIRClient } from "@plasmahealth/plasma-fhir-client";

const fhirUrl = "http://.../r4";
const authToken = "123123123";
const plasma: PlasmaFHIRClient = PlasmaFHIRClient.forBearerToken(fhirUrl, "authToken");

Initializing for Backend Application

If you are building a "Backend" SMART-on-FHIR application, we recommend that you use the PlasmaPlatformClient module. This will help you to generate the authentication token you need in order to make requests.

Example:

const plasmaBaseUrl = "https://plasma.smart-on-fhir.com";
const projectId = "{your-project-id}";
const projectSecret = "{your-project-secret}";
const environmentId = "{your-environment-id}";

const plasma = await PlasmaPlatformClient.forBackend(plasmaBaseUrl, projectId, environmentId, projectSecret);
const patients = await plasma.searchPatient({ name: "John" });