UNPKG

@i4mi/ionic-on-fhir

Version:

IONIC wrapper for the I4MI fhir resource library

156 lines (155 loc) 5.92 kB
import { Resource } from '@i4mi/fhir_r4'; import { InAppBrowser } from '@ionic-native/in-app-browser/ngx'; import { SecureStorage } from '@ionic-native/secure-storage/ngx'; import { InAppBrowserSettings } from './ionic-on-fhir.types'; export declare class IonicOnFhirService { private iab; private secStorage; private authWindow; private authRequestParams; private authResponseParams; private tokenExchangeParams; private conformanceStatementUrl; private fhirServerUrl; private storage; private iabSettings; private loggedIn; private apiMethods; constructor(iab: InAppBrowser, secStorage: SecureStorage); /** * First to call. * Set values the library needs for the authentication process. * @param fhirServerUrl The url to the server (for example test.midata.coop) * @param clientId App name given to the auth request as client id */ initIonicOnFhir(fhirServerUrl: string, clientId: string): void; /** * Checks if user is logged in. This is deprecated and will be removed, because * it's not reliable. Instead, you are encouraged to keep track of your login-state * in your application. * @returns boolean (true if logged in) * @deprecated */ isLoggedIn(): boolean; /** * Config params for in app browser as array<{key:value}> * Call when you do not want default settings * @param settings: Array<InAppBrowserSettings> Array of inappbrowser settings. Documented here: * https://github.com/apache/cordova-plugin-inappbrowser */ configInAppBrowser(settings: Array<InAppBrowserSettings>): void; /** * Function that lets you define a different content type for you fhir server * than the default type of the lib. Default: "application/fhir+json;fhirVersion=4.0" * @param contentType content type for header param */ differentiateContentType(contentType: string): void; /** * Function that lets you define a different conformance endpoint url * if it diverges from standard pattern, which is serverUrl + "/fhir/metadata" * @param url of the conformance statement endpoint */ differentiateConformanceStatementUrl(url: string): void; /** * Function to differentiate from the default scope * 'user/*.*' * @param scope Scope of logged in user */ differentiateScope(scope: string): void; /** * Function to differentiate from the default aud * '/fhir' * @param scope Scope of logged in user */ differentiateAud(aud: string): void; /** * Authenticate someone over oAuth2 * @param params (optional) an Object * @returns Promise<any> - * if success: returns auth response (type AuthResponse) and saves response to secure storage * else: error message */ authenticate(params?: Object): Promise<any>; /** * Refresh session and refreshes it, if user was logged in. * Tries to refresh the authentication token by authorizing with the help of the refresh token. * This will generate a new authentication as well as a new refresh token. On successful refresh, * the old refresh_token will be invalid and both the access_token and the refresh_token will be overwritten. * Previous access_tokens will remain valid until their expiration timestamp is exceeded. * @returns resolves the auth response if success * @returns reject every other case */ refreshSession(): Promise<any>; /** * Destroys all auth information from storage * and sets logged in to false */ logout(): Promise<any>; /** * Creates a resource * on the fhir server * @param resource resource to save * @returns resolve of resource as JSON if status 200 or 201 * @returns reject every other case with message */ create(resource: Resource | any): Promise<any>; /** * Updates a resource * on the fhir server * @param resource resource to update * @returns resolve of resource as JSON if status 200 or 201 * @returns reject every other case with message */ update(resource: Resource | any): Promise<any>; /** * Searches for one or multiple resources * @param resourceType resource type to look up * @param params search parameters according fhir resource guide$ * @returns resolve of resource as JSON if status 200 or 201 * @returns reject every other case with message */ search(resourceType: string, params: any): Promise<any>; /** * Makes api call to get the auth and token url * from the fhir/midatata of the server. * Returns a json response with a resource in the .body * Rejects the original error if one occures */ private fetchConformanceStatement; /** * function that interprets the result of the api request */ private interpretConfirmantStatementResponse; /** * Inits a session: * State and state hash (jsSHA-256) */ private initSession; /** * Generates random state string with given length * If lengts set to 0, it will take 122 * @param length length of the string to generate */ private generateRandomState; /** * After successful authentication on midata this method is invoked. It exchanges the authCode * obtained from midata with the access_token used to query the FHIR endpoint API. */ private exchangeTokenForCode; /** * function that interprets the result of the api request */ private interpretTokenResponse; /** * Saves given response body in the secure storage */ private saveAuthResponse; /** * Loads the auth response if there was one (for refresh token etc.) */ private getAuthResponse; /** * Checks if the device is secure or not */ private checkIfDeviceSecure; }