@medplum/core 0.9.11 → 0.9.12
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 +7 -19
- 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 +7 -19
- 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/client.d.ts +8 -22
- package/package.json +2 -2
- package/document.pdf +0 -0
- package/test.pdf +0 -1
- package/test2.pdf +0 -1
- package/test3.pdf.txt +0 -1
- package/test4.pdf +0 -1
- package/test5.pdf +0 -0
- package/test7-2.pdf +0 -1
- package/test7.pdf +0 -1
- package/test8-2.pdf +0 -0
- package/test8.pdf +0 -0
- package/test9-2.pdf +0 -0
- package/test9-3.pdf +0 -0
- package/test9-4.pdf +0 -0
- package/test9.pdf +0 -0
package/dist/esm/index.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t,e,n,i){return new(n||(n=Promise))((function(r,s){function o(t){try{l(i.next(t))}catch(t){s(t)}}function a(t){try{l(i.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))}function e(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function n(t,e,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(t,n):r?r.value=n:e.set(t,n),n}var i,r,s,o;class a{constructor(t=10){i.add(this),r.set(this,void 0),s.set(this,void 0),n(this,r,t,"f"),n(this,s,new Map,"f")}clear(){e(this,s,"f").clear()}get(t){const n=e(this,s,"f").get(t);return n&&(e(this,s,"f").delete(t),e(this,s,"f").set(t,n)),n}set(t,n){e(this,s,"f").has(t)?e(this,s,"f").delete(t):e(this,s,"f").size>=e(this,r,"f")&&e(this,s,"f").delete(e(this,i,"m",o).call(this)),e(this,s,"f").set(t,n)}delete(t){e(this,s,"f").delete(t)}keys(){return e(this,s,"f").keys()}}function l(t,e){const n=[];return t.line&&n.push(...t.line),t.city&&n.push(t.city),t.state&&n.push(t.state),t.postalCode&&n.push(t.postalCode),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&n.push("["+t.use+"]"),n.join(", ").trim()}function c(t,e){const n=[];return t.prefix&&((null==e?void 0:e.all)||(null==e?void 0:e.prefix))&&n.push(...t.prefix),t.given&&n.push(...t.given),t.family&&n.push(t.family),t.suffix&&((null==e?void 0:e.all)||(null==e?void 0:e.suffix))&&n.push(...t.suffix),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&n.push("["+t.use+"]"),n.join(" ").trim()}function h(t){const e=[];return t.given&&e.push(...t.given),e.join(" ").trim()}function u(t){return t.family||""}function f(t){const e=d(t),n=g(t);return n===e?{reference:e}:{reference:e,display:n}}function d(t){return t.resourceType+"/"+t.id}function p(t){var e;return null===(e=null==t?void 0:t.reference)||void 0===e?void 0:e.split("/")[1]}function v(t){return"Patient"===t.resourceType||"Practitioner"===t.resourceType||"RelatedPerson"===t.resourceType}function g(t){var e,n;if(v(t)){const e=function(t){const e=t.name;if(e&&e.length>0)return c(e[0]);return}(t);if(e)return e}if("Device"===t.resourceType){const e=function(t){const e=t.deviceName;if(e&&e.length>0)return e[0].name;return}(t);if(e)return e}return"Observation"===t.resourceType&&"code"in t&&(null===(e=t.code)||void 0===e?void 0:e.text)?null===(n=t.code)||void 0===n?void 0:n.text:"User"===t.resourceType&&t.email?t.email:"name"in t&&t.name&&"string"==typeof t.name?t.name:d(t)}function m(t){if(v(t)){const e=t.photo;if(e)for(const t of e){const e=y(t);if(e)return e}}if("Bot"===t.resourceType&&t.photo){const e=y(t.photo);if(e)return e}}function y(t){if(t.url&&t.contentType&&t.contentType.startsWith("image/"))return t.url}function w(t){return t?new Date(t):void 0}function T(t,e){const n=new Date(t);n.setUTCHours(0,0,0,0);const i=e?new Date(e):new Date;i.setUTCHours(0,0,0,0);const r=n.getUTCFullYear(),s=n.getUTCMonth(),o=n.getUTCDate(),a=i.getUTCFullYear(),l=i.getUTCMonth(),c=i.getUTCDate();let h=a-r;(l<s||l===s&&c<o)&&h--;let u=12*a+l-(12*r+s);c<o&&u--;return{years:h,months:u,days:Math.floor((i.getTime()-n.getTime())/864e5)}}function b(t,e){const{years:n,months:i,days:r}=T(t,e);return n>=2?n.toString().padStart(3,"0")+"Y":i>=1?i.toString().padStart(3,"0")+"M":r.toString().padStart(3,"0")+"D"}function E(t){const e={};return S(t.item,e),e}function S(t,e){if(t)for(const n of t)n.linkId&&n.answer&&n.answer.length>0&&(e[n.linkId]=n.answer[0]),S(n.item,e)}function A(t,e){const n=t.identifier;if(!n)return;const i=Array.isArray(n)?n:[n];for(const t of i)if(t.system===e)return t.value}function k(t,...e){var n;let i=t;for(let t=0;t<e.length&&i;t++)i=null===(n=null==i?void 0:i.extension)||void 0===n?void 0:n.find((n=>n.url===e[t]));return null==i?void 0:i.valueString}function x(t,e){return JSON.stringify(t,P,e?2:void 0)}function P(t,e){return!function(t){return!!t.match(/\d+$/)}(t)&&O(e)?void 0:e}function O(t){if(null==t)return!0;const e=typeof t;return"string"===e&&""===t||"object"===e&&0===Object.keys(t).length}function U(t,e,n){return t===e||(!(!O(t)||!O(e))||!O(t)&&!O(e)&&(Array.isArray(t)&&Array.isArray(e)?function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!U(t[n],e[n]))return!1;return!0}(t,e):!Array.isArray(t)&&!Array.isArray(e)&&(C(t)&&C(e)?function(t,e,n){const i=new Set;Object.keys(t).forEach((t=>i.add(t))),Object.keys(e).forEach((t=>i.add(t))),"meta"===n&&(i.delete("versionId"),i.delete("lastUpdated"),i.delete("author"));for(const n of i){if(!U(t[n],e[n],n))return!1}return!0}(t,e,n):(C(t)||C(e),!1))))}function R(t){return!!t.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)}function C(t){return null!==t&&"object"==typeof t}function M(t){return t.every((t=>"string"==typeof t))}r=new WeakMap,s=new WeakMap,i=new WeakSet,o=function(){return e(this,s,"f").keys().next().value};const L=[];for(let t=0;t<256;t++)L.push(t.toString(16).padStart(2,"0"));function D(t){const e=new Uint8Array(t),n=new Array(e.length);for(let t=0;t<e.length;t++)n[t]=L[e[t]];return n.join("")}function _(t){const e=new Uint8Array(t),n=[];for(let t=0;t<e.length;t++)n[t]=String.fromCharCode(e[t]);return window.btoa(n.join(""))}function I(t){return t.charAt(0).toUpperCase()+t.substring(1)}function j(t){return t===t.toLowerCase()}function W(){const t=new Uint32Array(28);return crypto.getRandomValues(t),D(t.buffer)}var N;function B(t){const e=function(t){if("undefined"!=typeof window)return window.atob(t);if("undefined"!=typeof Buffer)return Buffer.from(t,"base64").toString("binary");throw new Error("Unable to decode base64")}(t.replace(/-/g,"+").replace(/_/g,"/")),n=Array.from(e).reduce(((t,e)=>`${t}%${("00"+e.charCodeAt(0).toString(16)).slice(-2)}`),""),i=decodeURIComponent(n);return JSON.parse(i)}N=new WeakMap;const Q={resourceType:"OperationOutcome",id:"ok",issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},$={resourceType:"OperationOutcome",id:"created",issue:[{severity:"information",code:"information",details:{text:"Created"}}]},F={resourceType:"OperationOutcome",id:"not-modified",issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},H={resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},q={resourceType:"OperationOutcome",id:"gone",issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},X={resourceType:"OperationOutcome",id:"access-denied",issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function z(t,e){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:t},expression:e?[e]:void 0}]}}function Y(t){return"ok"===t.id||"created"===t.id||"not-modified"===t.id}function V(t){return"not-found"===t.id}function G(t){return"gone"===t.id}function K(t){return"ok"===t.id?200:"created"===t.id?201:"not-modified"===t.id?304:"access-denied"===t.id?403:"not-found"===t.id?404:"gone"===t.id?410:400}function J(t,e){if(!Y(t)||void 0===e)throw new Z(t)}class Z extends Error{constructor(t){var e,n;super(null===(n=null===(e=null==t?void 0:t.issue)||void 0===e?void 0:e[0].details)||void 0===n?void 0:n.text),this.outcome=t}}var tt,et,nt,it,rt,st,ot,at,lt,ct,ht,ut,ft,dt,pt,vt,gt,mt,yt,wt,Tt,bt,Et,St,At,kt,xt,Pt,Ot,Ut,Rt,Ct,Mt,Lt,Dt,_t,It,jt,Wt;class Nt{constructor(t){this[rt]="ReadablePromise",tt.set(this,void 0),et.set(this,"pending"),nt.set(this,void 0),it.set(this,void 0),n(this,tt,t.then((t=>(n(this,et,"success","f"),n(this,nt,t,"f"),t)),(t=>{throw n(this,et,"error","f"),n(this,it,t,"f"),t})),"f")}isPending(){return"pending"===e(this,et,"f")}read(){switch(e(this,et,"f")){case"pending":throw e(this,tt,"f");case"error":throw e(this,it,"f");default:return e(this,nt,"f")}}then(t,n){return e(this,tt,"f").then(t,n)}catch(t){return e(this,tt,"f").catch(t)}finally(t){return e(this,tt,"f").finally(t)}}tt=new WeakMap,et=new WeakMap,nt=new WeakMap,it=new WeakMap,rt=Symbol.toStringTag;class Bt{constructor(){st.set(this,void 0),n(this,st,"undefined"!=typeof localStorage?localStorage:new Qt,"f")}clear(){e(this,st,"f").clear()}getString(t){return e(this,st,"f").getItem(t)||void 0}setString(t,n){n?e(this,st,"f").setItem(t,n):e(this,st,"f").removeItem(t)}getObject(t){const e=this.getString(t);return e?JSON.parse(e):void 0}setObject(t,e){this.setString(t,e?x(e):void 0)}}st=new WeakMap;class Qt{constructor(){ot.set(this,void 0),n(this,ot,new Map,"f")}get length(){return e(this,ot,"f").size}clear(){e(this,ot,"f").clear()}getItem(t){var n;return null!==(n=e(this,ot,"f").get(t))&&void 0!==n?n:null}setItem(t,n){n?e(this,ot,"f").set(t,n):e(this,ot,"f").delete(t)}removeItem(t){e(this,ot,"f").delete(t)}key(t){return Array.from(e(this,ot,"f").keys())[t]}}function $t(){return{types:{}}}function Ft(t,e){return{display:t,description:e,properties:{},searchParams:{_lastUpdated:{base:[t],code:"_lastUpdated",type:"date",expression:t+".meta.lastUpdated"}}}}function Ht(t,e){var n;const i=e.name;if(!i)return;t.types[i]=Ft(i,e.description);const r=null===(n=e.snapshot)||void 0===n?void 0:n.element;if(r){const e=r.filter((t=>t.path!==i&&t.path));e.forEach((e=>function(t,e){var n,i;const r=e.path,s=null===(i=null===(n=e.type)||void 0===n?void 0:n[0])||void 0===i?void 0:i.code;if("Element"!==s&&"BackboneElement"!==s)return;const o=r.split("."),a=Xt(o);a in t.types||(t.types[a]=Ft(a,e.definition),t.types[a].parentType=Xt(o.slice(0,o.length-1)))}(t,e))),e.forEach((e=>function(t,e){const n=e.path.split(".");if(1===n.length)return;const i=Xt(n.slice(0,n.length-1)),r=t.types[i],s=n[n.length-1];r.properties[s]=e}(t,e)))}}function qt(t,e){if(e.base)for(const n of e.base){const i=t.types[n];i&&(i.searchParams||(i.searchParams={}),i.searchParams[e.code]=e)}}function Xt(t){return t.map(I).join("")}function zt(t){const e=t.path.replaceAll("[x]","").split(".").pop();return"id"===e?"ID":e.split(/(?=[A-Z])/).map(I).join(" ").replace("_"," ").replace(/\s+/g," ")}ot=new WeakMap,function(t){t.Address="Address",t.Age="Age",t.Annotation="Annotation",t.Attachment="Attachment",t.BackboneElement="BackboneElement",t.CodeableConcept="CodeableConcept",t.Coding="Coding",t.ContactDetail="ContactDetail",t.ContactPoint="ContactPoint",t.Contributor="Contributor",t.Count="Count",t.DataRequirement="DataRequirement",t.Distance="Distance",t.Dosage="Dosage",t.Duration="Duration",t.Expression="Expression",t.Extension="Extension",t.HumanName="HumanName",t.Identifier="Identifier",t.MarketingStatus="MarketingStatus",t.Meta="Meta",t.Money="Money",t.Narrative="Narrative",t.ParameterDefinition="ParameterDefinition",t.Period="Period",t.Population="Population",t.ProdCharacteristic="ProdCharacteristic",t.ProductShelfLife="ProductShelfLife",t.Quantity="Quantity",t.Range="Range",t.Ratio="Ratio",t.Reference="Reference",t.RelatedArtifact="RelatedArtifact",t.Resource="Resource",t.SampledData="SampledData",t.Signature="Signature",t.SubstanceAmount="SubstanceAmount",t.SystemString="http://hl7.org/fhirpath/System.String",t.Timing="Timing",t.TriggerDefinition="TriggerDefinition",t.UsageContext="UsageContext",t.base64Binary="base64Binary",t.boolean="boolean",t.canonical="canonical",t.code="code",t.date="date",t.dateTime="dateTime",t.decimal="decimal",t.id="id",t.instant="instant",t.integer="integer",t.markdown="markdown",t.oid="oid",t.positiveInt="positiveInt",t.string="string",t.time="time",t.unsignedInt="unsignedInt",t.uri="uri",t.url="url",t.uuid="uuid"}(at||(at={}));const Yt="launch/patient openid fhirUser offline_access user/*.*";class Vt extends class{constructor(){N.set(this,void 0),n(this,N,{},"f")}addEventListener(t,n){e(this,N,"f")[t]||(e(this,N,"f")[t]=[]),e(this,N,"f")[t].push(n)}removeEventListeneer(t,n){const i=e(this,N,"f")[t];if(i)for(let t=0;t<i.length;t++)if(i[t]===n)return void i.splice(t,1)}dispatchEvent(t){const n=e(this,N,"f")[t.type];return n&&n.forEach((e=>e.call(this,t))),!t.defaultPrevented}}{constructor(t){var i;if(super(),lt.add(this),ct.set(this,void 0),ht.set(this,void 0),ut.set(this,void 0),ft.set(this,void 0),dt.set(this,void 0),pt.set(this,void 0),vt.set(this,void 0),gt.set(this,void 0),mt.set(this,void 0),yt.set(this,void 0),wt.set(this,void 0),Tt.set(this,void 0),bt.set(this,void 0),Et.set(this,void 0),St.set(this,void 0),At.set(this,void 0),kt.set(this,void 0),null==t?void 0:t.baseUrl){if(!t.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");if(!t.baseUrl.endsWith("/"))throw new Error("Base URL must end with a trailing slash")}n(this,ct,(null==t?void 0:t.fetch)||window.fetch.bind(window),"f"),n(this,ht,null==t?void 0:t.createPdf,"f"),n(this,ut,new Bt,"f"),n(this,ft,{types:{}},"f"),n(this,dt,new a(null!==(i=null==t?void 0:t.resourceCacheSize)&&void 0!==i?i:1e3),"f"),n(this,pt,(null==t?void 0:t.baseUrl)||"https://api.medplum.com/","f"),n(this,vt,(null==t?void 0:t.clientId)||"","f"),n(this,gt,(null==t?void 0:t.authorizeUrl)||e(this,pt,"f")+"oauth2/authorize","f"),n(this,mt,(null==t?void 0:t.tokenUrl)||e(this,pt,"f")+"oauth2/token","f"),n(this,yt,(null==t?void 0:t.logoutUrl)||e(this,pt,"f")+"oauth2/logout","f"),n(this,wt,null==t?void 0:t.onUnauthenticated,"f");const r=this.getActiveLogin();r&&(n(this,Tt,r.accessToken,"f"),n(this,bt,r.refreshToken,"f"),e(this,lt,"m",Pt).call(this).catch(console.log)),e(this,lt,"m",Wt).call(this)}getBaseUrl(){return e(this,pt,"f")}clear(){e(this,ut,"f").clear(),e(this,dt,"f").clear(),n(this,Tt,void 0,"f"),n(this,bt,void 0,"f"),n(this,At,void 0,"f"),n(this,kt,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(t){t=t.toString(),e(this,dt,"f").delete(t)}invalidateSearches(t){const n="fhir/R4/"+t;for(const t of e(this,dt,"f").keys())(t.endsWith(n)||t.includes(n+"?"))&&e(this,dt,"f").delete(t)}get(t,n={}){if(t=t.toString(),!(null==n?void 0:n.cache)){const n=e(this,dt,"f").get(t);if(n)return n}const i=new Nt(e(this,lt,"m",Ot).call(this,"GET",t,n));return e(this,dt,"f").set(t,i),i}post(t,n,i,r={}){return t=t.toString(),n&&e(this,lt,"m",Ct).call(this,r,n),i&&e(this,lt,"m",Rt).call(this,r,i),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"POST",t,r)}put(t,n,i,r={}){return t=t.toString(),n&&e(this,lt,"m",Ct).call(this,r,n),i&&e(this,lt,"m",Rt).call(this,r,i),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"PUT",t,r)}patch(t,n,i={}){return t=t.toString(),e(this,lt,"m",Ct).call(this,i,n),e(this,lt,"m",Rt).call(this,i,"application/json-patch+json"),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"PATCH",t,i)}delete(t,n={}){return t=t.toString(),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"DELETE",t,n)}register(e){return t(this,void 0,void 0,(function*(){const t=yield this.post("auth/register",e);yield this.setActiveLogin(t)}))}startLogin(n){return t(this,void 0,void 0,(function*(){return yield e(this,lt,"m",Lt).call(this),this.post("auth/login",Object.assign(Object.assign({},n),{clientId:e(this,vt,"f"),scope:Yt,codeChallengeMethod:"S256",codeChallenge:e(this,ut,"f").getString("codeChallenge")}))}))}startGoogleLogin(n){return t(this,void 0,void 0,(function*(){return yield e(this,lt,"m",Lt).call(this),this.post("auth/google",n)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const t=new URLSearchParams(window.location.search).get("code");return t?this.processCode(t):void e(this,lt,"m",Dt).call(this)}signOutWithRedirect(){window.location.assign(e(this,yt,"f"))}fhirUrl(...t){return new URL(e(this,pt,"f")+"fhir/R4/"+t.join("/"))}fhirSearchUrl(t,e){const n=this.fhirUrl(t);return n.search=e.toString(),n}search(t,e,n={}){return this.get(this.fhirSearchUrl(t,e),n)}searchOne(t,n,i={}){const r=this.fhirSearchUrl(t,n);r.searchParams.set("_count","1"),r.searchParams.sort();const s=r.toString()+"-searchOne";if(!(null==i?void 0:i.cache)){const t=e(this,dt,"f").get(s);if(t)return t}const o=new Nt(this.search(t,r.searchParams,i).then((t=>{var e,n;return null===(n=null===(e=t.entry)||void 0===e?void 0:e[0])||void 0===n?void 0:n.resource})));return e(this,dt,"f").set(s,o),o}searchResources(t,n,i={}){const r=this.fhirSearchUrl(t,n).toString()+"-searchResources";if(!(null==i?void 0:i.cache)){const t=e(this,dt,"f").get(r);if(t)return t}const s=new Nt(this.search(t,n,i).then((t=>{var e,n;return null!==(n=null===(e=t.entry)||void 0===e?void 0:e.map((t=>t.resource)))&&void 0!==n?n:[]})));return e(this,dt,"f").set(r,s),s}searchValueSet(t,e,n={}){const i=this.fhirUrl("ValueSet","$expand");return i.searchParams.set("url",t),i.searchParams.set("filter",e),this.get(i.toString(),n)}getCached(t,n){const i=e(this,dt,"f").get(this.fhirUrl(t,n).toString());return i&&!i.isPending()?i.read():void 0}getCachedReference(t){const e=t.reference,[n,i]=e.split("/");return this.getCached(n,i)}readResource(t,e){return this.get(this.fhirUrl(t,e))}readReference(t){const e=null==t?void 0:t.reference;if(!e)return new Nt(Promise.reject(new Error("Missing reference")));const[n,i]=e.split("/");return this.readResource(n,i)}getSchema(){return e(this,ft,"f")}requestSchema(n){return t(this,void 0,void 0,(function*(){if(n in e(this,ft,"f").types)return Promise.resolve(e(this,ft,"f"));const t=`{\n StructureDefinitionList(name: "${n}") {\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: "${n}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),i=yield this.graphql(t);for(const t of i.data.StructureDefinitionList)Ht(e(this,ft,"f"),t);for(const t of i.data.SearchParameterList)qt(e(this,ft,"f"),t);return e(this,ft,"f")}))}readHistory(t,e){return this.get(this.fhirUrl(t,e,"_history"))}readVersion(t,e,n){return this.get(this.fhirUrl(t,e,"_history",n))}readPatientEverything(t){return this.get(this.fhirUrl("Patient",t,"$everything"))}createResource(t){if(!t.resourceType)throw new Error("Missing resourceType");return this.invalidateSearches(t.resourceType),this.post(this.fhirUrl(t.resourceType),t)}createResourceIfNoneExist(e,n){var i;return t(this,void 0,void 0,(function*(){return null!==(i=yield this.searchOne(e.resourceType,n))&&void 0!==i?i:this.createResource(e)}))}createBinary(t,e,n){const i=this.fhirUrl("Binary");return e&&i.searchParams.set("_filename",e),this.post(i,t,n)}createPdf(n,i,r,s){return t(this,void 0,void 0,(function*(){if(!e(this,ht,"f"))throw new Error("PDF creation not enabled");const t=yield e(this,ht,"f").call(this,n,r,s);return this.createBinary(t,i,"application/pdf")}))}createComment(t,e){const n=this.getProfile();let i,r;return"Encounter"===t.resourceType&&(i=f(t),r=t.subject),"ServiceRequest"===t.resourceType&&(i=t.encounter,r=t.subject),"Patient"===t.resourceType&&(r=f(t)),this.createResource({resourceType:"Communication",basedOn:[f(t)],encounter:i,subject:r,sender:n?f(n):void 0,sent:(new Date).toISOString(),payload:[{contentString:e}]})}updateResource(t){if(!t.resourceType)throw new Error("Missing resourceType");if(!t.id)throw new Error("Missing id");return this.invalidateSearches(t.resourceType),this.put(this.fhirUrl(t.resourceType,t.id),t)}patchResource(t,e,n){return this.invalidateSearches(t),this.patch(this.fhirUrl(t,e),n)}deleteResource(t,e){return this.invalidateSearches(t),this.delete(this.fhirUrl(t,e))}sendEmail(t){return this.post("email/v1/send",t,"application/json")}graphql(t,e){return this.post(this.fhirUrl("$graphql"),{query:t},"application/json",e)}getActiveLogin(){return e(this,ut,"f").getObject("activeLogin")}setActiveLogin(i){return t(this,void 0,void 0,(function*(){n(this,Tt,i.accessToken,"f"),n(this,bt,i.refreshToken,"f"),n(this,At,void 0,"f"),n(this,kt,void 0,"f"),e(this,ut,"f").setObject("activeLogin",i),e(this,lt,"m",xt).call(this,i),e(this,dt,"f").clear(),n(this,Et,void 0,"f"),yield e(this,lt,"m",Pt).call(this)}))}getAccessToken(){return e(this,Tt,"f")}setAccessToken(t){n(this,Tt,t,"f"),n(this,bt,void 0,"f"),n(this,At,void 0,"f"),n(this,kt,void 0,"f")}getLogins(){var t;return null!==(t=e(this,ut,"f").getObject("logins"))&&void 0!==t?t:[]}isLoading(){return!!e(this,St,"f")}getProfile(){return e(this,At,"f")}getProfileAsync(){return t(this,void 0,void 0,(function*(){return e(this,St,"f")&&(yield e(this,St,"f")),this.getProfile()}))}getUserConfiguration(){return e(this,kt,"f")}download(n,i={}){return t(this,void 0,void 0,(function*(){e(this,Et,"f")&&(yield e(this,Et,"f")),e(this,lt,"m",Ut).call(this,i);return(yield e(this,ct,"f").call(this,n.toString(),i)).blob()}))}processCode(t){if(!e(this,ut,"f").getString("pkceState"))throw this.clear(),new Error("Invalid PCKE state");const n=e(this,ut,"f").getString("codeVerifier");if(!n)throw this.clear(),new Error("Invalid PCKE code verifier");const i=new URLSearchParams;return i.set("grant_type","authorization_code"),i.set("client_id",e(this,vt,"f")),i.set("code_verifier",n),i.set("code",t),i.set("redirect_uri",Gt()),e(this,lt,"m",It).call(this,i)}startClientLogin(n,i){return t(this,void 0,void 0,(function*(){const t=new URLSearchParams;return t.set("grant_type","client_credentials"),t.set("client_id",n),t.set("client_secret",i),e(this,lt,"m",It).call(this,t)}))}}function Gt(){return window.location.protocol+"//"+window.location.host+"/"}function Kt(t){return[{type:at.boolean,value:t}]}function Jt(t){return Number.isSafeInteger(t)?{type:at.integer,value:t}:"number"==typeof t?{type:at.decimal,value:t}:"boolean"==typeof t?{type:at.boolean,value:t}:"string"==typeof t?{type:at.string,value:t}:ae(t)?{type:at.Quantity,value:t}:{type:at.BackboneElement,value:t}}function Zt(t){return 0!==t.length&&!!t[0].value}function te(t){const e=[];for(const n of t){let t=!1;for(const i of e)if(Zt(ie(n,i))){t=!0;break}t||e.push(n)}return e}function ee(t){return Kt(!Zt(t))}function ne(t,e){return 0===t.length||0===e.length?[]:t.length!==e.length?Kt(!1):Kt(t.every(((t,n)=>Zt(ie(t,e[n])))))}function ie(t,e){const n=t.value,i=e.value;return"number"==typeof n&&"number"==typeof i?Kt(Math.abs(n-i)<1e-8):ae(n)&&ae(i)?Kt(le(n,i)):Kt("object"==typeof n&&"object"==typeof i?ce(t,e):n===i)}function re(t,e){return 0===t.length&&0===e.length?Kt(!0):t.length!==e.length?Kt(!1):(t.sort(se),e.sort(se),Kt(t.every(((t,n)=>Zt(function(t,e){const n=t.value,i=e.value;if("number"==typeof n&&"number"==typeof i)return Kt(Math.abs(n-i)<.01);if(ae(n)&&ae(i))return Kt(le(n,i));if("object"==typeof n&&"object"==typeof i)return Kt(ce(n,i));if("string"==typeof n&&"string"==typeof i)return Kt(n.toLowerCase()===i.toLowerCase());return Kt(n===i)}(t,e[n]))))))}function se(t,e){const n=t.value,i=e.value;return"number"==typeof n&&"number"==typeof i?n-i:"string"==typeof n&&"string"==typeof i?n.localeCompare(i):0}function oe(t,e){const{value:n}=t;if(null==n)return!1;switch(e){case"Boolean":return"boolean"==typeof n;case"Decimal":case"Integer":return"number"==typeof n;case"Date":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof n&&!!n.match(/^T\d/);case"Period":return!(!(i=n)||"object"!=typeof i||!("start"in i));case"Quantity":return ae(n);default:return"object"==typeof n&&(null==n?void 0:n.resourceType)===e}var i}function ae(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function le(t,e){return Math.abs(t.value-e.value)<.01&&(t.unit===e.unit||t.code===e.code||t.unit===e.code||t.code===e.unit)}function ce(t,e){const n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!1;for(const i of n){const n=t[i],r=e[i];if(he(n)&&he(r)){if(!ce(n,r))return!1}else if(n!==r)return!1}return!0}function he(t){return null!==t&&"object"==typeof t}var ue,fe;ct=new WeakMap,ht=new WeakMap,ut=new WeakMap,ft=new WeakMap,dt=new WeakMap,pt=new WeakMap,vt=new WeakMap,gt=new WeakMap,mt=new WeakMap,yt=new WeakMap,wt=new WeakMap,Tt=new WeakMap,bt=new WeakMap,Et=new WeakMap,St=new WeakMap,At=new WeakMap,kt=new WeakMap,lt=new WeakSet,xt=function(t){const n=this.getLogins().filter((e=>{var n,i;return(null===(n=e.profile)||void 0===n?void 0:n.reference)!==(null===(i=t.profile)||void 0===i?void 0:i.reference)}));n.push(t),e(this,ut,"f").setObject("logins",n)},Pt=function(){return t(this,void 0,void 0,(function*(){return n(this,St,new Promise(((t,i)=>{this.get("auth/me").then((i=>{n(this,St,void 0,"f"),n(this,At,i.profile,"f"),n(this,kt,i.config,"f"),this.dispatchEvent({type:"change"}),t(e(this,At,"f"))})).catch(i)})),"f"),e(this,St,"f")}))},Ot=function(n,i,r={}){return t(this,void 0,void 0,(function*(){e(this,Et,"f")&&(yield e(this,Et,"f")),i.startsWith("http")||(i=e(this,pt,"f")+i),r.method=n,e(this,lt,"m",Ut).call(this,r);const t=yield e(this,ct,"f").call(this,i,r);if(401===t.status)return e(this,lt,"m",Mt).call(this,n,i,r);if(204===t.status||304===t.status)return;const s=yield t.json();return"OperationOutcome"!==(null==s?void 0:s.resourceType)||Y(s)?s:Promise.reject(s)}))},Ut=function(t){t.headers||(t.headers={});const n=t.headers;n["Content-Type"]||(n["Content-Type"]="application/fhir+json"),e(this,Tt,"f")&&(n.Authorization="Bearer "+e(this,Tt,"f")),t.cache||(t.cache="no-cache"),t.credentials||(t.credentials="include")},Rt=function(t,e){t.headers||(t.headers={});t.headers["Content-Type"]=e},Ct=function(t,e){"string"==typeof e||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Uint8Array&&e instanceof Uint8Array?t.body=e:e&&(t.body=JSON.stringify(e))},Mt=function(n,i,r){return t(this,void 0,void 0,(function*(){return e(this,lt,"m",_t).call(this).then((()=>e(this,lt,"m",Ot).call(this,n,i,r))).catch((t=>(this.clear(),e(this,wt,"f")&&e(this,wt,"f").call(this),Promise.reject(t))))}))},Lt=function(){return t(this,void 0,void 0,(function*(){const n=W();e(this,ut,"f").setString("pkceState",n);const i=W();e(this,ut,"f").setString("codeVerifier",i);const r=_(yield function(e){return t(this,void 0,void 0,(function*(){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}))}(i)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");e(this,ut,"f").setString("codeChallenge",r)}))},Dt=function(){e(this,lt,"m",Lt).call(this);const t=new URL(e(this,gt,"f"));t.searchParams.set("response_type","code"),t.searchParams.set("state",e(this,ut,"f").getString("pkceState")),t.searchParams.set("client_id",e(this,vt,"f")),t.searchParams.set("redirect_uri",Gt()),t.searchParams.set("scope",Yt),t.searchParams.set("code_challenge_method","S256"),t.searchParams.set("code_challenge",e(this,ut,"f").getString("codeChallenge")),window.location.assign(t.toString())},_t=function(){return t(this,void 0,void 0,(function*(){if(e(this,Et,"f"))return e(this,Et,"f");if(!e(this,bt,"f"))throw this.clear(),new Error("Invalid refresh token");const t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("client_id",e(this,vt,"f")),t.set("refresh_token",e(this,bt,"f")),n(this,Et,e(this,lt,"m",It).call(this,t),"f"),yield e(this,Et,"f")}))},It=function(n){return t(this,void 0,void 0,(function*(){return e(this,ct,"f").call(this,e(this,mt,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n}).then((t=>{if(!t.ok)throw new Error("Failed to fetch tokens");return t.json()})).then((t=>e(this,lt,"m",jt).call(this,t))).then((()=>this.getProfile()))}))},jt=function(n){return t(this,void 0,void 0,(function*(){const t=n.access_token,i=function(t){const[e,n,i]=t.split(".");return B(n)}(t);if(Date.now()>=1e3*i.exp)throw this.clear(),new Error("Token expired");if(e(this,vt,"f")&&i.client_id!==e(this,vt,"f"))throw this.clear(),new Error("Token was not issued for this audience");yield this.setActiveLogin({accessToken:t,refreshToken:n.refresh_token,project:n.project,profile:n.profile})}))},Wt=function(){try{window.addEventListener("storage",(t=>{null!==t.key&&"activeLogin"!==t.key||window.location.reload()}))}catch(t){}};class de{constructor(t,e){this.original=t,this.child=e}eval(t){try{return t.length>0?t.map((t=>this.child.eval([t]))).flat():this.child.eval(t)}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class pe{constructor(t){this.value=t}eval(){return[this.value]}}class ve{constructor(t){this.name=t,ue.add(this)}eval(t){return"$this"===this.name?t:t.map((t=>e(this,ue,"m",fe).call(this,t))).flat().filter((t=>void 0!==(null==t?void 0:t.value)))}}ue=new WeakSet,fe=function(t){const e=t.value;if(!e||"object"!=typeof e)return;if("resourceType"in e&&e.resourceType===this.name)return t;let n;if(this.name in e)n=e[this.name];else{const t=Object.keys(e).find((t=>t.startsWith(this.name)));t&&(n=e[t])}return void 0!==n?Array.isArray(n)?n.map(Jt):[Jt(n)]:void 0};class ge{eval(){return[]}}class me{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class ye{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class we{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t);if(1!==e.length)return[];const n=this.right.eval(t);if(1!==n.length)return[];const i=e[0].value,r=n[0].value,s=ae(i)?i.value:i,o=ae(r)?r.value:r,a=this.impl(s,o);return"boolean"==typeof a?Kt(a):ae(i)?[{type:at.Quantity,value:Object.assign(Object.assign({},i),{value:a})}]:[Jt(a)]}}class Te{constructor(t,e){this.left=t,this.right=e}eval(t){const e=[...this.left.eval(t),...this.right.eval(t)];return e.length>0&&e.every((t=>"string"==typeof t.value))?[{type:at.string,value:e.map((t=>t.value)).join("")}]:e}}class be{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Kt(e.some((t=>t.value===n[0].value)))}}class Ee{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return Kt(this.right.eval(t).some((t=>t.value===e[0].value)))}}class Se{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class Ae{constructor(t,e){this.left=t,this.right=e}eval(t){return te([...this.left.eval(t),...this.right.eval(t)])}}class ke{constructor(t,e){this.left=t,this.right=e}eval(t){return ne(this.left.eval(t),this.right.eval(t))}}class xe{constructor(t,e){this.left=t,this.right=e}eval(t){return ee(ne(this.left.eval(t),this.right.eval(t)))}}class Pe{constructor(t,e){this.left=t,this.right=e}eval(t){return re(this.left.eval(t),this.right.eval(t))}}class Oe{constructor(t,e){this.left=t,this.right=e}eval(t){return ee(re(this.left.eval(t),this.right.eval(t)))}}class Ue{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(1!==e.length)return[];const n=this.right.name;return Kt(oe(e[0],n))}}class Re{constructor(t,e){this.left=t,this.right=e}eval(t){var e,n,i,r;const s=this.left.eval(t),o=this.right.eval(t);return!0===(null===(e=s[0])||void 0===e?void 0:e.value)&&!0===(null===(n=o[0])||void 0===n?void 0:n.value)?Kt(!0):!1===(null===(i=s[0])||void 0===i?void 0:i.value)||!1===(null===(r=o[0])||void 0===r?void 0:r.value)?Kt(!1):[]}}class Ce{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(Zt(e))return e;const n=this.right.eval(t);return Zt(n)?n:[]}}class Me{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);if(0===e.length&&0===n.length)return[];const i=0===e.length?null:e[0].value,r=0===n.length?null:n[0].value;return!0===i&&!0!==r||!0!==i&&!0===r?Kt(!0):!0===i&&!0===r||!1===i&&!1===r?Kt(!1):[]}}class Le{constructor(t,e,n){this.name=t,this.args=e,this.impl=n}eval(t){return this.impl(t,...this.args)}}class De{constructor(t,e){this.left=t,this.expr=e}eval(t){const e=this.expr.eval(t);if(1!==e.length)return[];const n=e[0].value;if("number"!=typeof n)throw new Error("Invalid indexer expression: should return integer}");const i=this.left.eval(t);return n in i?[i[n]]:[]}}function _e(t){if(t.startsWith("T"))return t+"T00:00:00.000Z".substring(t.length);if(t.length<=10)return t;try{return new Date(t).toISOString()}catch(e){return t}}const Ie=()=>[],je={empty:t=>Kt(0===t.length),exists:(t,e)=>Kt(e?t.filter((t=>Zt(e.eval([t])))).length>0:t.length>0),all:(t,e)=>Kt(t.every((t=>Zt(e.eval([t]))))),allTrue:t=>{for(const e of t)if(!e.value)return Kt(!1);return Kt(!0)},anyTrue:t=>{for(const e of t)if(e.value)return Kt(!0);return Kt(!1)},allFalse:t=>{for(const e of t)if(e.value)return Kt(!1);return Kt(!0)},anyFalse:t=>{for(const e of t)if(!e.value)return Kt(!0);return Kt(!1)},subsetOf:Ie,supersetOf:Ie,count:t=>[{type:at.integer,value:t.length}],distinct:t=>{const e=[];for(const n of t)e.some((t=>t.value===n.value))||e.push(n);return e},isDistinct:t=>Kt(t.length===je.distinct(t).length),where:(t,e)=>t.filter((t=>Zt(e.eval([t])))),select:(t,e)=>t.map((t=>e.eval([t]))).flat(),repeat:Ie,ofType:Ie,single:t=>{if(t.length>1)throw new Error("Expected input length one for single()");return 0===t.length?[]:t.slice(0,1)},first:t=>0===t.length?[]:t.slice(0,1),last:t=>0===t.length?[]:t.slice(t.length-1,t.length),tail:t=>0===t.length?[]:t.slice(1,t.length),skip:(t,e)=>{var n;const i=null===(n=e.eval([])[0])||void 0===n?void 0:n.value;if("number"!=typeof i)throw new Error("Expected a number for skip(num)");return i>=t.length?[]:i<=0?t:t.slice(i,t.length)},take:(t,e)=>{var n;const i=null===(n=e.eval([])[0])||void 0===n?void 0:n.value;if("number"!=typeof i)throw new Error("Expected a number for take(num)");return i>=t.length?t:i<=0?[]:t.slice(0,i)},intersect:(t,e)=>{if(!e)return t;const n=e.eval([]),i=[];for(const e of t)!i.some((t=>t.value===e.value))&&n.some((t=>t.value===e.value))&&i.push(e);return i},exclude:(t,e)=>{if(!e)return t;const n=e.eval([]),i=[];for(const e of t)n.some((t=>t.value===e.value))||i.push(e);return i},union:(t,e)=>{if(!e)return t;const n=e.eval([]);return te([...t,...n])},combine:(t,e)=>{if(!e)return t;const n=e.eval([]);return[...t,...n]},iif:(t,e,n,i)=>{const r=e.eval(t);if(r.length>1||1===r.length&&"boolean"!=typeof r[0].value)throw new Error("Expected criterion to evaluate to a Boolean");return Zt(r)?n.eval(t):i?i.eval(t):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);if("boolean"==typeof e)return[{type:at.boolean,value:e}];if("number"==typeof e&&(0===e||1===e))return Kt(!!e);if("string"==typeof e){const t=e.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return Kt(!0);if(["false","f","no","n","0","0.0"].includes(t))return Kt(!1)}return[]},convertsToBoolean:t=>0===t.length?[]:Kt(1===je.toBoolean(t).length),toInteger:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"number"==typeof e?[{type:at.integer,value:e}]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[{type:at.integer,value:parseInt(e,10)}]:"boolean"==typeof e?[{type:at.integer,value:e?1:0}]:[]},convertsToInteger:t=>0===t.length?[]:Kt(1===je.toInteger(t).length),toDate:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:at.date,value:_e(e)}]:[]},convertsToDate:t=>0===t.length?[]:Kt(1===je.toDate(t).length),toDateTime:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:at.dateTime,value:_e(e)}]:[]},convertsToDateTime:t=>0===t.length?[]:Kt(1===je.toDateTime(t).length),toDecimal:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"number"==typeof e?[{type:at.decimal,value:e}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:at.decimal,value:parseFloat(e)}]:"boolean"==typeof e?[{type:at.decimal,value:e?1:0}]:[]},convertsToDecimal:t=>0===t.length?[]:Kt(1===je.toDecimal(t).length),toQuantity:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return ae(e)?[{type:at.Quantity,value:e}]:"number"==typeof e?[{type:at.Quantity,value:{value:e,unit:"1"}}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:at.Quantity,value:{value:parseFloat(e),unit:"1"}}]:"boolean"==typeof e?[{type:at.Quantity,value:{value:e?1:0,unit:"1"}}]:[]},convertsToQuantity:t=>0===t.length?[]:Kt(1===je.toQuantity(t).length),toString:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return null==e?[]:ae(e)?[{type:at.string,value:`${e.value} '${e.unit}'`}]:[{type:at.string,value:e.toString()}]},convertsToString:t=>0===t.length?[]:Kt(1===je.toString(t).length),toTime:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[{type:at.time,value:_e("T"+t[1])}]}return[]},convertsToTime:t=>0===t.length?[]:Kt(1===je.toTime(t).length),indexOf:(t,e)=>We(((t,e)=>t.indexOf(e)),t,e),substring:(t,e,n)=>We(((t,e,n)=>{const i=e,r=n?i+n:t.length;return i<0||i>=t.length?void 0:t.substring(i,r)}),t,e,n),startsWith:(t,e)=>We(((t,e)=>t.startsWith(e)),t,e),endsWith:(t,e)=>We(((t,e)=>t.endsWith(e)),t,e),contains:(t,e)=>We(((t,e)=>t.includes(e)),t,e),upper:t=>We((t=>t.toUpperCase()),t),lower:t=>We((t=>t.toLowerCase()),t),replace:(t,e,n)=>We(((t,e,n)=>t.replaceAll(e,n)),t,e,n),matches:(t,e)=>We(((t,e)=>!!t.match(e)),t,e),replaceMatches:(t,e,n)=>We(((t,e,n)=>t.replaceAll(e,n)),t,e,n),length:t=>We((t=>t.length),t),toChars:t=>We((t=>t?t.split(""):void 0),t),abs:t=>Ne(Math.abs,t),ceiling:t=>Ne(Math.ceil,t),exp:t=>Ne(Math.exp,t),floor:t=>Ne(Math.floor,t),ln:t=>Ne(Math.log,t),log:(t,e)=>Ne(((t,e)=>Math.log(t)/Math.log(e)),t,e),power:(t,e)=>Ne(Math.pow,t,e),round:t=>Ne(Math.round,t),sqrt:t=>Ne(Math.sqrt,t),truncate:t=>Ne((t=>0|t),t),children:Ie,descendants:Ie,trace:(t,e)=>(console.log("trace",t,e),t),now:()=>[{type:at.dateTime,value:(new Date).toISOString()}],timeOfDay:()=>[{type:at.time,value:(new Date).toISOString().substring(11)}],today:()=>[{type:at.date,value:(new Date).toISOString().substring(0,10)}],between:(t,e,n,i)=>{const r=je.toDateTime(e.eval(t));if(0===r.length)throw new Error("Invalid start date");const s=je.toDateTime(n.eval(t));if(0===s.length)throw new Error("Invalid end date");const o=i.eval(t)[0].value;if("years"!==o&&"months"!==o&&"days"!==o)throw new Error("Invalid units");const a=T(r[0].value,s[0].value);return[{type:at.Quantity,value:{value:a[o],unit:o}}]},is:(t,e)=>{let n="";return e instanceof ve?n=e.name:e instanceof Se&&(n=e.left.name+"."+e.right.name),n?t.map((t=>({type:at.boolean,value:oe(t,n)}))):[]},not:t=>je.toBoolean(t).map((t=>({type:at.boolean,value:!t.value}))),resolve:t=>t.map((t=>{const e=t.value;let n;if("string"==typeof e)n=e;else if("object"==typeof e){const t=e;if(t.resource)return{type:at.BackboneElement,value:t.resource};n=t.reference}if(!n)return{type:at.BackboneElement,value:null};const[i,r]=n.split("/");return{type:at.BackboneElement,value:{resourceType:i,id:r}}})).filter((t=>!!t.value)),as:t=>t,type:t=>t.map((({value:t})=>"boolean"==typeof t?{type:at.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof t?{type:at.BackboneElement,value:{namespace:"System",name:"Integer"}}:t&&"object"==typeof t&&"resourceType"in t?{type:at.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:at.BackboneElement,value:null})),conformsTo:(t,e)=>{const n=e.eval([])[0].value;if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const i=n.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>{var e;return{type:at.boolean,value:(null===(e=t.value)||void 0===e?void 0:e.resourceType)===i}}))}};function We(t,e,...n){if(0===e.length)return[];const[{value:i}]=Be(e,1);if("string"!=typeof i)throw new Error("String function cannot be called with non-string");const r=t(i,...n.map((t=>{var n,i;return t&&(null===(i=null===(n=t.eval(e))||void 0===n?void 0:n[0])||void 0===i?void 0:i.value)})));return void 0===r?[]:Array.isArray(r)?r.map(Jt):[Jt(r)]}function Ne(t,e,...n){if(0===e.length)return[];const[{value:i}]=Be(e,1),r=ae(i),s=r?i.value:i;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...n.map((t=>{var e,n;return null===(n=null===(e=t.eval([]))||void 0===e?void 0:e[0])||void 0===n?void 0:n.value})));return[{type:r?at.Quantity:e[0].type,value:r?Object.assign(Object.assign({},i),{value:o}):o}]}function Be(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);for(const e of t)if(null==e)throw new Error("Expected non-null argument");return t}var Qe,$e,Fe,He,qe,Xe,ze,Ye,Ve,Ge,Ke,Je,Ze,tn,en,nn,rn,sn;function on(t){return new cn(t).tokenize()}const an=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],ln=["!=","!~","<=",">=","{}"];class cn{constructor(t){Qe.add(this),$e.set(this,void 0),Fe.set(this,void 0),n(this,$e,t,"f"),n(this,Fe,0,"f")}tokenize(){const t=[];for(;e(this,Fe,"f")<e(this,$e,"f").length;){const n=e(this,Qe,"m",qe).call(this);n&&t.push(n)}return t}}function hn(t,e){return{id:t,value:e}}var un,fn,dn,pn,vn,gn,mn,yn,wn;$e=new WeakMap,Fe=new WeakMap,Qe=new WeakSet,He=function(){const t=e(this,Fe,"f"),i=e(this,Qe,"m",qe).call(this);return n(this,Fe,t,"f"),i},qe=function(){e(this,Qe,"m",Xe).call(this);const t=e(this,Qe,"m",nn).call(this);if(!t)return;const n=e(this,Qe,"m",sn).call(this);return"/"===t&&"*"===n?e(this,Qe,"m",ze).call(this):"/"===t&&"/"===n?e(this,Qe,"m",Ye).call(this):"'"===t?e(this,Qe,"m",Ve).call(this):"`"===t?e(this,Qe,"m",Ge).call(this):"@"===t?e(this,Qe,"m",Ke).call(this):t.match(/\d/)?e(this,Qe,"m",Je).call(this):t.match(/\w/)||"$"===t&&n.match(/\w/)?e(this,Qe,"m",Ze).call(this):e(this,Qe,"m",tn).call(this)},Xe=function(){return hn("Whitespace",e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/\s/))))},ze=function(){const t=e(this,Fe,"f");return e(this,Qe,"m",en).call(this,(()=>"*"!==e(this,Qe,"m",nn).call(this)||"/"!==e(this,Qe,"m",sn).call(this))),n(this,Fe,e(this,Fe,"f")+2,"f"),hn("Comment",e(this,$e,"f").substring(t,e(this,Fe,"f")))},Ye=function(){return hn("Comment",e(this,Qe,"m",en).call(this,(()=>"\n"!==e(this,Qe,"m",nn).call(this))))},Ve=function(){var t,i;n(this,Fe,(t=e(this,Fe,"f"),++t),"f");const r=hn("String",e(this,Qe,"m",en).call(this,(()=>"\\"===e(this,Qe,"m",rn).call(this)||"'"!==e(this,Qe,"m",nn).call(this))));return n(this,Fe,(i=e(this,Fe,"f"),++i),"f"),r},Ge=function(){var t,i;n(this,Fe,(t=e(this,Fe,"f"),++t),"f");const r=hn("Symbol",e(this,Qe,"m",en).call(this,(()=>"`"!==e(this,Qe,"m",nn).call(this))));return n(this,Fe,(i=e(this,Fe,"f"),++i),"f"),r},Ke=function(){var t,i,r,s,o;const a=e(this,Fe,"f");return n(this,Fe,(t=e(this,Fe,"f"),++t),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d-]/))),"T"===e(this,Qe,"m",nn).call(this)&&(n(this,Fe,(i=e(this,Fe,"f"),++i),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d:]/))),"."===e(this,Qe,"m",nn).call(this)&&e(this,Qe,"m",sn).call(this).match(/\d/)&&(n(this,Fe,(r=e(this,Fe,"f"),++r),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d]/)))),"Z"===e(this,Qe,"m",nn).call(this)?n(this,Fe,(s=e(this,Fe,"f"),++s),"f"):"+"!==e(this,Qe,"m",nn).call(this)&&"-"!==e(this,Qe,"m",nn).call(this)||(n(this,Fe,(o=e(this,Fe,"f"),++o),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d:]/))))),hn("DateTime",e(this,$e,"f").substring(a+1,e(this,Fe,"f")))},Je=function(){var t;const i=e(this,Fe,"f");let r="Number";return e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/\d/))),"."===e(this,Qe,"m",nn).call(this)&&e(this,Qe,"m",sn).call(this).match(/\d/)&&(n(this,Fe,(t=e(this,Fe,"f"),++t),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/\d/))))," "===e(this,Qe,"m",nn).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&an.includes(t.value))return!0}return!1}(e(this,Qe,"m",He).call(this))&&(r="Quantity",e(this,Qe,"m",qe).call(this)),hn(r,e(this,$e,"f").substring(i,e(this,Fe,"f")))},Ze=function(){return hn("Symbol",e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[$\w]/))))},tn=function(){var t;const i=e(this,Qe,"m",nn).call(this),r=i+e(this,Qe,"m",sn).call(this);return ln.includes(r)?(n(this,Fe,e(this,Fe,"f")+2,"f"),hn(r,r)):(n(this,Fe,(t=e(this,Fe,"f"),++t),"f"),hn(i,i))},en=function(t){var i;const r=e(this,Fe,"f");for(;e(this,Fe,"f")<e(this,$e,"f").length&&t();)n(this,Fe,(i=e(this,Fe,"f"),++i),"f");return e(this,$e,"f").substring(r,e(this,Fe,"f"))},nn=function(){return e(this,$e,"f")[e(this,Fe,"f")]},rn=function(){var t;return null!==(t=e(this,$e,"f")[e(this,Fe,"f")-1])&&void 0!==t?t:""},sn=function(){var t;return null!==(t=e(this,$e,"f")[e(this,Fe,"f")+1])&&void 0!==t?t:""};un=new WeakMap,fn=new WeakMap;class Tn{constructor(t,e,i){dn.add(this),pn.set(this,void 0),vn.set(this,void 0),gn.set(this,void 0),n(this,pn,t,"f"),n(this,vn,e,"f"),n(this,gn,i,"f")}match(t){const n=e(this,dn,"m",wn).call(this);return(null==n?void 0:n.id)===t&&(e(this,dn,"m",yn).call(this),!0)}consumeAndParse(t=100){const n=e(this,dn,"m",yn).call(this),i=e(this,vn,"f")[n.id];if(!i)throw Error(`Parse error at ${n.value}. No matching prefix parselet.`);let r=i.parse(this,n);for(;t>e(this,dn,"m",mn).call(this);){const t=e(this,dn,"m",yn).call(this);r=e(this,gn,"f")[t.id].parse(this,r,t)}return r}}pn=new WeakMap,vn=new WeakMap,gn=new WeakMap,dn=new WeakSet,mn=function(){const t=e(this,dn,"m",wn).call(this);if(!t)return 100;const n=e(this,gn,"f")[t.id];return n?n.precedence:100},yn=function(){if(!e(this,pn,"f").length)throw Error("Cant consume unknown more tokens.");return e(this,pn,"f").shift()},wn=function(){return e(this,pn,"f").length>0?e(this,pn,"f")[0]:void 0};const bn={parse(t){const e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},En={parse(t,e){const n=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new De(e,n)},precedence:2},Sn={parse(t,e){if(!(e instanceof ve))throw new Error("Unexpected parentheses");if(!(e.name in je))throw new Error("Unrecognized function: "+e.name);const n=[];for(;!t.match(")");)n.push(t.consumeAndParse()),t.match(",");return new Le(e.name,n,je[e.name])},precedence:0};function An(t){const e=t.split(" "),n=parseFloat(e[0]);let i=e[1];return i=i&&i.startsWith("'")&&i.endsWith("'")?i.substring(1,i.length-1):"{"+i+"}",{value:n,unit:i}}const kn=(new class{constructor(){un.set(this,{}),fn.set(this,{})}registerInfix(t,n){return e(this,fn,"f")[t]=n,this}registerPrefix(t,n){return e(this,un,"f")[t]=n,this}prefix(t,e,n){return this.registerPrefix(t,{parse(t,i){const r=t.consumeAndParse(e);return n(i,r)}})}infixLeft(t,e,n){return this.registerInfix(t,{parse(t,i,r){const s=t.consumeAndParse(e);return n(i,r,s)},precedence:e})}construct(t){return new Tn(on(t),e(this,un,"f"),e(this,fn,"f"))}}).registerPrefix("String",{parse:(t,e)=>new pe({type:at.string,value:e.value})}).registerPrefix("DateTime",{parse:(t,e)=>new pe({type:at.dateTime,value:_e(e.value)})}).registerPrefix("Quantity",{parse:(t,e)=>new pe({type:at.Quantity,value:An(e.value)})}).registerPrefix("Number",{parse:(t,e)=>new pe({type:at.decimal,value:parseFloat(e.value)})}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new pe({type:at.boolean,value:!1}):"true"===e.value?new pe({type:at.boolean,value:!0}):new ve(e.value)}).registerPrefix("{}",{parse:()=>new ge}).registerPrefix("(",bn).registerInfix("[",En).registerInfix("(",Sn).prefix("+",3,((t,e)=>new me(e,(t=>t)))).prefix("-",3,((t,e)=>new we(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,n)=>new Se(t,n))).infixLeft("/",4,((t,e,n)=>new we(t,n,((t,e)=>t/e)))).infixLeft("*",4,((t,e,n)=>new we(t,n,((t,e)=>t*e)))).infixLeft("+",5,((t,e,n)=>new we(t,n,((t,e)=>t+e)))).infixLeft("-",5,((t,e,n)=>new we(t,n,((t,e)=>t-e)))).infixLeft("|",7,((t,e,n)=>new Ae(t,n))).infixLeft("=",9,((t,e,n)=>new ke(t,n))).infixLeft("!=",9,((t,e,n)=>new xe(t,n))).infixLeft("~",9,((t,e,n)=>new Pe(t,n))).infixLeft("!~",9,((t,e,n)=>new Oe(t,n))).infixLeft("<",8,((t,e,n)=>new we(t,n,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,n)=>new we(t,n,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,n)=>new we(t,n,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,n)=>new we(t,n,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,n)=>new Te(t,n))).infixLeft("Symbol",6,((t,e,n)=>{switch(e.value){case"and":return new Re(t,n);case"as":return new ye(t,n);case"contains":return new be(t,n);case"div":return new we(t,n,((t,e)=>t/e|0));case"in":return new Ee(t,n);case"is":return new Ue(t,n);case"mod":return new we(t,n,((t,e)=>t%e));case"or":return new Ce(t,n);case"xor":return new Me(t,n);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function xn(t){try{return new de(t,kn.construct(t).consumeAndParse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}function Pn(t,e){Array.isArray(e)||(e=[e]);const n=Array.isArray(e)?e:[e];for(let t=0;t<n.length;t++){const e=n[t];"object"==typeof e&&"type"in e&&"value"in e||(n[t]={type:at.BackboneElement,value:e})}return xn(t).eval(n).map((t=>t.value))}const On="\r",Un="|",Rn="^";class Cn{constructor(t){this.segments=t}get(t){return"number"==typeof t?this.segments[t]:this.segments.find((e=>e.name===t))}getAll(t){return this.segments.filter((e=>e.name===t))}toString(){return this.segments.map((t=>t.toString())).join("\r")}buildAck(){var t,e,n,i,r,s;const o=new Date,a=this.get("MSH"),l=(null===(t=null==a?void 0:a.get(2))||void 0===t?void 0:t.toString())||"",c=(null===(e=null==a?void 0:a.get(3))||void 0===e?void 0:e.toString())||"",h=(null===(n=null==a?void 0:a.get(4))||void 0===n?void 0:n.toString())||"",u=(null===(i=null==a?void 0:a.get(5))||void 0===i?void 0:i.toString())||"",f=(null===(r=null==a?void 0:a.get(9))||void 0===r?void 0:r.toString())||"",d=(null===(s=null==a?void 0:a.get(12))||void 0===s?void 0:s.toString())||"2.5.1";return new Cn([new Mn(["MSH","^~\\&",h,u,l,c,o.toISOString(),"","ACK",o.getTime().toString(),"P",d]),new Mn(["MSA","AA",f,"OK"])])}static parse(t){if(!t.startsWith("MSH|^~\\&")){const t=new Error("Invalid HL7 message");throw t.type="entity.parse.failed",t}return new Cn(t.split(/[\r\n]+/).map((t=>Mn.parse(t))))}}class Mn{constructor(t){M(t)?this.fields=t.map((t=>Ln.parse(t))):this.fields=t,this.name=this.fields[0].components[0]}get(t){return this.fields[t]}toString(){return this.fields.map((t=>t.toString())).join("|")}static parse(t){return new Mn(t.split("|").map((t=>Ln.parse(t))))}}class Ln{constructor(t){this.components=t}get(t){return this.components[t]}toString(){return this.components.join("^")}static parse(t){return new Ln(t.split("^"))}}const Dn=20;var _n;!function(t){t.EQUALS="eq",t.NOT_EQUALS="ne",t.GREATER_THAN="gt",t.LESS_THAN="lt",t.GREATER_THAN_OR_EQUALS="ge",t.LESS_THAN_OR_EQUALS="le",t.STARTS_AFTER="sa",t.ENDS_BEFORE="eb",t.APPROXIMATELY="ap",t.CONTAINS="contains",t.EXACT="exact",t.TEXT="text",t.ABOVE="above",t.BELOW="below",t.IN="in",t.NOT_IN="not-in",t.OF_TYPE="of-type"}(_n||(_n={}));const In=[_n.CONTAINS,_n.EXACT,_n.TEXT,_n.ABOVE,_n.BELOW,_n.IN,_n.NOT_IN,_n.OF_TYPE],jn=[_n.NOT_EQUALS,_n.GREATER_THAN,_n.LESS_THAN,_n.GREATER_THAN_OR_EQUALS,_n.LESS_THAN_OR_EQUALS,_n.STARTS_AFTER,_n.ENDS_BEFORE,_n.APPROXIMATELY];function Wn(t){const e=new URL(t,"https://example.com/"),n=e.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let i,r,s,o,a,l;return new URLSearchParams(e.search).forEach(((t,e)=>{"_fields"===e?s=t.split(","):"_offset"===e?o=parseInt(t):"_count"===e?a=parseInt(t):"_total"===e?l=t:"_sort"===e?(r=r||[],r.push(function(t){return t.startsWith("-")?{code:t.substring(1),descending:!0}:{code:t}}(t))):(i=i||[],i.push(function(t,e){let n=t,i=_n.EQUALS;for(const t of In){const e=n.indexOf(":"+t);-1!==e&&(i=t,n=n.substring(0,e))}for(const t of jn)e.match(new RegExp("^"+t+"\\d"))&&(i=t,e=e.substring(t.length));return{code:n,operator:i,value:e}}(e,t)))})),{resourceType:n,filters:i,fields:s,offset:o,count:a,total:l,sortRules:r}}function Nn(t){const e=[];return t.fields&&e.push("_fields="+t.fields.join(",")),t.filters&&t.filters.forEach((t=>e.push(function(t){const e=In.includes(t.operator)?":"+t.operator:"",n=jn.includes(t.operator)?t.operator:"";return`${t.code}${e}=${n}${encodeURIComponent(t.value)}`}(t)))),t.sortRules&&t.sortRules.length>0&&e.push(function(t){if(!t||0===t.length)return"";return"_sort="+t.map((t=>t.descending?"-"+t.code:t.code)).join(",")}(t.sortRules)),void 0!==t.offset&&e.push("_offset="+t.offset),void 0!==t.count&&e.push("_count="+t.count),void 0!==t.total&&e.push("_total="+t.total),0===e.length?"":(e.sort(),"?"+e.join("&"))}var Bn;function Qn(t,e,n){var i,r,s,o;if("_lastUpdated"===n.code)return{columnName:"lastUpdated",type:Bn.DATETIME};const a=n.code.split("-").reduce(((t,e,n)=>t+(n?I(e):e)),"");const l=null===(i=$n(e,n.expression))||void 0===i?void 0:i.split(".");if(!l)return{columnName:a,type:Bn.TEXT};let c,h,u=e,f=!1;for(let e=1;e<l.length;e++){const n=l[e];if(c=null===(s=null===(r=t.types[u])||void 0===r?void 0:r.properties)||void 0===s?void 0:s[n],!c)return{columnName:a,type:Bn.TEXT,array:f};if("*"===c.max&&(f=!0),h=null===(o=c.type)||void 0===o?void 0:o[0].code,!h)return{columnName:a,type:Bn.TEXT,array:f};e<l.length-1&&("Element"===h||"BackboneElement"===h?u+=I(n):u=h)}const d=function(t,e){let n=Bn.TEXT;switch(t.type){case"date":n=e===at.dateTime||e===at.instant?Bn.DATETIME:Bn.DATE;break;case"number":n=Bn.NUMBER;break;case"quantity":n=Bn.QUANTITY;break;case"reference":n=Bn.REFERENCE;break;case"token":"boolean"===e&&(n=Bn.BOOLEAN)}return n}(n,h);return{columnName:a,type:d,elementDefinition:c,array:f}}function $n(t,e){const n=e.split(" | ");for(const e of n){const n=Fn(e);if(n.startsWith(t+"."))return n}}function Fn(t){let e=t.trim();return e.startsWith("(")&&e.endsWith(")")&&(e=e.substring(1,e.length-1)),e.includes(" as ")&&(e=e.substring(0,e.indexOf(" as "))),e.includes(".where(")&&(e=e.substring(0,e.indexOf(".where("))),e}!function(t){t.BOOLEAN="BOOLEAN",t.NUMBER="NUMBER",t.QUANTITY="QUANTITY",t.TEXT="TEXT",t.REFERENCE="REFERENCE",t.DATE="DATE",t.DATETIME="DATETIME",t.PERIOD="PERIOD"}(Bn||(Bn={}));export{Rn as COMPONENT_SEPARATOR,Dn as DEFAULT_SEARCH_COUNT,Un as FIELD_SEPARATOR,Ln as Hl7Field,Cn as Hl7Message,Mn as Hl7Segment,a as LRUCache,Vt as MedplumClient,Z as OperationOutcomeError,_n as Operator,at as PropertyType,Nt as ReadablePromise,On as SEGMENT_SEPARATOR,Bn as SearchParameterType,X as accessDenied,Q as allOk,_ as arrayBufferToBase64,D as arrayBufferToHex,J as assertOk,z as badRequest,Xt as buildTypeName,T as calculateAge,b as calculateAgeString,I as capitalize,f as createReference,$t as createSchema,Ft as createTypeSchema,$ as created,U as deepEquals,Pn as evalFhirPath,l as formatAddress,u as formatFamilyName,h as formatGivenName,c as formatHumanName,Nn as formatSearchQuery,w as getDateProperty,g as getDisplayString,$n as getExpressionForResourceType,k as getExtensionValue,A as getIdentifier,m as getImageSrc,zt as getPropertyDisplayName,E as getQuestionnaireAnswers,d as getReferenceString,Qn as getSearchParameterDetails,K as getStatus,q as gone,qt as indexSearchParameter,Ht as indexStructureDefinition,G as isGone,j as isLowerCase,V as isNotFound,C as isObject,Y as isOk,v as isProfileResource,M as isStringArray,R as isUUID,H as notFound,F as notModified,xn as parseFhirPath,Wn as parseSearchDefinition,p as resolveId,x as stringify,on as tokenize};
|
|
1
|
+
function t(t,e,n,i){return new(n||(n=Promise))((function(r,s){function o(t){try{l(i.next(t))}catch(t){s(t)}}function a(t){try{l(i.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))}function e(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function n(t,e,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(t,n):r?r.value=n:e.set(t,n),n}var i,r,s,o;class a{constructor(t=10){i.add(this),r.set(this,void 0),s.set(this,void 0),n(this,r,t,"f"),n(this,s,new Map,"f")}clear(){e(this,s,"f").clear()}get(t){const n=e(this,s,"f").get(t);return n&&(e(this,s,"f").delete(t),e(this,s,"f").set(t,n)),n}set(t,n){e(this,s,"f").has(t)?e(this,s,"f").delete(t):e(this,s,"f").size>=e(this,r,"f")&&e(this,s,"f").delete(e(this,i,"m",o).call(this)),e(this,s,"f").set(t,n)}delete(t){e(this,s,"f").delete(t)}keys(){return e(this,s,"f").keys()}}function l(t,e){const n=[];return t.line&&n.push(...t.line),t.city&&n.push(t.city),t.state&&n.push(t.state),t.postalCode&&n.push(t.postalCode),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&n.push("["+t.use+"]"),n.join(", ").trim()}function c(t,e){const n=[];return t.prefix&&((null==e?void 0:e.all)||(null==e?void 0:e.prefix))&&n.push(...t.prefix),t.given&&n.push(...t.given),t.family&&n.push(t.family),t.suffix&&((null==e?void 0:e.all)||(null==e?void 0:e.suffix))&&n.push(...t.suffix),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&n.push("["+t.use+"]"),n.join(" ").trim()}function h(t){const e=[];return t.given&&e.push(...t.given),e.join(" ").trim()}function u(t){return t.family||""}function f(t){const e=d(t),n=g(t);return n===e?{reference:e}:{reference:e,display:n}}function d(t){return t.resourceType+"/"+t.id}function p(t){var e;return null===(e=null==t?void 0:t.reference)||void 0===e?void 0:e.split("/")[1]}function v(t){return"Patient"===t.resourceType||"Practitioner"===t.resourceType||"RelatedPerson"===t.resourceType}function g(t){var e,n;if(v(t)){const e=function(t){const e=t.name;if(e&&e.length>0)return c(e[0]);return}(t);if(e)return e}if("Device"===t.resourceType){const e=function(t){const e=t.deviceName;if(e&&e.length>0)return e[0].name;return}(t);if(e)return e}return"Observation"===t.resourceType&&"code"in t&&(null===(e=t.code)||void 0===e?void 0:e.text)?null===(n=t.code)||void 0===n?void 0:n.text:"User"===t.resourceType&&t.email?t.email:"name"in t&&t.name&&"string"==typeof t.name?t.name:d(t)}function m(t){if(v(t)){const e=t.photo;if(e)for(const t of e){const e=y(t);if(e)return e}}if("Bot"===t.resourceType&&t.photo){const e=y(t.photo);if(e)return e}}function y(t){if(t.url&&t.contentType&&t.contentType.startsWith("image/"))return t.url}function w(t){return t?new Date(t):void 0}function T(t,e){const n=new Date(t);n.setUTCHours(0,0,0,0);const i=e?new Date(e):new Date;i.setUTCHours(0,0,0,0);const r=n.getUTCFullYear(),s=n.getUTCMonth(),o=n.getUTCDate(),a=i.getUTCFullYear(),l=i.getUTCMonth(),c=i.getUTCDate();let h=a-r;(l<s||l===s&&c<o)&&h--;let u=12*a+l-(12*r+s);c<o&&u--;return{years:h,months:u,days:Math.floor((i.getTime()-n.getTime())/864e5)}}function b(t,e){const{years:n,months:i,days:r}=T(t,e);return n>=2?n.toString().padStart(3,"0")+"Y":i>=1?i.toString().padStart(3,"0")+"M":r.toString().padStart(3,"0")+"D"}function E(t){const e={};return S(t.item,e),e}function S(t,e){if(t)for(const n of t)n.linkId&&n.answer&&n.answer.length>0&&(e[n.linkId]=n.answer[0]),S(n.item,e)}function A(t,e){const n=t.identifier;if(!n)return;const i=Array.isArray(n)?n:[n];for(const t of i)if(t.system===e)return t.value}function k(t,...e){var n;let i=t;for(let t=0;t<e.length&&i;t++)i=null===(n=null==i?void 0:i.extension)||void 0===n?void 0:n.find((n=>n.url===e[t]));return null==i?void 0:i.valueString}function x(t,e){return JSON.stringify(t,P,e?2:void 0)}function P(t,e){return!function(t){return!!t.match(/\d+$/)}(t)&&O(e)?void 0:e}function O(t){if(null==t)return!0;const e=typeof t;return"string"===e&&""===t||"object"===e&&0===Object.keys(t).length}function U(t,e,n){return t===e||(!(!O(t)||!O(e))||!O(t)&&!O(e)&&(Array.isArray(t)&&Array.isArray(e)?function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!U(t[n],e[n]))return!1;return!0}(t,e):!Array.isArray(t)&&!Array.isArray(e)&&(C(t)&&C(e)?function(t,e,n){const i=new Set;Object.keys(t).forEach((t=>i.add(t))),Object.keys(e).forEach((t=>i.add(t))),"meta"===n&&(i.delete("versionId"),i.delete("lastUpdated"),i.delete("author"));for(const n of i){if(!U(t[n],e[n],n))return!1}return!0}(t,e,n):(C(t)||C(e),!1))))}function R(t){return!!t.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)}function C(t){return null!==t&&"object"==typeof t}function M(t){return t.every((t=>"string"==typeof t))}r=new WeakMap,s=new WeakMap,i=new WeakSet,o=function(){return e(this,s,"f").keys().next().value};const L=[];for(let t=0;t<256;t++)L.push(t.toString(16).padStart(2,"0"));function D(t){const e=new Uint8Array(t),n=new Array(e.length);for(let t=0;t<e.length;t++)n[t]=L[e[t]];return n.join("")}function _(t){const e=new Uint8Array(t),n=[];for(let t=0;t<e.length;t++)n[t]=String.fromCharCode(e[t]);return window.btoa(n.join(""))}function I(t){return t.charAt(0).toUpperCase()+t.substring(1)}function j(t){return t===t.toLowerCase()}function W(){const t=new Uint32Array(28);return crypto.getRandomValues(t),D(t.buffer)}var N;function B(t){const e=function(t){if("undefined"!=typeof window)return window.atob(t);if("undefined"!=typeof Buffer)return Buffer.from(t,"base64").toString("binary");throw new Error("Unable to decode base64")}(t.replace(/-/g,"+").replace(/_/g,"/")),n=Array.from(e).reduce(((t,e)=>`${t}%${("00"+e.charCodeAt(0).toString(16)).slice(-2)}`),""),i=decodeURIComponent(n);return JSON.parse(i)}N=new WeakMap;const Q={resourceType:"OperationOutcome",id:"ok",issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},$={resourceType:"OperationOutcome",id:"created",issue:[{severity:"information",code:"information",details:{text:"Created"}}]},F={resourceType:"OperationOutcome",id:"not-modified",issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},H={resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},q={resourceType:"OperationOutcome",id:"gone",issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},X={resourceType:"OperationOutcome",id:"access-denied",issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function z(t,e){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:t},expression:e?[e]:void 0}]}}function Y(t){return"ok"===t.id||"created"===t.id||"not-modified"===t.id}function V(t){return"not-found"===t.id}function G(t){return"gone"===t.id}function K(t){return"ok"===t.id?200:"created"===t.id?201:"not-modified"===t.id?304:"access-denied"===t.id?403:"not-found"===t.id?404:"gone"===t.id?410:400}function J(t,e){if(!Y(t)||void 0===e)throw new Z(t)}class Z extends Error{constructor(t){var e,n;super(null===(n=null===(e=null==t?void 0:t.issue)||void 0===e?void 0:e[0].details)||void 0===n?void 0:n.text),this.outcome=t}}var tt,et,nt,it,rt,st,ot,at,lt,ct,ht,ut,ft,dt,pt,vt,gt,mt,yt,wt,Tt,bt,Et,St,At,kt,xt,Pt,Ot,Ut,Rt,Ct,Mt,Lt,Dt,_t,It,jt,Wt;class Nt{constructor(t){this[rt]="ReadablePromise",tt.set(this,void 0),et.set(this,"pending"),nt.set(this,void 0),it.set(this,void 0),n(this,tt,t.then((t=>(n(this,et,"success","f"),n(this,nt,t,"f"),t)),(t=>{throw n(this,et,"error","f"),n(this,it,t,"f"),t})),"f")}isPending(){return"pending"===e(this,et,"f")}read(){switch(e(this,et,"f")){case"pending":throw e(this,tt,"f");case"error":throw e(this,it,"f");default:return e(this,nt,"f")}}then(t,n){return e(this,tt,"f").then(t,n)}catch(t){return e(this,tt,"f").catch(t)}finally(t){return e(this,tt,"f").finally(t)}}tt=new WeakMap,et=new WeakMap,nt=new WeakMap,it=new WeakMap,rt=Symbol.toStringTag;class Bt{constructor(){st.set(this,void 0),n(this,st,"undefined"!=typeof localStorage?localStorage:new Qt,"f")}clear(){e(this,st,"f").clear()}getString(t){return e(this,st,"f").getItem(t)||void 0}setString(t,n){n?e(this,st,"f").setItem(t,n):e(this,st,"f").removeItem(t)}getObject(t){const e=this.getString(t);return e?JSON.parse(e):void 0}setObject(t,e){this.setString(t,e?x(e):void 0)}}st=new WeakMap;class Qt{constructor(){ot.set(this,void 0),n(this,ot,new Map,"f")}get length(){return e(this,ot,"f").size}clear(){e(this,ot,"f").clear()}getItem(t){var n;return null!==(n=e(this,ot,"f").get(t))&&void 0!==n?n:null}setItem(t,n){n?e(this,ot,"f").set(t,n):e(this,ot,"f").delete(t)}removeItem(t){e(this,ot,"f").delete(t)}key(t){return Array.from(e(this,ot,"f").keys())[t]}}function $t(){return{types:{}}}function Ft(t,e){return{display:t,description:e,properties:{},searchParams:{_lastUpdated:{base:[t],code:"_lastUpdated",type:"date",expression:t+".meta.lastUpdated"}}}}function Ht(t,e){var n;const i=e.name;if(!i)return;t.types[i]=Ft(i,e.description);const r=null===(n=e.snapshot)||void 0===n?void 0:n.element;if(r){const e=r.filter((t=>t.path!==i&&t.path));e.forEach((e=>function(t,e){var n,i;const r=e.path,s=null===(i=null===(n=e.type)||void 0===n?void 0:n[0])||void 0===i?void 0:i.code;if("Element"!==s&&"BackboneElement"!==s)return;const o=r.split("."),a=Xt(o);a in t.types||(t.types[a]=Ft(a,e.definition),t.types[a].parentType=Xt(o.slice(0,o.length-1)))}(t,e))),e.forEach((e=>function(t,e){const n=e.path.split(".");if(1===n.length)return;const i=Xt(n.slice(0,n.length-1)),r=t.types[i],s=n[n.length-1];r.properties[s]=e}(t,e)))}}function qt(t,e){if(e.base)for(const n of e.base){const i=t.types[n];i&&(i.searchParams||(i.searchParams={}),i.searchParams[e.code]=e)}}function Xt(t){return t.map(I).join("")}function zt(t){const e=t.path.replaceAll("[x]","").split(".").pop();return"id"===e?"ID":e.split(/(?=[A-Z])/).map(I).join(" ").replace("_"," ").replace(/\s+/g," ")}ot=new WeakMap,function(t){t.Address="Address",t.Age="Age",t.Annotation="Annotation",t.Attachment="Attachment",t.BackboneElement="BackboneElement",t.CodeableConcept="CodeableConcept",t.Coding="Coding",t.ContactDetail="ContactDetail",t.ContactPoint="ContactPoint",t.Contributor="Contributor",t.Count="Count",t.DataRequirement="DataRequirement",t.Distance="Distance",t.Dosage="Dosage",t.Duration="Duration",t.Expression="Expression",t.Extension="Extension",t.HumanName="HumanName",t.Identifier="Identifier",t.MarketingStatus="MarketingStatus",t.Meta="Meta",t.Money="Money",t.Narrative="Narrative",t.ParameterDefinition="ParameterDefinition",t.Period="Period",t.Population="Population",t.ProdCharacteristic="ProdCharacteristic",t.ProductShelfLife="ProductShelfLife",t.Quantity="Quantity",t.Range="Range",t.Ratio="Ratio",t.Reference="Reference",t.RelatedArtifact="RelatedArtifact",t.Resource="Resource",t.SampledData="SampledData",t.Signature="Signature",t.SubstanceAmount="SubstanceAmount",t.SystemString="http://hl7.org/fhirpath/System.String",t.Timing="Timing",t.TriggerDefinition="TriggerDefinition",t.UsageContext="UsageContext",t.base64Binary="base64Binary",t.boolean="boolean",t.canonical="canonical",t.code="code",t.date="date",t.dateTime="dateTime",t.decimal="decimal",t.id="id",t.instant="instant",t.integer="integer",t.markdown="markdown",t.oid="oid",t.positiveInt="positiveInt",t.string="string",t.time="time",t.unsignedInt="unsignedInt",t.uri="uri",t.url="url",t.uuid="uuid"}(at||(at={}));const Yt="launch/patient openid fhirUser offline_access user/*.*";class Vt extends class{constructor(){N.set(this,void 0),n(this,N,{},"f")}addEventListener(t,n){e(this,N,"f")[t]||(e(this,N,"f")[t]=[]),e(this,N,"f")[t].push(n)}removeEventListeneer(t,n){const i=e(this,N,"f")[t];if(i)for(let t=0;t<i.length;t++)if(i[t]===n)return void i.splice(t,1)}dispatchEvent(t){const n=e(this,N,"f")[t.type];return n&&n.forEach((e=>e.call(this,t))),!t.defaultPrevented}}{constructor(t){var i;if(super(),lt.add(this),ct.set(this,void 0),ht.set(this,void 0),ut.set(this,void 0),ft.set(this,void 0),dt.set(this,void 0),pt.set(this,void 0),vt.set(this,void 0),gt.set(this,void 0),mt.set(this,void 0),yt.set(this,void 0),wt.set(this,void 0),Tt.set(this,void 0),bt.set(this,void 0),Et.set(this,void 0),St.set(this,void 0),At.set(this,void 0),kt.set(this,void 0),null==t?void 0:t.baseUrl){if(!t.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");if(!t.baseUrl.endsWith("/"))throw new Error("Base URL must end with a trailing slash")}n(this,ct,(null==t?void 0:t.fetch)||window.fetch.bind(window),"f"),n(this,ht,null==t?void 0:t.createPdf,"f"),n(this,ut,new Bt,"f"),n(this,ft,{types:{}},"f"),n(this,dt,new a(null!==(i=null==t?void 0:t.resourceCacheSize)&&void 0!==i?i:1e3),"f"),n(this,pt,(null==t?void 0:t.baseUrl)||"https://api.medplum.com/","f"),n(this,vt,(null==t?void 0:t.clientId)||"","f"),n(this,gt,(null==t?void 0:t.authorizeUrl)||e(this,pt,"f")+"oauth2/authorize","f"),n(this,mt,(null==t?void 0:t.tokenUrl)||e(this,pt,"f")+"oauth2/token","f"),n(this,yt,(null==t?void 0:t.logoutUrl)||e(this,pt,"f")+"oauth2/logout","f"),n(this,wt,null==t?void 0:t.onUnauthenticated,"f");const r=this.getActiveLogin();r&&(n(this,Tt,r.accessToken,"f"),n(this,bt,r.refreshToken,"f"),e(this,lt,"m",Pt).call(this).catch(console.log)),e(this,lt,"m",Wt).call(this)}getBaseUrl(){return e(this,pt,"f")}clear(){e(this,ut,"f").clear(),e(this,dt,"f").clear(),n(this,Tt,void 0,"f"),n(this,bt,void 0,"f"),n(this,At,void 0,"f"),n(this,kt,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(t){t=t.toString(),e(this,dt,"f").delete(t)}invalidateSearches(t){const n="fhir/R4/"+t;for(const t of e(this,dt,"f").keys())(t.endsWith(n)||t.includes(n+"?"))&&e(this,dt,"f").delete(t)}get(t,n={}){if(t=t.toString(),!(null==n?void 0:n.cache)){const n=e(this,dt,"f").get(t);if(n)return n}const i=new Nt(e(this,lt,"m",Ot).call(this,"GET",t,n));return e(this,dt,"f").set(t,i),i}post(t,n,i,r={}){return t=t.toString(),n&&e(this,lt,"m",Ct).call(this,r,n),i&&e(this,lt,"m",Rt).call(this,r,i),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"POST",t,r)}put(t,n,i,r={}){return t=t.toString(),n&&e(this,lt,"m",Ct).call(this,r,n),i&&e(this,lt,"m",Rt).call(this,r,i),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"PUT",t,r)}patch(t,n,i={}){return t=t.toString(),e(this,lt,"m",Ct).call(this,i,n),e(this,lt,"m",Rt).call(this,i,"application/json-patch+json"),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"PATCH",t,i)}delete(t,n={}){return t=t.toString(),this.invalidateUrl(t),e(this,lt,"m",Ot).call(this,"DELETE",t,n)}register(e){return t(this,void 0,void 0,(function*(){const t=yield this.post("auth/register",e);yield this.setActiveLogin(t)}))}startLogin(n){return t(this,void 0,void 0,(function*(){return yield e(this,lt,"m",Lt).call(this),this.post("auth/login",Object.assign(Object.assign({},n),{clientId:e(this,vt,"f"),scope:Yt,codeChallengeMethod:"S256",codeChallenge:e(this,ut,"f").getString("codeChallenge")}))}))}startGoogleLogin(n){return t(this,void 0,void 0,(function*(){return yield e(this,lt,"m",Lt).call(this),this.post("auth/google",n)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const t=new URLSearchParams(window.location.search).get("code");return t?this.processCode(t):void e(this,lt,"m",Dt).call(this)}signOutWithRedirect(){window.location.assign(e(this,yt,"f"))}fhirUrl(...t){return new URL(e(this,pt,"f")+"fhir/R4/"+t.join("/"))}fhirSearchUrl(t,e){const n=this.fhirUrl(t);return e&&(n.search=e.toString()),n}search(t,e,n={}){return this.get(this.fhirSearchUrl(t,e),n)}searchOne(t,n,i={}){const r=this.fhirSearchUrl(t,n);r.searchParams.set("_count","1"),r.searchParams.sort();const s=r.toString()+"-searchOne";if(!(null==i?void 0:i.cache)){const t=e(this,dt,"f").get(s);if(t)return t}const o=new Nt(this.search(t,r.searchParams,i).then((t=>{var e,n;return null===(n=null===(e=t.entry)||void 0===e?void 0:e[0])||void 0===n?void 0:n.resource})));return e(this,dt,"f").set(s,o),o}searchResources(t,n,i={}){const r=this.fhirSearchUrl(t,n).toString()+"-searchResources";if(!(null==i?void 0:i.cache)){const t=e(this,dt,"f").get(r);if(t)return t}const s=new Nt(this.search(t,n,i).then((t=>{var e,n;return null!==(n=null===(e=t.entry)||void 0===e?void 0:e.map((t=>t.resource)))&&void 0!==n?n:[]})));return e(this,dt,"f").set(r,s),s}searchValueSet(t,e,n={}){const i=this.fhirUrl("ValueSet","$expand");return i.searchParams.set("url",t),i.searchParams.set("filter",e),this.get(i.toString(),n)}getCached(t,n){const i=e(this,dt,"f").get(this.fhirUrl(t,n).toString());return i&&!i.isPending()?i.read():void 0}getCachedReference(t){const e=t.reference,[n,i]=e.split("/");return this.getCached(n,i)}readResource(t,e){return this.get(this.fhirUrl(t,e))}readReference(t){const e=null==t?void 0:t.reference;if(!e)return new Nt(Promise.reject(new Error("Missing reference")));const[n,i]=e.split("/");return this.readResource(n,i)}getSchema(){return e(this,ft,"f")}requestSchema(n){return t(this,void 0,void 0,(function*(){if(n in e(this,ft,"f").types)return Promise.resolve(e(this,ft,"f"));const t=`{\n StructureDefinitionList(name: "${n}") {\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: "${n}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),i=yield this.graphql(t);for(const t of i.data.StructureDefinitionList)Ht(e(this,ft,"f"),t);for(const t of i.data.SearchParameterList)qt(e(this,ft,"f"),t);return e(this,ft,"f")}))}readHistory(t,e){return this.get(this.fhirUrl(t,e,"_history"))}readVersion(t,e,n){return this.get(this.fhirUrl(t,e,"_history",n))}readPatientEverything(t){return this.get(this.fhirUrl("Patient",t,"$everything"))}createResource(t){if(!t.resourceType)throw new Error("Missing resourceType");return this.invalidateSearches(t.resourceType),this.post(this.fhirUrl(t.resourceType),t)}createResourceIfNoneExist(e,n){var i;return t(this,void 0,void 0,(function*(){return null!==(i=yield this.searchOne(e.resourceType,n))&&void 0!==i?i:this.createResource(e)}))}createBinary(t,e,n){const i=this.fhirUrl("Binary");return e&&i.searchParams.set("_filename",e),this.post(i,t,n)}createPdf(n,i,r,s){return t(this,void 0,void 0,(function*(){if(!e(this,ht,"f"))throw new Error("PDF creation not enabled");const t=yield e(this,ht,"f").call(this,n,r,s);return this.createBinary(t,i,"application/pdf")}))}createComment(t,e){const n=this.getProfile();let i,r;return"Encounter"===t.resourceType&&(i=f(t),r=t.subject),"ServiceRequest"===t.resourceType&&(i=t.encounter,r=t.subject),"Patient"===t.resourceType&&(r=f(t)),this.createResource({resourceType:"Communication",basedOn:[f(t)],encounter:i,subject:r,sender:n?f(n):void 0,sent:(new Date).toISOString(),payload:[{contentString:e}]})}updateResource(t){if(!t.resourceType)throw new Error("Missing resourceType");if(!t.id)throw new Error("Missing id");return this.invalidateSearches(t.resourceType),this.put(this.fhirUrl(t.resourceType,t.id),t)}patchResource(t,e,n){return this.invalidateSearches(t),this.patch(this.fhirUrl(t,e),n)}deleteResource(t,e){return this.invalidateSearches(t),this.delete(this.fhirUrl(t,e))}sendEmail(t){return this.post("email/v1/send",t,"application/json")}graphql(t,e){return this.post(this.fhirUrl("$graphql"),{query:t},"application/json",e)}getActiveLogin(){return e(this,ut,"f").getObject("activeLogin")}setActiveLogin(i){return t(this,void 0,void 0,(function*(){n(this,Tt,i.accessToken,"f"),n(this,bt,i.refreshToken,"f"),n(this,At,void 0,"f"),n(this,kt,void 0,"f"),e(this,ut,"f").setObject("activeLogin",i),e(this,lt,"m",xt).call(this,i),e(this,dt,"f").clear(),n(this,Et,void 0,"f"),yield e(this,lt,"m",Pt).call(this)}))}getAccessToken(){return e(this,Tt,"f")}setAccessToken(t){n(this,Tt,t,"f"),n(this,bt,void 0,"f"),n(this,At,void 0,"f"),n(this,kt,void 0,"f")}getLogins(){var t;return null!==(t=e(this,ut,"f").getObject("logins"))&&void 0!==t?t:[]}isLoading(){return!!e(this,St,"f")}getProfile(){return e(this,At,"f")}getProfileAsync(){return t(this,void 0,void 0,(function*(){return e(this,St,"f")&&(yield e(this,St,"f")),this.getProfile()}))}getUserConfiguration(){return e(this,kt,"f")}download(n,i={}){return t(this,void 0,void 0,(function*(){e(this,Et,"f")&&(yield e(this,Et,"f")),e(this,lt,"m",Ut).call(this,i);return(yield e(this,ct,"f").call(this,n.toString(),i)).blob()}))}processCode(t){if(!e(this,ut,"f").getString("pkceState"))throw this.clear(),new Error("Invalid PCKE state");const n=e(this,ut,"f").getString("codeVerifier");if(!n)throw this.clear(),new Error("Invalid PCKE code verifier");const i=new URLSearchParams;return i.set("grant_type","authorization_code"),i.set("client_id",e(this,vt,"f")),i.set("code_verifier",n),i.set("code",t),i.set("redirect_uri",Gt()),e(this,lt,"m",It).call(this,i)}startClientLogin(n,i){return t(this,void 0,void 0,(function*(){const t=new URLSearchParams;return t.set("grant_type","client_credentials"),t.set("client_id",n),t.set("client_secret",i),e(this,lt,"m",It).call(this,t)}))}}function Gt(){return window.location.protocol+"//"+window.location.host+"/"}function Kt(t){return[{type:at.boolean,value:t}]}function Jt(t){return Number.isSafeInteger(t)?{type:at.integer,value:t}:"number"==typeof t?{type:at.decimal,value:t}:"boolean"==typeof t?{type:at.boolean,value:t}:"string"==typeof t?{type:at.string,value:t}:ae(t)?{type:at.Quantity,value:t}:{type:at.BackboneElement,value:t}}function Zt(t){return 0!==t.length&&!!t[0].value}function te(t){const e=[];for(const n of t){let t=!1;for(const i of e)if(Zt(ie(n,i))){t=!0;break}t||e.push(n)}return e}function ee(t){return Kt(!Zt(t))}function ne(t,e){return 0===t.length||0===e.length?[]:t.length!==e.length?Kt(!1):Kt(t.every(((t,n)=>Zt(ie(t,e[n])))))}function ie(t,e){const n=t.value,i=e.value;return"number"==typeof n&&"number"==typeof i?Kt(Math.abs(n-i)<1e-8):ae(n)&&ae(i)?Kt(le(n,i)):Kt("object"==typeof n&&"object"==typeof i?ce(t,e):n===i)}function re(t,e){return 0===t.length&&0===e.length?Kt(!0):t.length!==e.length?Kt(!1):(t.sort(se),e.sort(se),Kt(t.every(((t,n)=>Zt(function(t,e){const n=t.value,i=e.value;if("number"==typeof n&&"number"==typeof i)return Kt(Math.abs(n-i)<.01);if(ae(n)&&ae(i))return Kt(le(n,i));if("object"==typeof n&&"object"==typeof i)return Kt(ce(n,i));if("string"==typeof n&&"string"==typeof i)return Kt(n.toLowerCase()===i.toLowerCase());return Kt(n===i)}(t,e[n]))))))}function se(t,e){const n=t.value,i=e.value;return"number"==typeof n&&"number"==typeof i?n-i:"string"==typeof n&&"string"==typeof i?n.localeCompare(i):0}function oe(t,e){const{value:n}=t;if(null==n)return!1;switch(e){case"Boolean":return"boolean"==typeof n;case"Decimal":case"Integer":return"number"==typeof n;case"Date":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof n&&!!n.match(/^T\d/);case"Period":return!(!(i=n)||"object"!=typeof i||!("start"in i));case"Quantity":return ae(n);default:return"object"==typeof n&&(null==n?void 0:n.resourceType)===e}var i}function ae(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function le(t,e){return Math.abs(t.value-e.value)<.01&&(t.unit===e.unit||t.code===e.code||t.unit===e.code||t.code===e.unit)}function ce(t,e){const n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!1;for(const i of n){const n=t[i],r=e[i];if(he(n)&&he(r)){if(!ce(n,r))return!1}else if(n!==r)return!1}return!0}function he(t){return null!==t&&"object"==typeof t}var ue,fe;ct=new WeakMap,ht=new WeakMap,ut=new WeakMap,ft=new WeakMap,dt=new WeakMap,pt=new WeakMap,vt=new WeakMap,gt=new WeakMap,mt=new WeakMap,yt=new WeakMap,wt=new WeakMap,Tt=new WeakMap,bt=new WeakMap,Et=new WeakMap,St=new WeakMap,At=new WeakMap,kt=new WeakMap,lt=new WeakSet,xt=function(t){const n=this.getLogins().filter((e=>{var n,i;return(null===(n=e.profile)||void 0===n?void 0:n.reference)!==(null===(i=t.profile)||void 0===i?void 0:i.reference)}));n.push(t),e(this,ut,"f").setObject("logins",n)},Pt=function(){return t(this,void 0,void 0,(function*(){return n(this,St,new Promise(((t,i)=>{this.get("auth/me").then((i=>{n(this,St,void 0,"f"),n(this,At,i.profile,"f"),n(this,kt,i.config,"f"),this.dispatchEvent({type:"change"}),t(e(this,At,"f"))})).catch(i)})),"f"),e(this,St,"f")}))},Ot=function(n,i,r={}){return t(this,void 0,void 0,(function*(){e(this,Et,"f")&&(yield e(this,Et,"f")),i.startsWith("http")||(i=e(this,pt,"f")+i),r.method=n,e(this,lt,"m",Ut).call(this,r);const t=yield e(this,ct,"f").call(this,i,r);if(401===t.status)return e(this,lt,"m",Mt).call(this,n,i,r);if(204===t.status||304===t.status)return;const s=yield t.json();return"OperationOutcome"!==(null==s?void 0:s.resourceType)||Y(s)?s:Promise.reject(s)}))},Ut=function(t){t.headers||(t.headers={});const n=t.headers;n["Content-Type"]||(n["Content-Type"]="application/fhir+json"),e(this,Tt,"f")&&(n.Authorization="Bearer "+e(this,Tt,"f")),t.cache||(t.cache="no-cache"),t.credentials||(t.credentials="include")},Rt=function(t,e){t.headers||(t.headers={});t.headers["Content-Type"]=e},Ct=function(t,e){"string"==typeof e||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Uint8Array&&e instanceof Uint8Array?t.body=e:e&&(t.body=JSON.stringify(e))},Mt=function(n,i,r){return t(this,void 0,void 0,(function*(){return e(this,lt,"m",_t).call(this).then((()=>e(this,lt,"m",Ot).call(this,n,i,r))).catch((t=>(this.clear(),e(this,wt,"f")&&e(this,wt,"f").call(this),Promise.reject(t))))}))},Lt=function(){return t(this,void 0,void 0,(function*(){const n=W();e(this,ut,"f").setString("pkceState",n);const i=W();e(this,ut,"f").setString("codeVerifier",i);const r=_(yield function(e){return t(this,void 0,void 0,(function*(){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}))}(i)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");e(this,ut,"f").setString("codeChallenge",r)}))},Dt=function(){e(this,lt,"m",Lt).call(this);const t=new URL(e(this,gt,"f"));t.searchParams.set("response_type","code"),t.searchParams.set("state",e(this,ut,"f").getString("pkceState")),t.searchParams.set("client_id",e(this,vt,"f")),t.searchParams.set("redirect_uri",Gt()),t.searchParams.set("scope",Yt),t.searchParams.set("code_challenge_method","S256"),t.searchParams.set("code_challenge",e(this,ut,"f").getString("codeChallenge")),window.location.assign(t.toString())},_t=function(){return t(this,void 0,void 0,(function*(){if(e(this,Et,"f"))return e(this,Et,"f");if(!e(this,bt,"f"))throw this.clear(),new Error("Invalid refresh token");const t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("client_id",e(this,vt,"f")),t.set("refresh_token",e(this,bt,"f")),n(this,Et,e(this,lt,"m",It).call(this,t),"f"),yield e(this,Et,"f")}))},It=function(n){return t(this,void 0,void 0,(function*(){return e(this,ct,"f").call(this,e(this,mt,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n}).then((t=>{if(!t.ok)throw new Error("Failed to fetch tokens");return t.json()})).then((t=>e(this,lt,"m",jt).call(this,t))).then((()=>this.getProfile()))}))},jt=function(n){return t(this,void 0,void 0,(function*(){const t=n.access_token,i=function(t){const[e,n,i]=t.split(".");return B(n)}(t);if(Date.now()>=1e3*i.exp)throw this.clear(),new Error("Token expired");if(e(this,vt,"f")&&i.client_id!==e(this,vt,"f"))throw this.clear(),new Error("Token was not issued for this audience");yield this.setActiveLogin({accessToken:t,refreshToken:n.refresh_token,project:n.project,profile:n.profile})}))},Wt=function(){try{window.addEventListener("storage",(t=>{null!==t.key&&"activeLogin"!==t.key||window.location.reload()}))}catch(t){}};class de{constructor(t,e){this.original=t,this.child=e}eval(t){try{return t.length>0?t.map((t=>this.child.eval([t]))).flat():this.child.eval(t)}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class pe{constructor(t){this.value=t}eval(){return[this.value]}}class ve{constructor(t){this.name=t,ue.add(this)}eval(t){return"$this"===this.name?t:t.map((t=>e(this,ue,"m",fe).call(this,t))).flat().filter((t=>void 0!==(null==t?void 0:t.value)))}}ue=new WeakSet,fe=function(t){const e=t.value;if(!e||"object"!=typeof e)return;if("resourceType"in e&&e.resourceType===this.name)return t;let n;if(this.name in e)n=e[this.name];else{const t=Object.keys(e).find((t=>t.startsWith(this.name)));t&&(n=e[t])}return void 0!==n?Array.isArray(n)?n.map(Jt):[Jt(n)]:void 0};class ge{eval(){return[]}}class me{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class ye{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class we{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t);if(1!==e.length)return[];const n=this.right.eval(t);if(1!==n.length)return[];const i=e[0].value,r=n[0].value,s=ae(i)?i.value:i,o=ae(r)?r.value:r,a=this.impl(s,o);return"boolean"==typeof a?Kt(a):ae(i)?[{type:at.Quantity,value:Object.assign(Object.assign({},i),{value:a})}]:[Jt(a)]}}class Te{constructor(t,e){this.left=t,this.right=e}eval(t){const e=[...this.left.eval(t),...this.right.eval(t)];return e.length>0&&e.every((t=>"string"==typeof t.value))?[{type:at.string,value:e.map((t=>t.value)).join("")}]:e}}class be{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Kt(e.some((t=>t.value===n[0].value)))}}class Ee{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return Kt(this.right.eval(t).some((t=>t.value===e[0].value)))}}class Se{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class Ae{constructor(t,e){this.left=t,this.right=e}eval(t){return te([...this.left.eval(t),...this.right.eval(t)])}}class ke{constructor(t,e){this.left=t,this.right=e}eval(t){return ne(this.left.eval(t),this.right.eval(t))}}class xe{constructor(t,e){this.left=t,this.right=e}eval(t){return ee(ne(this.left.eval(t),this.right.eval(t)))}}class Pe{constructor(t,e){this.left=t,this.right=e}eval(t){return re(this.left.eval(t),this.right.eval(t))}}class Oe{constructor(t,e){this.left=t,this.right=e}eval(t){return ee(re(this.left.eval(t),this.right.eval(t)))}}class Ue{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(1!==e.length)return[];const n=this.right.name;return Kt(oe(e[0],n))}}class Re{constructor(t,e){this.left=t,this.right=e}eval(t){var e,n,i,r;const s=this.left.eval(t),o=this.right.eval(t);return!0===(null===(e=s[0])||void 0===e?void 0:e.value)&&!0===(null===(n=o[0])||void 0===n?void 0:n.value)?Kt(!0):!1===(null===(i=s[0])||void 0===i?void 0:i.value)||!1===(null===(r=o[0])||void 0===r?void 0:r.value)?Kt(!1):[]}}class Ce{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(Zt(e))return e;const n=this.right.eval(t);return Zt(n)?n:[]}}class Me{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);if(0===e.length&&0===n.length)return[];const i=0===e.length?null:e[0].value,r=0===n.length?null:n[0].value;return!0===i&&!0!==r||!0!==i&&!0===r?Kt(!0):!0===i&&!0===r||!1===i&&!1===r?Kt(!1):[]}}class Le{constructor(t,e,n){this.name=t,this.args=e,this.impl=n}eval(t){return this.impl(t,...this.args)}}class De{constructor(t,e){this.left=t,this.expr=e}eval(t){const e=this.expr.eval(t);if(1!==e.length)return[];const n=e[0].value;if("number"!=typeof n)throw new Error("Invalid indexer expression: should return integer}");const i=this.left.eval(t);return n in i?[i[n]]:[]}}function _e(t){if(t.startsWith("T"))return t+"T00:00:00.000Z".substring(t.length);if(t.length<=10)return t;try{return new Date(t).toISOString()}catch(e){return t}}const Ie=()=>[],je={empty:t=>Kt(0===t.length),exists:(t,e)=>Kt(e?t.filter((t=>Zt(e.eval([t])))).length>0:t.length>0),all:(t,e)=>Kt(t.every((t=>Zt(e.eval([t]))))),allTrue:t=>{for(const e of t)if(!e.value)return Kt(!1);return Kt(!0)},anyTrue:t=>{for(const e of t)if(e.value)return Kt(!0);return Kt(!1)},allFalse:t=>{for(const e of t)if(e.value)return Kt(!1);return Kt(!0)},anyFalse:t=>{for(const e of t)if(!e.value)return Kt(!0);return Kt(!1)},subsetOf:Ie,supersetOf:Ie,count:t=>[{type:at.integer,value:t.length}],distinct:t=>{const e=[];for(const n of t)e.some((t=>t.value===n.value))||e.push(n);return e},isDistinct:t=>Kt(t.length===je.distinct(t).length),where:(t,e)=>t.filter((t=>Zt(e.eval([t])))),select:(t,e)=>t.map((t=>e.eval([t]))).flat(),repeat:Ie,ofType:Ie,single:t=>{if(t.length>1)throw new Error("Expected input length one for single()");return 0===t.length?[]:t.slice(0,1)},first:t=>0===t.length?[]:t.slice(0,1),last:t=>0===t.length?[]:t.slice(t.length-1,t.length),tail:t=>0===t.length?[]:t.slice(1,t.length),skip:(t,e)=>{var n;const i=null===(n=e.eval([])[0])||void 0===n?void 0:n.value;if("number"!=typeof i)throw new Error("Expected a number for skip(num)");return i>=t.length?[]:i<=0?t:t.slice(i,t.length)},take:(t,e)=>{var n;const i=null===(n=e.eval([])[0])||void 0===n?void 0:n.value;if("number"!=typeof i)throw new Error("Expected a number for take(num)");return i>=t.length?t:i<=0?[]:t.slice(0,i)},intersect:(t,e)=>{if(!e)return t;const n=e.eval([]),i=[];for(const e of t)!i.some((t=>t.value===e.value))&&n.some((t=>t.value===e.value))&&i.push(e);return i},exclude:(t,e)=>{if(!e)return t;const n=e.eval([]),i=[];for(const e of t)n.some((t=>t.value===e.value))||i.push(e);return i},union:(t,e)=>{if(!e)return t;const n=e.eval([]);return te([...t,...n])},combine:(t,e)=>{if(!e)return t;const n=e.eval([]);return[...t,...n]},iif:(t,e,n,i)=>{const r=e.eval(t);if(r.length>1||1===r.length&&"boolean"!=typeof r[0].value)throw new Error("Expected criterion to evaluate to a Boolean");return Zt(r)?n.eval(t):i?i.eval(t):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);if("boolean"==typeof e)return[{type:at.boolean,value:e}];if("number"==typeof e&&(0===e||1===e))return Kt(!!e);if("string"==typeof e){const t=e.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return Kt(!0);if(["false","f","no","n","0","0.0"].includes(t))return Kt(!1)}return[]},convertsToBoolean:t=>0===t.length?[]:Kt(1===je.toBoolean(t).length),toInteger:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"number"==typeof e?[{type:at.integer,value:e}]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[{type:at.integer,value:parseInt(e,10)}]:"boolean"==typeof e?[{type:at.integer,value:e?1:0}]:[]},convertsToInteger:t=>0===t.length?[]:Kt(1===je.toInteger(t).length),toDate:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:at.date,value:_e(e)}]:[]},convertsToDate:t=>0===t.length?[]:Kt(1===je.toDate(t).length),toDateTime:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:at.dateTime,value:_e(e)}]:[]},convertsToDateTime:t=>0===t.length?[]:Kt(1===je.toDateTime(t).length),toDecimal:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return"number"==typeof e?[{type:at.decimal,value:e}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:at.decimal,value:parseFloat(e)}]:"boolean"==typeof e?[{type:at.decimal,value:e?1:0}]:[]},convertsToDecimal:t=>0===t.length?[]:Kt(1===je.toDecimal(t).length),toQuantity:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return ae(e)?[{type:at.Quantity,value:e}]:"number"==typeof e?[{type:at.Quantity,value:{value:e,unit:"1"}}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:at.Quantity,value:{value:parseFloat(e),unit:"1"}}]:"boolean"==typeof e?[{type:at.Quantity,value:{value:e?1:0,unit:"1"}}]:[]},convertsToQuantity:t=>0===t.length?[]:Kt(1===je.toQuantity(t).length),toString:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);return null==e?[]:ae(e)?[{type:at.string,value:`${e.value} '${e.unit}'`}]:[{type:at.string,value:e.toString()}]},convertsToString:t=>0===t.length?[]:Kt(1===je.toString(t).length),toTime:t=>{if(0===t.length)return[];const[{value:e}]=Be(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[{type:at.time,value:_e("T"+t[1])}]}return[]},convertsToTime:t=>0===t.length?[]:Kt(1===je.toTime(t).length),indexOf:(t,e)=>We(((t,e)=>t.indexOf(e)),t,e),substring:(t,e,n)=>We(((t,e,n)=>{const i=e,r=n?i+n:t.length;return i<0||i>=t.length?void 0:t.substring(i,r)}),t,e,n),startsWith:(t,e)=>We(((t,e)=>t.startsWith(e)),t,e),endsWith:(t,e)=>We(((t,e)=>t.endsWith(e)),t,e),contains:(t,e)=>We(((t,e)=>t.includes(e)),t,e),upper:t=>We((t=>t.toUpperCase()),t),lower:t=>We((t=>t.toLowerCase()),t),replace:(t,e,n)=>We(((t,e,n)=>t.replaceAll(e,n)),t,e,n),matches:(t,e)=>We(((t,e)=>!!t.match(e)),t,e),replaceMatches:(t,e,n)=>We(((t,e,n)=>t.replaceAll(e,n)),t,e,n),length:t=>We((t=>t.length),t),toChars:t=>We((t=>t?t.split(""):void 0),t),abs:t=>Ne(Math.abs,t),ceiling:t=>Ne(Math.ceil,t),exp:t=>Ne(Math.exp,t),floor:t=>Ne(Math.floor,t),ln:t=>Ne(Math.log,t),log:(t,e)=>Ne(((t,e)=>Math.log(t)/Math.log(e)),t,e),power:(t,e)=>Ne(Math.pow,t,e),round:t=>Ne(Math.round,t),sqrt:t=>Ne(Math.sqrt,t),truncate:t=>Ne((t=>0|t),t),children:Ie,descendants:Ie,trace:(t,e)=>(console.log("trace",t,e),t),now:()=>[{type:at.dateTime,value:(new Date).toISOString()}],timeOfDay:()=>[{type:at.time,value:(new Date).toISOString().substring(11)}],today:()=>[{type:at.date,value:(new Date).toISOString().substring(0,10)}],between:(t,e,n,i)=>{const r=je.toDateTime(e.eval(t));if(0===r.length)throw new Error("Invalid start date");const s=je.toDateTime(n.eval(t));if(0===s.length)throw new Error("Invalid end date");const o=i.eval(t)[0].value;if("years"!==o&&"months"!==o&&"days"!==o)throw new Error("Invalid units");const a=T(r[0].value,s[0].value);return[{type:at.Quantity,value:{value:a[o],unit:o}}]},is:(t,e)=>{let n="";return e instanceof ve?n=e.name:e instanceof Se&&(n=e.left.name+"."+e.right.name),n?t.map((t=>({type:at.boolean,value:oe(t,n)}))):[]},not:t=>je.toBoolean(t).map((t=>({type:at.boolean,value:!t.value}))),resolve:t=>t.map((t=>{const e=t.value;let n;if("string"==typeof e)n=e;else if("object"==typeof e){const t=e;if(t.resource)return{type:at.BackboneElement,value:t.resource};n=t.reference}if(!n)return{type:at.BackboneElement,value:null};const[i,r]=n.split("/");return{type:at.BackboneElement,value:{resourceType:i,id:r}}})).filter((t=>!!t.value)),as:t=>t,type:t=>t.map((({value:t})=>"boolean"==typeof t?{type:at.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof t?{type:at.BackboneElement,value:{namespace:"System",name:"Integer"}}:t&&"object"==typeof t&&"resourceType"in t?{type:at.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:at.BackboneElement,value:null})),conformsTo:(t,e)=>{const n=e.eval([])[0].value;if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const i=n.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>{var e;return{type:at.boolean,value:(null===(e=t.value)||void 0===e?void 0:e.resourceType)===i}}))}};function We(t,e,...n){if(0===e.length)return[];const[{value:i}]=Be(e,1);if("string"!=typeof i)throw new Error("String function cannot be called with non-string");const r=t(i,...n.map((t=>{var n,i;return t&&(null===(i=null===(n=t.eval(e))||void 0===n?void 0:n[0])||void 0===i?void 0:i.value)})));return void 0===r?[]:Array.isArray(r)?r.map(Jt):[Jt(r)]}function Ne(t,e,...n){if(0===e.length)return[];const[{value:i}]=Be(e,1),r=ae(i),s=r?i.value:i;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...n.map((t=>{var e,n;return null===(n=null===(e=t.eval([]))||void 0===e?void 0:e[0])||void 0===n?void 0:n.value})));return[{type:r?at.Quantity:e[0].type,value:r?Object.assign(Object.assign({},i),{value:o}):o}]}function Be(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);for(const e of t)if(null==e)throw new Error("Expected non-null argument");return t}var Qe,$e,Fe,He,qe,Xe,ze,Ye,Ve,Ge,Ke,Je,Ze,tn,en,nn,rn,sn;function on(t){return new cn(t).tokenize()}const an=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],ln=["!=","!~","<=",">=","{}"];class cn{constructor(t){Qe.add(this),$e.set(this,void 0),Fe.set(this,void 0),n(this,$e,t,"f"),n(this,Fe,0,"f")}tokenize(){const t=[];for(;e(this,Fe,"f")<e(this,$e,"f").length;){const n=e(this,Qe,"m",qe).call(this);n&&t.push(n)}return t}}function hn(t,e){return{id:t,value:e}}var un,fn,dn,pn,vn,gn,mn,yn,wn;$e=new WeakMap,Fe=new WeakMap,Qe=new WeakSet,He=function(){const t=e(this,Fe,"f"),i=e(this,Qe,"m",qe).call(this);return n(this,Fe,t,"f"),i},qe=function(){e(this,Qe,"m",Xe).call(this);const t=e(this,Qe,"m",nn).call(this);if(!t)return;const n=e(this,Qe,"m",sn).call(this);return"/"===t&&"*"===n?e(this,Qe,"m",ze).call(this):"/"===t&&"/"===n?e(this,Qe,"m",Ye).call(this):"'"===t?e(this,Qe,"m",Ve).call(this):"`"===t?e(this,Qe,"m",Ge).call(this):"@"===t?e(this,Qe,"m",Ke).call(this):t.match(/\d/)?e(this,Qe,"m",Je).call(this):t.match(/\w/)||"$"===t&&n.match(/\w/)?e(this,Qe,"m",Ze).call(this):e(this,Qe,"m",tn).call(this)},Xe=function(){return hn("Whitespace",e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/\s/))))},ze=function(){const t=e(this,Fe,"f");return e(this,Qe,"m",en).call(this,(()=>"*"!==e(this,Qe,"m",nn).call(this)||"/"!==e(this,Qe,"m",sn).call(this))),n(this,Fe,e(this,Fe,"f")+2,"f"),hn("Comment",e(this,$e,"f").substring(t,e(this,Fe,"f")))},Ye=function(){return hn("Comment",e(this,Qe,"m",en).call(this,(()=>"\n"!==e(this,Qe,"m",nn).call(this))))},Ve=function(){var t,i;n(this,Fe,(t=e(this,Fe,"f"),++t),"f");const r=hn("String",e(this,Qe,"m",en).call(this,(()=>"\\"===e(this,Qe,"m",rn).call(this)||"'"!==e(this,Qe,"m",nn).call(this))));return n(this,Fe,(i=e(this,Fe,"f"),++i),"f"),r},Ge=function(){var t,i;n(this,Fe,(t=e(this,Fe,"f"),++t),"f");const r=hn("Symbol",e(this,Qe,"m",en).call(this,(()=>"`"!==e(this,Qe,"m",nn).call(this))));return n(this,Fe,(i=e(this,Fe,"f"),++i),"f"),r},Ke=function(){var t,i,r,s,o;const a=e(this,Fe,"f");return n(this,Fe,(t=e(this,Fe,"f"),++t),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d-]/))),"T"===e(this,Qe,"m",nn).call(this)&&(n(this,Fe,(i=e(this,Fe,"f"),++i),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d:]/))),"."===e(this,Qe,"m",nn).call(this)&&e(this,Qe,"m",sn).call(this).match(/\d/)&&(n(this,Fe,(r=e(this,Fe,"f"),++r),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d]/)))),"Z"===e(this,Qe,"m",nn).call(this)?n(this,Fe,(s=e(this,Fe,"f"),++s),"f"):"+"!==e(this,Qe,"m",nn).call(this)&&"-"!==e(this,Qe,"m",nn).call(this)||(n(this,Fe,(o=e(this,Fe,"f"),++o),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[\d:]/))))),hn("DateTime",e(this,$e,"f").substring(a+1,e(this,Fe,"f")))},Je=function(){var t;const i=e(this,Fe,"f");let r="Number";return e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/\d/))),"."===e(this,Qe,"m",nn).call(this)&&e(this,Qe,"m",sn).call(this).match(/\d/)&&(n(this,Fe,(t=e(this,Fe,"f"),++t),"f"),e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/\d/))))," "===e(this,Qe,"m",nn).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&an.includes(t.value))return!0}return!1}(e(this,Qe,"m",He).call(this))&&(r="Quantity",e(this,Qe,"m",qe).call(this)),hn(r,e(this,$e,"f").substring(i,e(this,Fe,"f")))},Ze=function(){return hn("Symbol",e(this,Qe,"m",en).call(this,(()=>e(this,Qe,"m",nn).call(this).match(/[$\w]/))))},tn=function(){var t;const i=e(this,Qe,"m",nn).call(this),r=i+e(this,Qe,"m",sn).call(this);return ln.includes(r)?(n(this,Fe,e(this,Fe,"f")+2,"f"),hn(r,r)):(n(this,Fe,(t=e(this,Fe,"f"),++t),"f"),hn(i,i))},en=function(t){var i;const r=e(this,Fe,"f");for(;e(this,Fe,"f")<e(this,$e,"f").length&&t();)n(this,Fe,(i=e(this,Fe,"f"),++i),"f");return e(this,$e,"f").substring(r,e(this,Fe,"f"))},nn=function(){return e(this,$e,"f")[e(this,Fe,"f")]},rn=function(){var t;return null!==(t=e(this,$e,"f")[e(this,Fe,"f")-1])&&void 0!==t?t:""},sn=function(){var t;return null!==(t=e(this,$e,"f")[e(this,Fe,"f")+1])&&void 0!==t?t:""};un=new WeakMap,fn=new WeakMap;class Tn{constructor(t,e,i){dn.add(this),pn.set(this,void 0),vn.set(this,void 0),gn.set(this,void 0),n(this,pn,t,"f"),n(this,vn,e,"f"),n(this,gn,i,"f")}match(t){const n=e(this,dn,"m",wn).call(this);return(null==n?void 0:n.id)===t&&(e(this,dn,"m",yn).call(this),!0)}consumeAndParse(t=100){const n=e(this,dn,"m",yn).call(this),i=e(this,vn,"f")[n.id];if(!i)throw Error(`Parse error at ${n.value}. No matching prefix parselet.`);let r=i.parse(this,n);for(;t>e(this,dn,"m",mn).call(this);){const t=e(this,dn,"m",yn).call(this);r=e(this,gn,"f")[t.id].parse(this,r,t)}return r}}pn=new WeakMap,vn=new WeakMap,gn=new WeakMap,dn=new WeakSet,mn=function(){const t=e(this,dn,"m",wn).call(this);if(!t)return 100;const n=e(this,gn,"f")[t.id];return n?n.precedence:100},yn=function(){if(!e(this,pn,"f").length)throw Error("Cant consume unknown more tokens.");return e(this,pn,"f").shift()},wn=function(){return e(this,pn,"f").length>0?e(this,pn,"f")[0]:void 0};const bn={parse(t){const e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},En={parse(t,e){const n=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new De(e,n)},precedence:2},Sn={parse(t,e){if(!(e instanceof ve))throw new Error("Unexpected parentheses");if(!(e.name in je))throw new Error("Unrecognized function: "+e.name);const n=[];for(;!t.match(")");)n.push(t.consumeAndParse()),t.match(",");return new Le(e.name,n,je[e.name])},precedence:0};function An(t){const e=t.split(" "),n=parseFloat(e[0]);let i=e[1];return i=i&&i.startsWith("'")&&i.endsWith("'")?i.substring(1,i.length-1):"{"+i+"}",{value:n,unit:i}}const kn=(new class{constructor(){un.set(this,{}),fn.set(this,{})}registerInfix(t,n){return e(this,fn,"f")[t]=n,this}registerPrefix(t,n){return e(this,un,"f")[t]=n,this}prefix(t,e,n){return this.registerPrefix(t,{parse(t,i){const r=t.consumeAndParse(e);return n(i,r)}})}infixLeft(t,e,n){return this.registerInfix(t,{parse(t,i,r){const s=t.consumeAndParse(e);return n(i,r,s)},precedence:e})}construct(t){return new Tn(on(t),e(this,un,"f"),e(this,fn,"f"))}}).registerPrefix("String",{parse:(t,e)=>new pe({type:at.string,value:e.value})}).registerPrefix("DateTime",{parse:(t,e)=>new pe({type:at.dateTime,value:_e(e.value)})}).registerPrefix("Quantity",{parse:(t,e)=>new pe({type:at.Quantity,value:An(e.value)})}).registerPrefix("Number",{parse:(t,e)=>new pe({type:at.decimal,value:parseFloat(e.value)})}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new pe({type:at.boolean,value:!1}):"true"===e.value?new pe({type:at.boolean,value:!0}):new ve(e.value)}).registerPrefix("{}",{parse:()=>new ge}).registerPrefix("(",bn).registerInfix("[",En).registerInfix("(",Sn).prefix("+",3,((t,e)=>new me(e,(t=>t)))).prefix("-",3,((t,e)=>new we(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,n)=>new Se(t,n))).infixLeft("/",4,((t,e,n)=>new we(t,n,((t,e)=>t/e)))).infixLeft("*",4,((t,e,n)=>new we(t,n,((t,e)=>t*e)))).infixLeft("+",5,((t,e,n)=>new we(t,n,((t,e)=>t+e)))).infixLeft("-",5,((t,e,n)=>new we(t,n,((t,e)=>t-e)))).infixLeft("|",7,((t,e,n)=>new Ae(t,n))).infixLeft("=",9,((t,e,n)=>new ke(t,n))).infixLeft("!=",9,((t,e,n)=>new xe(t,n))).infixLeft("~",9,((t,e,n)=>new Pe(t,n))).infixLeft("!~",9,((t,e,n)=>new Oe(t,n))).infixLeft("<",8,((t,e,n)=>new we(t,n,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,n)=>new we(t,n,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,n)=>new we(t,n,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,n)=>new we(t,n,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,n)=>new Te(t,n))).infixLeft("Symbol",6,((t,e,n)=>{switch(e.value){case"and":return new Re(t,n);case"as":return new ye(t,n);case"contains":return new be(t,n);case"div":return new we(t,n,((t,e)=>t/e|0));case"in":return new Ee(t,n);case"is":return new Ue(t,n);case"mod":return new we(t,n,((t,e)=>t%e));case"or":return new Ce(t,n);case"xor":return new Me(t,n);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function xn(t){try{return new de(t,kn.construct(t).consumeAndParse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}function Pn(t,e){Array.isArray(e)||(e=[e]);const n=Array.isArray(e)?e:[e];for(let t=0;t<n.length;t++){const e=n[t];"object"==typeof e&&"type"in e&&"value"in e||(n[t]={type:at.BackboneElement,value:e})}return xn(t).eval(n).map((t=>t.value))}const On="\r",Un="|",Rn="^";class Cn{constructor(t){this.segments=t}get(t){return"number"==typeof t?this.segments[t]:this.segments.find((e=>e.name===t))}getAll(t){return this.segments.filter((e=>e.name===t))}toString(){return this.segments.map((t=>t.toString())).join("\r")}buildAck(){var t,e,n,i,r,s;const o=new Date,a=this.get("MSH"),l=(null===(t=null==a?void 0:a.get(2))||void 0===t?void 0:t.toString())||"",c=(null===(e=null==a?void 0:a.get(3))||void 0===e?void 0:e.toString())||"",h=(null===(n=null==a?void 0:a.get(4))||void 0===n?void 0:n.toString())||"",u=(null===(i=null==a?void 0:a.get(5))||void 0===i?void 0:i.toString())||"",f=(null===(r=null==a?void 0:a.get(9))||void 0===r?void 0:r.toString())||"",d=(null===(s=null==a?void 0:a.get(12))||void 0===s?void 0:s.toString())||"2.5.1";return new Cn([new Mn(["MSH","^~\\&",h,u,l,c,o.toISOString(),"","ACK",o.getTime().toString(),"P",d]),new Mn(["MSA","AA",f,"OK"])])}static parse(t){if(!t.startsWith("MSH|^~\\&")){const t=new Error("Invalid HL7 message");throw t.type="entity.parse.failed",t}return new Cn(t.split(/[\r\n]+/).map((t=>Mn.parse(t))))}}class Mn{constructor(t){M(t)?this.fields=t.map((t=>Ln.parse(t))):this.fields=t,this.name=this.fields[0].components[0]}get(t){return this.fields[t]}toString(){return this.fields.map((t=>t.toString())).join("|")}static parse(t){return new Mn(t.split("|").map((t=>Ln.parse(t))))}}class Ln{constructor(t){this.components=t}get(t){return this.components[t]}toString(){return this.components.join("^")}static parse(t){return new Ln(t.split("^"))}}const Dn=20;var _n;!function(t){t.EQUALS="eq",t.NOT_EQUALS="ne",t.GREATER_THAN="gt",t.LESS_THAN="lt",t.GREATER_THAN_OR_EQUALS="ge",t.LESS_THAN_OR_EQUALS="le",t.STARTS_AFTER="sa",t.ENDS_BEFORE="eb",t.APPROXIMATELY="ap",t.CONTAINS="contains",t.EXACT="exact",t.TEXT="text",t.ABOVE="above",t.BELOW="below",t.IN="in",t.NOT_IN="not-in",t.OF_TYPE="of-type"}(_n||(_n={}));const In=[_n.CONTAINS,_n.EXACT,_n.TEXT,_n.ABOVE,_n.BELOW,_n.IN,_n.NOT_IN,_n.OF_TYPE],jn=[_n.NOT_EQUALS,_n.GREATER_THAN,_n.LESS_THAN,_n.GREATER_THAN_OR_EQUALS,_n.LESS_THAN_OR_EQUALS,_n.STARTS_AFTER,_n.ENDS_BEFORE,_n.APPROXIMATELY];function Wn(t){const e=new URL(t,"https://example.com/"),n=e.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let i,r,s,o,a,l;return new URLSearchParams(e.search).forEach(((t,e)=>{"_fields"===e?s=t.split(","):"_offset"===e?o=parseInt(t):"_count"===e?a=parseInt(t):"_total"===e?l=t:"_sort"===e?(r=r||[],r.push(function(t){return t.startsWith("-")?{code:t.substring(1),descending:!0}:{code:t}}(t))):(i=i||[],i.push(function(t,e){let n=t,i=_n.EQUALS;for(const t of In){const e=n.indexOf(":"+t);-1!==e&&(i=t,n=n.substring(0,e))}for(const t of jn)e.match(new RegExp("^"+t+"\\d"))&&(i=t,e=e.substring(t.length));return{code:n,operator:i,value:e}}(e,t)))})),{resourceType:n,filters:i,fields:s,offset:o,count:a,total:l,sortRules:r}}function Nn(t){const e=[];return t.fields&&e.push("_fields="+t.fields.join(",")),t.filters&&t.filters.forEach((t=>e.push(function(t){const e=In.includes(t.operator)?":"+t.operator:"",n=jn.includes(t.operator)?t.operator:"";return`${t.code}${e}=${n}${encodeURIComponent(t.value)}`}(t)))),t.sortRules&&t.sortRules.length>0&&e.push(function(t){if(!t||0===t.length)return"";return"_sort="+t.map((t=>t.descending?"-"+t.code:t.code)).join(",")}(t.sortRules)),void 0!==t.offset&&e.push("_offset="+t.offset),void 0!==t.count&&e.push("_count="+t.count),void 0!==t.total&&e.push("_total="+t.total),0===e.length?"":(e.sort(),"?"+e.join("&"))}var Bn;function Qn(t,e,n){var i,r,s,o;if("_lastUpdated"===n.code)return{columnName:"lastUpdated",type:Bn.DATETIME};const a=n.code.split("-").reduce(((t,e,n)=>t+(n?I(e):e)),"");const l=null===(i=$n(e,n.expression))||void 0===i?void 0:i.split(".");if(!l)return{columnName:a,type:Bn.TEXT};let c,h,u=e,f=!1;for(let e=1;e<l.length;e++){const n=l[e];if(c=null===(s=null===(r=t.types[u])||void 0===r?void 0:r.properties)||void 0===s?void 0:s[n],!c)return{columnName:a,type:Bn.TEXT,array:f};if("*"===c.max&&(f=!0),h=null===(o=c.type)||void 0===o?void 0:o[0].code,!h)return{columnName:a,type:Bn.TEXT,array:f};e<l.length-1&&("Element"===h||"BackboneElement"===h?u+=I(n):u=h)}const d=function(t,e){let n=Bn.TEXT;switch(t.type){case"date":n=e===at.dateTime||e===at.instant?Bn.DATETIME:Bn.DATE;break;case"number":n=Bn.NUMBER;break;case"quantity":n=Bn.QUANTITY;break;case"reference":n=Bn.REFERENCE;break;case"token":"boolean"===e&&(n=Bn.BOOLEAN)}return n}(n,h);return{columnName:a,type:d,elementDefinition:c,array:f}}function $n(t,e){const n=e.split(" | ");for(const e of n){const n=Fn(e);if(n.startsWith(t+"."))return n}}function Fn(t){let e=t.trim();return e.startsWith("(")&&e.endsWith(")")&&(e=e.substring(1,e.length-1)),e.includes(" as ")&&(e=e.substring(0,e.indexOf(" as "))),e.includes(".where(")&&(e=e.substring(0,e.indexOf(".where("))),e}!function(t){t.BOOLEAN="BOOLEAN",t.NUMBER="NUMBER",t.QUANTITY="QUANTITY",t.TEXT="TEXT",t.REFERENCE="REFERENCE",t.DATE="DATE",t.DATETIME="DATETIME",t.PERIOD="PERIOD"}(Bn||(Bn={}));export{Rn as COMPONENT_SEPARATOR,Dn as DEFAULT_SEARCH_COUNT,Un as FIELD_SEPARATOR,Ln as Hl7Field,Cn as Hl7Message,Mn as Hl7Segment,a as LRUCache,Vt as MedplumClient,Z as OperationOutcomeError,_n as Operator,at as PropertyType,Nt as ReadablePromise,On as SEGMENT_SEPARATOR,Bn as SearchParameterType,X as accessDenied,Q as allOk,_ as arrayBufferToBase64,D as arrayBufferToHex,J as assertOk,z as badRequest,Xt as buildTypeName,T as calculateAge,b as calculateAgeString,I as capitalize,f as createReference,$t as createSchema,Ft as createTypeSchema,$ as created,U as deepEquals,Pn as evalFhirPath,l as formatAddress,u as formatFamilyName,h as formatGivenName,c as formatHumanName,Nn as formatSearchQuery,w as getDateProperty,g as getDisplayString,$n as getExpressionForResourceType,k as getExtensionValue,A as getIdentifier,m as getImageSrc,zt as getPropertyDisplayName,E as getQuestionnaireAnswers,d as getReferenceString,Qn as getSearchParameterDetails,K as getStatus,q as gone,qt as indexSearchParameter,Ht as indexStructureDefinition,G as isGone,j as isLowerCase,V as isNotFound,C as isObject,Y as isOk,v as isProfileResource,M as isStringArray,R as isUUID,H as notFound,F as notModified,xn as parseFhirPath,Wn as parseSearchDefinition,p as resolveId,x as stringify,on as tokenize};
|
|
2
2
|
//# sourceMappingURL=index.min.js.map
|