Skip to content

Commit

Permalink
Allow to set headers on FHIR calls (fixes smart-on-fhir#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
sringuette committed Feb 4, 2021
1 parent 54b3175 commit 3a381c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ Note that these config files are in `json5` format which is like a loose version
Any config file might contain the following options:

- `server` - an object describing the FHIR API server
- `server.url` - The base URL of the FHIR API server to use. Note that the picker will only work with open servers that do not require authorization.
- `server.type` - The FHIR version. Currently this can be `DSTU-2` or `STU-3` or `R4`.
- `server.tags` - An array of tag objects to be rendered in the tags auto-complete menu. This defaults to an empty array and in that case the tag selection widget will not have a drop-down menu options but it will still allow you to search by typing some tag manually. In other words, using an empty array is like saying that we just don't know what tags (if any) are available on that server. The list of tags might look like this:
- `server.url` - The base URL of the FHIR API server to use. Note that the picker will only work with open servers that do not require authorization unless the headers option is added.
- `server.headers` - Optional headers (as key/value) to send to the FHIR server. Please note that any secret credentials used here are sent to the client browser and are accessible using developper tools. Headers might look like this:
```js
{
Authorization: "Bearer my-token"
}
```
- `server.type` - The FHIR version. Currently this can be `DSTU-2` or `STU-3` or `R4`.
- `server.tags` - An array of tag objects to be rendered in the tags auto-complete menu. This defaults to an empty array and in that case the tag selection widget will not have a drop-down menu options but it will still allow you to search by typing some tag manually. In other words, using an empty array is like saying that we just don't know what tags (if any) are available on that server. The list of tags might look like this:
```js
[
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/PatientDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class PatientDetail extends React.Component

// Find $everything
.then(state => {
return getAllPages({ url: `${server.url}/Patient/${state.patient.id}/$everything?_count=500` })
return getAllPages({ url: `${server.url}/Patient/${state.patient.id}/$everything?_count=500`, headers: server.headers })
.then(data => {
let groups = {};
data.forEach(entry => {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/PatientSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import moment from "moment"
import { CODE_SYSTEMS } from "./constants"
import { parseQueryString, request } from "."
import { intVal, getPath } from "."
import $ from "jquery"

/**
* This is just a helper class that is used as a query builder. It has some
Expand Down Expand Up @@ -819,6 +820,10 @@ export default class PatientSearch
}
};

if (server.headers) {
options.headers = $.extend(true, options.headers, server.headers);
}

return this.getPatientIDs(server)
.then(ids => {
if (ids.length) {
Expand Down

0 comments on commit 3a381c2

Please sign in to comment.