Flexpa Node SDK
The Flexpa Node SDK is a TypeScript library that provides a simple way to interact with the Flexpa API and FHIR API.
It provides a set of methods to perform the token exchange, introspect, refresh, and revoke the access token.
It also provides methods to interact with the FHIR API, such as reading, searching, and retrieving all the resources for the patient.
#Prerequisites
To use the Flexpa Node SDK, you must have NodeJs version 18 or higher installed on your machine. You can download NodeJs from the official website.
#Installation
To install the Flexpa Node SDK, run this command in your terminal.
Install SDK
yarn install @flexpa/node-sdk
#Getting Started
After installing the package, import it into your project to start using the FlexpaClient
.
Import FlexpaClient
import FlexpaClient from '@flexpa/node-sdk';
#Initialize
You have a few different options for initializing the FlexpaClient
, depending on whether or not you have an existing access token or need to perform the token exchange.
If you already have a workflow set up to obtain an access token and you simply want to use the FlexpaClient
to call our APIs, please use the fromBearerToken function.
If you'd like to use the FlexpaClient
to assist with the full token exchange process, please use the fromExchange function.
This will ultimately provide you with an access token that you can use to call our APIs.
Both methods will provide a FlexpaClient
that you can use to interact with the Flexpa APIs.
Once the FlexpaClient
is initialized, you can use it to call the Flexpa APIs, such as the Link API and the FHIR API.
#fromBearerToken
Initialize a FlexpaClient
from a given access token.
This is the recommended way to initialize the FlexpaClient
if you already have an access token and need to call the Flexpa APIs.
Parameters
- bearerTokenstringRequired
Access token
- apiBaseUrlstring
Flexpa API endpoint (default: https://api.flexpa.com
)
From Bearer Token
const flexpaClient = FlexpaClient.fromBearerToken('your-access-token');
#fromExchange
Initialize a FlexpaClient
from the token that is received after performing the Exchange step.
This is the recommended way to initialize the FlexpaClient
if you need to perform the token exchange and then call the Flexpa APIs.
Parameters
- publicTokenstringRequired
Public Token
- secretKeystringRequired
Secret Key
- apiBaseUrlstring
Flexpa API endpoint (default: https://api.flexpa.com
)
From Exchange
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
#Link API
#exchange
Perform the token exchange.
Parameters
- publicTokenstringRequired
Public Token
- secretKeystringRequired
Secret Key
Exchange
await flexpaClient.exchange(
'your-public-token',
'your-secret-key'
);
#introspect
Retrieve details about the access token
Introspect
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
const tokenDetails = await flexpaClient.introspect('your-access-token');
#tokenRefresh
Refresh the access token.
This method is only supported for MULTIPLE
usage patient authorizations.
Parameters
- publishableKeystringRequired
Publishable Key
- secretKeystringRequired
Secret Key
Token Refresh
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
const newAccessTokenData = await flexpaClient.refresh(
'your-publishable-key',
'your-secret-key'
);
#revoke
Revoke the access token
Parameters
- secretKeystringRequired
Secret Key
Revoke
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
await flexpaClient.revoke('your-access-token');
#FHIR API
#getCapabilityStatement
Get Capability Statement
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
const capabilityStatement = await flexpaClient.getCapabilityStatement();
#read
Read a FHIR resource
Parameters
- resourceTypestringRequired
Supported FHIR Resource
- idstringRequired
Resource ID
- numRetriesnumber
Number of retries (default: 10
)
- delayMsnumber
Delay in milliseconds (default: 1000
)
Read
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
const patient = await flexpaClient.read('Patient', 'patient-id');
#search
Search a FHIR resource
Parameters
- resourceTypestringRequired
Supported FHIR Resource
- searchParamsDictionaryRequired
Dictionary of search parameters
- numRetriesnumber
Number of retries (default: 10
)
- delayMsnumber
Delay in milliseconds (default: 1000
)
Search
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
const patients = await flexpaClient.search('Patient',
{ given: 'John' }
);
const observations = await flexpaClient.search('Observation',
{ patient: 'patient-id' }
);
#Patient $everything
Retrieve all the resources for the patient
$everything
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
const patientData = await flexpaClient.$everything();
#Utilities
#getAccessToken
Retrieve the access token
Get Access Token
const flexpaClient = await FlexpaClient.fromExchange(
'your-public-token',
'your-secret-key'
);
const accessToken = flexpaClient.getAccessToken();