fhirclient
Version:
JavaScript client for Fast Healthcare Interoperability Resources
114 lines (85 loc) • 3.27 kB
Markdown
SMART on FHIR JavaScript Library
================================
This is a JavaScript library for connecting SMART apps to FHIR servers.
It works both in browsers (IE 10+) and on the server (Node 10+).
[](https://github.com/smart-on-fhir/client-js/actions/workflows/node.yml)
[](https://github.com/smart-on-fhir/client-js/actions/workflows/browser.yml)
[](https://coveralls.io/github/smart-on-fhir/client-js?branch=master)
[](https://badge.fury.io/js/fhirclient)
[](https://badgen.net/npm/types/fhirclient)
[](https://badgen.net/npm/node/fhirclient)
[](https://www.npmtrends.com/fhirclient)
<br/><br/>
## Installation
### From NPM
```sh
npm i fhirclient
```
### From CDN
Include it with a `script` tag from one of the following locations:
From NPM Release:
- https://cdn.jsdelivr.net/npm/fhirclient/build/fhir-client.js
- https://cdn.jsdelivr.net/npm/fhirclient/build/fhir-client.min.js
Latest development builds from GitHub:
- https://combinatronics.com/smart-on-fhir/client-js/master/dist/build/fhir-client.js
- https://combinatronics.com/smart-on-fhir/client-js/master/dist/build/fhir-client.min.js
## Browser Usage
In the browser you typically have to create two separate pages that correspond to your
`launch_uri` (Launch Page) and `redirect_uri` (Index Page).
### As Library
```html
<!-- launch.html -->
<script src="./node_module/fhirclient/build/fhir-client.js"></script>
<script>
FHIR.oauth2.authorize({
"client_id": "my_web_app",
"scope": "patient/*.read"
});
</script>
<!-- index.html -->
<script src="./node_module/fhirclient/build/fhir-client.js"></script>
<script>
FHIR.oauth2.ready()
.then(client => client.request("Patient"))
.then(console.log)
.catch(console.error);
</script>
```
```js
import FHIR from "fhirclient"
// Launch Page
FHIR.oauth2.authorize({
"client_id": "my_web_app",
"scope": "patient/*.read"
});
// Index Page
FHIR.oauth2.ready()
.then(client => client.request("Patient"))
.then(console.log)
.catch(console.error);
```
The server is fundamentally different environment than the browser but the
API is very similar. Here is a simple Express example:
```js
const fhirClient = require("fhirclient");
// This is what the EHR will call
app.get("/launch", (req, res) => {
fhirClient(req, res).authorize({
"client_id": "my_web_app",
"scope": "patient/*.read"
});
});
// This is what the Auth server will redirect to
app.get("/", (req, res) => {
fhirClient(req, res).ready()
.then(client => client.request("Patient"))
.then(res.json)
.catch(res.json);
});
```
<br/>
Apache 2.0