@medplum/core 2.0.12 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +138 -22
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/esm/bundle.mjs +36 -0
- package/dist/esm/bundle.mjs.map +1 -0
- package/dist/esm/client.mjs +83 -5
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/fhirmapper/tokenize.mjs +2 -3
- package/dist/esm/fhirmapper/tokenize.mjs.map +1 -1
- package/dist/esm/fhirpath/atoms.mjs +13 -19
- package/dist/esm/fhirpath/atoms.mjs.map +1 -1
- package/dist/esm/filter/parse.mjs +1 -2
- package/dist/esm/filter/parse.mjs.map +1 -1
- package/dist/esm/filter/tokenize.mjs +2 -3
- package/dist/esm/filter/tokenize.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/schema.mjs +7 -4
- package/dist/esm/schema.mjs.map +1 -1
- package/dist/esm/search/match.mjs +2 -2
- package/dist/esm/search/match.mjs.map +1 -1
- package/dist/esm/search/search.mjs +3 -0
- package/dist/esm/search/search.mjs.map +1 -1
- package/dist/esm/types.mjs +1 -1
- package/dist/esm/types.mjs.map +1 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/types/bundle.d.ts +11 -0
- package/dist/types/client.d.ts +56 -2
- package/dist/types/fhirpath/atoms.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/search/search.d.ts +1 -0
- package/dist/types/utils.d.ts +8 -1
- package/package.json +1 -1
package/dist/cjs/index.min.cjs
CHANGED
|
@@ -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,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function n(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof 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"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}var i,r,o,s;class a{constructor(e=10){i.add(this),r.set(this,void 0),o.set(this,void 0),n(this,r,e,"f"),n(this,o,new Map,"f")}clear(){t(this,o,"f").clear()}get(e){const n=t(this,o,"f").get(e);return n&&(t(this,o,"f").delete(e),t(this,o,"f").set(e,n)),n}set(e,n){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,i,"m",s).call(this)),t(this,o,"f").set(e,n)}delete(e){t(this,o,"f").delete(e)}keys(){return t(this,o,"f").keys()}}function c(e,t){const n=[];return e.prefix&&!1!==t?.prefix&&n.push(...e.prefix),e.given&&n.push(...e.given),e.family&&n.push(e.family),e.suffix&&!1!==t?.suffix&&n.push(...e.suffix),e.use&&(t?.all||t?.use)&&n.push("["+e.use+"]"),n.join(" ").trim()}function u(e){return e instanceof Date&&!isNaN(e.getTime())}function l(e,t,n){if(!e)return"";const i=new Date("2000-01-01T"+e+"Z");return u(i)?i.toLocaleTimeString(t,n):""}function p(e,t,n){if(!e)return"";const i=new Date(e);return u(i)?i.toLocaleString(t,n):""}r=new WeakMap,o=new WeakMap,i=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 n=[];return e.comparator&&(n.push(e.comparator),n.push(" ")),void 0!==e.value&&(void 0!==t?n.push(e.value.toFixed(t)):n.push(e.value)),e.unit&&("%"!==e.unit&&" "!==n[n.length-1]&&n.push(" "),n.push(e.unit)),n.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),n=T(e);return n===t?{reference:t}:{reference:t,display:n}}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 b(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function E(e,t){const n=new Date(e);n.setUTCHours(0,0,0,0);const i=t?new Date(t):new Date;i.setUTCHours(0,0,0,0);const r=n.getUTCFullYear(),o=n.getUTCMonth(),s=n.getUTCDate(),a=i.getUTCFullYear(),c=i.getUTCMonth(),u=i.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((i.getTime()-n.getTime())/864e5)}}function P(e,t){if(e)for(const n of e)n.linkId&&n.answer&&n.answer.length>0&&(t[n.linkId]=n.answer[0]),P(n.item,t)}function D(e,...t){let n=e;for(let e=0;e<t.length&&n;e++)n=n?.extension?.find((n=>n.url===t[e]));return n?.valueString}function C(e,t){return JSON.stringify(e,k,t?2:void 0)}function k(e,t){return!function(e){return!!e.match(/\d+$/)}(e)&&A(t)?void 0:t}function A(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,n){return e===t||(!(!A(e)||!A(t))||!A(e)&&!A(t)&&(Array.isArray(e)&&Array.isArray(t)?function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!R(e[n],t[n]))return!1;return!0}(e,t):!Array.isArray(e)&&!Array.isArray(t)&&(O(e)&&O(t)?function(e,t,n){const i=new Set;Object.keys(e).forEach((e=>i.add(e))),Object.keys(t).forEach((e=>i.add(e))),"meta"===n&&(i.delete("versionId"),i.delete("lastUpdated"),i.delete("author"));for(const n of i){if(!R(e[n],t[n],n))return!1}return!0}(e,t,n):(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),n=new Array(t.length);for(let e=0;e<t.length;e++)n[e]=I[t[e]];return n.join("")}function L(e){const t=new Uint8Array(e),n=[];for(let e=0;e<t.length;e++)n[e]=String.fromCharCode(t[e]);return window.btoa(n.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(E(t.birthDate).years,e.age)}(e,t)}function W(e,t,n){return(void 0===t.low?.value||B(e,t.low.value,n))&&(void 0===t.high?.value||Q(e,t.high.value,n))}function Q(e,t,n){return $(e,n)<=$(t,n)}function B(e,t,n){return $(e,n)>=$(t,n)}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),n(this,F,{},"f")}addEventListener(e,n){t(this,F,"f")[e]||(t(this,F,"f")[e]=[]),t(this,F,"f")[e].push(n)}removeEventListeneer(e,n){const i=t(this,F,"f")[e];if(i)for(let e=0;e<i.length;e++)if(i[e]===n)return void i.splice(e,1)}dispatchEvent(e){const n=t(this,F,"f")[e.type];return n&&n.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,"/")),n=Array.from(t).reduce(((e,t)=>`${e}%${("00"+t.charCodeAt(0).toString(16)).slice(-2)}`),""),i=decodeURIComponent(n);return JSON.parse(i)}function G(e){const[t,n,i]=e.split(".");return z(n)}F=new WeakMap;const V="ok",X="created",J="gone",Y="not-modified",K="not-found",Z="unauthorized",ee="forbidden",te="too-many-requests",ne={resourceType:"OperationOutcome",id:V,issue:[{severity:"information",code:"informational",details:{text:"All OK"}}]},ie={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(ge(e)),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)?ge(e):JSON.stringify(e):"Unknown error"}function ge(e){const t=[];if(e.issue)for(const n of e.issue){let e=n.details?.text||"Unknown error";n.expression?.length&&(e+=` (${n.expression.join(", ")})`),t.push(e)}return t.length>0?t.join("; "):"Unknown error"}var ve,xe,we,Se,Te,be,Ee;class Pe{constructor(e){this[Te]="ReadablePromise",ve.set(this,void 0),xe.set(this,"pending"),we.set(this,void 0),Se.set(this,void 0),n(this,ve,e.then((e=>(n(this,xe,"success","f"),n(this,we,e,"f"),e)),(e=>{throw n(this,xe,"error","f"),n(this,Se,e,"f"),e})),"f")}isPending(){return"pending"===t(this,xe,"f")}isOk(){return"success"===t(this,xe,"f")}read(){switch(t(this,xe,"f")){case"pending":throw t(this,ve,"f");case"error":throw t(this,Se,"f");default:return t(this,we,"f")}}then(e,n){return t(this,ve,"f").then(e,n)}catch(e){return t(this,ve,"f").catch(e)}finally(e){return t(this,ve,"f").finally(e)}}ve=new WeakMap,xe=new WeakMap,we=new WeakMap,Se=new WeakMap,Te=Symbol.toStringTag;class De{constructor(){be.set(this,void 0),n(this,be,"undefined"!=typeof localStorage?localStorage:new Ce,"f")}clear(){t(this,be,"f").clear()}getString(e){return t(this,be,"f").getItem(e)||void 0}setString(e,n){n?t(this,be,"f").setItem(e,n):t(this,be,"f").removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?C(t):void 0)}}be=new WeakMap;class Ce{constructor(){Ee.set(this,void 0),n(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,n){n?t(this,Ee,"f").set(e,n):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 ke,Ae={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 Re(e){if(!e.name)return;const t=e.snapshot?.element;t&&(t.forEach((t=>function(e,t){const n=t.path,i=t.type?.[0]?.code;if(void 0!==i&&"Element"!==i&&"BackboneElement"!==i)return;const r=n.split(".");r[0]=e.name;const o=Me(r);let s=je.types[o];s||(je.types[o]=s={});s.parentType=s.parentType||Me(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 n=t.path,i=n.split(".");if(1===i.length)return;i[0]=e.name;const r=Me(i.slice(0,i.length-1)),o=je.types[r];if(!o)return;const s=i[i.length-1];o.properties[s]=t}(e,t))))}function Oe(e){if(e.base)for(const t of e.base){const n=je.types[t];n&&(n.searchParams||(n.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"}}),n.searchParams[e.code]=e)}}function Me(e){return 1===e.length?e[0]:e.map(N).join("")}function Ie(e){const t=e.structureDefinition;return t&&t.name===e.elementDefinition?.path&&"resource"===t.kind&&!t.abstract}e.PropertyType=void 0,(ke=e.PropertyType||(e.PropertyType={})).Address="Address",ke.Age="Age",ke.Annotation="Annotation",ke.Attachment="Attachment",ke.BackboneElement="BackboneElement",ke.CodeableConcept="CodeableConcept",ke.Coding="Coding",ke.ContactDetail="ContactDetail",ke.ContactPoint="ContactPoint",ke.Contributor="Contributor",ke.Count="Count",ke.DataRequirement="DataRequirement",ke.Distance="Distance",ke.Dosage="Dosage",ke.Duration="Duration",ke.Expression="Expression",ke.Extension="Extension",ke.HumanName="HumanName",ke.Identifier="Identifier",ke.MarketingStatus="MarketingStatus",ke.Meta="Meta",ke.Money="Money",ke.Narrative="Narrative",ke.ParameterDefinition="ParameterDefinition",ke.Period="Period",ke.Population="Population",ke.ProdCharacteristic="ProdCharacteristic",ke.ProductShelfLife="ProductShelfLife",ke.Quantity="Quantity",ke.Range="Range",ke.Ratio="Ratio",ke.Reference="Reference",ke.RelatedArtifact="RelatedArtifact",ke.SampledData="SampledData",ke.Signature="Signature",ke.SubstanceAmount="SubstanceAmount",ke.SystemString="http://hl7.org/fhirpath/System.String",ke.Timing="Timing",ke.TriggerDefinition="TriggerDefinition",ke.UsageContext="UsageContext",ke.base64Binary="base64Binary",ke.boolean="boolean",ke.canonical="canonical",ke.code="code",ke.date="date",ke.dateTime="dateTime",ke.decimal="decimal",ke.id="id",ke.instant="instant",ke.integer="integer",ke.markdown="markdown",ke.oid="oid",ke.positiveInt="positiveInt",ke.string="string",ke.time="time",ke.unsignedInt="unsignedInt",ke.uri="uri",ke.url="url",ke.uuid="uuid";const Ue=new Set(["ID","PKCE","JWKS","URI","URL"]);function Le(e){const t=e.toUpperCase();return Ue.has(t)?t:t.charAt(0)+e.slice(1)}function Ne(e,t){const n=je.types[e];if(!n)return;const i=n.properties[t]??n.properties[t+"[x]"];if(i){if(i.contentReference){const e=i.contentReference.substring(1).split("."),t=e.pop();return Ne(Me(e),t)}return i}}function _e(e){return!(!e||"object"!=typeof e||!("resourceType"in e))}const je=Ae;var We,Qe,Be,$e,qe,Fe,He,ze,Ge,Ve,Xe,Je,Ye,Ke,Ze,et,tt,nt,it,rt,ot,st,at,ct,ut,lt,pt,dt,ht,ft,mt,yt,gt,vt,xt,wt,St,Tt,bt,Et,Pt;const Dt={resourceType:"Device",id:"system",deviceName:[{name:"System"}]};function Ct(){return"undefined"==typeof window?"":window.location.protocol+"//"+window.location.host+"/"}var kt,At,Rt,Ot,Mt,It,Ut,Lt,Nt,_t,jt,Wt,Qt,Bt,$t,qt,Ft,Ht,zt,Gt,Vt,Xt,Jt,Yt,Kt,Zt,en,tn,nn,rn,on,sn,an,cn;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,nt=new WeakMap,it=new WeakMap,rt=new WeakMap,ot=new WeakMap,st=new WeakMap,at=new WeakMap,We=new WeakSet,ct=function(e){const n=this.getLogins().filter((t=>t.profile?.reference!==e.profile?.reference));n.push(e),t(this,$e,"f").setObject("logins",n)},ut=async function(){return n(this,ot,new Promise(((e,i)=>{this.get("auth/me").then((i=>{n(this,ot,void 0,"f"),n(this,st,i.profile,"f"),n(this,at,i.config,"f"),this.dispatchEvent({type:"change"}),e(t(this,st,"f"))})).catch(i)})),"f"),t(this,ot,"f")},lt=function(e,n){if(t(this,Fe,"f")<=0||"no-cache"===n?.cache||"reload"===n?.cache)return;const i=t(this,qe,"f").get(e);return!i||i.requestTime+t(this,Fe,"f")<Date.now()?void 0:i},pt=function(e,n){t(this,Fe,"f")>0&&t(this,qe,"f").set(e,{requestTime:Date.now(),value:n})},dt=function(e){e?.id&&t(this,We,"m",pt).call(this,this.fhirUrl(e.resourceType,e.id).toString(),new Pe(Promise.resolve(e)))},ht=function(e){t(this,Fe,"f")>0&&t(this,qe,"f").delete(e)},ft=async function(e,n,i={}){t(this,rt,"f")&&await t(this,rt,"f"),n.startsWith("http")||(n=t(this,He,"f")+n),i.method=e,t(this,We,"m",gt).call(this,i);const r=await t(this,We,"m",mt).call(this,n,i);if(401===r.status)return t(this,We,"m",wt).call(this,e,n,i);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},mt=async function(e,n){let i;for(let r=0;r<3;r++){if(i=await t(this,Qe,"f").call(this,e,n),i.status<500)return i;await new Promise((e=>setTimeout(e,200)))}return i},yt=async function(){const e=[...t(this,Ke,"f")];if(t(this,Ke,"f").length=0,n(this,tt,void 0,"f"),1===e.length){const n=e[0];return void n.resolve(await t(this,We,"m",ft).call(this,n.method,t(this,ze,"f")+n.url,n.options))}const i={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",i);for(let t=0;t<e.length;t++){const n=e[t],i=r.entry?.[t];i?.response?.outcome&&!he(i.response.outcome)?n.reject(new fe(i.response.outcome)):n.resolve(i?.resource)}},gt=function(e){e.headers||(e.headers={});const n=e.headers;n["X-Medplum"]="extended",n["Content-Type"]||(n["Content-Type"]="application/fhir+json"),t(this,nt,"f")&&(n.Authorization="Bearer "+t(this,nt,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},vt=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},xt=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))},wt=function(e,n,i){return t(this,We,"m",Tt).call(this)?t(this,We,"m",ft).call(this,e,n,i):(this.clearActiveLogin(),t(this,Je,"f")&&t(this,Je,"f").call(this),Promise.reject(new Error("Unauthenticated")))},St=async function(e){const n=await this.ensureCodeChallenge(e||{}),i=new URL(t(this,Ge,"f"));i.searchParams.set("response_type","code"),i.searchParams.set("state",sessionStorage.getItem("pkceState")),i.searchParams.set("client_id",n.clientId||t(this,Ze,"f")),i.searchParams.set("redirect_uri",n.redirectUri||Ct()),i.searchParams.set("code_challenge_method",n.codeChallengeMethod),i.searchParams.set("code_challenge",n.codeChallenge),i.searchParams.set("scope",n.scope||"openid profile"),window.location.assign(i.toString())},Tt=function(){if(t(this,rt,"f"))return t(this,rt,"f");if(t(this,it,"f")){const e=new URLSearchParams;return e.set("grant_type","refresh_token"),e.set("client_id",t(this,Ze,"f")),e.set("refresh_token",t(this,it,"f")),n(this,rt,t(this,We,"m",bt).call(this,e),"f"),t(this,rt,"f")}return t(this,Ze,"f")&&t(this,et,"f")?(n(this,rt,this.startClientLogin(t(this,Ze,"f"),t(this,et,"f")),"f"),t(this,rt,"f")):void 0},bt=async function(e){const n=await t(this,Qe,"f").call(this,t(this,Ve,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e,credentials:"include"});if(!n.ok)throw this.clearActiveLogin(),new Error("Failed to fetch tokens");const i=await n.json();return await t(this,We,"m",Et).call(this,i),this.getProfile()},Et=async function(e){const n=e.access_token,i=G(n);if(Date.now()>=1e3*i.exp)throw this.clearActiveLogin(),new Error("Token expired");if(t(this,Ze,"f")&&i.client_id!==t(this,Ze,"f"))throw this.clearActiveLogin(),new Error("Token was not issued for this audience");return this.setActiveLogin({accessToken:n,refreshToken:e.refresh_token,project:e.project,profile:e.profile})},Pt=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class un{constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}}class ln{constructor(e,t,n){this.operator=e,this.left=t,this.right=n}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class pn{constructor(){kt.set(this,{}),At.set(this,{})}registerInfix(e,n){return t(this,At,"f")[e]=n,this}registerPrefix(e,n){return t(this,kt,"f")[e]=n,this}prefix(e,t,n){return this.registerPrefix(e,{parse(e,i){const r=e.consumeAndParse(t);return n(i,r)}})}infixLeft(e,t,n){return this.registerInfix(e,{parse(e,i,r){const o=e.consumeAndParse(t);return n(i,r,o)},precedence:t})}construct(e){return new dn(e,t(this,kt,"f"),t(this,At,"f"))}}kt=new WeakMap,At=new WeakMap;class dn{constructor(e,t,i){Rt.set(this,void 0),Ot.set(this,void 0),Mt.set(this,void 0),n(this,Rt,e,"f"),n(this,Ot,t,"f"),n(this,Mt,i,"f")}hasMore(){return t(this,Rt,"f").length>0}match(e){const t=this.peek();return t?.id===e&&(this.consume(),!0)}consumeAndParse(e=1/0){const n=this.consume(),i=t(this,Ot,"f")[n.id];if(!i)throw Error(`Parse error at "${n.value}" (line ${n.line}, column ${n.column}). No matching prefix parselet.`);let r=i.parse(this,n);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,n){if(!t(this,Rt,"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(n&&this.peek()?.value!==n){const e=this.peek();throw Error(`Expected "${n}" but got "${e.value}" at line ${e.line} column ${e.column}.`)}return t(this,Rt,"f").shift()}peek(){return t(this,Rt,"f").length>0?t(this,Rt,"f")[0]:void 0}removeComments(){n(this,Rt,t(this,Rt,"f").filter((e=>"Comment"!==e.id)),"f")}getInfixParselet(e){return t(this,Mt,"f")["Symbol"===e.id?e.value:e.id]}}Rt=new WeakMap,Ot=new WeakMap,Mt=new WeakMap;const hn=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"];class fn{constructor(e,t,i,r){It.add(this),Ut.set(this,void 0),Lt.set(this,void 0),Nt.set(this,void 0),_t.set(this,void 0),jt.set(this,void 0),Wt.set(this,[]),Qt.set(this,{index:0,line:1,column:0}),Bt.set(this,[]),n(this,Ut,e,"f"),n(this,Lt,t,"f"),n(this,Nt,i,"f"),n(this,_t,!!r?.dateTimeLiterals,"f"),n(this,jt,r?.symbolRegex??/[$\w]/,"f")}tokenize(){for(;t(this,Qt,"f").index<t(this,Ut,"f").length;){const e=t(this,It,"m",Ft).call(this);e&&t(this,Wt,"f").push(e)}return t(this,Wt,"f")}}function mn(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 yn(t){return[{type:e.PropertyType.boolean,value:t}]}function gn(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}:Rn(t)?{type:e.PropertyType.Quantity,value:t}:_e(t)?{type:t.resourceType,value:t}:{type:e.PropertyType.BackboneElement,value:t}}function vn(e){return 0!==e.length&&!!e[0].value}function xn(t,n){if(!t?.value)return;const i=Ne(t.type,n);if(i){const e=function(e,t,n){const i=n.type;if(!i||0===i.length)return;let r,o="undefined";if(1===i.length)r=e.value[t],o=i[0].code;else for(const n of i){const i=t.replace("[x]","")+N(n.code);if(i in e.value){r=e.value[i],o=n.code;break}}if(A(r))return;"Element"!==o&&"BackboneElement"!==o||(o=Me(n.path?.split(".")));return Array.isArray(r)?r.map((e=>wn(e,o))):wn(r,o)}(t,n,i);if(e)return e}return function(t,n){const i=t.value;if(!i||"object"!=typeof i)return;let r;if(n in i)r=i[n];else for(const t in e.PropertyType){const e=n+N(t);if(e in i){r=i[e];break}}if(A(r))return;return Array.isArray(r)?r.map(gn):gn(r)}(t,n)}function wn(e,t){return"Resource"===t&&_e(e)&&(t=e.resourceType),{type:t,value:e}}function Sn(e){const t=[];for(const n of e){let e=!1;for(const i of t)if(vn(En(n,i))){e=!0;break}e||t.push(n)}return t}function Tn(e){return yn(!vn(e))}function bn(e,t){return 0===e.length||0===t.length?[]:e.length!==t.length?yn(!1):yn(e.every(((e,n)=>vn(En(e,t[n])))))}function En(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?yn(Math.abs(n-i)<1e-8):Rn(n)&&Rn(i)?yn(On(n,i)):yn("object"==typeof n&&"object"==typeof i?Mn(e,t):n===i)}function Pn(e,t){return 0===e.length&&0===t.length?yn(!0):e.length!==t.length?yn(!1):(e.sort(Cn),t.sort(Cn),yn(e.every(((e,n)=>vn(Dn(e,t[n]))))))}function Dn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?yn(Math.abs(n-i)<.01):Rn(n)&&Rn(i)?yn(On(n,i)):yn("object"==typeof n&&"object"==typeof i?Mn(n,i):"string"==typeof n&&"string"==typeof i?n.toLowerCase()===i.toLowerCase():n===i)}function Cn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?n-i:"string"==typeof n&&"string"==typeof i?n.localeCompare(i):0}function kn(e,t){const{value:n}=e;if(null==n)return!1;switch(t){case"Boolean":return"boolean"==typeof n;case"Decimal":case"Integer":return"number"==typeof n;case"Date":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof n&&!!n.match(/^T\d/);case"Period":return An(n);case"Quantity":return Rn(n);default:return"object"==typeof n&&n?.resourceType===t}}function An(e){return!(!e||"object"!=typeof e||!("start"in e))}function Rn(e){return!(!e||"object"!=typeof e||!("value"in e)||"number"!=typeof e.value)}function On(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 Mn(e,t){const n=Object.keys(e),i=Object.keys(t);if(n.length!==i.length)return!1;for(const i of n){const n=e[i],r=t[i];if(In(n)&&In(r)){if(!Mn(n,r))return!1}else if(n!==r)return!1}return!0}function In(e){return null!==e&&"object"==typeof e}Ut=new WeakMap,Lt=new WeakMap,Nt=new WeakMap,_t=new WeakMap,jt=new WeakMap,Wt=new WeakMap,Qt=new WeakMap,Bt=new WeakMap,It=new WeakSet,$t=function(){return t(this,Wt,"f").slice(-1)[0]},qt=function(){t(this,It,"m",on).call(this);const e=t(this,It,"m",Ft).call(this);return t(this,It,"m",sn).call(this),e},Ft=function(){t(this,It,"m",Ht).call(this);const e=t(this,It,"m",tn).call(this);if(!e)return;t(this,It,"m",on).call(this);const n=t(this,It,"m",rn).call(this);return"/"===e&&"*"===n?t(this,It,"m",zt).call(this):"/"===e&&"/"===n?t(this,It,"m",Gt).call(this):"'"===e||'"'===e?t(this,It,"m",Vt).call(this,e):"`"===e?t(this,It,"m",Xt).call(this):"@"===e?t(this,It,"m",Jt).call(this):e.match(/\d/)?t(this,It,"m",Yt).call(this):e.match(/\w/)||"$"===e&&n.match(/\w/)?t(this,It,"m",Kt).call(this):t(this,It,"m",Zt).call(this)},Ht=function(){t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(/\s/)))},zt=function(){const e=t(this,Qt,"f").index;return t(this,It,"m",en).call(this,(()=>"*"!==t(this,It,"m",tn).call(this)||"/"!==t(this,It,"m",rn).call(this))),t(this,It,"m",an).call(this),t(this,It,"m",an).call(this),t(this,It,"m",cn).call(this,"Comment",t(this,Ut,"f").substring(e,t(this,Qt,"f").index))},Gt=function(){return t(this,It,"m",cn).call(this,"Comment",t(this,It,"m",en).call(this,(()=>"\n"!==t(this,It,"m",tn).call(this))))},Vt=function(e){t(this,It,"m",an).call(this);const n=t(this,It,"m",cn).call(this,"String",t(this,It,"m",en).call(this,(()=>"\\"===t(this,It,"m",nn).call(this)||t(this,It,"m",tn).call(this)!==e)));return t(this,It,"m",an).call(this),n},Xt=function(){t(this,It,"m",an).call(this);const e=t(this,It,"m",cn).call(this,"Symbol",t(this,It,"m",en).call(this,(()=>"`"!==t(this,It,"m",tn).call(this))));return t(this,It,"m",an).call(this),e},Jt=function(){t(this,It,"m",an).call(this);const e=t(this,Qt,"f").index;return t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(/[\d-]/))),"T"===t(this,It,"m",tn).call(this)&&(t(this,It,"m",an).call(this),t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(/[\d:]/))),"."===t(this,It,"m",tn).call(this)&&t(this,It,"m",rn).call(this).match(/\d/)&&(t(this,It,"m",an).call(this),t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(/\d/)))),"Z"===t(this,It,"m",tn).call(this)?t(this,It,"m",an).call(this):"+"!==t(this,It,"m",tn).call(this)&&"-"!==t(this,It,"m",tn).call(this)||(t(this,It,"m",an).call(this),t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(/[\d:]/))))),t(this,It,"m",cn).call(this,"DateTime",t(this,Ut,"f").substring(e,t(this,Qt,"f").index))},Yt=function(){const e=t(this,Qt,"f").index;let n="Number";return t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(/\d/))),"."===t(this,It,"m",tn).call(this)&&t(this,It,"m",rn).call(this).match(/\d/)&&(t(this,It,"m",an).call(this),t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(/\d/)))),"-"===t(this,It,"m",tn).call(this)&&t(this,_t,"f")?(t(this,Qt,"f").index=e-1,t(this,It,"m",Jt).call(this)):(" "===t(this,It,"m",tn).call(this)&&function(e){if(e){if("String"===e.id)return!0;if("Symbol"===e.id&&hn.includes(e.value))return!0}return!1}(t(this,It,"m",qt).call(this))&&(n="Quantity",t(this,It,"m",Ft).call(this)),t(this,It,"m",cn).call(this,n,t(this,Ut,"f").substring(e,t(this,Qt,"f").index)))},Kt=function(){const e=t(this,It,"m",en).call(this,(()=>t(this,It,"m",tn).call(this).match(t(this,jt,"f"))));return"."!==t(this,It,"m",$t).call(this)?.value&&t(this,Lt,"f").includes(e)?t(this,It,"m",cn).call(this,e,e):t(this,It,"m",cn).call(this,"Symbol",e)},Zt=function(){const e=t(this,It,"m",tn).call(this),n=e+t(this,It,"m",rn).call(this);return t(this,Nt,"f").includes(n)?(t(this,It,"m",an).call(this),t(this,It,"m",an).call(this),t(this,It,"m",cn).call(this,n,n)):(t(this,It,"m",an).call(this),t(this,It,"m",cn).call(this,e,e))},en=function(e){const n=t(this,Qt,"f").index;for(;t(this,Qt,"f").index<t(this,Ut,"f").length&&e();)t(this,It,"m",an).call(this);return t(this,Ut,"f").substring(n,t(this,Qt,"f").index)},tn=function(){return t(this,Ut,"f")[t(this,Qt,"f").index]},nn=function(){return t(this,Ut,"f")[t(this,Qt,"f").index-1]??""},rn=function(){return t(this,Ut,"f")[t(this,Qt,"f").index+1]??""},on=function(){t(this,Bt,"f").push({...t(this,Qt,"f")})},sn=function(){const e=t(this,Bt,"f").pop();if(!e)throw new Error("No mark to reset to");t(this,Qt,"f").index=e.index,t(this,Qt,"f").line=e.line,t(this,Qt,"f").column=e.column},an=function(){t(this,Qt,"f").index++,"\n"===t(this,It,"m",tn).call(this)?(t(this,Qt,"f").line++,t(this,Qt,"f").column=0):t(this,Qt,"f").column++},cn=function(e,n){const i=t(this,Bt,"f").pop();if(!i)throw new Error("No mark for token");return{id:e,value:n,...i}};const Un=()=>[],Ln={empty:e=>yn(0===e.length),exists:(e,t)=>yn(t?e.filter((e=>vn(t.eval([e])))).length>0:e.length>0),all:(e,t)=>yn(e.every((e=>vn(t.eval([e]))))),allTrue:e=>{for(const t of e)if(!t.value)return yn(!1);return yn(!0)},anyTrue:e=>{for(const t of e)if(t.value)return yn(!0);return yn(!1)},allFalse:e=>{for(const t of e)if(t.value)return yn(!1);return yn(!0)},anyFalse:e=>{for(const t of e)if(!t.value)return yn(!0);return yn(!1)},subsetOf:Un,supersetOf:Un,count:t=>[{type:e.PropertyType.integer,value:t.length}],distinct:e=>{const t=[];for(const n of e)t.some((e=>e.value===n.value))||t.push(n);return t},isDistinct:e=>yn(e.length===Ln.distinct(e).length),where:(e,t)=>e.filter((e=>vn(t.eval([e])))),select:(e,t)=>e.map((e=>t.eval([e]))).flat(),repeat:Un,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 n=t.eval(e)[0]?.value;if("number"!=typeof n)throw new Error("Expected a number for skip(num)");return n>=e.length?[]:n<=0?e:e.slice(n,e.length)},take:(e,t)=>{const n=t.eval(e)[0]?.value;if("number"!=typeof n)throw new Error("Expected a number for take(num)");return n>=e.length?e:n<=0?[]:e.slice(0,n)},intersect:(e,t)=>{if(!t)return e;const n=t.eval(e),i=[];for(const t of e)!i.some((e=>e.value===t.value))&&n.some((e=>e.value===t.value))&&i.push(t);return i},exclude:(e,t)=>{if(!t)return e;const n=t.eval(e),i=[];for(const t of e)n.some((e=>e.value===t.value))||i.push(t);return i},union:(e,t)=>{if(!t)return e;const n=t.eval(e);return Sn([...e,...n])},combine:(e,t)=>{if(!t)return e;const n=t.eval(e);return[...e,...n]},iif:(e,t,n,i)=>{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 vn(r)?n.eval(e):i?i.eval(e):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);if("boolean"==typeof n)return[{type:e.PropertyType.boolean,value:n}];if("number"==typeof n&&(0===n||1===n))return yn(!!n);if("string"==typeof n){const e=n.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(e))return yn(!0);if(["false","f","no","n","0","0.0"].includes(e))return yn(!1)}return[]},convertsToBoolean:e=>0===e.length?[]:yn(1===Ln.toBoolean(e).length),toInteger:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);return"number"==typeof n?[{type:e.PropertyType.integer,value:n}]:"string"==typeof n&&n.match(/^[+-]?\d+$/)?[{type:e.PropertyType.integer,value:parseInt(n,10)}]:"boolean"==typeof n?[{type:e.PropertyType.integer,value:n?1:0}]:[]},convertsToInteger:e=>0===e.length?[]:yn(1===Ln.toInteger(e).length),toDate:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.date,value:mn(n)}]:[]},convertsToDate:e=>0===e.length?[]:yn(1===Ln.toDate(e).length),toDateTime:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.dateTime,value:mn(n)}]:[]},convertsToDateTime:e=>0===e.length?[]:yn(1===Ln.toDateTime(e).length),toDecimal:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);return"number"==typeof n?[{type:e.PropertyType.decimal,value:n}]:"string"==typeof n&&n.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:e.PropertyType.decimal,value:parseFloat(n)}]:"boolean"==typeof n?[{type:e.PropertyType.decimal,value:n?1:0}]:[]},convertsToDecimal:e=>0===e.length?[]:yn(1===Ln.toDecimal(e).length),toQuantity:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);return Rn(n)?[{type:e.PropertyType.Quantity,value:n}]:"number"==typeof n?[{type:e.PropertyType.Quantity,value:{value:n,unit:"1"}}]:"string"==typeof n&&n.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:e.PropertyType.Quantity,value:{value:parseFloat(n),unit:"1"}}]:"boolean"==typeof n?[{type:e.PropertyType.Quantity,value:{value:n?1:0,unit:"1"}}]:[]},convertsToQuantity:e=>0===e.length?[]:yn(1===Ln.toQuantity(e).length),toString:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);return null==n?[]:Rn(n)?[{type:e.PropertyType.string,value:`${n.value} '${n.unit}'`}]:[{type:e.PropertyType.string,value:n.toString()}]},convertsToString:e=>0===e.length?[]:yn(1===Ln.toString(e).length),toTime:t=>{if(0===t.length)return[];const[{value:n}]=jn(t,1);if("string"==typeof n){const t=n.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[{type:e.PropertyType.time,value:mn("T"+t[1])}]}return[]},convertsToTime:e=>0===e.length?[]:yn(1===Ln.toTime(e).length),indexOf:(e,t)=>Nn(((e,t)=>e.indexOf(t)),e,t),substring:(e,t,n)=>Nn(((e,t,n)=>{const i=t,r=n?i+n:e.length;return i<0||i>=e.length?void 0:e.substring(i,r)}),e,t,n),startsWith:(e,t)=>Nn(((e,t)=>e.startsWith(t)),e,t),endsWith:(e,t)=>Nn(((e,t)=>e.endsWith(t)),e,t),contains:(e,t)=>Nn(((e,t)=>e.includes(t)),e,t),upper:e=>Nn((e=>e.toUpperCase()),e),lower:e=>Nn((e=>e.toLowerCase()),e),replace:(e,t,n)=>Nn(((e,t,n)=>e.replaceAll(t,n)),e,t,n),matches:(e,t)=>Nn(((e,t)=>!!e.match(t)),e,t),replaceMatches:(e,t,n)=>Nn(((e,t,n)=>e.replaceAll(t,n)),e,t,n),length:e=>Nn((e=>e.length),e),toChars:e=>Nn((e=>e?e.split(""):void 0),e),abs:e=>_n(Math.abs,e),ceiling:e=>_n(Math.ceil,e),exp:e=>_n(Math.exp,e),floor:e=>_n(Math.floor,e),ln:e=>_n(Math.log,e),log:(e,t)=>_n(((e,t)=>Math.log(e)/Math.log(t)),e,t),power:(e,t)=>_n(Math.pow,e,t),round:e=>_n(Math.round,e),sqrt:e=>_n(Math.sqrt,e),truncate:e=>_n((e=>0|e),e),children:Un,descendants:Un,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,n,i,r)=>{const o=Ln.toDateTime(n.eval(t));if(0===o.length)throw new Error("Invalid start date");const s=Ln.toDateTime(i.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=E(o[0].value,s[0].value);return[{type:e.PropertyType.Quantity,value:{value:c[a],unit:a}}]},is:(t,n)=>{let i="";return n instanceof qn?i=n.name:n instanceof Yn&&(i=n.left.name+"."+n.right.name),i?t.map((t=>({type:e.PropertyType.boolean,value:kn(t,i)}))):[]},not:t=>Ln.toBoolean(t).map((t=>({type:e.PropertyType.boolean,value:!t.value}))),resolve:t=>t.map((t=>{const n=t.value;let i;if("string"==typeof n)i=n;else if("object"==typeof n){const e=n;if(e.resource)return gn(e.resource);e.reference?i=e.reference:e.type&&e.identifier&&(i=`${e.type}?identifier=${e.identifier.system}|${e.identifier.value}`)}if(i?.includes("?")){const[e]=i.split("?");return{type:e,value:{resourceType:e}}}if(i?.includes("/")){const[e,t]=i.split("/");return{type:e,value:{resourceType:e,id:t}}}return{type:e.PropertyType.BackboneElement,value:void 0}})).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"}}:_e(t)?{type:e.PropertyType.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:e.PropertyType.BackboneElement,value:null})),conformsTo:(t,n)=>{const i=n.eval(t)[0].value;if(!i.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const r=i.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>({type:e.PropertyType.boolean,value:t.value?.resourceType===r})))}};function Nn(e,t,...n){if(0===t.length)return[];const[{value:i}]=jn(t,1);if("string"!=typeof i)throw new Error("String function cannot be called with non-string");const r=e(i,...n.map((e=>e&&e.eval(t)?.[0]?.value)));return void 0===r?[]:Array.isArray(r)?r.map(gn):[gn(r)]}function _n(t,n,...i){if(0===n.length)return[];const[{value:r}]=jn(n,1),o=Rn(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,...i.map((e=>e.eval(n)?.[0]?.value)));return[{type:o?e.PropertyType.Quantity:n[0].type,value:o?{...r,value:a}:a}]}function jn(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 Wn,Qn;class Bn{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 $n{constructor(e){this.value=e}eval(){return[this.value]}toString(){const e=this.value.value;return"string"==typeof e?`'${e}'`:e.toString()}}class qn{constructor(e){Wn.add(this),this.name=e}eval(e){return"$this"===this.name?e:e.map((e=>t(this,Wn,"m",Qn).call(this,e))).flat().filter((e=>void 0!==e?.value))}toString(){return this.name}}Wn=new WeakSet,Qn=function(e){const t=e.value;if(t&&"object"==typeof t)return _e(t)&&t.resourceType===this.name?e:xn(e,this.name)};class Fn{eval(){return[]}toString(){return"{}"}}class Hn extends un{constructor(e,t,n){super(e,t),this.impl=n}eval(e){return this.impl(this.child.eval(e))}toString(){return this.child.toString()}}class zn extends ln{constructor(e,t){super("as",e,t)}eval(e){return Ln.ofType(this.left.eval(e),this.right)}}class Gn extends ln{constructor(e,t,n,i){super(e,t,n),this.impl=i}eval(t){const n=this.left.eval(t);if(1!==n.length)return[];const i=this.right.eval(t);if(1!==i.length)return[];const r=n[0].value,o=i[0].value,s=Rn(r)?r.value:r,a=Rn(o)?o.value:o,c=this.impl(s,a);return"boolean"==typeof c?yn(c):Rn(r)?[{type:e.PropertyType.Quantity,value:{...r,value:c}}]:[gn(c)]}}class Vn extends ln{constructor(e,t){super("&",e,t)}eval(t){const n=[...this.left.eval(t),...this.right.eval(t)];return n.length>0&&n.every((e=>"string"==typeof e.value))?[{type:e.PropertyType.string,value:n.map((e=>e.value)).join("")}]:n}}class Xn extends ln{constructor(e,t){super("contains",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);return yn(t.some((e=>e.value===n[0].value)))}}class Jn extends ln{constructor(e,t){super("in",e,t)}eval(e){const t=this.left.eval(e);return yn(this.right.eval(e).some((e=>e.value===t[0].value)))}}class Yn extends ln{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 Kn extends ln{constructor(e,t){super("|",e,t)}eval(e){return Sn([...this.left.eval(e),...this.right.eval(e)])}}class Zn extends ln{constructor(e,t){super("=",e,t)}eval(e){return bn(this.left.eval(e),this.right.eval(e))}}class ei extends ln{constructor(e,t){super("!=",e,t)}eval(e){return Tn(bn(this.left.eval(e),this.right.eval(e)))}}class ti extends ln{constructor(e,t){super("~",e,t)}eval(e){return Pn(this.left.eval(e),this.right.eval(e))}}class ni extends ln{constructor(e,t){super("!~",e,t)}eval(e){return Tn(Pn(this.left.eval(e),this.right.eval(e)))}}class ii extends ln{constructor(e,t){super("is",e,t)}eval(e){const t=this.left.eval(e);if(1!==t.length)return[];const n=this.right.name;return yn(kn(t[0],n))}}class ri extends ln{constructor(e,t){super("and",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);return!0===t[0]?.value&&!0===n[0]?.value?yn(!0):!1===t[0]?.value||!1===n[0]?.value?yn(!1):[]}}class oi extends ln{constructor(e,t){super("or",e,t)}eval(e){const t=this.left.eval(e);if(vn(t))return t;const n=this.right.eval(e);return vn(n)?n:[]}}class si extends ln{constructor(e,t){super("xor",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);if(0===t.length&&0===n.length)return[];const i=0===t.length?null:t[0].value,r=0===n.length?null:n[0].value;return!0===i&&!0!==r||!0!==i&&!0===r?yn(!0):!0===i&&!0===r||!1===i&&!1===r?yn(!1):[]}}class ai{constructor(e,t){this.name=e,this.args=t}eval(e){const t=Ln[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 ci{constructor(e,t){this.left=e,this.expr=t}eval(e){const t=this.expr.eval(e);if(1!==t.length)return[];const n=t[0].value;if("number"!=typeof n)throw new Error("Invalid indexer expression: should return integer}");const i=this.left.eval(e);return n in i?[i[n]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}}const ui=["true","false"],li=["!=","!~","<=",">=","{}","->"];function pi(e){return new fn(e,ui,li).tokenize()}const di={parse(e){const t=e.consumeAndParse();if(!e.match(")"))throw new Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},hi={parse(e,t){const n=e.consumeAndParse();if(!e.match("]"))throw new Error("Parse error: expected `]`");return new ci(t,n)},precedence:2},fi={parse(e,t){if(!(t instanceof qn))throw new Error("Unexpected parentheses");const n=[];for(;!e.match(")");)n.push(e.consumeAndParse()),e.match(",");return new ai(t.name,n)},precedence:0};function mi(e){const t=e.split(" "),n=parseFloat(t[0]);let i=t[1];return i=i&&i.startsWith("'")&&i.endsWith("'")?i.substring(1,i.length-1):"{"+i+"}",{value:n,unit:i}}function yi(){return(new pn).registerPrefix("String",{parse:(t,n)=>new $n({type:e.PropertyType.string,value:n.value})}).registerPrefix("DateTime",{parse:(t,n)=>new $n({type:e.PropertyType.dateTime,value:mn(n.value)})}).registerPrefix("Quantity",{parse:(t,n)=>new $n({type:e.PropertyType.Quantity,value:mi(n.value)})}).registerPrefix("Number",{parse:(t,n)=>new $n({type:e.PropertyType.decimal,value:parseFloat(n.value)})}).registerPrefix("true",{parse:()=>new $n({type:e.PropertyType.boolean,value:!0})}).registerPrefix("false",{parse:()=>new $n({type:e.PropertyType.boolean,value:!1})}).registerPrefix("Symbol",{parse:(e,t)=>new qn(t.value)}).registerPrefix("{}",{parse:()=>new Fn}).registerPrefix("(",di).registerInfix("[",hi).registerInfix("(",fi).prefix("+",3,((e,t)=>new Hn("+",t,(e=>e)))).prefix("-",3,((e,t)=>new Gn("-",t,t,((e,t)=>-t)))).infixLeft(".",1,((e,t,n)=>new Yn(e,n))).infixLeft("/",4,((e,t,n)=>new Gn("/",e,n,((e,t)=>e/t)))).infixLeft("*",4,((e,t,n)=>new Gn("*",e,n,((e,t)=>e*t)))).infixLeft("+",5,((e,t,n)=>new Gn("+",e,n,((e,t)=>e+t)))).infixLeft("-",5,((e,t,n)=>new Gn("-",e,n,((e,t)=>e-t)))).infixLeft("|",7,((e,t,n)=>new Kn(e,n))).infixLeft("=",9,((e,t,n)=>new Zn(e,n))).infixLeft("!=",9,((e,t,n)=>new ei(e,n))).infixLeft("~",9,((e,t,n)=>new ti(e,n))).infixLeft("!~",9,((e,t,n)=>new ni(e,n))).infixLeft("<",8,((e,t,n)=>new Gn("<",e,n,((e,t)=>e<t)))).infixLeft("<=",8,((e,t,n)=>new Gn("<=",e,n,((e,t)=>e<=t)))).infixLeft(">",8,((e,t,n)=>new Gn(">",e,n,((e,t)=>e>t)))).infixLeft(">=",8,((e,t,n)=>new Gn(">=",e,n,((e,t)=>e>=t)))).infixLeft("&",5,((e,t,n)=>new Vn(e,n))).infixLeft("and",6,((e,t,n)=>new ri(e,n))).infixLeft("as",6,((e,t,n)=>new zn(e,n))).infixLeft("contains",6,((e,t,n)=>new Xn(e,n))).infixLeft("div",6,((e,t,n)=>new Gn("div",e,n,((e,t)=>e/t|0)))).infixLeft("in",6,((e,t,n)=>new Jn(e,n))).infixLeft("is",6,((e,t,n)=>new ii(e,n))).infixLeft("mod",6,((e,t,n)=>new Gn("mod",e,n,((e,t)=>e%t)))).infixLeft("or",6,((e,t,n)=>new oi(e,n))).infixLeft("xor",6,((e,t,n)=>new si(e,n)))}const gi=yi();function vi(e){return new Bn(e,gi.construct(pi(e)).consumeAndParse())}function xi(e,t){const n=Array.isArray(t)?t:[t];for(let e=0;e<n.length;e++){const t=n[e];"object"==typeof t&&"type"in t&&"value"in t||(n[e]=gn(n[e]))}return wi(e,n).map((e=>e.value))}function wi(e,t){return vi(e).eval(t)}const Si=[...li,"->","<<",">>"];var Ti,bi,Ei,Pi,Di,Ci,ki,Ai,Ri,Oi,Mi,Ii,Ui,Li,Ni,_i,ji,Wi,Qi;class Bi{constructor(e){Ti.add(this),this.parser=e,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,Ti,"m",bi).call(this);break;case"imports":t(this,Ti,"m",Ei).call(this);break;case"group":t(this,Ti,"m",Pi).call(this);break;case"conceptmap":t(this,Ti,"m",Qi).call(this);break;default:throw new Error(`Unexpected token: ${e}`)}}return this.structureMap}}Ti=new WeakSet,bi=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)},Ei=function(){this.parser.consume("Symbol","imports"),this.structureMap.import||(this.structureMap.import=[]),this.structureMap.import.push(this.parser.consume("String").value)},Pi=function(){const e={};this.parser.consume("Symbol","group"),e.name=this.parser.consume("Symbol").value,e.input=t(this,Ti,"m",Di).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,Ti,"m",ki).call(this),this.structureMap.group||(this.structureMap.group=[]),this.structureMap.group.push(e)},Di=function(){const e=[];for(this.parser.consume("(");this.parser.hasMore()&&")"!==this.parser.peek()?.value;)e.push(t(this,Ti,"m",Ci).call(this)),","===this.parser.peek()?.value&&this.parser.consume(",");return this.parser.consume(")"),e},Ci=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},ki=function(){const e=[];for(this.parser.consume("{");this.parser.hasMore()&&"}"!==this.parser.peek()?.value;)e.push(t(this,Ti,"m",Ai).call(this));return this.parser.consume("}"),e},Ai=function(){const e={source:t(this,Ti,"m",Ri).call(this)};return"->"===this.parser.peek()?.value&&(this.parser.consume("->"),e.target=t(this,Ti,"m",Mi).call(this)),"then"===this.parser.peek()?.value&&(this.parser.consume("Symbol","then"),"{"===this.parser.peek()?.id?e.rule=t(this,Ti,"m",ki).call(this):e.dependent=t(this,Ti,"m",Wi).call(this)),"String"===this.parser.peek()?.id?e.name=this.parser.consume().value:e.name=e.source?.[0]?.element,this.parser.consume(";"),e},Ri=function(){const e=[t(this,Ti,"m",Oi).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(t(this,Ti,"m",Oi).call(this));return e},Oi=function(){const e={},n=t(this,Ti,"m",ji).call(this);if(n.includes(".")){const t=n.split(".");e.context=t[0],e.element=t[1]}else e.context=n;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},Mi=function(){const e=[t(this,Ti,"m",Ii).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(t(this,Ti,"m",Ii).call(this));return e},Ii=function(){const e={},n=t(this,Ti,"m",ji).call(this);if(n.includes(".")){const t=n.split(".");e.contextType="variable",e.context=t[0],e.element=t[1]}else e.context=n;return"="===this.parser.peek()?.value&&(this.parser.consume("="),t(this,Ti,"m",Ui).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},Ui=function(e){e.transform="copy";const n=this.parser.consumeAndParse(6);if(n instanceof qn)t(this,Ti,"m",Li).call(this,e,n);else if(n instanceof ai)t(this,Ti,"m",Ni).call(this,e,n);else{if(!(n instanceof $n))throw new Error(`Unexpected FHIRPath: ${n}`);t(this,Ti,"m",_i).call(this,e,n)}},Li=function(e,t){e.parameter=[{valueId:t.name}]},Ni=function(e,t){const n=t.name;switch(n){case"create":e.parameter=[{valueString:t.args?.[0].value.value}];break;case"translate":e.parameter=[{}];break;default:throw new Error("Unknown target function: "+n)}},_i=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)}},ji=function(){let e=this.parser.consume().value;for(;"."===this.parser.peek()?.value;)this.parser.consume("."),e+="."+this.parser.consume().value;return e},Wi=function(){const e=this.parser.consumeAndParse(100);return[{name:e.name,variable:e.args.map((e=>e.name))}]},Qi=function(){for(;"}"!==this.parser.peek()?.value;)this.parser.consume();this.parser.consume("}")};const $i=yi().registerInfix("->",{precedence:100}).registerInfix(";",{precedence:200});const qi=[...li,"eq","ne","co"];class Fi{constructor(e,t,n){this.path=e,this.operator=t,this.value=n}}class Hi{constructor(e){this.child=e}}class zi{constructor(e,t,n){this.keyword=e,this.left=t,this.right=n}}class Gi{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 Hi(this.parse()),this.parser.consume(")")):e=new Fi(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 zi(t,e,this.parse())):e}}const Vi=yi();class Xi{constructor(e="\r",t="|",n="^",i="~",r="\\",o="&"){this.segmentSeparator=e,this.fieldSeparator=t,this.componentSeparator=n,this.repetitionSeparator=i,this.escapeCharacter=r,this.subcomponentSeparator=o}getMsh2(){return this.fieldSeparator+this.componentSeparator+this.repetitionSeparator+this.escapeCharacter+this.subcomponentSeparator}}class Ji{constructor(e,t=new Xi){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"),n=t?.get(2)?.toString()||"",i=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 Ji([new Yi(["MSH",this.context.getMsh2(),r,o,n,i,e.toISOString(),"","ACK",e.getTime().toString(),"P",a],this.context),new Yi(["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 Xi("\r",e.charAt(3),e.charAt(4),e.charAt(5),e.charAt(6),e.charAt(7));return new Ji(e.split(/[\r\n]+/).map((e=>Yi.parse(e,t))),t)}}class Yi{constructor(e,t=new Xi){this.context=t,M(e)?this.fields=e.map((e=>Ki.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 Xi){return new Yi(e.split(t.fieldSeparator).map((e=>Ki.parse(e,t))),t)}}class Ki{constructor(e,t=new Xi){this.context=t,this.components=e}get(e,t,n=0){let i=this.components[n][e]||"";return void 0!==t&&(i=i.split(this.context.subcomponentSeparator)[t]||""),i}toString(){return this.components.map((e=>e.join(this.context.componentSeparator))).join(this.context.repetitionSeparator)}static parse(e,t=new Xi){return new Ki(e.split(t.repetitionSeparator).map((e=>e.split(t.componentSeparator))),t)}}var Zi,er,tr,nr,ir,rr,or,sr,ar,cr,ur,lr,pr,dr;const hr={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"},fr=new Set(["resourceType","id","meta","implicitRules","language","text","contained","extension","modifierExtension"]);function mr(e){const t=je.types[e];return t&&t.structureDefinition.id===e&&"resource"===t.structureDefinition.kind}class yr{constructor(e){Zi.add(this),er.set(this,void 0),tr.set(this,void 0),n(this,er,[],"f"),n(this,tr,e,"f")}validate(){const e=t(this,tr,"f");if(!e)throw new fe(pe("Resource is null"));const n=e.resourceType;if(!n)throw new fe(pe("Missing resource type"));if(gr(e,"",t(this,er,"f")),t(this,Zi,"m",nr).call(this,gn(e),n),t(this,er,"f").length>0)throw new fe({resourceType:"OperationOutcome",issue:t(this,er,"f")})}}function gr(e,t,n){null===e?n.push(vr(t,"Invalid null value")):Array.isArray(e)?function(e,t,n){for(let i=0;i<e.length;i++)void 0===e[i]?n.push(vr(`${t}[${i}]`,"Invalid undefined value")):gr(e[i],`${t}[${i}]`,n)}(e,t,n):"object"==typeof e&&function(e,t,n){for(const[i,r]of Object.entries(e))gr(r,`${t}${t?".":""}${i}`,n)}(e,t,n)}function vr(e,t){return{severity:"error",code:"structure",details:{text:t},expression:[e]}}var xr;function wr(t,n){let i=je.types[t]?.searchParamsDetails?.[n.code];return i||(i=function(t,n){const i=n.code,r=function(e){return e.split("-").reduce(((e,t,n)=>e+(n?N(t):t)),"")}(i),o=br(t,n.expression)?.split(".");if(!o)return{columnName:r,type:e.SearchParameterType.TEXT};const s=Tr(n);let a,c,u=t,l=!1;for(let e=1;e<o.length;e++){if(a=Ne(u,o[e]),!a)throw new Error(`Element definition not found for ${t} ${n.code}`);if("*"===a.max&&(l=!0),c=a.type?.[0].code,!c)return{columnName:r,type:s,array:l};e<o.length-1&&(u=Sr(c)?Me(a.path?.split(".")):c)}const p=Tr(n,c),d={columnName:r,type:p,elementDefinition:a,array:l};return function(e,t,n){const i=je.types[e];i.searchParamsDetails||(i.searchParamsDetails={});i.searchParamsDetails[t]=n}(t,i,d),d}(t,n)),i}function Sr(e){return"Element"===e||"BackboneElement"===e}function Tr(t,n){let i=e.SearchParameterType.TEXT;switch(t.type){case"date":i=n===e.PropertyType.dateTime||n===e.PropertyType.instant?e.SearchParameterType.DATETIME:e.SearchParameterType.DATE;break;case"number":i=e.SearchParameterType.NUMBER;break;case"quantity":i=e.SearchParameterType.QUANTITY;break;case"reference":i=e.SearchParameterType.REFERENCE;break;case"token":"boolean"===n&&(i=e.SearchParameterType.BOOLEAN)}return i}function br(e,t){const n=t.split(" | ");for(const t of n){if((i=t).includes(" as Period")||i.includes(" as SampledDate"))continue;const n=Er(t);if(n.startsWith(e+"."))return n}var i}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 n=[" != "," as ",".as(",".exists(",".resolve(",".where("];for(const e of n)t.includes(e)&&(t=t.substring(0,t.indexOf(e)));return t}er=new WeakMap,tr=new WeakMap,Zi=new WeakSet,nr=function(e,n){const i=je.types[e.type];if(!i)throw new fe(pe("Unknown type: "+e.type));const r=i.properties;t(this,Zi,"m",ir).call(this,n,r,e),t(this,Zi,"m",ur).call(this,n,e,r)},ir=function(e,n,i){for(const[r,o]of Object.entries(n))t(this,Zi,"m",rr).call(this,e+"."+r,o,i)},rr=function(e,n,i){const r=xn(i,e.split(".").pop());if(A(r))void 0!==n.min&&n.min>0&&t(this,er,"f").push(vr(e,"Missing required property"));else if("*"===n.max){if(!Array.isArray(r))return void t(this,er,"f").push(vr(e,"Expected array for property"));for(const i of r)t(this,Zi,"m",or).call(this,e,n,i)}else t(this,Zi,"m",or).call(this,e,n,r)},or=function(e,n,i){null!==i.value&&(_(i.type.charAt(0))?t(this,Zi,"m",sr).call(this,n,i):t(this,Zi,"m",nr).call(this,i,e))},sr=function(e,n){const{type:i,value:r}=n;if(null===r)return;const o=hr[n.type];typeof r===o?"string"===o?t(this,Zi,"m",ar).call(this,e,i,r):"number"===o&&t(this,Zi,"m",cr).call(this,e,i,r):t(this,Zi,"m",dr).call(this,e,"Invalid type for "+i)},ar=function(e,n,i){if(!i.trim())return void t(this,Zi,"m",dr).call(this,e,"Invalid empty string");const r=je.types[n]?.properties?.value;if(r?.type){const o=D(r.type[0],"http://hl7.org/fhir/StructureDefinition/regex");o&&(i.match(new RegExp(o))||t(this,Zi,"m",dr).call(this,e,"Invalid "+n+" format"))}},cr=function(n,i,r){var o;!isNaN(r)&&isFinite(r)?((o=i)!==e.PropertyType.integer&&o!==e.PropertyType.positiveInt&&o!==e.PropertyType.unsignedInt||Number.isInteger(r)||t(this,Zi,"m",dr).call(this,n,"Number is not an integer"),i===e.PropertyType.positiveInt&&r<=0&&t(this,Zi,"m",dr).call(this,n,"Number is less than or equal to zero"),i===e.PropertyType.unsignedInt&&r<0&&t(this,Zi,"m",dr).call(this,n,"Number is negative")):t(this,Zi,"m",dr).call(this,n,"Invalid "+i+" value")},ur=function(e,n,i){const r=n.value;for(const o of Object.keys(r))t(this,Zi,"m",lr).call(this,e,o,n,i)},lr=function(e,n,i,r){if(!(fr.has(n)||n in r||function(e,t,n){for(const i of Object.keys(n)){if(!i.endsWith("[x]"))continue;const n=i.replace("[x]","");if(!e.startsWith(n))continue;let r=xn(t,i);if(r&&(Array.isArray(r)&&(r=r[0]),r&&e===n+N(r.type)))return!0}return!1}(n,i,r)||t(this,Zi,"m",pr).call(this,e,n,i))){const i=`${e}.${n}`;t(this,er,"f").push(vr(i,`Invalid additional property "${i}"`))}},pr=function(e,n,i){if(!n.startsWith("_"))return!1;return n.slice(1)in i.value&&(t(this,Zi,"m",nr).call(this,{type:"Element",value:i.value[n]},e),!0)},dr=function(e,n){t(this,er,"f").push(vr(e.path,n))},e.SearchParameterType=void 0,(xr=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",xr.NUMBER="NUMBER",xr.QUANTITY="QUANTITY",xr.TEXT="TEXT",xr.REFERENCE="REFERENCE",xr.DATE="DATE",xr.DATETIME="DATETIME",xr.PERIOD="PERIOD",xr.UUID="UUID";var Pr;e.Operator=void 0,(Pr=e.Operator||(e.Operator={})).EQUALS="eq",Pr.NOT_EQUALS="ne",Pr.GREATER_THAN="gt",Pr.LESS_THAN="lt",Pr.GREATER_THAN_OR_EQUALS="ge",Pr.LESS_THAN_OR_EQUALS="le",Pr.STARTS_AFTER="sa",Pr.ENDS_BEFORE="eb",Pr.APPROXIMATELY="ap",Pr.CONTAINS="contains",Pr.EXACT="exact",Pr.TEXT="text",Pr.NOT="not",Pr.ABOVE="above",Pr.BELOW="below",Pr.IN="in",Pr.NOT_IN="not-in",Pr.OF_TYPE="of-type",Pr.MISSING="missing",Pr.IDENTIFIER="identifier";const Dr={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,missing:e.Operator.MISSING,identifier:e.Operator.IDENTIFIER},Cr={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};function kr(e){return Ar(e.pathname.split("/").filter(Boolean).pop(),Object.fromEntries(e.searchParams.entries()))}function Ar(e,t){const n={resourceType:e};for(const[e,i]of Object.entries(t))Array.isArray(i)?i.forEach((t=>Rr(n,e,t))):Rr(n,e,i??"");return n}function Rr(t,n,i){let r,o;const s=n.indexOf(":");switch(s>=0?(r=n.substring(0,s),o=n.substring(s+1)):(r=n,o=""),r){case"_sort":!function(e,t){for(const n of t.split(",")){let t,i=!1;n.startsWith("-")?(t=n.substring(1),i=!0):t=n,e.sortRules||(e.sortRules=[]),e.sortRules.push({code:t,descending:i})}}(t,i);break;case"_count":t.count=parseInt(i);break;case"_offset":t.offset=parseInt(i);break;case"_total":t.total=i;break;case"_summary":t.total="estimate",t.count=0;break;case"_revinclude":t.revInclude=i;break;case"_fields":t.fields=i.split(",");break;default:{const n=je.types[t.resourceType]?.searchParams?.[r];n?function(t,n,i,r){if("missing"===i)return void Ir(t,{code:n.code,operator:e.Operator.MISSING,value:r});switch(n.type){case"number":case"date":!function(e,t,n){const{operator:i,value:r}=Or(n);Ir(e,{code:t.code,operator:i,value:r})}(t,n,r);break;case"reference":case"string":case"token":case"uri":!function(e,t,n,i){Ir(e,{code:t.code,operator:Mr(n),value:i})}(t,n,i,r);break;case"quantity":!function(e,t,n){const[i,r,o]=n.split("|"),{operator:s,value:a}=Or(i);Ir(e,{code:t.code,operator:s,value:a,unitSystem:r,unitCode:o})}(t,n,r)}}(t,n,o,i):function(t,n,i,r){let o=e.Operator.EQUALS;if(i)o=i;else if(r.length>=2){const e=r.substring(0,2);e in Cr&&(2===r.length||r.at(2)?.match(/\d/))&&(o=e,r=r.substring(e.length))}Ir(t,{code:n,operator:o,value:r})}(t,r,o,i)}}}function Or(t){const n=t.substring(0,2),i=Cr[n];return i?{operator:i,value:t.substring(2)}:{operator:e.Operator.EQUALS,value:t}}function Mr(t){return Dr[t]||e.Operator.EQUALS}function Ir(e,t){e.filters?e.filters.push(t):e.filters=[t]}function Ur(t,n,i){const r=je.types[n.resourceType]?.searchParams?.[i.code];switch(r?.type){case"reference":return function(t,n,i){const r=xi(i.expression,t),o=jr(n.operator);if(""===n.value&&0===r.length)return n.operator===e.Operator.EQUALS;const s=r.map((e=>"string"==typeof e?e:e.reference));for(const e of n.value.split(",")){let t=s.includes(e);if(t||"_compartment"!==n.code||(t=s.some((t=>t?.endsWith("/"+e)))),t)return!o}return o}(t,i,r);case"string":return Lr(t,i,r);case"token":return function(t,n,i){const r=wr(t.resourceType,i);return r.type===e.SearchParameterType.BOOLEAN?function(e,t,n){const i=xi(n.expression,e),r="true"===t.value,o=i.includes(r);return jr(t.operator)?!o:o}(t,n,i):Lr(t,n,i,!0)}(t,i,r);case"date":return function(e,t,n){const i=xi(n.expression,e),r=t.value.split(","),o=jr(t.operator);for(const e of i)for(const n of r){if(_r(e,t.operator,n))return!o}return o}(t,i,r)}return!1}function Lr(e,t,n,i){const r=xi(n.expression,e),o=t.value.split(","),s=jr(t.operator);for(const e of r)for(const n of o){if(Nr(e,t.operator,n,i))return!s}return s}function Nr(e,t,n,i){if(i&&n.includes("|")){const[i,r]=n.split("|");return Nr(e,t,i,!1)&&(!r||Nr(e,t,r,!1))}let r="";return e&&("string"==typeof e?r=e:"object"==typeof e&&(r=JSON.stringify(e))),r.toLowerCase().includes(n.toLowerCase())}function _r(t,n,i){switch(n){case e.Operator.STARTS_AFTER:case e.Operator.GREATER_THAN:return t>i;case e.Operator.GREATER_THAN_OR_EQUALS:return t>=i;case e.Operator.ENDS_BEFORE:case e.Operator.LESS_THAN:return t<i;case e.Operator.LESS_THAN_OR_EQUALS:return t<=i;case e.Operator.EQUALS:case e.Operator.NOT_EQUALS:return t===i}return!1}function jr(t){return t===e.Operator.NOT_EQUALS||t===e.Operator.NOT}e.AndAtom=ri,e.ArithemticOperatorAtom=Gn,e.AsAtom=zn,e.ClientStorage=De,e.ConcatAtom=Vn,e.ContainsAtom=Xn,e.DEFAULT_SEARCH_COUNT=20,e.DotAtom=Yn,e.EmptySetAtom=Fn,e.EqualsAtom=Zn,e.EquivalentAtom=ti,e.FHIRPATH_KEYWORDS=ui,e.FHIRPATH_OPERATORS=li,e.FhirFilterComparison=Fi,e.FhirFilterConnective=zi,e.FhirFilterNegation=Hi,e.FhirPathAtom=Bn,e.FhirSchemaValidator=yr,e.FunctionAtom=ai,e.Hl7Context=Xi,e.Hl7Field=Ki,e.Hl7Message=Ji,e.Hl7Segment=Yi,e.InAtom=Jn,e.IndexerAtom=ci,e.InfixOperatorAtom=ln,e.IsAtom=ii,e.LRUCache=a,e.LiteralAtom=$n,e.MEDPLUM_VERSION="2.0.12-b25d6c05",e.MedplumClient=class extends H{constructor(e){if(super(),We.add(this),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),nt.set(this,void 0),it.set(this,void 0),rt.set(this,void 0),ot.set(this,void 0),st.set(this,void 0),at.set(this,void 0),e?.baseUrl&&!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");n(this,Qe,e?.fetch||function(){if(!globalThis.fetch)throw new Error("Fetch not available in this environment");return globalThis.fetch.bind(globalThis)}(),"f"),n(this,$e,e?.storage||new De,"f"),n(this,Be,e?.createPdf,"f"),n(this,qe,new a(e?.resourceCacheSize??1e3),"f"),n(this,Fe,e?.cacheTime??6e4,"f"),n(this,He,function(e){if(!e)return e;return e.endsWith("/")?e:e+"/"}(e?.baseUrl)||"https://api.medplum.com/","f"),n(this,ze,t(this,He,"f")+"fhir/R4/","f"),n(this,Ze,e?.clientId||"","f"),n(this,Ge,e?.authorizeUrl||t(this,He,"f")+"oauth2/authorize","f"),n(this,Ve,e?.tokenUrl||t(this,He,"f")+"oauth2/token","f"),n(this,Xe,e?.logoutUrl||t(this,He,"f")+"oauth2/logout","f"),n(this,Je,e?.onUnauthenticated,"f"),n(this,Ye,e?.autoBatchTime??0,"f"),n(this,Ke,[],"f");const i=this.getActiveLogin();i&&(n(this,nt,i.accessToken,"f"),n(this,it,i.refreshToken,"f"),t(this,We,"m",ut).call(this).catch(console.log)),t(this,We,"m",Pt).call(this)}getBaseUrl(){return t(this,He,"f")}clear(){t(this,$e,"f").clear(),this.clearActiveLogin()}clearActiveLogin(){t(this,$e,"f").setString("activeLogin",void 0),t(this,qe,"f").clear(),n(this,nt,void 0,"f"),n(this,it,void 0,"f"),n(this,st,void 0,"f"),n(this,at,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(e){e=e.toString(),t(this,qe,"f").delete(e)}invalidateSearches(e){const n="fhir/R4/"+e;for(const e of t(this,qe,"f").keys())(e.endsWith(n)||e.includes(n+"?"))&&t(this,qe,"f").delete(e)}get(e,i={}){e=e.toString();const r=t(this,We,"m",lt).call(this,e,i);if(r)return r.value;let o;o=e.startsWith(t(this,ze,"f"))&&t(this,Ye,"f")>0?new Promise(((r,o)=>{t(this,Ke,"f").push({method:"GET",url:e.replace(t(this,ze,"f"),""),options:i,resolve:r,reject:o}),t(this,tt,"f")||n(this,tt,setTimeout((()=>t(this,We,"m",yt).call(this)),t(this,Ye,"f")),"f")})):t(this,We,"m",ft).call(this,"GET",e,i);const s=new Pe(o);return t(this,We,"m",pt).call(this,e,s),s}post(e,n,i,r={}){return e=e.toString(),n&&t(this,We,"m",xt).call(this,r,n),i&&t(this,We,"m",vt).call(this,r,i),this.invalidateUrl(e),t(this,We,"m",ft).call(this,"POST",e,r)}put(e,n,i,r={}){return e=e.toString(),n&&t(this,We,"m",xt).call(this,r,n),i&&t(this,We,"m",vt).call(this,r,i),this.invalidateUrl(e),t(this,We,"m",ft).call(this,"PUT",e,r)}patch(e,n,i={}){return e=e.toString(),t(this,We,"m",xt).call(this,i,n),t(this,We,"m",vt).call(this,i,"application/json-patch+json"),this.invalidateUrl(e),t(this,We,"m",ft).call(this,"PATCH",e,i)}delete(e,n={}){return e=e.toString(),this.invalidateUrl(e),t(this,We,"m",ft).call(this,"DELETE",e,n)}async startNewUser(e){const{codeChallengeMethod:t,codeChallenge:n}=await this.startPkce();return this.post("auth/newuser",{...e,codeChallengeMethod:t,codeChallenge:n})}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,Ze,"f"),scope:e.scope})}async startGoogleLogin(e){return this.post("auth/google",{...await this.ensureCodeChallenge(e),clientId:e.clientId??t(this,Ze,"f"),scope:e.scope})}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(t(this,Xe,"f"),{}),this.clear()}async signInWithRedirect(e){const n=new URLSearchParams(window.location.search).get("code");return n?this.processCode(n):void await t(this,We,"m",St).call(this,e)}signOutWithRedirect(){window.location.assign(t(this,Xe,"f"))}async signInWithExternalAuth(e,t,n,i){const r=await this.ensureCodeChallenge(i);window.location.assign(this.getExternalAuthRedirectUri(e,t,n,r))}getExternalAuthRedirectUri(e,t,n,i){const r=new URL(e);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",t),r.searchParams.set("redirect_uri",n),r.searchParams.set("scope","openid profile email"),r.searchParams.set("state",JSON.stringify(i)),r.toString()}fhirUrl(...e){return new URL(t(this,ze,"f")+e.join("/"))}fhirSearchUrl(e,t){const n=this.fhirUrl(e);return t&&(n.search=new URLSearchParams(t).toString()),n}search(e,n,i={}){const r=this.fhirSearchUrl(e,n),o=r.toString()+"-search",s=t(this,We,"m",lt).call(this,o,i);if(s)return s.value;const a=new Pe((async()=>{const e=await this.get(r,i);if(e.entry)for(const n of e.entry)t(this,We,"m",dt).call(this,n.resource);return e})());return t(this,We,"m",pt).call(this,o,a),a}searchOne(e,n,i={}){const r=this.fhirSearchUrl(e,n);r.searchParams.set("_count","1"),r.searchParams.sort();const o=r.toString()+"-searchOne",s=t(this,We,"m",lt).call(this,o,i);if(s)return s.value;const a=new Pe(this.search(e,r.searchParams,i).then((e=>e.entry?.[0]?.resource)));return t(this,We,"m",pt).call(this,o,a),a}searchResources(e,n,i={}){const r=this.fhirSearchUrl(e,n).toString()+"-searchResources",o=t(this,We,"m",lt).call(this,r,i);if(o)return o.value;const s=new Pe(this.search(e,n,i).then((e=>e.entry?.map((e=>e.resource))??[])));return t(this,We,"m",pt).call(this,r,s),s}searchValueSet(e,t,n={}){const i=this.fhirUrl("ValueSet","$expand");return i.searchParams.set("url",e),i.searchParams.set("filter",t),this.get(i.toString(),n)}getCached(e,n){const i=t(this,qe,"f").get(this.fhirUrl(e,n).toString())?.value;return i&&i.isOk()?i.read():void 0}getCachedReference(e){const t=e.reference;if(!t)return;if("system"===t)return Dt;const[n,i]=t.split("/");return n&&i?this.getCached(n,i):void 0}readResource(e,t,n={}){return this.get(this.fhirUrl(e,t),n)}readReference(e,t={}){const n=e?.reference;if(!n)return new Pe(Promise.reject(new Error("Missing reference")));if("system"===n)return new Pe(Promise.resolve(Dt));const[i,r]=n.split("/");return i&&r?this.readResource(i,r,t):new Pe(Promise.reject(new Error("Invalid reference")))}getSchema(){return je}requestSchema(e){if(e in je.types)return Promise.resolve(je);const n=e+"-requestSchema",i=t(this,We,"m",lt).call(this,n,void 0);if(i)return i.value;const r=new Pe((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," "),n=await this.graphql(t);for(const e of n.data.StructureDefinitionList)Re(e);for(const e of n.data.SearchParameterList)Oe(e);return je})());return t(this,We,"m",pt).call(this,n,r),r}readHistory(e,t,n={}){return this.get(this.fhirUrl(e,t,"_history"),n)}readVersion(e,t,n,i={}){return this.get(this.fhirUrl(e,t,"_history",n),i)}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,n,i){const r=this.fhirUrl("Binary");return t&&r.searchParams.set("_filename",t),i?this.uploadwithProgress(r,e,n,i):this.post(r,e,n)}uploadwithProgress(e,n,i,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,nt,"f")),a.setRequestHeader("Cache-Control","no-cache, no-store, max-age=0"),a.setRequestHeader("Content-Type",i),a.setRequestHeader("X-Medplum","extended"),a.send(n)}))}async createPdf(e,n,i,r){if(!t(this,Be,"f"))throw new Error("PDF creation not enabled");const o=await t(this,Be,"f").call(this,e,i,r);return this.createBinary(o,n,"application/pdf")}createComment(e,t){const n=this.getProfile();let i,r;return"Encounter"===e.resourceType&&(i=x(e),r=e.subject),"ServiceRequest"===e.resourceType&&(i=e.encounter,r=e.subject),"Patient"===e.resourceType&&(r=x(e)),this.createResource({resourceType:"Communication",basedOn:[x(e)],encounter:i,subject:r,sender:n?x(n):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 n=await this.put(this.fhirUrl(e.resourceType,e.id),e);return n||(n=e),t(this,We,"m",dt).call(this,n),n}patchResource(e,t,n){return this.invalidateSearches(e),this.patch(this.fhirUrl(e,t),n)}deleteResource(e,n){return t(this,We,"m",ht).call(this,this.fhirUrl(e,n).toString()),this.invalidateSearches(e),this.delete(this.fhirUrl(e,n))}validateResource(e){return this.post(this.fhirUrl(e.resourceType,"$validate"),e)}executeBot(e,t,n,i={}){let r;if("string"==typeof e){const t=e;r=this.fhirUrl("Bot",t,"$execute")}else{const t=e;r=this.fhirUrl("Bot","$execute")+`?identifier=${t.system}|${t.value}`}return this.post(r,t,n,i)}executeBatch(e){return this.post("fhir/R4",e)}sendEmail(e){return this.post("email/v1/send",e,"application/json")}graphql(e,t,n,i){return this.post(this.fhirUrl("$graphql"),{query:e,operationName:t,variables:n},"application/json",i)}readResourceGraph(e,t,n){return this.get(`${this.fhirUrl(e,t)}/$graph?graph=${n}`)}getActiveLogin(){return t(this,$e,"f").getObject("activeLogin")}async setActiveLogin(e){this.clearActiveLogin(),n(this,nt,e.accessToken,"f"),n(this,it,e.refreshToken,"f"),t(this,$e,"f").setObject("activeLogin",e),t(this,We,"m",ct).call(this,e),n(this,rt,void 0,"f"),await t(this,We,"m",ut).call(this)}getAccessToken(){return t(this,nt,"f")}setAccessToken(e){n(this,nt,e,"f"),n(this,it,void 0,"f"),n(this,st,void 0,"f"),n(this,at,void 0,"f")}getLogins(){return t(this,$e,"f").getObject("logins")??[]}isLoading(){return!!t(this,ot,"f")}getProfile(){return t(this,st,"f")}async getProfileAsync(){return t(this,ot,"f")&&await t(this,ot,"f"),this.getProfile()}getUserConfiguration(){return t(this,at,"f")}async download(e,n={}){t(this,rt,"f")&&await t(this,rt,"f"),t(this,We,"m",gt).call(this,n);return(await t(this,Qe,"f").call(this,e.toString(),n)).blob()}async startPkce(){const e=q();sessionStorage.setItem("pkceState",e);const t=q();sessionStorage.setItem("codeVerifier",t);const n=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",n),{codeChallengeMethod:"S256",codeChallenge:n}}processCode(e,n){const i=new URLSearchParams;if(i.set("grant_type","authorization_code"),i.set("code",e),i.set("client_id",n?.clientId||t(this,Ze,"f")),i.set("redirect_uri",n?.redirectUri||Ct()),"undefined"!=typeof sessionStorage){const e=sessionStorage.getItem("codeVerifier");e&&i.set("code_verifier",e)}return t(this,We,"m",bt).call(this,i)}async startClientLogin(e,i){n(this,Ze,e,"f"),n(this,et,i,"f");const r=new URLSearchParams;return r.set("grant_type","client_credentials"),r.set("client_id",e),r.set("client_secret",i),t(this,We,"m",bt).call(this,r)}},e.MemoryStorage=Ce,e.NotEqualsAtom=ei,e.NotEquivalentAtom=ni,e.OperationOutcomeError=fe,e.OrAtom=oi,e.Parser=dn,e.ParserBuilder=pn,e.PrefixOperatorAtom=un,e.ReadablePromise=Pe,e.SymbolAtom=qn,e.Tokenizer=fn,e.UnaryOperatorAtom=Hn,e.UnionAtom=Kn,e.XorAtom=si,e.allOk=ne,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=yn,e.buildTypeName=Me,e.calculateAge=E,e.calculateAgeString=function(e,t){const{years:n,months:i,days:r}=E(e,t);return n>=2?n.toString().padStart(3,"0")+"Y":i>=1?i.toString().padStart(3,"0")+"M":r.toString().padStart(3,"0")+"D"},e.capitalize=N,e.checkForNull=gr,e.createReference=x,e.createStructureIssue=vr,e.created=ie,e.deepClone=function(e){return JSON.parse(JSON.stringify(e))},e.deepEquals=R,e.evalFhirPath=xi,e.evalFhirPathTyped=wi,e.fhirPathArrayEquals=bn,e.fhirPathArrayEquivalent=Pn,e.fhirPathEquals=En,e.fhirPathEquivalent=Dn,e.fhirPathIs=kn,e.fhirPathNot=Tn,e.findObservationInterval=function(e,t,n,i){return e.qualifiedInterval?.find((r=>j(r,t)&&function(e,t,n){return!!e.range&&W(t,e.range,n)}(r,n,e.quantitativeDetails?.decimalPrecision)&&(void 0===i||r.category===i)))},e.findObservationReferenceRange=function(e,t,n){return e.qualifiedInterval?.find((e=>j(e,t)&&n.includes(e.condition)))},e.forbidden=ae,e.formatAddress=function(e,t){const n=[];if(e.line&&n.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),n.push(t.join(", "))}return e.use&&(t?.all||t?.use)&&n.push("["+e.use+"]"),n.join(t?.lineSeparator||", ").trim()},e.formatCodeableConcept=y,e.formatCoding=g,e.formatDate=function(e,t,n){if(!e)return"";const i=new Date(e);return u(i)?(i.setUTCHours(0,0,0,0),i.toLocaleDateString(t,{timeZone:"UTC",...n})):""},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,n){return e&&(e.start||e.end)?p(e.start,t,n)+" - "+p(e.end,t,n):""},e.formatQuantity=m,e.formatRange=function(e,t,n=!1){if(n&&void 0===t)throw new Error("Precision must be specified for exclusive ranges");const i=e?.low&&{...e.low},r=e?.high&&{...e.high};return!e||void 0===i?.value&&void 0===r?.value?"":void 0!==e.low?.value&&void 0===e.high?.value?n&&void 0!==t?(e.low.value=function(e,t,n=1){return(v(e,t)-n)*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?n&&void 0!==t?(e.high.value=function(e,t,n=1){return(v(e,t)+n)*Math.pow(10,-t)}(e.high.value,t),`< ${m(e.high,t)}`):`<= ${m(e.high,t)}`:(i?.unit===r?.unit&&delete i?.unit,`${m(i,t)} - ${m(r,t)}`)},e.formatSearchQuery=function(t){const n=[];return t.fields&&n.push("_fields="+t.fields.join(",")),t.filters&&t.filters.forEach((t=>n.push(function(t){const n=t.operator in Dr?":"+t.operator:"",i=t.operator!==e.Operator.EQUALS&&t.operator in Cr?t.operator:"";return`${t.code}${n}=${i}${encodeURIComponent(t.value)}`}(t)))),t.sortRules&&t.sortRules.length>0&&n.push("_sort="+t.sortRules.map((e=>e.descending?"-"+e.code:e.code)).join(",")),void 0!==t.offset&&n.push("_offset="+t.offset),void 0!==t.count&&n.push("_count="+t.count),void 0!==t.total&&n.push("_total="+t.total),0===n.length?"":(n.sort(),"?"+n.join("&"))},e.formatTime=l,e.formatTiming=function(e){if(!e)return"";const t=[];if(e.repeat?.periodUnit){const n=e.repeat.frequency||1,i=e.repeat.period||1,r=e.repeat.periodUnit;1===n&&1===i?t.push(d[r]):(1===n?t.push("once"):t.push(n+" times"),1===i?t.push("per "+h[r]):t.push("per "+i+" "+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=Ne,e.getElementDefinitionTypeName=function(e){const t=e.type?.[0]?.code;return"BackboneElement"===t||"Element"===t?Me(e.path?.split(".")):t},e.getExpressionForResourceType=br,e.getExtension=function(e,...t){let n=e;for(let e=0;e<t.length&&n;e++)n=n?.extension?.find((n=>n.url===t[e]));return n},e.getExtensionValue=D,e.getIdentifier=function(e,t){const n=e.identifier;if(!n)return;const i=Array.isArray(n)?n:[n];for(const e of i)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 b(t);for(const e of t){const t=b(e);if(t)return t}}},e.getPropertyDisplayName=function(e){return e.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(Le).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 je.types[e]},e.getResourceTypes=function(){const e=[];for(const[t,n]of Object.entries(je.types))Ie(n)&&e.push(t);return e},e.getSearchParameterDetails=wr,e.getSearchParameters=function(e){return je.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=xn,e.globalSchema=je,e.gone=ce,e.indexSearchParameter=Oe,e.indexSearchParameterBundle=function(e){for(const t of e.entry){const e=t.resource;"SearchParameter"===e.resourceType&&Oe(e)}},e.indexStructureDefinition=Re,e.indexStructureDefinitionBundle=function(e){for(const t of e.entry){const e=t.resource;"StructureDefinition"===e.resourceType&&Re(e)}},e.initFhirPathParserBuilder=yi,e.isEmpty=A,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=An,e.isProfileResource=S,e.isQuantity=Rn,e.isQuantityEquivalent=On,e.isReference=function(e){return!(!e||"object"!=typeof e||!("reference"in e))},e.isResource=_e,e.isResourceType=mr,e.isResourceTypeSchema=Ie,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 n of t.filters)if(!Ur(e,t,n))return!1;return!0},e.normalizeErrorString=ye,e.normalizeOperationOutcome=me,e.notFound=oe,e.notModified=re,e.operationOutcomeToString=ge,e.parseFhirPath=vi,e.parseFilterParameter=function(e){const t=Vi.construct(new fn(e,ui,qi,{dateTimeLiterals:!0,symbolRegex:/[^\s\])]/}).tokenize());return t.removeComments(),new Gi(t).parse()},e.parseJWTPayload=G,e.parseMappingLanguage=function(e){const t=$i.construct(new fn(e,ui,Si).tokenize());return t.removeComments(),new Bi(t).parse()},e.parseSearchDefinition=function(e){return kr(new URL(e,"https://example.com/"))},e.parseSearchRequest=function(e,t){return Ar(e,t)},e.parseSearchUrl=kr,e.preciseEquals=function(e,t,n){return $(e,n)===$(t,n)},e.preciseGreaterThan=function(e,t,n){return $(e,n)>$(t,n)},e.preciseGreaterThanOrEquals=B,e.preciseLessThan=function(e,t,n){return $(e,n)<$(t,n)},e.preciseLessThanOrEquals=Q,e.preciseRound=function(e,t){return parseFloat(e.toFixed(t))},e.removeDuplicates=Sn,e.resolveId=function(e){return e?.reference?.split("/")[1]},e.setCodeBySystem=function(e,t,n){e.coding||(e.coding=[]);const i=e.coding?.find((e=>e.system===t));i?i.code=n:e.coding?.push({system:t,code:n})},e.stringify=C,e.toJsBoolean=vn,e.toTypedValue=gn,e.tokenize=pi,e.tooManyRequests=ue,e.unauthorized=se,e.validateResource=function(e){new yr(e).validate()},e.validateResourceType=function(e){if(!e)throw new fe(pe("Resource type is null"));if(!mr(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){return"reference"===e&&"string"==typeof t&&t.includes("/")?"urn:uuid:"+t.split("/")[1]:t}function n(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function i(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof 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"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}var r,o,s,a;class c{constructor(e=10){r.add(this),o.set(this,void 0),s.set(this,void 0),i(this,o,e,"f"),i(this,s,new Map,"f")}clear(){n(this,s,"f").clear()}get(e){const t=n(this,s,"f").get(e);return t&&(n(this,s,"f").delete(e),n(this,s,"f").set(e,t)),t}set(e,t){n(this,s,"f").has(e)?n(this,s,"f").delete(e):n(this,s,"f").size>=n(this,o,"f")&&n(this,s,"f").delete(n(this,r,"m",a).call(this)),n(this,s,"f").set(e,t)}delete(e){n(this,s,"f").delete(e)}keys(){return n(this,s,"f").keys()}}function u(e,t){const n=[];return e.prefix&&!1!==t?.prefix&&n.push(...e.prefix),e.given&&n.push(...e.given),e.family&&n.push(e.family),e.suffix&&!1!==t?.suffix&&n.push(...e.suffix),e.use&&(t?.all||t?.use)&&n.push("["+e.use+"]"),n.join(" ").trim()}function l(e){return e instanceof Date&&!isNaN(e.getTime())}function p(e,t,n){if(!e)return"";const i=new Date("2000-01-01T"+e+"Z");return l(i)?i.toLocaleTimeString(t,n):""}function d(e,t,n){if(!e)return"";const i=new Date(e);return l(i)?i.toLocaleString(t,n):""}o=new WeakMap,s=new WeakMap,r=new WeakSet,a=function(){return n(this,s,"f").keys().next().value};const h={s:"every second",min:"every minute",h:"hourly",d:"daily",wk:"weekly",mo:"monthly",a:"annually"},f={s:"second",min:"minute",h:"hour",d:"day",wk:"week",mo:"month",a:"year"},m={s:"seconds",min:"minutes",h:"hours",d:"days",wk:"weeks",mo:"months",a:"years"};function y(e,t){if(!e)return"";const n=[];return e.comparator&&(n.push(e.comparator),n.push(" ")),void 0!==e.value&&(void 0!==t?n.push(e.value.toFixed(t)):n.push(e.value)),e.unit&&("%"!==e.unit&&" "!==n[n.length-1]&&n.push(" "),n.push(e.unit)),n.join("").trim()}function g(e){return e?e.text?e.text:e.coding?e.coding.map((e=>v(e))).join(", "):"":""}function v(e){return e?.display||e?.code||""}function x(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function w(e){const t=S(e),n=E(e);return n===t?{reference:t}:{reference:t,display:n}}function S(e){return e.resourceType+"/"+e.id}function T(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function E(e){if(T(e)){const t=function(e){const t=e.name;if(t&&t.length>0)return u(t[0]);return}(e);if(t)return t}if("Device"===e.resourceType){const t=function(e){const t=e.deviceName;if(t&&t.length>0)return t[0].name;return}(e);if(t)return t}return"Observation"===e.resourceType&&"code"in e&&e.code?.text?e.code.text:"User"===e.resourceType&&e.email?e.email:"name"in e&&e.name&&"string"==typeof e.name?e.name:S(e)}function b(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function P(e,t){const n=new Date(e);n.setUTCHours(0,0,0,0);const i=t?new Date(t):new Date;i.setUTCHours(0,0,0,0);const r=n.getUTCFullYear(),o=n.getUTCMonth(),s=n.getUTCDate(),a=i.getUTCFullYear(),c=i.getUTCMonth(),u=i.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((i.getTime()-n.getTime())/864e5)}}function D(e,t){if(e)for(const n of e)n.linkId&&n.answer&&n.answer.length>0&&(t[n.linkId]=n.answer[0]),D(n.item,t)}function k(e,...t){let n=e;for(let e=0;e<t.length&&n;e++)n=n?.extension?.find((n=>n.url===t[e]));return n?.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)&&R(t)?void 0:t}function R(e){if(null==e)return!0;const t=typeof e;return"string"===t&&""===e||"object"===t&&0===Object.keys(e).length}function O(e,t,n){return e===t||(!(!R(e)||!R(t))||!R(e)&&!R(t)&&(Array.isArray(e)&&Array.isArray(t)?function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!O(e[n],t[n]))return!1;return!0}(e,t):!Array.isArray(e)&&!Array.isArray(t)&&(M(e)&&M(t)?function(e,t,n){const i=new Set;Object.keys(e).forEach((e=>i.add(e))),Object.keys(t).forEach((e=>i.add(e))),"meta"===n&&(i.delete("versionId"),i.delete("lastUpdated"),i.delete("author"));for(const n of i){if(!O(e[n],t[n],n))return!1}return!0}(e,t,n):(M(e)||M(t),!1))))}function M(e){return null!==e&&"object"==typeof e}function I(e){return e.every((e=>"string"==typeof e))}const U=[];for(let e=0;e<256;e++)U.push(e.toString(16).padStart(2,"0"));function L(e){const t=new Uint8Array(e),n=new Array(t.length);for(let e=0;e<t.length;e++)n[e]=U[t[e]];return n.join("")}function N(e){const t=new Uint8Array(e),n=[];for(let e=0;e<t.length;e++)n[e]=String.fromCharCode(t[e]);return window.btoa(n.join(""))}function _(e){return e.charAt(0).toUpperCase()+e.substring(1)}function j(e){return e===e.toLowerCase()&&e!==e.toUpperCase()}function W(e,t){return function(e,t){return!e.gender||e.gender===t.gender}(e,t)&&function(e,t){return!e.age||B(P(t.birthDate).years,e.age)}(e,t)}function B(e,t,n){return(void 0===t.low?.value||$(e,t.low.value,n))&&(void 0===t.high?.value||Q(e,t.high.value,n))}function Q(e,t,n){return q(e,n)<=q(t,n)}function $(e,t,n){return q(e,n)>=q(t,n)}function q(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function F(){const e=new Uint32Array(28);return crypto.getRandomValues(e),L(e.buffer)}var H;class z{constructor(){H.set(this,void 0),i(this,H,{},"f")}addEventListener(e,t){n(this,H,"f")[e]||(n(this,H,"f")[e]=[]),n(this,H,"f")[e].push(t)}removeEventListeneer(e,t){const i=n(this,H,"f")[e];if(i)for(let e=0;e<i.length;e++)if(i[e]===t)return void i.splice(e,1)}dispatchEvent(e){const t=n(this,H,"f")[e.type];return t&&t.forEach((t=>t.call(this,e))),!e.defaultPrevented}}function V(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,"/")),n=Array.from(t).reduce(((e,t)=>`${e}%${("00"+t.charCodeAt(0).toString(16)).slice(-2)}`),""),i=decodeURIComponent(n);return JSON.parse(i)}function G(e){const[t,n,i]=e.split(".");return V(n)}H=new WeakMap;const J="ok",X="created",Y="gone",K="not-modified",Z="not-found",ee="unauthorized",te="forbidden",ne="too-many-requests",ie={resourceType:"OperationOutcome",id:J,issue:[{severity:"information",code:"informational",details:{text:"All OK"}}]},re={resourceType:"OperationOutcome",id:X,issue:[{severity:"information",code:"informational",details:{text:"Created"}}]},oe={resourceType:"OperationOutcome",id:K,issue:[{severity:"information",code:"informational",details:{text:"Not Modified"}}]},se={resourceType:"OperationOutcome",id:Z,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},ae={resourceType:"OperationOutcome",id:ee,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},ce={resourceType:"OperationOutcome",id:te,issue:[{severity:"error",code:"forbidden",details:{text:"Forbidden"}}]},ue={resourceType:"OperationOutcome",id:Y,issue:[{severity:"error",code:"deleted",details:{text:"Gone"}}]},le={resourceType:"OperationOutcome",id:ne,issue:[{severity:"error",code:"throttled",details:{text:"Too Many Requests"}}]};function pe(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}}function de(e){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"structure",details:{text:e}}]}}function he(e){return"object"==typeof e&&null!==e&&"OperationOutcome"===e.resourceType}function fe(e){return e.id===J||e.id===X||e.id===K}class me extends Error{constructor(e,t){super(ve(e)),this.outcome=e,this.cause=t}}function ye(e){return e instanceof me?e.outcome:he(e)?e:pe(ge(e))}function ge(e){return e?"string"==typeof e?e:e instanceof Error?e.message:he(e)?ve(e):JSON.stringify(e):"Unknown error"}function ve(e){const t=[];if(e.issue)for(const n of e.issue){let e=n.details?.text||"Unknown error";n.expression?.length&&(e+=` (${n.expression.join(", ")})`),t.push(e)}return t.length>0?t.join("; "):"Unknown error"}var xe,we,Se,Te,Ee,be,Pe;class De{constructor(e){this[Ee]="ReadablePromise",xe.set(this,void 0),we.set(this,"pending"),Se.set(this,void 0),Te.set(this,void 0),i(this,xe,e.then((e=>(i(this,we,"success","f"),i(this,Se,e,"f"),e)),(e=>{throw i(this,we,"error","f"),i(this,Te,e,"f"),e})),"f")}isPending(){return"pending"===n(this,we,"f")}isOk(){return"success"===n(this,we,"f")}read(){switch(n(this,we,"f")){case"pending":throw n(this,xe,"f");case"error":throw n(this,Te,"f");default:return n(this,Se,"f")}}then(e,t){return n(this,xe,"f").then(e,t)}catch(e){return n(this,xe,"f").catch(e)}finally(e){return n(this,xe,"f").finally(e)}}xe=new WeakMap,we=new WeakMap,Se=new WeakMap,Te=new WeakMap,Ee=Symbol.toStringTag;class ke{constructor(){be.set(this,void 0),i(this,be,"undefined"!=typeof localStorage?localStorage:new Ae,"f")}clear(){n(this,be,"f").clear()}getString(e){return n(this,be,"f").getItem(e)||void 0}setString(e,t){t?n(this,be,"f").setItem(e,t):n(this,be,"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)}}be=new WeakMap;class Ae{constructor(){Pe.set(this,void 0),i(this,Pe,new Map,"f")}get length(){return n(this,Pe,"f").size}clear(){n(this,Pe,"f").clear()}getItem(e){return n(this,Pe,"f").get(e)??null}setItem(e,t){t?n(this,Pe,"f").set(e,t):n(this,Pe,"f").delete(e)}removeItem(e){n(this,Pe,"f").delete(e)}key(e){return Array.from(n(this,Pe,"f").keys())[e]}}Pe=new WeakMap;var Ce,Re={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 Oe(e){if(!e.name)return;const t=e.snapshot?.element;t&&(t.forEach((t=>function(e,t){const n=t.path,i=t.type?.[0]?.code;if(void 0!==i&&"Element"!==i&&"BackboneElement"!==i)return;const r=n.split(".");r[0]=e.name;const o=Ie(r);let s=We.types[o];s||(We.types[o]=s={});s.parentType=s.parentType||Ie(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 n=t.path,i=n.split(".");if(1===i.length)return;i[0]=e.name;const r=Ie(i.slice(0,i.length-1)),o=We.types[r];if(!o)return;const s=i[i.length-1];o.properties[s]=t}(e,t))))}function Me(e){if(e.base)for(const t of e.base){const n=We.types[t];n&&(n.searchParams||(n.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"}}),n.searchParams[e.code]=e)}}function Ie(e){return 1===e.length?e[0]:e.map(_).join("")}function Ue(e){const t=e.structureDefinition;return t&&t.name===e.elementDefinition?.path&&"resource"===t.kind&&!t.abstract}e.PropertyType=void 0,(Ce=e.PropertyType||(e.PropertyType={})).Address="Address",Ce.Age="Age",Ce.Annotation="Annotation",Ce.Attachment="Attachment",Ce.BackboneElement="BackboneElement",Ce.CodeableConcept="CodeableConcept",Ce.Coding="Coding",Ce.ContactDetail="ContactDetail",Ce.ContactPoint="ContactPoint",Ce.Contributor="Contributor",Ce.Count="Count",Ce.DataRequirement="DataRequirement",Ce.Distance="Distance",Ce.Dosage="Dosage",Ce.Duration="Duration",Ce.Expression="Expression",Ce.Extension="Extension",Ce.HumanName="HumanName",Ce.Identifier="Identifier",Ce.MarketingStatus="MarketingStatus",Ce.Meta="Meta",Ce.Money="Money",Ce.Narrative="Narrative",Ce.ParameterDefinition="ParameterDefinition",Ce.Period="Period",Ce.Population="Population",Ce.ProdCharacteristic="ProdCharacteristic",Ce.ProductShelfLife="ProductShelfLife",Ce.Quantity="Quantity",Ce.Range="Range",Ce.Ratio="Ratio",Ce.Reference="Reference",Ce.RelatedArtifact="RelatedArtifact",Ce.SampledData="SampledData",Ce.Signature="Signature",Ce.SubstanceAmount="SubstanceAmount",Ce.SystemString="http://hl7.org/fhirpath/System.String",Ce.Timing="Timing",Ce.TriggerDefinition="TriggerDefinition",Ce.UsageContext="UsageContext",Ce.base64Binary="base64Binary",Ce.boolean="boolean",Ce.canonical="canonical",Ce.code="code",Ce.date="date",Ce.dateTime="dateTime",Ce.decimal="decimal",Ce.id="id",Ce.instant="instant",Ce.integer="integer",Ce.markdown="markdown",Ce.oid="oid",Ce.positiveInt="positiveInt",Ce.string="string",Ce.time="time",Ce.unsignedInt="unsignedInt",Ce.uri="uri",Ce.url="url",Ce.uuid="uuid";const Le=new Set(["ID","IP","PKCE","JWKS","URI","URL"]);function Ne(e){const t=e.toUpperCase();return Le.has(t)?t:t.charAt(0)+e.slice(1)}function _e(e,t){const n=We.types[e];if(!n)return;const i=n.properties[t]??n.properties[t+"[x]"];if(i){if(i.contentReference){const e=i.contentReference.substring(1).split("."),t=e.pop();return _e(Ie(e),t)}return i}}function je(e){return!(!e||"object"!=typeof e||!("resourceType"in e))}const We=Re;var Be,Qe,$e,qe,Fe,He,ze,Ve,Ge,Je,Xe,Ye,Ke,Ze,et,tt,nt,it,rt,ot,st,at,ct,ut,lt,pt,dt,ht,ft,mt,yt,gt,vt,xt,wt,St,Tt,Et,bt,Pt,Dt,kt;const At={resourceType:"Device",id:"system",deviceName:[{name:"System"}]};function Ct(){return"undefined"==typeof window?"":window.location.protocol+"//"+window.location.host+"/"}function Rt(e){return e?e.endsWith("/")?e:e+"/":e}var Ot,Mt,It,Ut,Lt,Nt,_t,jt,Wt,Bt,Qt,$t,qt,Ft,Ht,zt,Vt,Gt,Jt,Xt,Yt,Kt,Zt,en,tn,nn,rn,on,sn,an,cn,un,ln,pn;Qe=new WeakMap,$e=new WeakMap,qe=new WeakMap,Fe=new WeakMap,He=new WeakMap,ze=new WeakMap,Ve=new WeakMap,Ge=new WeakMap,Je=new WeakMap,Xe=new WeakMap,Ye=new WeakMap,Ke=new WeakMap,Ze=new WeakMap,et=new WeakMap,tt=new WeakMap,nt=new WeakMap,it=new WeakMap,rt=new WeakMap,ot=new WeakMap,st=new WeakMap,at=new WeakMap,ct=new WeakMap,ut=new WeakMap,Be=new WeakSet,lt=function(e){const t=this.getLogins().filter((t=>t.profile?.reference!==e.profile?.reference));t.push(e),n(this,qe,"f").setObject("logins",t)},pt=async function(){return i(this,at,new Promise(((e,t)=>{this.get("auth/me").then((t=>{i(this,at,void 0,"f"),i(this,ct,t.profile,"f"),i(this,ut,t.config,"f"),this.dispatchEvent({type:"change"}),e(n(this,ct,"f"))})).catch(t)})),"f"),n(this,at,"f")},dt=function(e,t){if(n(this,He,"f")<=0||"no-cache"===t?.cache||"reload"===t?.cache)return;const i=n(this,Fe,"f").get(e);return!i||i.requestTime+n(this,He,"f")<Date.now()?void 0:i},ht=function(e,t){n(this,He,"f")>0&&n(this,Fe,"f").set(e,{requestTime:Date.now(),value:t})},ft=function(e){e?.id&&n(this,Be,"m",ht).call(this,this.fhirUrl(e.resourceType,e.id).toString(),new De(Promise.resolve(e)))},mt=function(e){n(this,He,"f")>0&&n(this,Fe,"f").delete(e)},yt=async function(e,t,i={}){n(this,st,"f")&&await n(this,st,"f"),t.startsWith("http")||(t=n(this,ze,"f")+t),i.method=e,n(this,Be,"m",xt).call(this,i);const r=await n(this,Be,"m",gt).call(this,t,i);if(401===r.status)return n(this,Be,"m",Tt).call(this,e,t,i);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 me(ye(o));return o},gt=async function(e,t){let i;for(let r=0;r<3;r++){if(i=await n(this,Qe,"f").call(this,e,t),i.status<500)return i;await new Promise((e=>setTimeout(e,200)))}return i},vt=async function(){const e=[...n(this,et,"f")];if(n(this,et,"f").length=0,i(this,it,void 0,"f"),1===e.length){const t=e[0];try{t.resolve(await n(this,Be,"m",yt).call(this,t.method,n(this,Ve,"f")+t.url,t.options))}catch(e){t.reject(new me(ye(e)))}return}const t={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",t);for(let t=0;t<e.length;t++){const n=e[t],i=r.entry?.[t];i?.response?.outcome&&!fe(i.response.outcome)?n.reject(new me(i.response.outcome)):n.resolve(i?.resource)}},xt=function(e){e.headers||(e.headers={});const t=e.headers;t["X-Medplum"]="extended",t["Content-Type"]||(t["Content-Type"]="application/fhir+json"),n(this,rt,"f")&&(t.Authorization="Bearer "+n(this,rt,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},wt=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},St=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))},Tt=function(e,t,i){return n(this,Be,"m",bt).call(this)?n(this,Be,"m",yt).call(this,e,t,i):(this.clearActiveLogin(),n(this,Ke,"f")&&n(this,Ke,"f").call(this),Promise.reject(new Error("Unauthenticated")))},Et=async function(e){const t=await this.ensureCodeChallenge(e||{}),i=new URL(n(this,Ge,"f"));i.searchParams.set("response_type","code"),i.searchParams.set("state",sessionStorage.getItem("pkceState")),i.searchParams.set("client_id",t.clientId||n(this,tt,"f")),i.searchParams.set("redirect_uri",t.redirectUri||Ct()),i.searchParams.set("code_challenge_method",t.codeChallengeMethod),i.searchParams.set("code_challenge",t.codeChallenge),i.searchParams.set("scope",t.scope||"openid profile"),window.location.assign(i.toString())},bt=function(){if(n(this,st,"f"))return n(this,st,"f");if(n(this,ot,"f")){const e=new URLSearchParams;return e.set("grant_type","refresh_token"),e.set("client_id",n(this,tt,"f")),e.set("refresh_token",n(this,ot,"f")),i(this,st,n(this,Be,"m",Pt).call(this,e),"f"),n(this,st,"f")}return n(this,tt,"f")&&n(this,nt,"f")?(i(this,st,this.startClientLogin(n(this,tt,"f"),n(this,nt,"f")),"f"),n(this,st,"f")):void 0},Pt=async function(e){const t=await n(this,Qe,"f").call(this,n(this,Je,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e,credentials:"include"});if(!t.ok)throw this.clearActiveLogin(),new Error("Failed to fetch tokens");const i=await t.json();return await n(this,Be,"m",Dt).call(this,i),this.getProfile()},Dt=async function(e){const t=e.access_token,i=G(t);if(Date.now()>=1e3*i.exp)throw this.clearActiveLogin(),new Error("Token expired");if(n(this,tt,"f")&&i.client_id!==n(this,tt,"f"))throw this.clearActiveLogin(),new Error("Token was not issued for this audience");return this.setActiveLogin({accessToken:t,refreshToken:e.refresh_token,project:e.project,profile:e.profile})},kt=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class dn{constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}}class hn{constructor(e,t,n){this.operator=e,this.left=t,this.right=n}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class fn{constructor(){Ot.set(this,{}),Mt.set(this,{})}registerInfix(e,t){return n(this,Mt,"f")[e]=t,this}registerPrefix(e,t){return n(this,Ot,"f")[e]=t,this}prefix(e,t,n){return this.registerPrefix(e,{parse(e,i){const r=e.consumeAndParse(t);return n(i,r)}})}infixLeft(e,t,n){return this.registerInfix(e,{parse(e,i,r){const o=e.consumeAndParse(t);return n(i,r,o)},precedence:t})}construct(e){return new mn(e,n(this,Ot,"f"),n(this,Mt,"f"))}}Ot=new WeakMap,Mt=new WeakMap;class mn{constructor(e,t,n){It.set(this,void 0),Ut.set(this,void 0),Lt.set(this,void 0),i(this,It,e,"f"),i(this,Ut,t,"f"),i(this,Lt,n,"f")}hasMore(){return n(this,It,"f").length>0}match(e){const t=this.peek();return t?.id===e&&(this.consume(),!0)}consumeAndParse(e=1/0){const t=this.consume(),i=n(this,Ut,"f")[t.id];if(!i)throw Error(`Parse error at "${t.value}" (line ${t.line}, column ${t.column}). No matching prefix parselet.`);let r=i.parse(this,t);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,t){if(!n(this,It,"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(t&&this.peek()?.value!==t){const e=this.peek();throw Error(`Expected "${t}" but got "${e.value}" at line ${e.line} column ${e.column}.`)}return n(this,It,"f").shift()}peek(){return n(this,It,"f").length>0?n(this,It,"f")[0]:void 0}removeComments(){i(this,It,n(this,It,"f").filter((e=>"Comment"!==e.id)),"f")}getInfixParselet(e){return n(this,Lt,"f")["Symbol"===e.id?e.value:e.id]}}It=new WeakMap,Ut=new WeakMap,Lt=new WeakMap;const yn=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"];class gn{constructor(e,t,n,r){Nt.add(this),_t.set(this,void 0),jt.set(this,void 0),Wt.set(this,void 0),Bt.set(this,void 0),Qt.set(this,void 0),$t.set(this,[]),qt.set(this,{index:0,line:1,column:0}),Ft.set(this,[]),i(this,_t,e,"f"),i(this,jt,t,"f"),i(this,Wt,n,"f"),i(this,Bt,!!r?.dateTimeLiterals,"f"),i(this,Qt,r?.symbolRegex??/[$\w]/,"f")}tokenize(){for(;n(this,qt,"f").index<n(this,_t,"f").length;){const e=n(this,Nt,"m",Vt).call(this);e&&n(this,$t,"f").push(e)}return n(this,$t,"f")}}function vn(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 xn(t){return[{type:e.PropertyType.boolean,value:t}]}function wn(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}:In(t)?{type:e.PropertyType.Quantity,value:t}:je(t)?{type:t.resourceType,value:t}:{type:e.PropertyType.BackboneElement,value:t}}function Sn(e){return 0!==e.length&&!!e[0].value}function Tn(t,n){if(!t?.value)return;const i=_e(t.type,n);if(i){const e=function(e,t,n){const i=n.type;if(!i||0===i.length)return;let r,o="undefined";if(1===i.length)r=e.value[t],o=i[0].code;else for(const n of i){const i=t.replace("[x]","")+_(n.code);if(i in e.value){r=e.value[i],o=n.code;break}}if(R(r))return;"Element"!==o&&"BackboneElement"!==o||(o=Ie(n.path?.split(".")));return Array.isArray(r)?r.map((e=>En(e,o))):En(r,o)}(t,n,i);if(e)return e}return function(t,n){const i=t.value;if(!i||"object"!=typeof i)return;let r;if(n in i)r=i[n];else for(const t in e.PropertyType){const e=n+_(t);if(e in i){r=i[e];break}}if(R(r))return;return Array.isArray(r)?r.map(wn):wn(r)}(t,n)}function En(e,t){return"Resource"===t&&je(e)&&(t=e.resourceType),{type:t,value:e}}function bn(e){const t=[];for(const n of e){let e=!1;for(const i of t)if(Sn(kn(n,i))){e=!0;break}e||t.push(n)}return t}function Pn(e){return xn(!Sn(e))}function Dn(e,t){return 0===e.length||0===t.length?[]:e.length!==t.length?xn(!1):xn(e.every(((e,n)=>Sn(kn(e,t[n])))))}function kn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?xn(Math.abs(n-i)<1e-8):In(n)&&In(i)?xn(Un(n,i)):xn("object"==typeof n&&"object"==typeof i?Ln(e,t):n===i)}function An(e,t){return 0===e.length&&0===t.length?xn(!0):e.length!==t.length?xn(!1):(e.sort(Rn),t.sort(Rn),xn(e.every(((e,n)=>Sn(Cn(e,t[n]))))))}function Cn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?xn(Math.abs(n-i)<.01):In(n)&&In(i)?xn(Un(n,i)):xn("object"==typeof n&&"object"==typeof i?Ln(n,i):"string"==typeof n&&"string"==typeof i?n.toLowerCase()===i.toLowerCase():n===i)}function Rn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?n-i:"string"==typeof n&&"string"==typeof i?n.localeCompare(i):0}function On(e,t){const{value:n}=e;if(null==n)return!1;switch(t){case"Boolean":return"boolean"==typeof n;case"Decimal":case"Integer":return"number"==typeof n;case"Date":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof n&&!!n.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof n&&!!n.match(/^T\d/);case"Period":return Mn(n);case"Quantity":return In(n);default:return"object"==typeof n&&n?.resourceType===t}}function Mn(e){return!(!e||"object"!=typeof e||!("start"in e))}function In(e){return!(!e||"object"!=typeof e||!("value"in e)||"number"!=typeof e.value)}function Un(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 Ln(e,t){const n=Object.keys(e),i=Object.keys(t);if(n.length!==i.length)return!1;for(const i of n){const n=e[i],r=t[i];if(Nn(n)&&Nn(r)){if(!Ln(n,r))return!1}else if(n!==r)return!1}return!0}function Nn(e){return null!==e&&"object"==typeof e}_t=new WeakMap,jt=new WeakMap,Wt=new WeakMap,Bt=new WeakMap,Qt=new WeakMap,$t=new WeakMap,qt=new WeakMap,Ft=new WeakMap,Nt=new WeakSet,Ht=function(){return n(this,$t,"f").slice(-1)[0]},zt=function(){n(this,Nt,"m",cn).call(this);const e=n(this,Nt,"m",Vt).call(this);return n(this,Nt,"m",un).call(this),e},Vt=function(){n(this,Nt,"m",Gt).call(this);const e=n(this,Nt,"m",on).call(this);if(!e)return;n(this,Nt,"m",cn).call(this);const t=n(this,Nt,"m",an).call(this);return"/"===e&&"*"===t?n(this,Nt,"m",Jt).call(this):"/"===e&&"/"===t?n(this,Nt,"m",Xt).call(this):"'"===e||'"'===e?n(this,Nt,"m",Yt).call(this,e):"`"===e?n(this,Nt,"m",Kt).call(this):"@"===e?n(this,Nt,"m",Zt).call(this):e.match(/\d/)?n(this,Nt,"m",en).call(this):e.match(/\w/)||"$"===e&&t.match(/\w/)?n(this,Nt,"m",tn).call(this):n(this,Nt,"m",nn).call(this)},Gt=function(){n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(/\s/)))},Jt=function(){const e=n(this,qt,"f").index;return n(this,Nt,"m",rn).call(this,(()=>"*"!==n(this,Nt,"m",on).call(this)||"/"!==n(this,Nt,"m",an).call(this))),n(this,Nt,"m",ln).call(this),n(this,Nt,"m",ln).call(this),n(this,Nt,"m",pn).call(this,"Comment",n(this,_t,"f").substring(e,n(this,qt,"f").index))},Xt=function(){return n(this,Nt,"m",pn).call(this,"Comment",n(this,Nt,"m",rn).call(this,(()=>"\n"!==n(this,Nt,"m",on).call(this))))},Yt=function(e){n(this,Nt,"m",ln).call(this);const t=n(this,Nt,"m",pn).call(this,"String",n(this,Nt,"m",rn).call(this,(()=>"\\"===n(this,Nt,"m",sn).call(this)||n(this,Nt,"m",on).call(this)!==e)));return n(this,Nt,"m",ln).call(this),t},Kt=function(){n(this,Nt,"m",ln).call(this);const e=n(this,Nt,"m",pn).call(this,"Symbol",n(this,Nt,"m",rn).call(this,(()=>"`"!==n(this,Nt,"m",on).call(this))));return n(this,Nt,"m",ln).call(this),e},Zt=function(){n(this,Nt,"m",ln).call(this);const e=n(this,qt,"f").index;return n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(/[\d-]/))),"T"===n(this,Nt,"m",on).call(this)&&(n(this,Nt,"m",ln).call(this),n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(/[\d:]/))),"."===n(this,Nt,"m",on).call(this)&&n(this,Nt,"m",an).call(this).match(/\d/)&&(n(this,Nt,"m",ln).call(this),n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(/\d/)))),"Z"===n(this,Nt,"m",on).call(this)?n(this,Nt,"m",ln).call(this):"+"!==n(this,Nt,"m",on).call(this)&&"-"!==n(this,Nt,"m",on).call(this)||(n(this,Nt,"m",ln).call(this),n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(/[\d:]/))))),n(this,Nt,"m",pn).call(this,"DateTime",n(this,_t,"f").substring(e,n(this,qt,"f").index))},en=function(){const e=n(this,qt,"f").index;let t="Number";return n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(/\d/))),"."===n(this,Nt,"m",on).call(this)&&n(this,Nt,"m",an).call(this).match(/\d/)&&(n(this,Nt,"m",ln).call(this),n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(/\d/)))),"-"===n(this,Nt,"m",on).call(this)&&n(this,Bt,"f")?(n(this,qt,"f").index=e-1,n(this,Nt,"m",Zt).call(this)):(" "===n(this,Nt,"m",on).call(this)&&function(e){if(e){if("String"===e.id)return!0;if("Symbol"===e.id&&yn.includes(e.value))return!0}return!1}(n(this,Nt,"m",zt).call(this))&&(t="Quantity",n(this,Nt,"m",Vt).call(this)),n(this,Nt,"m",pn).call(this,t,n(this,_t,"f").substring(e,n(this,qt,"f").index)))},tn=function(){const e=n(this,Nt,"m",rn).call(this,(()=>n(this,Nt,"m",on).call(this).match(n(this,Qt,"f"))));return"."!==n(this,Nt,"m",Ht).call(this)?.value&&n(this,jt,"f").includes(e)?n(this,Nt,"m",pn).call(this,e,e):n(this,Nt,"m",pn).call(this,"Symbol",e)},nn=function(){const e=n(this,Nt,"m",on).call(this),t=e+n(this,Nt,"m",an).call(this);return n(this,Wt,"f").includes(t)?(n(this,Nt,"m",ln).call(this),n(this,Nt,"m",ln).call(this),n(this,Nt,"m",pn).call(this,t,t)):(n(this,Nt,"m",ln).call(this),n(this,Nt,"m",pn).call(this,e,e))},rn=function(e){const t=n(this,qt,"f").index;for(;n(this,qt,"f").index<n(this,_t,"f").length&&e();)n(this,Nt,"m",ln).call(this);return n(this,_t,"f").substring(t,n(this,qt,"f").index)},on=function(){return n(this,_t,"f")[n(this,qt,"f").index]},sn=function(){return n(this,_t,"f")[n(this,qt,"f").index-1]??""},an=function(){return n(this,_t,"f")[n(this,qt,"f").index+1]??""},cn=function(){n(this,Ft,"f").push({...n(this,qt,"f")})},un=function(){const e=n(this,Ft,"f").pop();if(!e)throw new Error("No mark to reset to");n(this,qt,"f").index=e.index,n(this,qt,"f").line=e.line,n(this,qt,"f").column=e.column},ln=function(){n(this,qt,"f").index++,"\n"===n(this,Nt,"m",on).call(this)?(n(this,qt,"f").line++,n(this,qt,"f").column=0):n(this,qt,"f").column++},pn=function(e,t){const i=n(this,Ft,"f").pop();if(!i)throw new Error("No mark for token");return{id:e,value:t,...i}};const _n=()=>[],jn={empty:e=>xn(0===e.length),exists:(e,t)=>xn(t?e.filter((e=>Sn(t.eval([e])))).length>0:e.length>0),all:(e,t)=>xn(e.every((e=>Sn(t.eval([e]))))),allTrue:e=>{for(const t of e)if(!t.value)return xn(!1);return xn(!0)},anyTrue:e=>{for(const t of e)if(t.value)return xn(!0);return xn(!1)},allFalse:e=>{for(const t of e)if(t.value)return xn(!1);return xn(!0)},anyFalse:e=>{for(const t of e)if(!t.value)return xn(!0);return xn(!1)},subsetOf:_n,supersetOf:_n,count:t=>[{type:e.PropertyType.integer,value:t.length}],distinct:e=>{const t=[];for(const n of e)t.some((e=>e.value===n.value))||t.push(n);return t},isDistinct:e=>xn(e.length===jn.distinct(e).length),where:(e,t)=>e.filter((e=>Sn(t.eval([e])))),select:(e,t)=>e.map((e=>t.eval([e]))).flat(),repeat:_n,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 n=t.eval(e)[0]?.value;if("number"!=typeof n)throw new Error("Expected a number for skip(num)");return n>=e.length?[]:n<=0?e:e.slice(n,e.length)},take:(e,t)=>{const n=t.eval(e)[0]?.value;if("number"!=typeof n)throw new Error("Expected a number for take(num)");return n>=e.length?e:n<=0?[]:e.slice(0,n)},intersect:(e,t)=>{if(!t)return e;const n=t.eval(e),i=[];for(const t of e)!i.some((e=>e.value===t.value))&&n.some((e=>e.value===t.value))&&i.push(t);return i},exclude:(e,t)=>{if(!t)return e;const n=t.eval(e),i=[];for(const t of e)n.some((e=>e.value===t.value))||i.push(t);return i},union:(e,t)=>{if(!t)return e;const n=t.eval(e);return bn([...e,...n])},combine:(e,t)=>{if(!t)return e;const n=t.eval(e);return[...e,...n]},iif:(e,t,n,i)=>{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 Sn(r)?n.eval(e):i?i.eval(e):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);if("boolean"==typeof n)return[{type:e.PropertyType.boolean,value:n}];if("number"==typeof n&&(0===n||1===n))return xn(!!n);if("string"==typeof n){const e=n.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(e))return xn(!0);if(["false","f","no","n","0","0.0"].includes(e))return xn(!1)}return[]},convertsToBoolean:e=>0===e.length?[]:xn(1===jn.toBoolean(e).length),toInteger:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);return"number"==typeof n?[{type:e.PropertyType.integer,value:n}]:"string"==typeof n&&n.match(/^[+-]?\d+$/)?[{type:e.PropertyType.integer,value:parseInt(n,10)}]:"boolean"==typeof n?[{type:e.PropertyType.integer,value:n?1:0}]:[]},convertsToInteger:e=>0===e.length?[]:xn(1===jn.toInteger(e).length),toDate:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.date,value:vn(n)}]:[]},convertsToDate:e=>0===e.length?[]:xn(1===jn.toDate(e).length),toDateTime:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.dateTime,value:vn(n)}]:[]},convertsToDateTime:e=>0===e.length?[]:xn(1===jn.toDateTime(e).length),toDecimal:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);return"number"==typeof n?[{type:e.PropertyType.decimal,value:n}]:"string"==typeof n&&n.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:e.PropertyType.decimal,value:parseFloat(n)}]:"boolean"==typeof n?[{type:e.PropertyType.decimal,value:n?1:0}]:[]},convertsToDecimal:e=>0===e.length?[]:xn(1===jn.toDecimal(e).length),toQuantity:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);return In(n)?[{type:e.PropertyType.Quantity,value:n}]:"number"==typeof n?[{type:e.PropertyType.Quantity,value:{value:n,unit:"1"}}]:"string"==typeof n&&n.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:e.PropertyType.Quantity,value:{value:parseFloat(n),unit:"1"}}]:"boolean"==typeof n?[{type:e.PropertyType.Quantity,value:{value:n?1:0,unit:"1"}}]:[]},convertsToQuantity:e=>0===e.length?[]:xn(1===jn.toQuantity(e).length),toString:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);return null==n?[]:In(n)?[{type:e.PropertyType.string,value:`${n.value} '${n.unit}'`}]:[{type:e.PropertyType.string,value:n.toString()}]},convertsToString:e=>0===e.length?[]:xn(1===jn.toString(e).length),toTime:t=>{if(0===t.length)return[];const[{value:n}]=Qn(t,1);if("string"==typeof n){const t=n.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[{type:e.PropertyType.time,value:vn("T"+t[1])}]}return[]},convertsToTime:e=>0===e.length?[]:xn(1===jn.toTime(e).length),indexOf:(e,t)=>Wn(((e,t)=>e.indexOf(t)),e,t),substring:(e,t,n)=>Wn(((e,t,n)=>{const i=t,r=n?i+n:e.length;return i<0||i>=e.length?void 0:e.substring(i,r)}),e,t,n),startsWith:(e,t)=>Wn(((e,t)=>e.startsWith(t)),e,t),endsWith:(e,t)=>Wn(((e,t)=>e.endsWith(t)),e,t),contains:(e,t)=>Wn(((e,t)=>e.includes(t)),e,t),upper:e=>Wn((e=>e.toUpperCase()),e),lower:e=>Wn((e=>e.toLowerCase()),e),replace:(e,t,n)=>Wn(((e,t,n)=>e.replaceAll(t,n)),e,t,n),matches:(e,t)=>Wn(((e,t)=>!!e.match(t)),e,t),replaceMatches:(e,t,n)=>Wn(((e,t,n)=>e.replaceAll(t,n)),e,t,n),length:e=>Wn((e=>e.length),e),toChars:e=>Wn((e=>e?e.split(""):void 0),e),abs:e=>Bn(Math.abs,e),ceiling:e=>Bn(Math.ceil,e),exp:e=>Bn(Math.exp,e),floor:e=>Bn(Math.floor,e),ln:e=>Bn(Math.log,e),log:(e,t)=>Bn(((e,t)=>Math.log(e)/Math.log(t)),e,t),power:(e,t)=>Bn(Math.pow,e,t),round:e=>Bn(Math.round,e),sqrt:e=>Bn(Math.sqrt,e),truncate:e=>Bn((e=>0|e),e),children:_n,descendants:_n,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,n,i,r)=>{const o=jn.toDateTime(n.eval(t));if(0===o.length)throw new Error("Invalid start date");const s=jn.toDateTime(i.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=P(o[0].value,s[0].value);return[{type:e.PropertyType.Quantity,value:{value:c[a],unit:a}}]},is:(t,n)=>{let i="";return n instanceof Fn?i=n.name:n instanceof Kn&&(i=n.left.name+"."+n.right.name),i?t.map((t=>({type:e.PropertyType.boolean,value:On(t,i)}))):[]},not:t=>jn.toBoolean(t).map((t=>({type:e.PropertyType.boolean,value:!t.value}))),resolve:t=>t.map((t=>{const n=t.value;let i;if("string"==typeof n)i=n;else if("object"==typeof n){const e=n;if(e.resource)return wn(e.resource);e.reference?i=e.reference:e.type&&e.identifier&&(i=`${e.type}?identifier=${e.identifier.system}|${e.identifier.value}`)}if(i?.includes("?")){const[e]=i.split("?");return{type:e,value:{resourceType:e}}}if(i?.includes("/")){const[e,t]=i.split("/");return{type:e,value:{resourceType:e,id:t}}}return{type:e.PropertyType.BackboneElement,value:void 0}})).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"}}:je(t)?{type:e.PropertyType.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:e.PropertyType.BackboneElement,value:null})),conformsTo:(t,n)=>{const i=n.eval(t)[0].value;if(!i.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const r=i.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>({type:e.PropertyType.boolean,value:t.value?.resourceType===r})))}};function Wn(e,t,...n){if(0===t.length)return[];const[{value:i}]=Qn(t,1);if("string"!=typeof i)throw new Error("String function cannot be called with non-string");const r=e(i,...n.map((e=>e&&e.eval(t)?.[0]?.value)));return void 0===r?[]:Array.isArray(r)?r.map(wn):[wn(r)]}function Bn(t,n,...i){if(0===n.length)return[];const[{value:r}]=Qn(n,1),o=In(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,...i.map((e=>e.eval(n)?.[0]?.value)));return[{type:o?e.PropertyType.Quantity:n[0].type,value:o?{...r,value:a}:a}]}function Qn(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}class $n{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 qn{constructor(e){this.value=e}eval(){return[this.value]}toString(){const e=this.value.value;return"string"==typeof e?`'${e}'`:e.toString()}}class Fn{constructor(e){this.name=e}eval(e){return"$this"===this.name?e:e.flatMap((e=>this.evalValue(e))).filter((e=>void 0!==e?.value))}evalValue(e){const t=e.value;if(t&&"object"==typeof t)return je(t)&&t.resourceType===this.name?e:Tn(e,this.name)}toString(){return this.name}}class Hn{eval(){return[]}toString(){return"{}"}}class zn extends dn{constructor(e,t,n){super(e,t),this.impl=n}eval(e){return this.impl(this.child.eval(e))}toString(){return this.child.toString()}}class Vn extends hn{constructor(e,t){super("as",e,t)}eval(e){return jn.ofType(this.left.eval(e),this.right)}}class Gn extends hn{constructor(e,t,n,i){super(e,t,n),this.impl=i}eval(t){const n=this.left.eval(t);if(1!==n.length)return[];const i=this.right.eval(t);if(1!==i.length)return[];const r=n[0].value,o=i[0].value,s=In(r)?r.value:r,a=In(o)?o.value:o,c=this.impl(s,a);return"boolean"==typeof c?xn(c):In(r)?[{type:e.PropertyType.Quantity,value:{...r,value:c}}]:[wn(c)]}}class Jn extends hn{constructor(e,t){super("&",e,t)}eval(t){const n=[...this.left.eval(t),...this.right.eval(t)];return n.length>0&&n.every((e=>"string"==typeof e.value))?[{type:e.PropertyType.string,value:n.map((e=>e.value)).join("")}]:n}}class Xn extends hn{constructor(e,t){super("contains",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);return xn(t.some((e=>e.value===n[0].value)))}}class Yn extends hn{constructor(e,t){super("in",e,t)}eval(e){const t=this.left.eval(e);return xn(this.right.eval(e).some((e=>e.value===t[0].value)))}}class Kn extends hn{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 Zn extends hn{constructor(e,t){super("|",e,t)}eval(e){return bn([...this.left.eval(e),...this.right.eval(e)])}}class ei extends hn{constructor(e,t){super("=",e,t)}eval(e){return Dn(this.left.eval(e),this.right.eval(e))}}class ti extends hn{constructor(e,t){super("!=",e,t)}eval(e){return Pn(Dn(this.left.eval(e),this.right.eval(e)))}}class ni extends hn{constructor(e,t){super("~",e,t)}eval(e){return An(this.left.eval(e),this.right.eval(e))}}class ii extends hn{constructor(e,t){super("!~",e,t)}eval(e){return Pn(An(this.left.eval(e),this.right.eval(e)))}}class ri extends hn{constructor(e,t){super("is",e,t)}eval(e){const t=this.left.eval(e);if(1!==t.length)return[];const n=this.right.name;return xn(On(t[0],n))}}class oi extends hn{constructor(e,t){super("and",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);return!0===t[0]?.value&&!0===n[0]?.value?xn(!0):!1===t[0]?.value||!1===n[0]?.value?xn(!1):[]}}class si extends hn{constructor(e,t){super("or",e,t)}eval(e){const t=this.left.eval(e);if(Sn(t))return t;const n=this.right.eval(e);return Sn(n)?n:[]}}class ai extends hn{constructor(e,t){super("xor",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);if(0===t.length&&0===n.length)return[];const i=0===t.length?null:t[0].value,r=0===n.length?null:n[0].value;return!0===i&&!0!==r||!0!==i&&!0===r?xn(!0):!0===i&&!0===r||!1===i&&!1===r?xn(!1):[]}}class ci{constructor(e,t){this.name=e,this.args=t}eval(e){const t=jn[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 ui{constructor(e,t){this.left=e,this.expr=t}eval(e){const t=this.expr.eval(e);if(1!==t.length)return[];const n=t[0].value;if("number"!=typeof n)throw new Error("Invalid indexer expression: should return integer}");const i=this.left.eval(e);return n in i?[i[n]]:[]}toString(){return`${this.left.toString()}[${this.expr.toString()}]`}}const li=["true","false"],pi=["!=","!~","<=",">=","{}","->"];function di(e){return new gn(e,li,pi).tokenize()}const hi={parse(e){const t=e.consumeAndParse();if(!e.match(")"))throw new Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},fi={parse(e,t){const n=e.consumeAndParse();if(!e.match("]"))throw new Error("Parse error: expected `]`");return new ui(t,n)},precedence:2},mi={parse(e,t){if(!(t instanceof Fn))throw new Error("Unexpected parentheses");const n=[];for(;!e.match(")");)n.push(e.consumeAndParse()),e.match(",");return new ci(t.name,n)},precedence:0};function yi(e){const t=e.split(" "),n=parseFloat(t[0]);let i=t[1];return i=i&&i.startsWith("'")&&i.endsWith("'")?i.substring(1,i.length-1):"{"+i+"}",{value:n,unit:i}}function gi(){return(new fn).registerPrefix("String",{parse:(t,n)=>new qn({type:e.PropertyType.string,value:n.value})}).registerPrefix("DateTime",{parse:(t,n)=>new qn({type:e.PropertyType.dateTime,value:vn(n.value)})}).registerPrefix("Quantity",{parse:(t,n)=>new qn({type:e.PropertyType.Quantity,value:yi(n.value)})}).registerPrefix("Number",{parse:(t,n)=>new qn({type:e.PropertyType.decimal,value:parseFloat(n.value)})}).registerPrefix("true",{parse:()=>new qn({type:e.PropertyType.boolean,value:!0})}).registerPrefix("false",{parse:()=>new qn({type:e.PropertyType.boolean,value:!1})}).registerPrefix("Symbol",{parse:(e,t)=>new Fn(t.value)}).registerPrefix("{}",{parse:()=>new Hn}).registerPrefix("(",hi).registerInfix("[",fi).registerInfix("(",mi).prefix("+",3,((e,t)=>new zn("+",t,(e=>e)))).prefix("-",3,((e,t)=>new Gn("-",t,t,((e,t)=>-t)))).infixLeft(".",1,((e,t,n)=>new Kn(e,n))).infixLeft("/",4,((e,t,n)=>new Gn("/",e,n,((e,t)=>e/t)))).infixLeft("*",4,((e,t,n)=>new Gn("*",e,n,((e,t)=>e*t)))).infixLeft("+",5,((e,t,n)=>new Gn("+",e,n,((e,t)=>e+t)))).infixLeft("-",5,((e,t,n)=>new Gn("-",e,n,((e,t)=>e-t)))).infixLeft("|",7,((e,t,n)=>new Zn(e,n))).infixLeft("=",9,((e,t,n)=>new ei(e,n))).infixLeft("!=",9,((e,t,n)=>new ti(e,n))).infixLeft("~",9,((e,t,n)=>new ni(e,n))).infixLeft("!~",9,((e,t,n)=>new ii(e,n))).infixLeft("<",8,((e,t,n)=>new Gn("<",e,n,((e,t)=>e<t)))).infixLeft("<=",8,((e,t,n)=>new Gn("<=",e,n,((e,t)=>e<=t)))).infixLeft(">",8,((e,t,n)=>new Gn(">",e,n,((e,t)=>e>t)))).infixLeft(">=",8,((e,t,n)=>new Gn(">=",e,n,((e,t)=>e>=t)))).infixLeft("&",5,((e,t,n)=>new Jn(e,n))).infixLeft("and",6,((e,t,n)=>new oi(e,n))).infixLeft("as",6,((e,t,n)=>new Vn(e,n))).infixLeft("contains",6,((e,t,n)=>new Xn(e,n))).infixLeft("div",6,((e,t,n)=>new Gn("div",e,n,((e,t)=>e/t|0)))).infixLeft("in",6,((e,t,n)=>new Yn(e,n))).infixLeft("is",6,((e,t,n)=>new ri(e,n))).infixLeft("mod",6,((e,t,n)=>new Gn("mod",e,n,((e,t)=>e%t)))).infixLeft("or",6,((e,t,n)=>new si(e,n))).infixLeft("xor",6,((e,t,n)=>new ai(e,n)))}const vi=gi();function xi(e){return new $n(e,vi.construct(di(e)).consumeAndParse())}function wi(e,t){const n=Array.isArray(t)?t:[t];for(let e=0;e<n.length;e++){const t=n[e];"object"==typeof t&&"type"in t&&"value"in t||(n[e]=wn(n[e]))}return Si(e,n).map((e=>e.value))}function Si(e,t){return xi(e).eval(t)}const Ti=[...pi,"->","<<",">>"];var Ei,bi,Pi,Di,ki,Ai,Ci,Ri,Oi,Mi,Ii,Ui,Li,Ni,_i,ji,Wi,Bi,Qi;class $i{constructor(e){Ei.add(this),this.parser=e,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":n(this,Ei,"m",bi).call(this);break;case"imports":n(this,Ei,"m",Pi).call(this);break;case"group":n(this,Ei,"m",Di).call(this);break;case"conceptmap":n(this,Ei,"m",Qi).call(this);break;default:throw new Error(`Unexpected token: ${e}`)}}return this.structureMap}}Ei=new WeakSet,bi=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)},Pi=function(){this.parser.consume("Symbol","imports"),this.structureMap.import||(this.structureMap.import=[]),this.structureMap.import.push(this.parser.consume("String").value)},Di=function(){const e={};this.parser.consume("Symbol","group"),e.name=this.parser.consume("Symbol").value,e.input=n(this,Ei,"m",ki).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=n(this,Ei,"m",Ci).call(this),this.structureMap.group||(this.structureMap.group=[]),this.structureMap.group.push(e)},ki=function(){const e=[];for(this.parser.consume("(");this.parser.hasMore()&&")"!==this.parser.peek()?.value;)e.push(n(this,Ei,"m",Ai).call(this)),","===this.parser.peek()?.value&&this.parser.consume(",");return this.parser.consume(")"),e},Ai=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},Ci=function(){const e=[];for(this.parser.consume("{");this.parser.hasMore()&&"}"!==this.parser.peek()?.value;)e.push(n(this,Ei,"m",Ri).call(this));return this.parser.consume("}"),e},Ri=function(){const e={source:n(this,Ei,"m",Oi).call(this)};return"->"===this.parser.peek()?.value&&(this.parser.consume("->"),e.target=n(this,Ei,"m",Ii).call(this)),"then"===this.parser.peek()?.value&&(this.parser.consume("Symbol","then"),"{"===this.parser.peek()?.id?e.rule=n(this,Ei,"m",Ci).call(this):e.dependent=n(this,Ei,"m",Bi).call(this)),"String"===this.parser.peek()?.id?e.name=this.parser.consume().value:e.name=e.source?.[0]?.element,this.parser.consume(";"),e},Oi=function(){const e=[n(this,Ei,"m",Mi).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(n(this,Ei,"m",Mi).call(this));return e},Mi=function(){const e={},t=n(this,Ei,"m",Wi).call(this);if(t.includes(".")){const n=t.split(".");e.context=n[0],e.element=n[1]}else e.context=t;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},Ii=function(){const e=[n(this,Ei,"m",Ui).call(this)];for(;this.parser.hasMore()&&","===this.parser.peek()?.value;)this.parser.consume(","),e.push(n(this,Ei,"m",Ui).call(this));return e},Ui=function(){const e={},t=n(this,Ei,"m",Wi).call(this);if(t.includes(".")){const n=t.split(".");e.contextType="variable",e.context=n[0],e.element=n[1]}else e.context=t;return"="===this.parser.peek()?.value&&(this.parser.consume("="),n(this,Ei,"m",Li).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},Li=function(e){e.transform="copy";const t=this.parser.consumeAndParse(6);if(t instanceof Fn)n(this,Ei,"m",Ni).call(this,e,t);else if(t instanceof ci)n(this,Ei,"m",_i).call(this,e,t);else{if(!(t instanceof qn))throw new Error(`Unexpected FHIRPath: ${t}`);n(this,Ei,"m",ji).call(this,e,t)}},Ni=function(e,t){e.parameter=[{valueId:t.name}]},_i=function(e,t){const n=t.name;switch(n){case"create":e.parameter=[{valueString:t.args?.[0].value.value}];break;case"translate":e.parameter=[{}];break;default:throw new Error("Unknown target function: "+n)}},ji=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)}},Wi=function(){let e=this.parser.consume().value;for(;"."===this.parser.peek()?.value;)this.parser.consume("."),e+="."+this.parser.consume().value;return e},Bi=function(){const e=this.parser.consumeAndParse(100);return[{name:e.name,variable:e.args.map((e=>e.name))}]},Qi=function(){for(;"}"!==this.parser.peek()?.value;)this.parser.consume();this.parser.consume("}")};const qi=gi().registerInfix("->",{precedence:100}).registerInfix(";",{precedence:200});const Fi=[...pi,"eq","ne","co"];class Hi{constructor(e,t,n){this.path=e,this.operator=t,this.value=n}}class zi{constructor(e){this.child=e}}class Vi{constructor(e,t,n){this.keyword=e,this.left=t,this.right=n}}class Gi{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 zi(this.parse()),this.parser.consume(")")):e=new Hi(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 Vi(t,e,this.parse())):e}}const Ji=gi();class Xi{constructor(e="\r",t="|",n="^",i="~",r="\\",o="&"){this.segmentSeparator=e,this.fieldSeparator=t,this.componentSeparator=n,this.repetitionSeparator=i,this.escapeCharacter=r,this.subcomponentSeparator=o}getMsh2(){return this.fieldSeparator+this.componentSeparator+this.repetitionSeparator+this.escapeCharacter+this.subcomponentSeparator}}class Yi{constructor(e,t=new Xi){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"),n=t?.get(2)?.toString()||"",i=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 Yi([new Ki(["MSH",this.context.getMsh2(),r,o,n,i,e.toISOString(),"","ACK",e.getTime().toString(),"P",a],this.context),new Ki(["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 Xi("\r",e.charAt(3),e.charAt(4),e.charAt(5),e.charAt(6),e.charAt(7));return new Yi(e.split(/[\r\n]+/).map((e=>Ki.parse(e,t))),t)}}class Ki{constructor(e,t=new Xi){this.context=t,I(e)?this.fields=e.map((e=>Zi.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 Xi){return new Ki(e.split(t.fieldSeparator).map((e=>Zi.parse(e,t))),t)}}class Zi{constructor(e,t=new Xi){this.context=t,this.components=e}get(e,t,n=0){let i=this.components[n][e]||"";return void 0!==t&&(i=i.split(this.context.subcomponentSeparator)[t]||""),i}toString(){return this.components.map((e=>e.join(this.context.componentSeparator))).join(this.context.repetitionSeparator)}static parse(e,t=new Xi){return new Zi(e.split(t.repetitionSeparator).map((e=>e.split(t.componentSeparator))),t)}}var er,tr,nr,ir,rr,or,sr,ar,cr,ur,lr,pr,dr,hr;const fr={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"},mr=new Set(["resourceType","id","meta","implicitRules","language","text","contained","extension","modifierExtension"]);function yr(e){const t=We.types[e];return t&&t.structureDefinition.id===e&&"resource"===t.structureDefinition.kind}class gr{constructor(e){er.add(this),tr.set(this,void 0),nr.set(this,void 0),i(this,tr,[],"f"),i(this,nr,e,"f")}validate(){const e=n(this,nr,"f");if(!e)throw new me(de("Resource is null"));const t=e.resourceType;if(!t)throw new me(de("Missing resource type"));if(vr(e,"",n(this,tr,"f")),n(this,er,"m",ir).call(this,wn(e),t),n(this,tr,"f").length>0)throw new me({resourceType:"OperationOutcome",issue:n(this,tr,"f")})}}function vr(e,t,n){null===e?n.push(xr(t,"Invalid null value")):Array.isArray(e)?function(e,t,n){for(let i=0;i<e.length;i++)void 0===e[i]?n.push(xr(`${t}[${i}]`,"Invalid undefined value")):vr(e[i],`${t}[${i}]`,n)}(e,t,n):"object"==typeof e&&function(e,t,n){for(const[i,r]of Object.entries(e))vr(r,`${t}${t?".":""}${i}`,n)}(e,t,n)}function xr(e,t){return{severity:"error",code:"structure",details:{text:t},expression:[e]}}var wr;function Sr(t,n){let i=We.types[t]?.searchParamsDetails?.[n.code];return i||(i=function(t,n){const i=n.code,r=function(e){return e.split("-").reduce(((e,t,n)=>e+(n?_(t):t)),"")}(i),o=br(t,n.expression)?.split(".");if(!o)return{columnName:r,type:e.SearchParameterType.TEXT};const s=Er(n);let a,c,u=t,l=!1;for(let e=1;e<o.length;e++){if(a=_e(u,o[e]),!a)throw new Error(`Element definition not found for ${t} ${n.code}`);if("*"===a.max&&(l=!0),c=a.type?.[0].code,!c)return{columnName:r,type:s,array:l};e<o.length-1&&(u=Tr(c)?Ie(a.path?.split(".")):c)}const p=Er(n,c),d={columnName:r,type:p,elementDefinition:a,array:l};return function(e,t,n){const i=We.types[e];i.searchParamsDetails||(i.searchParamsDetails={});i.searchParamsDetails[t]=n}(t,i,d),d}(t,n)),i}function Tr(e){return"Element"===e||"BackboneElement"===e}function Er(t,n){let i=e.SearchParameterType.TEXT;switch(t.type){case"date":i=n===e.PropertyType.dateTime||n===e.PropertyType.instant?e.SearchParameterType.DATETIME:e.SearchParameterType.DATE;break;case"number":i=e.SearchParameterType.NUMBER;break;case"quantity":i=e.SearchParameterType.QUANTITY;break;case"reference":i=e.SearchParameterType.REFERENCE;break;case"token":"boolean"===n&&(i=e.SearchParameterType.BOOLEAN)}return i}function br(e,t){const n=t.split(" | ");for(const t of n){if((i=t).includes(" as Period")||i.includes(" as SampledDate"))continue;const n=Pr(t);if(n.startsWith(e+"."))return n}var i}function Pr(e){let t=e.trim();t.startsWith("(")&&t.endsWith(")")&&(t=t.substring(1,t.length-1)),t.includes("[0]")&&(t=t.replaceAll("[0]",""));const n=[" != "," as ",".as(",".exists(",".resolve(",".where("];for(const e of n)t.includes(e)&&(t=t.substring(0,t.indexOf(e)));return t}tr=new WeakMap,nr=new WeakMap,er=new WeakSet,ir=function(e,t){const i=We.types[e.type];if(!i)throw new me(de("Unknown type: "+e.type));const r=i.properties;n(this,er,"m",rr).call(this,t,r,e),n(this,er,"m",lr).call(this,t,e,r)},rr=function(e,t,i){for(const[r,o]of Object.entries(t))n(this,er,"m",or).call(this,e+"."+r,o,i)},or=function(e,t,i){const r=Tn(i,e.split(".").pop());if(R(r))void 0!==t.min&&t.min>0&&n(this,tr,"f").push(xr(e,"Missing required property"));else if("*"===t.max){if(!Array.isArray(r))return void n(this,tr,"f").push(xr(e,"Expected array for property"));for(const i of r)n(this,er,"m",sr).call(this,e,t,i)}else{if(Array.isArray(r))return void n(this,tr,"f").push(xr(e,"Expected single value for property"));n(this,er,"m",sr).call(this,e,t,r)}},sr=function(e,t,i){null!==i.value&&(j(i.type.charAt(0))?n(this,er,"m",ar).call(this,t,i):n(this,er,"m",ir).call(this,i,e))},ar=function(e,t){const{type:i,value:r}=t;if(null===r)return;const o=fr[t.type];typeof r===o?"string"===o?n(this,er,"m",cr).call(this,e,i,r):"number"===o&&n(this,er,"m",ur).call(this,e,i,r):n(this,er,"m",hr).call(this,e,"Invalid type for "+i)},cr=function(e,t,i){if(!i.trim())return void n(this,er,"m",hr).call(this,e,"Invalid empty string");const r=We.types[t]?.properties?.value;if(r?.type){const o=k(r.type[0],"http://hl7.org/fhir/StructureDefinition/regex");o&&(i.match(new RegExp(o))||n(this,er,"m",hr).call(this,e,"Invalid "+t+" format"))}},ur=function(t,i,r){var o;!isNaN(r)&&isFinite(r)?((o=i)!==e.PropertyType.integer&&o!==e.PropertyType.positiveInt&&o!==e.PropertyType.unsignedInt||Number.isInteger(r)||n(this,er,"m",hr).call(this,t,"Number is not an integer"),i===e.PropertyType.positiveInt&&r<=0&&n(this,er,"m",hr).call(this,t,"Number is less than or equal to zero"),i===e.PropertyType.unsignedInt&&r<0&&n(this,er,"m",hr).call(this,t,"Number is negative")):n(this,er,"m",hr).call(this,t,"Invalid "+i+" value")},lr=function(e,t,i){const r=t.value;for(const o of Object.keys(r))n(this,er,"m",pr).call(this,e,o,t,i)},pr=function(e,t,i,r){if(!(mr.has(t)||t in r||function(e,t,n){for(const i of Object.keys(n)){if(!i.endsWith("[x]"))continue;const n=i.replace("[x]","");if(!e.startsWith(n))continue;let r=Tn(t,i);if(r&&(Array.isArray(r)&&(r=r[0]),r&&e===n+_(r.type)))return!0}return!1}(t,i,r)||n(this,er,"m",dr).call(this,e,t,i))){const i=`${e}.${t}`;n(this,tr,"f").push(xr(i,`Invalid additional property "${i}"`))}},dr=function(e,t,i){if(!t.startsWith("_"))return!1;return t.slice(1)in i.value&&(n(this,er,"m",ir).call(this,{type:"Element",value:i.value[t]},e),!0)},hr=function(e,t){n(this,tr,"f").push(xr(e.path,t))},e.SearchParameterType=void 0,(wr=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",wr.NUMBER="NUMBER",wr.QUANTITY="QUANTITY",wr.TEXT="TEXT",wr.REFERENCE="REFERENCE",wr.DATE="DATE",wr.DATETIME="DATETIME",wr.PERIOD="PERIOD",wr.UUID="UUID";var Dr;e.Operator=void 0,(Dr=e.Operator||(e.Operator={})).EQUALS="eq",Dr.NOT_EQUALS="ne",Dr.GREATER_THAN="gt",Dr.LESS_THAN="lt",Dr.GREATER_THAN_OR_EQUALS="ge",Dr.LESS_THAN_OR_EQUALS="le",Dr.STARTS_AFTER="sa",Dr.ENDS_BEFORE="eb",Dr.APPROXIMATELY="ap",Dr.CONTAINS="contains",Dr.EXACT="exact",Dr.TEXT="text",Dr.NOT="not",Dr.ABOVE="above",Dr.BELOW="below",Dr.IN="in",Dr.NOT_IN="not-in",Dr.OF_TYPE="of-type",Dr.MISSING="missing",Dr.IDENTIFIER="identifier";const kr={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,missing:e.Operator.MISSING,identifier:e.Operator.IDENTIFIER},Ar={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};function Cr(e){return Rr(e.pathname.split("/").filter(Boolean).pop(),Object.fromEntries(e.searchParams.entries()))}function Rr(e,t){const n={resourceType:e};for(const[e,i]of Object.entries(t))Array.isArray(i)?i.forEach((t=>Or(n,e,t))):Or(n,e,i??"");return n}function Or(t,n,i){let r,o;const s=n.indexOf(":");switch(s>=0?(r=n.substring(0,s),o=n.substring(s+1)):(r=n,o=""),r){case"_sort":!function(e,t){for(const n of t.split(",")){let t,i=!1;n.startsWith("-")?(t=n.substring(1),i=!0):t=n,e.sortRules||(e.sortRules=[]),e.sortRules.push({code:t,descending:i})}}(t,i);break;case"_count":t.count=parseInt(i);break;case"_offset":t.offset=parseInt(i);break;case"_total":t.total=i;break;case"_summary":t.total="estimate",t.count=0;break;case"_include":t.include=i;break;case"_revinclude":t.revInclude=i;break;case"_fields":t.fields=i.split(",");break;default:{const n=We.types[t.resourceType]?.searchParams?.[r];n?function(t,n,i,r){if("missing"===i)return void Ur(t,{code:n.code,operator:e.Operator.MISSING,value:r});switch(n.type){case"number":case"date":!function(e,t,n){const{operator:i,value:r}=Mr(n);Ur(e,{code:t.code,operator:i,value:r})}(t,n,r);break;case"reference":case"string":case"token":case"uri":!function(e,t,n,i){Ur(e,{code:t.code,operator:Ir(n),value:i})}(t,n,i,r);break;case"quantity":!function(e,t,n){const[i,r,o]=n.split("|"),{operator:s,value:a}=Mr(i);Ur(e,{code:t.code,operator:s,value:a,unitSystem:r,unitCode:o})}(t,n,r)}}(t,n,o,i):function(t,n,i,r){let o=e.Operator.EQUALS;if(i)o=i;else if(r.length>=2){const e=r.substring(0,2);e in Ar&&(2===r.length||r.at(2)?.match(/\d/))&&(o=e,r=r.substring(e.length))}Ur(t,{code:n,operator:o,value:r})}(t,r,o,i)}}}function Mr(t){const n=t.substring(0,2),i=Ar[n];return i?{operator:i,value:t.substring(2)}:{operator:e.Operator.EQUALS,value:t}}function Ir(t){return kr[t]||e.Operator.EQUALS}function Ur(e,t){e.filters?e.filters.push(t):e.filters=[t]}function Lr(t,n,i){const r=We.types[n.resourceType]?.searchParams?.[i.code];switch(r?.type){case"reference":return function(t,n,i){const r=wi(i.expression,t),o=Wr(n.operator);if(""===n.value&&0===r.length)return n.operator===e.Operator.EQUALS;const s=r.map((e=>"string"==typeof e?e:e.reference));for(const e of n.value.split(",")){let t=s.includes(e);if(t||"_compartment"!==n.code||(t=s.some((t=>t?.endsWith("/"+e)))),t)return!o}return o}(t,i,r);case"string":case"uri":return Nr(t,i,r);case"token":return function(t,n,i){const r=Sr(t.resourceType,i);return r.type===e.SearchParameterType.BOOLEAN?function(e,t,n){const i=wi(n.expression,e),r="true"===t.value,o=i.includes(r);return Wr(t.operator)?!o:o}(t,n,i):Nr(t,n,i,!0)}(t,i,r);case"date":return function(e,t,n){const i=wi(n.expression,e),r=t.value.split(","),o=Wr(t.operator);for(const e of i)for(const n of r){if(jr(e,t.operator,n))return!o}return o}(t,i,r)}return!1}function Nr(e,t,n,i){const r=wi(n.expression,e),o=t.value.split(","),s=Wr(t.operator);for(const e of r)for(const n of o){if(_r(e,t.operator,n,i))return!s}return s}function _r(e,t,n,i){if(i&&n.includes("|")){const[i,r]=n.split("|");return _r(e,t,i,!1)&&(!r||_r(e,t,r,!1))}let r="";return e&&("string"==typeof e?r=e:"object"==typeof e&&(r=JSON.stringify(e))),r.toLowerCase().includes(n.toLowerCase())}function jr(t,n,i){switch(n){case e.Operator.STARTS_AFTER:case e.Operator.GREATER_THAN:return t>i;case e.Operator.GREATER_THAN_OR_EQUALS:return t>=i;case e.Operator.ENDS_BEFORE:case e.Operator.LESS_THAN:return t<i;case e.Operator.LESS_THAN_OR_EQUALS:return t<=i;case e.Operator.EQUALS:case e.Operator.NOT_EQUALS:return t===i}return!1}function Wr(t){return t===e.Operator.NOT_EQUALS||t===e.Operator.NOT}e.AndAtom=oi,e.ArithemticOperatorAtom=Gn,e.AsAtom=Vn,e.ClientStorage=ke,e.ConcatAtom=Jn,e.ContainsAtom=Xn,e.DEFAULT_SEARCH_COUNT=20,e.DotAtom=Kn,e.EmptySetAtom=Hn,e.EqualsAtom=ei,e.EquivalentAtom=ni,e.FHIRPATH_KEYWORDS=li,e.FHIRPATH_OPERATORS=pi,e.FhirFilterComparison=Hi,e.FhirFilterConnective=Vi,e.FhirFilterNegation=zi,e.FhirPathAtom=$n,e.FhirSchemaValidator=gr,e.FunctionAtom=ci,e.Hl7Context=Xi,e.Hl7Field=Zi,e.Hl7Message=Yi,e.Hl7Segment=Ki,e.InAtom=Yn,e.IndexerAtom=ui,e.InfixOperatorAtom=hn,e.IsAtom=ri,e.LRUCache=c,e.LiteralAtom=qn,e.MEDPLUM_VERSION="2.0.14-8c7457fd",e.MedplumClient=class extends z{constructor(e){if(super(),Be.add(this),Qe.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),Ve.set(this,void 0),Ge.set(this,void 0),Je.set(this,void 0),Xe.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),nt.set(this,void 0),it.set(this,void 0),rt.set(this,void 0),ot.set(this,void 0),st.set(this,void 0),at.set(this,void 0),ct.set(this,void 0),ut.set(this,void 0),e?.baseUrl&&!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");i(this,Qe,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?.storage||new ke,"f"),i(this,$e,e?.createPdf,"f"),i(this,Fe,new c(e?.resourceCacheSize??1e3),"f"),i(this,He,e?.cacheTime??6e4,"f"),i(this,ze,Rt(e?.baseUrl)||"https://api.medplum.com/","f"),i(this,Ve,n(this,ze,"f")+(Rt(e?.fhirUrlPath)||"fhir/R4/"),"f"),i(this,tt,e?.clientId||"","f"),i(this,Ge,e?.authorizeUrl||n(this,ze,"f")+"oauth2/authorize","f"),i(this,Je,e?.tokenUrl||n(this,ze,"f")+"oauth2/token","f"),i(this,Xe,e?.logoutUrl||n(this,ze,"f")+"oauth2/logout","f"),i(this,Ye,n(this,ze,"f")+"auth/exchange","f"),i(this,Ke,e?.onUnauthenticated,"f"),i(this,Ze,e?.autoBatchTime??0,"f"),i(this,et,[],"f");const t=this.getActiveLogin();t&&(i(this,rt,t.accessToken,"f"),i(this,ot,t.refreshToken,"f"),n(this,Be,"m",pt).call(this).catch(console.log)),n(this,Be,"m",kt).call(this)}getBaseUrl(){return n(this,ze,"f")}clear(){n(this,qe,"f").clear(),this.clearActiveLogin()}clearActiveLogin(){n(this,qe,"f").setString("activeLogin",void 0),n(this,Fe,"f").clear(),i(this,rt,void 0,"f"),i(this,ot,void 0,"f"),i(this,ct,void 0,"f"),i(this,ut,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(e){e=e.toString(),n(this,Fe,"f").delete(e)}invalidateSearches(e){const t="fhir/R4/"+e;for(const e of n(this,Fe,"f").keys())(e.endsWith(t)||e.includes(t+"?"))&&n(this,Fe,"f").delete(e)}get(e,t={}){e=e.toString();const r=n(this,Be,"m",dt).call(this,e,t);if(r)return r.value;let o;o=e.startsWith(n(this,Ve,"f"))&&n(this,Ze,"f")>0?new Promise(((r,o)=>{n(this,et,"f").push({method:"GET",url:e.replace(n(this,Ve,"f"),""),options:t,resolve:r,reject:o}),n(this,it,"f")||i(this,it,setTimeout((()=>n(this,Be,"m",vt).call(this)),n(this,Ze,"f")),"f")})):n(this,Be,"m",yt).call(this,"GET",e,t);const s=new De(o);return n(this,Be,"m",ht).call(this,e,s),s}post(e,t,i,r={}){return e=e.toString(),t&&n(this,Be,"m",St).call(this,r,t),i&&n(this,Be,"m",wt).call(this,r,i),this.invalidateUrl(e),n(this,Be,"m",yt).call(this,"POST",e,r)}put(e,t,i,r={}){return e=e.toString(),t&&n(this,Be,"m",St).call(this,r,t),i&&n(this,Be,"m",wt).call(this,r,i),this.invalidateUrl(e),n(this,Be,"m",yt).call(this,"PUT",e,r)}patch(e,t,i={}){return e=e.toString(),n(this,Be,"m",St).call(this,i,t),n(this,Be,"m",wt).call(this,i,"application/json-patch+json"),this.invalidateUrl(e),n(this,Be,"m",yt).call(this,"PATCH",e,i)}delete(e,t={}){return e=e.toString(),this.invalidateUrl(e),n(this,Be,"m",yt).call(this,"DELETE",e,t)}async startNewUser(e){const{codeChallengeMethod:t,codeChallenge:n}=await this.startPkce();return this.post("auth/newuser",{...e,codeChallengeMethod:t,codeChallenge:n})}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??n(this,tt,"f"),scope:e.scope})}async startGoogleLogin(e){return this.post("auth/google",{...await this.ensureCodeChallenge(e),clientId:e.clientId??n(this,tt,"f"),scope:e.scope})}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(n(this,Xe,"f"),{}),this.clear()}async signInWithRedirect(e){const t=new URLSearchParams(window.location.search).get("code");return t?this.processCode(t):void await n(this,Be,"m",Et).call(this,e)}signOutWithRedirect(){window.location.assign(n(this,Xe,"f"))}async signInWithExternalAuth(e,t,n,i){const r=await this.ensureCodeChallenge(i);window.location.assign(this.getExternalAuthRedirectUri(e,t,n,r))}async exchangeExternalAccessToken(e,t){if(!(t=t||n(this,tt,"f")))throw new Error("MedplumClient is missing clientId");const i=await n(this,Qe,"f").call(this,n(this,Ye,"f"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:n(this,tt,"f"),externalAccessToken:e}),credentials:"include"});if(!i.ok)throw this.clearActiveLogin(),new Error("Failed to fetch tokens");const r=await i.json();return await n(this,Be,"m",Dt).call(this,r),this.getProfile()}getExternalAuthRedirectUri(e,t,n,i){const r=new URL(e);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",t),r.searchParams.set("redirect_uri",n),r.searchParams.set("scope","openid profile email"),r.searchParams.set("state",JSON.stringify(i)),r.toString()}fhirUrl(...e){return new URL(n(this,Ve,"f")+e.join("/"))}fhirSearchUrl(e,t){const n=this.fhirUrl(e);return t&&(n.search=new URLSearchParams(t).toString()),n}search(e,t,i={}){const r=this.fhirSearchUrl(e,t),o=r.toString()+"-search",s=n(this,Be,"m",dt).call(this,o,i);if(s)return s.value;const a=new De((async()=>{const e=await this.get(r,i);if(e.entry)for(const t of e.entry)n(this,Be,"m",ft).call(this,t.resource);return e})());return n(this,Be,"m",ht).call(this,o,a),a}searchOne(e,t,i={}){const r=this.fhirSearchUrl(e,t);r.searchParams.set("_count","1"),r.searchParams.sort();const o=r.toString()+"-searchOne",s=n(this,Be,"m",dt).call(this,o,i);if(s)return s.value;const a=new De(this.search(e,r.searchParams,i).then((e=>e.entry?.[0]?.resource)));return n(this,Be,"m",ht).call(this,o,a),a}searchResources(e,t,i={}){const r=this.fhirSearchUrl(e,t).toString()+"-searchResources",o=n(this,Be,"m",dt).call(this,r,i);if(o)return o.value;const s=new De(this.search(e,t,i).then((e=>e.entry?.map((e=>e.resource))??[])));return n(this,Be,"m",ht).call(this,r,s),s}async*searchResourcePages(e,t,n={}){let i=this.fhirSearchUrl(e,t);for(;i;){const t=new URL(i).searchParams,r=await this.search(e,t,n),o=r?.link?.find((e=>"next"===e.relation));if(!r?.entry?.length&&!o)break;yield r?.entry?.map((e=>e.resource))??[],i=o?.url?new URL(o?.url):void 0}}searchValueSet(e,t,n={}){const i=this.fhirUrl("ValueSet","$expand");return i.searchParams.set("url",e),i.searchParams.set("filter",t),this.get(i.toString(),n)}getCached(e,t){const i=n(this,Fe,"f").get(this.fhirUrl(e,t).toString())?.value;return i&&i.isOk()?i.read():void 0}getCachedReference(e){const t=e.reference;if(!t)return;if("system"===t)return At;const[n,i]=t.split("/");return n&&i?this.getCached(n,i):void 0}readResource(e,t,n={}){return this.get(this.fhirUrl(e,t),n)}readReference(e,t={}){const n=e?.reference;if(!n)return new De(Promise.reject(new Error("Missing reference")));if("system"===n)return new De(Promise.resolve(At));const[i,r]=n.split("/");return i&&r?this.readResource(i,r,t):new De(Promise.reject(new Error("Invalid reference")))}getSchema(){return We}requestSchema(e){if(e in We.types)return Promise.resolve(We);const t=e+"-requestSchema",i=n(this,Be,"m",dt).call(this,t,void 0);if(i)return i.value;const r=new De((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," "),n=await this.graphql(t);for(const e of n.data.StructureDefinitionList)Oe(e);for(const e of n.data.SearchParameterList)Me(e);return We})());return n(this,Be,"m",ht).call(this,t,r),r}readHistory(e,t,n={}){return this.get(this.fhirUrl(e,t,"_history"),n)}readVersion(e,t,n,i={}){return this.get(this.fhirUrl(e,t,"_history",n),i)}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,n,i){const r=this.fhirUrl("Binary");return t&&r.searchParams.set("_filename",t),i?this.uploadwithProgress(r,e,n,i):this.post(r,e,n)}uploadwithProgress(e,t,i,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 "+n(this,rt,"f")),a.setRequestHeader("Cache-Control","no-cache, no-store, max-age=0"),a.setRequestHeader("Content-Type",i),a.setRequestHeader("X-Medplum","extended"),a.send(t)}))}async createPdf(e,t,i,r){if(!n(this,$e,"f"))throw new Error("PDF creation not enabled");const o=await n(this,$e,"f").call(this,e,i,r);return this.createBinary(o,t,"application/pdf")}createComment(e,t){const n=this.getProfile();let i,r;return"Encounter"===e.resourceType&&(i=w(e),r=e.subject),"ServiceRequest"===e.resourceType&&(i=e.encounter,r=e.subject),"Patient"===e.resourceType&&(r=w(e)),this.createResource({resourceType:"Communication",basedOn:[w(e)],encounter:i,subject:r,sender:n?w(n):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 t=await this.put(this.fhirUrl(e.resourceType,e.id),e);return t||(t=e),n(this,Be,"m",ft).call(this,t),t}patchResource(e,t,n){return this.invalidateSearches(e),this.patch(this.fhirUrl(e,t),n)}deleteResource(e,t){return n(this,Be,"m",mt).call(this,this.fhirUrl(e,t).toString()),this.invalidateSearches(e),this.delete(this.fhirUrl(e,t))}validateResource(e){return this.post(this.fhirUrl(e.resourceType,"$validate"),e)}executeBot(e,t,n,i={}){let r;if("string"==typeof e){const t=e;r=this.fhirUrl("Bot",t,"$execute")}else{const t=e;r=this.fhirUrl("Bot","$execute")+`?identifier=${t.system}|${t.value}`}return this.post(r,t,n,i)}executeBatch(e){return this.post("fhir/R4",e)}sendEmail(e){return this.post("email/v1/send",e,"application/json")}graphql(e,t,n,i){return this.post(this.fhirUrl("$graphql"),{query:e,operationName:t,variables:n},"application/json",i)}readResourceGraph(e,t,n){return this.get(`${this.fhirUrl(e,t)}/$graph?graph=${n}`)}getActiveLogin(){return n(this,qe,"f").getObject("activeLogin")}async setActiveLogin(e){this.clearActiveLogin(),i(this,rt,e.accessToken,"f"),i(this,ot,e.refreshToken,"f"),n(this,qe,"f").setObject("activeLogin",e),n(this,Be,"m",lt).call(this,e),i(this,st,void 0,"f"),await n(this,Be,"m",pt).call(this)}getAccessToken(){return n(this,rt,"f")}setAccessToken(e){i(this,rt,e,"f"),i(this,ot,void 0,"f"),i(this,ct,void 0,"f"),i(this,ut,void 0,"f")}getLogins(){return n(this,qe,"f").getObject("logins")??[]}isLoading(){return!!n(this,at,"f")}getProfile(){return n(this,ct,"f")}async getProfileAsync(){return n(this,at,"f")&&await n(this,at,"f"),this.getProfile()}getUserConfiguration(){return n(this,ut,"f")}async download(e,t={}){n(this,st,"f")&&await n(this,st,"f"),n(this,Be,"m",xt).call(this,t);return(await n(this,Qe,"f").call(this,e.toString(),t)).blob()}async startPkce(){const e=F();sessionStorage.setItem("pkceState",e);const t=F();sessionStorage.setItem("codeVerifier",t);const n=N(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",n),{codeChallengeMethod:"S256",codeChallenge:n}}processCode(e,t){const i=new URLSearchParams;if(i.set("grant_type","authorization_code"),i.set("code",e),i.set("client_id",t?.clientId||n(this,tt,"f")),i.set("redirect_uri",t?.redirectUri||Ct()),"undefined"!=typeof sessionStorage){const e=sessionStorage.getItem("codeVerifier");e&&i.set("code_verifier",e)}return n(this,Be,"m",Pt).call(this,i)}async startClientLogin(e,t){i(this,tt,e,"f"),i(this,nt,t,"f");const r=new URLSearchParams;return r.set("grant_type","client_credentials"),r.set("client_id",e),r.set("client_secret",t),n(this,Be,"m",Pt).call(this,r)}async invite(e,t){return this.post("admin/projects/"+e+"/invite",t)}},e.MemoryStorage=Ae,e.NotEqualsAtom=ti,e.NotEquivalentAtom=ii,e.OperationOutcomeError=me,e.OrAtom=si,e.Parser=mn,e.ParserBuilder=fn,e.PrefixOperatorAtom=dn,e.ReadablePromise=De,e.SymbolAtom=Fn,e.Tokenizer=gn,e.UnaryOperatorAtom=zn,e.UnionAtom=Zn,e.XorAtom=ai,e.allOk=ie,e.arrayBufferToBase64=N,e.arrayBufferToHex=L,e.assertOk=function(e,t){if(!fe(e)||void 0===t)throw new me(e)},e.badRequest=pe,e.booleanToTypedValue=xn,e.buildTypeName=Ie,e.calculateAge=P,e.calculateAgeString=function(e,t){const{years:n,months:i,days:r}=P(e,t);return n>=2?n.toString().padStart(3,"0")+"Y":i>=1?i.toString().padStart(3,"0")+"M":r.toString().padStart(3,"0")+"D"},e.capitalize=_,e.checkForNull=vr,e.convertToTransactionBundle=function(e){for(const t of e.entry||[])delete t?.resource?.meta,t.fullUrl="urn:uuid:"+t?.resource?.id,delete t?.resource?.id;const n=e.entry,i=JSON.stringify({resourceType:"Bundle",type:"transaction",entry:n?.map((e=>({fullUrl:e.fullUrl,request:{method:"POST",url:e.resource.resourceType},resource:e.resource})))},t,2);return JSON.parse(i)},e.createReference=w,e.createStructureIssue=xr,e.created=re,e.deepClone=function(e){return JSON.parse(JSON.stringify(e))},e.deepEquals=O,e.evalFhirPath=wi,e.evalFhirPathTyped=Si,e.fhirPathArrayEquals=Dn,e.fhirPathArrayEquivalent=An,e.fhirPathEquals=kn,e.fhirPathEquivalent=Cn,e.fhirPathIs=On,e.fhirPathNot=Pn,e.findObservationInterval=function(e,t,n,i){return e.qualifiedInterval?.find((r=>W(r,t)&&function(e,t,n){return!!e.range&&B(t,e.range,n)}(r,n,e.quantitativeDetails?.decimalPrecision)&&(void 0===i||r.category===i)))},e.findObservationReferenceRange=function(e,t,n){return e.qualifiedInterval?.find((e=>W(e,t)&&n.includes(e.condition)))},e.forbidden=ce,e.formatAddress=function(e,t){const n=[];if(e.line&&n.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),n.push(t.join(", "))}return e.use&&(t?.all||t?.use)&&n.push("["+e.use+"]"),n.join(t?.lineSeparator||", ").trim()},e.formatCodeableConcept=g,e.formatCoding=v,e.formatDate=function(e,t,n){if(!e)return"";const i=new Date(e);return l(i)?(i.setUTCHours(0,0,0,0),i.toLocaleDateString(t,{timeZone:"UTC",...n})):""},e.formatDateTime=d,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=u,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?y(t.valueQuantity):t.valueCodeableConcept?g(t.valueCodeableConcept):t.valueString?t.valueString:"":""},e.formatPeriod=function(e,t,n){return e&&(e.start||e.end)?d(e.start,t,n)+" - "+d(e.end,t,n):""},e.formatQuantity=y,e.formatRange=function(e,t,n=!1){if(n&&void 0===t)throw new Error("Precision must be specified for exclusive ranges");const i=e?.low&&{...e.low},r=e?.high&&{...e.high};return!e||void 0===i?.value&&void 0===r?.value?"":void 0!==e.low?.value&&void 0===e.high?.value?n&&void 0!==t?(e.low.value=function(e,t,n=1){return(x(e,t)-n)*Math.pow(10,-t)}(e.low.value,t),`> ${y(e.low,t)}`):`>= ${y(e.low,t)}`:void 0===e.low?.value&&void 0!==e.high?.value?n&&void 0!==t?(e.high.value=function(e,t,n=1){return(x(e,t)+n)*Math.pow(10,-t)}(e.high.value,t),`< ${y(e.high,t)}`):`<= ${y(e.high,t)}`:(i?.unit===r?.unit&&delete i?.unit,`${y(i,t)} - ${y(r,t)}`)},e.formatSearchQuery=function(t){const n=[];return t.fields&&n.push("_fields="+t.fields.join(",")),t.filters&&t.filters.forEach((t=>n.push(function(t){const n=t.operator in kr?":"+t.operator:"",i=t.operator!==e.Operator.EQUALS&&t.operator in Ar?t.operator:"";return`${t.code}${n}=${i}${encodeURIComponent(t.value)}`}(t)))),t.sortRules&&t.sortRules.length>0&&n.push("_sort="+t.sortRules.map((e=>e.descending?"-"+e.code:e.code)).join(",")),void 0!==t.offset&&n.push("_offset="+t.offset),void 0!==t.count&&n.push("_count="+t.count),void 0!==t.total&&n.push("_total="+t.total),0===n.length?"":(n.sort(),"?"+n.join("&"))},e.formatTime=p,e.formatTiming=function(e){if(!e)return"";const t=[];if(e.repeat?.periodUnit){const n=e.repeat.frequency||1,i=e.repeat.period||1,r=e.repeat.periodUnit;1===n&&1===i?t.push(h[r]):(1===n?t.push("once"):t.push(n+" times"),1===i?t.push("per "+f[r]):t.push("per "+i+" "+m[r])),e.repeat.dayOfWeek&&t.push("on "+e.repeat.dayOfWeek.map(_).join(", ")),e.repeat.timeOfDay&&t.push("at "+e.repeat.timeOfDay.map((e=>p(e))).join(", "))}return e.event&&t.push(e.event.map((e=>d(e))).join(", ")),_(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=E,e.getElementDefinition=_e,e.getElementDefinitionTypeName=function(e){const t=e.type?.[0]?.code;return"BackboneElement"===t||"Element"===t?Ie(e.path?.split(".")):t},e.getExpressionForResourceType=br,e.getExtension=function(e,...t){let n=e;for(let e=0;e<t.length&&n;e++)n=n?.extension?.find((n=>n.url===t[e]));return n},e.getExtensionValue=k,e.getIdentifier=function(e,t){const n=e.identifier;if(!n)return;const i=Array.isArray(n)?n:[n];for(const e of i)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 b(t);for(const e of t){const t=b(e);if(t)return t}}},e.getPropertyDisplayName=function(e){return e.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(Ne).join(" ").replace("_"," ").replace(/\s+/g," ")},e.getQuestionnaireAnswers=function(e){const t={};return D(e.item,t),t},e.getReferenceString=S,e.getResourceTypeSchema=function(e){return We.types[e]},e.getResourceTypes=function(){const e=[];for(const[t,n]of Object.entries(We.types))Ue(n)&&e.push(t);return e},e.getSearchParameterDetails=Sr,e.getSearchParameters=function(e){return We.types[e].searchParams},e.getStatus=function(e){return e.id===J?200:e.id===X?201:e.id===K?304:e.id===ee?401:e.id===te?403:e.id===Z?404:e.id===Y?410:e.id===ne?429:400},e.getTypedPropertyValue=Tn,e.globalSchema=We,e.gone=ue,e.indexSearchParameter=Me,e.indexSearchParameterBundle=function(e){for(const t of e.entry){const e=t.resource;"SearchParameter"===e.resourceType&&Me(e)}},e.indexStructureDefinition=Oe,e.indexStructureDefinitionBundle=function(e){for(const t of e.entry){const e=t.resource;"StructureDefinition"===e.resourceType&&Oe(e)}},e.initFhirPathParserBuilder=gi,e.isEmpty=R,e.isGone=function(e){return e.id===Y},e.isLowerCase=j,e.isNotFound=function(e){return e.id===Z},e.isObject=M,e.isOk=fe,e.isOperationOutcome=he,e.isPeriod=Mn,e.isProfileResource=T,e.isQuantity=In,e.isQuantityEquivalent=Un,e.isReference=function(e){return!(!e||"object"!=typeof e||!("reference"in e))},e.isResource=je,e.isResourceType=yr,e.isResourceTypeSchema=Ue,e.isStringArray=I,e.isUUID=function(e){return!!e.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)},e.isValidDate=l,e.matchesRange=B,e.matchesSearchRequest=function(e,t){if(t.resourceType!==e.resourceType)return!1;if(t.filters)for(const n of t.filters)if(!Lr(e,t,n))return!1;return!0},e.normalizeErrorString=ge,e.normalizeOperationOutcome=ye,e.notFound=se,e.notModified=oe,e.operationOutcomeToString=ve,e.parseFhirPath=xi,e.parseFilterParameter=function(e){const t=Ji.construct(new gn(e,li,Fi,{dateTimeLiterals:!0,symbolRegex:/[^\s\])]/}).tokenize());return t.removeComments(),new Gi(t).parse()},e.parseJWTPayload=G,e.parseMappingLanguage=function(e){const t=qi.construct(new gn(e,li,Ti).tokenize());return t.removeComments(),new $i(t).parse()},e.parseSearchDefinition=function(e){return Cr(new URL(e,"https://example.com/"))},e.parseSearchRequest=function(e,t){return Rr(e,t)},e.parseSearchUrl=Cr,e.preciseEquals=function(e,t,n){return q(e,n)===q(t,n)},e.preciseGreaterThan=function(e,t,n){return q(e,n)>q(t,n)},e.preciseGreaterThanOrEquals=$,e.preciseLessThan=function(e,t,n){return q(e,n)<q(t,n)},e.preciseLessThanOrEquals=Q,e.preciseRound=function(e,t){return parseFloat(e.toFixed(t))},e.removeDuplicates=bn,e.resolveId=function(e){return e?.reference?.split("/")[1]},e.setCodeBySystem=function(e,t,n){e.coding||(e.coding=[]);const i=e.coding?.find((e=>e.system===t));i?i.code=n:e.coding?.push({system:t,code:n})},e.stringify=A,e.toJsBoolean=Sn,e.toTypedValue=wn,e.tokenize=di,e.tooManyRequests=le,e.unauthorized=ae,e.validateResource=function(e){new gr(e).validate()},e.validateResourceType=function(e){if(!e)throw new me(de("Resource type is null"));if(!yr(e))throw new me(de("Unknown resource type"))},e.validationError=de}));
|