@medplum/core 0.9.4 → 0.9.7

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