TypeScript SDK
The Oystehr TypeScript SDK makes it easy to work with Oystehr's APIs (opens in a new tab) from TypeScript.
While you can always make raw HTTP requests to Oystehr's APIs from any language, this SDK provides several advantages for developers:
- TypeScript types — The SDK provides complete typing for requests and responses across all of Oystehr's APIs. This gives you helpful autocomplete and build-time type checking.
- Convenience functions — The SDK provides convenience functions for doing common tasks like uploading and downloading files with Z3.
Usage
Installation
Our SDK is available as an npm package (opens in a new tab).
npm install @zapehr/sdk
Overview
- Import the SDK.
- Initialize the SDK with a Oystehr access token. (Learn how to get an access token).
- Invoke any of Oystehr's APIs with a function call.
Example
Create a Patient resource in FHIR with the v2 SDK
import zapehr from '@zapehr/sdk'
// Initialize the SDK with a Oystehr access token
zapehr.init({
ZAPEHR_ACCESS_TOKEN: "<your_access_token>",
});
// Create a Patient FHIR resource
const patient = await zapehr.fhir.create<Patient>({
resourceType: 'Patient',
active: true,
name: [
{
given: ['Jon'],
family: 'Snow',
},
],
address: [
{
use: 'home',
type: 'physical',
text: 'Winterfell',
},
],
});
Convenience Functions
Z3
Under the hood, uploading and downloading files with Z3 is a two-step process:
- Create a presigned URL to upload or download the file (API Reference (opens in a new tab)).
- Upload or download the file using the presigned URL.
The SDK provides convenience functions which combine these steps into a single function call to make it a one-liner:
Upload a file to Z3 with the SDK
await zapehr.project.z3.uploadFile(
{ bucketName: 'your-bucket-name', 'objectPath+': 'path/to/your-filename', file: someFileBlob }
);
In the example, someFileBlob
is a Blob (opens in a new tab).
Download a file from Z3 with the SDK
const downloadedBuffer = await zapehr.project.z3.downloadFile(
{ bucketName: 'your-bucket-name', 'objectPath+': 'path/to/your-filename' }
);
Zambda
Uploading code for your Zambda Functions is very similar to uploading a file with Z3. After creating your .zip
archive, use the uploadFile()
function to deploy your code.
Deploy a code zip to a Zambda Function
const zambdaFile = fs.readFileSync('build/your-zambda-code.zip');
await zapehr.project.zambda.uploadFile({
id: yourZambdaId,
file: new Blob([zambdaFile]),
});