@zapehr/sdk
TypeScript icon, indicating that this package has built-in type declarations

2.1.7 • Public • Published

ZapEHR Logo

The complete health-tech developer platform.

WebsiteDocumentation

Version Compatible Node Versions Install Size Minified Size Downloads / Month License

ZapEHR SDK

The ZapEHR SDK is a TypeScript library for interacting with ZapEHR's FHIR and Project APIs.

While you can always make raw HTTP requests to ZapEHR'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 ZapEHR'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.

Installation

npm install @zapehr/sdk

Usage

  1. Import the SDK.
  2. Initialize the SDK with a ZapEHR access token. (Learn how to get an access token).
  3. Invoke any of ZapEHR's APIs with a function call.
import zapehr from '@zapehr/sdk'

zapehr.init({
  ZAPEHR_ACCESS_TOKEN: 'your_access_token',
});

// Create a Patient FHIR resource
const patient = await zapehr.fhir.create({
  resourceType: 'Patient',
});

// Upload a zambda
try {
  const zambda = await zapehr.project.zambda.create({ name: 'new zambda', triggerMethod: 'http_open' });
  const fileHandle = await fs.open('./path/to/my/zambda.zip')
  const file = new Blob([await fileHandle.readFile()]);
  await zapehr.project.zambda.uploadFile({ id: createZambda.data.id, file, })
} catch (err) {
  // Handle error thrown by ZapEHR or JS in some way
}

Convenience Functions

Z3

Under the hood, uploading and downloading files with Z3 is a two-step process:

  1. Create a presigned URL to upload or download the file (API Reference).
  2. 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:

    await zapehr.project.z3.uploadFile(
      { bucketName: 'your-bucket-name', 'objectPath+': 'path/to/your-filename', file: someFileBlob }
    );

In the example, someFileBlob is a Blob.

    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.

  const zambdaFile = fs.readFileSync('build/your-zambda-code.zip');
  await zapehr.project.zambda.uploadFile({
    id: yourZambdaId,
    file: new Blob([zambdaFile]),
  });

Package Sidebar

Install

npm i @zapehr/sdk

Weekly Downloads

725

Version

2.1.7

License

MIT

Unpacked Size

1.33 MB

Total Files

153

Last publish

Collaborators

  • cwelchml
  • ibenham
  • shawnlimkq95
  • ozubaidi
  • jsaewitz
  • bholyshevskyi
  • awillinghamml