PlasmaFHIRApi
Last updated
Last updated
The PlasmaFHIRApi
allows you to perform basic CRUD operations on FHIR resources. This API supports TypeScript and has full type support for FHIR resources.
The PlasmaFHIRApi
requires two pieces of data to initialize:
FHIR Server URL (so it knows where to query for data)
Auth Token (to prove to the server that you have permission to query for data)
If you are using the library, you can initialize a PlasmaFHIRApi
directly from the initialized client object.
If you want to use the API for a backend workflow, you can initialize a PlasmaFHIRApi
like this:
serverUrl
: URL of the FHIR server
privateKey
: Private key used for the JWT
clientId
: Client ID of your app
tokenUrl
: URL of the token endpoint
(!) Important: You MUST use Node 18.x or higher (because it uses the fetch
API).
npm install node-fetch@2 --save
Create and import the fetch-polyfill.js
file as described
(This initialization method may change slightly in the future)
Any resource can be read using readResource
and specifying the type of resource you want to read, along with any query string parameters you want to include.
NOTE: that you can also pass in the serverUrl
and authToken
if you'd like. If you don't pass them in, then the values provided when the API was initialized will be used.
When you are working with patient-specific data, it's recommended to use readPatientResource
. This function will specifically ask you to provide the patientId
so you don't forget. This method will incur an additional network query cost the first time you use it, because it will look up the "Conformance Statement" to determine which search parameter to use for the patient.
In some cases, we have resource-specific APIs. The purpose of this is to 1) provide more specificity to the search parameters you are allowed to pass in, and 2) to provide some abstraction for some common data types.
For example, vital signs are a type of Observation
with a category
of vital-signs
, so you could get that data like this:
But an easier method would be:
Or
Alternatively, you can use a polyfill as described here:
NOTE: If you don't want to use Resources
from plasma-fhir-app-utils
, you can also import the resource you need from the (they are compatible).