@medplum/core 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +349 -300
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +349 -301
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/cache.d.ts +1 -3
- package/dist/types/client.d.ts +9 -66
- package/dist/types/eventtarget.d.ts +3 -3
- package/dist/types/search.d.ts +1 -0
- package/dist/types/storage.d.ts +2 -2
- package/dist/types/utils.d.ts +6 -0
- package/package.json +2 -2
- package/rollup.config.js +0 -36
package/dist/cjs/index.min.js
CHANGED
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function t(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}class r{constructor(e=10){this.max=e,this.cache=new Map}clear(){this.cache.clear()}get(e){const t=this.cache.get(e);return t&&(this.cache.delete(e),this.cache.set(e,t)),t}set(e,t){this.cache.has(e)?this.cache.delete(e):this.cache.size>=this.max&&this.cache.delete(this.first()),this.cache.set(e,t)}first(){return this.cache.keys().next().value}}function n(e,t){const r=[];return e.prefix&&((null==t?void 0:t.all)||(null==t?void 0:t.prefix))&&r.push(...e.prefix),e.given&&r.push(...e.given),e.family&&r.push(e.family),e.suffix&&((null==t?void 0:t.all)||(null==t?void 0:t.suffix))&&r.push(...e.suffix),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&r.push("["+e.use+"]"),r.join(" ").trim()}function i(e){return e.resourceType+"/"+e.id}function o(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function s(e){if(o(e)){const t=function(e){const t=e.name;if(t&&t.length>0)return n(t[0]);return}(e);if(t)return t}if("Device"===e.resourceType){const t=function(e){const t=e.deviceName;if(t&&t.length>0)return t[0].name;return}(e);if(t)return t}return"User"===e.resourceType&&e.email?e.email:"name"in e&&e.name&&"string"==typeof e.name?e.name:i(e)}function a(e,t){return JSON.stringify(e,c,t?2:void 0)}function c(e,t){return function(e){if(null==e)return!0;const t=typeof e;return"string"===t&&""===e||"object"===t&&0===Object.keys(e).length}(t)?void 0:t}function u(e){return null!==e&&"object"==typeof e}const h=[];for(let e=0;e<256;e++)h.push(e.toString(16).padStart(2,"0"));function l(e){const t=new Uint8Array(e),r=new Array(t.length);for(let e=0;e<t.length;e++)r[e]=h[t[e]];return r.join("")}function d(e){const t=new Uint8Array(e),r=[];for(let e=0;e<t.length;e++)r[e]=String.fromCharCode(t[e]);return window.btoa(r.join(""))}function p(e){return e.charAt(0).toUpperCase()+e.substr(1)}function f(){const e=new Uint32Array(28);return crypto.getRandomValues(e),l(e.buffer)}function g(e){const[t,r,n]=e.split(".");return function(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),r=window.atob(t),n=Array.from(r).reduce(((e,t)=>`${e}%${("00"+t.charCodeAt(0).toString(16)).slice(-2)}`),""),i=decodeURIComponent(n);return JSON.parse(i)}(r)}const m="ok",v="created",y="gone",T="not-modified",E="not-found",S="access-denied",O={resourceType:"OperationOutcome",id:m,issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},P={resourceType:"OperationOutcome",id:v,issue:[{severity:"information",code:"information",details:{text:"Created"}}]},U={resourceType:"OperationOutcome",id:T,issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},R={resourceType:"OperationOutcome",id:E,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},A={resourceType:"OperationOutcome",id:y,issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},C={resourceType:"OperationOutcome",id:S,issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function b(e){return e.id===m||e.id===v||e.id===T}class w extends Error{constructor(e){var t,r;super(null===(r=null===(t=null==e?void 0:e.issue)||void 0===t?void 0:t[0].details)||void 0===r?void 0:r.text),this.outcome=e}}var I;e.Operator=void 0,(I=e.Operator||(e.Operator={})).EQUALS="eq",I.NOT_EQUALS="ne",I.GREATER_THAN="gt",I.LESS_THAN="lt",I.GREATER_THAN_OR_EQUALS="ge",I.LESS_THAN_OR_EQUALS="le",I.STARTS_AFTER="sa",I.ENDS_BEFORE="eb",I.APPROXIMATELY="ap",I.CONTAINS="contains",I.EXACT="exact",I.TEXT="text",I.ABOVE="above",I.BELOW="below",I.IN="in",I.NOT_IN="not-in",I.OF_TYPE="of-type";const _=[e.Operator.CONTAINS,e.Operator.EXACT,e.Operator.TEXT,e.Operator.ABOVE,e.Operator.BELOW,e.Operator.IN,e.Operator.NOT_IN,e.Operator.OF_TYPE],k=[e.Operator.NOT_EQUALS,e.Operator.GREATER_THAN,e.Operator.LESS_THAN,e.Operator.GREATER_THAN_OR_EQUALS,e.Operator.LESS_THAN_OR_EQUALS,e.Operator.STARTS_AFTER,e.Operator.ENDS_BEFORE,e.Operator.APPROXIMATELY];function L(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>{const r=_.includes(e.operator)?":"+e.operator:"",n=k.includes(e.operator)?e.operator:"";t.push(`${e.code}${r}=${n}${encodeURIComponent(e.value)}`)})),e.sortRules&&t.push(function(e){if(!e||0===e.length)return"";return"_sort="+e.map((e=>e.descending?"-"+e.code:e.code)).join(",")}(e.sortRules)),e.page&&e.page>0&&t.push("_page="+e.page),e.count&&e.count>0&&t.push("_count="+e.count),0===t.length?"":(t.sort(),"?"+t.join("&"))}class N{constructor(){this.storage="undefined"!=typeof localStorage?localStorage:new x}clear(){this.storage.clear()}getString(e){return this.storage.getItem(e)||void 0}setString(e,t){t?this.storage.setItem(e,t):this.storage.removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?a(t):void 0)}}class x{constructor(){this.data=new Map}get length(){return this.data.size}clear(){this.data.clear()}getItem(e){var t;return null!==(t=this.data.get(e))&&void 0!==t?t:null}setItem(e,t){t?this.data.set(e,t):this.data.delete(e)}removeItem(e){this.data.delete(e)}key(e){return Array.from(this.data.keys())[e]}}var j;function D(){return{types:{}}}function M(e,t){var r;const n=t.name;if(!n)return;e.types[n]={display:n,description:t.description,properties:{}};const i=null===(r=t.snapshot)||void 0===r?void 0:r.element;if(i){const t=i.filter((e=>e.path!==n&&e.path));t.forEach((t=>function(e,t){var r,n;const i=t.path,o=null===(n=null===(r=t.type)||void 0===r?void 0:r[0])||void 0===n?void 0:n.code;if("Element"!==o&&"BackboneElement"!==o)return;const s=i.split("."),a=q(s);a in e.types||(e.types[a]={display:a,description:t.definition,parentType:q(s.slice(0,s.length-1)),properties:{}})}(e,t))),t.forEach((t=>function(e,t){const r=t.path.split(".");if(1===r.length)return;const n=q(r.slice(0,r.length-1)),i=e.types[n],o=r[r.length-1];i.properties[o]=t}(e,t)))}}function B(e,t){if(t.base)for(const r of t.base){const n=e.types[r];n&&(n.searchParams||(n.searchParams={}),n.searchParams[t.code]=t)}}function q(e){return e.map(p).join("")}e.PropertyType=void 0,(j=e.PropertyType||(e.PropertyType={})).Address="Address",j.Age="Age",j.Annotation="Annotation",j.Attachment="Attachment",j.BackboneElement="BackboneElement",j.CodeableConcept="CodeableConcept",j.Coding="Coding",j.ContactDetail="ContactDetail",j.ContactPoint="ContactPoint",j.Contributor="Contributor",j.Count="Count",j.DataRequirement="DataRequirement",j.Distance="Distance",j.Dosage="Dosage",j.Duration="Duration",j.Expression="Expression",j.Extension="Extension",j.HumanName="HumanName",j.Identifier="Identifier",j.MarketingStatus="MarketingStatus",j.Meta="Meta",j.Money="Money",j.Narrative="Narrative",j.ParameterDefinition="ParameterDefinition",j.Period="Period",j.Population="Population",j.ProdCharacteristic="ProdCharacteristic",j.ProductShelfLife="ProductShelfLife",j.Quantity="Quantity",j.Range="Range",j.Ratio="Ratio",j.Reference="Reference",j.RelatedArtifact="RelatedArtifact",j.Resource="Resource",j.SampledData="SampledData",j.Signature="Signature",j.SubstanceAmount="SubstanceAmount",j.SystemString="http://hl7.org/fhirpath/System.String",j.Timing="Timing",j.TriggerDefinition="TriggerDefinition",j.UsageContext="UsageContext",j.base64Binary="base64Binary",j.boolean="boolean",j.canonical="canonical",j.code="code",j.date="date",j.dateTime="dateTime",j.decimal="decimal",j.id="id",j.instant="instant",j.integer="integer",j.markdown="markdown",j.oid="oid",j.positiveInt="positiveInt",j.string="string",j.time="time",j.unsignedInt="unsignedInt",j.uri="uri",j.url="url",j.uuid="uuid";const F="launch/patient openid fhirUser offline_access user/*.*";function H(){return window.location.protocol+"//"+window.location.host+"/"}var z;function Q(e,t){const r=t.split(" | ");for(const t of r){const r=$(t);if(r.startsWith(e+"."))return r}}function $(e){let t=e.trim();return t.startsWith("(")&&t.endsWith(")")&&(t=t.substring(1,t.length-1)),t.includes(" as ")&&(t=t.substring(0,t.indexOf(" as "))),t.includes(".where(")&&(t=t.substring(0,t.indexOf(".where("))),t}e.SearchParameterType=void 0,(z=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",z.NUMBER="NUMBER",z.QUANTITY="QUANTITY",z.TEXT="TEXT",z.REFERENCE="REFERENCE",z.DATE="DATE",z.DATETIME="DATETIME",z.PERIOD="PERIOD",e.MedplumClient=class extends class{constructor(){this.listeners={}}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeEventListeneer(e,t){const r=this.listeners[e];if(r)for(let e=0;e<r.length;e++)if(r[e]===t)return void r.splice(e,1)}dispatchEvent(e){const t=this.listeners[e.type];return t&&t.forEach((t=>t.call(this,e))),!e.defaultPrevented}}{constructor(e){var t;if(super(),null==e?void 0:e.baseUrl){if(!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");if(!e.baseUrl.endsWith("/"))throw new Error("Base URL must end with a trailing slash")}this.fetch=(null==e?void 0:e.fetch)||window.fetch.bind(window),this.storage=new N,this.schema={types:{}},this.resourceCache=new r(null!==(t=null==e?void 0:e.resourceCacheSize)&&void 0!==t?t:1e3),this.baseUrl=(null==e?void 0:e.baseUrl)||"https://api.medplum.com/",this.clientId=(null==e?void 0:e.clientId)||"",this.authorizeUrl=(null==e?void 0:e.authorizeUrl)||this.baseUrl+"oauth2/authorize",this.tokenUrl=(null==e?void 0:e.tokenUrl)||this.baseUrl+"oauth2/token",this.logoutUrl=(null==e?void 0:e.logoutUrl)||this.baseUrl+"oauth2/logout",this.onUnauthenticated=null==e?void 0:e.onUnauthenticated,this.loading=!1,this.refreshProfile().catch(console.log),this.setupStorageListener()}clear(){this.storage.clear(),this.resourceCache.clear(),this.dispatchEvent({type:"change"})}get(e){return this.request("GET",e)}post(e,t,r){return this.request("POST",e,r,t)}put(e,t,r){return this.request("PUT",e,r,t)}delete(e){return this.request("DELETE",e)}register(e){return t(this,void 0,void 0,(function*(){const t=yield this.post("auth/register",e);yield this.setActiveLogin(t)}))}startLogin(e,r,n){return t(this,void 0,void 0,(function*(){return yield this.startPkce(),this.post("auth/login",{clientId:this.clientId,scope:F,codeChallengeMethod:"S256",codeChallenge:this.storage.getString("codeChallenge"),email:e,password:r,remember:!!n})}))}startGoogleLogin(e){return t(this,void 0,void 0,(function*(){return yield this.startPkce(),this.post("auth/google",e)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const e=new URLSearchParams(window.location.search).get("code");return e?this.processCode(e):void this.requestAuthorization()}signOutWithRedirect(){window.location.assign(this.logoutUrl)}fhirUrl(...e){const t=[this.baseUrl,"fhir/R4"];return e.forEach((e=>t.push("/",encodeURIComponent(e)))),t.join("")}search(e){return this.get(this.fhirUrl(e.resourceType)+L(e))}searchValueSet(e,t){return this.get(this.fhirUrl("ValueSet","$expand")+`?url=${encodeURIComponent(e)}`+`&filter=${encodeURIComponent(t)}`)}getCached(e,t){const r=this.resourceCache.get(e+"/"+t);if(r&&!("then"in r))return r}getCachedReference(e){const t=this.resourceCache.get(e.reference);if(t&&!("then"in t))return t}read(e,t){const r=e+"/"+t,n=this.get(this.fhirUrl(e,t)).then((e=>(this.resourceCache.set(r,e),e)));return this.resourceCache.set(r,n),n}readCached(e,t){const r=this.resourceCache.get(e+"/"+t);return r?Promise.resolve(r):this.read(e,t)}readReference(e){const t=null==e?void 0:e.reference;if(!t)return Promise.reject("Missing reference");const[r,n]=t.split("/");return this.read(r,n)}readCachedReference(e){const t=null==e?void 0:e.reference;if(!t)return Promise.reject("Missing reference");const[r,n]=t.split("/");return this.readCached(r,n)}getSchema(){return this.schema}requestSchema(e){return t(this,void 0,void 0,(function*(){if(e in this.schema.types)return Promise.resolve(this.schema);const t=`{\n StructureDefinitionList(name: "${encodeURIComponent(e)}") {\n name,\n description,\n snapshot {\n element {\n id,\n path,\n min,\n max,\n type {\n code,\n targetProfile\n },\n binding {\n valueSet\n },\n definition\n }\n }\n }\n SearchParameterList(base: "${encodeURIComponent(e)}") {\n base,\n code,\n type\n }\n }`.replace(/\s+/g," "),r=yield this.graphql(t);for(const e of r.data.StructureDefinitionList)M(this.schema,e);for(const e of r.data.SearchParameterList)B(this.schema,e);return this.schema}))}readHistory(e,t){return this.get(this.fhirUrl(e,t,"_history"))}readPatientEverything(e){return this.get(this.fhirUrl("Patient",e,"$everything"))}create(e){if(!e.resourceType)throw new Error("Missing resourceType");return this.post(this.fhirUrl(e.resourceType),e)}createBinary(e,t,r){return this.post(this.fhirUrl("Binary")+"?_filename="+encodeURIComponent(t),e,r)}update(e){if(!e.resourceType)throw new Error("Missing resourceType");if(!e.id)throw new Error("Missing id");return this.put(this.fhirUrl(e.resourceType,e.id),e)}patch(e,t,r){return this.request("PATCH",this.fhirUrl(e,t),"application/json-patch+json",r)}deleteResource(e,t){return this.delete(this.fhirUrl(e,t))}graphql(e){return this.post(this.fhirUrl("$graphql"),{query:e},"application/json")}getActiveLogin(){return this.storage.getObject("activeLogin")}setActiveLogin(e){return t(this,void 0,void 0,(function*(){this.storage.setObject("activeLogin",e),this.addLogin(e),this.resourceCache.clear(),this.refreshPromise=void 0,yield this.refreshProfile()}))}getLogins(){var e;return null!==(e=this.storage.getObject("logins"))&&void 0!==e?e:[]}addLogin(e){const t=this.getLogins().filter((t=>{var r,n;return(null===(r=t.profile)||void 0===r?void 0:r.reference)!==(null===(n=e.profile)||void 0===n?void 0:n.reference)}));t.push(e),this.storage.setObject("logins",t)}refreshProfile(){var e;return t(this,void 0,void 0,(function*(){const t=null===(e=this.getActiveLogin())||void 0===e?void 0:e.profile;return(null==t?void 0:t.reference)&&(this.loading=!0,this.storage.setObject("profile",yield this.readCachedReference(t)),this.loading=!1,this.dispatchEvent({type:"change"})),this.getProfile()}))}getProfile(){return this.storage.getObject("profile")}isLoading(){return this.loading}request(e,r,n,i){var o;return t(this,void 0,void 0,(function*(){this.refreshPromise&&(yield this.refreshPromise),r.startsWith("http")||(r=this.baseUrl+r);const t={"Content-Type":n||"application/fhir+json"},s=null===(o=this.getActiveLogin())||void 0===o?void 0:o.accessToken;s&&(t.Authorization="Bearer "+s);const c={method:e,cache:"no-cache",credentials:"include",headers:t};i&&("string"==typeof i||"undefined"!=typeof File&&i instanceof File?c.body=i:c.body=a(i));const u=yield this.fetch(r,c);if(401===u.status)return this.handleUnauthenticated(e,r,n,i);if(204===u.status||304===u.status)return;const h=yield u.json();return"OperationOutcome"!==h.resourceType||b(h)?h:Promise.reject(h)}))}handleUnauthenticated(e,r,n,i){return t(this,void 0,void 0,(function*(){return this.refresh().then((()=>this.request(e,r,n,i))).catch((e=>(this.clear(),this.onUnauthenticated&&this.onUnauthenticated(),Promise.reject(e))))}))}startPkce(){return t(this,void 0,void 0,(function*(){const e=f();this.storage.setString("pkceState",e);const r=f();this.storage.setString("codeVerifier",r);const n=d(yield function(e){return t(this,void 0,void 0,(function*(){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}))}(r)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");this.storage.setString("codeChallenge",n)}))}requestAuthorization(){return t(this,void 0,void 0,(function*(){if(!this.authorizeUrl)throw new Error("Missing authorize URL");this.startPkce(),window.location.assign(this.authorizeUrl+"?response_type=code&state="+encodeURIComponent(this.storage.getString("pkceState"))+"&client_id="+encodeURIComponent(this.clientId)+"&redirect_uri="+encodeURIComponent(H())+"&scope="+encodeURIComponent(F)+"&code_challenge_method=S256&code_challenge="+encodeURIComponent(this.storage.getString("codeChallenge")))}))}processCode(e){if(!this.storage.getString("pkceState"))throw this.clear(),new Error("Invalid PCKE state");const t=this.storage.getString("codeVerifier");if(!t)throw this.clear(),new Error("Invalid PCKE code verifier");return this.fetchTokens("grant_type=authorization_code"+(this.clientId?"&client_id="+encodeURIComponent(this.clientId):"")+"&code_verifier="+encodeURIComponent(t)+"&redirect_uri="+encodeURIComponent(H())+"&code="+encodeURIComponent(e))}refresh(){var e;return t(this,void 0,void 0,(function*(){if(this.refreshPromise)return this.refreshPromise;const t=null===(e=this.getActiveLogin())||void 0===e?void 0:e.refreshToken;if(!t)return this.clear(),Promise.reject("Invalid refresh token");this.refreshPromise=this.fetchTokens("grant_type=refresh_token&client_id="+encodeURIComponent(this.clientId)+"&refresh_token="+encodeURIComponent(t)),yield this.refreshPromise}))}fetchTokens(e){return t(this,void 0,void 0,(function*(){return this.tokenUrl?this.fetch(this.tokenUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e}).then((e=>e.ok?e.json():Promise.reject("Failed to fetch tokens"))).then((e=>this.verifyTokens(e))).then((()=>this.getProfile())):Promise.reject("Missing token URL")}))}verifyTokens(e){return t(this,void 0,void 0,(function*(){const t=e.access_token,r=g(t);return Date.now()>=1e3*r.exp?(this.clear(),Promise.reject("Token expired")):this.clientId&&r.client_id!==this.clientId?(this.clear(),Promise.reject("Token was not issued for this audience")):void(yield this.setActiveLogin({accessToken:t,refreshToken:e.refresh_token,project:e.project,profile:e.profile}))}))}setupStorageListener(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}}},e.OperationOutcomeError=w,e.accessDenied=C,e.allOk=O,e.arrayBufferToBase64=d,e.arrayBufferToHex=l,e.assertOk=function(e,t){if(!b(e)||void 0===t)throw new w(e)},e.badRequest=function(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}},e.buildTypeName=q,e.capitalize=p,e.createReference=function(e){const t=i(e),r=s(e);return r===t?{reference:t}:{reference:t,display:r}},e.createSchema=D,e.created=P,e.deepEquals=function e(t,r,n){let i=Object.keys(t),o=Object.keys(r);if("meta"===n&&(i=i.filter((e=>"versionId"!==e&&"lastUpdated"!==e&&"author"!==e)),o=o.filter((e=>"versionId"!==e&&"lastUpdated"!==e&&"author"!==e))),i.length!==o.length)return!1;for(const n of i){const i=t[n],o=r[n];if(u(i)&&u(o)){if(!e(i,o,n))return!1}else if(i!==o)return!1}return!0},e.formatAddress=function(e,t){const r=[];return e.line&&r.push(...e.line),e.city&&r.push(e.city),e.state&&r.push(e.state),e.postalCode&&r.push(e.postalCode),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&r.push("["+e.use+"]"),r.join(", ").trim()},e.formatFamilyName=function(e){return e.family||""},e.formatGivenName=function(e){const t=[];return e.given&&t.push(...e.given),t.join(" ").trim()},e.formatHumanName=n,e.formatSearchQuery=L,e.getDateProperty=function(e){return e?new Date(e):void 0},e.getDisplayString=s,e.getExpressionForResourceType=Q,e.getImageSrc=function(e){if(o(e)){const t=e.photo;if(t)for(const e of t)if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}},e.getPropertyDisplayName=function(e){return e.path.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(p).join(" ").replace("_"," ").replace(/\s+/g," ")},e.getReferenceString=i,e.getSearchParameterDetails=function(t,r,n){var i,o,s,a;const c=n.code.split("-").reduce(((e,t,r)=>e+(r?p(t):t)),""),u=null===(i=Q(r,n.expression))||void 0===i?void 0:i.split(".");if(!u)return{columnName:c,type:e.SearchParameterType.TEXT};let h,l=r,d=!1;for(let r=1;r<u.length;r++){const n=u[r],i=null===(s=null===(o=t.types[l])||void 0===o?void 0:o.properties)||void 0===s?void 0:s[n];if(!i)return{columnName:c,type:e.SearchParameterType.TEXT,array:d};if("*"===i.max&&(d=!0),h=null===(a=i.type)||void 0===a?void 0:a[0].code,!h)return{columnName:c,type:e.SearchParameterType.TEXT,array:d};r<u.length-1&&("Element"===h||"BackboneElement"===h?l+=p(n):l=h)}const f=function(t,r){let n=e.SearchParameterType.TEXT;switch(t.type){case"date":n=e.SearchParameterType.DATE;break;case"number":n=e.SearchParameterType.NUMBER;break;case"quantity":n=e.SearchParameterType.QUANTITY;break;case"reference":n=e.SearchParameterType.REFERENCE;break;case"token":"boolean"===r&&(n=e.SearchParameterType.BOOLEAN)}return n}(n,h);return{columnName:c,type:f,array:d}},e.getStatus=function(e){return e.id===m?200:e.id===v?201:e.id===T?304:e.id===S?403:e.id===E?404:e.id===y?410:400},e.gone=A,e.indexSearchParameter=B,e.indexStructureDefinition=M,e.isGone=function(e){return e.id===y},e.isLowerCase=function(e){return e===e.toLowerCase()},e.isNotFound=function(e){return e.id===E},e.isOk=b,e.isProfileResource=o,e.notFound=R,e.notModified=U,e.parseSearchDefinition=function(t){const r=t.pathname.split("/").pop(),n=new URLSearchParams(t.search),i=[],o=[];let s,a=0,c=10;return n.forEach(((t,r)=>{"_fields"===r?s=t.split(","):"_page"===r?a=parseInt(t):"_count"===r?c=parseInt(t):"_sort"===r?o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(t)):i.push(function(t,r){let n=t,i=e.Operator.EQUALS;for(const e of _){const t=n.indexOf(":"+e);-1!==t&&(i=e,n=n.substring(0,t))}for(const e of k)r.match(new RegExp("^"+e+"\\d"))&&(i=e,r=r.substring(e.length));return{code:n,operator:i,value:r}}(r,t))})),{resourceType:r,filters:i,fields:s,page:a,count:c,sortRules:o}},e.stringify=a,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */function t(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function i(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}function n(e,t,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(e,i):r?r.value=i:t.set(e,i),i}var r,o,s,a;class c{constructor(e=10){r.add(this),o.set(this,void 0),s.set(this,void 0),n(this,o,e,"f"),n(this,s,new Map,"f")}clear(){i(this,s,"f").clear()}get(e){const t=i(this,s,"f").get(e);return t&&(i(this,s,"f").delete(e),i(this,s,"f").set(e,t)),t}set(e,t){i(this,s,"f").has(e)?i(this,s,"f").delete(e):i(this,s,"f").size>=i(this,o,"f")&&i(this,s,"f").delete(i(this,r,"m",a).call(this)),i(this,s,"f").set(e,t)}}function h(e,t){const i=[];return e.prefix&&((null==t?void 0:t.all)||(null==t?void 0:t.prefix))&&i.push(...e.prefix),e.given&&i.push(...e.given),e.family&&i.push(e.family),e.suffix&&((null==t?void 0:t.all)||(null==t?void 0:t.suffix))&&i.push(...e.suffix),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&i.push("["+e.use+"]"),i.join(" ").trim()}function u(e){return e.resourceType+"/"+e.id}function l(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function d(e){if(l(e)){const t=function(e){const t=e.name;if(t&&t.length>0)return h(t[0]);return}(e);if(t)return t}if("Device"===e.resourceType){const t=function(e){const t=e.deviceName;if(t&&t.length>0)return t[0].name;return}(e);if(t)return t}return"User"===e.resourceType&&e.email?e.email:"name"in e&&e.name&&"string"==typeof e.name?e.name:u(e)}function f(e,t){return JSON.stringify(e,p,t?2:void 0)}function p(e,t){return function(e){if(null==e)return!0;const t=typeof e;return"string"===t&&""===e||"object"===t&&0===Object.keys(e).length}(t)?void 0:t}function m(e){return null!==e&&"object"==typeof e}o=new WeakMap,s=new WeakMap,r=new WeakSet,a=function(){return i(this,s,"f").keys().next().value};const g=[];for(let e=0;e<256;e++)g.push(e.toString(16).padStart(2,"0"));function v(e){const t=new Uint8Array(e),i=new Array(t.length);for(let e=0;e<t.length;e++)i[e]=g[t[e]];return i.join("")}function y(e){const t=new Uint8Array(e),i=[];for(let e=0;e<t.length;e++)i[e]=String.fromCharCode(t[e]);return window.btoa(i.join(""))}function T(e){return e.charAt(0).toUpperCase()+e.substr(1)}function E(){const e=new Uint32Array(28);return crypto.getRandomValues(e),v(e.buffer)}var w;function S(e){const[t,i,n]=e.split(".");return function(e){const t=e.replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(t),n=Array.from(i).reduce(((e,t)=>`${e}%${("00"+t.charCodeAt(0).toString(16)).slice(-2)}`),""),r=decodeURIComponent(n);return JSON.parse(r)}(i)}w=new WeakMap;const O="ok",R="created",P="gone",A="not-modified",C="not-found",b="access-denied",U={resourceType:"OperationOutcome",id:O,issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},k={resourceType:"OperationOutcome",id:R,issue:[{severity:"information",code:"information",details:{text:"Created"}}]},_={resourceType:"OperationOutcome",id:A,issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},I={resourceType:"OperationOutcome",id:C,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},N={resourceType:"OperationOutcome",id:P,issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},L={resourceType:"OperationOutcome",id:b,issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function x(e){return e.id===O||e.id===R||e.id===A}class M extends Error{constructor(e){var t,i;super(null===(i=null===(t=null==e?void 0:e.issue)||void 0===t?void 0:t[0].details)||void 0===i?void 0:i.text),this.outcome=e}}var j;e.Operator=void 0,(j=e.Operator||(e.Operator={})).EQUALS="eq",j.NOT_EQUALS="ne",j.GREATER_THAN="gt",j.LESS_THAN="lt",j.GREATER_THAN_OR_EQUALS="ge",j.LESS_THAN_OR_EQUALS="le",j.STARTS_AFTER="sa",j.ENDS_BEFORE="eb",j.APPROXIMATELY="ap",j.CONTAINS="contains",j.EXACT="exact",j.TEXT="text",j.ABOVE="above",j.BELOW="below",j.IN="in",j.NOT_IN="not-in",j.OF_TYPE="of-type";const D=[e.Operator.CONTAINS,e.Operator.EXACT,e.Operator.TEXT,e.Operator.ABOVE,e.Operator.BELOW,e.Operator.IN,e.Operator.NOT_IN,e.Operator.OF_TYPE],W=[e.Operator.NOT_EQUALS,e.Operator.GREATER_THAN,e.Operator.LESS_THAN,e.Operator.GREATER_THAN_OR_EQUALS,e.Operator.LESS_THAN_OR_EQUALS,e.Operator.STARTS_AFTER,e.Operator.ENDS_BEFORE,e.Operator.APPROXIMATELY];function B(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>{const i=D.includes(e.operator)?":"+e.operator:"",n=W.includes(e.operator)?e.operator:"";t.push(`${e.code}${i}=${n}${encodeURIComponent(e.value)}`)})),e.sortRules&&t.push(function(e){if(!e||0===e.length)return"";return"_sort="+e.map((e=>e.descending?"-"+e.code:e.code)).join(",")}(e.sortRules)),e.page&&e.page>0&&t.push("_page="+e.page),e.count&&e.count>0&&t.push("_count="+e.count),e.total&&t.push("_total="+encodeURIComponent(e.total)),0===t.length?"":(t.sort(),"?"+t.join("&"))}var F,H,Q,$,X,q,G,z,V,Y,J,K,Z,ee,te,ie,ne,re,oe,se,ae,ce,he,ue,le,de,fe,pe,me,ge,ve;class ye{constructor(){F.set(this,void 0),n(this,F,"undefined"!=typeof localStorage?localStorage:new Te,"f")}clear(){i(this,F,"f").clear()}getString(e){return i(this,F,"f").getItem(e)||void 0}setString(e,t){t?i(this,F,"f").setItem(e,t):i(this,F,"f").removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?f(t):void 0)}}F=new WeakMap;class Te{constructor(){H.set(this,void 0),n(this,H,new Map,"f")}get length(){return i(this,H,"f").size}clear(){i(this,H,"f").clear()}getItem(e){var t;return null!==(t=i(this,H,"f").get(e))&&void 0!==t?t:null}setItem(e,t){t?i(this,H,"f").set(e,t):i(this,H,"f").delete(e)}removeItem(e){i(this,H,"f").delete(e)}key(e){return Array.from(i(this,H,"f").keys())[e]}}function Ee(){return{types:{}}}function we(e,t){var i;const n=t.name;if(!n)return;e.types[n]={display:n,description:t.description,properties:{}};const r=null===(i=t.snapshot)||void 0===i?void 0:i.element;if(r){const t=r.filter((e=>e.path!==n&&e.path));t.forEach((t=>function(e,t){var i,n;const r=t.path,o=null===(n=null===(i=t.type)||void 0===i?void 0:i[0])||void 0===n?void 0:n.code;if("Element"!==o&&"BackboneElement"!==o)return;const s=r.split("."),a=Oe(s);a in e.types||(e.types[a]={display:a,description:t.definition,parentType:Oe(s.slice(0,s.length-1)),properties:{}})}(e,t))),t.forEach((t=>function(e,t){const i=t.path.split(".");if(1===i.length)return;const n=Oe(i.slice(0,i.length-1)),r=e.types[n],o=i[i.length-1];r.properties[o]=t}(e,t)))}}function Se(e,t){if(t.base)for(const i of t.base){const n=e.types[i];n&&(n.searchParams||(n.searchParams={}),n.searchParams[t.code]=t)}}function Oe(e){return e.map(T).join("")}H=new WeakMap,e.PropertyType=void 0,(Q=e.PropertyType||(e.PropertyType={})).Address="Address",Q.Age="Age",Q.Annotation="Annotation",Q.Attachment="Attachment",Q.BackboneElement="BackboneElement",Q.CodeableConcept="CodeableConcept",Q.Coding="Coding",Q.ContactDetail="ContactDetail",Q.ContactPoint="ContactPoint",Q.Contributor="Contributor",Q.Count="Count",Q.DataRequirement="DataRequirement",Q.Distance="Distance",Q.Dosage="Dosage",Q.Duration="Duration",Q.Expression="Expression",Q.Extension="Extension",Q.HumanName="HumanName",Q.Identifier="Identifier",Q.MarketingStatus="MarketingStatus",Q.Meta="Meta",Q.Money="Money",Q.Narrative="Narrative",Q.ParameterDefinition="ParameterDefinition",Q.Period="Period",Q.Population="Population",Q.ProdCharacteristic="ProdCharacteristic",Q.ProductShelfLife="ProductShelfLife",Q.Quantity="Quantity",Q.Range="Range",Q.Ratio="Ratio",Q.Reference="Reference",Q.RelatedArtifact="RelatedArtifact",Q.Resource="Resource",Q.SampledData="SampledData",Q.Signature="Signature",Q.SubstanceAmount="SubstanceAmount",Q.SystemString="http://hl7.org/fhirpath/System.String",Q.Timing="Timing",Q.TriggerDefinition="TriggerDefinition",Q.UsageContext="UsageContext",Q.base64Binary="base64Binary",Q.boolean="boolean",Q.canonical="canonical",Q.code="code",Q.date="date",Q.dateTime="dateTime",Q.decimal="decimal",Q.id="id",Q.instant="instant",Q.integer="integer",Q.markdown="markdown",Q.oid="oid",Q.positiveInt="positiveInt",Q.string="string",Q.time="time",Q.unsignedInt="unsignedInt",Q.uri="uri",Q.url="url",Q.uuid="uuid";const Re="launch/patient openid fhirUser offline_access user/*.*";function Pe(){return window.location.protocol+"//"+window.location.host+"/"}var Ae;function Ce(e,t){const i=t.split(" | ");for(const t of i){const i=be(t);if(i.startsWith(e+"."))return i}}function be(e){let t=e.trim();return t.startsWith("(")&&t.endsWith(")")&&(t=t.substring(1,t.length-1)),t.includes(" as ")&&(t=t.substring(0,t.indexOf(" as "))),t.includes(".where(")&&(t=t.substring(0,t.indexOf(".where("))),t}X=new WeakMap,q=new WeakMap,G=new WeakMap,z=new WeakMap,V=new WeakMap,Y=new WeakMap,J=new WeakMap,K=new WeakMap,Z=new WeakMap,ee=new WeakMap,te=new WeakMap,ie=new WeakMap,ne=new WeakMap,re=new WeakMap,oe=new WeakMap,se=new WeakMap,$=new WeakSet,ae=function(e){const t=this.getLogins().filter((t=>{var i,n;return(null===(i=t.profile)||void 0===i?void 0:i.reference)!==(null===(n=e.profile)||void 0===n?void 0:n.reference)}));t.push(e),i(this,q,"f").setObject("logins",t)},ce=function(){return t(this,void 0,void 0,(function*(){return n(this,re,new Promise(((e,t)=>{this.get("auth/me").then((t=>{n(this,re,void 0,"f"),n(this,oe,t.profile,"f"),n(this,se,t.config,"f"),this.dispatchEvent({type:"change"}),e(i(this,oe,"f"))})).catch(t)})),"f"),i(this,re,"f")}))},he=function(e,n,r,o){return t(this,void 0,void 0,(function*(){i(this,ne,"f")&&(yield i(this,ne,"f")),n.startsWith("http")||(n=i(this,V,"f")+n);const t=i(this,$,"m",ue).call(this,e,r,o),s=yield i(this,X,"f").call(this,n,t);if(401===s.status)return i(this,$,"m",le).call(this,e,n,r,o);if(204===s.status||304===s.status)return;const a=yield s.json();return"OperationOutcome"!==a.resourceType||x(a)?a:Promise.reject(a)}))},ue=function(e,t,n){const r={"Content-Type":t||"application/fhir+json"};i(this,te,"f")&&(r.Authorization="Bearer "+i(this,te,"f"));const o={method:e,cache:"no-cache",credentials:"include",headers:r};return n&&("string"==typeof n||"undefined"!=typeof File&&n instanceof File?o.body=n:o.body=f(n)),o},le=function(e,n,r,o){return t(this,void 0,void 0,(function*(){return i(this,$,"m",pe).call(this).then((()=>i(this,$,"m",he).call(this,e,n,r,o))).catch((e=>(this.clear(),i(this,ee,"f")&&i(this,ee,"f").call(this),Promise.reject(e))))}))},de=function(){return t(this,void 0,void 0,(function*(){const e=E();i(this,q,"f").setString("pkceState",e);const n=E();i(this,q,"f").setString("codeVerifier",n);const r=y(yield function(e){return t(this,void 0,void 0,(function*(){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}))}(n)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");i(this,q,"f").setString("codeChallenge",r)}))},fe=function(){return t(this,void 0,void 0,(function*(){if(!i(this,J,"f"))throw new Error("Missing authorize URL");i(this,$,"m",de).call(this),window.location.assign(i(this,J,"f")+"?response_type=code&state="+encodeURIComponent(i(this,q,"f").getString("pkceState"))+"&client_id="+encodeURIComponent(i(this,Y,"f"))+"&redirect_uri="+encodeURIComponent(Pe())+"&scope="+encodeURIComponent(Re)+"&code_challenge_method=S256&code_challenge="+encodeURIComponent(i(this,q,"f").getString("codeChallenge")))}))},pe=function(){return t(this,void 0,void 0,(function*(){return i(this,ne,"f")?i(this,ne,"f"):i(this,ie,"f")?(n(this,ne,i(this,$,"m",me).call(this,"grant_type=refresh_token&client_id="+encodeURIComponent(i(this,Y,"f"))+"&refresh_token="+encodeURIComponent(i(this,ie,"f"))),"f"),void(yield i(this,ne,"f"))):(this.clear(),Promise.reject("Invalid refresh token"))}))},me=function(e){return t(this,void 0,void 0,(function*(){return i(this,K,"f")?i(this,X,"f").call(this,i(this,K,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e}).then((e=>e.ok?e.json():Promise.reject("Failed to fetch tokens"))).then((e=>i(this,$,"m",ge).call(this,e))).then((()=>this.getProfile())):Promise.reject("Missing token URL")}))},ge=function(e){return t(this,void 0,void 0,(function*(){const t=e.access_token,n=S(t);return Date.now()>=1e3*n.exp?(this.clear(),Promise.reject("Token expired")):i(this,Y,"f")&&n.client_id!==i(this,Y,"f")?(this.clear(),Promise.reject("Token was not issued for this audience")):void(yield this.setActiveLogin({accessToken:t,refreshToken:e.refresh_token,project:e.project,profile:e.profile}))}))},ve=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}},e.SearchParameterType=void 0,(Ae=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",Ae.NUMBER="NUMBER",Ae.QUANTITY="QUANTITY",Ae.TEXT="TEXT",Ae.REFERENCE="REFERENCE",Ae.DATE="DATE",Ae.DATETIME="DATETIME",Ae.PERIOD="PERIOD",e.MedplumClient=class extends class{constructor(){w.set(this,void 0),n(this,w,{},"f")}addEventListener(e,t){i(this,w,"f")[e]||(i(this,w,"f")[e]=[]),i(this,w,"f")[e].push(t)}removeEventListeneer(e,t){const n=i(this,w,"f")[e];if(n)for(let e=0;e<n.length;e++)if(n[e]===t)return void n.splice(e,1)}dispatchEvent(e){const t=i(this,w,"f")[e.type];return t&&t.forEach((t=>t.call(this,e))),!e.defaultPrevented}}{constructor(e){var t;if(super(),$.add(this),X.set(this,void 0),q.set(this,void 0),G.set(this,void 0),z.set(this,void 0),V.set(this,void 0),Y.set(this,void 0),J.set(this,void 0),K.set(this,void 0),Z.set(this,void 0),ee.set(this,void 0),te.set(this,void 0),ie.set(this,void 0),ne.set(this,void 0),re.set(this,void 0),oe.set(this,void 0),se.set(this,void 0),null==e?void 0:e.baseUrl){if(!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");if(!e.baseUrl.endsWith("/"))throw new Error("Base URL must end with a trailing slash")}n(this,X,(null==e?void 0:e.fetch)||window.fetch.bind(window),"f"),n(this,q,new ye,"f"),n(this,G,{types:{}},"f"),n(this,z,new c(null!==(t=null==e?void 0:e.resourceCacheSize)&&void 0!==t?t:1e3),"f"),n(this,V,(null==e?void 0:e.baseUrl)||"https://api.medplum.com/","f"),n(this,Y,(null==e?void 0:e.clientId)||"","f"),n(this,J,(null==e?void 0:e.authorizeUrl)||i(this,V,"f")+"oauth2/authorize","f"),n(this,K,(null==e?void 0:e.tokenUrl)||i(this,V,"f")+"oauth2/token","f"),n(this,Z,(null==e?void 0:e.logoutUrl)||i(this,V,"f")+"oauth2/logout","f"),n(this,ee,null==e?void 0:e.onUnauthenticated,"f");const r=this.getActiveLogin();r&&(n(this,te,r.accessToken,"f"),n(this,ie,r.refreshToken,"f"),i(this,$,"m",ce).call(this).catch(console.log)),i(this,$,"m",ve).call(this)}clear(){i(this,q,"f").clear(),i(this,z,"f").clear(),n(this,te,void 0,"f"),n(this,ie,void 0,"f"),n(this,oe,void 0,"f"),n(this,se,void 0,"f"),this.dispatchEvent({type:"change"})}get(e){return i(this,$,"m",he).call(this,"GET",e)}post(e,t,n){return i(this,$,"m",he).call(this,"POST",e,n,t)}put(e,t,n){return i(this,$,"m",he).call(this,"PUT",e,n,t)}delete(e){return i(this,$,"m",he).call(this,"DELETE",e)}register(e){return t(this,void 0,void 0,(function*(){const t=yield this.post("auth/register",e);yield this.setActiveLogin(t)}))}startLogin(e,n,r){return t(this,void 0,void 0,(function*(){return yield i(this,$,"m",de).call(this),this.post("auth/login",{clientId:i(this,Y,"f"),scope:Re,codeChallengeMethod:"S256",codeChallenge:i(this,q,"f").getString("codeChallenge"),email:e,password:n,remember:!!r})}))}startGoogleLogin(e){return t(this,void 0,void 0,(function*(){return yield i(this,$,"m",de).call(this),this.post("auth/google",e)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const e=new URLSearchParams(window.location.search).get("code");return e?this.processCode(e):void i(this,$,"m",fe).call(this)}signOutWithRedirect(){window.location.assign(i(this,Z,"f"))}fhirUrl(...e){const t=[i(this,V,"f"),"fhir/R4"];return e.forEach((e=>t.push("/",encodeURIComponent(e)))),t.join("")}search(e){return this.get(this.fhirUrl(e.resourceType)+B(e))}searchValueSet(e,t){return this.get(this.fhirUrl("ValueSet","$expand")+`?url=${encodeURIComponent(e)}`+`&filter=${encodeURIComponent(t)}`)}getCached(e,t){const n=i(this,z,"f").get(e+"/"+t);if(n&&!("then"in n))return n}getCachedReference(e){const t=i(this,z,"f").get(e.reference);if(t&&!("then"in t))return t}read(e,t){const n=e+"/"+t,r=this.get(this.fhirUrl(e,t)).then((e=>(i(this,z,"f").set(n,e),e)));return i(this,z,"f").set(n,r),r}readCached(e,t){const n=i(this,z,"f").get(e+"/"+t);return n?Promise.resolve(n):this.read(e,t)}readReference(e){const t=null==e?void 0:e.reference;if(!t)return Promise.reject("Missing reference");const[i,n]=t.split("/");return this.read(i,n)}readCachedReference(e){const t=null==e?void 0:e.reference;if(!t)return Promise.reject("Missing reference");const[i,n]=t.split("/");return this.readCached(i,n)}getSchema(){return i(this,G,"f")}requestSchema(e){return t(this,void 0,void 0,(function*(){if(e in i(this,G,"f").types)return Promise.resolve(i(this,G,"f"));const t=`{\n StructureDefinitionList(name: "${encodeURIComponent(e)}") {\n name,\n description,\n snapshot {\n element {\n id,\n path,\n min,\n max,\n type {\n code,\n targetProfile\n },\n binding {\n valueSet\n },\n definition\n }\n }\n }\n SearchParameterList(base: "${encodeURIComponent(e)}") {\n base,\n code,\n type\n }\n }`.replace(/\s+/g," "),n=yield this.graphql(t);for(const e of n.data.StructureDefinitionList)we(i(this,G,"f"),e);for(const e of n.data.SearchParameterList)Se(i(this,G,"f"),e);return i(this,G,"f")}))}readHistory(e,t){return this.get(this.fhirUrl(e,t,"_history"))}readPatientEverything(e){return this.get(this.fhirUrl("Patient",e,"$everything"))}create(e){if(!e.resourceType)throw new Error("Missing resourceType");return this.post(this.fhirUrl(e.resourceType),e)}createBinary(e,t,i){return this.post(this.fhirUrl("Binary")+"?_filename="+encodeURIComponent(t),e,i)}update(e){if(!e.resourceType)throw new Error("Missing resourceType");if(!e.id)throw new Error("Missing id");return this.put(this.fhirUrl(e.resourceType,e.id),e)}patch(e,t,n){return i(this,$,"m",he).call(this,"PATCH",this.fhirUrl(e,t),"application/json-patch+json",n)}deleteResource(e,t){return this.delete(this.fhirUrl(e,t))}graphql(e){return this.post(this.fhirUrl("$graphql"),{query:e},"application/json")}getActiveLogin(){return i(this,q,"f").getObject("activeLogin")}setActiveLogin(e){return t(this,void 0,void 0,(function*(){n(this,te,e.accessToken,"f"),n(this,ie,e.refreshToken,"f"),n(this,oe,void 0,"f"),n(this,se,void 0,"f"),i(this,q,"f").setObject("activeLogin",e),i(this,$,"m",ae).call(this,e),i(this,z,"f").clear(),n(this,ne,void 0,"f"),yield i(this,$,"m",ce).call(this)}))}getLogins(){var e;return null!==(e=i(this,q,"f").getObject("logins"))&&void 0!==e?e:[]}isLoading(){return!!i(this,re,"f")}getProfile(){return i(this,oe,"f")}getProfileAsync(){return t(this,void 0,void 0,(function*(){return i(this,re,"f")&&(yield i(this,re,"f")),this.getProfile()}))}getUserConfiguration(){return i(this,se,"f")}download(e){return t(this,void 0,void 0,(function*(){i(this,ne,"f")&&(yield i(this,ne,"f"));const t=i(this,$,"m",ue).call(this,"GET");return(yield i(this,X,"f").call(this,e,t)).blob()}))}processCode(e){if(!i(this,q,"f").getString("pkceState"))throw this.clear(),new Error("Invalid PCKE state");const t=i(this,q,"f").getString("codeVerifier");if(!t)throw this.clear(),new Error("Invalid PCKE code verifier");return i(this,$,"m",me).call(this,"grant_type=authorization_code"+(i(this,Y,"f")?"&client_id="+encodeURIComponent(i(this,Y,"f")):"")+"&code_verifier="+encodeURIComponent(t)+"&redirect_uri="+encodeURIComponent(Pe())+"&code="+encodeURIComponent(e))}},e.OperationOutcomeError=M,e.accessDenied=L,e.allOk=U,e.arrayBufferToBase64=y,e.arrayBufferToHex=v,e.assertOk=function(e,t){if(!x(e)||void 0===t)throw new M(e)},e.badRequest=function(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}},e.buildTypeName=Oe,e.capitalize=T,e.createReference=function(e){const t=u(e),i=d(e);return i===t?{reference:t}:{reference:t,display:i}},e.createSchema=Ee,e.created=k,e.deepEquals=function e(t,i,n){let r=Object.keys(t),o=Object.keys(i);if("meta"===n&&(r=r.filter((e=>"versionId"!==e&&"lastUpdated"!==e&&"author"!==e)),o=o.filter((e=>"versionId"!==e&&"lastUpdated"!==e&&"author"!==e))),r.length!==o.length)return!1;for(const n of r){const r=t[n],o=i[n];if(m(r)&&m(o)){if(!e(r,o,n))return!1}else if(r!==o)return!1}return!0},e.formatAddress=function(e,t){const i=[];return e.line&&i.push(...e.line),e.city&&i.push(e.city),e.state&&i.push(e.state),e.postalCode&&i.push(e.postalCode),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&i.push("["+e.use+"]"),i.join(", ").trim()},e.formatFamilyName=function(e){return e.family||""},e.formatGivenName=function(e){const t=[];return e.given&&t.push(...e.given),t.join(" ").trim()},e.formatHumanName=h,e.formatSearchQuery=B,e.getDateProperty=function(e){return e?new Date(e):void 0},e.getDisplayString=d,e.getExpressionForResourceType=Ce,e.getImageSrc=function(e){if(l(e)){const t=e.photo;if(t)for(const e of t)if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}},e.getPropertyDisplayName=function(e){return e.path.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(T).join(" ").replace("_"," ").replace(/\s+/g," ")},e.getReferenceString=u,e.getSearchParameterDetails=function(t,i,n){var r,o,s,a;const c=n.code.split("-").reduce(((e,t,i)=>e+(i?T(t):t)),""),h=null===(r=Ce(i,n.expression))||void 0===r?void 0:r.split(".");if(!h)return{columnName:c,type:e.SearchParameterType.TEXT};let u,l=i,d=!1;for(let i=1;i<h.length;i++){const n=h[i],r=null===(s=null===(o=t.types[l])||void 0===o?void 0:o.properties)||void 0===s?void 0:s[n];if(!r)return{columnName:c,type:e.SearchParameterType.TEXT,array:d};if("*"===r.max&&(d=!0),u=null===(a=r.type)||void 0===a?void 0:a[0].code,!u)return{columnName:c,type:e.SearchParameterType.TEXT,array:d};i<h.length-1&&("Element"===u||"BackboneElement"===u?l+=T(n):l=u)}const f=function(t,i){let n=e.SearchParameterType.TEXT;switch(t.type){case"date":n=e.SearchParameterType.DATE;break;case"number":n=e.SearchParameterType.NUMBER;break;case"quantity":n=e.SearchParameterType.QUANTITY;break;case"reference":n=e.SearchParameterType.REFERENCE;break;case"token":"boolean"===i&&(n=e.SearchParameterType.BOOLEAN)}return n}(n,u);return{columnName:c,type:f,array:d}},e.getStatus=function(e){return e.id===O?200:e.id===R?201:e.id===A?304:e.id===b?403:e.id===C?404:e.id===P?410:400},e.gone=N,e.indexSearchParameter=Se,e.indexStructureDefinition=we,e.isGone=function(e){return e.id===P},e.isLowerCase=function(e){return e===e.toLowerCase()},e.isNotFound=function(e){return e.id===C},e.isOk=x,e.isProfileResource=l,e.notFound=I,e.notModified=_,e.parseSearchDefinition=function(t){const i=t.pathname.split("/").pop(),n=new URLSearchParams(t.search),r=[],o=[];let s,a,c=0,h=10;return n.forEach(((t,i)=>{"_fields"===i?s=t.split(","):"_page"===i?c=parseInt(t):"_count"===i?h=parseInt(t):"_total"===i?a=t:"_sort"===i?o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(t)):r.push(function(t,i){let n=t,r=e.Operator.EQUALS;for(const e of D){const t=n.indexOf(":"+e);-1!==t&&(r=e,n=n.substring(0,t))}for(const e of W)i.match(new RegExp("^"+e+"\\d"))&&(r=e,i=i.substring(e.length));return{code:n,operator:r,value:i}}(i,t))})),{resourceType:i,filters:r,fields:s,page:c,count:h,total:a,sortRules:o}},e.resolveId=function(e){var t;return null===(t=null==e?void 0:e.reference)||void 0===t?void 0:t.split("/")[1]},e.stringify=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
16
16
|
//# sourceMappingURL=index.min.js.map
|