From 3a381c239df291d424e6dfbf584eb18400fbc492 Mon Sep 17 00:00:00 2001 From: Simon Ringuette Date: Thu, 4 Feb 2021 00:21:28 -0500 Subject: [PATCH] Allow to set headers on FHIR calls (fixes #13) --- README.md | 12 +++++++++--- src/components/PatientDetail/index.js | 2 +- src/lib/PatientSearch.js | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 51734e4..61901bc 100644 --- a/README.md +++ b/README.md @@ -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 [ { diff --git a/src/components/PatientDetail/index.js b/src/components/PatientDetail/index.js index ab3c8d8..d282411 100644 --- a/src/components/PatientDetail/index.js +++ b/src/components/PatientDetail/index.js @@ -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 => { diff --git a/src/lib/PatientSearch.js b/src/lib/PatientSearch.js index 993a352..d9b011c 100644 --- a/src/lib/PatientSearch.js +++ b/src/lib/PatientSearch.js @@ -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 @@ -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) {