Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fhir-kit-client

Vermonster28.3kMIT1.9.2TypeScript support: included

FHIR Client

FHIR, SMART, CDS Hooks, HL7

readme

FHIRKit Client

npm version Build Status Coverage Status GitHub license

Node FHIR client library

Features

  • Support for R4 (4.0.1, 4.0.0, 3.5.0, 3.3.0, 3.2.0), STU3 (3.0.1, 1.8.0, 1.6.0, 1.4.0, 1.1.0) and DSTU2 (1.0.2)
  • Support for all FHIR REST actions
  • Support for FHIR operations
  • Typescript support
  • Pagination support for search results
  • Batch and transaction support
  • Support for absolute, in-bundle, and contained references
  • Metadata caching on client instance
  • SMART security support
  • Capability-checking tool based on server capability statements
  • Minimal dependencies
  • Contemporary async/await structure
  • Modern ES6 Classes
  • TDD with Mocha
  • URL polyfill (so it works in client-only apps without much trouble)
  • Support optional parameters for the request, such as TLS key and cert

Roadmap

Project roadmap uses Github Projects.

Typescript Support

There is now early Typescript support for this library. This library is intended to be agnostic to the version of FHIR, but there is a WIP pattern to use with @types/fhir.

Assume a project where you did the following setup:

> npm install fhir-kit-client
> npm install -D @types/fhir

Now in your code, you can:

import Client from 'fhir-kit-client'

const client = new Client({ baseUrl: 'http://foo.com' })

const isPatient = (resource: fhir4.Resource): resource is fhir4.Patient => {
  return resource.resourceType === 'Patient'
}

client
  .read({resourceType: 'Patient', id: '12'})
  .then(res => {
    if (isPatient(res)) {
      console.dir(res.name, { depth: 4})
    }
  })

This example uses a type guard for R4 Patient. If you are building an app that connects to systems with different versions, you could write a wrapper for each fhir version in your app.

Examples

Examples using promises...

const Client = require('fhir-kit-client');
const fhirClient = new Client({
  baseUrl: 'https://sb-fhir-stu3.smarthealthit.org/smartstu3/open'
  });

// Get SMART URLs for OAuth
fhirClient.smartAuthMetadata().then((response) => {
  console.log(response);
  });


// Direct request
fhirClient.request('Patient/123')
  .then(response => console.log(response));

fhirClient.request('Patient/123', { method: 'DELETE' })
  .then(response => console.log(response));

// Read a patient
fhirClient
  .read({ resourceType: 'Patient', id: '2e27c71e-30c8-4ceb-8c1c-5641e066c0a4' })
  .then((response) => {
    console.log(response);
  });


// Search for patients, and page through results
fhirClient
  .search({ resourceType: 'Patient', searchParams: { _count: '3', gender: 'female' } })
  .then((response) => {
    console.log(response);
    return response;
  })
  .then((response) => {
    console.log(response);
    return fhirClient.nextPage(response);
  })
  .then((response) => {
    console.log(response);
    return fhirClient.prevPage(response);
  })
  .catch((error) => {
    console.error(error);
  });

Examples using async/await...

const Client = require('fhir-kit-client');
const fhirClient = new Client({
  baseUrl: 'https://sb-fhir-stu3.smarthealthit.org/smartstu3/open'
  });

async function asyncExamples() {
  // Get SMART URLs for OAuth
  let response = await fhirClient.smartAuthMetadata();
  console.log(response);


  // Read a patient
  response = await fhirClient
    .read({ resourceType: 'Patient', id: '2e27c71e-30c8-4ceb-8c1c-5641e066c0a4' });
  console.log(response);


  // Search for a patient with name matching abbott, then paging
  let searchResponse = await fhirClient
    .search({ resourceType: 'Patient', searchParams: { name: 'abbott ' } })
  console.log(searchResponse);

  searchResponse = await fhirClient.nextPage(searchResponse);
  console.log(searchResponse);

  searchResponse = await fhirClient.prevPage(searchResponse);
  console.log(searchResponse);
}

asyncExamples();

For more examples see the JS Docs and Launch Examples below.

Documentation

JSDoc-generated documentation with plenty of examples

Launch Examples (SMART, CDS Hooks)

To see how to follow launch and authorization workflows for FHIR applications, see the examples directory and examples README.

Example React App

FHIRKit Create React App provides a create-react-app template that can be used to create a sample React app using FHIRKit Client.

Even more Examples (client-side ones)

See https://github.com/Vermonster/fhir-kit-client-examples for examples in React, Angular, and React Native.

Logging

The debug library can provide logging during development. Two different logging namespaces are provided, fhir-kit- client:info logs each request and response, and fhir-kit-client:error logs errors. To enable logging during development, add one of the namespaces to the DEBUG environment variable, or use fhir-kit-client:* to enable both.

$ DEBUG=fhir-kit-client:* node smart-launch.js

Contributing

FHIRKit Client is an open source Node.js FHIR client library that welcomes community contributions with enthusiasm.

All are welcome to participate. By participating in this project, you agree to follow the Code of Conduct.

Please see our Contributing document for more details on how to get started.

License

MIT

Copyright (c) 2018 Vermonster LLC

changelog

Changelog

1.9.2

  • Fix problem with typescript httpFor
  • Update node LTS requirement

1.9.1

  • Use node-abort-controller due to a problem with CRA (Create React App) 5+
  • Update dependencies

1.9.0

  • Update dependencies
  • Add support for conditional update

1.8.1

  • Address potential URL injection
  • Update typescript definitions

1.8.0

  • Add support for per-request signing (used by AWS HealthLake) thanks @ericfuxealth and @sdhakal-xealth!
  • Export CapabilityTool
  • Officially drop support for Node 10

1.7.2

  • Security updates

1.7.1

  • Fix a few problems with typescript definitions
  • Change to GH actions
  • Allow for longer FHIR ids (some systems use ids over 64)

1.7.0

  • Downgrade debug so it works in old IE (for Epic and other citrix-based EHRs)

1.6.8

  • Fix typescript interface for smart metadata

1.6.6 / 7 (re-tagged due to error)

  • Introduce typescript support
  • A few library version bumps

1.6.5

  • Minor updates

1.6.4

  • Update to use correct mime-type (thanks @oliveregger)
  • Update examples (human name)(thanks @oliveregger)

1.6.3

  • Fixed logging headers (thanks @jpnarkinsky and @awatson1978)
  • Updates SMART auth to not use set headers the deprecated way
  • Remove flatted

1.6.2

  • Add new client.request method to create request directly
  • Fix a bug where console.dir was not working with react native. NOTE: We will finally remove deprecation warnings and migrate to the new API in 1.7.0.
  • Update a dep in the examples

1.6.1

  • Fix a bug with headers when calling smart auth

1.6.0

  • Add support for .well-known (fetching SMART URIs)

1.5.3

  • Remove require url, as we are on node 10+ now

1.5.2

  • Add content-type default header if missing (fixes #129)
  • Update dependencies

1.5.1

  • Add support for operations

1.5.0

  • Drop support for node 8
  • Remove universal-url
  • Update dependencies

1.4.2

  • Update README

1.4.1

  • Update dependencies to address audit

1.4.0

  • Replace request with cross-fetch for better client support
  • Update npm packages
  • Update server example output
  • Refactor HttpClient
  • Add test for minimial response
  • Add test for setting TLS options (key, cert)
  • Fix code coverage tool
  • Better KeepAlive support
  • NOTE: Breaking Change: replaced Client.requestFor() function for accessing raw HTTP objects with Client.httpFor() which returns an object containing both the request and the response.

1.3.0 (June 12, 2019)

  • Add requestOptions (can be used to set cert/key/ca, etc) (thanks @sulkaharo)
  • Expose the raw http response object (thanks @sulkaharo)
  • Add support for POST searches
  • Fix null pointer exception (thanks @yinzara )

1.2.4 (May 9, 2019)

  • Use request errors to avoid throwing errors with no message (#99)

1.2.3 (Apr. 15, 2019)

  • Refactor parameters to replace headers with options. Use of the headers parameter is now DEPRECATED.

    Old style (DEPRECATED):

    client.read({
      resourceType: 'Patient',
      id: '123',
      headers: { CustomHeader: 'ABC' }
    });

    New style:

    client.read({
      resourceType: 'Patient',
      id: '123',
      options: { headers: { CustomHeader: 'ABC' } }
    })

1.2.2 (Feb. 22, 2019)

  • Improve error handling in search method

1.2.1 (Feb. 14, 2019)

  • Add missing request dependency

1.2.0 (Jan. 16, 2019)

  • Keep connections alive (#82)
  • Support repeated query parameters (#87)

1.1.0 (Jan. 16, 2019)

  • Add R4 support (#77)
  • Fix broken examples (#79)

1.0.0 (Dec. 21, 2018)

  • Fixed bug handling request errors (#72)
  • Breaking Change: Throw an error if a client's baseUrl is blank (#73)
  • Add the ability to add custom headers to a request (#74)