UNPKG

fhirclient

Version:

JavaScript client for Fast Healthcare Interoperability Resources

2 lines 205 kB
/*! For license information please see fhir-client.min.js.LICENSE.txt */ !function(){var t={7847:function(t,e,r){var n,o;n=function(){"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function n(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function s(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=o(t);if(e){var i=o(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return a(t)}(this,r)}}function u(){return u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(n){var i=Object.getOwnPropertyDescriptor(n,e);return i.get?i.get.call(arguments.length<3?t:r):i.value}},u.apply(this,arguments)}var c=function(){function e(){t(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return n(e,[{key:"addEventListener",value:function(t,e,r){t in this.listeners||(this.listeners[t]=[]),this.listeners[t].push({callback:e,options:r})}},{key:"removeEventListener",value:function(t,e){if(t in this.listeners)for(var r=this.listeners[t],n=0,o=r.length;n<o;n++)if(r[n].callback===e)return void r.splice(n,1)}},{key:"dispatchEvent",value:function(t){if(t.type in this.listeners){for(var e=this.listeners[t.type].slice(),r=0,n=e.length;r<n;r++){var o=e[r];try{o.callback.call(this,t)}catch(t){Promise.resolve().then((function(){throw t}))}o.options&&o.options.once&&this.removeEventListener(t.type,o.callback)}return!t.defaultPrevented}}}]),e}(),f=function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&i(t,e)}(f,e);var r=s(f);function f(){var e;return t(this,f),(e=r.call(this)).listeners||c.call(a(e)),Object.defineProperty(a(e),"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(a(e),"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(a(e),"reason",{value:void 0,writable:!0,configurable:!0}),e}return n(f,[{key:"toString",value:function(){return"[object AbortSignal]"}},{key:"dispatchEvent",value:function(t){"abort"===t.type&&(this.aborted=!0,"function"==typeof this.onabort&&this.onabort.call(this,t)),u(o(f.prototype),"dispatchEvent",this).call(this,t)}}]),f}(c),l=function(){function e(){t(this,e),Object.defineProperty(this,"signal",{value:new f,writable:!0,configurable:!0})}return n(e,[{key:"abort",value:function(t){var e;try{e=new Event("abort")}catch(t){"undefined"!=typeof document?document.createEvent?(e=document.createEvent("Event")).initEvent("abort",!1,!1):(e=document.createEventObject()).type="abort":e={type:"abort",bubbles:!1,cancelable:!1}}var r=t;if(void 0===r)if("undefined"==typeof document)(r=new Error("This operation was aborted")).name="AbortError";else try{r=new DOMException("signal is aborted without reason")}catch(t){(r=new Error("This operation was aborted")).name="AbortError"}this.signal.reason=r,this.signal.dispatchEvent(e)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();"undefined"!=typeof Symbol&&Symbol.toStringTag&&(l.prototype[Symbol.toStringTag]="AbortController",f.prototype[Symbol.toStringTag]="AbortSignal"),function(t){(function(t){return t.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):"function"==typeof t.Request&&!t.Request.prototype.hasOwnProperty("signal")||!t.AbortController})(t)&&(t.AbortController=l,t.AbortSignal=f)}("undefined"!=typeof self?self:r.g)},void 0===(o=n.call(e,r,e,t))||(t.exports=o)},2047:function(t,e,r){"use strict";var n;r(4554),r(7495),r(1761),r(5440),e.formatArgs=function(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),this.useColors){var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var n=0,o=0;e[0].replace(/%[a-zA-Z%]/g,(function(t){"%%"!==t&&(n++,"%c"===t&&(o=n))})),e.splice(o,0,r)}},e.save=function(t){try{t?e.storage.setItem("debug",t):e.storage.removeItem("debug")}catch(t){}},e.load=function(){var t;try{t=e.storage.getItem("debug")}catch(t){}return!t&&"undefined"!=typeof process&&"env"in process&&(t=process.env.DEBUG),t},e.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(t=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(t[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));var t},e.storage=function(){try{return localStorage}catch(t){}}(),e.destroy=(n=!1,function(){n||(n=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.log=console.debug||console.log||function(){},t.exports=r(9507)(e),t.exports.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}},9507:function(t,e,r){"use strict";var n=r(4994)(r(1132));r(8706),r(8598),r(2062),r(4782),r(4554),r(8130),r(9432),r(6099),r(4864),r(7495),r(8781),r(5440),r(744),r(3500),t.exports=function(t){function e(t){var r,n,i,a=null;function s(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];if(s.enabled){var i=s,a=Number(new Date),u=a-(r||a);i.diff=u,i.prev=r,i.curr=a,r=a,n[0]=e.coerce(n[0]),"string"!=typeof n[0]&&n.unshift("%O");var c=0;n[0]=n[0].replace(/%([a-zA-Z%])/g,(function(t,r){if("%%"===t)return"%";c++;var o=e.formatters[r];if("function"==typeof o){var a=n[c];t=o.call(i,a),n.splice(c,1),c--}return t})),e.formatArgs.call(i,n),(i.log||e.log).apply(i,n)}}return s.namespace=t,s.useColors=e.useColors(),s.color=e.selectColor(t),s.extend=o,s.destroy=e.destroy,Object.defineProperty(s,"enabled",{enumerable:!0,configurable:!1,get:function(){return null!==a?a:(n!==e.namespaces&&(n=e.namespaces,i=e.enabled(t)),i)},set:function(t){a=t}}),"function"==typeof e.init&&e.init(s),s}function o(t,r){var n=e(this.namespace+(void 0===r?":":r)+t);return n.log=this.log,n}function i(t){return t.toString().substring(2,t.toString().length-2).replace(/\.\*\?$/,"*")}return e.debug=e,e.default=e,e.coerce=function(t){return t instanceof Error?t.stack||t.message:t},e.disable=function(){var t=[].concat((0,n.default)(e.names.map(i)),(0,n.default)(e.skips.map(i).map((function(t){return"-"+t})))).join(",");return e.enable(""),t},e.enable=function(t){var r;e.save(t),e.namespaces=t,e.names=[],e.skips=[];var n=("string"==typeof t?t:"").split(/[\s,]+/),o=n.length;for(r=0;r<o;r++)n[r]&&("-"===(t=n[r].replace(/\*/g,".*?"))[0]?e.skips.push(new RegExp("^"+t.slice(1)+"$")):e.names.push(new RegExp("^"+t+"$")))},e.enabled=function(t){if("*"===t[t.length-1])return!0;var r,n;for(r=0,n=e.skips.length;r<n;r++)if(e.skips[r].test(t))return!1;for(r=0,n=e.names.length;r<n;r++)if(e.names[r].test(t))return!0;return!1},e.humanize=r(6585),e.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(t).forEach((function(r){e[r]=t[r]})),e.names=[],e.skips=[],e.formatters={},e.selectColor=function(t){for(var r=0,n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n),r|=0;return e.colors[Math.abs(r)%e.colors.length]},e.enable(e.load()),e}},7024:function(t,e,r){"use strict";r(2675),r(3851),r(1278);var n=r(4994),o=n(r(4756));r(8706),r(2008),r(113),r(6449),r(3792),r(8598),r(2062),r(4782),r(6910),r(3514),r(9085),r(9432),r(6099),r(3362),r(9391),r(7495),r(7764),r(1761),r(5440),r(5746),r(2762),r(778),r(3500),r(2953),r(3296),r(7208),r(8408);var i=n(r(3693)),a=n(r(7383)),s=n(r(4579)),u=n(r(9293));function c(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function f(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?c(Object(r),!0).forEach((function(e){(0,i.default)(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}Object.defineProperty(e,"__esModule",{value:!0});var l=r(5152),p=r(945),h=r(9830),d=("undefined"!=typeof FHIRCLIENT_PURE?window:r(4945)).Response,v=l.debug.extend("client");function y(t,e){return g.apply(this,arguments)}function g(){return g=(0,u.default)(o.default.mark((function t(e,r){var n,i,a;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=function(){return(a=(0,u.default)(o.default.mark((function t(e){var n,i,a;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.pathname.split("/").pop(),(0,l.assert)(n,'Invalid url "'.concat(e,'"')),(0,l.assert)(h.patientCompartment.indexOf(n)>-1,'Cannot filter "'.concat(n,'" resources by patient')),t.next=5,(0,l.fetchConformanceStatement)(r.state.serverUrl);case 5:return i=t.sent,a=(0,l.getPatientParam)(i,n),e.searchParams.set(a,r.patient.id),t.abrupt("return",e.href);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)},i=function(t){return a.apply(this,arguments)},n=(0,l.absolute)("/",r.state.serverUrl),!("string"==typeof e||e instanceof URL)){t.next=8;break}return t.next=6,i(new URL(e+"",n));case 6:return t.t0=t.sent,t.abrupt("return",{url:t.t0});case 8:return t.next=10,i(new URL(e.url+"",n));case 10:return e.url=t.sent,t.abrupt("return",e);case 12:case"end":return t.stop()}}),t)}))),g.apply(this,arguments)}function b(t,e,r,n,o){var i=(0,l.makeArray)(e.resolveReferences).filter(Boolean).map((function(t){return String(t).trim()})).filter(Boolean);if(!(i=i.filter((function(t,e){return!(i.indexOf(t,e+1)>-1&&(v('Duplicated reference path "%s"',t),1))}))).length)return Promise.resolve();var a={};i.forEach((function(t){var e=t.split(".").length;a[e]||(a[e]=[]),a[e].push(t)}));var s=Promise.resolve();return Object.keys(a).sort().forEach((function(i){var u=a[i];s=s.then((function(){return Promise.all(u.map((function(i){return function(t,e,r,n,o,i){var a=(0,l.getPath)(t,e);if(a){var s=Array.isArray(a);return Promise.all((0,l.makeArray)(a).filter(Boolean).map((function(a,u){var c=a.reference;if(c)return function(t,e,r,n){if(!e[t]){var o=n.signal,i=n.headers;e[t]=r.request({url:t,headers:i,signal:o}).then((function(r){return e[t]=r,r}),(function(r){throw delete e[t],r}))}return Promise.resolve(e[t])}(c,n,o,i).then((function(n){r&&(s?e.indexOf("..")>-1?(0,l.setPath)(t,"".concat(e.replace("..",".".concat(u,"."))),n):(0,l.setPath)(t,"".concat(e,".").concat(u),n):(0,l.setPath)(t,e,n))})).catch((function(t){if(404!==t.status)throw t}))})))}}(t,i,!!e.graph,r,n,o)})))}))})),s}var m=function(){return(0,s.default)((function t(e,r){var n=this;(0,a.default)(this,t),this.units=l.units;var i="string"==typeof r?{serverUrl:r}:r;(0,l.assert)(i.serverUrl&&i.serverUrl.match(/https?:\/\/.+/),'A "serverUrl" option is required and must begin with "http(s)"'),this.state=i,this.environment=e,this._refreshTask=null;var s=this;this.patient={get id(){return s.getPatientId()},read:function(t){var e=n.patient.id;return e?n.request(f(f({},t),{},{url:"Patient/".concat(e)})):Promise.reject(new Error("Patient is not available"))},request:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return n.patient.id?(0,u.default)(o.default.mark((function r(){var i;return o.default.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,y(t,n);case 2:return i=r.sent,r.abrupt("return",n.request(i,e));case 4:case"end":return r.stop()}}),r)})))():Promise.reject(new Error("Patient is not available"))}},this.encounter={get id(){return s.getEncounterId()},read:function(t){var e=n.encounter.id;return e?n.request(f(f({},t),{},{url:"Encounter/".concat(e)})):Promise.reject(new Error("Encounter is not available"))}},this.user={get fhirUser(){return s.getFhirUser()},get id(){return s.getUserId()},get resourceType(){return s.getUserType()},read:function(t){var e=n.user.fhirUser;return e?n.request(f(f({},t),{},{url:e})):Promise.reject(new Error("User is not available"))}},this.connect(e.fhir)}),[{key:"connect",value:function(t){if("function"==typeof t){var e={baseUrl:this.state.serverUrl.replace(/\/$/,"")},r=this.getState("tokenResponse.access_token");if(r)e.auth={token:r};else{var n=this.state,o=n.username,i=n.password;o&&i&&(e.auth={user:o,pass:i})}this.api=t(e);var a=this.getState("tokenResponse.patient");a&&(this.patient.api=t(f(f({},e),{},{patient:a})))}return this}},{key:"getPatientId",value:function(){var t=this.state.tokenResponse;return t?t.patient?t.patient:((this.state.scope||"").match(/\blaunch(\/patient)?\b/)?v("The ID of the selected patient is not available. Please check if your server supports that."):v(p.default.noScopeForId,"patient","patient"),null):(this.state.authorizeUri?v(p.default.noIfNoAuth,"the ID of the selected patient"):v(p.default.noFreeContext,"selected patient"),null)}},{key:"getEncounterId",value:function(){var t=this.state.tokenResponse;return t?t.encounter?t.encounter:((this.state.scope||"").match(/\blaunch(\/encounter)?\b/)?v("The ID of the selected encounter is not available. Please check if your server supports that, and that the selected patient has any recorded encounters."):v(p.default.noScopeForId,"encounter","encounter"),null):(this.state.authorizeUri?v(p.default.noIfNoAuth,"the ID of the selected encounter"):v(p.default.noFreeContext,"selected encounter"),null)}},{key:"getIdToken",value:function(){var t=this.state.tokenResponse;if(t){var e=t.id_token,r=this.state.scope||"";if(!e){var n=r.match(/\bopenid\b/),o=r.match(/\bprofile\b/),i=r.match(/\bfhirUser\b/);return v(n&&(i||o)?"The id_token is not available. Please check if your server supports that.":"You are trying to get the id_token but you are not using the right scopes. Please add 'openid' and 'fhirUser' or 'profile' to the scopes you are requesting."),null}return(0,l.jwtDecode)(e,this.environment)}return this.state.authorizeUri?v(p.default.noIfNoAuth,"the id_token"):v(p.default.noFreeContext,"id_token"),null}},{key:"getFhirUser",value:function(){var t=this.getIdToken();return t?t.fhirUser?t.fhirUser.split("/").slice(-2).join("/"):t.profile:null}},{key:"getUserId",value:function(){var t=this.getFhirUser();return t?t.split("/")[1]:null}},{key:"getUserType",value:function(){var t=this.getFhirUser();return t?t.split("/")[0]:null}},{key:"getAuthorizationHeader",value:function(){var t=this.getState("tokenResponse.access_token");if(t)return"Bearer "+t;var e=this.state,r=e.username,n=e.password;return r&&n?"Basic "+this.environment.btoa(r+":"+n):null}},{key:"_clearState",value:(r=(0,u.default)(o.default.mark((function t(){var e,r;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.environment.getStorage(),t.next=3,e.get(h.SMART_KEY);case 3:if(!(r=t.sent)){t.next=7;break}return t.next=7,e.unset(r);case 7:return t.next=9,e.unset(h.SMART_KEY);case 9:this.state.tokenResponse={};case 10:case"end":return t.stop()}}),t,this)}))),function(){return r.apply(this,arguments)})},{key:"create",value:function(t,e){return this.request(f(f({},e),{},{url:"".concat(t.resourceType),method:"POST",body:JSON.stringify(t),headers:f({"content-type":"application/json"},(e||{}).headers)}))}},{key:"update",value:function(t,e){return this.request(f(f({},e),{},{url:"".concat(t.resourceType,"/").concat(t.id),method:"PUT",body:JSON.stringify(t),headers:f({"content-type":"application/json"},(e||{}).headers)}))}},{key:"delete",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.request(f(f({},e),{},{url:t,method:"DELETE"}))}},{key:"patch",value:(e=(0,u.default)(o.default.mark((function t(e,r){var n,i=arguments;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=i.length>2&&void 0!==i[2]?i[2]:{},(0,l.assertJsonPatch)(r),t.abrupt("return",this.request(f(f({},n),{},{url:e,method:"PATCH",body:JSON.stringify(r),headers:f({prefer:"return=presentation","content-type":"application/json-patch+json; charset=UTF-8"},n.headers)})));case 3:case"end":return t.stop()}}),t,this)}))),function(t,r){return e.apply(this,arguments)})},{key:"request",value:(t=(0,u.default)(o.default.mark((function t(e){var r,n,i,a,s,c,h,v,y,g=this,m=arguments;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=m.length>1&&void 0!==m[1]?m[1]:{},n=m.length>2&&void 0!==m[2]?m[2]:{},a=l.debug.extend("client:request"),(0,l.assert)(e,"request requires an url or request options as argument"),"string"==typeof e||e instanceof URL?(s=String(e),e={}):s=String(e.url),s=(0,l.absolute)(s,this.state.serverUrl),c={graph:!1!==r.graph,flat:!!r.flat,pageLimit:null!==(i=r.pageLimit)&&void 0!==i?i:1,resolveReferences:r.resolveReferences||[],useRefreshToken:!1!==r.useRefreshToken,onPage:"function"==typeof r.onPage?r.onPage:void 0},h=e.signal||void 0,v=c.useRefreshToken?this.refreshIfNeeded({signal:h}).then((function(){return e})):Promise.resolve(e),t.abrupt("return",v.then((function(t){var e=g.getAuthorizationHeader();return e&&(t.headers=f(f({},t.headers),{},{authorization:e})),t})).then((function(t){return a("%s, options: %O, fhirOptions: %O",s,t,c),(0,l.request)(s,t).then((function(e){return t.includeResponse?(y=e.response,e.body):e}))})).catch(function(){var t=(0,u.default)(o.default.mark((function t(e){return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(401!=e.status){t.next=15;break}if(g.getState("tokenResponse.access_token")){t.next=4;break}throw e.message+="\nThis app cannot be accessed directly. Please launch it as SMART app!",e;case 4:if(c.useRefreshToken){t.next=10;break}return a("Your session has expired and the useRefreshToken option is set to false. Please re-launch the app."),t.next=8,g._clearState();case 8:case 13:throw e.message+="\n"+p.default.expired,e;case 10:return a("Auto-refresh failed! Please re-launch the app."),t.next=13,g._clearState();case 15:throw e;case 16:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()).catch((function(t){throw 403==t.status&&a("Permission denied! Please make sure that you have requested the proper scopes."),t})).then((function(t){return!t||"string"==typeof t||t instanceof d?e.includeResponse?{body:t,response:y}:t:(r=(0,u.default)(o.default.mark((function t(r){return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("Bundle"!=r.resourceType){t.next=5;break}return t.next=3,Promise.all((r.entry||[]).map((function(t){return b(t.resource,c,n,g,e)})));case 3:t.next=7;break;case 5:return t.next=7,b(r,c,n,g,e);case 7:return t.abrupt("return",r);case 8:case"end":return t.stop()}}),t)}))),function(t){return r.apply(this,arguments)})(t).then(function(){var t=(0,u.default)(o.default.mark((function t(e){var r,i,a;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||"Bundle"!=e.resourceType){t.next=19;break}if(r=e.link||[],c.flat&&(e=(e.entry||[]).map((function(t){return t.resource}))),!c.onPage){t.next=6;break}return t.next=6,c.onPage(e,f({},n));case 6:if(! --c.pageLimit){t.next=19;break}if(i=r.find((function(t){return"next"==t.relation})),e=(0,l.makeArray)(e),!i||!i.url){t.next=19;break}return t.next=12,g.request({url:i.url,signal:h},c,n);case 12:if(a=t.sent,!c.onPage){t.next=15;break}return t.abrupt("return",null);case 15:if(!c.resolveReferences.length){t.next=18;break}return Object.assign(n,a.references),t.abrupt("return",e.concat((0,l.makeArray)(a.data||a)));case 18:return t.abrupt("return",e.concat((0,l.makeArray)(a)));case 19:return t.abrupt("return",e);case 20:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()).then((function(t){if(c.graph)n={};else if(!c.onPage&&c.resolveReferences.length)return{data:t,references:n};return t})).then((function(t){return e.includeResponse?{body:t,response:y}:t}));var r})));case 10:case"end":return t.stop()}}),t,this)}))),function(e){return t.apply(this,arguments)})},{key:"refreshIfNeeded",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=this.getState("tokenResponse.access_token"),r=this.getState("tokenResponse.refresh_token"),n=this.state.expiresAt||0;return e&&r&&n-10<Date.now()/1e3?this.refresh(t):Promise.resolve(this.state)}},{key:"refresh",value:function(){var t,e,r=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=l.debug.extend("client:refresh");o("Attempting to refresh with refresh_token...");var i=null===(e=null===(t=this.state)||void 0===t?void 0:t.tokenResponse)||void 0===e?void 0:e.refresh_token;(0,l.assert)(i,"Unable to refresh. No refresh_token found.");var a=this.state.tokenUri;(0,l.assert)(a,"Unable to refresh. No tokenUri found.");var s=this.getState("tokenResponse.scope")||"",u=s.search(/\boffline_access\b/)>-1,c=s.search(/\bonline_access\b/)>-1;if((0,l.assert)(u||c,"Unable to refresh. No offline_access or online_access scope found."),!this._refreshTask){var p="grant_type=refresh_token&refresh_token=".concat(encodeURIComponent(i));this.environment.options.refreshTokenWithClientId&&(p+="&client_id=".concat(this.state.clientId));var h=f(f({credentials:this.environment.options.refreshTokenWithCredentials||"same-origin"},n),{},{method:"POST",mode:"cors",headers:f(f({},n.headers||{}),{},{"content-type":"application/x-www-form-urlencoded"}),body:p});if(!("authorization"in h.headers)){var d=this.state,v=d.clientSecret,y=d.clientId;v&&(h.headers.authorization="Basic "+this.environment.btoa(y+":"+v))}this._refreshTask=(0,l.request)(a,h).then((function(t){return(0,l.assert)(t.access_token,"No access token received"),o("Received new access token response %O",t),r.state.tokenResponse=f(f({},r.state.tokenResponse),t),r.state.expiresAt=(0,l.getAccessTokenExpiration)(t,r.environment),r.state})).catch((function(t){var e,n;throw(null===(n=null===(e=r.state)||void 0===e?void 0:e.tokenResponse)||void 0===n?void 0:n.refresh_token)&&(o("Deleting the expired or invalid refresh token."),delete r.state.tokenResponse.refresh_token),t})).finally((function(){r._refreshTask=null;var t=r.state.key;t?r.environment.getStorage().set(t,r.state):o("No 'key' found in Clint.state. Cannot persist the instance.")}))}return this._refreshTask}},{key:"byCode",value:function(t,e){return(0,l.byCode)(t,e)}},{key:"byCodes",value:function(t,e){return(0,l.byCodes)(t,e)}},{key:"getPath",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return(0,l.getPath)(t,e)}},{key:"getState",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(0,l.getPath)(f({},this.state),t)}},{key:"getFhirVersion",value:function(){return(0,l.fetchConformanceStatement)(this.state.serverUrl).then((function(t){return t.fhirVersion}))}},{key:"getFhirRelease",value:function(){return this.getFhirVersion().then((function(t){var e;return null!==(e=h.fhirVersions[t])&&void 0!==e?e:0}))}}]);var t,e,r}();e.default=m},1829:function(t,e,r){"use strict";r(825);var n=r(4994),o=n(r(4756));r(8706),r(2010),r(7495),r(1761);var i=n(r(9293)),a=n(r(7383)),s=n(r(4579)),u=n(r(8452)),c=n(r(3072)),f=n(r(9511)),l=n(r(1837));function p(t,e,r){return e=(0,c.default)(e),(0,u.default)(t,h()?Reflect.construct(e,r||[],(0,c.default)(t).constructor):e.apply(t,r))}function h(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(h=function(){return!!t})()}Object.defineProperty(e,"__esModule",{value:!0});var d=function(t){function e(t){var r;return(0,a.default)(this,e),(r=p(this,e,["".concat(t.status," ").concat(t.statusText,"\nURL: ").concat(t.url)])).name="HttpError",r.response=t,r.statusCode=t.status,r.status=t.status,r.statusText=t.statusText,r}return(0,f.default)(e,t),(0,s.default)(e,[{key:"parse",value:(r=(0,i.default)(o.default.mark((function t(){var e,r,n;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.response.bodyUsed){t.next=19;break}if(t.prev=1,!(e=this.response.headers.get("content-type")||"text/plain").match(/\bjson\b/i)){t.next=10;break}return t.next=6,this.response.json();case 6:(r=t.sent).error?(this.message+="\n"+r.error,r.error_description&&(this.message+=": "+r.error_description)):this.message+="\n\n"+JSON.stringify(r,null,4),t.next=15;break;case 10:if(!e.match(/^text\//i)){t.next=15;break}return t.next=13,this.response.text();case 13:(n=t.sent)&&(this.message+="\n\n"+n);case 15:t.next=19;break;case 17:t.prev=17,t.t0=t.catch(1);case 19:return t.abrupt("return",this);case 20:case"end":return t.stop()}}),t,this,[[1,17]])}))),function(){return r.apply(this,arguments)})},{key:"toJSON",value:function(){return{name:this.name,statusCode:this.statusCode,status:this.status,statusText:this.statusText,message:this.message}}}]);var r}((0,l.default)(Error));e.default=d},7129:function(t,e,r){"use strict";r(2675),r(2008),r(3851),r(1278),r(9432),r(3500);var n=r(4994);r(8706),r(3792),r(6099),r(7764),r(2953),r(3296),r(7208),r(8408);var o=n(r(3693)),i=n(r(7383)),a=n(r(4579));function s(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}Object.defineProperty(e,"__esModule",{value:!0});var u=r(438),c=r(7024),f=r(4944),l=r(4818),p=r(8127),h=function(){return(0,a.default)((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,i.default)(this,t),this._url=null,this._storage=null,this.security=l,this.options=function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?s(Object(r),!0).forEach((function(e){(0,o.default)(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}({replaceBrowserHistory:!0,fullSessionStorageSupport:!0,refreshTokenWithCredentials:"same-origin"},e)}),[{key:"relative",value:function(t){return new URL(t,this.getUrl().href).href}},{key:"fhir",get:function(){return"function"==typeof fhir?fhir:null}},{key:"getUrl",value:function(){return this._url||(this._url=new URL(location+"")),this._url}},{key:"redirect",value:function(t){location.href=t}},{key:"getStorage",value:function(){return this._storage||(this._storage=new f.default),this._storage}},{key:"getAbortController",value:function(){return AbortController}},{key:"atob",value:function(t){return window.atob(t)}},{key:"btoa",value:function(t){return window.btoa(t)}},{key:"base64urlencode",value:function(t){return"string"==typeof t?(0,p.encodeURL)(t):(0,p.fromUint8Array)(t,!0)}},{key:"base64urldecode",value:function(t){return(0,p.decode)(t)}},{key:"getSmartApi",value:function(){var t=this;return{ready:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return u.ready.apply(void 0,[t].concat(r))},authorize:function(e){return(0,u.authorize)(t,e)},init:function(e){return(0,u.init)(t,e)},client:function(e){return new c.default(t,e)},options:this.options,utils:{security:l}}}}])}();e.default=h},8932:function(t,e,r){"use strict";r(6099),r(3362);var n=(new(r(7129).default)).getSmartApi(),o=n.ready,i=n.authorize,a=n.init,s=n.client,u=n.options,c=n.utils;if("undefined"==typeof FHIRCLIENT_PURE){var f=r(4945);r(7847),window.fetch||(window.fetch=f.default,window.Headers=f.Headers,window.Request=f.Request,window.Response=f.Response)}var l={AbortController:window.AbortController,client:s,utils:c,oauth2:{settings:u,ready:o,authorize:i,init:a}};t.exports=l},5152:function(t,e,r){"use strict";r(2675),r(3851),r(1278);var n=r(4994),o=n(r(4756)),i=n(r(3693)),a=n(r(1847)),s=n(r(3738)),u=n(r(9293));r(8706),r(2008),r(113),r(8598),r(2062),r(2010),r(9432),r(6099),r(3362),r(7495),r(1761),r(5440),r(2762),r(3500);var c=["includeResponse"];function f(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function l(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?f(Object(r),!0).forEach((function(e){(0,i.default)(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}Object.defineProperty(e,"__esModule",{value:!0}),e.assertJsonPatch=e.assert=e.getTargetWindow=e.getPatientParam=e.byCodes=e.byCode=e.getAccessTokenExpiration=e.getTimeInFuture=e.jwtDecode=e.randomString=e.absolute=e.makeArray=e.setPath=e.getPath=e.fetchConformanceStatement=e.getAndCache=e.request=e.loweCaseKeys=e.responseToJSON=e.checkResponse=e.units=e.debug=void 0;var p=r(1829),h=r(9830),d=r(2047),v=("undefined"!=typeof FHIRCLIENT_PURE?window:r(4945)).fetch,y=d("FHIR");e.debug=y;var g={};function b(t){var e=t.value,r=t.code;if("number"!=typeof e)throw new Error("Found a non-numerical unit: "+e+" "+r)}function m(t){return w.apply(this,arguments)}function w(){return(w=(0,u.default)(o.default.mark((function t(e){var r;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.ok){t.next=5;break}return r=new p.default(e),t.next=4,r.parse();case 4:throw r;case 5:return t.abrupt("return",e);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function x(t){return t.text().then((function(t){return t.length?JSON.parse(t):""}))}function S(t){if(!t)return t;if(Array.isArray(t))return t.map((function(t){return t&&"object"===(0,s.default)(t)?S(t):t}));var e={};return Object.keys(t).forEach((function(r){var n=r.toLowerCase(),o=t[r];e[n]=o&&"object"==(0,s.default)(o)?S(o):o})),e}function A(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.includeResponse,n=(0,a.default)(e,c);return v(t,l(l({mode:"cors"},n),{},{headers:l({accept:"application/json"},S(n.headers))})).then(m).then((function(t){var e=t.headers.get("content-type")+"";return e.match(/\bjson\b/i)?x(t).then((function(e){return{res:t,body:e}})):e.match(/^text\//i)?t.text().then((function(e){return{res:t,body:e}})):{res:t}})).then((function(t){var e=t.res,o=t.body;if(!o&&201==e.status){var i=e.headers.get("location");if(i)return A(i,l(l({},n),{},{method:"GET",body:null,includeResponse:r}))}return r?{body:o,response:e}:void 0===o?e:o}))}function k(t,e){return arguments.length>2&&void 0!==arguments[2]&&arguments[2]||!g[t]?(g[t]=A(t,e),g[t]):Promise.resolve(g[t])}function O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!(e=e.trim()))return t;for(var r=e.split("."),n=t;n&&r.length;){var o=r.shift();if(!o&&Array.isArray(n))return n.map((function(t){return O(t,r.join("."))}));n=n[o]}return n}function E(t){return Array.isArray(t)?t:[t]}function P(t,e){var r=t.split(".")[1];return r?JSON.parse(e.atob(r)):null}function C(t,e){var r={};function n(t,e){t&&Array.isArray(t.coding)&&t.coding.forEach((function(t){var n=t.code;n&&(r[n]=r[n]||[],r[n].push(e))}))}return E(t).forEach((function(t){"Observation"===t.resourceType&&t[e]&&(Array.isArray(t[e])?t[e].forEach((function(e){return n(e,t)})):n(t[e],t))})),r}function R(){return R=(0,u.default)(o.default.mark((function t(e){var r,n,i,a,u,c,f,l=arguments;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=l.length>1&&void 0!==l[1]?l[1]:800,n=l.length>2&&void 0!==l[2]?l[2]:720,"function"!=typeof e){t.next=6;break}return t.next=5,e();case 5:e=t.sent;case 6:if(!e||"object"!=(0,s.default)(e)){t.next=8;break}return t.abrupt("return",e);case 8:if("string"==typeof e){t.next=11;break}return y("Invalid target type '%s'. Failing back to '_self'.",(0,s.default)(e)),t.abrupt("return",self);case 11:if("_self"!=e){t.next=13;break}return t.abrupt("return",self);case 13:if("_parent"!=e){t.next=15;break}return t.abrupt("return",parent);case 15:if("_top"!=e){t.next=17;break}return t.abrupt("return",top||self);case 17:if("_blank"!=e){t.next=34;break}if(a=null,t.prev=19,a=window.open("","SMARTAuthPopup")){t.next=23;break}throw new Error("Perhaps window.open was blocked");case 23:t.next=28;break;case 25:t.prev=25,t.t0=t.catch(19),i=t.t0;case 28:if(a){t.next=33;break}return y("Cannot open window. Failing back to '_self'. %s",i),t.abrupt("return",self);case 33:return t.abrupt("return",a);case 34:if("popup"!=e){t.next=51;break}if(c=null,t.prev=36,c=window.open("","SMARTAuthPopup",["height="+n,"width="+r,"menubar=0","resizable=1","status=0","top="+(screen.height-n)/2,"left="+(screen.width-r)/2].join(","))){t.next=40;break}throw new Error("Perhaps the popup window was blocked");case 40:t.next=45;break;case 42:t.prev=42,t.t1=t.catch(36),u=t.t1;case 45:if(c){t.next=50;break}return y("Cannot open window. Failing back to '_self'. %s",u),t.abrupt("return",self);case 50:return t.abrupt("return",c);case 51:if(!(f=frames[e])){t.next=54;break}return t.abrupt("return",f);case 54:return y("Unknown target '%s'. Failing back to '_self'.",e),t.abrupt("return",self);case 56:case"end":return t.stop()}}),t,null,[[19,25],[36,42]])}))),R.apply(this,arguments)}function _(t,e){if(!t)throw new Error(e)}e.units={cm:function(t){var e=t.code,r=t.value;if(b({code:e,value:r}),"cm"==e)return r;if("m"==e)return 100*r;if("in"==e)return 2.54*r;if("[in_us]"==e)return 2.54*r;if("[in_i]"==e)return 2.54*r;if("ft"==e)return 30.48*r;if("[ft_us]"==e)return 30.48*r;throw new Error("Unrecognized length unit: "+e)},kg:function(t){var e=t.code,r=t.value;if(b({code:e,value:r}),"kg"==e)return r;if("g"==e)return r/1e3;if(e.match(/lb/))return r/2.20462;if(e.match(/oz/))return r/35.274;throw new Error("Unrecognized weight unit: "+e)},any:function(t){return b(t),t.value}},e.checkResponse=m,e.responseToJSON=x,e.loweCaseKeys=S,e.request=A,e.getAndCache=k,e.fetchConformanceStatement=function(){var t=arguments.length>1?arguments[1]:void 0,e=String(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/").replace(/\/*$/,"/")+"metadata";return k(e,t).catch((function(t){throw new Error('Failed to fetch the conformance statement from "'.concat(e,'". ').concat(t))}))},e.getPath=O,e.setPath=function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return e.trim().split(".").reduce((function(t,e,o,i){if(!t||o!==i.length-1)return t&&void 0===t[e]&&n&&(t[e]=i[o+1].match(/^[0-9]+$/)?[]:{}),t?t[e]:void 0;t[e]=r}),t),t},e.makeArray=E,e.absolute=function(t,e){return t.match(/^http/)||t.match(/^urn/)?t:String(e||"").replace(/\/+$/,"")+"/"+t.replace(/^\/+/,"")},e.randomString=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:8,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=[],n=e.length;t--;)r.push(e.charAt(Math.floor(Math.random()*n)));return r.join("")},e.jwtDecode=P,e.getTimeInFuture=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:120,e=arguments.length>1?arguments[1]:void 0;return Math.floor(+(e||new Date)/1e3+t)},e.getAccessTokenExpiration=function(t,e){var r=Math.floor(Date.now()/1e3);if(t.expires_in)return r+t.expires_in;if(t.access_token){var n=P(t.access_token,e);if(n&&n.exp)return n.exp}return r+300},e.byCode=C,e.byCodes=function(t,e){var r=C(t,e);return function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return e.filter((function(t){return t+""in r})).reduce((function(t,e){return t.concat(r[e+""])}),[])}},e.getPatientParam=function(t,e){var r=(O(t,"rest.0.resource")||[]).find((function(t){return t.type===e}));if(!r)throw new Error('Resource "'.concat(e,'" is not supported by this FHIR server'));if(!Array.isArray(r.searchParam))throw new Error('No search parameters supported for "'.concat(e,'" on this FHIR server'));if("Patient"==e&&r.searchParam.find((function(t){return"_id"==t.name})))return"_id";var n=h.patientParams.find((function(t){return r.searchParam.find((function(e){return e.name==t}))}));if(!n)throw new Error("I don't know what param to use for "+e);return n},e.getTargetWindow=function(t){return R.apply(this,arguments)},e.assert=_,e.assertJsonPatch=function(t){_(Array.isArray(t),"The JSON patch must be an array"),_(t.length>0,"The JSON patch array should not be empty"),t.forEach((function(t){_(["add","replace","test","move","copy","remove"].indexOf(t.op)>-1,'Each patch operation must have an "op" property which must be one of: "add", "replace", "test", "move", "copy", "remove"'),_(t.path&&(0,s.default)(t.path),'Invalid "'.concat(t.op,'" operation. Missing "path" property')),"add"==t.op||"replace"==t.op||"test"==t.op?(_("value"in t,'Invalid "'.concat(t.op,'" operation. Missing "value" property')),_(3==Object.keys(t).length,'Invalid "'.concat(t.op,'" operation. Contains unknown properties'))):"move"==t.op||"copy"==t.op?(_("string"==typeof t.from,'Invalid "'.concat(t.op,'" operation. Requires a string "from" property')),_(3==Object.keys(t).length,'Invalid "'.concat(t.op,'" operation. Contains unknown properties'))):_(2==Object.keys(t).length,'Invalid "'.concat(t.op,'" operation. Contains unknown properties'))}))}},4818:function(t,e,r){"use strict";r(2675),r(2008),r(3851),r(1278),r(9432),r(3500);var n=r(4994),o=n(r(4756));r(8706),r(4423),r(3792),r(4743),r(6099),r(1699),r(1489),r(1630),r(2170),r(5044),r(1920),r(1694),r(9955),r(3206),r(4496),r(6651),r(2887),r(9369),r(6812),r(8995),r(1575),r(6072),r(8747),r(8845),r(9423),r(7301),r(373),r(6614),r(1405),r(3684),r(2480);var i=n(r(3693)),a=n(r(9293)),s=n(r(3738));function u(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function c(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?u(Object(r),!0).forEach((function(e){(0,i.default)(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}Object.defineProperty(e,"__esModule",{value:!0}),e.signCompactJws=e.importJWK=e.generatePKCEChallenge=e.digestSha256=e.randomBytes=void 0;var f=r(8127),l="object"===("undefined"==typeof globalThis?"undefined":(0,s.default)(globalThis))&&globalThis.crypto?globalThis.crypto:r(7525).default,p=function(){if(!l.subtle){if(!globalThis.isSecureContext)throw new Error("Some of the required subtle crypto functionality is not available unless you run this app in secure context (using HTTPS or running locally). See https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts");throw new Error("Some of the required subtle crypto functionality is not available in the current environment (no crypto.subtle)")}return l.subtle},h={ES384:{name:"ECDSA",namedCurve:"P-384"},RS384:{name:"RSASSA-PKCS1-v1_5",modulusLength:4096,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-384"}}};function d(t){return l.getRandomValues(new Uint8Array(t))}function v(t){return y.apply(this,arguments)}function y(){return(y=(0,a.default)(o.default.mark((function t(e){var r,n;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=(new TextEncoder).encode(e),t.next=3,p().digest("SHA-256",r);case 3:return n=t.sent,t.abrupt("return",new Uint8Array(n));case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}e.randomBytes=d,e.digestSha256=v;var g=function(){var t=(0,a.default)(o.default.mark((function t(){var e,r,n,i=arguments;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=d(i.length>0&&void 0!==i[0]?i[0]:96),r=(0,f.fromUint8Array)(e,!0),t.t0=f.fromUint8Array,t.next=6,v(r);case 6:return t.t1=t.sent,n=(0,t.t0)(t.t1,!0),t.abrupt("return",{codeChallenge:n,codeVerifier:r});case 9:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}();function b(){return(b=(0,a.default)(o.default.mark((function t(e){return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.alg){t.next=2;break}throw new Error('The "alg" property of the JWK must be set to "ES384" or "RS384"');case 2:if(Array.isArray(e.key_ops)||(e.key_ops=["sign"]),e.key_ops.includes("sign")){t.next=5;break}throw new Error('The "key_ops" property of the JWK does not contain "sign"');case 5:return t.prev=5,t.next=8,p().importKey("jwk",e,h[e.alg],!0===e.ext,e.key_ops);case 8:return t.abrupt("return",t.sent);case 11:throw t.prev=11,t.t0=t.catch(5),new Error("The ".concat(e.alg," is not supported by this browser: ").concat(t.t0));case 14:case"end":return t.stop()}}),t,null,[[5,11]])})))).apply(this,arguments)}function m(){return(m=(0,a.default)(o.default.mark((function t(e,r,n,i){var a,s,u,l;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=JSON.stringify(c(c({},n),{},{alg:e})),s=JSON.stringify(i),u="".concat((0,f.encodeURL)(a),".").concat((0,f.encodeURL)(s)),t.next=5,p().sign(c(c({},r.algorithm),{},{hash:"SHA-384"}),r,(new TextEncoder).encode(u));case 5:return l=t.sent,t.abrupt("return","".concat(u,".").concat((0,f.fromUint8Array)(new Uint8Array(l),!0)));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}e.generatePKCEChallenge=g,e.importJWK=function(t){return b.apply(this,arguments)},e.signCompactJws=function(t,e,r,n){return m.apply(this,arguments)}},9830:function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SMART_KEY=e.patientParams=e.fhirVersions=e.patientCompartment=void 0,e.patientCompartment=["Account","AdverseEvent","AllergyIntolerance","Appointment","AppointmentResponse","AuditEvent","Basic","BodySite","BodyStructure","CarePlan","CareTeam","ChargeItem","Claim","ClaimResponse","ClinicalImpression","Communication","CommunicationRequest","Composition","Condition","Consent","Coverage","CoverageEligibilityRequest","CoverageEligibilityResponse","DetectedIssue","DeviceRequest","DeviceUseRequest","DeviceUseStatement","DiagnosticOrder","DiagnosticReport","DocumentManifest","DocumentReference","EligibilityRequest","Encounter","EnrollmentRequest","EpisodeOfCare","ExplanationOfBenefit","FamilyMemberHistory","Flag","Goal","Group","ImagingManifest","ImagingObjectSelection","ImagingStudy","Immunization","ImmunizationEvaluation","ImmunizationRecommendation","Invoice","List","MeasureReport","Media","MedicationAdministration","MedicationDispense","MedicationOrder","MedicationRequest","MedicationStatement","MolecularSequence","NutritionOrder","Observation","Order","Patient","Person","Procedure","ProcedureRequest","Provenance","QuestionnaireResponse","ReferralRequest","RelatedPerson","RequestGroup","ResearchSubject","RiskAssessment","Schedule","ServiceRequest","Specimen","SupplyDelivery","SupplyRequest","VisionPrescription"],e.fhirVersions={"0.4.0":2,"0.5.0":2,"1.0.0":2,"1.0.1":2,"1.0.2":2,"1.1.0":3,"1.4.0":3,"1.6.0":3,"1.8.0":3,"3.0.0":3,"3.0.1":3,"3.3.0":4,"3.5.0":4,"4.0.0":4,"4.0.1":4},e.patientParams=["patient","subject","requester","member","actor","beneficiary"],e.SMART_KEY="SMART_KEY"},438:function(t,e,r){"use strict";r(2675),r(3851),r(1278),r(9432);var n=r(4994),o=n(r(4756));r(8706),r(2008),r(113),r(4423),r(3792),r(8598),r(2062),r(2010),r(9085),r(6099),r(3362),r(4864),r(7495),r(8781),r(1699),r(7764),r(1761),r(5440),r(3500),r(2953),r(3296),r(7208),r(8408);var i=n(r(3693)),a=n(r(9293)),s=n(r(3738));function u(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function c(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?u(Object(r),!0).forEach((function(e){(0,i.default)(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}Object.defineProperty(e,"__esModule",{value:!0}),e.init=e.buildTokenRequest=e.ready=e.onMessage=e.isInPopUp=e.isInFrame=e.authorize=e.getSecurityExtensions=e.fetchWellKnownJson=e.KEY=void 0;var f=r(5152),l=r(7024),p=r(9830);Object.defineProperty(e,"KEY",{enumerable:!0,get:function(){return p.SMART_KEY}});var h=f.debug.extend("oauth2");function d(){return"object"===("undefined"==typeof window?"undefined":(0,s.default)(window))}function v(){var t=arguments.length>1?arguments[1]:void 0,e=String(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/").replace(/\/*$/,"/")+".well-known/smart-configuration";return(0,f.getAndCache)(e,t).catch((function(t){throw new Error('Failed to fetch the well-known json "'.concat(e,'". ').concat(t.message))}))}function y(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/";return function(){return v(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",arguments.length>1?arguments[1]:void 0).then((function(t){if(!t.authorization_endpoint||!t.token_endpoint)throw new Error("Invalid wellKnownJson");return{registrationUri:t.registration_endpoint||"",authorizeUri:t.authorization_endpoint,tokenUri:t.token_endpoint,codeChallengeMethods:t.code_challenge_methods_supported||[]}}))}(t).catch((function(){return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",e=arguments.length>1?arguments[1]:void 0;return(0,f.fetchConformanceStatement)(t,e).then((function(t){var e=((0,f.getPath)(t||{},"rest.0.security.extension")||[]).filter((function(t){return"http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris"===t.url})).map((function(t){return t.extension}))[0],r={registrationUri:"",authorizeUri:"",tokenUri:"",codeChallengeMethods:[]};return e&&e.forEach((function(t){"register"===t.url&&(r.registrationUri=t.valueUri),"authorize"===t.url&&(r.authorizeUri=t.valueUri),"token"===t.url&&(r.tokenUri=t.valueUri)})),r}))}(t)}))}function g(t){return b.apply(this,arguments)}function b(){return b=(0,a.default)(o.default.mark((function t(e){var r,n,i,a,s,u,c,l,v,b,A,k,O,E,P,C,R,_,T,j,U,I,F,M,L,B,N,D,K,q,H,z,G,J,V,W,Y,$=arguments;return o.default.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=$.length>1&&void 0!==$[1]?$[1]:{},n=e.getUrl(),!Array.isArray(r)){t.next=11;break}if(i=n.searchParams.get("iss")||n.searchParams.get("fhirServiceUrl")){t.next=6;break}throw new Error('Passing in an "iss" url parameter is required if authorize uses multiple configurations');case 6:return a=r.find((function(t){if(t.issMatch){if("function"==typeof t.issMatch)return!!t.issMatch(i);if("string"==typeof t.issMatch)return t.issMatch===i;if(t.issMatch instanceof RegExp)return t.issMatch.test(i)}return!1})),(0,f.assert)(a,'No configuration found matching the current "iss" parameter "'.concat(i,'"')),t.next=10,g(e,a);case 10:return t.abrupt("return",t.sent);case 11:if(s=r.clientSecret,u=r.fakeTokenResponse,c=r.encounterId,l=r.target,v=r.width,b=r.height,A=r.pkceMode,k=r.clientPublicKeySetUrl,O=r.redirect_uri,E=r.client_id,P=r.iss,C=r.launch,R=r.patientId,_=r.fhirServiceUrl,T=r.redirectUri,j=r.noRedirect,U=r.scope,I=void 0===U?"":U,F=r.clientId,M=r.completeInTarget,L=r.clientPrivateJwk,B=r.stateKey,N=e.getStorage(),P=n.searchParams.get("iss")||P,_=n.searchParams.get("fhirServiceUrl")||_,C=n.searchParams.get("launch")||C,R=n.searchParams.get("patientId")||R,(F=n.searchParams.get("clientId")||F)||(F=E),T||(T=O),T?T.match(/^https?\:\/\//)||(T=e.r