@medplum/core 2.0.6 → 2.0.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 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).medplum=e.medplum||{},e.medplum.core={}))}(this,(function(e){"use strict";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)}keys(){return t(this,o,"f").keys()}}function c(e,t){const i=[];return e.prefix&&!1!==t?.prefix&&i.push(...e.prefix),e.given&&i.push(...e.given),e.family&&i.push(e.family),e.suffix&&!1!==t?.suffix&&i.push(...e.suffix),e.use&&(t?.all||t?.use)&&i.push("["+e.use+"]"),i.join(" ").trim()}function u(e){return e instanceof Date&&!isNaN(e.getTime())}function l(e,t,i){if(!e)return"";const n=new Date("2000-01-01T"+e+"Z");return u(n)?n.toLocaleTimeString(t,i):""}function p(e,t,i){if(!e)return"";const n=new Date(e);return u(n)?n.toLocaleString(t,i):""}r=new WeakMap,o=new WeakMap,n=new WeakSet,s=function(){return t(this,o,"f").keys().next().value};const d={s:"every second",min:"every minute",h:"hourly",d:"daily",wk:"weekly",mo:"monthly",a:"annually"},h={s:"second",min:"minute",h:"hour",d:"day",wk:"week",mo:"month",a:"year"},f={s:"seconds",min:"minutes",h:"hours",d:"days",wk:"weeks",mo:"months",a:"years"};function m(e,t){if(!e)return"";const i=[];return e.comparator&&(i.push(e.comparator),i.push(" ")),void 0!==e.value&&(void 0!==t?i.push(e.value.toFixed(t)):i.push(e.value)),e.unit&&("%"!==e.unit&&" "!==i[i.length-1]&&i.push(" "),i.push(e.unit)),i.join("").trim()}function y(e){return e?e.text?e.text:e.coding?e.coding.map((e=>g(e))).join(", "):"":""}function g(e){return e?.display||e?.code||""}function v(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function x(e){const t=w(e),i=T(e);return i===t?{reference:t}:{reference:t,display:i}}function w(e){return e.resourceType+"/"+e.id}function S(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function T(e){if(S(e)){const t=function(e){const t=e.name;if(t&&t.length>0)return c(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&&e.code?.text?e.code.text:"User"===e.resourceType&&e.email?e.email:"name"in e&&e.name&&"string"==typeof e.name?e.name:w(e)}function E(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function b(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 p=12*a+c-(12*r+o);u<s&&p--;return{years:l,months:p,days:Math.floor((n.getTime()-i.getTime())/864e5)}}function P(e,t){if(e)for(const i of e)i.linkId&&i.answer&&i.answer.length>0&&(t[i.linkId]=i.answer[0]),P(i.item,t)}function D(e,...t){let i=e;for(let e=0;e<t.length&&i;e++)i=i?.extension?.find((i=>i.url===t[e]));return i?.valueString}function A(e,t){return JSON.stringify(e,C,t?2:void 0)}function C(e,t){return!function(e){return!!e.match(/\d+$/)}(e)&&k(t)?void 0:t}function k(e){if(null==e)return!0;const t=typeof e;return"string"===t&&""===e||"object"===t&&0===Object.keys(e).length}function R(e,t,i){return e===t||(!(!k(e)||!k(t))||!k(e)&&!k(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(!R(e[i],t[i]))return!1;return!0}(e,t):!Array.isArray(e)&&!Array.isArray(t)&&(O(e)&&O(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(!R(e[i],t[i],i))return!1}return!0}(e,t,i):(O(e)||O(t),!1))))}function O(e){return null!==e&&"object"==typeof e}function M(e){return e.every((e=>"string"==typeof e))}const I=[];for(let e=0;e<256;e++)I.push(e.toString(16).padStart(2,"0"));function U(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 L(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 N(e){return e.charAt(0).toUpperCase()+e.substring(1)}function _(e){return e===e.toLowerCase()&&e!==e.toUpperCase()}function j(e,t){return function(e,t){return!e.gender||e.gender===t.gender}(e,t)&&function(e,t){return!e.age||W(b(t.birthDate).years,e.age)}(e,t)}function W(e,t,i){return(void 0===t.low?.value||B(e,t.low.value,i))&&(void 0===t.high?.value||Q(e,t.high.value,i))}function Q(e,t,i){return $(e,i)<=$(t,i)}function B(e,t,i){return $(e,i)>=$(t,i)}function $(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function q(){const e=new Uint32Array(28);return crypto.getRandomValues(e),U(e.buffer)}var F;class H{constructor(){F.set(this,void 0),i(this,F,{},"f")}addEventListener(e,i){t(this,F,"f")[e]||(t(this,F,"f")[e]=[]),t(this,F,"f")[e].push(i)}removeEventListeneer(e,i){const n=t(this,F,"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,F,"f")[e.type];return i&&i.forEach((t=>t.call(this,e))),!e.defaultPrevented}}function z(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)}function G(e){const[t,i,n]=e.split(".");return z(i)}F=new WeakMap;const V="ok",X="created",J="gone",Y="not-modified",K="not-found",Z="unauthorized",ee="forbidden",te="too-many-requests",ie={resourceType:"OperationOutcome",id:V,issue:[{severity:"information",code:"informational",details:{text:"All OK"}}]},ne={resourceType:"OperationOutcome",id:X,issue:[{severity:"information",code:"informational",details:{text:"Created"}}]},re={resourceType:"OperationOutcome",id:Y,issue:[{severity:"information",code:"informational",details:{text:"Not Modified"}}]},oe={resourceType:"OperationOutcome",id:K,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},se={resourceType:"OperationOutcome",id:Z,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},ae={resourceType:"OperationOutcome",id:ee,issue:[{severity:"error",code:"forbidden",details:{text:"Forbidden"}}]},ce={resourceType:"OperationOutcome",id:J,issue:[{severity:"error",code:"deleted",details:{text:"Gone"}}]},ue={resourceType:"OperationOutcome",id:te,issue:[{severity:"error",code:"throttled",details:{text:"Too Many Requests"}}]};function le(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}}function pe(e){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"structure",details:{text:e}}]}}function de(e){return"object"==typeof e&&null!==e&&"OperationOutcome"===e.resourceType}function he(e){return e.id===V||e.id===X||e.id===Y}class fe extends Error{constructor(e,t){super(e?.issue?.[0].details?.text),this.outcome=e,this.cause=t}}function me(e){return e instanceof fe?e.outcome:de(e)?e:le(ye(e))}function ye(e){return e?"string"==typeof e?e:e instanceof Error?e.message:de(e)?e.issue?.[0]?.details?.text??"Unknown error":JSON.stringify(e):"Unknown error"}var ge,ve,xe,we,Se,Te,Ee;class be{constructor(e){this[Se]="ReadablePromise",ge.set(this,void 0),ve.set(this,"pending"),xe.set(this,void 0),we.set(this,void 0),i(this,ge,e.then((e=>(i(this,ve,"success","f"),i(this,xe,e,"f"),e)),(e=>{throw i(this,ve,"error","f"),i(this,we,e,"f"),e})),"f")}isPending(){return"pending"===t(this,ve,"f")}isOk(){return"success"===t(this,ve,"f")}read(){switch(t(this,ve,"f")){case"pending":throw t(this,ge,"f");case"error":throw t(this,we,"f");default:return t(this,xe,"f")}}then(e,i){return t(this,ge,"f").then(e,i)}catch(e){return t(this,ge,"f").catch(e)}finally(e){return t(this,ge,"f").finally(e)}}ge=new WeakMap,ve=new WeakMap,xe=new WeakMap,we=new WeakMap,Se=Symbol.toStringTag;class Pe{constructor(){Te.set(this,void 0),i(this,Te,"undefined"!=typeof localStorage?localStorage:new De,"f")}clear(){t(this,Te,"f").clear()}getString(e){return t(this,Te,"f").getItem(e)||void 0}setString(e,i){i?t(this,Te,"f").setItem(e,i):t(this,Te,"f").removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?A(t):void 0)}}Te=new WeakMap;class De{constructor(){Ee.set(this,void 0),i(this,Ee,new Map,"f")}get length(){return t(this,Ee,"f").size}clear(){t(this,Ee,"f").clear()}getItem(e){return t(this,Ee,"f").get(e)??null}setItem(e,i){i?t(this,Ee,"f").set(e,i):t(this,Ee,"f").delete(e)}removeItem(e){t(this,Ee,"f").delete(e)}key(e){return Array.from(t(this,Ee,"f").keys())[e]}}Ee=new WeakMap;var Ae,Ce={types:{Element:{display:"Element",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]}}},BackboneElement:{display:"BackboneElement",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]}}},Address:{display:"Address",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"code"}]},text:{type:[{code:"string"}]},line:{max:"*",type:[{code:"string"}]},city:{type:[{code:"string"}]},district:{type:[{code:"string"}]},state:{type:[{code:"string"}]},postalCode:{type:[{code:"string"}]},country:{type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Age:{display:"Age",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Annotation:{display:"Annotation",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},"author[x]":{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Organization"]},{code:"string"}]},time:{type:[{code:"dateTime"}]},text:{min:1,type:[{code:"markdown"}]}}},Attachment:{display:"Attachment",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},contentType:{type:[{code:"code"}]},language:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]},url:{type:[{code:"url"}]},size:{type:[{code:"unsignedInt"}]},hash:{type:[{code:"base64Binary"}]},title:{type:[{code:"string"}]},creation:{type:[{code:"dateTime"}]}}},CodeableConcept:{display:"CodeableConcept",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},coding:{max:"*",type:[{code:"Coding"}]},text:{type:[{code:"string"}]}}},Coding:{display:"Coding",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},system:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},code:{type:[{code:"code"}]},display:{type:[{code:"string"}]},userSelected:{type:[{code:"boolean"}]}}},ContactDetail:{display:"ContactDetail",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},name:{type:[{code:"string"}]},telecom:{max:"*",type:[{code:"ContactPoint"}]}}},ContactPoint:{display:"ContactPoint",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},system:{type:[{code:"code"}]},value:{type:[{code:"string"}]},use:{type:[{code:"code"}]},rank:{type:[{code:"positiveInt"}]},period:{type:[{code:"Period"}]}}},Contributor:{display:"Contributor",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{min:1,type:[{code:"string"}]},contact:{max:"*",type:[{code:"ContactDetail"}]}}},Count:{display:"Count",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},DataRequirement:{display:"DataRequirement",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},profile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},"subject[x]":{type:[{code:"CodeableConcept"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Group"]}]},mustSupport:{max:"*",type:[{code:"string"}]},codeFilter:{max:"*",type:[{code:"Element"}]},dateFilter:{max:"*",type:[{code:"Element"}]},limit:{type:[{code:"positiveInt"}]},sort:{max:"*",type:[{code:"Element"}]}}},DataRequirementCodeFilter:{display:"DataRequirementCodeFilter",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]},code:{max:"*",type:[{code:"Coding"}]}}},DataRequirementDateFilter:{display:"DataRequirementDateFilter",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},"value[x]":{type:[{code:"dateTime"},{code:"Period"},{code:"Duration"}]}}},DataRequirementSort:{display:"DataRequirementSort",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},direction:{min:1,type:[{code:"code"}]}}},Distance:{display:"Distance",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Dosage:{display:"Dosage",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},sequence:{type:[{code:"integer"}]},text:{type:[{code:"string"}]},additionalInstruction:{max:"*",type:[{code:"CodeableConcept"}]},patientInstruction:{type:[{code:"string"}]},timing:{type:[{code:"Timing"}]},"asNeeded[x]":{type:[{code:"boolean"},{code:"CodeableConcept"}]},site:{type:[{code:"CodeableConcept"}]},route:{type:[{code:"CodeableConcept"}]},method:{type:[{code:"CodeableConcept"}]},doseAndRate:{max:"*",type:[{code:"Element"}]},maxDosePerPeriod:{type:[{code:"Ratio"}]},maxDosePerAdministration:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},maxDosePerLifetime:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},DosageDoseAndRate:{display:"DosageDoseAndRate",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{type:[{code:"CodeableConcept"}]},"dose[x]":{type:[{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},"rate[x]":{type:[{code:"Ratio"},{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Duration:{display:"Duration",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},ElementDefinition:{display:"ElementDefinition",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},representation:{max:"*",type:[{code:"code"}]},sliceName:{type:[{code:"string"}]},sliceIsConstraining:{type:[{code:"boolean"}]},label:{type:[{code:"string"}]},code:{max:"*",type:[{code:"Coding"}]},slicing:{type:[{code:"Element"}]},short:{type:[{code:"string"}]},definition:{type:[{code:"markdown"}]},comment:{type:[{code:"markdown"}]},requirements:{type:[{code:"markdown"}]},alias:{max:"*",type:[{code:"string"}]},min:{type:[{code:"unsignedInt"}]},max:{type:[{code:"string"}]},base:{type:[{code:"Element"}]},contentReference:{type:[{code:"uri"}]},type:{max:"*",type:[{code:"Element"}]},"defaultValue[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},meaningWhenMissing:{type:[{code:"markdown"}]},orderMeaning:{type:[{code:"string"}]},"fixed[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},"pattern[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},example:{max:"*",type:[{code:"Element"}]},"minValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},"maxValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},maxLength:{type:[{code:"integer"}]},condition:{max:"*",type:[{code:"id"}]},constraint:{max:"*",type:[{code:"Element"}]},mustSupport:{type:[{code:"boolean"}]},isModifier:{type:[{code:"boolean"}]},isModifierReason:{type:[{code:"string"}]},isSummary:{type:[{code:"boolean"}]},binding:{type:[{code:"Element"}]},mapping:{max:"*",type:[{code:"Element"}]}}},ElementDefinitionSlicing:{display:"ElementDefinitionSlicing",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},discriminator:{max:"*",type:[{code:"Element"}]},description:{type:[{code:"string"}]},ordered:{type:[{code:"boolean"}]},rules:{min:1,type:[{code:"code"}]}}},ElementDefinitionSlicingDiscriminator:{display:"ElementDefinitionSlicingDiscriminator",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},path:{min:1,type:[{code:"string"}]}}},ElementDefinitionBase:{display:"ElementDefinitionBase",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},min:{min:1,type:[{code:"unsignedInt"}]},max:{min:1,type:[{code:"string"}]}}},ElementDefinitionType:{display:"ElementDefinitionType",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},code:{min:1,type:[{code:"uri"}]},profile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},targetProfile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},aggregation:{max:"*",type:[{code:"code"}]},versioning:{type:[{code:"code"}]}}},ElementDefinitionExample:{display:"ElementDefinitionExample",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},label:{min:1,type:[{code:"string"}]},"value[x]":{min:1,type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},ElementDefinitionConstraint:{display:"ElementDefinitionConstraint",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},key:{min:1,type:[{code:"id"}]},requirements:{type:[{code:"string"}]},severity:{min:1,type:[{code:"code"}]},human:{min:1,type:[{code:"string"}]},expression:{type:[{code:"string"}]},xpath:{type:[{code:"string"}]},source:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},ElementDefinitionBinding:{display:"ElementDefinitionBinding",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},strength:{min:1,type:[{code:"code"}]},description:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]}}},ElementDefinitionMapping:{display:"ElementDefinitionMapping",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},identity:{min:1,type:[{code:"id"}]},language:{type:[{code:"code"}]},map:{min:1,type:[{code:"string"}]},comment:{type:[{code:"string"}]}}},Expression:{display:"Expression",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},description:{type:[{code:"string"}]},name:{type:[{code:"id"}]},language:{min:1,type:[{code:"code"}]},expression:{type:[{code:"string"}]},reference:{type:[{code:"uri"}]}}},Extension:{display:"Extension",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},url:{min:1,type:[{code:"string"}]},"value[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},HumanName:{display:"HumanName",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},use:{type:[{code:"code"}]},text:{type:[{code:"string"}]},family:{type:[{code:"string"}]},given:{max:"*",type:[{code:"string"}]},prefix:{max:"*",type:[{code:"string"}]},suffix:{max:"*",type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Identifier:{display:"Identifier",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"CodeableConcept"}]},system:{type:[{code:"uri"}]},value:{type:[{code:"string"}]},period:{type:[{code:"Period"}]},assigner:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MarketingStatus:{display:"MarketingStatus",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},country:{min:1,type:[{code:"CodeableConcept"}]},jurisdiction:{type:[{code:"CodeableConcept"}]},status:{min:1,type:[{code:"CodeableConcept"}]},dateRange:{min:1,type:[{code:"Period"}]},restoreDate:{type:[{code:"dateTime"}]}}},Meta:{display:"Meta",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},versionId:{type:[{code:"id"}]},lastUpdated:{type:[{code:"instant"}]},source:{type:[{code:"uri"}]},profile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},security:{max:"*",type:[{code:"Coding"}]},tag:{max:"*",type:[{code:"Coding"}]},project:{type:[{code:"uri"}]},author:{type:[{code:"Reference"}]},account:{type:[{code:"Reference"}]},compartment:{max:"*",type:[{code:"Reference"}]}}},Money:{display:"Money",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},currency:{type:[{code:"code"}]}}},Narrative:{display:"Narrative",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},status:{min:1,type:[{code:"code"}]},div:{min:1,type:[{code:"xhtml"}]}}},ParameterDefinition:{display:"ParameterDefinition",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},name:{type:[{code:"code"}]},use:{min:1,type:[{code:"code"}]},min:{type:[{code:"integer"}]},max:{type:[{code:"string"}]},documentation:{type:[{code:"string"}]},type:{min:1,type:[{code:"code"}]},profile:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},Period:{display:"Period",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},start:{type:[{code:"dateTime"}]},end:{type:[{code:"dateTime"}]}}},Population:{display:"Population",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},"age[x]":{type:[{code:"Range"},{code:"CodeableConcept"}]},gender:{type:[{code:"CodeableConcept"}]},race:{type:[{code:"CodeableConcept"}]},physiologicalCondition:{type:[{code:"CodeableConcept"}]}}},ProdCharacteristic:{display:"ProdCharacteristic",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},height:{type:[{code:"Quantity"}]},width:{type:[{code:"Quantity"}]},depth:{type:[{code:"Quantity"}]},weight:{type:[{code:"Quantity"}]},nominalVolume:{type:[{code:"Quantity"}]},externalDiameter:{type:[{code:"Quantity"}]},shape:{type:[{code:"string"}]},color:{max:"*",type:[{code:"string"}]},imprint:{max:"*",type:[{code:"string"}]},image:{max:"*",type:[{code:"Attachment"}]},scoring:{type:[{code:"CodeableConcept"}]}}},ProductShelfLife:{display:"ProductShelfLife",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},identifier:{type:[{code:"Identifier"}]},type:{min:1,type:[{code:"CodeableConcept"}]},period:{min:1,type:[{code:"Quantity"}]},specialPrecautionsForStorage:{max:"*",type:[{code:"CodeableConcept"}]}}},Quantity:{display:"Quantity",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{max:"0",type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Range:{display:"Range",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},low:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},high:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Ratio:{display:"Ratio",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},numerator:{type:[{code:"Quantity"}]},denominator:{type:[{code:"Quantity"}]}}},Reference:{display:"Reference",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},reference:{type:[{code:"string"}]},type:{type:[{code:"uri"}]},identifier:{type:[{code:"Identifier"}]},display:{type:[{code:"string"}]}}},RelatedArtifact:{display:"RelatedArtifact",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},label:{type:[{code:"string"}]},display:{type:[{code:"string"}]},citation:{type:[{code:"markdown"}]},url:{type:[{code:"url"}]},document:{type:[{code:"Attachment"}]},resource:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/Resource"]}]}}},SampledData:{display:"SampledData",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},origin:{min:1,type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},period:{min:1,type:[{code:"decimal"}]},factor:{type:[{code:"decimal"}]},lowerLimit:{type:[{code:"decimal"}]},upperLimit:{type:[{code:"decimal"}]},dimensions:{min:1,type:[{code:"positiveInt"}]},data:{type:[{code:"string"}]}}},Signature:{display:"Signature",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,max:"*",type:[{code:"Coding"}]},when:{min:1,type:[{code:"instant"}]},who:{min:1,type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},onBehalfOf:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},targetFormat:{type:[{code:"code"}]},sigFormat:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]}}},SubstanceAmount:{display:"SubstanceAmount",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},"amount[x]":{type:[{code:"Quantity"},{code:"Range"},{code:"string"}]},amountType:{type:[{code:"CodeableConcept"}]},amountText:{type:[{code:"string"}]},referenceRange:{type:[{code:"Element"}]}}},SubstanceAmountReferenceRange:{display:"SubstanceAmountReferenceRange",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},lowLimit:{type:[{code:"Quantity"}]},highLimit:{type:[{code:"Quantity"}]}}},Timing:{display:"Timing",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},event:{max:"*",type:[{code:"dateTime"}]},repeat:{type:[{code:"Element"}]},code:{type:[{code:"CodeableConcept"}]}}},TimingRepeat:{display:"TimingRepeat",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},"bounds[x]":{type:[{code:"Duration"},{code:"Range"},{code:"Period"}]},count:{type:[{code:"positiveInt"}]},countMax:{type:[{code:"positiveInt"}]},duration:{type:[{code:"decimal"}]},durationMax:{type:[{code:"decimal"}]},durationUnit:{type:[{code:"code"}]},frequency:{type:[{code:"positiveInt"}]},frequencyMax:{type:[{code:"positiveInt"}]},period:{type:[{code:"decimal"}]},periodMax:{type:[{code:"decimal"}]},periodUnit:{type:[{code:"code"}]},dayOfWeek:{max:"*",type:[{code:"code"}]},timeOfDay:{max:"*",type:[{code:"time"}]},when:{max:"*",type:[{code:"code"}]},offset:{type:[{code:"unsignedInt"}]}}},TriggerDefinition:{display:"TriggerDefinition",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{type:[{code:"string"}]},"timing[x]":{type:[{code:"Timing"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Schedule"]},{code:"date"},{code:"dateTime"}]},data:{max:"*",type:[{code:"DataRequirement"}]},condition:{type:[{code:"Expression"}]}}},UsageContext:{display:"UsageContext",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},code:{min:1,type:[{code:"Coding"}]},"value[x]":{min:1,type:[{code:"CodeableConcept"},{code:"Quantity"},{code:"Range"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/PlanDefinition","http://hl7.org/fhir/StructureDefinition/ResearchStudy","http://hl7.org/fhir/StructureDefinition/InsurancePlan","http://hl7.org/fhir/StructureDefinition/HealthcareService","http://hl7.org/fhir/StructureDefinition/Group","http://hl7.org/fhir/StructureDefinition/Location","http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MetadataResource:{display:"MetadataResource",properties:{id:{type:[{code:"string"}]},meta:{type:[{code:"Meta"}]},implicitRules:{type:[{code:"uri"}]},language:{type:[{code:"code"}]},text:{type:[{code:"Narrative"}]},contained:{max:"*",type:[{code:"Resource"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},url:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},name:{type:[{code:"string"}]},title:{type:[{code:"string"}]},status:{min:1,type:[{code:"code"}]},experimental:{type:[{code:"boolean"}]},date:{type:[{code:"dateTime"}]},publisher:{type:[{code:"string"}]},contact:{max:"*",type:[{code:"ContactDetail"}]},description:{type:[{code:"markdown"}]},useContext:{max:"*",type:[{code:"UsageContext"}]},jurisdiction:{max:"*",type:[{code:"CodeableConcept"}]}}},IdentityProvider:{display:"IdentityProvider",properties:{authorizeUrl:{min:1,type:[{code:"string"}]},tokenUrl:{min:1,type:[{code:"string"}]},userInfoUrl:{min:1,type:[{code:"string"}]},clientId:{min:1,type:[{code:"string"}]},clientSecret:{min:1,type:[{code:"string"}]},useSubject:{type:[{code:"boolean"}]}}}}};function ke(e){if(!e.name)return;const t=e.snapshot?.element;t&&(t.forEach((t=>function(e,t){const i=t.path,n=t.type?.[0]?.code;if(void 0!==n&&"Element"!==n&&"BackboneElement"!==n)return;const r=i.split(".");r[0]=e.name;const o=Oe(r);let s=_e.types[o];s||(_e.types[o]=s={});s.parentType=s.parentType||Oe(r.slice(0,r.length-1)),s.display=s.display||o,s.structureDefinition=s.structureDefinition||e,s.elementDefinition=s.elementDefinition||t,s.description=s.description||t.definition,s.properties=s.properties||{}}(e,t))),t.forEach((t=>function(e,t){const i=t.path,n=i.split(".");if(1===n.length)return;n[0]=e.name;const r=Oe(n.slice(0,n.length-1)),o=_e.types[r];if(!o)return;const s=n[n.length-1];o.properties[s]=t}(e,t))))}function Re(e){if(e.base)for(const t of e.base){const i=_e.types[t];i&&(i.searchParams||(i.searchParams={_id:{base:[t],code:"_id",type:"token",expression:t+".id"},_lastUpdated:{base:[t],code:"_lastUpdated",type:"date",expression:t+".meta.lastUpdated"},_compartment:{base:[t],code:"_compartment",type:"reference",expression:t+".meta.compartment"},_profile:{base:[t],code:"_profile",type:"uri",expression:t+".meta.profile"},_security:{base:[t],code:"_security",type:"token",expression:t+".meta.security"},_source:{base:[t],code:"_source",type:"uri",expression:t+".meta.source"},_tag:{base:[t],code:"_tag",type:"token",expression:t+".meta.tag"}}),i.searchParams[e.code]=e)}}function Oe(e){return 1===e.length?e[0]:e.map(N).join("")}function Me(e){const t=e.structureDefinition;return t&&t.name===e.elementDefinition?.path&&"resource"===t.kind&&!t.abstract}e.PropertyType=void 0,(Ae=e.PropertyType||(e.PropertyType={})).Address="Address",Ae.Age="Age",Ae.Annotation="Annotation",Ae.Attachment="Attachment",Ae.BackboneElement="BackboneElement",Ae.CodeableConcept="CodeableConcept",Ae.Coding="Coding",Ae.ContactDetail="ContactDetail",Ae.ContactPoint="ContactPoint",Ae.Contributor="Contributor",Ae.Count="Count",Ae.DataRequirement="DataRequirement",Ae.Distance="Distance",Ae.Dosage="Dosage",Ae.Duration="Duration",Ae.Expression="Expression",Ae.Extension="Extension",Ae.HumanName="HumanName",Ae.Identifier="Identifier",Ae.MarketingStatus="MarketingStatus",Ae.Meta="Meta",Ae.Money="Money",Ae.Narrative="Narrative",Ae.ParameterDefinition="ParameterDefinition",Ae.Period="Period",Ae.Population="Population",Ae.ProdCharacteristic="ProdCharacteristic",Ae.ProductShelfLife="ProductShelfLife",Ae.Quantity="Quantity",Ae.Range="Range",Ae.Ratio="Ratio",Ae.Reference="Reference",Ae.RelatedArtifact="RelatedArtifact",Ae.SampledData="SampledData",Ae.Signature="Signature",Ae.SubstanceAmount="SubstanceAmount",Ae.SystemString="http://hl7.org/fhirpath/System.String",Ae.Timing="Timing",Ae.TriggerDefinition="TriggerDefinition",Ae.UsageContext="UsageContext",Ae.base64Binary="base64Binary",Ae.boolean="boolean",Ae.canonical="canonical",Ae.code="code",Ae.date="date",Ae.dateTime="dateTime",Ae.decimal="decimal",Ae.id="id",Ae.instant="instant",Ae.integer="integer",Ae.markdown="markdown",Ae.oid="oid",Ae.positiveInt="positiveInt",Ae.string="string",Ae.time="time",Ae.unsignedInt="unsignedInt",Ae.uri="uri",Ae.url="url",Ae.uuid="uuid";const Ie=new Set(["ID","PKCE","JWKS","URI","URL"]);function Ue(e){const t=e.toUpperCase();return Ie.has(t)?t:t.charAt(0)+e.slice(1)}function Le(e,t){const i=_e.types[e];if(!i)return;const n=i.properties[t]??i.properties[t+"[x]"];if(n){if(n.contentReference){const e=n.contentReference.substring(1).split("."),t=e.pop();return Le(Oe(e),t)}return n}}function Ne(e){return!(!e||"object"!=typeof e||!("resourceType"in e))}const _e=Ce;var je,We,Qe,Be,$e,qe,Fe,He,ze,Ge,Ve,Xe,Je,Ye,Ke,Ze,et,tt,it,nt,rt,ot,st,at,ct,ut,lt,pt,dt,ht,ft,mt,yt,gt,vt,xt,wt,St,Tt,Et,bt;const Pt={resourceType:"Device",id:"system",deviceName:[{name:"System"}]};function Dt(){return"undefined"==typeof window?"":window.location.protocol+"//"+window.location.host+"/"}var At,Ct,kt,Rt,Ot,Mt,It,Ut,Lt,Nt,_t,jt,Wt,Qt,Bt,$t,qt,Ft,Ht,zt,Gt,Vt,Xt,Jt,Yt,Kt,Zt,ei,ti,ii,ni,ri,oi,si;We=new WeakMap,Qe=new WeakMap,Be=new WeakMap,$e=new WeakMap,qe=new WeakMap,Fe=new WeakMap,He=new WeakMap,ze=new WeakMap,Ge=new WeakMap,Ve=new WeakMap,Xe=new WeakMap,Je=new WeakMap,Ye=new WeakMap,Ke=new WeakMap,Ze=new WeakMap,et=new WeakMap,tt=new WeakMap,it=new WeakMap,nt=new WeakMap,rt=new WeakMap,ot=new WeakMap,st=new WeakMap,je=new WeakSet,at=function(e){const i=this.getLogins().filter((t=>t.profile?.reference!==e.profile?.reference));i.push(e),t(this,Be,"f").setObject("logins",i)},ct=async function(){return i(this,rt,new Promise(((e,n)=>{this.get("auth/me").then((n=>{i(this,rt,void 0,"f"),i(this,ot,n.profile,"f"),i(this,st,n.config,"f"),this.dispatchEvent({type:"change"}),e(t(this,ot,"f"))})).catch(n)})),"f"),t(this,rt,"f")},ut=function(e,i){if(t(this,qe,"f")<=0||"no-cache"===i?.cache||"reload"===i?.cache)return;const n=t(this,$e,"f").get(e);return!n||n.requestTime+t(this,qe,"f")<Date.now()?void 0:n},lt=function(e,i){t(this,qe,"f")>0&&t(this,$e,"f").set(e,{requestTime:Date.now(),value:i})},pt=function(e){e?.id&&t(this,je,"m",lt).call(this,this.fhirUrl(e.resourceType,e.id).toString(),new be(Promise.resolve(e)))},dt=function(e){t(this,qe,"f")>0&&t(this,$e,"f").delete(e)},ht=async function(e,i,n={}){t(this,nt,"f")&&await t(this,nt,"f"),i.startsWith("http")||(i=t(this,Fe,"f")+i),n.method=e,t(this,je,"m",yt).call(this,n);const r=await t(this,je,"m",ft).call(this,i,n);if(401===r.status)return t(this,je,"m",xt).call(this,e,i,n);if(204===r.status||304===r.status)return;let o;try{o=await r.json()}catch(e){throw console.error("Error parsing response",r.status,e),e}if(r.status>=400)throw new fe(me(o));return o},ft=async function(e,i){let n;for(let r=0;r<3;r++){if(n=await t(this,We,"f").call(this,e,i),n.status<500)return n;await new Promise((e=>setTimeout(e,200)))}return n},mt=async function(){const e=[...t(this,Ye,"f")];if(t(this,Ye,"f").length=0,i(this,et,void 0,"f"),1===e.length){const i=e[0];return void i.resolve(await t(this,je,"m",ht).call(this,i.method,t(this,He,"f")+i.url,i.options))}const n={resourceType:"Bundle",type:"batch",entry:e.map((e=>({request:{method:e.method,url:e.url},resource:e.options.body?JSON.parse(e.options.body):void 0})))},r=await this.post("fhir/R4",n);for(let t=0;t<e.length;t++){const i=e[t],n=r.entry?.[t];n?.response?.outcome&&!he(n.response.outcome)?i.reject(new fe(n.response.outcome)):i.resolve(n?.resource)}},yt=function(e){e.headers||(e.headers={});const i=e.headers;i["X-Medplum"]="extended",i["Content-Type"]||(i["Content-Type"]="application/fhir+json"),t(this,tt,"f")&&(i.Authorization="Bearer "+t(this,tt,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},gt=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},vt=function(e,t){"string"==typeof t||"undefined"!=typeof Blob&&t instanceof Blob||"undefined"!=typeof File&&t instanceof File||"undefined"!=typeof Uint8Array&&t instanceof Uint8Array?e.body=t:t&&(e.body=JSON.stringify(t))},xt=function(e,i,n){return t(this,je,"m",St).call(this)?t(this,je,"m",ht).call(this,e,i,n):(this.clearActiveLogin(),t(this,Xe,"f")&&t(this,Xe,"f").call(this),Promise.reject(new Error("Unauthenticated")))},wt=async function(e){const i=await this.ensureCodeChallenge(e||{}),n=new URL(t(this,ze,"f"));n.searchParams.set("response_type","code"),n.searchParams.set("state",sessionStorage.getItem("pkceState")),n.searchParams.set("client_id",i.clientId||t(this,Ke,"f")),n.searchParams.set("redirect_uri",i.redirectUri||Dt()),n.searchParams.set("code_challenge_method",i.codeChallengeMethod),n.searchParams.set("code_challenge",i.codeChallenge),n.searchParams.set("scope",i.scope||"openid profile"),window.location.assign(n.toString())},St=function(){if(t(this,nt,"f"))return t(this,nt,"f");if(t(this,it,"f")){const e=new URLSearchParams;return e.set("grant_type","refresh_token"),e.set("client_id",t(this,Ke,"f")),e.set("refresh_token",t(this,it,"f")),i(this,nt,t(this,je,"m",Tt).call(this,e),"f"),t(this,nt,"f")}return t(this,Ke,"f")&&t(this,Ze,"f")?(i(this,nt,this.startClientLogin(t(this,Ke,"f"),t(this,Ze,"f")),"f"),t(this,nt,"f")):void 0},Tt=async function(e){const i=await t(this,We,"f").call(this,t(this,Ge,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e,credentials:"include"});if(!i.ok)throw this.clearActiveLogin(),new Error("Failed to fetch tokens");const n=await i.json();return await t(this,je,"m",Et).call(this,n),this.getProfile()},Et=async function(e){const i=e.access_token,n=G(i);if(Date.now()>=1e3*n.exp)throw this.clearActiveLogin(),new Error("Token expired");if(t(this,Ke,"f")&&n.client_id!==t(this,Ke,"f"))throw this.clearActiveLogin(),new Error("Token was not issued for this audience");return this.setActiveLogin({accessToken:i,refreshToken:e.refresh_token,project:e.project,profile:e.profile})},bt=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class ai{constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}}class ci{constructor(e,t,i){this.operator=e,this.left=t,this.right=i}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class ui{constructor(){At.set(this,{}),Ct.set(this,{})}registerInfix(e,i){return t(this,Ct,"f")[e]=i,this}registerPrefix(e,i){return t(this,At,"f")[e]=i,this}prefix(e,t,i){return this.registerPrefix(e,{parse(e,n){const r=e.consumeAndParse(t);return i(n,r)}})}infixLeft(e,t,i){return this.registerInfix(e,{parse(e,n,r){const o=e.consumeAndParse(t);return i(n,r,o)},precedence:t})}construct(e){return new li(e,t(this,At,"f"),t(this,Ct,"f"))}}At=new WeakMap,Ct=new WeakMap;class li{constructor(e,t,n){kt.set(this,void 0),Rt.set(this,void 0),Ot.set(this,void 0),i(this,kt,e,"f"),i(this,Rt,t,"f"),i(this,Ot,n,"f")}hasMore(){return t(this,kt,"f").length>0}match(e){const t=this.peek();return t?.id===e&&(this.consume(),!0)}consumeAndParse(e=1/0){const i=this.consume(),n=t(this,Rt,"f")[i.id];if(!n)throw Error(`Parse error at "${i.value}" (line ${i.line}, column ${i.column}). No matching prefix parselet.`);let r=n.parse(this,i);for(;e>this.getPrecedence();){const e=this.consume();r=this.getInfixParselet(e).parse(this,r,e)}return r}getPrecedence(){const e=this.peek();if(!e)return 1/0;const t=this.getInfixParselet(e);return t?t.precedence:1/0}consume(e,i){if(!t(this,kt,"f").length)throw Error("Cant consume unknown more tokens.");if(e&&this.peek()?.id!==e){const t=this.peek();throw Error(`Expected ${e} but got "${t.id}" at line ${t.line} column ${t.column}.`)}if(i&&this.peek()?.value!==i){const e=this.peek();throw Error(`Expected "${i}" but got "${e.value}" at line ${e.line} column ${e.column}.`)}return t(this,kt,"f").shift()}peek(){return t(this,kt,"f").length>0?t(this,kt,"f")[0]:void 0}removeComments(){i(this,kt,t(this,kt,"f").filter((e=>"Comment"!==e.id)),"f")}getInfixParselet(e){return t(this,Ot,"f")["Symbol"===e.id?e.value:e.id]}}kt=new WeakMap,Rt=new WeakMap,Ot=new WeakMap;const pi=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"];class di{constructor(e,t,n,r){Mt.add(this),It.set(this,void 0),Ut.set(this,void 0),Lt.set(this,void 0),Nt.set(this,void 0),_t.set(this,void 0),jt.set(this,[]),Wt.set(this,{index:0,line:1,column:0}),Qt.set(this,[]),i(this,It,e,"f"),i(this,Ut,t,"f"),i(this,Lt,n,"f"),i(this,Nt,!!r?.dateTimeLiterals,"f"),i(this,_t,r?.symbolRegex??/[$\w]/,"f")}tokenize(){for(;t(this,Wt,"f").index<t(this,It,"f").length;){const e=t(this,Mt,"m",qt).call(this);e&&t(this,jt,"f").push(e)}return t(this,jt,"f")}}function hi(e){if(e.startsWith("T"))return e+"T00:00:00.000Z".substring(e.length);if(e.length<=10)return e;try{return new Date(e).toISOString()}catch(t){return e}}function fi(t){return[{type:e.PropertyType.boolean,value:t}]}function mi(t){return null==t?{type:"undefined",value:void 0}:Number.isSafeInteger(t)?{type:e.PropertyType.integer,value:t}:"number"==typeof t?{type:e.PropertyType.decimal,value:t}:"boolean"==typeof t?{type:e.PropertyType.boolean,value:t}:"string"==typeof t?{type:e.PropertyType.string,value:t}:Ci(t)?{type:e.PropertyType.Quantity,value:t}:Ne(t)?{type:t.resourceType,value:t}:{type:e.PropertyType.BackboneElement,value:t}}function yi(e){return 0!==e.length&&!!e[0].value}function gi(t,i){if(!t?.value)return;const n=Le(t.type,i);if(n){const e=function(e,t,i){const n=i.type;if(!n||0===n.length)return;let r,o="undefined";if(1===n.length)r=e.value[t],o=n[0].code;else for(const i of n){const n=t.replace("[x]","")+N(i.code);if(n in e.value){r=e.value[n],o=i.code;break}}if(k(r))return;"Element"!==o&&"BackboneElement"!==o||(o=Oe(i.path?.split(".")));return Array.isArray(r)?r.map((e=>vi(e,o))):vi(r,o)}(t,i,n);if(e)return e}return function(t,i){const n=t.value;if(!n||"object"!=typeof n)return;let r;if(i in n)r=n[i];else for(const t in e.PropertyType){const e=i+N(t);if(e in n){r=n[e];break}}if(k(r))return;return Array.isArray(r)?r.map(mi):mi(r)}(t,i)}function vi(e,t){return"Resource"===t&&Ne(e)&&(t=e.resourceType),{type:t,value:e}}function xi(e){const t=[];for(const i of e){let e=!1;for(const n of t)if(yi(Ti(i,n))){e=!0;break}e||t.push(i)}return t}function wi(e){return fi(!yi(e))}function Si(e,t){return 0===e.length||0===t.length?[]:e.length!==t.length?fi(!1):fi(e.every(((e,i)=>yi(Ti(e,t[i])))))}function Ti(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?fi(Math.abs(i-n)<1e-8):Ci(i)&&Ci(n)?fi(ki(i,n)):fi("object"==typeof i&&"object"==typeof n?Ri(e,t):i===n)}function Ei(e,t){return 0===e.length&&0===t.length?fi(!0):e.length!==t.length?fi(!1):(e.sort(Pi),t.sort(Pi),fi(e.every(((e,i)=>yi(bi(e,t[i]))))))}function bi(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?fi(Math.abs(i-n)<.01):Ci(i)&&Ci(n)?fi(ki(i,n)):fi("object"==typeof i&&"object"==typeof n?Ri(i,n):"string"==typeof i&&"string"==typeof n?i.toLowerCase()===n.toLowerCase():i===n)}function Pi(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?i-n:"string"==typeof i&&"string"==typeof n?i.localeCompare(n):0}function Di(e,t){const{value:i}=e;if(null==i)return!1;switch(t){case"Boolean":return"boolean"==typeof i;case"Decimal":case"Integer":return"number"==typeof i;case"Date":return"string"==typeof i&&!!i.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof i&&!!i.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof i&&!!i.match(/^T\d/);case"Period":return Ai(i);case"Quantity":return Ci(i);default:return"object"==typeof i&&i?.resourceType===t}}function Ai(e){return!(!e||"object"!=typeof e||!("start"in e))}function Ci(e){return!(!e||"object"!=typeof e||!("value"in e)||"number"!=typeof e.value)}function ki(e,t){return Math.abs(e.value-t.value)<.01&&(e.unit===t.unit||e.code===t.code||e.unit===t.code||e.code===t.unit)}function Ri(e,t){const i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(const n of i){const i=e[n],r=t[n];if(Oi(i)&&Oi(r)){if(!Ri(i,r))return!1}else if(i!==r)return!1}return!0}function Oi(e){return null!==e&&"object"==typeof e}It=new WeakMap,Ut=new WeakMap,Lt=new WeakMap,Nt=new WeakMap,_t=new WeakMap,jt=new WeakMap,Wt=new WeakMap,Qt=new WeakMap,Mt=new WeakSet,Bt=function(){return t(this,jt,"f").slice(-1)[0]},$t=function(){t(this,Mt,"m",ni).call(this);const e=t(this,Mt,"m",qt).call(this);return t(this,Mt,"m",ri).call(this),e},qt=function(){t(this,Mt,"m",Ft).call(this);const e=t(this,Mt,"m",ei).call(this);if(!e)return;t(this,Mt,"m",ni).call(this);const i=t(this,Mt,"m",ii).call(this);return"/"===e&&"*"===i?t(this,Mt,"m",Ht).call(this):"/"===e&&"/"===i?t(this,Mt,"m",zt).call(this):"'"===e||'"'===e?t(this,Mt,"m",Gt).call(this,e):"`"===e?t(this,Mt,"m",Vt).call(this):"@"===e?t(this,Mt,"m",Xt).call(this):e.match(/\d/)?t(this,Mt,"m",Jt).call(this):e.match(/\w/)||"$"===e&&i.match(/\w/)?t(this,Mt,"m",Yt).call(this):t(this,Mt,"m",Kt).call(this)},Ft=function(){t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\s/)))},Ht=function(){const e=t(this,Wt,"f").index;return t(this,Mt,"m",Zt).call(this,(()=>"*"!==t(this,Mt,"m",ei).call(this)||"/"!==t(this,Mt,"m",ii).call(this))),t(this,Mt,"m",oi).call(this),t(this,Mt,"m",oi).call(this),t(this,Mt,"m",si).call(this,"Comment",t(this,It,"f").substring(e,t(this,Wt,"f").index))},zt=function(){return t(this,Mt,"m",si).call(this,"Comment",t(this,Mt,"m",Zt).call(this,(()=>"\n"!==t(this,Mt,"m",ei).call(this))))},Gt=function(e){t(this,Mt,"m",oi).call(this);const i=t(this,Mt,"m",si).call(this,"String",t(this,Mt,"m",Zt).call(this,(()=>"\\"===t(this,Mt,"m",ti).call(this)||t(this,Mt,"m",ei).call(this)!==e)));return t(this,Mt,"m",oi).call(this),i},Vt=function(){t(this,Mt,"m",oi).call(this);const e=t(this,Mt,"m",si).call(this,"Symbol",t(this,Mt,"m",Zt).call(this,(()=>"`"!==t(this,Mt,"m",ei).call(this))));return t(this,Mt,"m",oi).call(this),e},Xt=function(){t(this,Mt,"m",oi).call(this);const e=t(this,Wt,"f").index;return t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/[\d-]/))),"T"===t(this,Mt,"m",ei).call(this)&&(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/[\d:]/))),"."===t(this,Mt,"m",ei).call(this)&&t(this,Mt,"m",ii).call(this).match(/\d/)&&(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\d/)))),"Z"===t(this,Mt,"m",ei).call(this)?t(this,Mt,"m",oi).call(this):"+"!==t(this,Mt,"m",ei).call(this)&&"-"!==t(this,Mt,"m",ei).call(this)||(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/[\d:]/))))),t(this,Mt,"m",si).call(this,"DateTime",t(this,It,"f").substring(e,t(this,Wt,"f").index))},Jt=function(){const e=t(this,Wt,"f").index;let i="Number";return t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\d/))),"."===t(this,Mt,"m",ei).call(this)&&t(this,Mt,"m",ii).call(this).match(/\d/)&&(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\d/)))),"-"===t(this,Mt,"m",ei).call(this)&&t(this,Nt,"f")?(t(this,Wt,"f").index=e-1,t(this,Mt,"m",Xt).call(this)):(" "===t(this,Mt,"m",ei).call(this)&&function(e){if(e){if("String"===e.id)return!0;if("Symbol"===e.id&&pi.includes(e.value))return!0}return!1}(t(this,Mt,"m",$t).call(this))&&(i="Quantity",t(this,Mt,"m",qt).call(this)),t(this,Mt,"m",si).call(this,i,t(this,It,"f").substring(e,t(this,Wt,"f").index)))},Yt=function(){const e=t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(t(this,_t,"f"))));return"."!==t(this,Mt,"m",Bt).call(this)?.value&&t(this,Ut,"f").includes(e)?t(this,Mt,"m",si).call(this,e,e):t(this,Mt,"m",si).call(this,"Symbol",e)},Kt=function(){const e=t(this,Mt,"m",ei).call(this),i=e+t(this,Mt,"m",ii).call(this);return t(this,Lt,"f").includes(i)?(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",oi).call(this),t(this,Mt,"m",si).call(this,i,i)):(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",si).call(this,e,e))},Zt=function(e){const i=t(this,Wt,"f").index;for(;t(this,Wt,"f").index<t(this,It,"f").length&&e();)t(this,Mt,"m",oi).call(this);return t(this,It,"f").substring(i,t(this,Wt,"f").index)},ei=function(){return t(this,It,"f")[t(this,Wt,"f").index]},ti=function(){return t(this,It,"f")[t(this,Wt,"f").index-1]??""},ii=function(){return t(this,It,"f")[t(this,Wt,"f").index+1]??""},ni=function(){t(this,Qt,"f").push({...t(this,Wt,"f")})},ri=function(){const e=t(this,Qt,"f").pop();if(!e)throw new Error("No mark to reset to");t(this,Wt,"f").index=e.index,t(this,Wt,"f").line=e.line,t(this,Wt,"f").column=e.column},oi=function(){t(this,Wt,"f").index++,"\n"===t(this,Mt,"m",ei).call(this)?(t(this,Wt,"f").line++,t(this,Wt,"f").column=0):t(this,Wt,"f").column++},si=function(e,i){const n=t(this,Qt,"f").pop();if(!n)throw new Error("No mark for token");return{id:e,value:i,...n}};const Mi=()=>[],Ii={empty:e=>fi(0===e.length),exists:(e,t)=>fi(t?e.filter((e=>yi(t.eval([e])))).length>0:e.length>0),all:(e,t)=>fi(e.every((e=>yi(t.eval([e]))))),allTrue:e=>{for(const t of e)if(!t.value)return fi(!1);return fi(!0)},anyTrue:e=>{for(const t of e)if(t.value)return fi(!0);return fi(!1)},allFalse:e=>{for(const t of e)if(t.value)return fi(!1);return fi(!0)},anyFalse:e=>{for(const t of e)if(!t.value)return fi(!0);return fi(!1)},subsetOf:Mi,supersetOf:Mi,count:t=>[{type:e.PropertyType.integer,value:t.length}],distinct:e=>{const t=[];for(const i of e)t.some((e=>e.value===i.value))||t.push(i);return t},isDistinct:e=>fi(e.length===Ii.distinct(e).length),where:(e,t)=>e.filter((e=>yi(t.eval([e])))),select:(e,t)=>e.map((e=>t.eval([e]))).flat(),repeat:Mi,ofType:(e,t)=>e.filter((e=>e.type===t.name)),single:e=>{if(e.length>1)throw new Error("Expected input length one for single()");return 0===e.length?[]:e.slice(0,1)},first:e=>0===e.length?[]:e.slice(0,1),last:e=>0===e.length?[]:e.slice(e.length-1,e.length),tail:e=>0===e.length?[]:e.slice(1,e.length),skip:(e,t)=>{const i=t.eval(e)[0]?.value;if("number"!=typeof i)throw new Error("Expected a number for skip(num)");return i>=e.length?[]:i<=0?e:e.slice(i,e.length)},take:(e,t)=>{const i=t.eval(e)[0]?.value;if("number"!=typeof i)throw new Error("Expected a number for take(num)");return i>=e.length?e:i<=0?[]:e.slice(0,i)},intersect:(e,t)=>{if(!t)return e;const i=t.eval(e),n=[];for(const t of e)!n.some((e=>e.value===t.value))&&i.some((e=>e.value===t.value))&&n.push(t);return n},exclude:(e,t)=>{if(!t)return e;const i=t.eval(e),n=[];for(const t of e)i.some((e=>e.value===t.value))||n.push(t);return n},union:(e,t)=>{if(!t)return e;const i=t.eval(e);return xi([...e,...i])},combine:(e,t)=>{if(!t)return e;const i=t.eval(e);return[...e,...i]},iif:(e,t,i,n)=>{const r=t.eval(e);if(r.length>1||1===r.length&&"boolean"!=typeof r[0].value)throw new Error("Expected criterion to evaluate to a Boolean");return yi(r)?i.eval(e):n?n.eval(e):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);if("boolean"==typeof i)return[{type:e.PropertyType.boolean,value:i}];if("number"==typeof i&&(0===i||1===i))return fi(!!i);if("string"==typeof i){const e=i.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(e))return fi(!0);if(["false","f","no","n","0","0.0"].includes(e))return fi(!1)}return[]},convertsToBoolean:e=>0===e.length?[]:fi(1===Ii.toBoolean(e).length),toInteger:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"number"==typeof i?[{type:e.PropertyType.integer,value:i}]:"string"==typeof i&&i.match(/^[+-]?\d+$/)?[{type:e.PropertyType.integer,value:parseInt(i,10)}]:"boolean"==typeof i?[{type:e.PropertyType.integer,value:i?1:0}]:[]},convertsToInteger:e=>0===e.length?[]:fi(1===Ii.toInteger(e).length),toDate:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"string"==typeof i&&i.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.date,value:hi(i)}]:[]},convertsToDate:e=>0===e.length?[]:fi(1===Ii.toDate(e).length),toDateTime:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"string"==typeof i&&i.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.dateTime,value:hi(i)}]:[]},convertsToDateTime:e=>0===e.length?[]:fi(1===Ii.toDateTime(e).length),toDecimal:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"number"==typeof i?[{type:e.PropertyType.decimal,value:i}]:"string"==typeof i&&i.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:e.PropertyType.decimal,value:parseFloat(i)}]:"boolean"==typeof i?[{type:e.PropertyType.decimal,value:i?1:0}]:[]},convertsToDecimal:e=>0===e.length?[]:fi(1===Ii.toDecimal(e).length),toQuantity:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return Ci(i)?[{type:e.PropertyType.Quantity,value:i}]:"number"==typeof i?[{type:e.PropertyType.Quantity,value:{value:i,unit:"1"}}]:"string"==typeof i&&i.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:e.PropertyType.Quantity,value:{value:parseFloat(i),unit:"1"}}]:"boolean"==typeof i?[{type:e.PropertyType.Quantity,value:{value:i?1:0,unit:"1"}}]:[]},convertsToQuantity:e=>0===e.length?[]:fi(1===Ii.toQuantity(e).length),toString:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return null==i?[]:Ci(i)?[{type:e.PropertyType.string,value:`${i.value} '${i.unit}'`}]:[{type:e.PropertyType.string,value:i.toString()}]},convertsToString:e=>0===e.length?[]:fi(1===Ii.toString(e).length),toTime:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);if("string"==typeof i){const t=i.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[{type:e.PropertyType.time,value:hi("T"+t[1])}]}return[]},convertsToTime:e=>0===e.length?[]:fi(1===Ii.toTime(e).length),indexOf:(e,t)=>Ui(((e,t)=>e.indexOf(t)),e,t),substring:(e,t,i)=>Ui(((e,t,i)=>{const n=t,r=i?n+i:e.length;return n<0||n>=e.length?void 0:e.substring(n,r)}),e,t,i),startsWith:(e,t)=>Ui(((e,t)=>e.startsWith(t)),e,t),endsWith:(e,t)=>Ui(((e,t)=>e.endsWith(t)),e,t),contains:(e,t)=>Ui(((e,t)=>e.includes(t)),e,t),upper:e=>Ui((e=>e.toUpperCase()),e),lower:e=>Ui((e=>e.toLowerCase()),e),replace:(e,t,i)=>Ui(((e,t,i)=>e.replaceAll(t,i)),e,t,i),matches:(e,t)=>Ui(((e,t)=>!!e.match(t)),e,t),replaceMatches:(e,t,i)=>Ui(((e,t,i)=>e.replaceAll(t,i)),e,t,i),length:e=>Ui((e=>e.length),e),toChars:e=>Ui((e=>e?e.split(""):void 0),e),abs:e=>Li(Math.abs,e),ceiling:e=>Li(Math.ceil,e),exp:e=>Li(Math.exp,e),floor:e=>Li(Math.floor,e),ln:e=>Li(Math.log,e),log:(e,t)=>Li(((e,t)=>Math.log(e)/Math.log(t)),e,t),power:(e,t)=>Li(Math.pow,e,t),round:e=>Li(Math.round,e),sqrt:e=>Li(Math.sqrt,e),truncate:e=>Li((e=>0|e),e),children:Mi,descendants:Mi,trace:(e,t)=>(console.log("trace",e,t),e),now:()=>[{type:e.PropertyType.dateTime,value:(new Date).toISOString()}],timeOfDay:()=>[{type:e.PropertyType.time,value:(new Date).toISOString().substring(11)}],today:()=>[{type:e.PropertyType.date,value:(new Date).toISOString().substring(0,10)}],between:(t,i,n,r)=>{const o=Ii.toDateTime(i.eval(t));if(0===o.length)throw new Error("Invalid start date");const s=Ii.toDateTime(n.eval(t));if(0===s.length)throw new Error("Invalid end date");const a=r.eval(t)[0]?.value;if("years"!==a&&"months"!==a&&"days"!==a)throw new Error("Invalid units");const c=b(o[0].value,s[0].value);return[{type:e.PropertyType.Quantity,value:{value:c[a],unit:a}}]},is:(t,i)=>{let n="";return i instanceof Bi?n=i.name:i instanceof Xi&&(n=i.left.name+"."+i.right.name),n?t.map((t=>({type:e.PropertyType.boolean,value:Di(t,n)}))):[]},not:t=>Ii.toBoolean(t).map((t=>({type:e.PropertyType.boolean,value:!t.value}))),resolve:t=>t.map((t=>{const i=t.value;let n;if("string"==typeof i)n=i;else if("object"==typeof i){const e=i;if(e.resource)return mi(e.resource);n=e.reference}if(!n)return{type:e.PropertyType.BackboneElement,value:null};const[r,o]=n.split("/");return{type:e.PropertyType.BackboneElement,value:{resourceType:r,id:o}}})).filter((e=>!!e.value)),as:e=>e,type:t=>t.map((({value:t})=>"boolean"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Integer"}}:Ne(t)?{type:e.PropertyType.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:e.PropertyType.BackboneElement,value:null})),conformsTo:(t,i)=>{const n=i.eval(t)[0].value;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=>({type:e.PropertyType.boolean,value:t.value?.resourceType===r})))}};function Ui(e,t,...i){if(0===t.length)return[];const[{value:n}]=Ni(t,1);if("string"!=typeof n)throw new Error("String function cannot be called with non-string");const r=e(n,...i.map((e=>e&&e.eval(t)?.[0]?.value)));return void 0===r?[]:Array.isArray(r)?r.map(mi):[mi(r)]}function Li(t,i,...n){if(0===i.length)return[];const[{value:r}]=Ni(i,1),o=Ci(r),s=o?r.value:r;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const a=t(s,...n.map((e=>e.eval(i)?.[0]?.value)));return[{type:o?e.PropertyType.Quantity:i[0].type,value:o?{...r,value:a}:a}]}function Ni(e,t){if(e.length!==t)throw new Error(`Expected ${t} arguments`);for(const t of e)if(null==t)throw new Error("Expected non-null argument");return e}var _i,ji;class Wi{constructor(e,t){this.original=e,this.child=t}eval(e){try{return e.length>0?e.map((e=>this.child.eval([e]))).flat():this.child.eval([])}catch(e){throw new Error(`FhirPathError on "${this.original}": ${e}`)}}toString(){return this.child.toString()}}class Qi{constructor(e){this.value=e}eval(){return[this.value]}toString(){const e=this.value.value;return"string"==typeof e?`'${e}'`:e.toString()}}class Bi{constructor(e){this.name=e,_i.add(this)}eval(e){return"$this"===this.name?e:e.map((e=>t(this,_i,"m",ji).call(this,e))).flat().filter((e=>void 0!==e?.value))}toString(){return this.name}}_i=new WeakSet,ji=function(e){const t=e.value;if(t&&"object"==typeof t)return Ne(t)&&t.resourceType===this.name?e:gi(e,this.name)};class $i{eval(){return[]}toString(){return"{}"}}class qi extends ai{constructor(e,t,i){super(e,t),this.impl=i}eval(e){return this.impl(this.child.eval(e))}toString(){return this.child.toString()}}class Fi extends ci{constructor(e,t){super("as",e,t)}eval(e){return Ii.ofType(this.left.eval(e),this.right)}}class Hi extends ci{constructor(e,t,i,n){super(e,t,i),this.impl=n}eval(t){const i=this.left.eval(t);if(1!==i.length)return[];const n=this.right.eval(t);if(1!==n.length)return[];const r=i[0].value,o=n[0].value,s=Ci(r)?r.value:r,a=Ci(o)?o.value:o,c=this.impl(s,a);return"boolean"==typeof c?fi(c):Ci(r)?[{type:e.PropertyType.Quantity,value:{...r,value:c}}]:[mi(c)]}}class zi extends ci{constructor(e,t){super("&",e,t)}eval(t){const i=[...this.left.eval(t),...this.right.eval(t)];return i.length>0&&i.every((e=>"string"==typeof e.value))?[{type:e.PropertyType.string,value:i.map((e=>e.value)).join("")}]:i}}class Gi extends ci{constructor(e,t){super("contains",e,t)}eval(e){const t=this.left.eval(e),i=this.right.eval(e);return fi(t.some((e=>e.value===i[0].value)))}}class Vi extends ci{constructor(e,t){super("in",e,t)}eval(e){const t=this.left.eval(e);return fi(this.right.eval(e).some((e=>e.value===t[0].value)))}}class Xi extends ci{constructor(e,t){super(".",e,t)}eval(e){return this.right.eval(this.left.eval(e))}toString(){return`${this.left.toString()}.${this.right.toString()}`}}class Ji extends ci{constructor(e,t){super("|",e,t)}eval(e){return xi([...this.left.eval(e),...this.right.eval(e)])}}class Yi extends ci{constructor(e,t){super("=",e,t)}eval(e){return Si(this.left.eval(e),this.right.eval(e))}}class Ki extends ci{constructor(e,t){super("!=",e,t)}eval(e){return wi(Si(this.left.eval(e),this.right.eval(e)))}}class Zi extends ci{constructor(e,t){super("~",e,t)}eval(e){return Ei(this.left.eval(e),this.right.eval(e))}}class en extends ci{constructor(e,t){super("!~",e,t)}eval(e){return wi(Ei(this.left.eval(e),this.right.eval(e)))}}class tn extends ci{constructor(e,t){super("is",e,t)}eval(e){const t=this.left.eval(e);if(1!==t.length)return[];const i=this.right.name;return fi(Di(t[0],i))}}class nn extends ci{constructor(e,t){super("and",e,t)}eval(e){const t=this.left.eval(e),i=this.right.eval(e);return!0===t[0]?.value&&!0===i[0]?.value?fi(!0):!1===t[0]?.value||!1===i[0]?.value?fi(!1):[]}}class rn extends ci{constructor(e,t){super("or",e,t)}eval(e){const t=this.left.eval(e);if(yi(t))return t;const i=this.right.eval(e);return yi(i)?i:[]}}class on extends ci{constructor(e,t){super("xor",e,t)}eval(e){const t=this.left.eval(e),i=this.right.eval(e);if(0===t.length&&0===i.length)return[];const n=0===t.length?null:t[0].value,r=0===i.length?null:i[0].value;return!0===n&&!0!==r||!0!==n&&!0===r?fi(!0):!0===n&&!0===r||!1===n&&!1===r?fi(!1):[]}}class sn{constructor(e,t){this.name=e,this.args=t}eval(e){const t=Ii[this.name];if(!t)throw new Error("Unrecognized function: "+this.name);return t(e,...this.args)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}}class an{constructor(e,t){this.left=e,this.expr=t}eval(e){const t=this.expr.eval(e);if(1!==t.length)return[];const i=t[0].value;if("number"!=typeof i)throw new Error("Invalid indexer expression: should return integer}");const n=this.left.eval(e);return i in n?[n[i]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}}const cn=["true","false"],un=["!=","!~","<=",">=","{}","->"];function ln(e){return new di(e,cn,un).tokenize()}const pn={parse(e){const t=e.consumeAndParse();if(!e.match(")"))throw new Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},dn={parse(e,t){const i=e.consumeAndParse();if(!e.match("]"))throw new Error("Parse error: expected `]`");return new an(t,i)},precedence:2},hn={parse(e,t){if(!(t instanceof Bi))throw new Error("Unexpected parentheses");const i=[];for(;!e.match(")");)i.push(e.consumeAndParse()),e.match(",");return new sn(t.name,i)},precedence:0};function fn(e){const t=e.split(" "),i=parseFloat(t[0]);let n=t[1];return n=n&&n.startsWith("'")&&n.endsWith("'")?n.substring(1,n.length-1):"{"+n+"}",{value:i,unit:n}}function mn(){return(new ui).registerPrefix("String",{parse:(t,i)=>new Qi({type:e.PropertyType.string,value:i.value})}).registerPrefix("DateTime",{parse:(t,i)=>new Qi({type:e.PropertyType.dateTime,value:hi(i.value)})}).registerPrefix("Quantity",{parse:(t,i)=>new Qi({type:e.PropertyType.Quantity,value:fn(i.value)})}).registerPrefix("Number",{parse:(t,i)=>new Qi({type:e.PropertyType.decimal,value:parseFloat(i.value)})}).registerPrefix("true",{parse:()=>new Qi({type:e.PropertyType.boolean,value:!0})}).registerPrefix("false",{parse:()=>new Qi({type:e.PropertyType.boolean,value:!1})}).registerPrefix("Symbol",{parse:(e,t)=>new Bi(t.value)}).registerPrefix("{}",{parse:()=>new $i}).registerPrefix("(",pn).registerInfix("[",dn).registerInfix("(",hn).prefix("+",3,((e,t)=>new qi("+",t,(e=>e)))).prefix("-",3,((e,t)=>new Hi("-",t,t,((e,t)=>-t)))).infixLeft(".",1,((e,t,i)=>new Xi(e,i))).infixLeft("/",4,((e,t,i)=>new Hi("/",e,i,((e,t)=>e/t)))).infixLeft("*",4,((e,t,i)=>new Hi("*",e,i,((e,t)=>e*t)))).infixLeft("+",5,((e,t,i)=>new Hi("+",e,i,((e,t)=>e+t)))).infixLeft("-",5,((e,t,i)=>new Hi("-",e,i,((e,t)=>e-t)))).infixLeft("|",7,((e,t,i)=>new Ji(e,i))).infixLeft("=",9,((e,t,i)=>new Yi(e,i))).infixLeft("!=",9,((e,t,i)=>new Ki(e,i))).infixLeft("~",9,((e,t,i)=>new Zi(e,i))).infixLeft("!~",9,((e,t,i)=>new en(e,i))).infixLeft("<",8,((e,t,i)=>new Hi("<",e,i,((e,t)=>e<t)))).infixLeft("<=",8,((e,t,i)=>new Hi("<=",e,i,((e,t)=>e<=t)))).infixLeft(">",8,((e,t,i)=>new Hi(">",e,i,((e,t)=>e>t)))).infixLeft(">=",8,((e,t,i)=>new Hi(">=",e,i,((e,t)=>e>=t)))).infixLeft("&",5,((e,t,i)=>new zi(e,i))).infixLeft("and",6,((e,t,i)=>new nn(e,i))).infixLeft("as",6,((e,t,i)=>new Fi(e,i))).infixLeft("contains",6,((e,t,i)=>new Gi(e,i))).infixLeft("div",6,((e,t,i)=>new Hi("div",e,i,((e,t)=>e/t|0)))).infixLeft("in",6,((e,t,i)=>new Vi(e,i))).infixLeft("is",6,((e,t,i)=>new tn(e,i))).infixLeft("mod",6,((e,t,i)=>new Hi("mod",e,i,((e,t)=>e%t)))).infixLeft("or",6,((e,t,i)=>new rn(e,i))).infixLeft("xor",6,((e,t,i)=>new on(e,i)))}const yn=mn();function gn(e){return new Wi(e,yn.construct(ln(e)).consumeAndParse())}function vn(e,t){const i=Array.isArray(t)?t:[t];for(let e=0;e<i.length;e++){const t=i[e];"object"==typeof t&&"type"in t&&"value"in t||(i[e]=mi(i[e]))}return xn(e,i).map((e=>e.value))}function xn(e,t){return gn(e).eval(t)}const wn=[...un,"->","<<",">>"];var Sn,Tn,En,bn,Pn,Dn,An,Cn,kn,Rn,On,Mn,In,Un,Ln,Nn,_n,jn,Wn;class Qn{constructor(e){this.parser=e,Sn.add(this),this.structureMap={resourceType:"StructureMap"}}parse(){for(this.parser.consume("Symbol","map"),this.structureMap.url=this.parser.consume("String").value,this.parser.consume("="),this.structureMap.name=this.parser.consume().value;this.parser.hasMore();){const e=this.parser.peek()?.value;switch(e){case"uses":t(this,Sn,"m",Tn).call(this);break;case"imports":t(this,Sn,"m",En).call(this);break;case"group":t(this,Sn,"m",bn).call(this);break;case"conceptmap":t(this,Sn,"m",Wn).call(this);break;default:throw new Error(`Unexpected token: ${e}`)}}return this.structureMap}}Sn=new WeakSet,Tn=function(){this.parser.consume("Symbol","uses");const e={};e.url=this.parser.consume("String").value,"alias"===this.parser.peek()?.value&&(this.parser.consume("Symbol","alias"),e.alias=this.parser.consume("Symbol").value),this.parser.consume("Symbol","as"),e.mode=this.parser.consume().value,this.structureMap.structure||(this.structureMap.structure=[]),this.structureMap.structure.push(e)},En=function(){this.parser.consume("Symbol","imports"),this.structureMap.import||(this.structureMap.import=[]),this.structureMap.import.push(this.parser.consume("String").value)},bn=function(){const e={};this.parser.consume("Symbol","group"),e.name=this.parser.consume("Symbol").value,e.input=t(this,Sn,"m",Pn).call(this),"extends"===this.parser.peek()?.value&&(this.parser.consume("Symbol","extends"),e.extends=this.parser.consume("Symbol").value),"<<"===this.parser.peek()?.value?(this.parser.consume("<<"),e.typeMode=this.parser.consume().value,"+"===this.parser.peek()?.value&&(this.parser.consume("+"),e.typeMode="type-and-types"),this.parser.consume(">>")):e.typeMode="none",e.rule=t(this,Sn,"m",An).call(this),this.structureMap.group||(this.structureMap.group=[]),this.structureMap.group.push(e)},Pn=function(){const e=[];for(this.parser.consume("(");this.parser.hasMore()&&")"!==this.parser.peek()?.value;)e.push(t(this,Sn,"m",Dn).call(this)),","===this.parser.peek()?.value&&this.parser.consume(",");return this.parser.consume(")"),e},Dn=function(){const e={};return e.mode=this.parser.consume().value,e.name=this.parser.consume("Symbol").value,":"===this.parser.peek()?.value&&(this.parser.consume(":"),e.type=this.parser.consume("Symbol").value),e},An=function(){const e=[];for(this.parser.consume("{");this.parser.hasMore()&&"}"!==this.parser.peek()?.value;)e.push(t(this,Sn,"m",Cn).call(this));return this.parser.consume("}"),e},Cn=function(){const e={source:t(this,Sn,"m",kn).call(this)};return"->"===this.parser.peek()?.value&&(this.parser.consume("->"),e.target=t(this,Sn,"m",On).call(this)),"then"===this.parser.peek()?.value&&(this.parser.consume("Symbol","then"),"{"===this.parser.peek()?.id?e.rule=t(this,Sn,"m",An).call(this):e.dependent=t(this,Sn,"m",jn).call(this)),"String"===this.parser.peek()?.id?e.name=this.parser.consume().value:e.name=e.source?.[0]?.element,this.parser.consume(";"),e},kn=function(){const e=[t(this,Sn,"m",Rn).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(t(this,Sn,"m",Rn).call(this));return e},Rn=function(){const e={},i=t(this,Sn,"m",_n).call(this);if(i.includes(".")){const t=i.split(".");e.context=t[0],e.element=t[1]}else e.context=i;if(this.parser.hasMore()&&":"===this.parser.peek()?.value&&(this.parser.consume(":"),e.type=this.parser.consume().value),this.parser.hasMore()&&"default"===this.parser.peek()?.value&&(this.parser.consume("default"),this.parser.consumeAndParse()),"first"!==this.parser.peek()?.value&&"not_first"!==this.parser.peek()?.value&&"last"!==this.parser.peek()?.value&&"not_last"!==this.parser.peek()?.value&&"only_one"!==this.parser.peek()?.value||(e.listMode=this.parser.consume().value),"as"===this.parser.peek()?.value&&(this.parser.consume("Symbol","as"),e.variable=this.parser.consume().value),"where"===this.parser.peek()?.value){this.parser.consume("Symbol","where");const t=this.parser.consumeAndParse(100);e.condition=t.toString()}if("check"===this.parser.peek()?.value){this.parser.consume("Symbol","check");const t=this.parser.consumeAndParse(100);e.check=t.toString()}return e},On=function(){const e=[t(this,Sn,"m",Mn).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(t(this,Sn,"m",Mn).call(this));return e},Mn=function(){const e={},i=t(this,Sn,"m",_n).call(this);if(i.includes(".")){const t=i.split(".");e.contextType="variable",e.context=t[0],e.element=t[1]}else e.context=i;return"="===this.parser.peek()?.value&&(this.parser.consume("="),t(this,Sn,"m",In).call(this,e)),"as"===this.parser.peek()?.value&&(this.parser.consume("Symbol","as"),e.variable=this.parser.consume().value),"first"!==this.parser.peek()?.value&&"share"!==this.parser.peek()?.value&&"last"!==this.parser.peek()?.value&&"collate"!==this.parser.peek()?.value||(e.listMode=[this.parser.consume().value]),e},In=function(e){e.transform="copy";const i=this.parser.consumeAndParse(6);if(i instanceof Bi)t(this,Sn,"m",Un).call(this,e,i);else if(i instanceof sn)t(this,Sn,"m",Ln).call(this,e,i);else{if(!(i instanceof Qi))throw new Error(`Unexpected FHIRPath: ${i}`);t(this,Sn,"m",Nn).call(this,e,i)}},Un=function(e,t){e.parameter=[{valueId:t.name}]},Ln=function(e,t){const i=t.name;switch(i){case"create":e.parameter=[{valueString:t.args?.[0].value.value}];break;case"translate":e.parameter=[{}];break;default:throw new Error("Unknown target function: "+i)}},Nn=function(e,t){switch(t.value.type){case"boolean":e.parameter=[{valueBoolean:t.value.value}];break;case"decimal":e.parameter=[{valueDecimal:t.value.value}];break;case"string":e.parameter=[{valueString:t.value.value}];break;default:throw new Error("Unknown target literal type: "+t.value.type)}},_n=function(){let e=this.parser.consume().value;for(;"."===this.parser.peek()?.value;)this.parser.consume("."),e+="."+this.parser.consume().value;return e},jn=function(){const e=this.parser.consumeAndParse(100);return[{name:e.name,variable:e.args.map((e=>e.name))}]},Wn=function(){for(;"}"!==this.parser.peek()?.value;)this.parser.consume();this.parser.consume("}")};const Bn=mn().registerInfix("->",{precedence:100}).registerInfix(";",{precedence:200});const $n=[...un,"eq","ne","co"];class qn{constructor(e,t,i){this.path=e,this.operator=t,this.value=i}}class Fn{constructor(e){this.child=e}}class Hn{constructor(e,t,i){this.keyword=e,this.left=t,this.right=i}}class zn{constructor(e){this.parser=e}parse(){let e;"("===this.parser.peek()?.value?(this.parser.consume("("),e=this.parse(),this.parser.consume(")")):"not"===this.parser.peek()?.value?(this.parser.consume("Symbol","not"),this.parser.consume("("),e=new Fn(this.parse()),this.parser.consume(")")):e=new qn(this.parser.consume("Symbol").value,this.parser.consume("Symbol").value,this.parser.consume().value);const t=this.parser.peek()?.value;return"and"===t||"or"===t?(this.parser.consume("Symbol",t),new Hn(t,e,this.parse())):e}}const Gn=mn();class Vn{constructor(e="\r",t="|",i="^",n="~",r="\\",o="&"){this.segmentSeparator=e,this.fieldSeparator=t,this.componentSeparator=i,this.repetitionSeparator=n,this.escapeCharacter=r,this.subcomponentSeparator=o}getMsh2(){return this.fieldSeparator+this.componentSeparator+this.repetitionSeparator+this.escapeCharacter+this.subcomponentSeparator}}class Xn{constructor(e,t=new Vn){this.context=t,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(this.context.segmentSeparator)}buildAck(){const e=new Date,t=this.get("MSH"),i=t?.get(2)?.toString()||"",n=t?.get(3)?.toString()||"",r=t?.get(4)?.toString()||"",o=t?.get(5)?.toString()||"",s=t?.get(9)?.toString()||"",a=t?.get(12)?.toString()||"2.5.1";return new Xn([new Jn(["MSH",this.context.getMsh2(),r,o,i,n,e.toISOString(),"","ACK",e.getTime().toString(),"P",a],this.context),new Jn(["MSA","AA",s,"OK"],this.context)])}static parse(e){if(!e.startsWith("MSH")){const e=new Error("Invalid HL7 message");throw e.type="entity.parse.failed",e}const t=new Vn("\r",e.charAt(3),e.charAt(4),e.charAt(5),e.charAt(6),e.charAt(7));return new Xn(e.split(/[\r\n]+/).map((e=>Jn.parse(e,t))),t)}}class Jn{constructor(e,t=new Vn){this.context=t,M(e)?this.fields=e.map((e=>Yn.parse(e))):this.fields=e,this.name=this.fields[0].components[0][0]}get(e){return this.fields[e]}toString(){return this.fields.map((e=>e.toString())).join(this.context.fieldSeparator)}static parse(e,t=new Vn){return new Jn(e.split(t.fieldSeparator).map((e=>Yn.parse(e,t))),t)}}class Yn{constructor(e,t=new Vn){this.context=t,this.components=e}get(e,t,i=0){let n=this.components[i][e]||"";return void 0!==t&&(n=n.split(this.context.subcomponentSeparator)[t]||""),n}toString(){return this.components.map((e=>e.join(this.context.componentSeparator))).join(this.context.repetitionSeparator)}static parse(e,t=new Vn){return new Yn(e.split(t.repetitionSeparator).map((e=>e.split(t.componentSeparator))),t)}}var Kn,Zn,er,tr,ir,nr,rr,or,sr,ar,cr,ur,lr,pr;const dr={base64Binary:"string",boolean:"boolean",canonical:"string",code:"string",date:"string",dateTime:"string",decimal:"number",id:"string",instant:"string",integer:"number",markdown:"string",oid:"string",positiveInt:"number",string:"string",time:"string",unsignedInt:"number",uri:"string",url:"string",uuid:"string",xhtml:"string","http://hl7.org/fhirpath/System.String":"string"},hr=new Set(["resourceType","id","meta","implicitRules","language","text","contained","extension","modifierExtension"]);function fr(e){const t=_e.types[e];return t&&t.structureDefinition.id===e&&"resource"===t.structureDefinition.kind}class mr{constructor(e){Kn.add(this),Zn.set(this,void 0),er.set(this,void 0),i(this,Zn,[],"f"),i(this,er,e,"f")}validate(){const e=t(this,er,"f");if(!e)throw new fe(pe("Resource is null"));const i=e.resourceType;if(!i)throw new fe(pe("Missing resource type"));if(yr(e,"",t(this,Zn,"f")),t(this,Kn,"m",tr).call(this,mi(e),i),t(this,Zn,"f").length>0)throw new fe({resourceType:"OperationOutcome",issue:t(this,Zn,"f")})}}function yr(e,t,i){null===e?i.push(gr(t,"Invalid null value")):Array.isArray(e)?function(e,t,i){for(let n=0;n<e.length;n++)void 0===e[n]?i.push(gr(`${t}[${n}]`,"Invalid undefined value")):yr(e[n],`${t}[${n}]`,i)}(e,t,i):"object"==typeof e&&function(e,t,i){for(const[n,r]of Object.entries(e))yr(r,`${t}${t?".":""}${n}`,i)}(e,t,i)}function gr(e,t){return{severity:"error",code:"structure",details:{text:t},expression:[e]}}var vr;function xr(t,i){let n=_e.types[t]?.searchParamsDetails?.[i.code];return n||(n=function(t,i){const n=i.code,r=function(e){return e.split("-").reduce(((e,t,i)=>e+(i?N(t):t)),"")}(n),o=Tr(t,i.expression)?.split(".");if(!o)return{columnName:r,type:e.SearchParameterType.TEXT};const s=Sr(i);let a,c,u=t,l=!1;for(let e=1;e<o.length;e++){if(a=Le(u,o[e]),!a)throw new Error(`Element definition not found for ${t} ${i.code}`);if("*"===a.max&&(l=!0),c=a.type?.[0].code,!c)return{columnName:r,type:s,array:l};e<o.length-1&&(u=wr(c)?Oe(a.path?.split(".")):c)}const p=Sr(i,c),d={columnName:r,type:p,elementDefinition:a,array:l};return function(e,t,i){const n=_e.types[e];n.searchParamsDetails||(n.searchParamsDetails={});n.searchParamsDetails[t]=i}(t,n,d),d}(t,i)),n}function wr(e){return"Element"===e||"BackboneElement"===e}function Sr(t,i){let n=e.SearchParameterType.TEXT;switch(t.type){case"date":n=i===e.PropertyType.dateTime||i===e.PropertyType.instant?e.SearchParameterType.DATETIME:e.SearchParameterType.DATE;break;case"number":n=e.SearchParameterType.NUMBER;break;case"quantity":n=e.SearchParameterType.QUANTITY;break;case"reference":n=e.SearchParameterType.REFERENCE;break;case"token":"boolean"===i&&(n=e.SearchParameterType.BOOLEAN)}return n}function Tr(e,t){const i=t.split(" | ");for(const t of i){if((n=t).includes(" as Period")||n.includes(" as SampledDate"))continue;const i=Er(t);if(i.startsWith(e+"."))return i}var n}function Er(e){let t=e.trim();t.startsWith("(")&&t.endsWith(")")&&(t=t.substring(1,t.length-1)),t.includes("[0]")&&(t=t.replaceAll("[0]",""));const i=[" != "," as ",".as(",".exists(",".where("];for(const e of i)t.includes(e)&&(t=t.substring(0,t.indexOf(e)));return t}Zn=new WeakMap,er=new WeakMap,Kn=new WeakSet,tr=function(e,i){const n=_e.types[e.type];if(!n)throw new fe(pe("Unknown type: "+e.type));const r=n.properties;t(this,Kn,"m",ir).call(this,i,r,e),t(this,Kn,"m",cr).call(this,i,e,r)},ir=function(e,i,n){for(const[r,o]of Object.entries(i))t(this,Kn,"m",nr).call(this,e+"."+r,o,n)},nr=function(e,i,n){const r=gi(n,e.split(".").pop());if(k(r))void 0!==i.min&&i.min>0&&t(this,Zn,"f").push(gr(e,"Missing required property"));else if("*"===i.max){if(!Array.isArray(r))return void t(this,Zn,"f").push(gr(e,"Expected array for property"));for(const n of r)t(this,Kn,"m",rr).call(this,e,i,n)}else t(this,Kn,"m",rr).call(this,e,i,r)},rr=function(e,i,n){null!==n.value&&(_(n.type.charAt(0))?t(this,Kn,"m",or).call(this,i,n):t(this,Kn,"m",tr).call(this,n,e))},or=function(e,i){const{type:n,value:r}=i;if(null===r)return;const o=dr[i.type];typeof r===o?"string"===o?t(this,Kn,"m",sr).call(this,e,n,r):"number"===o&&t(this,Kn,"m",ar).call(this,e,n,r):t(this,Kn,"m",pr).call(this,e,"Invalid type for "+n)},sr=function(e,i,n){if(!n.trim())return void t(this,Kn,"m",pr).call(this,e,"Invalid empty string");const r=_e.types[i]?.properties?.value;if(r?.type){const o=D(r.type[0],"http://hl7.org/fhir/StructureDefinition/regex");o&&(n.match(new RegExp(o))||t(this,Kn,"m",pr).call(this,e,"Invalid "+i+" format"))}},ar=function(i,n,r){var o;!isNaN(r)&&isFinite(r)?((o=n)!==e.PropertyType.integer&&o!==e.PropertyType.positiveInt&&o!==e.PropertyType.unsignedInt||Number.isInteger(r)||t(this,Kn,"m",pr).call(this,i,"Number is not an integer"),n===e.PropertyType.positiveInt&&r<=0&&t(this,Kn,"m",pr).call(this,i,"Number is less than or equal to zero"),n===e.PropertyType.unsignedInt&&r<0&&t(this,Kn,"m",pr).call(this,i,"Number is negative")):t(this,Kn,"m",pr).call(this,i,"Invalid "+n+" value")},cr=function(e,i,n){const r=i.value;for(const o of Object.keys(r))t(this,Kn,"m",ur).call(this,e,o,i,n)},ur=function(e,i,n,r){if(!(hr.has(i)||i in r||function(e,t,i){for(const n of Object.keys(i)){if(!n.endsWith("[x]"))continue;const i=n.replace("[x]","");if(!e.startsWith(i))continue;let r=gi(t,n);if(r&&(Array.isArray(r)&&(r=r[0]),r&&e===i+N(r.type)))return!0}return!1}(i,n,r)||t(this,Kn,"m",lr).call(this,e,i,n))){const n=`${e}.${i}`;t(this,Zn,"f").push(gr(n,`Invalid additional property "${n}"`))}},lr=function(e,i,n){if(!i.startsWith("_"))return!1;return i.slice(1)in n.value&&(t(this,Kn,"m",tr).call(this,{type:"Element",value:n.value[i]},e),!0)},pr=function(e,i){t(this,Zn,"f").push(gr(e.path,i))},e.SearchParameterType=void 0,(vr=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",vr.NUMBER="NUMBER",vr.QUANTITY="QUANTITY",vr.TEXT="TEXT",vr.REFERENCE="REFERENCE",vr.DATE="DATE",vr.DATETIME="DATETIME",vr.PERIOD="PERIOD";var br;e.Operator=void 0,(br=e.Operator||(e.Operator={})).EQUALS="eq",br.NOT_EQUALS="ne",br.GREATER_THAN="gt",br.LESS_THAN="lt",br.GREATER_THAN_OR_EQUALS="ge",br.LESS_THAN_OR_EQUALS="le",br.STARTS_AFTER="sa",br.ENDS_BEFORE="eb",br.APPROXIMATELY="ap",br.CONTAINS="contains",br.EXACT="exact",br.TEXT="text",br.NOT="not",br.ABOVE="above",br.BELOW="below",br.IN="in",br.NOT_IN="not-in",br.OF_TYPE="of-type",br.MISSING="missing";const Pr=[e.Operator.CONTAINS,e.Operator.EXACT,e.Operator.TEXT,e.Operator.NOT,e.Operator.ABOVE,e.Operator.BELOW,e.Operator.IN,e.Operator.NOT_IN,e.Operator.OF_TYPE,e.Operator.MISSING],Dr=[e.Operator.NOT_EQUALS,e.Operator.GREATER_THAN,e.Operator.LESS_THAN,e.Operator.GREATER_THAN_OR_EQUALS,e.Operator.LESS_THAN_OR_EQUALS,e.Operator.STARTS_AFTER,e.Operator.ENDS_BEFORE,e.Operator.APPROXIMATELY];function Ar(t,i,n){const r=_e.types[i.resourceType]?.searchParams?.[n.code];switch(r?.type){case"reference":return function(t,i,n){const r=vn(n.expression,t),o=Or(i.operator);if(""===i.value&&0===r.length)return i.operator===e.Operator.EQUALS;const s=r.map((e=>"string"==typeof e?e:e.reference));for(const e of i.value.split(",")){let t=s.includes(e);if(t||"_compartment"!==i.code||(t=s.some((t=>t?.endsWith("/"+e)))),t)return!o}return o}(t,n,r);case"string":return Cr(t,n,r);case"token":return function(t,i,n){const r=xr(t.resourceType,n);return r.type===e.SearchParameterType.BOOLEAN?function(e,t,i){const n=vn(i.expression,e),r="true"===t.value,o=n.includes(r);return Or(t.operator)?!o:o}(t,i,n):Cr(t,i,n,!0)}(t,n,r);case"date":return function(e,t,i){const n=vn(i.expression,e),r=t.value.split(","),o=Or(t.operator);for(const e of n)for(const i of r){if(Rr(e,t.operator,i))return!o}return o}(t,n,r)}return!1}function Cr(e,t,i,n){const r=vn(i.expression,e),o=t.value.split(","),s=Or(t.operator);for(const e of r)for(const i of o){if(kr(e,t.operator,i,n))return!s}return s}function kr(e,t,i,n){if(n&&i.includes("|")){const[n,r]=i.split("|");return kr(e,t,n,!1)&&(!r||kr(e,t,r,!1))}let r="";return e&&("string"==typeof e?r=e:"object"==typeof e&&(r=JSON.stringify(e))),r.toLowerCase().includes(i.toLowerCase())}function Rr(t,i,n){switch(i){case e.Operator.STARTS_AFTER:case e.Operator.GREATER_THAN:return t>n;case e.Operator.GREATER_THAN_OR_EQUALS:return t>=n;case e.Operator.ENDS_BEFORE:case e.Operator.LESS_THAN:return t<n;case e.Operator.LESS_THAN_OR_EQUALS:return t<=n;case e.Operator.EQUALS:case e.Operator.NOT_EQUALS:return t===n}return!1}function Or(t){return t===e.Operator.NOT_EQUALS||t===e.Operator.NOT}var Mr,Ir,Ur,Lr,Nr,_r,jr,Wr,Qr;const Br={eq:e.Operator.EQUALS,ne:e.Operator.NOT_EQUALS,lt:e.Operator.LESS_THAN,le:e.Operator.LESS_THAN_OR_EQUALS,gt:e.Operator.GREATER_THAN,ge:e.Operator.GREATER_THAN_OR_EQUALS,sa:e.Operator.STARTS_AFTER,eb:e.Operator.ENDS_BEFORE,ap:e.Operator.APPROXIMATELY},$r={contains:e.Operator.CONTAINS,exact:e.Operator.EXACT,above:e.Operator.ABOVE,below:e.Operator.BELOW,text:e.Operator.TEXT,not:e.Operator.NOT,in:e.Operator.IN,"not-in":e.Operator.NOT_IN,"of-type":e.Operator.OF_TYPE};class qr{constructor(e,i){Mr.add(this),this.resourceType=e,this.filters=[],this.sortRules=[];for(const[e,n]of Object.entries(i))Array.isArray(n)?n.forEach((i=>t(this,Mr,"m",Ir).call(this,e,i))):t(this,Mr,"m",Ir).call(this,e,n??"")}}function Fr(t){const i=t.substring(0,2);return i in Br?{operator:Br[i],value:t.substring(2)}:{operator:e.Operator.EQUALS,value:t}}function Hr(t){return $r[t]||e.Operator.EQUALS}Mr=new WeakSet,Ir=function(e,i){let n,r;const o=e.indexOf(":");switch(o>=0?(n=e.substring(0,o),r=e.substring(o+1)):(n=e,r=""),n){case"_sort":t(this,Mr,"m",Ur).call(this,i);break;case"_count":this.count=parseInt(i);break;case"_offset":this.offset=parseInt(i);break;case"_total":this.total=i;break;case"_summary":this.total="estimate",this.count=0;break;case"_revinclude":this.revInclude=i;break;default:{const e=_e.types[this.resourceType]?.searchParams?.[n];e?t(this,Mr,"m",Lr).call(this,e,r,i):t(this,Mr,"m",Qr).call(this,n,r,i)}}},Ur=function(e){for(const t of e.split(",")){let e,i=!1;t.startsWith("-")?(e=t.substring(1),i=!0):e=t,this.sortRules.push({code:e,descending:i})}},Lr=function(i,n,r){if("missing"!==n)switch(i.type){case"number":case"date":t(this,Mr,"m",Nr).call(this,i,r);break;case"string":case"token":case"uri":t(this,Mr,"m",_r).call(this,i,n,r);break;case"reference":t(this,Mr,"m",jr).call(this,i,r);break;case"quantity":t(this,Mr,"m",Wr).call(this,i,r)}else this.filters.push({code:i.code,operator:e.Operator.MISSING,value:r})},Nr=function(e,t){const{operator:i,value:n}=Fr(t);this.filters.push({code:e.code,operator:i,value:n})},_r=function(e,t,i){this.filters.push({code:e.code,operator:Hr(t),value:i})},jr=function(t,i){this.filters.push({code:t.code,operator:e.Operator.EQUALS,value:i})},Wr=function(e,t){const[i,n,r]=t.split("|"),{operator:o,value:s}=Fr(i);this.filters.push({code:e.code,operator:o,value:s,unitSystem:n,unitCode:r})},Qr=function(t,i,n){let r=e.Operator.EQUALS;if(i)r=i;else for(const e of Object.keys(Br))n.match(new RegExp("^"+e+"\\d"))&&(r=e,n=n.substring(e.length));this.filters.push({code:t,operator:r,value:n})},e.AndAtom=nn,e.ArithemticOperatorAtom=Hi,e.AsAtom=Fi,e.ConcatAtom=zi,e.ContainsAtom=Gi,e.DEFAULT_SEARCH_COUNT=20,e.DotAtom=Xi,e.EmptySetAtom=$i,e.EqualsAtom=Yi,e.EquivalentAtom=Zi,e.FHIRPATH_KEYWORDS=cn,e.FHIRPATH_OPERATORS=un,e.FhirFilterComparison=qn,e.FhirFilterConnective=Hn,e.FhirFilterNegation=Fn,e.FhirPathAtom=Wi,e.FhirSchemaValidator=mr,e.FunctionAtom=sn,e.Hl7Context=Vn,e.Hl7Field=Yn,e.Hl7Message=Xn,e.Hl7Segment=Jn,e.InAtom=Vi,e.IndexerAtom=an,e.InfixOperatorAtom=ci,e.IsAtom=tn,e.LRUCache=a,e.LiteralAtom=Qi,e.MEDPLUM_VERSION="2.0.6-c4b403f5",e.MedplumClient=class extends H{constructor(e){if(super(),je.add(this),We.set(this,void 0),Qe.set(this,void 0),Be.set(this,void 0),$e.set(this,void 0),qe.set(this,void 0),Fe.set(this,void 0),He.set(this,void 0),ze.set(this,void 0),Ge.set(this,void 0),Ve.set(this,void 0),Xe.set(this,void 0),Je.set(this,void 0),Ye.set(this,void 0),Ke.set(this,void 0),Ze.set(this,void 0),et.set(this,void 0),tt.set(this,void 0),it.set(this,void 0),nt.set(this,void 0),rt.set(this,void 0),ot.set(this,void 0),st.set(this,void 0),e?.baseUrl&&!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");i(this,We,e?.fetch||function(){if(!globalThis.fetch)throw new Error("Fetch not available in this environment");return globalThis.fetch.bind(globalThis)}(),"f"),i(this,Qe,e?.createPdf,"f"),i(this,Be,new Pe,"f"),i(this,$e,new a(e?.resourceCacheSize??1e3),"f"),i(this,qe,e?.cacheTime??6e4,"f"),i(this,Fe,function(e){if(!e)return e;return e.endsWith("/")?e:e+"/"}(e?.baseUrl)||"https://api.medplum.com/","f"),i(this,He,t(this,Fe,"f")+"fhir/R4/","f"),i(this,Ke,e?.clientId||"","f"),i(this,ze,e?.authorizeUrl||t(this,Fe,"f")+"oauth2/authorize","f"),i(this,Ge,e?.tokenUrl||t(this,Fe,"f")+"oauth2/token","f"),i(this,Ve,e?.logoutUrl||t(this,Fe,"f")+"oauth2/logout","f"),i(this,Xe,e?.onUnauthenticated,"f"),i(this,Je,e?.autoBatchTime??0,"f"),i(this,Ye,[],"f");const n=this.getActiveLogin();n&&(i(this,tt,n.accessToken,"f"),i(this,it,n.refreshToken,"f"),t(this,je,"m",ct).call(this).catch(console.log)),t(this,je,"m",bt).call(this)}getBaseUrl(){return t(this,Fe,"f")}clear(){t(this,Be,"f").clear(),this.clearActiveLogin()}clearActiveLogin(){t(this,Be,"f").setString("activeLogin",void 0),t(this,$e,"f").clear(),i(this,tt,void 0,"f"),i(this,it,void 0,"f"),i(this,ot,void 0,"f"),i(this,st,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(e){e=e.toString(),t(this,$e,"f").delete(e)}invalidateSearches(e){const i="fhir/R4/"+e;for(const e of t(this,$e,"f").keys())(e.endsWith(i)||e.includes(i+"?"))&&t(this,$e,"f").delete(e)}get(e,n={}){e=e.toString();const r=t(this,je,"m",ut).call(this,e,n);if(r)return r.value;let o;o=e.startsWith(t(this,He,"f"))&&t(this,Je,"f")>0?new Promise(((r,o)=>{t(this,Ye,"f").push({method:"GET",url:e.replace(t(this,He,"f"),""),options:n,resolve:r,reject:o}),t(this,et,"f")||i(this,et,setTimeout((()=>t(this,je,"m",mt).call(this)),t(this,Je,"f")),"f")})):t(this,je,"m",ht).call(this,"GET",e,n);const s=new be(o);return t(this,je,"m",lt).call(this,e,s),s}post(e,i,n,r={}){return e=e.toString(),i&&t(this,je,"m",vt).call(this,r,i),n&&t(this,je,"m",gt).call(this,r,n),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"POST",e,r)}put(e,i,n,r={}){return e=e.toString(),i&&t(this,je,"m",vt).call(this,r,i),n&&t(this,je,"m",gt).call(this,r,n),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"PUT",e,r)}patch(e,i,n={}){return e=e.toString(),t(this,je,"m",vt).call(this,n,i),t(this,je,"m",gt).call(this,n,"application/json-patch+json"),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"PATCH",e,n)}delete(e,i={}){return e=e.toString(),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"DELETE",e,i)}async startNewUser(e){const{codeChallengeMethod:t,codeChallenge:i}=await this.startPkce();return this.post("auth/newuser",{...e,codeChallengeMethod:t,codeChallenge:i})}async startNewProject(e){return this.post("auth/newproject",e)}async startNewPatient(e){return this.post("auth/newpatient",e)}async startLogin(e){return this.post("auth/login",{...await this.ensureCodeChallenge(e),clientId:e.clientId??t(this,Ke,"f"),scope:e.scope})}async startGoogleLogin(e){return this.post("auth/google",{...await this.ensureCodeChallenge(e),clientId:e.clientId??t(this,Ke,"f"),scope:e.scope})}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(t(this,Ve,"f"),{}),this.clear()}async signInWithRedirect(e){const i=new URLSearchParams(window.location.search).get("code");return i?this.processCode(i):void await t(this,je,"m",wt).call(this,e)}signOutWithRedirect(){window.location.assign(t(this,Ve,"f"))}async signInWithExternalAuth(e,t,i,n){const r=await this.ensureCodeChallenge(n);window.location.assign(this.getExternalAuthRedirectUri(e,t,i,r))}getExternalAuthRedirectUri(e,t,i,n){const r=new URL(e);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",t),r.searchParams.set("redirect_uri",i),r.searchParams.set("scope","openid profile email"),r.searchParams.set("state",JSON.stringify(n)),r.toString()}fhirUrl(...e){return new URL(t(this,He,"f")+e.join("/"))}fhirSearchUrl(e,t){const i=this.fhirUrl(e);return t&&(i.search=new URLSearchParams(t).toString()),i}search(e,i,n={}){const r=this.fhirSearchUrl(e,i),o=r.toString()+"-search",s=t(this,je,"m",ut).call(this,o,n);if(s)return s.value;const a=new be((async()=>{const e=await this.get(r,n);if(e.entry)for(const i of e.entry)t(this,je,"m",pt).call(this,i.resource);return e})());return t(this,je,"m",lt).call(this,o,a),a}searchOne(e,i,n={}){const r=this.fhirSearchUrl(e,i);r.searchParams.set("_count","1"),r.searchParams.sort();const o=r.toString()+"-searchOne",s=t(this,je,"m",ut).call(this,o,n);if(s)return s.value;const a=new be(this.search(e,r.searchParams,n).then((e=>e.entry?.[0]?.resource)));return t(this,je,"m",lt).call(this,o,a),a}searchResources(e,i,n={}){const r=this.fhirSearchUrl(e,i).toString()+"-searchResources",o=t(this,je,"m",ut).call(this,r,n);if(o)return o.value;const s=new be(this.search(e,i,n).then((e=>e.entry?.map((e=>e.resource))??[])));return t(this,je,"m",lt).call(this,r,s),s}searchValueSet(e,t,i={}){const n=this.fhirUrl("ValueSet","$expand");return n.searchParams.set("url",e),n.searchParams.set("filter",t),this.get(n.toString(),i)}getCached(e,i){const n=t(this,$e,"f").get(this.fhirUrl(e,i).toString())?.value;return n&&n.isOk()?n.read():void 0}getCachedReference(e){const t=e.reference;if(!t)return;if("system"===t)return Pt;const[i,n]=t.split("/");return i&&n?this.getCached(i,n):void 0}readResource(e,t,i={}){return this.get(this.fhirUrl(e,t),i)}readReference(e,t={}){const i=e?.reference;if(!i)return new be(Promise.reject(new Error("Missing reference")));if("system"===i)return new be(Promise.resolve(Pt));const[n,r]=i.split("/");return n&&r?this.readResource(n,r,t):new be(Promise.reject(new Error("Invalid reference")))}getSchema(){return _e}requestSchema(e){if(e in _e.types)return Promise.resolve(_e);const i=e+"-requestSchema",n=t(this,je,"m",ut).call(this,i,void 0);if(n)return n.value;const r=new be((async()=>{const t=`{\n StructureDefinitionList(name: "${e}") {\n name,\n description,\n snapshot {\n element {\n id,\n path,\n min,\n max,\n type {\n code,\n targetProfile\n },\n binding {\n valueSet\n },\n definition\n }\n }\n }\n SearchParameterList(base: "${e}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),i=await this.graphql(t);for(const e of i.data.StructureDefinitionList)ke(e);for(const e of i.data.SearchParameterList)Re(e);return _e})());return t(this,je,"m",lt).call(this,i,r),r}readHistory(e,t,i={}){return this.get(this.fhirUrl(e,t,"_history"),i)}readVersion(e,t,i,n={}){return this.get(this.fhirUrl(e,t,"_history",i),n)}readPatientEverything(e,t={}){return this.get(this.fhirUrl("Patient",e,"$everything"),t)}createResource(e){if(!e.resourceType)throw new Error("Missing resourceType");return this.invalidateSearches(e.resourceType),this.post(this.fhirUrl(e.resourceType),e)}async createResourceIfNoneExist(e,t){return await this.searchOne(e.resourceType,t)??this.createResource(e)}createBinary(e,t,i,n){const r=this.fhirUrl("Binary");return t&&r.searchParams.set("_filename",t),n?this.uploadwithProgress(r,e,i,n):this.post(r,e,i)}uploadwithProgress(e,i,n,r){return new Promise(((o,s)=>{const a=new XMLHttpRequest;a.responseType="json",a.onabort=()=>s(new Error("Request aborted")),a.onerror=()=>s(new Error("Request error")),r&&(a.upload.onprogress=e=>r(e),a.upload.onload=e=>r(e)),a.onload=()=>{a.status>=200&&a.status<300?o(a.response):s(new Error(a.statusText))},a.open("POST",e),a.withCredentials=!0,a.setRequestHeader("Authorization","Bearer "+t(this,tt,"f")),a.setRequestHeader("Cache-Control","no-cache, no-store, max-age=0"),a.setRequestHeader("Content-Type",n),a.setRequestHeader("X-Medplum","extended"),a.send(i)}))}async createPdf(e,i,n,r){if(!t(this,Qe,"f"))throw new Error("PDF creation not enabled");const o=await t(this,Qe,"f").call(this,e,n,r);return this.createBinary(o,i,"application/pdf")}createComment(e,t){const i=this.getProfile();let n,r;return"Encounter"===e.resourceType&&(n=x(e),r=e.subject),"ServiceRequest"===e.resourceType&&(n=e.encounter,r=e.subject),"Patient"===e.resourceType&&(r=x(e)),this.createResource({resourceType:"Communication",basedOn:[x(e)],encounter:n,subject:r,sender:i?x(i):void 0,sent:(new Date).toISOString(),payload:[{contentString:t}]})}async updateResource(e){if(!e.resourceType)throw new Error("Missing resourceType");if(!e.id)throw new Error("Missing id");this.invalidateSearches(e.resourceType);let i=await this.put(this.fhirUrl(e.resourceType,e.id),e);return i||(i=e),t(this,je,"m",pt).call(this,i),i}patchResource(e,t,i){return this.invalidateSearches(e),this.patch(this.fhirUrl(e,t),i)}deleteResource(e,i){return t(this,je,"m",dt).call(this,this.fhirUrl(e,i).toString()),this.invalidateSearches(e),this.delete(this.fhirUrl(e,i))}validateResource(e){return this.post(this.fhirUrl(e.resourceType,"$validate"),e)}executeBatch(e){return this.post("fhir/R4",e)}sendEmail(e){return this.post("email/v1/send",e,"application/json")}graphql(e,t,i,n){return this.post(this.fhirUrl("$graphql"),{query:e,operationName:t,variables:i},"application/json",n)}readResourceGraph(e,t,i){return this.get(`${this.fhirUrl(e,t)}/$graph?graph=${i}`)}getActiveLogin(){return t(this,Be,"f").getObject("activeLogin")}async setActiveLogin(e){this.clearActiveLogin(),i(this,tt,e.accessToken,"f"),i(this,it,e.refreshToken,"f"),t(this,Be,"f").setObject("activeLogin",e),t(this,je,"m",at).call(this,e),i(this,nt,void 0,"f"),await t(this,je,"m",ct).call(this)}getAccessToken(){return t(this,tt,"f")}setAccessToken(e){i(this,tt,e,"f"),i(this,it,void 0,"f"),i(this,ot,void 0,"f"),i(this,st,void 0,"f")}getLogins(){return t(this,Be,"f").getObject("logins")??[]}isLoading(){return!!t(this,rt,"f")}getProfile(){return t(this,ot,"f")}async getProfileAsync(){return t(this,rt,"f")&&await t(this,rt,"f"),this.getProfile()}getUserConfiguration(){return t(this,st,"f")}async download(e,i={}){t(this,nt,"f")&&await t(this,nt,"f"),t(this,je,"m",yt).call(this,i);return(await t(this,We,"f").call(this,e.toString(),i)).blob()}async startPkce(){const e=q();sessionStorage.setItem("pkceState",e);const t=q();sessionStorage.setItem("codeVerifier",t);const i=L(await async function(e){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}(t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");return sessionStorage.setItem("codeChallenge",i),{codeChallengeMethod:"S256",codeChallenge:i}}processCode(e){const i=new URLSearchParams;if(i.set("grant_type","authorization_code"),i.set("client_id",t(this,Ke,"f")),i.set("code",e),i.set("redirect_uri",Dt()),"undefined"!=typeof sessionStorage){const e=sessionStorage.getItem("codeVerifier");e&&i.set("code_verifier",e)}return t(this,je,"m",Tt).call(this,i)}async startClientLogin(e,n){i(this,Ke,e,"f"),i(this,Ze,n,"f");const r=new URLSearchParams;return r.set("grant_type","client_credentials"),r.set("client_id",e),r.set("client_secret",n),t(this,je,"m",Tt).call(this,r)}},e.NotEqualsAtom=Ki,e.NotEquivalentAtom=en,e.OperationOutcomeError=fe,e.OrAtom=rn,e.Parser=li,e.ParserBuilder=ui,e.PrefixOperatorAtom=ai,e.ReadablePromise=be,e.SymbolAtom=Bi,e.Tokenizer=di,e.UnaryOperatorAtom=qi,e.UnionAtom=Ji,e.XorAtom=on,e.allOk=ie,e.arrayBufferToBase64=L,e.arrayBufferToHex=U,e.assertOk=function(e,t){if(!he(e)||void 0===t)throw new fe(e)},e.badRequest=le,e.booleanToTypedValue=fi,e.buildTypeName=Oe,e.calculateAge=b,e.calculateAgeString=function(e,t){const{years:i,months:n,days:r}=b(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"},e.capitalize=N,e.checkForNull=yr,e.createReference=x,e.createStructureIssue=gr,e.created=ne,e.deepClone=function(e){return JSON.parse(JSON.stringify(e))},e.deepEquals=R,e.evalFhirPath=vn,e.evalFhirPathTyped=xn,e.fhirPathArrayEquals=Si,e.fhirPathArrayEquivalent=Ei,e.fhirPathEquals=Ti,e.fhirPathEquivalent=bi,e.fhirPathIs=Di,e.fhirPathNot=wi,e.findObservationInterval=function(e,t,i,n){return e.qualifiedInterval?.find((r=>j(r,t)&&function(e,t,i){return!!e.range&&W(t,e.range,i)}(r,i,e.quantitativeDetails?.decimalPrecision)&&(void 0===n||r.category===n)))},e.findObservationReferenceRange=function(e,t,i){return e.qualifiedInterval?.find((e=>j(e,t)&&i.includes(e.condition)))},e.forbidden=ae,e.formatAddress=function(e,t){const i=[];if(e.line&&i.push(...e.line),e.city||e.state||e.postalCode){const t=[];e.city&&t.push(e.city),e.state&&t.push(e.state),e.postalCode&&t.push(e.postalCode),i.push(t.join(", "))}return e.use&&(t?.all||t?.use)&&i.push("["+e.use+"]"),i.join(t?.lineSeparator||", ").trim()},e.formatCodeableConcept=y,e.formatCoding=g,e.formatDate=function(e,t,i){if(!e)return"";const n=new Date(e);return u(n)?(n.setUTCHours(0,0,0,0),n.toLocaleDateString(t,{timeZone:"UTC",...i})):""},e.formatDateTime=p,e.formatFamilyName=function(e){return e.family||""},e.formatGivenName=function(e){const t=[];return e.given&&t.push(...e.given),t.join(" ").trim()},e.formatHumanName=c,e.formatMoney=function(e){return void 0===e?.value?"":e.value.toLocaleString(void 0,{style:"currency",currency:e.currency||"USD",currencyDisplay:"narrowSymbol"})},e.formatObservationValue=function e(t){return t?"component"in t?t.component.map((t=>e(t))).join(" / "):t?.valueQuantity?m(t.valueQuantity):t.valueCodeableConcept?y(t.valueCodeableConcept):t.valueString?t.valueString:"":""},e.formatPeriod=function(e,t,i){return e&&(e.start||e.end)?p(e.start,t,i)+" - "+p(e.end,t,i):""},e.formatQuantity=m,e.formatRange=function(e,t,i=!1){if(i&&void 0===t)throw new Error("Precision must be specified for exclusive ranges");const n=e?.low&&{...e.low},r=e?.high&&{...e.high};return!e||void 0===n?.value&&void 0===r?.value?"":void 0!==e.low?.value&&void 0===e.high?.value?i&&void 0!==t?(e.low.value=function(e,t,i=1){return(v(e,t)-i)*Math.pow(10,-t)}(e.low.value,t),`> ${m(e.low,t)}`):`>= ${m(e.low,t)}`:void 0===e.low?.value&&void 0!==e.high?.value?i&&void 0!==t?(e.high.value=function(e,t,i=1){return(v(e,t)+i)*Math.pow(10,-t)}(e.high.value,t),`< ${m(e.high,t)}`):`<= ${m(e.high,t)}`:(n?.unit===r?.unit&&delete n?.unit,`${m(n,t)} - ${m(r,t)}`)},e.formatSearchQuery=function(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>t.push(function(e){const t=Pr.includes(e.operator)?":"+e.operator:"",i=Dr.includes(e.operator)?e.operator:"";return`${e.code}${t}=${i}${encodeURIComponent(e.value)}`}(e)))),e.sortRules&&e.sortRules.length>0&&t.push("_sort="+e.sortRules.map((e=>e.descending?"-"+e.code:e.code)).join(",")),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="+e.total),0===t.length?"":(t.sort(),"?"+t.join("&"))},e.formatTime=l,e.formatTiming=function(e){if(!e)return"";const t=[];if(e.repeat?.periodUnit){const i=e.repeat.frequency||1,n=e.repeat.period||1,r=e.repeat.periodUnit;1===i&&1===n?t.push(d[r]):(1===i?t.push("once"):t.push(i+" times"),1===n?t.push("per "+h[r]):t.push("per "+n+" "+f[r])),e.repeat.dayOfWeek&&t.push("on "+e.repeat.dayOfWeek.map(N).join(", ")),e.repeat.timeOfDay&&t.push("at "+e.repeat.timeOfDay.map((e=>l(e))).join(", "))}return e.event&&t.push(e.event.map((e=>p(e))).join(", ")),N(t.join(" ").trim())},e.getCodeBySystem=function(e,t){return e?.coding?.find((e=>e.system===t))?.code},e.getDateProperty=function(e){return e?new Date(e):void 0},e.getDisplayString=T,e.getElementDefinition=Le,e.getElementDefinitionTypeName=function(e){const t=e.type?.[0]?.code;return"BackboneElement"===t||"Element"===t?Oe(e.path?.split(".")):t},e.getExpressionForResourceType=Tr,e.getExtension=function(e,...t){let i=e;for(let e=0;e<t.length&&i;e++)i=i?.extension?.find((i=>i.url===t[e]));return i},e.getExtensionValue=D,e.getIdentifier=function(e,t){const i=e.identifier;if(!i)return;const n=Array.isArray(i)?i:[i];for(const e of n)if(e.system===t)return e.value},e.getImageSrc=function(e){if(!("photo"in e))return;const t=e.photo;if(t){if(!Array.isArray(t))return E(t);for(const e of t){const t=E(e);if(t)return t}}},e.getPropertyDisplayName=function(e){return e.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(Ue).join(" ").replace("_"," ").replace(/\s+/g," ")},e.getQuestionnaireAnswers=function(e){const t={};return P(e.item,t),t},e.getReferenceString=w,e.getResourceTypeSchema=function(e){return _e.types[e]},e.getResourceTypes=function(){const e=[];for(const[t,i]of Object.entries(_e.types))Me(i)&&e.push(t);return e},e.getSearchParameterDetails=xr,e.getSearchParameters=function(e){return _e.types[e].searchParams},e.getStatus=function(e){return e.id===V?200:e.id===X?201:e.id===Y?304:e.id===Z?401:e.id===ee?403:e.id===K?404:e.id===J?410:e.id===te?429:400},e.getTypedPropertyValue=gi,e.globalSchema=_e,e.gone=ce,e.indexSearchParameter=Re,e.indexSearchParameterBundle=function(e){for(const t of e.entry){const e=t.resource;"SearchParameter"===e.resourceType&&Re(e)}},e.indexStructureDefinition=ke,e.indexStructureDefinitionBundle=function(e){for(const t of e.entry){const e=t.resource;"StructureDefinition"===e.resourceType&&ke(e)}},e.initFhirPathParserBuilder=mn,e.isEmpty=k,e.isGone=function(e){return e.id===J},e.isLowerCase=_,e.isNotFound=function(e){return e.id===K},e.isObject=O,e.isOk=he,e.isOperationOutcome=de,e.isPeriod=Ai,e.isProfileResource=S,e.isQuantity=Ci,e.isQuantityEquivalent=ki,e.isReference=function(e){return!(!e||"object"!=typeof e||!("reference"in e))},e.isResource=Ne,e.isResourceType=fr,e.isResourceTypeSchema=Me,e.isStringArray=M,e.isUUID=function(e){return!!e.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)},e.isValidDate=u,e.matchesRange=W,e.matchesSearchRequest=function(e,t){if(t.resourceType!==e.resourceType)return!1;if(t.filters)for(const i of t.filters)if(!Ar(e,t,i))return!1;return!0},e.normalizeErrorString=ye,e.normalizeOperationOutcome=me,e.notFound=oe,e.notModified=re,e.parseFhirPath=gn,e.parseFilterParameter=function(e){const t=Gn.construct(new di(e,cn,$n,{dateTimeLiterals:!0,symbolRegex:/[^\s\])]/}).tokenize());return t.removeComments(),new zn(t).parse()},e.parseJWTPayload=G,e.parseMappingLanguage=function(e){const t=Bn.construct(new di(e,cn,wn).tokenize());return t.removeComments(),new Qn(t).parse()},e.parseSearchDefinition=function(t){const i=new URL(t,"https://example.com/"),n=i.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let r,o,s,a,c,u;return new URLSearchParams(i.search).forEach(((t,i)=>{"_fields"===i?s=t.split(","):"_offset"===i?a=parseInt(t):"_count"===i?c=parseInt(t):"_total"===i?u=t:"_sort"===i?(o=o||[],o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(t))):(r=r||[],r.push(function(t,i){let n=t,r=e.Operator.EQUALS;for(const e of Pr){const t=n.indexOf(":"+e);-1!==t&&(r=e,n=n.substring(0,t))}for(const e of Dr)i.match(new RegExp("^"+e+"\\d"))&&(r=e,i=i.substring(e.length));return{code:n,operator:r,value:i}}(i,t)))})),{resourceType:n,filters:r,fields:s,offset:a,count:c,total:u,sortRules:o}},e.parseSearchRequest=function(e,t){return new qr(e,t)},e.parseSearchUrl=function(e){const t=e.pathname.split("/").pop();return new qr(t,Object.fromEntries(e.searchParams.entries()))},e.preciseEquals=function(e,t,i){return $(e,i)===$(t,i)},e.preciseGreaterThan=function(e,t,i){return $(e,i)>$(t,i)},e.preciseGreaterThanOrEquals=B,e.preciseLessThan=function(e,t,i){return $(e,i)<$(t,i)},e.preciseLessThanOrEquals=Q,e.preciseRound=function(e,t){return parseFloat(e.toFixed(t))},e.removeDuplicates=xi,e.resolveId=function(e){return e?.reference?.split("/")[1]},e.setCodeBySystem=function(e,t,i){e.coding||(e.coding=[]);const n=e.coding?.find((e=>e.system===t));n?n.code=i:e.coding?.push({system:t,code:i})},e.stringify=A,e.toJsBoolean=yi,e.toTypedValue=mi,e.tokenize=ln,e.tooManyRequests=ue,e.unauthorized=se,e.validateResource=function(e){new mr(e).validate()},e.validateResourceType=function(e){if(!e)throw new fe(pe("Resource type is null"));if(!fr(e))throw new fe(pe("Unknown resource type"))},e.validationError=pe}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).medplum=e.medplum||{},e.medplum.core={}))}(this,(function(e){"use strict";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)}keys(){return t(this,o,"f").keys()}}function c(e,t){const i=[];return e.prefix&&!1!==t?.prefix&&i.push(...e.prefix),e.given&&i.push(...e.given),e.family&&i.push(e.family),e.suffix&&!1!==t?.suffix&&i.push(...e.suffix),e.use&&(t?.all||t?.use)&&i.push("["+e.use+"]"),i.join(" ").trim()}function u(e){return e instanceof Date&&!isNaN(e.getTime())}function l(e,t,i){if(!e)return"";const n=new Date("2000-01-01T"+e+"Z");return u(n)?n.toLocaleTimeString(t,i):""}function p(e,t,i){if(!e)return"";const n=new Date(e);return u(n)?n.toLocaleString(t,i):""}r=new WeakMap,o=new WeakMap,n=new WeakSet,s=function(){return t(this,o,"f").keys().next().value};const d={s:"every second",min:"every minute",h:"hourly",d:"daily",wk:"weekly",mo:"monthly",a:"annually"},h={s:"second",min:"minute",h:"hour",d:"day",wk:"week",mo:"month",a:"year"},f={s:"seconds",min:"minutes",h:"hours",d:"days",wk:"weeks",mo:"months",a:"years"};function m(e,t){if(!e)return"";const i=[];return e.comparator&&(i.push(e.comparator),i.push(" ")),void 0!==e.value&&(void 0!==t?i.push(e.value.toFixed(t)):i.push(e.value)),e.unit&&("%"!==e.unit&&" "!==i[i.length-1]&&i.push(" "),i.push(e.unit)),i.join("").trim()}function y(e){return e?e.text?e.text:e.coding?e.coding.map((e=>g(e))).join(", "):"":""}function g(e){return e?.display||e?.code||""}function v(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function x(e){const t=w(e),i=T(e);return i===t?{reference:t}:{reference:t,display:i}}function w(e){return e.resourceType+"/"+e.id}function S(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function T(e){if(S(e)){const t=function(e){const t=e.name;if(t&&t.length>0)return c(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&&e.code?.text?e.code.text:"User"===e.resourceType&&e.email?e.email:"name"in e&&e.name&&"string"==typeof e.name?e.name:w(e)}function E(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function b(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 p=12*a+c-(12*r+o);u<s&&p--;return{years:l,months:p,days:Math.floor((n.getTime()-i.getTime())/864e5)}}function P(e,t){if(e)for(const i of e)i.linkId&&i.answer&&i.answer.length>0&&(t[i.linkId]=i.answer[0]),P(i.item,t)}function D(e,...t){let i=e;for(let e=0;e<t.length&&i;e++)i=i?.extension?.find((i=>i.url===t[e]));return i?.valueString}function A(e,t){return JSON.stringify(e,C,t?2:void 0)}function C(e,t){return!function(e){return!!e.match(/\d+$/)}(e)&&k(t)?void 0:t}function k(e){if(null==e)return!0;const t=typeof e;return"string"===t&&""===e||"object"===t&&0===Object.keys(e).length}function R(e,t,i){return e===t||(!(!k(e)||!k(t))||!k(e)&&!k(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(!R(e[i],t[i]))return!1;return!0}(e,t):!Array.isArray(e)&&!Array.isArray(t)&&(O(e)&&O(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(!R(e[i],t[i],i))return!1}return!0}(e,t,i):(O(e)||O(t),!1))))}function O(e){return null!==e&&"object"==typeof e}function M(e){return e.every((e=>"string"==typeof e))}const I=[];for(let e=0;e<256;e++)I.push(e.toString(16).padStart(2,"0"));function U(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 L(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 N(e){return e.charAt(0).toUpperCase()+e.substring(1)}function _(e){return e===e.toLowerCase()&&e!==e.toUpperCase()}function j(e,t){return function(e,t){return!e.gender||e.gender===t.gender}(e,t)&&function(e,t){return!e.age||W(b(t.birthDate).years,e.age)}(e,t)}function W(e,t,i){return(void 0===t.low?.value||B(e,t.low.value,i))&&(void 0===t.high?.value||Q(e,t.high.value,i))}function Q(e,t,i){return $(e,i)<=$(t,i)}function B(e,t,i){return $(e,i)>=$(t,i)}function $(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function q(){const e=new Uint32Array(28);return crypto.getRandomValues(e),U(e.buffer)}var F;class H{constructor(){F.set(this,void 0),i(this,F,{},"f")}addEventListener(e,i){t(this,F,"f")[e]||(t(this,F,"f")[e]=[]),t(this,F,"f")[e].push(i)}removeEventListeneer(e,i){const n=t(this,F,"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,F,"f")[e.type];return i&&i.forEach((t=>t.call(this,e))),!e.defaultPrevented}}function z(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)}function G(e){const[t,i,n]=e.split(".");return z(i)}F=new WeakMap;const V="ok",X="created",J="gone",Y="not-modified",K="not-found",Z="unauthorized",ee="forbidden",te="too-many-requests",ie={resourceType:"OperationOutcome",id:V,issue:[{severity:"information",code:"informational",details:{text:"All OK"}}]},ne={resourceType:"OperationOutcome",id:X,issue:[{severity:"information",code:"informational",details:{text:"Created"}}]},re={resourceType:"OperationOutcome",id:Y,issue:[{severity:"information",code:"informational",details:{text:"Not Modified"}}]},oe={resourceType:"OperationOutcome",id:K,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},se={resourceType:"OperationOutcome",id:Z,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},ae={resourceType:"OperationOutcome",id:ee,issue:[{severity:"error",code:"forbidden",details:{text:"Forbidden"}}]},ce={resourceType:"OperationOutcome",id:J,issue:[{severity:"error",code:"deleted",details:{text:"Gone"}}]},ue={resourceType:"OperationOutcome",id:te,issue:[{severity:"error",code:"throttled",details:{text:"Too Many Requests"}}]};function le(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}}function pe(e){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"structure",details:{text:e}}]}}function de(e){return"object"==typeof e&&null!==e&&"OperationOutcome"===e.resourceType}function he(e){return e.id===V||e.id===X||e.id===Y}class fe extends Error{constructor(e,t){super(e?.issue?.[0].details?.text),this.outcome=e,this.cause=t}}function me(e){return e instanceof fe?e.outcome:de(e)?e:le(ye(e))}function ye(e){return e?"string"==typeof e?e:e instanceof Error?e.message:de(e)?e.issue?.[0]?.details?.text??"Unknown error":JSON.stringify(e):"Unknown error"}var ge,ve,xe,we,Se,Te,Ee;class be{constructor(e){this[Se]="ReadablePromise",ge.set(this,void 0),ve.set(this,"pending"),xe.set(this,void 0),we.set(this,void 0),i(this,ge,e.then((e=>(i(this,ve,"success","f"),i(this,xe,e,"f"),e)),(e=>{throw i(this,ve,"error","f"),i(this,we,e,"f"),e})),"f")}isPending(){return"pending"===t(this,ve,"f")}isOk(){return"success"===t(this,ve,"f")}read(){switch(t(this,ve,"f")){case"pending":throw t(this,ge,"f");case"error":throw t(this,we,"f");default:return t(this,xe,"f")}}then(e,i){return t(this,ge,"f").then(e,i)}catch(e){return t(this,ge,"f").catch(e)}finally(e){return t(this,ge,"f").finally(e)}}ge=new WeakMap,ve=new WeakMap,xe=new WeakMap,we=new WeakMap,Se=Symbol.toStringTag;class Pe{constructor(){Te.set(this,void 0),i(this,Te,"undefined"!=typeof localStorage?localStorage:new De,"f")}clear(){t(this,Te,"f").clear()}getString(e){return t(this,Te,"f").getItem(e)||void 0}setString(e,i){i?t(this,Te,"f").setItem(e,i):t(this,Te,"f").removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?A(t):void 0)}}Te=new WeakMap;class De{constructor(){Ee.set(this,void 0),i(this,Ee,new Map,"f")}get length(){return t(this,Ee,"f").size}clear(){t(this,Ee,"f").clear()}getItem(e){return t(this,Ee,"f").get(e)??null}setItem(e,i){i?t(this,Ee,"f").set(e,i):t(this,Ee,"f").delete(e)}removeItem(e){t(this,Ee,"f").delete(e)}key(e){return Array.from(t(this,Ee,"f").keys())[e]}}Ee=new WeakMap;var Ae,Ce={types:{Element:{display:"Element",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]}}},BackboneElement:{display:"BackboneElement",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]}}},Address:{display:"Address",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"code"}]},text:{type:[{code:"string"}]},line:{max:"*",type:[{code:"string"}]},city:{type:[{code:"string"}]},district:{type:[{code:"string"}]},state:{type:[{code:"string"}]},postalCode:{type:[{code:"string"}]},country:{type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Age:{display:"Age",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Annotation:{display:"Annotation",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},"author[x]":{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Organization"]},{code:"string"}]},time:{type:[{code:"dateTime"}]},text:{min:1,type:[{code:"markdown"}]}}},Attachment:{display:"Attachment",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},contentType:{type:[{code:"code"}]},language:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]},url:{type:[{code:"url"}]},size:{type:[{code:"unsignedInt"}]},hash:{type:[{code:"base64Binary"}]},title:{type:[{code:"string"}]},creation:{type:[{code:"dateTime"}]}}},CodeableConcept:{display:"CodeableConcept",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},coding:{max:"*",type:[{code:"Coding"}]},text:{type:[{code:"string"}]}}},Coding:{display:"Coding",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},system:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},code:{type:[{code:"code"}]},display:{type:[{code:"string"}]},userSelected:{type:[{code:"boolean"}]}}},ContactDetail:{display:"ContactDetail",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},name:{type:[{code:"string"}]},telecom:{max:"*",type:[{code:"ContactPoint"}]}}},ContactPoint:{display:"ContactPoint",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},system:{type:[{code:"code"}]},value:{type:[{code:"string"}]},use:{type:[{code:"code"}]},rank:{type:[{code:"positiveInt"}]},period:{type:[{code:"Period"}]}}},Contributor:{display:"Contributor",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{min:1,type:[{code:"string"}]},contact:{max:"*",type:[{code:"ContactDetail"}]}}},Count:{display:"Count",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},DataRequirement:{display:"DataRequirement",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},profile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},"subject[x]":{type:[{code:"CodeableConcept"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Group"]}]},mustSupport:{max:"*",type:[{code:"string"}]},codeFilter:{max:"*",type:[{code:"Element"}]},dateFilter:{max:"*",type:[{code:"Element"}]},limit:{type:[{code:"positiveInt"}]},sort:{max:"*",type:[{code:"Element"}]}}},DataRequirementCodeFilter:{display:"DataRequirementCodeFilter",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]},code:{max:"*",type:[{code:"Coding"}]}}},DataRequirementDateFilter:{display:"DataRequirementDateFilter",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{type:[{code:"string"}]},searchParam:{type:[{code:"string"}]},"value[x]":{type:[{code:"dateTime"},{code:"Period"},{code:"Duration"}]}}},DataRequirementSort:{display:"DataRequirementSort",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},direction:{min:1,type:[{code:"code"}]}}},Distance:{display:"Distance",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Dosage:{display:"Dosage",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},sequence:{type:[{code:"integer"}]},text:{type:[{code:"string"}]},additionalInstruction:{max:"*",type:[{code:"CodeableConcept"}]},patientInstruction:{type:[{code:"string"}]},timing:{type:[{code:"Timing"}]},"asNeeded[x]":{type:[{code:"boolean"},{code:"CodeableConcept"}]},site:{type:[{code:"CodeableConcept"}]},route:{type:[{code:"CodeableConcept"}]},method:{type:[{code:"CodeableConcept"}]},doseAndRate:{max:"*",type:[{code:"Element"}]},maxDosePerPeriod:{type:[{code:"Ratio"}]},maxDosePerAdministration:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},maxDosePerLifetime:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},DosageDoseAndRate:{display:"DosageDoseAndRate",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{type:[{code:"CodeableConcept"}]},"dose[x]":{type:[{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},"rate[x]":{type:[{code:"Ratio"},{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Duration:{display:"Duration",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},ElementDefinition:{display:"ElementDefinition",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},representation:{max:"*",type:[{code:"code"}]},sliceName:{type:[{code:"string"}]},sliceIsConstraining:{type:[{code:"boolean"}]},label:{type:[{code:"string"}]},code:{max:"*",type:[{code:"Coding"}]},slicing:{type:[{code:"Element"}]},short:{type:[{code:"string"}]},definition:{type:[{code:"markdown"}]},comment:{type:[{code:"markdown"}]},requirements:{type:[{code:"markdown"}]},alias:{max:"*",type:[{code:"string"}]},min:{type:[{code:"unsignedInt"}]},max:{type:[{code:"string"}]},base:{type:[{code:"Element"}]},contentReference:{type:[{code:"uri"}]},type:{max:"*",type:[{code:"Element"}]},"defaultValue[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},meaningWhenMissing:{type:[{code:"markdown"}]},orderMeaning:{type:[{code:"string"}]},"fixed[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},"pattern[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]},example:{max:"*",type:[{code:"Element"}]},"minValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},"maxValue[x]":{type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},maxLength:{type:[{code:"integer"}]},condition:{max:"*",type:[{code:"id"}]},constraint:{max:"*",type:[{code:"Element"}]},mustSupport:{type:[{code:"boolean"}]},isModifier:{type:[{code:"boolean"}]},isModifierReason:{type:[{code:"string"}]},isSummary:{type:[{code:"boolean"}]},binding:{type:[{code:"Element"}]},mapping:{max:"*",type:[{code:"Element"}]}}},ElementDefinitionSlicing:{display:"ElementDefinitionSlicing",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},discriminator:{max:"*",type:[{code:"Element"}]},description:{type:[{code:"string"}]},ordered:{type:[{code:"boolean"}]},rules:{min:1,type:[{code:"code"}]}}},ElementDefinitionSlicingDiscriminator:{display:"ElementDefinitionSlicingDiscriminator",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},path:{min:1,type:[{code:"string"}]}}},ElementDefinitionBase:{display:"ElementDefinitionBase",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},path:{min:1,type:[{code:"string"}]},min:{min:1,type:[{code:"unsignedInt"}]},max:{min:1,type:[{code:"string"}]}}},ElementDefinitionType:{display:"ElementDefinitionType",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},code:{min:1,type:[{code:"uri"}]},profile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},targetProfile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},aggregation:{max:"*",type:[{code:"code"}]},versioning:{type:[{code:"code"}]}}},ElementDefinitionExample:{display:"ElementDefinitionExample",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},label:{min:1,type:[{code:"string"}]},"value[x]":{min:1,type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},ElementDefinitionConstraint:{display:"ElementDefinitionConstraint",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},key:{min:1,type:[{code:"id"}]},requirements:{type:[{code:"string"}]},severity:{min:1,type:[{code:"code"}]},human:{min:1,type:[{code:"string"}]},expression:{type:[{code:"string"}]},xpath:{type:[{code:"string"}]},source:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},ElementDefinitionBinding:{display:"ElementDefinitionBinding",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},strength:{min:1,type:[{code:"code"}]},description:{type:[{code:"string"}]},valueSet:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]}}},ElementDefinitionMapping:{display:"ElementDefinitionMapping",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},identity:{min:1,type:[{code:"id"}]},language:{type:[{code:"code"}]},map:{min:1,type:[{code:"string"}]},comment:{type:[{code:"string"}]}}},Expression:{display:"Expression",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},description:{type:[{code:"string"}]},name:{type:[{code:"id"}]},language:{min:1,type:[{code:"code"}]},expression:{type:[{code:"string"}]},reference:{type:[{code:"uri"}]}}},Extension:{display:"Extension",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},url:{min:1,type:[{code:"string"}]},"value[x]":{type:[{code:"base64Binary"},{code:"boolean"},{code:"canonical"},{code:"code"},{code:"date"},{code:"dateTime"},{code:"decimal"},{code:"id"},{code:"instant"},{code:"integer"},{code:"markdown"},{code:"oid"},{code:"positiveInt"},{code:"string"},{code:"time"},{code:"unsignedInt"},{code:"uri"},{code:"url"},{code:"uuid"},{code:"Address"},{code:"Age"},{code:"Annotation"},{code:"Attachment"},{code:"CodeableConcept"},{code:"Coding"},{code:"ContactPoint"},{code:"Count"},{code:"Distance"},{code:"Duration"},{code:"HumanName"},{code:"Identifier"},{code:"Money"},{code:"Period"},{code:"Quantity"},{code:"Range"},{code:"Ratio"},{code:"Reference"},{code:"SampledData"},{code:"Signature"},{code:"Timing"},{code:"ContactDetail"},{code:"Contributor"},{code:"DataRequirement"},{code:"Expression"},{code:"ParameterDefinition"},{code:"RelatedArtifact"},{code:"TriggerDefinition"},{code:"UsageContext"},{code:"Dosage"},{code:"Meta"}]}}},HumanName:{display:"HumanName",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},use:{type:[{code:"code"}]},text:{type:[{code:"string"}]},family:{type:[{code:"string"}]},given:{max:"*",type:[{code:"string"}]},prefix:{max:"*",type:[{code:"string"}]},suffix:{max:"*",type:[{code:"string"}]},period:{type:[{code:"Period"}]}}},Identifier:{display:"Identifier",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},use:{type:[{code:"code"}]},type:{type:[{code:"CodeableConcept"}]},system:{type:[{code:"uri"}]},value:{type:[{code:"string"}]},period:{type:[{code:"Period"}]},assigner:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MarketingStatus:{display:"MarketingStatus",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},country:{min:1,type:[{code:"CodeableConcept"}]},jurisdiction:{type:[{code:"CodeableConcept"}]},status:{min:1,type:[{code:"CodeableConcept"}]},dateRange:{min:1,type:[{code:"Period"}]},restoreDate:{type:[{code:"dateTime"}]}}},Meta:{display:"Meta",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},versionId:{type:[{code:"id"}]},lastUpdated:{type:[{code:"instant"}]},source:{type:[{code:"uri"}]},profile:{max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},security:{max:"*",type:[{code:"Coding"}]},tag:{max:"*",type:[{code:"Coding"}]},project:{type:[{code:"uri"}]},author:{type:[{code:"Reference"}]},account:{type:[{code:"Reference"}]},compartment:{max:"*",type:[{code:"Reference"}]}}},Money:{display:"Money",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},currency:{type:[{code:"code"}]}}},Narrative:{display:"Narrative",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},status:{min:1,type:[{code:"code"}]},div:{min:1,type:[{code:"xhtml"}]}}},ParameterDefinition:{display:"ParameterDefinition",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},name:{type:[{code:"code"}]},use:{min:1,type:[{code:"code"}]},min:{type:[{code:"integer"}]},max:{type:[{code:"string"}]},documentation:{type:[{code:"string"}]},type:{min:1,type:[{code:"code"}]},profile:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},Period:{display:"Period",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},start:{type:[{code:"dateTime"}]},end:{type:[{code:"dateTime"}]}}},Population:{display:"Population",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},"age[x]":{type:[{code:"Range"},{code:"CodeableConcept"}]},gender:{type:[{code:"CodeableConcept"}]},race:{type:[{code:"CodeableConcept"}]},physiologicalCondition:{type:[{code:"CodeableConcept"}]}}},ProdCharacteristic:{display:"ProdCharacteristic",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},height:{type:[{code:"Quantity"}]},width:{type:[{code:"Quantity"}]},depth:{type:[{code:"Quantity"}]},weight:{type:[{code:"Quantity"}]},nominalVolume:{type:[{code:"Quantity"}]},externalDiameter:{type:[{code:"Quantity"}]},shape:{type:[{code:"string"}]},color:{max:"*",type:[{code:"string"}]},imprint:{max:"*",type:[{code:"string"}]},image:{max:"*",type:[{code:"Attachment"}]},scoring:{type:[{code:"CodeableConcept"}]}}},ProductShelfLife:{display:"ProductShelfLife",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},identifier:{type:[{code:"Identifier"}]},type:{min:1,type:[{code:"CodeableConcept"}]},period:{min:1,type:[{code:"Quantity"}]},specialPrecautionsForStorage:{max:"*",type:[{code:"CodeableConcept"}]}}},Quantity:{display:"Quantity",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},value:{type:[{code:"decimal"}]},comparator:{max:"0",type:[{code:"code"}]},unit:{type:[{code:"string"}]},system:{type:[{code:"uri"}]},code:{type:[{code:"code"}]}}},Range:{display:"Range",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},low:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},high:{type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Ratio:{display:"Ratio",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},numerator:{type:[{code:"Quantity"}]},denominator:{type:[{code:"Quantity"}]}}},Reference:{display:"Reference",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},reference:{type:[{code:"string"}]},type:{type:[{code:"uri"}]},identifier:{type:[{code:"Identifier"}]},display:{type:[{code:"string"}]}}},RelatedArtifact:{display:"RelatedArtifact",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},label:{type:[{code:"string"}]},display:{type:[{code:"string"}]},citation:{type:[{code:"markdown"}]},url:{type:[{code:"url"}]},document:{type:[{code:"Attachment"}]},resource:{type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/Resource"]}]}}},SampledData:{display:"SampledData",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},origin:{min:1,type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},period:{min:1,type:[{code:"decimal"}]},factor:{type:[{code:"decimal"}]},lowerLimit:{type:[{code:"decimal"}]},upperLimit:{type:[{code:"decimal"}]},dimensions:{min:1,type:[{code:"positiveInt"}]},data:{type:[{code:"string"}]}}},Signature:{display:"Signature",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,max:"*",type:[{code:"Coding"}]},when:{min:1,type:[{code:"instant"}]},who:{min:1,type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},onBehalfOf:{type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Practitioner","http://hl7.org/fhir/StructureDefinition/PractitionerRole","http://hl7.org/fhir/StructureDefinition/RelatedPerson","http://hl7.org/fhir/StructureDefinition/Patient","http://hl7.org/fhir/StructureDefinition/Device","http://hl7.org/fhir/StructureDefinition/Organization"]}]},targetFormat:{type:[{code:"code"}]},sigFormat:{type:[{code:"code"}]},data:{type:[{code:"base64Binary"}]}}},SubstanceAmount:{display:"SubstanceAmount",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},"amount[x]":{type:[{code:"Quantity"},{code:"Range"},{code:"string"}]},amountType:{type:[{code:"CodeableConcept"}]},amountText:{type:[{code:"string"}]},referenceRange:{type:[{code:"Element"}]}}},SubstanceAmountReferenceRange:{display:"SubstanceAmountReferenceRange",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},lowLimit:{type:[{code:"Quantity"}]},highLimit:{type:[{code:"Quantity"}]}}},Timing:{display:"Timing",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},event:{max:"*",type:[{code:"dateTime"}]},repeat:{type:[{code:"Element"}]},code:{type:[{code:"CodeableConcept"}]}}},TimingRepeat:{display:"TimingRepeat",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},"bounds[x]":{type:[{code:"Duration"},{code:"Range"},{code:"Period"}]},count:{type:[{code:"positiveInt"}]},countMax:{type:[{code:"positiveInt"}]},duration:{type:[{code:"decimal"}]},durationMax:{type:[{code:"decimal"}]},durationUnit:{type:[{code:"code"}]},frequency:{type:[{code:"positiveInt"}]},frequencyMax:{type:[{code:"positiveInt"}]},period:{type:[{code:"decimal"}]},periodMax:{type:[{code:"decimal"}]},periodUnit:{type:[{code:"code"}]},dayOfWeek:{max:"*",type:[{code:"code"}]},timeOfDay:{max:"*",type:[{code:"time"}]},when:{max:"*",type:[{code:"code"}]},offset:{type:[{code:"unsignedInt"}]}}},TriggerDefinition:{display:"TriggerDefinition",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},type:{min:1,type:[{code:"code"}]},name:{type:[{code:"string"}]},"timing[x]":{type:[{code:"Timing"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Schedule"]},{code:"date"},{code:"dateTime"}]},data:{max:"*",type:[{code:"DataRequirement"}]},condition:{type:[{code:"Expression"}]}}},UsageContext:{display:"UsageContext",properties:{id:{type:[{code:"string"}]},extension:{max:"*",type:[{code:"Extension"}]},code:{min:1,type:[{code:"Coding"}]},"value[x]":{min:1,type:[{code:"CodeableConcept"},{code:"Quantity"},{code:"Range"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/PlanDefinition","http://hl7.org/fhir/StructureDefinition/ResearchStudy","http://hl7.org/fhir/StructureDefinition/InsurancePlan","http://hl7.org/fhir/StructureDefinition/HealthcareService","http://hl7.org/fhir/StructureDefinition/Group","http://hl7.org/fhir/StructureDefinition/Location","http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MetadataResource:{display:"MetadataResource",properties:{id:{type:[{code:"string"}]},meta:{type:[{code:"Meta"}]},implicitRules:{type:[{code:"uri"}]},language:{type:[{code:"code"}]},text:{type:[{code:"Narrative"}]},contained:{max:"*",type:[{code:"Resource"}]},extension:{max:"*",type:[{code:"Extension"}]},modifierExtension:{max:"*",type:[{code:"Extension"}]},url:{type:[{code:"uri"}]},version:{type:[{code:"string"}]},name:{type:[{code:"string"}]},title:{type:[{code:"string"}]},status:{min:1,type:[{code:"code"}]},experimental:{type:[{code:"boolean"}]},date:{type:[{code:"dateTime"}]},publisher:{type:[{code:"string"}]},contact:{max:"*",type:[{code:"ContactDetail"}]},description:{type:[{code:"markdown"}]},useContext:{max:"*",type:[{code:"UsageContext"}]},jurisdiction:{max:"*",type:[{code:"CodeableConcept"}]}}},IdentityProvider:{display:"IdentityProvider",properties:{authorizeUrl:{min:1,type:[{code:"string"}]},tokenUrl:{min:1,type:[{code:"string"}]},userInfoUrl:{min:1,type:[{code:"string"}]},clientId:{min:1,type:[{code:"string"}]},clientSecret:{min:1,type:[{code:"string"}]},useSubject:{type:[{code:"boolean"}]}}}}};function ke(e){if(!e.name)return;const t=e.snapshot?.element;t&&(t.forEach((t=>function(e,t){const i=t.path,n=t.type?.[0]?.code;if(void 0!==n&&"Element"!==n&&"BackboneElement"!==n)return;const r=i.split(".");r[0]=e.name;const o=Oe(r);let s=_e.types[o];s||(_e.types[o]=s={});s.parentType=s.parentType||Oe(r.slice(0,r.length-1)),s.display=s.display||o,s.structureDefinition=s.structureDefinition||e,s.elementDefinition=s.elementDefinition||t,s.description=s.description||t.definition,s.properties=s.properties||{}}(e,t))),t.forEach((t=>function(e,t){const i=t.path,n=i.split(".");if(1===n.length)return;n[0]=e.name;const r=Oe(n.slice(0,n.length-1)),o=_e.types[r];if(!o)return;const s=n[n.length-1];o.properties[s]=t}(e,t))))}function Re(e){if(e.base)for(const t of e.base){const i=_e.types[t];i&&(i.searchParams||(i.searchParams={_id:{base:[t],code:"_id",type:"token",expression:t+".id"},_lastUpdated:{base:[t],code:"_lastUpdated",type:"date",expression:t+".meta.lastUpdated"},_compartment:{base:[t],code:"_compartment",type:"reference",expression:t+".meta.compartment"},_profile:{base:[t],code:"_profile",type:"uri",expression:t+".meta.profile"},_security:{base:[t],code:"_security",type:"token",expression:t+".meta.security"},_source:{base:[t],code:"_source",type:"uri",expression:t+".meta.source"},_tag:{base:[t],code:"_tag",type:"token",expression:t+".meta.tag"}}),i.searchParams[e.code]=e)}}function Oe(e){return 1===e.length?e[0]:e.map(N).join("")}function Me(e){const t=e.structureDefinition;return t&&t.name===e.elementDefinition?.path&&"resource"===t.kind&&!t.abstract}e.PropertyType=void 0,(Ae=e.PropertyType||(e.PropertyType={})).Address="Address",Ae.Age="Age",Ae.Annotation="Annotation",Ae.Attachment="Attachment",Ae.BackboneElement="BackboneElement",Ae.CodeableConcept="CodeableConcept",Ae.Coding="Coding",Ae.ContactDetail="ContactDetail",Ae.ContactPoint="ContactPoint",Ae.Contributor="Contributor",Ae.Count="Count",Ae.DataRequirement="DataRequirement",Ae.Distance="Distance",Ae.Dosage="Dosage",Ae.Duration="Duration",Ae.Expression="Expression",Ae.Extension="Extension",Ae.HumanName="HumanName",Ae.Identifier="Identifier",Ae.MarketingStatus="MarketingStatus",Ae.Meta="Meta",Ae.Money="Money",Ae.Narrative="Narrative",Ae.ParameterDefinition="ParameterDefinition",Ae.Period="Period",Ae.Population="Population",Ae.ProdCharacteristic="ProdCharacteristic",Ae.ProductShelfLife="ProductShelfLife",Ae.Quantity="Quantity",Ae.Range="Range",Ae.Ratio="Ratio",Ae.Reference="Reference",Ae.RelatedArtifact="RelatedArtifact",Ae.SampledData="SampledData",Ae.Signature="Signature",Ae.SubstanceAmount="SubstanceAmount",Ae.SystemString="http://hl7.org/fhirpath/System.String",Ae.Timing="Timing",Ae.TriggerDefinition="TriggerDefinition",Ae.UsageContext="UsageContext",Ae.base64Binary="base64Binary",Ae.boolean="boolean",Ae.canonical="canonical",Ae.code="code",Ae.date="date",Ae.dateTime="dateTime",Ae.decimal="decimal",Ae.id="id",Ae.instant="instant",Ae.integer="integer",Ae.markdown="markdown",Ae.oid="oid",Ae.positiveInt="positiveInt",Ae.string="string",Ae.time="time",Ae.unsignedInt="unsignedInt",Ae.uri="uri",Ae.url="url",Ae.uuid="uuid";const Ie=new Set(["ID","PKCE","JWKS","URI","URL"]);function Ue(e){const t=e.toUpperCase();return Ie.has(t)?t:t.charAt(0)+e.slice(1)}function Le(e,t){const i=_e.types[e];if(!i)return;const n=i.properties[t]??i.properties[t+"[x]"];if(n){if(n.contentReference){const e=n.contentReference.substring(1).split("."),t=e.pop();return Le(Oe(e),t)}return n}}function Ne(e){return!(!e||"object"!=typeof e||!("resourceType"in e))}const _e=Ce;var je,We,Qe,Be,$e,qe,Fe,He,ze,Ge,Ve,Xe,Je,Ye,Ke,Ze,et,tt,it,nt,rt,ot,st,at,ct,ut,lt,pt,dt,ht,ft,mt,yt,gt,vt,xt,wt,St,Tt,Et,bt;const Pt={resourceType:"Device",id:"system",deviceName:[{name:"System"}]};function Dt(){return"undefined"==typeof window?"":window.location.protocol+"//"+window.location.host+"/"}var At,Ct,kt,Rt,Ot,Mt,It,Ut,Lt,Nt,_t,jt,Wt,Qt,Bt,$t,qt,Ft,Ht,zt,Gt,Vt,Xt,Jt,Yt,Kt,Zt,ei,ti,ii,ni,ri,oi,si;We=new WeakMap,Qe=new WeakMap,Be=new WeakMap,$e=new WeakMap,qe=new WeakMap,Fe=new WeakMap,He=new WeakMap,ze=new WeakMap,Ge=new WeakMap,Ve=new WeakMap,Xe=new WeakMap,Je=new WeakMap,Ye=new WeakMap,Ke=new WeakMap,Ze=new WeakMap,et=new WeakMap,tt=new WeakMap,it=new WeakMap,nt=new WeakMap,rt=new WeakMap,ot=new WeakMap,st=new WeakMap,je=new WeakSet,at=function(e){const i=this.getLogins().filter((t=>t.profile?.reference!==e.profile?.reference));i.push(e),t(this,Be,"f").setObject("logins",i)},ct=async function(){return i(this,rt,new Promise(((e,n)=>{this.get("auth/me").then((n=>{i(this,rt,void 0,"f"),i(this,ot,n.profile,"f"),i(this,st,n.config,"f"),this.dispatchEvent({type:"change"}),e(t(this,ot,"f"))})).catch(n)})),"f"),t(this,rt,"f")},ut=function(e,i){if(t(this,qe,"f")<=0||"no-cache"===i?.cache||"reload"===i?.cache)return;const n=t(this,$e,"f").get(e);return!n||n.requestTime+t(this,qe,"f")<Date.now()?void 0:n},lt=function(e,i){t(this,qe,"f")>0&&t(this,$e,"f").set(e,{requestTime:Date.now(),value:i})},pt=function(e){e?.id&&t(this,je,"m",lt).call(this,this.fhirUrl(e.resourceType,e.id).toString(),new be(Promise.resolve(e)))},dt=function(e){t(this,qe,"f")>0&&t(this,$e,"f").delete(e)},ht=async function(e,i,n={}){t(this,nt,"f")&&await t(this,nt,"f"),i.startsWith("http")||(i=t(this,Fe,"f")+i),n.method=e,t(this,je,"m",yt).call(this,n);const r=await t(this,je,"m",ft).call(this,i,n);if(401===r.status)return t(this,je,"m",xt).call(this,e,i,n);if(204===r.status||304===r.status)return;let o;try{o=await r.json()}catch(e){throw console.error("Error parsing response",r.status,e),e}if(r.status>=400)throw new fe(me(o));return o},ft=async function(e,i){let n;for(let r=0;r<3;r++){if(n=await t(this,We,"f").call(this,e,i),n.status<500)return n;await new Promise((e=>setTimeout(e,200)))}return n},mt=async function(){const e=[...t(this,Ye,"f")];if(t(this,Ye,"f").length=0,i(this,et,void 0,"f"),1===e.length){const i=e[0];return void i.resolve(await t(this,je,"m",ht).call(this,i.method,t(this,He,"f")+i.url,i.options))}const n={resourceType:"Bundle",type:"batch",entry:e.map((e=>({request:{method:e.method,url:e.url},resource:e.options.body?JSON.parse(e.options.body):void 0})))},r=await this.post("fhir/R4",n);for(let t=0;t<e.length;t++){const i=e[t],n=r.entry?.[t];n?.response?.outcome&&!he(n.response.outcome)?i.reject(new fe(n.response.outcome)):i.resolve(n?.resource)}},yt=function(e){e.headers||(e.headers={});const i=e.headers;i["X-Medplum"]="extended",i["Content-Type"]||(i["Content-Type"]="application/fhir+json"),t(this,tt,"f")&&(i.Authorization="Bearer "+t(this,tt,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},gt=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},vt=function(e,t){"string"==typeof t||"undefined"!=typeof Blob&&t instanceof Blob||"undefined"!=typeof File&&t instanceof File||"undefined"!=typeof Uint8Array&&t instanceof Uint8Array?e.body=t:t&&(e.body=JSON.stringify(t))},xt=function(e,i,n){return t(this,je,"m",St).call(this)?t(this,je,"m",ht).call(this,e,i,n):(this.clearActiveLogin(),t(this,Xe,"f")&&t(this,Xe,"f").call(this),Promise.reject(new Error("Unauthenticated")))},wt=async function(e){const i=await this.ensureCodeChallenge(e||{}),n=new URL(t(this,ze,"f"));n.searchParams.set("response_type","code"),n.searchParams.set("state",sessionStorage.getItem("pkceState")),n.searchParams.set("client_id",i.clientId||t(this,Ke,"f")),n.searchParams.set("redirect_uri",i.redirectUri||Dt()),n.searchParams.set("code_challenge_method",i.codeChallengeMethod),n.searchParams.set("code_challenge",i.codeChallenge),n.searchParams.set("scope",i.scope||"openid profile"),window.location.assign(n.toString())},St=function(){if(t(this,nt,"f"))return t(this,nt,"f");if(t(this,it,"f")){const e=new URLSearchParams;return e.set("grant_type","refresh_token"),e.set("client_id",t(this,Ke,"f")),e.set("refresh_token",t(this,it,"f")),i(this,nt,t(this,je,"m",Tt).call(this,e),"f"),t(this,nt,"f")}return t(this,Ke,"f")&&t(this,Ze,"f")?(i(this,nt,this.startClientLogin(t(this,Ke,"f"),t(this,Ze,"f")),"f"),t(this,nt,"f")):void 0},Tt=async function(e){const i=await t(this,We,"f").call(this,t(this,Ge,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e,credentials:"include"});if(!i.ok)throw this.clearActiveLogin(),new Error("Failed to fetch tokens");const n=await i.json();return await t(this,je,"m",Et).call(this,n),this.getProfile()},Et=async function(e){const i=e.access_token,n=G(i);if(Date.now()>=1e3*n.exp)throw this.clearActiveLogin(),new Error("Token expired");if(t(this,Ke,"f")&&n.client_id!==t(this,Ke,"f"))throw this.clearActiveLogin(),new Error("Token was not issued for this audience");return this.setActiveLogin({accessToken:i,refreshToken:e.refresh_token,project:e.project,profile:e.profile})},bt=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class ai{constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}}class ci{constructor(e,t,i){this.operator=e,this.left=t,this.right=i}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class ui{constructor(){At.set(this,{}),Ct.set(this,{})}registerInfix(e,i){return t(this,Ct,"f")[e]=i,this}registerPrefix(e,i){return t(this,At,"f")[e]=i,this}prefix(e,t,i){return this.registerPrefix(e,{parse(e,n){const r=e.consumeAndParse(t);return i(n,r)}})}infixLeft(e,t,i){return this.registerInfix(e,{parse(e,n,r){const o=e.consumeAndParse(t);return i(n,r,o)},precedence:t})}construct(e){return new li(e,t(this,At,"f"),t(this,Ct,"f"))}}At=new WeakMap,Ct=new WeakMap;class li{constructor(e,t,n){kt.set(this,void 0),Rt.set(this,void 0),Ot.set(this,void 0),i(this,kt,e,"f"),i(this,Rt,t,"f"),i(this,Ot,n,"f")}hasMore(){return t(this,kt,"f").length>0}match(e){const t=this.peek();return t?.id===e&&(this.consume(),!0)}consumeAndParse(e=1/0){const i=this.consume(),n=t(this,Rt,"f")[i.id];if(!n)throw Error(`Parse error at "${i.value}" (line ${i.line}, column ${i.column}). No matching prefix parselet.`);let r=n.parse(this,i);for(;e>this.getPrecedence();){const e=this.consume();r=this.getInfixParselet(e).parse(this,r,e)}return r}getPrecedence(){const e=this.peek();if(!e)return 1/0;const t=this.getInfixParselet(e);return t?t.precedence:1/0}consume(e,i){if(!t(this,kt,"f").length)throw Error("Cant consume unknown more tokens.");if(e&&this.peek()?.id!==e){const t=this.peek();throw Error(`Expected ${e} but got "${t.id}" at line ${t.line} column ${t.column}.`)}if(i&&this.peek()?.value!==i){const e=this.peek();throw Error(`Expected "${i}" but got "${e.value}" at line ${e.line} column ${e.column}.`)}return t(this,kt,"f").shift()}peek(){return t(this,kt,"f").length>0?t(this,kt,"f")[0]:void 0}removeComments(){i(this,kt,t(this,kt,"f").filter((e=>"Comment"!==e.id)),"f")}getInfixParselet(e){return t(this,Ot,"f")["Symbol"===e.id?e.value:e.id]}}kt=new WeakMap,Rt=new WeakMap,Ot=new WeakMap;const pi=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"];class di{constructor(e,t,n,r){Mt.add(this),It.set(this,void 0),Ut.set(this,void 0),Lt.set(this,void 0),Nt.set(this,void 0),_t.set(this,void 0),jt.set(this,[]),Wt.set(this,{index:0,line:1,column:0}),Qt.set(this,[]),i(this,It,e,"f"),i(this,Ut,t,"f"),i(this,Lt,n,"f"),i(this,Nt,!!r?.dateTimeLiterals,"f"),i(this,_t,r?.symbolRegex??/[$\w]/,"f")}tokenize(){for(;t(this,Wt,"f").index<t(this,It,"f").length;){const e=t(this,Mt,"m",qt).call(this);e&&t(this,jt,"f").push(e)}return t(this,jt,"f")}}function hi(e){if(e.startsWith("T"))return e+"T00:00:00.000Z".substring(e.length);if(e.length<=10)return e;try{return new Date(e).toISOString()}catch(t){return e}}function fi(t){return[{type:e.PropertyType.boolean,value:t}]}function mi(t){return null==t?{type:"undefined",value:void 0}:Number.isSafeInteger(t)?{type:e.PropertyType.integer,value:t}:"number"==typeof t?{type:e.PropertyType.decimal,value:t}:"boolean"==typeof t?{type:e.PropertyType.boolean,value:t}:"string"==typeof t?{type:e.PropertyType.string,value:t}:Ci(t)?{type:e.PropertyType.Quantity,value:t}:Ne(t)?{type:t.resourceType,value:t}:{type:e.PropertyType.BackboneElement,value:t}}function yi(e){return 0!==e.length&&!!e[0].value}function gi(t,i){if(!t?.value)return;const n=Le(t.type,i);if(n){const e=function(e,t,i){const n=i.type;if(!n||0===n.length)return;let r,o="undefined";if(1===n.length)r=e.value[t],o=n[0].code;else for(const i of n){const n=t.replace("[x]","")+N(i.code);if(n in e.value){r=e.value[n],o=i.code;break}}if(k(r))return;"Element"!==o&&"BackboneElement"!==o||(o=Oe(i.path?.split(".")));return Array.isArray(r)?r.map((e=>vi(e,o))):vi(r,o)}(t,i,n);if(e)return e}return function(t,i){const n=t.value;if(!n||"object"!=typeof n)return;let r;if(i in n)r=n[i];else for(const t in e.PropertyType){const e=i+N(t);if(e in n){r=n[e];break}}if(k(r))return;return Array.isArray(r)?r.map(mi):mi(r)}(t,i)}function vi(e,t){return"Resource"===t&&Ne(e)&&(t=e.resourceType),{type:t,value:e}}function xi(e){const t=[];for(const i of e){let e=!1;for(const n of t)if(yi(Ti(i,n))){e=!0;break}e||t.push(i)}return t}function wi(e){return fi(!yi(e))}function Si(e,t){return 0===e.length||0===t.length?[]:e.length!==t.length?fi(!1):fi(e.every(((e,i)=>yi(Ti(e,t[i])))))}function Ti(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?fi(Math.abs(i-n)<1e-8):Ci(i)&&Ci(n)?fi(ki(i,n)):fi("object"==typeof i&&"object"==typeof n?Ri(e,t):i===n)}function Ei(e,t){return 0===e.length&&0===t.length?fi(!0):e.length!==t.length?fi(!1):(e.sort(Pi),t.sort(Pi),fi(e.every(((e,i)=>yi(bi(e,t[i]))))))}function bi(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?fi(Math.abs(i-n)<.01):Ci(i)&&Ci(n)?fi(ki(i,n)):fi("object"==typeof i&&"object"==typeof n?Ri(i,n):"string"==typeof i&&"string"==typeof n?i.toLowerCase()===n.toLowerCase():i===n)}function Pi(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?i-n:"string"==typeof i&&"string"==typeof n?i.localeCompare(n):0}function Di(e,t){const{value:i}=e;if(null==i)return!1;switch(t){case"Boolean":return"boolean"==typeof i;case"Decimal":case"Integer":return"number"==typeof i;case"Date":return"string"==typeof i&&!!i.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof i&&!!i.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof i&&!!i.match(/^T\d/);case"Period":return Ai(i);case"Quantity":return Ci(i);default:return"object"==typeof i&&i?.resourceType===t}}function Ai(e){return!(!e||"object"!=typeof e||!("start"in e))}function Ci(e){return!(!e||"object"!=typeof e||!("value"in e)||"number"!=typeof e.value)}function ki(e,t){return Math.abs(e.value-t.value)<.01&&(e.unit===t.unit||e.code===t.code||e.unit===t.code||e.code===t.unit)}function Ri(e,t){const i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(const n of i){const i=e[n],r=t[n];if(Oi(i)&&Oi(r)){if(!Ri(i,r))return!1}else if(i!==r)return!1}return!0}function Oi(e){return null!==e&&"object"==typeof e}It=new WeakMap,Ut=new WeakMap,Lt=new WeakMap,Nt=new WeakMap,_t=new WeakMap,jt=new WeakMap,Wt=new WeakMap,Qt=new WeakMap,Mt=new WeakSet,Bt=function(){return t(this,jt,"f").slice(-1)[0]},$t=function(){t(this,Mt,"m",ni).call(this);const e=t(this,Mt,"m",qt).call(this);return t(this,Mt,"m",ri).call(this),e},qt=function(){t(this,Mt,"m",Ft).call(this);const e=t(this,Mt,"m",ei).call(this);if(!e)return;t(this,Mt,"m",ni).call(this);const i=t(this,Mt,"m",ii).call(this);return"/"===e&&"*"===i?t(this,Mt,"m",Ht).call(this):"/"===e&&"/"===i?t(this,Mt,"m",zt).call(this):"'"===e||'"'===e?t(this,Mt,"m",Gt).call(this,e):"`"===e?t(this,Mt,"m",Vt).call(this):"@"===e?t(this,Mt,"m",Xt).call(this):e.match(/\d/)?t(this,Mt,"m",Jt).call(this):e.match(/\w/)||"$"===e&&i.match(/\w/)?t(this,Mt,"m",Yt).call(this):t(this,Mt,"m",Kt).call(this)},Ft=function(){t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\s/)))},Ht=function(){const e=t(this,Wt,"f").index;return t(this,Mt,"m",Zt).call(this,(()=>"*"!==t(this,Mt,"m",ei).call(this)||"/"!==t(this,Mt,"m",ii).call(this))),t(this,Mt,"m",oi).call(this),t(this,Mt,"m",oi).call(this),t(this,Mt,"m",si).call(this,"Comment",t(this,It,"f").substring(e,t(this,Wt,"f").index))},zt=function(){return t(this,Mt,"m",si).call(this,"Comment",t(this,Mt,"m",Zt).call(this,(()=>"\n"!==t(this,Mt,"m",ei).call(this))))},Gt=function(e){t(this,Mt,"m",oi).call(this);const i=t(this,Mt,"m",si).call(this,"String",t(this,Mt,"m",Zt).call(this,(()=>"\\"===t(this,Mt,"m",ti).call(this)||t(this,Mt,"m",ei).call(this)!==e)));return t(this,Mt,"m",oi).call(this),i},Vt=function(){t(this,Mt,"m",oi).call(this);const e=t(this,Mt,"m",si).call(this,"Symbol",t(this,Mt,"m",Zt).call(this,(()=>"`"!==t(this,Mt,"m",ei).call(this))));return t(this,Mt,"m",oi).call(this),e},Xt=function(){t(this,Mt,"m",oi).call(this);const e=t(this,Wt,"f").index;return t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/[\d-]/))),"T"===t(this,Mt,"m",ei).call(this)&&(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/[\d:]/))),"."===t(this,Mt,"m",ei).call(this)&&t(this,Mt,"m",ii).call(this).match(/\d/)&&(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\d/)))),"Z"===t(this,Mt,"m",ei).call(this)?t(this,Mt,"m",oi).call(this):"+"!==t(this,Mt,"m",ei).call(this)&&"-"!==t(this,Mt,"m",ei).call(this)||(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/[\d:]/))))),t(this,Mt,"m",si).call(this,"DateTime",t(this,It,"f").substring(e,t(this,Wt,"f").index))},Jt=function(){const e=t(this,Wt,"f").index;let i="Number";return t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\d/))),"."===t(this,Mt,"m",ei).call(this)&&t(this,Mt,"m",ii).call(this).match(/\d/)&&(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(/\d/)))),"-"===t(this,Mt,"m",ei).call(this)&&t(this,Nt,"f")?(t(this,Wt,"f").index=e-1,t(this,Mt,"m",Xt).call(this)):(" "===t(this,Mt,"m",ei).call(this)&&function(e){if(e){if("String"===e.id)return!0;if("Symbol"===e.id&&pi.includes(e.value))return!0}return!1}(t(this,Mt,"m",$t).call(this))&&(i="Quantity",t(this,Mt,"m",qt).call(this)),t(this,Mt,"m",si).call(this,i,t(this,It,"f").substring(e,t(this,Wt,"f").index)))},Yt=function(){const e=t(this,Mt,"m",Zt).call(this,(()=>t(this,Mt,"m",ei).call(this).match(t(this,_t,"f"))));return"."!==t(this,Mt,"m",Bt).call(this)?.value&&t(this,Ut,"f").includes(e)?t(this,Mt,"m",si).call(this,e,e):t(this,Mt,"m",si).call(this,"Symbol",e)},Kt=function(){const e=t(this,Mt,"m",ei).call(this),i=e+t(this,Mt,"m",ii).call(this);return t(this,Lt,"f").includes(i)?(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",oi).call(this),t(this,Mt,"m",si).call(this,i,i)):(t(this,Mt,"m",oi).call(this),t(this,Mt,"m",si).call(this,e,e))},Zt=function(e){const i=t(this,Wt,"f").index;for(;t(this,Wt,"f").index<t(this,It,"f").length&&e();)t(this,Mt,"m",oi).call(this);return t(this,It,"f").substring(i,t(this,Wt,"f").index)},ei=function(){return t(this,It,"f")[t(this,Wt,"f").index]},ti=function(){return t(this,It,"f")[t(this,Wt,"f").index-1]??""},ii=function(){return t(this,It,"f")[t(this,Wt,"f").index+1]??""},ni=function(){t(this,Qt,"f").push({...t(this,Wt,"f")})},ri=function(){const e=t(this,Qt,"f").pop();if(!e)throw new Error("No mark to reset to");t(this,Wt,"f").index=e.index,t(this,Wt,"f").line=e.line,t(this,Wt,"f").column=e.column},oi=function(){t(this,Wt,"f").index++,"\n"===t(this,Mt,"m",ei).call(this)?(t(this,Wt,"f").line++,t(this,Wt,"f").column=0):t(this,Wt,"f").column++},si=function(e,i){const n=t(this,Qt,"f").pop();if(!n)throw new Error("No mark for token");return{id:e,value:i,...n}};const Mi=()=>[],Ii={empty:e=>fi(0===e.length),exists:(e,t)=>fi(t?e.filter((e=>yi(t.eval([e])))).length>0:e.length>0),all:(e,t)=>fi(e.every((e=>yi(t.eval([e]))))),allTrue:e=>{for(const t of e)if(!t.value)return fi(!1);return fi(!0)},anyTrue:e=>{for(const t of e)if(t.value)return fi(!0);return fi(!1)},allFalse:e=>{for(const t of e)if(t.value)return fi(!1);return fi(!0)},anyFalse:e=>{for(const t of e)if(!t.value)return fi(!0);return fi(!1)},subsetOf:Mi,supersetOf:Mi,count:t=>[{type:e.PropertyType.integer,value:t.length}],distinct:e=>{const t=[];for(const i of e)t.some((e=>e.value===i.value))||t.push(i);return t},isDistinct:e=>fi(e.length===Ii.distinct(e).length),where:(e,t)=>e.filter((e=>yi(t.eval([e])))),select:(e,t)=>e.map((e=>t.eval([e]))).flat(),repeat:Mi,ofType:(e,t)=>e.filter((e=>e.type===t.name)),single:e=>{if(e.length>1)throw new Error("Expected input length one for single()");return 0===e.length?[]:e.slice(0,1)},first:e=>0===e.length?[]:e.slice(0,1),last:e=>0===e.length?[]:e.slice(e.length-1,e.length),tail:e=>0===e.length?[]:e.slice(1,e.length),skip:(e,t)=>{const i=t.eval(e)[0]?.value;if("number"!=typeof i)throw new Error("Expected a number for skip(num)");return i>=e.length?[]:i<=0?e:e.slice(i,e.length)},take:(e,t)=>{const i=t.eval(e)[0]?.value;if("number"!=typeof i)throw new Error("Expected a number for take(num)");return i>=e.length?e:i<=0?[]:e.slice(0,i)},intersect:(e,t)=>{if(!t)return e;const i=t.eval(e),n=[];for(const t of e)!n.some((e=>e.value===t.value))&&i.some((e=>e.value===t.value))&&n.push(t);return n},exclude:(e,t)=>{if(!t)return e;const i=t.eval(e),n=[];for(const t of e)i.some((e=>e.value===t.value))||n.push(t);return n},union:(e,t)=>{if(!t)return e;const i=t.eval(e);return xi([...e,...i])},combine:(e,t)=>{if(!t)return e;const i=t.eval(e);return[...e,...i]},iif:(e,t,i,n)=>{const r=t.eval(e);if(r.length>1||1===r.length&&"boolean"!=typeof r[0].value)throw new Error("Expected criterion to evaluate to a Boolean");return yi(r)?i.eval(e):n?n.eval(e):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);if("boolean"==typeof i)return[{type:e.PropertyType.boolean,value:i}];if("number"==typeof i&&(0===i||1===i))return fi(!!i);if("string"==typeof i){const e=i.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(e))return fi(!0);if(["false","f","no","n","0","0.0"].includes(e))return fi(!1)}return[]},convertsToBoolean:e=>0===e.length?[]:fi(1===Ii.toBoolean(e).length),toInteger:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"number"==typeof i?[{type:e.PropertyType.integer,value:i}]:"string"==typeof i&&i.match(/^[+-]?\d+$/)?[{type:e.PropertyType.integer,value:parseInt(i,10)}]:"boolean"==typeof i?[{type:e.PropertyType.integer,value:i?1:0}]:[]},convertsToInteger:e=>0===e.length?[]:fi(1===Ii.toInteger(e).length),toDate:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"string"==typeof i&&i.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.date,value:hi(i)}]:[]},convertsToDate:e=>0===e.length?[]:fi(1===Ii.toDate(e).length),toDateTime:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"string"==typeof i&&i.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.dateTime,value:hi(i)}]:[]},convertsToDateTime:e=>0===e.length?[]:fi(1===Ii.toDateTime(e).length),toDecimal:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return"number"==typeof i?[{type:e.PropertyType.decimal,value:i}]:"string"==typeof i&&i.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:e.PropertyType.decimal,value:parseFloat(i)}]:"boolean"==typeof i?[{type:e.PropertyType.decimal,value:i?1:0}]:[]},convertsToDecimal:e=>0===e.length?[]:fi(1===Ii.toDecimal(e).length),toQuantity:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return Ci(i)?[{type:e.PropertyType.Quantity,value:i}]:"number"==typeof i?[{type:e.PropertyType.Quantity,value:{value:i,unit:"1"}}]:"string"==typeof i&&i.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:e.PropertyType.Quantity,value:{value:parseFloat(i),unit:"1"}}]:"boolean"==typeof i?[{type:e.PropertyType.Quantity,value:{value:i?1:0,unit:"1"}}]:[]},convertsToQuantity:e=>0===e.length?[]:fi(1===Ii.toQuantity(e).length),toString:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);return null==i?[]:Ci(i)?[{type:e.PropertyType.string,value:`${i.value} '${i.unit}'`}]:[{type:e.PropertyType.string,value:i.toString()}]},convertsToString:e=>0===e.length?[]:fi(1===Ii.toString(e).length),toTime:t=>{if(0===t.length)return[];const[{value:i}]=Ni(t,1);if("string"==typeof i){const t=i.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[{type:e.PropertyType.time,value:hi("T"+t[1])}]}return[]},convertsToTime:e=>0===e.length?[]:fi(1===Ii.toTime(e).length),indexOf:(e,t)=>Ui(((e,t)=>e.indexOf(t)),e,t),substring:(e,t,i)=>Ui(((e,t,i)=>{const n=t,r=i?n+i:e.length;return n<0||n>=e.length?void 0:e.substring(n,r)}),e,t,i),startsWith:(e,t)=>Ui(((e,t)=>e.startsWith(t)),e,t),endsWith:(e,t)=>Ui(((e,t)=>e.endsWith(t)),e,t),contains:(e,t)=>Ui(((e,t)=>e.includes(t)),e,t),upper:e=>Ui((e=>e.toUpperCase()),e),lower:e=>Ui((e=>e.toLowerCase()),e),replace:(e,t,i)=>Ui(((e,t,i)=>e.replaceAll(t,i)),e,t,i),matches:(e,t)=>Ui(((e,t)=>!!e.match(t)),e,t),replaceMatches:(e,t,i)=>Ui(((e,t,i)=>e.replaceAll(t,i)),e,t,i),length:e=>Ui((e=>e.length),e),toChars:e=>Ui((e=>e?e.split(""):void 0),e),abs:e=>Li(Math.abs,e),ceiling:e=>Li(Math.ceil,e),exp:e=>Li(Math.exp,e),floor:e=>Li(Math.floor,e),ln:e=>Li(Math.log,e),log:(e,t)=>Li(((e,t)=>Math.log(e)/Math.log(t)),e,t),power:(e,t)=>Li(Math.pow,e,t),round:e=>Li(Math.round,e),sqrt:e=>Li(Math.sqrt,e),truncate:e=>Li((e=>0|e),e),children:Mi,descendants:Mi,trace:(e,t)=>(console.log("trace",e,t),e),now:()=>[{type:e.PropertyType.dateTime,value:(new Date).toISOString()}],timeOfDay:()=>[{type:e.PropertyType.time,value:(new Date).toISOString().substring(11)}],today:()=>[{type:e.PropertyType.date,value:(new Date).toISOString().substring(0,10)}],between:(t,i,n,r)=>{const o=Ii.toDateTime(i.eval(t));if(0===o.length)throw new Error("Invalid start date");const s=Ii.toDateTime(n.eval(t));if(0===s.length)throw new Error("Invalid end date");const a=r.eval(t)[0]?.value;if("years"!==a&&"months"!==a&&"days"!==a)throw new Error("Invalid units");const c=b(o[0].value,s[0].value);return[{type:e.PropertyType.Quantity,value:{value:c[a],unit:a}}]},is:(t,i)=>{let n="";return i instanceof Bi?n=i.name:i instanceof Xi&&(n=i.left.name+"."+i.right.name),n?t.map((t=>({type:e.PropertyType.boolean,value:Di(t,n)}))):[]},not:t=>Ii.toBoolean(t).map((t=>({type:e.PropertyType.boolean,value:!t.value}))),resolve:t=>t.map((t=>{const i=t.value;let n;if("string"==typeof i)n=i;else if("object"==typeof i){const e=i;if(e.resource)return mi(e.resource);n=e.reference}if(!n)return{type:e.PropertyType.BackboneElement,value:null};const[r,o]=n.split("/");return{type:e.PropertyType.BackboneElement,value:{resourceType:r,id:o}}})).filter((e=>!!e.value)),as:e=>e,type:t=>t.map((({value:t})=>"boolean"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Integer"}}:Ne(t)?{type:e.PropertyType.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:e.PropertyType.BackboneElement,value:null})),conformsTo:(t,i)=>{const n=i.eval(t)[0].value;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=>({type:e.PropertyType.boolean,value:t.value?.resourceType===r})))}};function Ui(e,t,...i){if(0===t.length)return[];const[{value:n}]=Ni(t,1);if("string"!=typeof n)throw new Error("String function cannot be called with non-string");const r=e(n,...i.map((e=>e&&e.eval(t)?.[0]?.value)));return void 0===r?[]:Array.isArray(r)?r.map(mi):[mi(r)]}function Li(t,i,...n){if(0===i.length)return[];const[{value:r}]=Ni(i,1),o=Ci(r),s=o?r.value:r;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const a=t(s,...n.map((e=>e.eval(i)?.[0]?.value)));return[{type:o?e.PropertyType.Quantity:i[0].type,value:o?{...r,value:a}:a}]}function Ni(e,t){if(e.length!==t)throw new Error(`Expected ${t} arguments`);for(const t of e)if(null==t)throw new Error("Expected non-null argument");return e}var _i,ji;class Wi{constructor(e,t){this.original=e,this.child=t}eval(e){try{return e.length>0?e.map((e=>this.child.eval([e]))).flat():this.child.eval([])}catch(e){throw new Error(`FhirPathError on "${this.original}": ${e}`)}}toString(){return this.child.toString()}}class Qi{constructor(e){this.value=e}eval(){return[this.value]}toString(){const e=this.value.value;return"string"==typeof e?`'${e}'`:e.toString()}}class Bi{constructor(e){this.name=e,_i.add(this)}eval(e){return"$this"===this.name?e:e.map((e=>t(this,_i,"m",ji).call(this,e))).flat().filter((e=>void 0!==e?.value))}toString(){return this.name}}_i=new WeakSet,ji=function(e){const t=e.value;if(t&&"object"==typeof t)return Ne(t)&&t.resourceType===this.name?e:gi(e,this.name)};class $i{eval(){return[]}toString(){return"{}"}}class qi extends ai{constructor(e,t,i){super(e,t),this.impl=i}eval(e){return this.impl(this.child.eval(e))}toString(){return this.child.toString()}}class Fi extends ci{constructor(e,t){super("as",e,t)}eval(e){return Ii.ofType(this.left.eval(e),this.right)}}class Hi extends ci{constructor(e,t,i,n){super(e,t,i),this.impl=n}eval(t){const i=this.left.eval(t);if(1!==i.length)return[];const n=this.right.eval(t);if(1!==n.length)return[];const r=i[0].value,o=n[0].value,s=Ci(r)?r.value:r,a=Ci(o)?o.value:o,c=this.impl(s,a);return"boolean"==typeof c?fi(c):Ci(r)?[{type:e.PropertyType.Quantity,value:{...r,value:c}}]:[mi(c)]}}class zi extends ci{constructor(e,t){super("&",e,t)}eval(t){const i=[...this.left.eval(t),...this.right.eval(t)];return i.length>0&&i.every((e=>"string"==typeof e.value))?[{type:e.PropertyType.string,value:i.map((e=>e.value)).join("")}]:i}}class Gi extends ci{constructor(e,t){super("contains",e,t)}eval(e){const t=this.left.eval(e),i=this.right.eval(e);return fi(t.some((e=>e.value===i[0].value)))}}class Vi extends ci{constructor(e,t){super("in",e,t)}eval(e){const t=this.left.eval(e);return fi(this.right.eval(e).some((e=>e.value===t[0].value)))}}class Xi extends ci{constructor(e,t){super(".",e,t)}eval(e){return this.right.eval(this.left.eval(e))}toString(){return`${this.left.toString()}.${this.right.toString()}`}}class Ji extends ci{constructor(e,t){super("|",e,t)}eval(e){return xi([...this.left.eval(e),...this.right.eval(e)])}}class Yi extends ci{constructor(e,t){super("=",e,t)}eval(e){return Si(this.left.eval(e),this.right.eval(e))}}class Ki extends ci{constructor(e,t){super("!=",e,t)}eval(e){return wi(Si(this.left.eval(e),this.right.eval(e)))}}class Zi extends ci{constructor(e,t){super("~",e,t)}eval(e){return Ei(this.left.eval(e),this.right.eval(e))}}class en extends ci{constructor(e,t){super("!~",e,t)}eval(e){return wi(Ei(this.left.eval(e),this.right.eval(e)))}}class tn extends ci{constructor(e,t){super("is",e,t)}eval(e){const t=this.left.eval(e);if(1!==t.length)return[];const i=this.right.name;return fi(Di(t[0],i))}}class nn extends ci{constructor(e,t){super("and",e,t)}eval(e){const t=this.left.eval(e),i=this.right.eval(e);return!0===t[0]?.value&&!0===i[0]?.value?fi(!0):!1===t[0]?.value||!1===i[0]?.value?fi(!1):[]}}class rn extends ci{constructor(e,t){super("or",e,t)}eval(e){const t=this.left.eval(e);if(yi(t))return t;const i=this.right.eval(e);return yi(i)?i:[]}}class on extends ci{constructor(e,t){super("xor",e,t)}eval(e){const t=this.left.eval(e),i=this.right.eval(e);if(0===t.length&&0===i.length)return[];const n=0===t.length?null:t[0].value,r=0===i.length?null:i[0].value;return!0===n&&!0!==r||!0!==n&&!0===r?fi(!0):!0===n&&!0===r||!1===n&&!1===r?fi(!1):[]}}class sn{constructor(e,t){this.name=e,this.args=t}eval(e){const t=Ii[this.name];if(!t)throw new Error("Unrecognized function: "+this.name);return t(e,...this.args)}toString(){return`${this.name}(${this.args.map((e=>e.toString())).join(", ")})`}}class an{constructor(e,t){this.left=e,this.expr=t}eval(e){const t=this.expr.eval(e);if(1!==t.length)return[];const i=t[0].value;if("number"!=typeof i)throw new Error("Invalid indexer expression: should return integer}");const n=this.left.eval(e);return i in n?[n[i]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}}const cn=["true","false"],un=["!=","!~","<=",">=","{}","->"];function ln(e){return new di(e,cn,un).tokenize()}const pn={parse(e){const t=e.consumeAndParse();if(!e.match(")"))throw new Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},dn={parse(e,t){const i=e.consumeAndParse();if(!e.match("]"))throw new Error("Parse error: expected `]`");return new an(t,i)},precedence:2},hn={parse(e,t){if(!(t instanceof Bi))throw new Error("Unexpected parentheses");const i=[];for(;!e.match(")");)i.push(e.consumeAndParse()),e.match(",");return new sn(t.name,i)},precedence:0};function fn(e){const t=e.split(" "),i=parseFloat(t[0]);let n=t[1];return n=n&&n.startsWith("'")&&n.endsWith("'")?n.substring(1,n.length-1):"{"+n+"}",{value:i,unit:n}}function mn(){return(new ui).registerPrefix("String",{parse:(t,i)=>new Qi({type:e.PropertyType.string,value:i.value})}).registerPrefix("DateTime",{parse:(t,i)=>new Qi({type:e.PropertyType.dateTime,value:hi(i.value)})}).registerPrefix("Quantity",{parse:(t,i)=>new Qi({type:e.PropertyType.Quantity,value:fn(i.value)})}).registerPrefix("Number",{parse:(t,i)=>new Qi({type:e.PropertyType.decimal,value:parseFloat(i.value)})}).registerPrefix("true",{parse:()=>new Qi({type:e.PropertyType.boolean,value:!0})}).registerPrefix("false",{parse:()=>new Qi({type:e.PropertyType.boolean,value:!1})}).registerPrefix("Symbol",{parse:(e,t)=>new Bi(t.value)}).registerPrefix("{}",{parse:()=>new $i}).registerPrefix("(",pn).registerInfix("[",dn).registerInfix("(",hn).prefix("+",3,((e,t)=>new qi("+",t,(e=>e)))).prefix("-",3,((e,t)=>new Hi("-",t,t,((e,t)=>-t)))).infixLeft(".",1,((e,t,i)=>new Xi(e,i))).infixLeft("/",4,((e,t,i)=>new Hi("/",e,i,((e,t)=>e/t)))).infixLeft("*",4,((e,t,i)=>new Hi("*",e,i,((e,t)=>e*t)))).infixLeft("+",5,((e,t,i)=>new Hi("+",e,i,((e,t)=>e+t)))).infixLeft("-",5,((e,t,i)=>new Hi("-",e,i,((e,t)=>e-t)))).infixLeft("|",7,((e,t,i)=>new Ji(e,i))).infixLeft("=",9,((e,t,i)=>new Yi(e,i))).infixLeft("!=",9,((e,t,i)=>new Ki(e,i))).infixLeft("~",9,((e,t,i)=>new Zi(e,i))).infixLeft("!~",9,((e,t,i)=>new en(e,i))).infixLeft("<",8,((e,t,i)=>new Hi("<",e,i,((e,t)=>e<t)))).infixLeft("<=",8,((e,t,i)=>new Hi("<=",e,i,((e,t)=>e<=t)))).infixLeft(">",8,((e,t,i)=>new Hi(">",e,i,((e,t)=>e>t)))).infixLeft(">=",8,((e,t,i)=>new Hi(">=",e,i,((e,t)=>e>=t)))).infixLeft("&",5,((e,t,i)=>new zi(e,i))).infixLeft("and",6,((e,t,i)=>new nn(e,i))).infixLeft("as",6,((e,t,i)=>new Fi(e,i))).infixLeft("contains",6,((e,t,i)=>new Gi(e,i))).infixLeft("div",6,((e,t,i)=>new Hi("div",e,i,((e,t)=>e/t|0)))).infixLeft("in",6,((e,t,i)=>new Vi(e,i))).infixLeft("is",6,((e,t,i)=>new tn(e,i))).infixLeft("mod",6,((e,t,i)=>new Hi("mod",e,i,((e,t)=>e%t)))).infixLeft("or",6,((e,t,i)=>new rn(e,i))).infixLeft("xor",6,((e,t,i)=>new on(e,i)))}const yn=mn();function gn(e){return new Wi(e,yn.construct(ln(e)).consumeAndParse())}function vn(e,t){const i=Array.isArray(t)?t:[t];for(let e=0;e<i.length;e++){const t=i[e];"object"==typeof t&&"type"in t&&"value"in t||(i[e]=mi(i[e]))}return xn(e,i).map((e=>e.value))}function xn(e,t){return gn(e).eval(t)}const wn=[...un,"->","<<",">>"];var Sn,Tn,En,bn,Pn,Dn,An,Cn,kn,Rn,On,Mn,In,Un,Ln,Nn,_n,jn,Wn;class Qn{constructor(e){this.parser=e,Sn.add(this),this.structureMap={resourceType:"StructureMap"}}parse(){for(this.parser.consume("Symbol","map"),this.structureMap.url=this.parser.consume("String").value,this.parser.consume("="),this.structureMap.name=this.parser.consume().value;this.parser.hasMore();){const e=this.parser.peek()?.value;switch(e){case"uses":t(this,Sn,"m",Tn).call(this);break;case"imports":t(this,Sn,"m",En).call(this);break;case"group":t(this,Sn,"m",bn).call(this);break;case"conceptmap":t(this,Sn,"m",Wn).call(this);break;default:throw new Error(`Unexpected token: ${e}`)}}return this.structureMap}}Sn=new WeakSet,Tn=function(){this.parser.consume("Symbol","uses");const e={};e.url=this.parser.consume("String").value,"alias"===this.parser.peek()?.value&&(this.parser.consume("Symbol","alias"),e.alias=this.parser.consume("Symbol").value),this.parser.consume("Symbol","as"),e.mode=this.parser.consume().value,this.structureMap.structure||(this.structureMap.structure=[]),this.structureMap.structure.push(e)},En=function(){this.parser.consume("Symbol","imports"),this.structureMap.import||(this.structureMap.import=[]),this.structureMap.import.push(this.parser.consume("String").value)},bn=function(){const e={};this.parser.consume("Symbol","group"),e.name=this.parser.consume("Symbol").value,e.input=t(this,Sn,"m",Pn).call(this),"extends"===this.parser.peek()?.value&&(this.parser.consume("Symbol","extends"),e.extends=this.parser.consume("Symbol").value),"<<"===this.parser.peek()?.value?(this.parser.consume("<<"),e.typeMode=this.parser.consume().value,"+"===this.parser.peek()?.value&&(this.parser.consume("+"),e.typeMode="type-and-types"),this.parser.consume(">>")):e.typeMode="none",e.rule=t(this,Sn,"m",An).call(this),this.structureMap.group||(this.structureMap.group=[]),this.structureMap.group.push(e)},Pn=function(){const e=[];for(this.parser.consume("(");this.parser.hasMore()&&")"!==this.parser.peek()?.value;)e.push(t(this,Sn,"m",Dn).call(this)),","===this.parser.peek()?.value&&this.parser.consume(",");return this.parser.consume(")"),e},Dn=function(){const e={};return e.mode=this.parser.consume().value,e.name=this.parser.consume("Symbol").value,":"===this.parser.peek()?.value&&(this.parser.consume(":"),e.type=this.parser.consume("Symbol").value),e},An=function(){const e=[];for(this.parser.consume("{");this.parser.hasMore()&&"}"!==this.parser.peek()?.value;)e.push(t(this,Sn,"m",Cn).call(this));return this.parser.consume("}"),e},Cn=function(){const e={source:t(this,Sn,"m",kn).call(this)};return"->"===this.parser.peek()?.value&&(this.parser.consume("->"),e.target=t(this,Sn,"m",On).call(this)),"then"===this.parser.peek()?.value&&(this.parser.consume("Symbol","then"),"{"===this.parser.peek()?.id?e.rule=t(this,Sn,"m",An).call(this):e.dependent=t(this,Sn,"m",jn).call(this)),"String"===this.parser.peek()?.id?e.name=this.parser.consume().value:e.name=e.source?.[0]?.element,this.parser.consume(";"),e},kn=function(){const e=[t(this,Sn,"m",Rn).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(t(this,Sn,"m",Rn).call(this));return e},Rn=function(){const e={},i=t(this,Sn,"m",_n).call(this);if(i.includes(".")){const t=i.split(".");e.context=t[0],e.element=t[1]}else e.context=i;if(this.parser.hasMore()&&":"===this.parser.peek()?.value&&(this.parser.consume(":"),e.type=this.parser.consume().value),this.parser.hasMore()&&"default"===this.parser.peek()?.value&&(this.parser.consume("default"),this.parser.consumeAndParse()),"first"!==this.parser.peek()?.value&&"not_first"!==this.parser.peek()?.value&&"last"!==this.parser.peek()?.value&&"not_last"!==this.parser.peek()?.value&&"only_one"!==this.parser.peek()?.value||(e.listMode=this.parser.consume().value),"as"===this.parser.peek()?.value&&(this.parser.consume("Symbol","as"),e.variable=this.parser.consume().value),"where"===this.parser.peek()?.value){this.parser.consume("Symbol","where");const t=this.parser.consumeAndParse(100);e.condition=t.toString()}if("check"===this.parser.peek()?.value){this.parser.consume("Symbol","check");const t=this.parser.consumeAndParse(100);e.check=t.toString()}return e},On=function(){const e=[t(this,Sn,"m",Mn).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(t(this,Sn,"m",Mn).call(this));return e},Mn=function(){const e={},i=t(this,Sn,"m",_n).call(this);if(i.includes(".")){const t=i.split(".");e.contextType="variable",e.context=t[0],e.element=t[1]}else e.context=i;return"="===this.parser.peek()?.value&&(this.parser.consume("="),t(this,Sn,"m",In).call(this,e)),"as"===this.parser.peek()?.value&&(this.parser.consume("Symbol","as"),e.variable=this.parser.consume().value),"first"!==this.parser.peek()?.value&&"share"!==this.parser.peek()?.value&&"last"!==this.parser.peek()?.value&&"collate"!==this.parser.peek()?.value||(e.listMode=[this.parser.consume().value]),e},In=function(e){e.transform="copy";const i=this.parser.consumeAndParse(6);if(i instanceof Bi)t(this,Sn,"m",Un).call(this,e,i);else if(i instanceof sn)t(this,Sn,"m",Ln).call(this,e,i);else{if(!(i instanceof Qi))throw new Error(`Unexpected FHIRPath: ${i}`);t(this,Sn,"m",Nn).call(this,e,i)}},Un=function(e,t){e.parameter=[{valueId:t.name}]},Ln=function(e,t){const i=t.name;switch(i){case"create":e.parameter=[{valueString:t.args?.[0].value.value}];break;case"translate":e.parameter=[{}];break;default:throw new Error("Unknown target function: "+i)}},Nn=function(e,t){switch(t.value.type){case"boolean":e.parameter=[{valueBoolean:t.value.value}];break;case"decimal":e.parameter=[{valueDecimal:t.value.value}];break;case"string":e.parameter=[{valueString:t.value.value}];break;default:throw new Error("Unknown target literal type: "+t.value.type)}},_n=function(){let e=this.parser.consume().value;for(;"."===this.parser.peek()?.value;)this.parser.consume("."),e+="."+this.parser.consume().value;return e},jn=function(){const e=this.parser.consumeAndParse(100);return[{name:e.name,variable:e.args.map((e=>e.name))}]},Wn=function(){for(;"}"!==this.parser.peek()?.value;)this.parser.consume();this.parser.consume("}")};const Bn=mn().registerInfix("->",{precedence:100}).registerInfix(";",{precedence:200});const $n=[...un,"eq","ne","co"];class qn{constructor(e,t,i){this.path=e,this.operator=t,this.value=i}}class Fn{constructor(e){this.child=e}}class Hn{constructor(e,t,i){this.keyword=e,this.left=t,this.right=i}}class zn{constructor(e){this.parser=e}parse(){let e;"("===this.parser.peek()?.value?(this.parser.consume("("),e=this.parse(),this.parser.consume(")")):"not"===this.parser.peek()?.value?(this.parser.consume("Symbol","not"),this.parser.consume("("),e=new Fn(this.parse()),this.parser.consume(")")):e=new qn(this.parser.consume("Symbol").value,this.parser.consume("Symbol").value,this.parser.consume().value);const t=this.parser.peek()?.value;return"and"===t||"or"===t?(this.parser.consume("Symbol",t),new Hn(t,e,this.parse())):e}}const Gn=mn();class Vn{constructor(e="\r",t="|",i="^",n="~",r="\\",o="&"){this.segmentSeparator=e,this.fieldSeparator=t,this.componentSeparator=i,this.repetitionSeparator=n,this.escapeCharacter=r,this.subcomponentSeparator=o}getMsh2(){return this.fieldSeparator+this.componentSeparator+this.repetitionSeparator+this.escapeCharacter+this.subcomponentSeparator}}class Xn{constructor(e,t=new Vn){this.context=t,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(this.context.segmentSeparator)}buildAck(){const e=new Date,t=this.get("MSH"),i=t?.get(2)?.toString()||"",n=t?.get(3)?.toString()||"",r=t?.get(4)?.toString()||"",o=t?.get(5)?.toString()||"",s=t?.get(9)?.toString()||"",a=t?.get(12)?.toString()||"2.5.1";return new Xn([new Jn(["MSH",this.context.getMsh2(),r,o,i,n,e.toISOString(),"","ACK",e.getTime().toString(),"P",a],this.context),new Jn(["MSA","AA",s,"OK"],this.context)])}static parse(e){if(!e.startsWith("MSH")){const e=new Error("Invalid HL7 message");throw e.type="entity.parse.failed",e}const t=new Vn("\r",e.charAt(3),e.charAt(4),e.charAt(5),e.charAt(6),e.charAt(7));return new Xn(e.split(/[\r\n]+/).map((e=>Jn.parse(e,t))),t)}}class Jn{constructor(e,t=new Vn){this.context=t,M(e)?this.fields=e.map((e=>Yn.parse(e))):this.fields=e,this.name=this.fields[0].components[0][0]}get(e){return this.fields[e]}toString(){return this.fields.map((e=>e.toString())).join(this.context.fieldSeparator)}static parse(e,t=new Vn){return new Jn(e.split(t.fieldSeparator).map((e=>Yn.parse(e,t))),t)}}class Yn{constructor(e,t=new Vn){this.context=t,this.components=e}get(e,t,i=0){let n=this.components[i][e]||"";return void 0!==t&&(n=n.split(this.context.subcomponentSeparator)[t]||""),n}toString(){return this.components.map((e=>e.join(this.context.componentSeparator))).join(this.context.repetitionSeparator)}static parse(e,t=new Vn){return new Yn(e.split(t.repetitionSeparator).map((e=>e.split(t.componentSeparator))),t)}}var Kn,Zn,er,tr,ir,nr,rr,or,sr,ar,cr,ur,lr,pr;const dr={base64Binary:"string",boolean:"boolean",canonical:"string",code:"string",date:"string",dateTime:"string",decimal:"number",id:"string",instant:"string",integer:"number",markdown:"string",oid:"string",positiveInt:"number",string:"string",time:"string",unsignedInt:"number",uri:"string",url:"string",uuid:"string",xhtml:"string","http://hl7.org/fhirpath/System.String":"string"},hr=new Set(["resourceType","id","meta","implicitRules","language","text","contained","extension","modifierExtension"]);function fr(e){const t=_e.types[e];return t&&t.structureDefinition.id===e&&"resource"===t.structureDefinition.kind}class mr{constructor(e){Kn.add(this),Zn.set(this,void 0),er.set(this,void 0),i(this,Zn,[],"f"),i(this,er,e,"f")}validate(){const e=t(this,er,"f");if(!e)throw new fe(pe("Resource is null"));const i=e.resourceType;if(!i)throw new fe(pe("Missing resource type"));if(yr(e,"",t(this,Zn,"f")),t(this,Kn,"m",tr).call(this,mi(e),i),t(this,Zn,"f").length>0)throw new fe({resourceType:"OperationOutcome",issue:t(this,Zn,"f")})}}function yr(e,t,i){null===e?i.push(gr(t,"Invalid null value")):Array.isArray(e)?function(e,t,i){for(let n=0;n<e.length;n++)void 0===e[n]?i.push(gr(`${t}[${n}]`,"Invalid undefined value")):yr(e[n],`${t}[${n}]`,i)}(e,t,i):"object"==typeof e&&function(e,t,i){for(const[n,r]of Object.entries(e))yr(r,`${t}${t?".":""}${n}`,i)}(e,t,i)}function gr(e,t){return{severity:"error",code:"structure",details:{text:t},expression:[e]}}var vr;function xr(t,i){let n=_e.types[t]?.searchParamsDetails?.[i.code];return n||(n=function(t,i){const n=i.code,r=function(e){return e.split("-").reduce(((e,t,i)=>e+(i?N(t):t)),"")}(n),o=Tr(t,i.expression)?.split(".");if(!o)return{columnName:r,type:e.SearchParameterType.TEXT};const s=Sr(i);let a,c,u=t,l=!1;for(let e=1;e<o.length;e++){if(a=Le(u,o[e]),!a)throw new Error(`Element definition not found for ${t} ${i.code}`);if("*"===a.max&&(l=!0),c=a.type?.[0].code,!c)return{columnName:r,type:s,array:l};e<o.length-1&&(u=wr(c)?Oe(a.path?.split(".")):c)}const p=Sr(i,c),d={columnName:r,type:p,elementDefinition:a,array:l};return function(e,t,i){const n=_e.types[e];n.searchParamsDetails||(n.searchParamsDetails={});n.searchParamsDetails[t]=i}(t,n,d),d}(t,i)),n}function wr(e){return"Element"===e||"BackboneElement"===e}function Sr(t,i){let n=e.SearchParameterType.TEXT;switch(t.type){case"date":n=i===e.PropertyType.dateTime||i===e.PropertyType.instant?e.SearchParameterType.DATETIME:e.SearchParameterType.DATE;break;case"number":n=e.SearchParameterType.NUMBER;break;case"quantity":n=e.SearchParameterType.QUANTITY;break;case"reference":n=e.SearchParameterType.REFERENCE;break;case"token":"boolean"===i&&(n=e.SearchParameterType.BOOLEAN)}return n}function Tr(e,t){const i=t.split(" | ");for(const t of i){if((n=t).includes(" as Period")||n.includes(" as SampledDate"))continue;const i=Er(t);if(i.startsWith(e+"."))return i}var n}function Er(e){let t=e.trim();t.startsWith("(")&&t.endsWith(")")&&(t=t.substring(1,t.length-1)),t.includes("[0]")&&(t=t.replaceAll("[0]",""));const i=[" != "," as ",".as(",".exists(",".resolve(",".where("];for(const e of i)t.includes(e)&&(t=t.substring(0,t.indexOf(e)));return t}Zn=new WeakMap,er=new WeakMap,Kn=new WeakSet,tr=function(e,i){const n=_e.types[e.type];if(!n)throw new fe(pe("Unknown type: "+e.type));const r=n.properties;t(this,Kn,"m",ir).call(this,i,r,e),t(this,Kn,"m",cr).call(this,i,e,r)},ir=function(e,i,n){for(const[r,o]of Object.entries(i))t(this,Kn,"m",nr).call(this,e+"."+r,o,n)},nr=function(e,i,n){const r=gi(n,e.split(".").pop());if(k(r))void 0!==i.min&&i.min>0&&t(this,Zn,"f").push(gr(e,"Missing required property"));else if("*"===i.max){if(!Array.isArray(r))return void t(this,Zn,"f").push(gr(e,"Expected array for property"));for(const n of r)t(this,Kn,"m",rr).call(this,e,i,n)}else t(this,Kn,"m",rr).call(this,e,i,r)},rr=function(e,i,n){null!==n.value&&(_(n.type.charAt(0))?t(this,Kn,"m",or).call(this,i,n):t(this,Kn,"m",tr).call(this,n,e))},or=function(e,i){const{type:n,value:r}=i;if(null===r)return;const o=dr[i.type];typeof r===o?"string"===o?t(this,Kn,"m",sr).call(this,e,n,r):"number"===o&&t(this,Kn,"m",ar).call(this,e,n,r):t(this,Kn,"m",pr).call(this,e,"Invalid type for "+n)},sr=function(e,i,n){if(!n.trim())return void t(this,Kn,"m",pr).call(this,e,"Invalid empty string");const r=_e.types[i]?.properties?.value;if(r?.type){const o=D(r.type[0],"http://hl7.org/fhir/StructureDefinition/regex");o&&(n.match(new RegExp(o))||t(this,Kn,"m",pr).call(this,e,"Invalid "+i+" format"))}},ar=function(i,n,r){var o;!isNaN(r)&&isFinite(r)?((o=n)!==e.PropertyType.integer&&o!==e.PropertyType.positiveInt&&o!==e.PropertyType.unsignedInt||Number.isInteger(r)||t(this,Kn,"m",pr).call(this,i,"Number is not an integer"),n===e.PropertyType.positiveInt&&r<=0&&t(this,Kn,"m",pr).call(this,i,"Number is less than or equal to zero"),n===e.PropertyType.unsignedInt&&r<0&&t(this,Kn,"m",pr).call(this,i,"Number is negative")):t(this,Kn,"m",pr).call(this,i,"Invalid "+n+" value")},cr=function(e,i,n){const r=i.value;for(const o of Object.keys(r))t(this,Kn,"m",ur).call(this,e,o,i,n)},ur=function(e,i,n,r){if(!(hr.has(i)||i in r||function(e,t,i){for(const n of Object.keys(i)){if(!n.endsWith("[x]"))continue;const i=n.replace("[x]","");if(!e.startsWith(i))continue;let r=gi(t,n);if(r&&(Array.isArray(r)&&(r=r[0]),r&&e===i+N(r.type)))return!0}return!1}(i,n,r)||t(this,Kn,"m",lr).call(this,e,i,n))){const n=`${e}.${i}`;t(this,Zn,"f").push(gr(n,`Invalid additional property "${n}"`))}},lr=function(e,i,n){if(!i.startsWith("_"))return!1;return i.slice(1)in n.value&&(t(this,Kn,"m",tr).call(this,{type:"Element",value:n.value[i]},e),!0)},pr=function(e,i){t(this,Zn,"f").push(gr(e.path,i))},e.SearchParameterType=void 0,(vr=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",vr.NUMBER="NUMBER",vr.QUANTITY="QUANTITY",vr.TEXT="TEXT",vr.REFERENCE="REFERENCE",vr.DATE="DATE",vr.DATETIME="DATETIME",vr.PERIOD="PERIOD";var br;e.Operator=void 0,(br=e.Operator||(e.Operator={})).EQUALS="eq",br.NOT_EQUALS="ne",br.GREATER_THAN="gt",br.LESS_THAN="lt",br.GREATER_THAN_OR_EQUALS="ge",br.LESS_THAN_OR_EQUALS="le",br.STARTS_AFTER="sa",br.ENDS_BEFORE="eb",br.APPROXIMATELY="ap",br.CONTAINS="contains",br.EXACT="exact",br.TEXT="text",br.NOT="not",br.ABOVE="above",br.BELOW="below",br.IN="in",br.NOT_IN="not-in",br.OF_TYPE="of-type",br.MISSING="missing";const Pr=[e.Operator.CONTAINS,e.Operator.EXACT,e.Operator.TEXT,e.Operator.NOT,e.Operator.ABOVE,e.Operator.BELOW,e.Operator.IN,e.Operator.NOT_IN,e.Operator.OF_TYPE,e.Operator.MISSING],Dr=[e.Operator.NOT_EQUALS,e.Operator.GREATER_THAN,e.Operator.LESS_THAN,e.Operator.GREATER_THAN_OR_EQUALS,e.Operator.LESS_THAN_OR_EQUALS,e.Operator.STARTS_AFTER,e.Operator.ENDS_BEFORE,e.Operator.APPROXIMATELY];function Ar(t,i,n){const r=_e.types[i.resourceType]?.searchParams?.[n.code];switch(r?.type){case"reference":return function(t,i,n){const r=vn(n.expression,t),o=Or(i.operator);if(""===i.value&&0===r.length)return i.operator===e.Operator.EQUALS;const s=r.map((e=>"string"==typeof e?e:e.reference));for(const e of i.value.split(",")){let t=s.includes(e);if(t||"_compartment"!==i.code||(t=s.some((t=>t?.endsWith("/"+e)))),t)return!o}return o}(t,n,r);case"string":return Cr(t,n,r);case"token":return function(t,i,n){const r=xr(t.resourceType,n);return r.type===e.SearchParameterType.BOOLEAN?function(e,t,i){const n=vn(i.expression,e),r="true"===t.value,o=n.includes(r);return Or(t.operator)?!o:o}(t,i,n):Cr(t,i,n,!0)}(t,n,r);case"date":return function(e,t,i){const n=vn(i.expression,e),r=t.value.split(","),o=Or(t.operator);for(const e of n)for(const i of r){if(Rr(e,t.operator,i))return!o}return o}(t,n,r)}return!1}function Cr(e,t,i,n){const r=vn(i.expression,e),o=t.value.split(","),s=Or(t.operator);for(const e of r)for(const i of o){if(kr(e,t.operator,i,n))return!s}return s}function kr(e,t,i,n){if(n&&i.includes("|")){const[n,r]=i.split("|");return kr(e,t,n,!1)&&(!r||kr(e,t,r,!1))}let r="";return e&&("string"==typeof e?r=e:"object"==typeof e&&(r=JSON.stringify(e))),r.toLowerCase().includes(i.toLowerCase())}function Rr(t,i,n){switch(i){case e.Operator.STARTS_AFTER:case e.Operator.GREATER_THAN:return t>n;case e.Operator.GREATER_THAN_OR_EQUALS:return t>=n;case e.Operator.ENDS_BEFORE:case e.Operator.LESS_THAN:return t<n;case e.Operator.LESS_THAN_OR_EQUALS:return t<=n;case e.Operator.EQUALS:case e.Operator.NOT_EQUALS:return t===n}return!1}function Or(t){return t===e.Operator.NOT_EQUALS||t===e.Operator.NOT}var Mr,Ir,Ur,Lr,Nr,_r,jr,Wr,Qr;const Br={eq:e.Operator.EQUALS,ne:e.Operator.NOT_EQUALS,lt:e.Operator.LESS_THAN,le:e.Operator.LESS_THAN_OR_EQUALS,gt:e.Operator.GREATER_THAN,ge:e.Operator.GREATER_THAN_OR_EQUALS,sa:e.Operator.STARTS_AFTER,eb:e.Operator.ENDS_BEFORE,ap:e.Operator.APPROXIMATELY},$r={contains:e.Operator.CONTAINS,exact:e.Operator.EXACT,above:e.Operator.ABOVE,below:e.Operator.BELOW,text:e.Operator.TEXT,not:e.Operator.NOT,in:e.Operator.IN,"not-in":e.Operator.NOT_IN,"of-type":e.Operator.OF_TYPE};class qr{constructor(e,i){Mr.add(this),this.resourceType=e,this.filters=[],this.sortRules=[];for(const[e,n]of Object.entries(i))Array.isArray(n)?n.forEach((i=>t(this,Mr,"m",Ir).call(this,e,i))):t(this,Mr,"m",Ir).call(this,e,n??"")}}function Fr(t){const i=t.substring(0,2);return i in Br?{operator:Br[i],value:t.substring(2)}:{operator:e.Operator.EQUALS,value:t}}function Hr(t){return $r[t]||e.Operator.EQUALS}Mr=new WeakSet,Ir=function(e,i){let n,r;const o=e.indexOf(":");switch(o>=0?(n=e.substring(0,o),r=e.substring(o+1)):(n=e,r=""),n){case"_sort":t(this,Mr,"m",Ur).call(this,i);break;case"_count":this.count=parseInt(i);break;case"_offset":this.offset=parseInt(i);break;case"_total":this.total=i;break;case"_summary":this.total="estimate",this.count=0;break;case"_revinclude":this.revInclude=i;break;default:{const e=_e.types[this.resourceType]?.searchParams?.[n];e?t(this,Mr,"m",Lr).call(this,e,r,i):t(this,Mr,"m",Qr).call(this,n,r,i)}}},Ur=function(e){for(const t of e.split(",")){let e,i=!1;t.startsWith("-")?(e=t.substring(1),i=!0):e=t,this.sortRules.push({code:e,descending:i})}},Lr=function(i,n,r){if("missing"!==n)switch(i.type){case"number":case"date":t(this,Mr,"m",Nr).call(this,i,r);break;case"string":case"token":case"uri":t(this,Mr,"m",_r).call(this,i,n,r);break;case"reference":t(this,Mr,"m",jr).call(this,i,r);break;case"quantity":t(this,Mr,"m",Wr).call(this,i,r)}else this.filters.push({code:i.code,operator:e.Operator.MISSING,value:r})},Nr=function(e,t){const{operator:i,value:n}=Fr(t);this.filters.push({code:e.code,operator:i,value:n})},_r=function(e,t,i){this.filters.push({code:e.code,operator:Hr(t),value:i})},jr=function(t,i){this.filters.push({code:t.code,operator:e.Operator.EQUALS,value:i})},Wr=function(e,t){const[i,n,r]=t.split("|"),{operator:o,value:s}=Fr(i);this.filters.push({code:e.code,operator:o,value:s,unitSystem:n,unitCode:r})},Qr=function(t,i,n){let r=e.Operator.EQUALS;if(i)r=i;else for(const e of Object.keys(Br))n.match(new RegExp("^"+e+"\\d"))&&(r=e,n=n.substring(e.length));this.filters.push({code:t,operator:r,value:n})},e.AndAtom=nn,e.ArithemticOperatorAtom=Hi,e.AsAtom=Fi,e.ConcatAtom=zi,e.ContainsAtom=Gi,e.DEFAULT_SEARCH_COUNT=20,e.DotAtom=Xi,e.EmptySetAtom=$i,e.EqualsAtom=Yi,e.EquivalentAtom=Zi,e.FHIRPATH_KEYWORDS=cn,e.FHIRPATH_OPERATORS=un,e.FhirFilterComparison=qn,e.FhirFilterConnective=Hn,e.FhirFilterNegation=Fn,e.FhirPathAtom=Wi,e.FhirSchemaValidator=mr,e.FunctionAtom=sn,e.Hl7Context=Vn,e.Hl7Field=Yn,e.Hl7Message=Xn,e.Hl7Segment=Jn,e.InAtom=Vi,e.IndexerAtom=an,e.InfixOperatorAtom=ci,e.IsAtom=tn,e.LRUCache=a,e.LiteralAtom=Qi,e.MEDPLUM_VERSION="2.0.7-c59953c5",e.MedplumClient=class extends H{constructor(e){if(super(),je.add(this),We.set(this,void 0),Qe.set(this,void 0),Be.set(this,void 0),$e.set(this,void 0),qe.set(this,void 0),Fe.set(this,void 0),He.set(this,void 0),ze.set(this,void 0),Ge.set(this,void 0),Ve.set(this,void 0),Xe.set(this,void 0),Je.set(this,void 0),Ye.set(this,void 0),Ke.set(this,void 0),Ze.set(this,void 0),et.set(this,void 0),tt.set(this,void 0),it.set(this,void 0),nt.set(this,void 0),rt.set(this,void 0),ot.set(this,void 0),st.set(this,void 0),e?.baseUrl&&!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");i(this,We,e?.fetch||function(){if(!globalThis.fetch)throw new Error("Fetch not available in this environment");return globalThis.fetch.bind(globalThis)}(),"f"),i(this,Qe,e?.createPdf,"f"),i(this,Be,new Pe,"f"),i(this,$e,new a(e?.resourceCacheSize??1e3),"f"),i(this,qe,e?.cacheTime??6e4,"f"),i(this,Fe,function(e){if(!e)return e;return e.endsWith("/")?e:e+"/"}(e?.baseUrl)||"https://api.medplum.com/","f"),i(this,He,t(this,Fe,"f")+"fhir/R4/","f"),i(this,Ke,e?.clientId||"","f"),i(this,ze,e?.authorizeUrl||t(this,Fe,"f")+"oauth2/authorize","f"),i(this,Ge,e?.tokenUrl||t(this,Fe,"f")+"oauth2/token","f"),i(this,Ve,e?.logoutUrl||t(this,Fe,"f")+"oauth2/logout","f"),i(this,Xe,e?.onUnauthenticated,"f"),i(this,Je,e?.autoBatchTime??0,"f"),i(this,Ye,[],"f");const n=this.getActiveLogin();n&&(i(this,tt,n.accessToken,"f"),i(this,it,n.refreshToken,"f"),t(this,je,"m",ct).call(this).catch(console.log)),t(this,je,"m",bt).call(this)}getBaseUrl(){return t(this,Fe,"f")}clear(){t(this,Be,"f").clear(),this.clearActiveLogin()}clearActiveLogin(){t(this,Be,"f").setString("activeLogin",void 0),t(this,$e,"f").clear(),i(this,tt,void 0,"f"),i(this,it,void 0,"f"),i(this,ot,void 0,"f"),i(this,st,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(e){e=e.toString(),t(this,$e,"f").delete(e)}invalidateSearches(e){const i="fhir/R4/"+e;for(const e of t(this,$e,"f").keys())(e.endsWith(i)||e.includes(i+"?"))&&t(this,$e,"f").delete(e)}get(e,n={}){e=e.toString();const r=t(this,je,"m",ut).call(this,e,n);if(r)return r.value;let o;o=e.startsWith(t(this,He,"f"))&&t(this,Je,"f")>0?new Promise(((r,o)=>{t(this,Ye,"f").push({method:"GET",url:e.replace(t(this,He,"f"),""),options:n,resolve:r,reject:o}),t(this,et,"f")||i(this,et,setTimeout((()=>t(this,je,"m",mt).call(this)),t(this,Je,"f")),"f")})):t(this,je,"m",ht).call(this,"GET",e,n);const s=new be(o);return t(this,je,"m",lt).call(this,e,s),s}post(e,i,n,r={}){return e=e.toString(),i&&t(this,je,"m",vt).call(this,r,i),n&&t(this,je,"m",gt).call(this,r,n),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"POST",e,r)}put(e,i,n,r={}){return e=e.toString(),i&&t(this,je,"m",vt).call(this,r,i),n&&t(this,je,"m",gt).call(this,r,n),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"PUT",e,r)}patch(e,i,n={}){return e=e.toString(),t(this,je,"m",vt).call(this,n,i),t(this,je,"m",gt).call(this,n,"application/json-patch+json"),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"PATCH",e,n)}delete(e,i={}){return e=e.toString(),this.invalidateUrl(e),t(this,je,"m",ht).call(this,"DELETE",e,i)}async startNewUser(e){const{codeChallengeMethod:t,codeChallenge:i}=await this.startPkce();return this.post("auth/newuser",{...e,codeChallengeMethod:t,codeChallenge:i})}async startNewProject(e){return this.post("auth/newproject",e)}async startNewPatient(e){return this.post("auth/newpatient",e)}async startLogin(e){return this.post("auth/login",{...await this.ensureCodeChallenge(e),clientId:e.clientId??t(this,Ke,"f"),scope:e.scope})}async startGoogleLogin(e){return this.post("auth/google",{...await this.ensureCodeChallenge(e),clientId:e.clientId??t(this,Ke,"f"),scope:e.scope})}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(t(this,Ve,"f"),{}),this.clear()}async signInWithRedirect(e){const i=new URLSearchParams(window.location.search).get("code");return i?this.processCode(i):void await t(this,je,"m",wt).call(this,e)}signOutWithRedirect(){window.location.assign(t(this,Ve,"f"))}async signInWithExternalAuth(e,t,i,n){const r=await this.ensureCodeChallenge(n);window.location.assign(this.getExternalAuthRedirectUri(e,t,i,r))}getExternalAuthRedirectUri(e,t,i,n){const r=new URL(e);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",t),r.searchParams.set("redirect_uri",i),r.searchParams.set("scope","openid profile email"),r.searchParams.set("state",JSON.stringify(n)),r.toString()}fhirUrl(...e){return new URL(t(this,He,"f")+e.join("/"))}fhirSearchUrl(e,t){const i=this.fhirUrl(e);return t&&(i.search=new URLSearchParams(t).toString()),i}search(e,i,n={}){const r=this.fhirSearchUrl(e,i),o=r.toString()+"-search",s=t(this,je,"m",ut).call(this,o,n);if(s)return s.value;const a=new be((async()=>{const e=await this.get(r,n);if(e.entry)for(const i of e.entry)t(this,je,"m",pt).call(this,i.resource);return e})());return t(this,je,"m",lt).call(this,o,a),a}searchOne(e,i,n={}){const r=this.fhirSearchUrl(e,i);r.searchParams.set("_count","1"),r.searchParams.sort();const o=r.toString()+"-searchOne",s=t(this,je,"m",ut).call(this,o,n);if(s)return s.value;const a=new be(this.search(e,r.searchParams,n).then((e=>e.entry?.[0]?.resource)));return t(this,je,"m",lt).call(this,o,a),a}searchResources(e,i,n={}){const r=this.fhirSearchUrl(e,i).toString()+"-searchResources",o=t(this,je,"m",ut).call(this,r,n);if(o)return o.value;const s=new be(this.search(e,i,n).then((e=>e.entry?.map((e=>e.resource))??[])));return t(this,je,"m",lt).call(this,r,s),s}searchValueSet(e,t,i={}){const n=this.fhirUrl("ValueSet","$expand");return n.searchParams.set("url",e),n.searchParams.set("filter",t),this.get(n.toString(),i)}getCached(e,i){const n=t(this,$e,"f").get(this.fhirUrl(e,i).toString())?.value;return n&&n.isOk()?n.read():void 0}getCachedReference(e){const t=e.reference;if(!t)return;if("system"===t)return Pt;const[i,n]=t.split("/");return i&&n?this.getCached(i,n):void 0}readResource(e,t,i={}){return this.get(this.fhirUrl(e,t),i)}readReference(e,t={}){const i=e?.reference;if(!i)return new be(Promise.reject(new Error("Missing reference")));if("system"===i)return new be(Promise.resolve(Pt));const[n,r]=i.split("/");return n&&r?this.readResource(n,r,t):new be(Promise.reject(new Error("Invalid reference")))}getSchema(){return _e}requestSchema(e){if(e in _e.types)return Promise.resolve(_e);const i=e+"-requestSchema",n=t(this,je,"m",ut).call(this,i,void 0);if(n)return n.value;const r=new be((async()=>{const t=`{\n StructureDefinitionList(name: "${e}") {\n name,\n description,\n snapshot {\n element {\n id,\n path,\n min,\n max,\n type {\n code,\n targetProfile\n },\n binding {\n valueSet\n },\n definition\n }\n }\n }\n SearchParameterList(base: "${e}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),i=await this.graphql(t);for(const e of i.data.StructureDefinitionList)ke(e);for(const e of i.data.SearchParameterList)Re(e);return _e})());return t(this,je,"m",lt).call(this,i,r),r}readHistory(e,t,i={}){return this.get(this.fhirUrl(e,t,"_history"),i)}readVersion(e,t,i,n={}){return this.get(this.fhirUrl(e,t,"_history",i),n)}readPatientEverything(e,t={}){return this.get(this.fhirUrl("Patient",e,"$everything"),t)}createResource(e){if(!e.resourceType)throw new Error("Missing resourceType");return this.invalidateSearches(e.resourceType),this.post(this.fhirUrl(e.resourceType),e)}async createResourceIfNoneExist(e,t){return await this.searchOne(e.resourceType,t)??this.createResource(e)}createBinary(e,t,i,n){const r=this.fhirUrl("Binary");return t&&r.searchParams.set("_filename",t),n?this.uploadwithProgress(r,e,i,n):this.post(r,e,i)}uploadwithProgress(e,i,n,r){return new Promise(((o,s)=>{const a=new XMLHttpRequest;a.responseType="json",a.onabort=()=>s(new Error("Request aborted")),a.onerror=()=>s(new Error("Request error")),r&&(a.upload.onprogress=e=>r(e),a.upload.onload=e=>r(e)),a.onload=()=>{a.status>=200&&a.status<300?o(a.response):s(new Error(a.statusText))},a.open("POST",e),a.withCredentials=!0,a.setRequestHeader("Authorization","Bearer "+t(this,tt,"f")),a.setRequestHeader("Cache-Control","no-cache, no-store, max-age=0"),a.setRequestHeader("Content-Type",n),a.setRequestHeader("X-Medplum","extended"),a.send(i)}))}async createPdf(e,i,n,r){if(!t(this,Qe,"f"))throw new Error("PDF creation not enabled");const o=await t(this,Qe,"f").call(this,e,n,r);return this.createBinary(o,i,"application/pdf")}createComment(e,t){const i=this.getProfile();let n,r;return"Encounter"===e.resourceType&&(n=x(e),r=e.subject),"ServiceRequest"===e.resourceType&&(n=e.encounter,r=e.subject),"Patient"===e.resourceType&&(r=x(e)),this.createResource({resourceType:"Communication",basedOn:[x(e)],encounter:n,subject:r,sender:i?x(i):void 0,sent:(new Date).toISOString(),payload:[{contentString:t}]})}async updateResource(e){if(!e.resourceType)throw new Error("Missing resourceType");if(!e.id)throw new Error("Missing id");this.invalidateSearches(e.resourceType);let i=await this.put(this.fhirUrl(e.resourceType,e.id),e);return i||(i=e),t(this,je,"m",pt).call(this,i),i}patchResource(e,t,i){return this.invalidateSearches(e),this.patch(this.fhirUrl(e,t),i)}deleteResource(e,i){return t(this,je,"m",dt).call(this,this.fhirUrl(e,i).toString()),this.invalidateSearches(e),this.delete(this.fhirUrl(e,i))}validateResource(e){return this.post(this.fhirUrl(e.resourceType,"$validate"),e)}executeBatch(e){return this.post("fhir/R4",e)}sendEmail(e){return this.post("email/v1/send",e,"application/json")}graphql(e,t,i,n){return this.post(this.fhirUrl("$graphql"),{query:e,operationName:t,variables:i},"application/json",n)}readResourceGraph(e,t,i){return this.get(`${this.fhirUrl(e,t)}/$graph?graph=${i}`)}getActiveLogin(){return t(this,Be,"f").getObject("activeLogin")}async setActiveLogin(e){this.clearActiveLogin(),i(this,tt,e.accessToken,"f"),i(this,it,e.refreshToken,"f"),t(this,Be,"f").setObject("activeLogin",e),t(this,je,"m",at).call(this,e),i(this,nt,void 0,"f"),await t(this,je,"m",ct).call(this)}getAccessToken(){return t(this,tt,"f")}setAccessToken(e){i(this,tt,e,"f"),i(this,it,void 0,"f"),i(this,ot,void 0,"f"),i(this,st,void 0,"f")}getLogins(){return t(this,Be,"f").getObject("logins")??[]}isLoading(){return!!t(this,rt,"f")}getProfile(){return t(this,ot,"f")}async getProfileAsync(){return t(this,rt,"f")&&await t(this,rt,"f"),this.getProfile()}getUserConfiguration(){return t(this,st,"f")}async download(e,i={}){t(this,nt,"f")&&await t(this,nt,"f"),t(this,je,"m",yt).call(this,i);return(await t(this,We,"f").call(this,e.toString(),i)).blob()}async startPkce(){const e=q();sessionStorage.setItem("pkceState",e);const t=q();sessionStorage.setItem("codeVerifier",t);const i=L(await async function(e){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}(t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");return sessionStorage.setItem("codeChallenge",i),{codeChallengeMethod:"S256",codeChallenge:i}}processCode(e){const i=new URLSearchParams;if(i.set("grant_type","authorization_code"),i.set("client_id",t(this,Ke,"f")),i.set("code",e),i.set("redirect_uri",Dt()),"undefined"!=typeof sessionStorage){const e=sessionStorage.getItem("codeVerifier");e&&i.set("code_verifier",e)}return t(this,je,"m",Tt).call(this,i)}async startClientLogin(e,n){i(this,Ke,e,"f"),i(this,Ze,n,"f");const r=new URLSearchParams;return r.set("grant_type","client_credentials"),r.set("client_id",e),r.set("client_secret",n),t(this,je,"m",Tt).call(this,r)}},e.NotEqualsAtom=Ki,e.NotEquivalentAtom=en,e.OperationOutcomeError=fe,e.OrAtom=rn,e.Parser=li,e.ParserBuilder=ui,e.PrefixOperatorAtom=ai,e.ReadablePromise=be,e.SymbolAtom=Bi,e.Tokenizer=di,e.UnaryOperatorAtom=qi,e.UnionAtom=Ji,e.XorAtom=on,e.allOk=ie,e.arrayBufferToBase64=L,e.arrayBufferToHex=U,e.assertOk=function(e,t){if(!he(e)||void 0===t)throw new fe(e)},e.badRequest=le,e.booleanToTypedValue=fi,e.buildTypeName=Oe,e.calculateAge=b,e.calculateAgeString=function(e,t){const{years:i,months:n,days:r}=b(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"},e.capitalize=N,e.checkForNull=yr,e.createReference=x,e.createStructureIssue=gr,e.created=ne,e.deepClone=function(e){return JSON.parse(JSON.stringify(e))},e.deepEquals=R,e.evalFhirPath=vn,e.evalFhirPathTyped=xn,e.fhirPathArrayEquals=Si,e.fhirPathArrayEquivalent=Ei,e.fhirPathEquals=Ti,e.fhirPathEquivalent=bi,e.fhirPathIs=Di,e.fhirPathNot=wi,e.findObservationInterval=function(e,t,i,n){return e.qualifiedInterval?.find((r=>j(r,t)&&function(e,t,i){return!!e.range&&W(t,e.range,i)}(r,i,e.quantitativeDetails?.decimalPrecision)&&(void 0===n||r.category===n)))},e.findObservationReferenceRange=function(e,t,i){return e.qualifiedInterval?.find((e=>j(e,t)&&i.includes(e.condition)))},e.forbidden=ae,e.formatAddress=function(e,t){const i=[];if(e.line&&i.push(...e.line),e.city||e.state||e.postalCode){const t=[];e.city&&t.push(e.city),e.state&&t.push(e.state),e.postalCode&&t.push(e.postalCode),i.push(t.join(", "))}return e.use&&(t?.all||t?.use)&&i.push("["+e.use+"]"),i.join(t?.lineSeparator||", ").trim()},e.formatCodeableConcept=y,e.formatCoding=g,e.formatDate=function(e,t,i){if(!e)return"";const n=new Date(e);return u(n)?(n.setUTCHours(0,0,0,0),n.toLocaleDateString(t,{timeZone:"UTC",...i})):""},e.formatDateTime=p,e.formatFamilyName=function(e){return e.family||""},e.formatGivenName=function(e){const t=[];return e.given&&t.push(...e.given),t.join(" ").trim()},e.formatHumanName=c,e.formatMoney=function(e){return void 0===e?.value?"":e.value.toLocaleString(void 0,{style:"currency",currency:e.currency||"USD",currencyDisplay:"narrowSymbol"})},e.formatObservationValue=function e(t){return t?"component"in t?t.component.map((t=>e(t))).join(" / "):t?.valueQuantity?m(t.valueQuantity):t.valueCodeableConcept?y(t.valueCodeableConcept):t.valueString?t.valueString:"":""},e.formatPeriod=function(e,t,i){return e&&(e.start||e.end)?p(e.start,t,i)+" - "+p(e.end,t,i):""},e.formatQuantity=m,e.formatRange=function(e,t,i=!1){if(i&&void 0===t)throw new Error("Precision must be specified for exclusive ranges");const n=e?.low&&{...e.low},r=e?.high&&{...e.high};return!e||void 0===n?.value&&void 0===r?.value?"":void 0!==e.low?.value&&void 0===e.high?.value?i&&void 0!==t?(e.low.value=function(e,t,i=1){return(v(e,t)-i)*Math.pow(10,-t)}(e.low.value,t),`> ${m(e.low,t)}`):`>= ${m(e.low,t)}`:void 0===e.low?.value&&void 0!==e.high?.value?i&&void 0!==t?(e.high.value=function(e,t,i=1){return(v(e,t)+i)*Math.pow(10,-t)}(e.high.value,t),`< ${m(e.high,t)}`):`<= ${m(e.high,t)}`:(n?.unit===r?.unit&&delete n?.unit,`${m(n,t)} - ${m(r,t)}`)},e.formatSearchQuery=function(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>t.push(function(e){const t=Pr.includes(e.operator)?":"+e.operator:"",i=Dr.includes(e.operator)?e.operator:"";return`${e.code}${t}=${i}${encodeURIComponent(e.value)}`}(e)))),e.sortRules&&e.sortRules.length>0&&t.push("_sort="+e.sortRules.map((e=>e.descending?"-"+e.code:e.code)).join(",")),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="+e.total),0===t.length?"":(t.sort(),"?"+t.join("&"))},e.formatTime=l,e.formatTiming=function(e){if(!e)return"";const t=[];if(e.repeat?.periodUnit){const i=e.repeat.frequency||1,n=e.repeat.period||1,r=e.repeat.periodUnit;1===i&&1===n?t.push(d[r]):(1===i?t.push("once"):t.push(i+" times"),1===n?t.push("per "+h[r]):t.push("per "+n+" "+f[r])),e.repeat.dayOfWeek&&t.push("on "+e.repeat.dayOfWeek.map(N).join(", ")),e.repeat.timeOfDay&&t.push("at "+e.repeat.timeOfDay.map((e=>l(e))).join(", "))}return e.event&&t.push(e.event.map((e=>p(e))).join(", ")),N(t.join(" ").trim())},e.getCodeBySystem=function(e,t){return e?.coding?.find((e=>e.system===t))?.code},e.getDateProperty=function(e){return e?new Date(e):void 0},e.getDisplayString=T,e.getElementDefinition=Le,e.getElementDefinitionTypeName=function(e){const t=e.type?.[0]?.code;return"BackboneElement"===t||"Element"===t?Oe(e.path?.split(".")):t},e.getExpressionForResourceType=Tr,e.getExtension=function(e,...t){let i=e;for(let e=0;e<t.length&&i;e++)i=i?.extension?.find((i=>i.url===t[e]));return i},e.getExtensionValue=D,e.getIdentifier=function(e,t){const i=e.identifier;if(!i)return;const n=Array.isArray(i)?i:[i];for(const e of n)if(e.system===t)return e.value},e.getImageSrc=function(e){if(!("photo"in e))return;const t=e.photo;if(t){if(!Array.isArray(t))return E(t);for(const e of t){const t=E(e);if(t)return t}}},e.getPropertyDisplayName=function(e){return e.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(Ue).join(" ").replace("_"," ").replace(/\s+/g," ")},e.getQuestionnaireAnswers=function(e){const t={};return P(e.item,t),t},e.getReferenceString=w,e.getResourceTypeSchema=function(e){return _e.types[e]},e.getResourceTypes=function(){const e=[];for(const[t,i]of Object.entries(_e.types))Me(i)&&e.push(t);return e},e.getSearchParameterDetails=xr,e.getSearchParameters=function(e){return _e.types[e].searchParams},e.getStatus=function(e){return e.id===V?200:e.id===X?201:e.id===Y?304:e.id===Z?401:e.id===ee?403:e.id===K?404:e.id===J?410:e.id===te?429:400},e.getTypedPropertyValue=gi,e.globalSchema=_e,e.gone=ce,e.indexSearchParameter=Re,e.indexSearchParameterBundle=function(e){for(const t of e.entry){const e=t.resource;"SearchParameter"===e.resourceType&&Re(e)}},e.indexStructureDefinition=ke,e.indexStructureDefinitionBundle=function(e){for(const t of e.entry){const e=t.resource;"StructureDefinition"===e.resourceType&&ke(e)}},e.initFhirPathParserBuilder=mn,e.isEmpty=k,e.isGone=function(e){return e.id===J},e.isLowerCase=_,e.isNotFound=function(e){return e.id===K},e.isObject=O,e.isOk=he,e.isOperationOutcome=de,e.isPeriod=Ai,e.isProfileResource=S,e.isQuantity=Ci,e.isQuantityEquivalent=ki,e.isReference=function(e){return!(!e||"object"!=typeof e||!("reference"in e))},e.isResource=Ne,e.isResourceType=fr,e.isResourceTypeSchema=Me,e.isStringArray=M,e.isUUID=function(e){return!!e.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)},e.isValidDate=u,e.matchesRange=W,e.matchesSearchRequest=function(e,t){if(t.resourceType!==e.resourceType)return!1;if(t.filters)for(const i of t.filters)if(!Ar(e,t,i))return!1;return!0},e.normalizeErrorString=ye,e.normalizeOperationOutcome=me,e.notFound=oe,e.notModified=re,e.parseFhirPath=gn,e.parseFilterParameter=function(e){const t=Gn.construct(new di(e,cn,$n,{dateTimeLiterals:!0,symbolRegex:/[^\s\])]/}).tokenize());return t.removeComments(),new zn(t).parse()},e.parseJWTPayload=G,e.parseMappingLanguage=function(e){const t=Bn.construct(new di(e,cn,wn).tokenize());return t.removeComments(),new Qn(t).parse()},e.parseSearchDefinition=function(t){const i=new URL(t,"https://example.com/"),n=i.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let r,o,s,a,c,u;return new URLSearchParams(i.search).forEach(((t,i)=>{"_fields"===i?s=t.split(","):"_offset"===i?a=parseInt(t):"_count"===i?c=parseInt(t):"_total"===i?u=t:"_sort"===i?(o=o||[],o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(t))):(r=r||[],r.push(function(t,i){let n=t,r=e.Operator.EQUALS;for(const e of Pr){const t=n.indexOf(":"+e);-1!==t&&(r=e,n=n.substring(0,t))}for(const e of Dr)i.match(new RegExp("^"+e+"\\d"))&&(r=e,i=i.substring(e.length));return{code:n,operator:r,value:i}}(i,t)))})),{resourceType:n,filters:r,fields:s,offset:a,count:c,total:u,sortRules:o}},e.parseSearchRequest=function(e,t){return new qr(e,t)},e.parseSearchUrl=function(e){const t=e.pathname.split("/").pop();return new qr(t,Object.fromEntries(e.searchParams.entries()))},e.preciseEquals=function(e,t,i){return $(e,i)===$(t,i)},e.preciseGreaterThan=function(e,t,i){return $(e,i)>$(t,i)},e.preciseGreaterThanOrEquals=B,e.preciseLessThan=function(e,t,i){return $(e,i)<$(t,i)},e.preciseLessThanOrEquals=Q,e.preciseRound=function(e,t){return parseFloat(e.toFixed(t))},e.removeDuplicates=xi,e.resolveId=function(e){return e?.reference?.split("/")[1]},e.setCodeBySystem=function(e,t,i){e.coding||(e.coding=[]);const n=e.coding?.find((e=>e.system===t));n?n.code=i:e.coding?.push({system:t,code:i})},e.stringify=A,e.toJsBoolean=yi,e.toTypedValue=mi,e.tokenize=ln,e.tooManyRequests=ue,e.unauthorized=se,e.validateResource=function(e){new mr(e).validate()},e.validateResourceType=function(e){if(!e)throw new fe(pe("Resource type is null"));if(!fr(e))throw new fe(pe("Unknown resource type"))},e.validationError=pe}));