forked from jmandel/fhir-js-client
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
329c776
commit 5f7d96c
Showing
187 changed files
with
9,957 additions
and
2,220 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { fhirclient } from "."; | ||
import BrowserStorage from "./BrowserStorage"; | ||
import * as browserLib from "./browser"; | ||
/** | ||
* Browser Adapter | ||
*/ | ||
export default class BrowserAdapter implements fhirclient.Adapter { | ||
/** | ||
* Stores the URL instance associated with this adapter | ||
*/ | ||
private _url; | ||
/** | ||
* Holds the Storage instance associated with this instance | ||
*/ | ||
private _storage; | ||
/** | ||
* Environment-specific options | ||
*/ | ||
options: fhirclient.BrowserFHIRSettings; | ||
security: { | ||
randomBytes: typeof browserLib.randomBytes; | ||
digestSha256: typeof browserLib.digestSha256; | ||
generatePKCEChallenge: (entropy?: number) => Promise<browserLib.PkcePair>; | ||
importJWK: typeof browserLib.importJWK; | ||
signCompactJws: typeof browserLib.signCompactJws; | ||
}; | ||
/** | ||
* @param options Environment-specific options | ||
*/ | ||
constructor(options?: fhirclient.BrowserFHIRSettings); | ||
/** | ||
* Given a relative path, returns an absolute url using the instance base URL | ||
*/ | ||
relative(path: string): string; | ||
/** | ||
* Given the current environment, this method must return the current url | ||
* as URL instance | ||
*/ | ||
getUrl(): URL; | ||
/** | ||
* Given the current environment, this method must redirect to the given | ||
* path | ||
*/ | ||
redirect(to: string): void; | ||
/** | ||
* Returns a BrowserStorage object which is just a wrapper around | ||
* sessionStorage | ||
*/ | ||
getStorage(): BrowserStorage; | ||
base64urlencode(input: string | Uint8Array): string; | ||
base64urldecode(input: string): string; | ||
/** | ||
* Creates and returns adapter-aware SMART api. Not that while the shape of | ||
* the returned object is well known, the arguments to this function are not. | ||
* Those who override this method are free to require any environment-specific | ||
* arguments. For example in node we will need a request, a response and | ||
* optionally a storage or storage factory function. | ||
*/ | ||
getSmartApi(): fhirclient.SMART_API; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const smart_1 = require("./smart"); | ||
const Client_1 = __importDefault(require("./Client")); | ||
const BrowserStorage_1 = __importDefault(require("./BrowserStorage")); | ||
const browserLib = __importStar(require("./browser")); | ||
/** | ||
* Browser Adapter | ||
*/ | ||
class BrowserAdapter { | ||
/** | ||
* @param options Environment-specific options | ||
*/ | ||
constructor(options = {}) { | ||
/** | ||
* Stores the URL instance associated with this adapter | ||
*/ | ||
this._url = null; | ||
/** | ||
* Holds the Storage instance associated with this instance | ||
*/ | ||
this._storage = null; | ||
this.security = { | ||
randomBytes: browserLib.randomBytes, | ||
digestSha256: browserLib.digestSha256, | ||
generatePKCEChallenge: browserLib.generatePKCEChallenge, | ||
importJWK: browserLib.importJWK, | ||
signCompactJws: browserLib.signCompactJws | ||
}; | ||
this.options = { ...options }; | ||
} | ||
/** | ||
* Given a relative path, returns an absolute url using the instance base URL | ||
*/ | ||
relative(path) { | ||
return new URL(path, this.getUrl().href).href; | ||
} | ||
/** | ||
* Given the current environment, this method must return the current url | ||
* as URL instance | ||
*/ | ||
getUrl() { | ||
if (!this._url) { | ||
this._url = new URL(location + ""); | ||
} | ||
return this._url; | ||
} | ||
/** | ||
* Given the current environment, this method must redirect to the given | ||
* path | ||
*/ | ||
redirect(to) { | ||
location.href = to; | ||
} | ||
/** | ||
* Returns a BrowserStorage object which is just a wrapper around | ||
* sessionStorage | ||
*/ | ||
getStorage() { | ||
if (!this._storage) { | ||
this._storage = new BrowserStorage_1.default(); | ||
} | ||
return this._storage; | ||
} | ||
base64urlencode(input) { | ||
return browserLib.base64urlencode(input); | ||
} | ||
base64urldecode(input) { | ||
return browserLib.base64urldecode(input); | ||
} | ||
/** | ||
* Creates and returns adapter-aware SMART api. Not that while the shape of | ||
* the returned object is well known, the arguments to this function are not. | ||
* Those who override this method are free to require any environment-specific | ||
* arguments. For example in node we will need a request, a response and | ||
* optionally a storage or storage factory function. | ||
*/ | ||
getSmartApi() { | ||
return { | ||
ready: (...args) => (0, smart_1.ready)(this, ...args), | ||
authorize: options => (0, smart_1.authorize)(this, options), | ||
init: options => (0, smart_1.init)(this, options), | ||
client: (state) => new Client_1.default(state, this.getStorage()), | ||
options: this.options, | ||
utils: { | ||
security: this.security | ||
} | ||
}; | ||
} | ||
} | ||
exports.default = BrowserAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { fhirclient } from "."; | ||
export default class Storage implements fhirclient.Storage { | ||
get(key: string): Promise<any>; | ||
set(key: string, value: any): Promise<any>; | ||
unset(key: string): Promise<boolean>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Storage { | ||
async get(key) { | ||
const value = sessionStorage[key]; | ||
if (value) { | ||
return JSON.parse(value); | ||
} | ||
return null; | ||
} | ||
async set(key, value) { | ||
sessionStorage[key] = JSON.stringify(value); | ||
return value; | ||
} | ||
async unset(key) { | ||
if (key in sessionStorage) { | ||
delete sessionStorage[key]; | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
exports.default = Storage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { fhirclient } from "."; | ||
/** | ||
* This is a FHIR client that is returned to you from the `ready()` call of the | ||
* **SMART API**. You can also create it yourself if needed: | ||
* | ||
* ```js | ||
* // BROWSER | ||
* const client = FHIR.client("https://r4.smarthealthit.org"); | ||
* | ||
* // SERVER | ||
* const client = smart(req, res).client("https://r4.smarthealthit.org"); | ||
* ``` | ||
*/ | ||
export default class Client implements fhirclient.ClientInterface { | ||
/** | ||
* The state of the client instance is an object with various properties. | ||
* It contains some details about how the client has been authorized and | ||
* determines the behavior of the client instance. This state is persisted | ||
* in `SessionStorage` in browsers or in request session on the servers. | ||
*/ | ||
readonly state: fhirclient.ClientState; | ||
/** | ||
* The Storage to use | ||
*/ | ||
readonly storage: fhirclient.Storage; | ||
/** | ||
* A SMART app is typically associated with a patient. This is a namespace | ||
* for the patient-related functionality of the client. | ||
*/ | ||
readonly patient: { | ||
/** | ||
* The ID of the current patient or `null` if there is no current patient | ||
*/ | ||
id: string | null; | ||
/** | ||
* A method to fetch the current patient resource from the FHIR server. | ||
* If there is no patient context, it will reject with an error. | ||
* @param {fhirclient.FetchOptions} [requestOptions] Any options to pass to the `fetch` call. | ||
* @category Request | ||
*/ | ||
read: fhirclient.RequestFunction<fhirclient.FHIR.Patient>; | ||
/** | ||
* This is similar to [[request]] but it makes requests in the | ||
* context of the current patient. For example, instead of doing | ||
* ```js | ||
* client.request("Observation?patient=" + client.patient.id) | ||
* ``` | ||
* you can do | ||
* ```js | ||
* client.patient.request("Observation") | ||
* ``` | ||
* The return type depends on the arguments. Typically it will be the | ||
* response payload JSON object. Can also be a string or the `Response` | ||
* object itself if we have received a non-json result, which allows us | ||
* to handle even binary responses. Can also be a [[CombinedFetchResult]] | ||
* object if the `requestOptions.includeResponse`s has been set to true. | ||
* @category Request | ||
*/ | ||
request: <R = fhirclient.FetchResult>(requestOptions: string | URL | fhirclient.RequestOptions, fhirOptions?: fhirclient.FhirOptions) => Promise<R>; | ||
}; | ||
/** | ||
* The client may be associated with a specific encounter, if the scopes | ||
* permit that and if the back-end server supports that. This is a namespace | ||
* for encounter-related functionality. | ||
*/ | ||
readonly encounter: { | ||
/** | ||
* The ID of the current encounter or `null` if there is no current | ||
* encounter | ||
*/ | ||
id: string | null; | ||
/** | ||
* A method to fetch the current encounter resource from the FHIR server. | ||
* If there is no encounter context, it will reject with an error. | ||
* @param [requestOptions] Any options to pass to the `fetch` call. | ||
* @category Request | ||
*/ | ||
read: fhirclient.RequestFunction<fhirclient.FHIR.Encounter>; | ||
}; | ||
/** | ||
* The client may be associated with a specific user, if the scopes | ||
* permit that. This is a namespace for user-related functionality. | ||
*/ | ||
readonly user: { | ||
/** | ||
* The ID of the current user or `null` if there is no current user | ||
*/ | ||
id: string | null; | ||
/** | ||
* A method to fetch the current user resource from the FHIR server. | ||
* If there is no user context, it will reject with an error. | ||
* @param [requestOptions] Any options to pass to the `fetch` call. | ||
* @category Request | ||
*/ | ||
read: fhirclient.RequestFunction<fhirclient.FHIR.Patient | fhirclient.FHIR.Practitioner | fhirclient.FHIR.RelatedPerson>; | ||
/** | ||
* Returns the profile of the logged_in user (if any), or null if the | ||
* user is not available. This is a string having the shape | ||
* `{user type}/{user id}`. For example `Practitioner/abc` or | ||
* `Patient/xyz`. | ||
* @alias client.getFhirUser() | ||
*/ | ||
fhirUser: string | null; | ||
/** | ||
* Returns the type of the logged-in user or null. The result can be | ||
* `Practitioner`, `Patient` or `RelatedPerson`. | ||
* @alias client.getUserType() | ||
*/ | ||
resourceType: string | null; | ||
}; | ||
/** | ||
* Refers to the refresh task while it is being performed. | ||
* @see [[refresh]] | ||
*/ | ||
private _refreshTask; | ||
/** | ||
* Validates the parameters and creates an instance. | ||
*/ | ||
constructor(state: fhirclient.ClientState | string, storage: fhirclient.Storage); | ||
getPatientId(): string | null; | ||
getEncounterId(): string | null; | ||
getIdToken(): fhirclient.IDToken | null; | ||
getFhirUser(): any; | ||
getUserId(): any; | ||
getUserType(): any; | ||
getAuthorizationHeader(): string | null; | ||
/** | ||
* Used internally to clear the state of the instance and the state in the | ||
* associated storage. | ||
*/ | ||
private _clearState; | ||
create<R = fhirclient.FHIR.Resource, O extends fhirclient.FetchOptions = {}>(resource: fhirclient.FHIR.Resource, requestOptions?: O): Promise<O["includeResponse"] extends true ? fhirclient.CombinedFetchResult<R> : R>; | ||
update<R = fhirclient.FHIR.Resource, O extends fhirclient.FetchOptions = {}>(resource: fhirclient.FHIR.Resource, requestOptions?: O): Promise<O["includeResponse"] extends true ? fhirclient.CombinedFetchResult<R> : R>; | ||
delete<R = unknown>(url: string, requestOptions?: fhirclient.FetchOptions): Promise<R>; | ||
patch<ResolveType = fhirclient.FHIR.Resource>(url: string, patch: fhirclient.JsonPatch, requestOptions?: fhirclient.FetchOptions): Promise<ResolveType>; | ||
request<T = any>(requestOptions: string | URL | fhirclient.RequestOptions, fhirOptions?: fhirclient.FhirOptions, _resolvedRefs?: fhirclient.JsonObject): Promise<T>; | ||
refreshIfNeeded(requestOptions?: RequestInit): Promise<any>; | ||
refresh(requestOptions?: RequestInit): Promise<any>; | ||
/** | ||
* Walks through an object (or array) and returns the value found at the | ||
* provided path. This function is very simple so it intentionally does not | ||
* support any argument polymorphism, meaning that the path can only be a | ||
* dot-separated string. If the path is invalid returns undefined. | ||
* @param obj The object (or Array) to walk through | ||
* @param path The path (eg. "a.b.4.c") | ||
* @returns {*} Whatever is found in the path or undefined | ||
* @todo This should be deprecated and moved elsewhere. One should not have | ||
* to obtain an instance of [[Client]] just to use utility functions like this. | ||
* @deprecated | ||
* @category Utility | ||
*/ | ||
getPath(obj: Record<string, any>, path?: string): any; | ||
/** | ||
* Returns a copy of the client state. Accepts a dot-separated path argument | ||
* (same as for `getPath`) to allow for selecting specific properties. | ||
* Examples: | ||
* ```js | ||
* client.getState(); // -> the entire state object | ||
* client.getState("serverUrl"); // -> the URL we are connected to | ||
* client.getState("tokenResponse.patient"); // -> The selected patient ID (if any) | ||
* ``` | ||
* @param path The path (eg. "a.b.4.c") | ||
* @returns {*} Whatever is found in the path or undefined | ||
*/ | ||
getState(path?: string): any; | ||
/** | ||
* Returns a promise that will be resolved with the fhir version as defined | ||
* in the CapabilityStatement. | ||
*/ | ||
getFhirVersion(): Promise<string>; | ||
/** | ||
* Returns a promise that will be resolved with the numeric fhir version | ||
* - 2 for DSTU2 | ||
* - 3 for STU3 | ||
* - 4 for R4 | ||
* - 0 if the version is not known | ||
*/ | ||
getFhirRelease(): Promise<number>; | ||
} |
Oops, something went wrong.