@medplum/core 2.0.4 → 2.0.5
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 +35 -21
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/esm/client.mjs +10 -17
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/outcomes.mjs +17 -2
- package/dist/esm/outcomes.mjs.map +1 -1
- package/dist/esm/search/match.mjs +9 -4
- package/dist/esm/search/match.mjs.map +1 -1
- package/dist/{esm → types}/outcomes.d.ts +7 -1
- package/package.json +4 -4
- package/tsconfig.build.json +9 -0
- package/dist/cjs/outcomes.d.ts +0 -31
- package/dist/esm/cache.d.ts +0 -34
- package/dist/esm/client.d.ts +0 -1218
- package/dist/esm/crypto.d.ts +0 -9
- package/dist/esm/eventtarget.d.ts +0 -13
- package/dist/esm/fhirlexer/index.d.ts +0 -2
- package/dist/esm/fhirlexer/parse.d.ts +0 -47
- package/dist/esm/fhirlexer/tokenize.d.ts +0 -14
- package/dist/esm/fhirmapper/parse.d.ts +0 -7
- package/dist/esm/fhirmapper/tokenize.d.ts +0 -2
- package/dist/esm/fhirpath/atoms.d.ts +0 -120
- package/dist/esm/fhirpath/date.d.ts +0 -1
- package/dist/esm/fhirpath/functions.d.ts +0 -6
- package/dist/esm/fhirpath/index.d.ts +0 -4
- package/dist/esm/fhirpath/parse.d.ts +0 -64
- package/dist/esm/fhirpath/tokenize.d.ts +0 -4
- package/dist/esm/fhirpath/utils.d.ts +0 -95
- package/dist/esm/format.d.ts +0 -118
- package/dist/esm/hl7.d.ts +0 -136
- package/dist/esm/index.d.ts +0 -14
- package/dist/esm/jwt.d.ts +0 -5
- package/dist/esm/readablepromise.d.ts +0 -48
- package/dist/esm/search/details.d.ts +0 -33
- package/dist/esm/search/match.d.ts +0 -9
- package/dist/esm/search/parse.d.ts +0 -17
- package/dist/esm/search/search.d.ts +0 -66
- package/dist/esm/storage.d.ts +0 -47
- package/dist/esm/types.d.ts +0 -200
- package/dist/esm/utils.d.ts +0 -259
- /package/dist/{cjs → types}/cache.d.ts +0 -0
- /package/dist/{cjs → types}/client.d.ts +0 -0
- /package/dist/{cjs → types}/crypto.d.ts +0 -0
- /package/dist/{cjs → types}/eventtarget.d.ts +0 -0
- /package/dist/{cjs → types}/fhirlexer/index.d.ts +0 -0
- /package/dist/{cjs → types}/fhirlexer/parse.d.ts +0 -0
- /package/dist/{cjs → types}/fhirlexer/tokenize.d.ts +0 -0
- /package/dist/{cjs → types}/fhirmapper/parse.d.ts +0 -0
- /package/dist/{cjs → types}/fhirmapper/tokenize.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/atoms.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/date.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/functions.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/index.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/parse.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/tokenize.d.ts +0 -0
- /package/dist/{cjs → types}/fhirpath/utils.d.ts +0 -0
- /package/dist/{cjs → types}/format.d.ts +0 -0
- /package/dist/{cjs → types}/hl7.d.ts +0 -0
- /package/dist/{cjs → types}/index.d.ts +0 -0
- /package/dist/{cjs → types}/jwt.d.ts +0 -0
- /package/dist/{cjs → types}/readablepromise.d.ts +0 -0
- /package/dist/{cjs → types}/search/details.d.ts +0 -0
- /package/dist/{cjs → types}/search/match.d.ts +0 -0
- /package/dist/{cjs → types}/search/parse.d.ts +0 -0
- /package/dist/{cjs → types}/search/search.d.ts +0 -0
- /package/dist/{cjs → types}/storage.d.ts +0 -0
- /package/dist/{cjs → types}/types.d.ts +0 -0
- /package/dist/{cjs → types}/utils.d.ts +0 -0
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 d(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 d(i)?i.toLocaleTimeString(t,n):""}function u(e,t,n){if(!e)return"";const i=new Date(e);return d(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 p={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 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 m(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=S(e),n=E(e);return n===t?{reference:t}:{reference:t,display:n}}function S(e){return e.resourceType+"/"+e.id}function w(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function E(e){if(w(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:S(e)}function T(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function b(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(),d=i.getUTCDate();let l=a-r;(c<o||c===o&&d<s)&&l--;let u=12*a+c-(12*r+o);d<s&&u--;return{years:l,months:u,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){return JSON.stringify(e,A,t?2:void 0)}function A(e,t){return!function(e){return!!e.match(/\d+$/)}(e)&&C(t)?void 0:t}function C(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||(!(!C(e)||!C(t))||!C(e)&&!C(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 k(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 M(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 U(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 L(e){return e.charAt(0).toUpperCase()+e.substring(1)}function _(e,t){return function(e,t){return!e.gender||e.gender===t.gender}(e,t)&&function(e,t){return!e.age||N(b(t.birthDate).years,e.age)}(e,t)}function N(e,t,n){return(void 0===t.low?.value||Q(e,t.low.value,n))&&(void 0===t.high?.value||j(e,t.high.value,n))}function j(e,t,n){return W(e,n)<=W(t,n)}function Q(e,t,n){return W(e,n)>=W(t,n)}function W(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function B(){const e=new Uint32Array(28);return crypto.getRandomValues(e),M(e.buffer)}var q;class ${constructor(){q.set(this,void 0),n(this,q,{},"f")}addEventListener(e,n){t(this,q,"f")[e]||(t(this,q,"f")[e]=[]),t(this,q,"f")[e].push(n)}removeEventListeneer(e,n){const i=t(this,q,"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,q,"f")[e.type];return n&&n.forEach((t=>t.call(this,e))),!e.defaultPrevented}}function F(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 H(e){const[t,n,i]=e.split(".");return F(n)}q=new WeakMap;const z="ok",G="created",V="gone",X="not-modified",J="not-found",Y="unauthorized",K="forbidden",Z="too-many-requests",ee={resourceType:"OperationOutcome",id:z,issue:[{severity:"information",code:"informational",details:{text:"All OK"}}]},te={resourceType:"OperationOutcome",id:G,issue:[{severity:"information",code:"informational",details:{text:"Created"}}]},ne={resourceType:"OperationOutcome",id:X,issue:[{severity:"information",code:"informational",details:{text:"Not Modified"}}]},ie={resourceType:"OperationOutcome",id:J,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},re={resourceType:"OperationOutcome",id:Y,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},oe={resourceType:"OperationOutcome",id:K,issue:[{severity:"error",code:"forbidden",details:{text:"Forbidden"}}]},se={resourceType:"OperationOutcome",id:V,issue:[{severity:"error",code:"deleted",details:{text:"Gone"}}]},ae={resourceType:"OperationOutcome",id:Z,issue:[{severity:"error",code:"throttled",details:{text:"Too Many Requests"}}]};function ce(e){return"object"==typeof e&&null!==e&&"OperationOutcome"===e.resourceType}function de(e){return e.id===z||e.id===G||e.id===X}class le extends Error{constructor(e){super(e?.issue?.[0].details?.text),this.outcome=e}}var ue,pe,he,fe,ye,me,ge;class ve{constructor(e){this[ye]="ReadablePromise",ue.set(this,void 0),pe.set(this,"pending"),he.set(this,void 0),fe.set(this,void 0),n(this,ue,e.then((e=>(n(this,pe,"success","f"),n(this,he,e,"f"),e)),(e=>{throw n(this,pe,"error","f"),n(this,fe,e,"f"),e})),"f")}isPending(){return"pending"===t(this,pe,"f")}isOk(){return"success"===t(this,pe,"f")}read(){switch(t(this,pe,"f")){case"pending":throw t(this,ue,"f");case"error":throw t(this,fe,"f");default:return t(this,he,"f")}}then(e,n){return t(this,ue,"f").then(e,n)}catch(e){return t(this,ue,"f").catch(e)}finally(e){return t(this,ue,"f").finally(e)}}ue=new WeakMap,pe=new WeakMap,he=new WeakMap,fe=new WeakMap,ye=Symbol.toStringTag;class xe{constructor(){me.set(this,void 0),n(this,me,"undefined"!=typeof localStorage?localStorage:new Se,"f")}clear(){t(this,me,"f").clear()}getString(e){return t(this,me,"f").getItem(e)||void 0}setString(e,n){n?t(this,me,"f").setItem(e,n):t(this,me,"f").removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?D(t):void 0)}}me=new WeakMap;class Se{constructor(){ge.set(this,void 0),n(this,ge,new Map,"f")}get length(){return t(this,ge,"f").size}clear(){t(this,ge,"f").clear()}getItem(e){return t(this,ge,"f").get(e)??null}setItem(e,n){n?t(this,ge,"f").set(e,n):t(this,ge,"f").delete(e)}removeItem(e){t(this,ge,"f").delete(e)}key(e){return Array.from(t(this,ge,"f").keys())[e]}}ge=new WeakMap;var we,Ee={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 Te(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("."),o=Pe(r);let s=Oe.types[o];s||(Oe.types[o]=s={});s.parentType=s.parentType||Pe(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((e=>function(e){const t=e.path,n=t.split(".");if(1===n.length)return;const i=Pe(n.slice(0,n.length-1)),r=Oe.types[i];if(!r)return;const o=n[n.length-1];r.properties[o]=e}(e))))}function be(e){if(e.base)for(const t of e.base){const n=Oe.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 Pe(e){return 1===e.length?e[0]:e.map(L).join("")}function De(e){return"http://hl7.org/fhir/StructureDefinition/DomainResource"===e.structureDefinition?.baseDefinition}e.PropertyType=void 0,(we=e.PropertyType||(e.PropertyType={})).Address="Address",we.Age="Age",we.Annotation="Annotation",we.Attachment="Attachment",we.BackboneElement="BackboneElement",we.CodeableConcept="CodeableConcept",we.Coding="Coding",we.ContactDetail="ContactDetail",we.ContactPoint="ContactPoint",we.Contributor="Contributor",we.Count="Count",we.DataRequirement="DataRequirement",we.Distance="Distance",we.Dosage="Dosage",we.Duration="Duration",we.Expression="Expression",we.Extension="Extension",we.HumanName="HumanName",we.Identifier="Identifier",we.MarketingStatus="MarketingStatus",we.Meta="Meta",we.Money="Money",we.Narrative="Narrative",we.ParameterDefinition="ParameterDefinition",we.Period="Period",we.Population="Population",we.ProdCharacteristic="ProdCharacteristic",we.ProductShelfLife="ProductShelfLife",we.Quantity="Quantity",we.Range="Range",we.Ratio="Ratio",we.Reference="Reference",we.RelatedArtifact="RelatedArtifact",we.SampledData="SampledData",we.Signature="Signature",we.SubstanceAmount="SubstanceAmount",we.SystemString="http://hl7.org/fhirpath/System.String",we.Timing="Timing",we.TriggerDefinition="TriggerDefinition",we.UsageContext="UsageContext",we.base64Binary="base64Binary",we.boolean="boolean",we.canonical="canonical",we.code="code",we.date="date",we.dateTime="dateTime",we.decimal="decimal",we.id="id",we.instant="instant",we.integer="integer",we.markdown="markdown",we.oid="oid",we.positiveInt="positiveInt",we.string="string",we.time="time",we.unsignedInt="unsignedInt",we.uri="uri",we.url="url",we.uuid="uuid";const Ae=new Set(["ID","PKCE","JWKS","URI","URL"]);function Ce(e){const t=e.toUpperCase();return Ae.has(t)?t:t.charAt(0)+e.slice(1)}function Re(e,t){const n=Oe.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 Re(Pe(e),t)}return i}}const Oe=Ee;var ke,Ie,Me,Ue,Le,_e,Ne,je,Qe,We,Be,qe,$e,Fe,He,ze,Ge,Ve,Xe,Je,Ye,Ke,Ze,et,tt,nt,it,rt,ot,st,at,ct,dt,lt,ut,pt,ht,ft,yt,mt,gt;const vt={resourceType:"Device",id:"system",deviceName:[{name:"System"}]};function xt(){return"undefined"==typeof window?void 0:window}function St(){const e=xt();return e?e.location.protocol+"//"+e.location.host+"/":""}var wt,Et,Tt,bt,Pt,Dt,At,Ct,Rt,Ot,kt,It,Mt,Ut,Lt,_t,Nt,jt,Qt,Wt,Bt,qt,$t,Ft,Ht,zt,Gt,Vt,Xt,Jt,Yt,Kt;Ie=new WeakMap,Me=new WeakMap,Ue=new WeakMap,Le=new WeakMap,_e=new WeakMap,Ne=new WeakMap,je=new WeakMap,Qe=new WeakMap,We=new WeakMap,Be=new WeakMap,qe=new WeakMap,$e=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,ke=new WeakSet,et=function(e){const n=this.getLogins().filter((t=>t.profile?.reference!==e.profile?.reference));n.push(e),t(this,Ue,"f").setObject("logins",n)},tt=async function(){return n(this,Ye,new Promise(((e,i)=>{this.get("auth/me").then((i=>{n(this,Ye,void 0,"f"),n(this,Ke,i.profile,"f"),n(this,Ze,i.config,"f"),this.dispatchEvent({type:"change"}),e(t(this,Ke,"f"))})).catch(i)})),"f"),t(this,Ye,"f")},nt=function(e,n){if(t(this,_e,"f")<=0||"no-cache"===n?.cache||"reload"===n?.cache)return;const i=t(this,Le,"f").get(e);return!i||i.requestTime+t(this,_e,"f")<Date.now()?void 0:i},it=function(e,n){t(this,_e,"f")>0&&t(this,Le,"f").set(e,{requestTime:Date.now(),value:n})},rt=function(e){e?.id&&t(this,ke,"m",it).call(this,this.fhirUrl(e.resourceType,e.id).toString(),new ve(Promise.resolve(e)))},ot=function(e){t(this,_e,"f")>0&&t(this,Le,"f").delete(e)},st=async function(e,n,i={}){t(this,Je,"f")&&await t(this,Je,"f"),n.startsWith("http")||(n=t(this,Ne,"f")+n),i.method=e,t(this,ke,"m",dt).call(this,i);const r=await t(this,ke,"m",at).call(this,n,i);if(401===r.status)return t(this,ke,"m",pt).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 o;return o},at=async function(e,n){let i;for(let r=0;r<3;r++){if(i=await t(this,Ie,"f").call(this,e,n),i.status<500)return i;await new Promise((e=>setTimeout(e,200)))}return i},ct=async function(){const e=[...t(this,Fe,"f")];if(t(this,Fe,"f").length=0,n(this,Ge,void 0,"f"),1===e.length){const n=e[0];return void n.resolve(await t(this,ke,"m",st).call(this,n.method,t(this,je,"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&&!de(i.response.outcome)?n.reject(i.response.outcome):n.resolve(i?.resource)}},dt=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,Ve,"f")&&(n.Authorization="Bearer "+t(this,Ve,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},lt=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},ut=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))},pt=function(e,n,i){return t(this,ke,"m",ft).call(this)?t(this,ke,"m",st).call(this,e,n,i):(this.clearActiveLogin(),t(this,qe,"f")&&t(this,qe,"f").call(this),Promise.reject(new Error("Unauthenticated")))},ht=async function(e){const n=await this.ensureCodeChallenge(e||{}),i=new URL(t(this,Qe,"f"));i.searchParams.set("response_type","code"),i.searchParams.set("state",sessionStorage.getItem("pkceState")),i.searchParams.set("client_id",n.clientId||t(this,He,"f")),i.searchParams.set("redirect_uri",n.redirectUri||St()),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())},ft=function(){if(t(this,Je,"f"))return t(this,Je,"f");if(t(this,Xe,"f")){const e=new URLSearchParams;return e.set("grant_type","refresh_token"),e.set("client_id",t(this,He,"f")),e.set("refresh_token",t(this,Xe,"f")),n(this,Je,t(this,ke,"m",yt).call(this,e),"f"),t(this,Je,"f")}return t(this,He,"f")&&t(this,ze,"f")?(n(this,Je,this.startClientLogin(t(this,He,"f"),t(this,ze,"f")),"f"),t(this,Je,"f")):void 0},yt=async function(e){const n=await t(this,Ie,"f").call(this,t(this,We,"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,ke,"m",mt).call(this,i),this.getProfile()},mt=async function(e){const n=e.access_token,i=H(n);if(Date.now()>=1e3*i.exp)throw this.clearActiveLogin(),new Error("Token expired");if(t(this,He,"f")&&i.client_id!==t(this,He,"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})},gt=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class Zt{constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}}class en{constructor(e,t,n){this.operator=e,this.left=t,this.right=n}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class tn{constructor(){wt.set(this,{}),Et.set(this,{})}registerInfix(e,n){return t(this,Et,"f")[e]=n,this}registerPrefix(e,n){return t(this,wt,"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 nn(e,t(this,wt,"f"),t(this,Et,"f"))}}wt=new WeakMap,Et=new WeakMap;class nn{constructor(e,t,i){Tt.set(this,void 0),bt.set(this,void 0),Pt.set(this,void 0),n(this,Tt,e,"f"),n(this,bt,t,"f"),n(this,Pt,i,"f")}hasMore(){return t(this,Tt,"f").length>0}match(e){return this.peek()?.id===e&&(this.consume(),!0)}consumeAndParse(e=1/0){const n=this.consume(),i=t(this,bt,"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,Tt,"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,Tt,"f").shift()}peek(){return t(this,Tt,"f").length>0?t(this,Tt,"f")[0]:void 0}removeComments(){n(this,Tt,t(this,Tt,"f").filter((e=>"Comment"!==e.id)),"f")}getInfixParselet(e){return t(this,Pt,"f")["Symbol"===e.id?e.value:e.id]}}Tt=new WeakMap,bt=new WeakMap,Pt=new WeakMap;const rn=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"];class on{constructor(e,t,i){Dt.add(this),At.set(this,void 0),Ct.set(this,void 0),Rt.set(this,void 0),Ot.set(this,[]),kt.set(this,{index:0,line:1,column:0}),It.set(this,[]),n(this,At,e,"f"),n(this,Ct,t,"f"),n(this,Rt,i,"f")}tokenize(){for(;t(this,kt,"f").index<t(this,At,"f").length;){const e=t(this,Dt,"m",Lt).call(this);e&&t(this,Ot,"f").push(e)}return t(this,Ot,"f")}}function sn(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 an(t){return[{type:e.PropertyType.boolean,value:t}]}function cn(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}:wn(t)?{type:e.PropertyType.Quantity,value:t}:"object"==typeof t&&"resourceType"in t?{type:t.resourceType,value:t}:{type:e.PropertyType.BackboneElement,value:t}}function dn(e){return 0!==e.length&&!!e[0].value}function ln(t,n){if(!t?.value)return;const i=Re(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]","")+L(n.code);if(i in e.value){r=e.value[i],o=n.code;break}}if(C(r))return;"Element"!==o&&"BackboneElement"!==o||(o=Pe(n.path?.split(".")));return Array.isArray(r)?r.map((e=>un(e,o))):un(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+L(t);if(e in i){r=i[e];break}}if(C(r))return;return Array.isArray(r)?r.map(cn):cn(r)}(t,n)}function un(e,t){return"Resource"===t&&"object"==typeof e&&"resourceType"in e&&(t=e.resourceType),{type:t,value:e}}function pn(e){const t=[];for(const n of e){let e=!1;for(const i of t)if(dn(yn(n,i))){e=!0;break}e||t.push(n)}return t}function hn(e){return an(!dn(e))}function fn(e,t){return 0===e.length||0===t.length?[]:e.length!==t.length?an(!1):an(e.every(((e,n)=>dn(yn(e,t[n])))))}function yn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?an(Math.abs(n-i)<1e-8):wn(n)&&wn(i)?an(En(n,i)):an("object"==typeof n&&"object"==typeof i?Tn(e,t):n===i)}function mn(e,t){return 0===e.length&&0===t.length?an(!0):e.length!==t.length?an(!1):(e.sort(vn),t.sort(vn),an(e.every(((e,n)=>dn(gn(e,t[n]))))))}function gn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?an(Math.abs(n-i)<.01):wn(n)&&wn(i)?an(En(n,i)):an("object"==typeof n&&"object"==typeof i?Tn(n,i):"string"==typeof n&&"string"==typeof i?n.toLowerCase()===i.toLowerCase():n===i)}function vn(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 xn(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 Sn(n);case"Quantity":return wn(n);default:return"object"==typeof n&&n?.resourceType===t}}function Sn(e){return!(!e||"object"!=typeof e||!("start"in e))}function wn(e){return!(!e||"object"!=typeof e||!("value"in e)||"number"!=typeof e.value)}function En(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 Tn(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(bn(n)&&bn(r)){if(!Tn(n,r))return!1}else if(n!==r)return!1}return!0}function bn(e){return null!==e&&"object"==typeof e}At=new WeakMap,Ct=new WeakMap,Rt=new WeakMap,Ot=new WeakMap,kt=new WeakMap,It=new WeakMap,Dt=new WeakSet,Mt=function(){return t(this,Ot,"f").slice(-1)[0]},Ut=function(){t(this,Dt,"m",Xt).call(this);const e=t(this,Dt,"m",Lt).call(this);return t(this,Dt,"m",Jt).call(this),e},Lt=function(){t(this,Dt,"m",_t).call(this);const e=t(this,Dt,"m",zt).call(this);if(!e)return;t(this,Dt,"m",Xt).call(this);const n=t(this,Dt,"m",Vt).call(this);return"/"===e&&"*"===n?t(this,Dt,"m",Nt).call(this):"/"===e&&"/"===n?t(this,Dt,"m",jt).call(this):"'"===e||'"'===e?t(this,Dt,"m",Qt).call(this,e):"`"===e?t(this,Dt,"m",Wt).call(this):"@"===e?t(this,Dt,"m",Bt).call(this):e.match(/\d/)?t(this,Dt,"m",qt).call(this):e.match(/\w/)||"$"===e&&n.match(/\w/)?t(this,Dt,"m",$t).call(this):t(this,Dt,"m",Ft).call(this)},_t=function(){t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/\s/)))},Nt=function(){const e=t(this,kt,"f").index;return t(this,Dt,"m",Ht).call(this,(()=>"*"!==t(this,Dt,"m",zt).call(this)||"/"!==t(this,Dt,"m",Vt).call(this))),t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Kt).call(this,"Comment",t(this,At,"f").substring(e,t(this,kt,"f").index))},jt=function(){return t(this,Dt,"m",Kt).call(this,"Comment",t(this,Dt,"m",Ht).call(this,(()=>"\n"!==t(this,Dt,"m",zt).call(this))))},Qt=function(e){t(this,Dt,"m",Yt).call(this);const n=t(this,Dt,"m",Kt).call(this,"String",t(this,Dt,"m",Ht).call(this,(()=>"\\"===t(this,Dt,"m",Gt).call(this)||t(this,Dt,"m",zt).call(this)!==e)));return t(this,Dt,"m",Yt).call(this),n},Wt=function(){t(this,Dt,"m",Yt).call(this);const e=t(this,Dt,"m",Kt).call(this,"Symbol",t(this,Dt,"m",Ht).call(this,(()=>"`"!==t(this,Dt,"m",zt).call(this))));return t(this,Dt,"m",Yt).call(this),e},Bt=function(){t(this,Dt,"m",Yt).call(this);const e=t(this,kt,"f").index;return t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/[\d-]/))),"T"===t(this,Dt,"m",zt).call(this)&&(t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/[\d:]/))),"."===t(this,Dt,"m",zt).call(this)&&t(this,Dt,"m",Vt).call(this).match(/\d/)&&(t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/\d/)))),"Z"===t(this,Dt,"m",zt).call(this)?t(this,Dt,"m",Yt).call(this):"+"!==t(this,Dt,"m",zt).call(this)&&"-"!==t(this,Dt,"m",zt).call(this)||(t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/[\d:]/))))),t(this,Dt,"m",Kt).call(this,"DateTime",t(this,At,"f").substring(e,t(this,kt,"f").index))},qt=function(){const e=t(this,kt,"f").index;let n="Number";return t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/\d/))),"."===t(this,Dt,"m",zt).call(this)&&t(this,Dt,"m",Vt).call(this).match(/\d/)&&(t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/\d/))))," "===t(this,Dt,"m",zt).call(this)&&function(e){if(e){if("String"===e.id)return!0;if("Symbol"===e.id&&rn.includes(e.value))return!0}return!1}(t(this,Dt,"m",Ut).call(this))&&(n="Quantity",t(this,Dt,"m",Lt).call(this)),t(this,Dt,"m",Kt).call(this,n,t(this,At,"f").substring(e,t(this,kt,"f").index))},$t=function(){const e=t(this,Dt,"m",Ht).call(this,(()=>t(this,Dt,"m",zt).call(this).match(/[$\w]/)));return"."!==t(this,Dt,"m",Mt).call(this)?.value&&t(this,Ct,"f").includes(e)?t(this,Dt,"m",Kt).call(this,e,e):t(this,Dt,"m",Kt).call(this,"Symbol",e)},Ft=function(){const e=t(this,Dt,"m",zt).call(this),n=e+t(this,Dt,"m",Vt).call(this);return t(this,Rt,"f").includes(n)?(t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Kt).call(this,n,n)):(t(this,Dt,"m",Yt).call(this),t(this,Dt,"m",Kt).call(this,e,e))},Ht=function(e){const n=t(this,kt,"f").index;for(;t(this,kt,"f").index<t(this,At,"f").length&&e();)t(this,Dt,"m",Yt).call(this);return t(this,At,"f").substring(n,t(this,kt,"f").index)},zt=function(){return t(this,At,"f")[t(this,kt,"f").index]},Gt=function(){return t(this,At,"f")[t(this,kt,"f").index-1]??""},Vt=function(){return t(this,At,"f")[t(this,kt,"f").index+1]??""},Xt=function(){t(this,It,"f").push({...t(this,kt,"f")})},Jt=function(){const e=t(this,It,"f").pop();if(!e)throw new Error("No mark to reset to");t(this,kt,"f").index=e.index,t(this,kt,"f").line=e.line,t(this,kt,"f").column=e.column},Yt=function(){t(this,kt,"f").index++,"\n"===t(this,Dt,"m",zt).call(this)?(t(this,kt,"f").line++,t(this,kt,"f").column=0):t(this,kt,"f").column++},Kt=function(e,n){const i=t(this,It,"f").pop();if(!i)throw new Error("No mark for token");return{id:e,value:n,...i}};const Pn=()=>[],Dn={empty:e=>an(0===e.length),exists:(e,t)=>an(t?e.filter((e=>dn(t.eval([e])))).length>0:e.length>0),all:(e,t)=>an(e.every((e=>dn(t.eval([e]))))),allTrue:e=>{for(const t of e)if(!t.value)return an(!1);return an(!0)},anyTrue:e=>{for(const t of e)if(t.value)return an(!0);return an(!1)},allFalse:e=>{for(const t of e)if(t.value)return an(!1);return an(!0)},anyFalse:e=>{for(const t of e)if(!t.value)return an(!0);return an(!1)},subsetOf:Pn,supersetOf:Pn,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=>an(e.length===Dn.distinct(e).length),where:(e,t)=>e.filter((e=>dn(t.eval([e])))),select:(e,t)=>e.map((e=>t.eval([e]))).flat(),repeat:Pn,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 pn([...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 dn(r)?n.eval(e):i?i.eval(e):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:n}]=Rn(t,1);if("boolean"==typeof n)return[{type:e.PropertyType.boolean,value:n}];if("number"==typeof n&&(0===n||1===n))return an(!!n);if("string"==typeof n){const e=n.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(e))return an(!0);if(["false","f","no","n","0","0.0"].includes(e))return an(!1)}return[]},convertsToBoolean:e=>0===e.length?[]:an(1===Dn.toBoolean(e).length),toInteger:t=>{if(0===t.length)return[];const[{value:n}]=Rn(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?[]:an(1===Dn.toInteger(e).length),toDate:t=>{if(0===t.length)return[];const[{value:n}]=Rn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.date,value:sn(n)}]:[]},convertsToDate:e=>0===e.length?[]:an(1===Dn.toDate(e).length),toDateTime:t=>{if(0===t.length)return[];const[{value:n}]=Rn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.dateTime,value:sn(n)}]:[]},convertsToDateTime:e=>0===e.length?[]:an(1===Dn.toDateTime(e).length),toDecimal:t=>{if(0===t.length)return[];const[{value:n}]=Rn(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?[]:an(1===Dn.toDecimal(e).length),toQuantity:t=>{if(0===t.length)return[];const[{value:n}]=Rn(t,1);return wn(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?[]:an(1===Dn.toQuantity(e).length),toString:t=>{if(0===t.length)return[];const[{value:n}]=Rn(t,1);return null==n?[]:wn(n)?[{type:e.PropertyType.string,value:`${n.value} '${n.unit}'`}]:[{type:e.PropertyType.string,value:n.toString()}]},convertsToString:e=>0===e.length?[]:an(1===Dn.toString(e).length),toTime:t=>{if(0===t.length)return[];const[{value:n}]=Rn(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:sn("T"+t[1])}]}return[]},convertsToTime:e=>0===e.length?[]:an(1===Dn.toTime(e).length),indexOf:(e,t)=>An(((e,t)=>e.indexOf(t)),e,t),substring:(e,t,n)=>An(((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)=>An(((e,t)=>e.startsWith(t)),e,t),endsWith:(e,t)=>An(((e,t)=>e.endsWith(t)),e,t),contains:(e,t)=>An(((e,t)=>e.includes(t)),e,t),upper:e=>An((e=>e.toUpperCase()),e),lower:e=>An((e=>e.toLowerCase()),e),replace:(e,t,n)=>An(((e,t,n)=>e.replaceAll(t,n)),e,t,n),matches:(e,t)=>An(((e,t)=>!!e.match(t)),e,t),replaceMatches:(e,t,n)=>An(((e,t,n)=>e.replaceAll(t,n)),e,t,n),length:e=>An((e=>e.length),e),toChars:e=>An((e=>e?e.split(""):void 0),e),abs:e=>Cn(Math.abs,e),ceiling:e=>Cn(Math.ceil,e),exp:e=>Cn(Math.exp,e),floor:e=>Cn(Math.floor,e),ln:e=>Cn(Math.log,e),log:(e,t)=>Cn(((e,t)=>Math.log(e)/Math.log(t)),e,t),power:(e,t)=>Cn(Math.pow,e,t),round:e=>Cn(Math.round,e),sqrt:e=>Cn(Math.sqrt,e),truncate:e=>Cn((e=>0|e),e),children:Pn,descendants:Pn,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=Dn.toDateTime(n.eval(t));if(0===o.length)throw new Error("Invalid start date");const s=Dn.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=b(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 Un?i=n.name:n instanceof qn&&(i=n.left.name+"."+n.right.name),i?t.map((t=>({type:e.PropertyType.boolean,value:xn(t,i)}))):[]},not:t=>Dn.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 cn(e.resource);i=e.reference}if(!i)return{type:e.PropertyType.BackboneElement,value:null};const[r,o]=i.split("/");return{type:e.PropertyType.BackboneElement,value:{resourceType:r,id:o}}})).filter((e=>!!e.value)),as:e=>e,type:t=>t.map((({value:t})=>"boolean"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Integer"}}:t&&"object"==typeof t&&"resourceType"in 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 An(e,t,...n){if(0===t.length)return[];const[{value:i}]=Rn(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(cn):[cn(r)]}function Cn(t,n,...i){if(0===n.length)return[];const[{value:r}]=Rn(n,1),o=wn(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 Rn(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 On,kn;class In{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 Mn{constructor(e){this.value=e}eval(){return[this.value]}toString(){const e=this.value.value;return"string"==typeof e?`'${e}'`:e.toString()}}class Un{constructor(e){this.name=e,On.add(this)}eval(e){return"$this"===this.name?e:e.map((e=>t(this,On,"m",kn).call(this,e))).flat().filter((e=>void 0!==e?.value))}toString(){return this.name}}On=new WeakSet,kn=function(e){const t=e.value;if(t&&"object"==typeof t)return"resourceType"in t&&t.resourceType===this.name?e:ln(e,this.name)};class Ln{eval(){return[]}toString(){return"{}"}}class _n extends Zt{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 Nn extends en{constructor(e,t){super("as",e,t)}eval(e){return Dn.ofType(this.left.eval(e),this.right)}}class jn extends en{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=wn(r)?r.value:r,a=wn(o)?o.value:o,c=this.impl(s,a);return"boolean"==typeof c?an(c):wn(r)?[{type:e.PropertyType.Quantity,value:{...r,value:c}}]:[cn(c)]}}class Qn extends en{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 Wn extends en{constructor(e,t){super("contains",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);return an(t.some((e=>e.value===n[0].value)))}}class Bn extends en{constructor(e,t){super("in",e,t)}eval(e){const t=this.left.eval(e);return an(this.right.eval(e).some((e=>e.value===t[0].value)))}}class qn extends en{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 $n extends en{constructor(e,t){super("|",e,t)}eval(e){return pn([...this.left.eval(e),...this.right.eval(e)])}}class Fn extends en{constructor(e,t){super("=",e,t)}eval(e){return fn(this.left.eval(e),this.right.eval(e))}}class Hn extends en{constructor(e,t){super("!=",e,t)}eval(e){return hn(fn(this.left.eval(e),this.right.eval(e)))}}class zn extends en{constructor(e,t){super("~",e,t)}eval(e){return mn(this.left.eval(e),this.right.eval(e))}}class Gn extends en{constructor(e,t){super("!~",e,t)}eval(e){return hn(mn(this.left.eval(e),this.right.eval(e)))}}class Vn extends en{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 an(xn(t[0],n))}}class Xn extends en{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?an(!0):!1===t[0]?.value||!1===n[0]?.value?an(!1):[]}}class Jn extends en{constructor(e,t){super("or",e,t)}eval(e){const t=this.left.eval(e);if(dn(t))return t;const n=this.right.eval(e);return dn(n)?n:[]}}class Yn extends en{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?an(!0):!0===i&&!0===r||!1===i&&!1===r?an(!1):[]}}class Kn{constructor(e,t){this.name=e,this.args=t}eval(e){const t=Dn[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 Zn{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 ei=["true","false"],ti=["!=","!~","<=",">=","{}","->"];function ni(e){return new on(e,ei,ti).tokenize()}const ii={parse(e){const t=e.consumeAndParse();if(!e.match(")"))throw new Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},ri={parse(e,t){const n=e.consumeAndParse();if(!e.match("]"))throw new Error("Parse error: expected `]`");return new Zn(t,n)},precedence:2},oi={parse(e,t){if(!(t instanceof Un))throw new Error("Unexpected parentheses");const n=[];for(;!e.match(")");)n.push(e.consumeAndParse()),e.match(",");return new Kn(t.name,n)},precedence:0};function si(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 ai(){return(new tn).registerPrefix("String",{parse:(t,n)=>new Mn({type:e.PropertyType.string,value:n.value})}).registerPrefix("DateTime",{parse:(t,n)=>new Mn({type:e.PropertyType.dateTime,value:sn(n.value)})}).registerPrefix("Quantity",{parse:(t,n)=>new Mn({type:e.PropertyType.Quantity,value:si(n.value)})}).registerPrefix("Number",{parse:(t,n)=>new Mn({type:e.PropertyType.decimal,value:parseFloat(n.value)})}).registerPrefix("true",{parse:()=>new Mn({type:e.PropertyType.boolean,value:!0})}).registerPrefix("false",{parse:()=>new Mn({type:e.PropertyType.boolean,value:!1})}).registerPrefix("Symbol",{parse:(e,t)=>new Un(t.value)}).registerPrefix("{}",{parse:()=>new Ln}).registerPrefix("(",ii).registerInfix("[",ri).registerInfix("(",oi).prefix("+",3,((e,t)=>new _n("+",t,(e=>e)))).prefix("-",3,((e,t)=>new jn("-",t,t,((e,t)=>-t)))).infixLeft(".",1,((e,t,n)=>new qn(e,n))).infixLeft("/",4,((e,t,n)=>new jn("/",e,n,((e,t)=>e/t)))).infixLeft("*",4,((e,t,n)=>new jn("*",e,n,((e,t)=>e*t)))).infixLeft("+",5,((e,t,n)=>new jn("+",e,n,((e,t)=>e+t)))).infixLeft("-",5,((e,t,n)=>new jn("-",e,n,((e,t)=>e-t)))).infixLeft("|",7,((e,t,n)=>new $n(e,n))).infixLeft("=",9,((e,t,n)=>new Fn(e,n))).infixLeft("!=",9,((e,t,n)=>new Hn(e,n))).infixLeft("~",9,((e,t,n)=>new zn(e,n))).infixLeft("!~",9,((e,t,n)=>new Gn(e,n))).infixLeft("<",8,((e,t,n)=>new jn("<",e,n,((e,t)=>e<t)))).infixLeft("<=",8,((e,t,n)=>new jn("<=",e,n,((e,t)=>e<=t)))).infixLeft(">",8,((e,t,n)=>new jn(">",e,n,((e,t)=>e>t)))).infixLeft(">=",8,((e,t,n)=>new jn(">=",e,n,((e,t)=>e>=t)))).infixLeft("&",5,((e,t,n)=>new Qn(e,n))).infixLeft("and",6,((e,t,n)=>new Xn(e,n))).infixLeft("as",6,((e,t,n)=>new Nn(e,n))).infixLeft("contains",6,((e,t,n)=>new Wn(e,n))).infixLeft("div",6,((e,t,n)=>new jn("div",e,n,((e,t)=>e/t|0)))).infixLeft("in",6,((e,t,n)=>new Bn(e,n))).infixLeft("is",6,((e,t,n)=>new Vn(e,n))).infixLeft("mod",6,((e,t,n)=>new jn("mod",e,n,((e,t)=>e%t)))).infixLeft("or",6,((e,t,n)=>new Jn(e,n))).infixLeft("xor",6,((e,t,n)=>new Yn(e,n)))}const ci=ai();function di(e){return new In(e,ci.construct(ni(e)).consumeAndParse())}function li(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]=cn(n[e]))}return ui(e,n).map((e=>e.value))}function ui(e,t){return di(e).eval(t)}class pi{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 hi{constructor(e,t=new pi){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 hi([new fi(["MSH",this.context.getMsh2(),r,o,n,i,e.toISOString(),"","ACK",e.getTime().toString(),"P",a],this.context),new fi(["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 pi("\r",e.charAt(3),e.charAt(4),e.charAt(5),e.charAt(6),e.charAt(7));return new hi(e.split(/[\r\n]+/).map((e=>fi.parse(e,t))),t)}}class fi{constructor(e,t=new pi){this.context=t,k(e)?this.fields=e.map((e=>yi.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 pi){return new fi(e.split(t.fieldSeparator).map((e=>yi.parse(e,t))),t)}}class yi{constructor(e,t=new pi){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 pi){return new yi(e.split(t.repetitionSeparator).map((e=>e.split(t.componentSeparator))),t)}}var mi;function gi(t,n){let i=Oe.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?L(t):t)),"")}(i),o=Si(t,n.expression)?.split(".");if(!o)return{columnName:r,type:e.SearchParameterType.TEXT};const s=xi(n);let a,c,d=t,l=!1;for(let e=1;e<o.length;e++){if(a=Re(d,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&&(d=vi(c)?Pe(a.path?.split(".")):c)}const u=xi(n,c),p={columnName:r,type:u,elementDefinition:a,array:l};return function(e,t,n){const i=Oe.types[e];i.searchParamsDetails||(i.searchParamsDetails={});i.searchParamsDetails[t]=n}(t,i,p),p}(t,n)),i}function vi(e){return"Element"===e||"BackboneElement"===e}function xi(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 Si(e,t){const n=t.split(" | ");for(const t of n){if((i=t).includes(" as Period")||i.includes(" as SampledDate"))continue;const n=wi(t);if(n.startsWith(e+"."))return n}var i}function wi(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(",".where("];for(const e of n)t.includes(e)&&(t=t.substring(0,t.indexOf(e)));return t}e.SearchParameterType=void 0,(mi=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",mi.NUMBER="NUMBER",mi.QUANTITY="QUANTITY",mi.TEXT="TEXT",mi.REFERENCE="REFERENCE",mi.DATE="DATE",mi.DATETIME="DATETIME",mi.PERIOD="PERIOD";var Ei;e.Operator=void 0,(Ei=e.Operator||(e.Operator={})).EQUALS="eq",Ei.NOT_EQUALS="ne",Ei.GREATER_THAN="gt",Ei.LESS_THAN="lt",Ei.GREATER_THAN_OR_EQUALS="ge",Ei.LESS_THAN_OR_EQUALS="le",Ei.STARTS_AFTER="sa",Ei.ENDS_BEFORE="eb",Ei.APPROXIMATELY="ap",Ei.CONTAINS="contains",Ei.EXACT="exact",Ei.TEXT="text",Ei.NOT="not",Ei.ABOVE="above",Ei.BELOW="below",Ei.IN="in",Ei.NOT_IN="not-in",Ei.OF_TYPE="of-type",Ei.MISSING="missing";const Ti=[e.Operator.CONTAINS,e.Operator.EXACT,e.Operator.TEXT,e.Operator.NOT,e.Operator.ABOVE,e.Operator.BELOW,e.Operator.IN,e.Operator.NOT_IN,e.Operator.OF_TYPE,e.Operator.MISSING],bi=[e.Operator.NOT_EQUALS,e.Operator.GREATER_THAN,e.Operator.LESS_THAN,e.Operator.GREATER_THAN_OR_EQUALS,e.Operator.LESS_THAN_OR_EQUALS,e.Operator.STARTS_AFTER,e.Operator.ENDS_BEFORE,e.Operator.APPROXIMATELY];function Pi(t,n,i){const r=Oe.types[n.resourceType]?.searchParams?.[i.code];switch(r?.type){case"reference":return function(t,n,i){const r=li(i.expression,t),o=Ri(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 Di(t,i,r);case"token":return function(t,n,i){const r=gi(t.resourceType,i);return r.type===e.SearchParameterType.BOOLEAN?function(e,t,n){const i=li(n.expression,e),r="true"===t.value,o=i.includes(r);return Ri(t.operator)?!o:o}(t,n,i):Di(t,n,i)}(t,i,r);case"date":return function(e,t,n){const i=li(n.expression,e),r=t.value.split(","),o=Ri(t.operator);for(const e of i)for(const n of r){if(Ci(e,t.operator,n))return!o}return o}(t,i,r)}return!1}function Di(e,t,n){const i=li(n.expression,e),r=t.value.split(","),o=Ri(t.operator);for(const e of i)for(const n of r){if(Ai(e,t.operator,n))return!o}return o}function Ai(e,t,n){let i="";return e&&("string"==typeof e?i=e:"object"==typeof e&&(i=JSON.stringify(e))),i.toLowerCase().includes(n.toLowerCase())}function Ci(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 Ri(t){return t===e.Operator.NOT_EQUALS||t===e.Operator.NOT}var Oi,ki,Ii,Mi,Ui,Li,_i,Ni,ji;const Qi={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},Wi={contains:e.Operator.CONTAINS,exact:e.Operator.EXACT,above:e.Operator.ABOVE,below:e.Operator.BELOW,text:e.Operator.TEXT,not:e.Operator.NOT,in:e.Operator.IN,"not-in":e.Operator.NOT_IN,"of-type":e.Operator.OF_TYPE};class Bi{constructor(e,n){Oi.add(this),this.resourceType=e,this.filters=[],this.sortRules=[];for(const[e,i]of Object.entries(n))Array.isArray(i)?i.forEach((n=>t(this,Oi,"m",ki).call(this,e,n))):t(this,Oi,"m",ki).call(this,e,i??"")}}function qi(t){const n=t.substring(0,2);return n in Qi?{operator:Qi[n],value:t.substring(2)}:{operator:e.Operator.EQUALS,value:t}}function $i(t){return Wi[t]||e.Operator.EQUALS}Oi=new WeakSet,ki=function(e,n){let i,r;const o=e.indexOf(":");switch(o>=0?(i=e.substring(0,o),r=e.substring(o+1)):(i=e,r=""),i){case"_sort":t(this,Oi,"m",Ii).call(this,n);break;case"_count":this.count=parseInt(n);break;case"_offset":this.offset=parseInt(n);break;case"_total":this.total=n;break;case"_summary":this.total="estimate",this.count=0;break;case"_revinclude":this.revInclude=n;break;default:{const e=Oe.types[this.resourceType]?.searchParams?.[i];e?t(this,Oi,"m",Mi).call(this,e,r,n):t(this,Oi,"m",ji).call(this,i,r,n)}}},Ii=function(e){for(const t of e.split(",")){let e,n=!1;t.startsWith("-")?(e=t.substring(1),n=!0):e=t,this.sortRules.push({code:e,descending:n})}},Mi=function(n,i,r){if("missing"!==i)switch(n.type){case"number":case"date":t(this,Oi,"m",Ui).call(this,n,r);break;case"string":case"token":case"uri":t(this,Oi,"m",Li).call(this,n,i,r);break;case"reference":t(this,Oi,"m",_i).call(this,n,r);break;case"quantity":t(this,Oi,"m",Ni).call(this,n,r)}else this.filters.push({code:n.code,operator:e.Operator.MISSING,value:r})},Ui=function(e,t){const{operator:n,value:i}=qi(t);this.filters.push({code:e.code,operator:n,value:i})},Li=function(e,t,n){this.filters.push({code:e.code,operator:$i(t),value:n})},_i=function(t,n){this.filters.push({code:t.code,operator:e.Operator.EQUALS,value:n})},Ni=function(e,t){const[n,i,r]=t.split("|"),{operator:o,value:s}=qi(n);this.filters.push({code:e.code,operator:o,value:s,unitSystem:i,unitCode:r})},ji=function(t,n,i){let r=e.Operator.EQUALS;if(n)r=n;else for(const e of Object.keys(Qi))i.match(new RegExp("^"+e+"\\d"))&&(r=e,i=i.substring(e.length));this.filters.push({code:t,operator:r,value:i})},e.AndAtom=Xn,e.ArithemticOperatorAtom=jn,e.AsAtom=Nn,e.ConcatAtom=Qn,e.ContainsAtom=Wn,e.DEFAULT_SEARCH_COUNT=20,e.DotAtom=qn,e.EmptySetAtom=Ln,e.EqualsAtom=Fn,e.EquivalentAtom=zn,e.FHIRPATH_KEYWORDS=ei,e.FHIRPATH_OPERATORS=ti,e.FhirPathAtom=In,e.FunctionAtom=Kn,e.Hl7Context=pi,e.Hl7Field=yi,e.Hl7Message=hi,e.Hl7Segment=fi,e.InAtom=Bn,e.IndexerAtom=Zn,e.IsAtom=Vn,e.LRUCache=a,e.LiteralAtom=Mn,e.MEDPLUM_VERSION="2.0.4-c4747b4e",e.MedplumClient=class extends ${constructor(e){if(super(),ke.add(this),Ie.set(this,void 0),Me.set(this,void 0),Ue.set(this,void 0),Le.set(this,void 0),_e.set(this,void 0),Ne.set(this,void 0),je.set(this,void 0),Qe.set(this,void 0),We.set(this,void 0),Be.set(this,void 0),qe.set(this,void 0),$e.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),e?.baseUrl&&!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");n(this,Ie,e?.fetch||function(){const e=xt();if(!e)throw new Error("Fetch not available in this environment");return e.fetch.bind(e)}(),"f"),n(this,Me,e?.createPdf,"f"),n(this,Ue,new xe,"f"),n(this,Le,new a(e?.resourceCacheSize??1e3),"f"),n(this,_e,e?.cacheTime??6e4,"f"),n(this,Ne,function(e){if(!e)return e;return e.endsWith("/")?e:e+"/"}(e?.baseUrl)||"https://api.medplum.com/","f"),n(this,je,t(this,Ne,"f")+"fhir/R4/","f"),n(this,He,e?.clientId||"","f"),n(this,Qe,e?.authorizeUrl||t(this,Ne,"f")+"oauth2/authorize","f"),n(this,We,e?.tokenUrl||t(this,Ne,"f")+"oauth2/token","f"),n(this,Be,e?.logoutUrl||t(this,Ne,"f")+"oauth2/logout","f"),n(this,qe,e?.onUnauthenticated,"f"),n(this,$e,e?.autoBatchTime??0,"f"),n(this,Fe,[],"f");const i=this.getActiveLogin();i&&(n(this,Ve,i.accessToken,"f"),n(this,Xe,i.refreshToken,"f"),t(this,ke,"m",tt).call(this).catch(console.log)),t(this,ke,"m",gt).call(this)}getBaseUrl(){return t(this,Ne,"f")}clear(){t(this,Ue,"f").clear(),this.clearActiveLogin()}clearActiveLogin(){t(this,Ue,"f").setString("activeLogin",void 0),t(this,Le,"f").clear(),n(this,Ve,void 0,"f"),n(this,Xe,void 0,"f"),n(this,Ke,void 0,"f"),n(this,Ze,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(e){e=e.toString(),t(this,Le,"f").delete(e)}invalidateSearches(e){const n="fhir/R4/"+e;for(const e of t(this,Le,"f").keys())(e.endsWith(n)||e.includes(n+"?"))&&t(this,Le,"f").delete(e)}get(e,i={}){e=e.toString();const r=t(this,ke,"m",nt).call(this,e,i);if(r)return r.value;let o;o=e.startsWith(t(this,je,"f"))&&t(this,$e,"f")>0?new Promise(((r,o)=>{t(this,Fe,"f").push({method:"GET",url:e.replace(t(this,je,"f"),""),options:i,resolve:r,reject:o}),t(this,Ge,"f")||n(this,Ge,setTimeout((()=>t(this,ke,"m",ct).call(this)),t(this,$e,"f")),"f")})):t(this,ke,"m",st).call(this,"GET",e,i);const s=new ve(o);return t(this,ke,"m",it).call(this,e,s),s}post(e,n,i,r={}){return e=e.toString(),n&&t(this,ke,"m",ut).call(this,r,n),i&&t(this,ke,"m",lt).call(this,r,i),this.invalidateUrl(e),t(this,ke,"m",st).call(this,"POST",e,r)}put(e,n,i,r={}){return e=e.toString(),n&&t(this,ke,"m",ut).call(this,r,n),i&&t(this,ke,"m",lt).call(this,r,i),this.invalidateUrl(e),t(this,ke,"m",st).call(this,"PUT",e,r)}patch(e,n,i={}){return e=e.toString(),t(this,ke,"m",ut).call(this,i,n),t(this,ke,"m",lt).call(this,i,"application/json-patch+json"),this.invalidateUrl(e),t(this,ke,"m",st).call(this,"PATCH",e,i)}delete(e,n={}){return e=e.toString(),this.invalidateUrl(e),t(this,ke,"m",st).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,He,"f"),scope:e.scope})}async startGoogleLogin(e){return this.post("auth/google",{...await this.ensureCodeChallenge(e),clientId:e.clientId??t(this,He,"f"),scope:e.scope})}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(t(this,Be,"f"),{}),this.clear()}async signInWithRedirect(e){const n=new URLSearchParams(window.location.search).get("code");return n?this.processCode(n):void await t(this,ke,"m",ht).call(this,e)}signOutWithRedirect(){window.location.assign(t(this,Be,"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,je,"f")+e.join("/"))}fhirSearchUrl(e,t){const n=this.fhirUrl(e);return t&&(n.search=t.toString()),n}search(e,n,i={}){const r=this.fhirSearchUrl(e,n),o=r.toString()+"-search",s=t(this,ke,"m",nt).call(this,o,i);if(s)return s.value;const a=new ve((async()=>{const e=await this.get(r,i);if(e.entry)for(const n of e.entry)t(this,ke,"m",rt).call(this,n.resource);return e})());return t(this,ke,"m",it).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,ke,"m",nt).call(this,o,i);if(s)return s.value;const a=new ve(this.search(e,r.searchParams,i).then((e=>e.entry?.[0]?.resource)));return t(this,ke,"m",it).call(this,o,a),a}searchResources(e,n,i={}){const r=this.fhirSearchUrl(e,n).toString()+"-searchResources",o=t(this,ke,"m",nt).call(this,r,i);if(o)return o.value;const s=new ve(this.search(e,n,i).then((e=>e.entry?.map((e=>e.resource))??[])));return t(this,ke,"m",it).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,Le,"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 vt;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 ve(Promise.reject(new Error("Missing reference")));if("system"===n)return new ve(Promise.resolve(vt));const[i,r]=n.split("/");return i&&r?this.readResource(i,r,t):new ve(Promise.reject(new Error("Invalid reference")))}getSchema(){return Oe}requestSchema(e){if(e in Oe.types)return Promise.resolve(Oe);const n=e+"-requestSchema",i=t(this,ke,"m",nt).call(this,n,void 0);if(i)return i.value;const r=new ve((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)Te(e);for(const e of n.data.SearchParameterList)be(e);return Oe})());return t(this,ke,"m",it).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,Ve,"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,Me,"f"))throw new Error("PDF creation not enabled");const o=await t(this,Me,"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,ke,"m",rt).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,ke,"m",ot).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)}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,Ue,"f").getObject("activeLogin")}async setActiveLogin(e){this.clearActiveLogin(),n(this,Ve,e.accessToken,"f"),n(this,Xe,e.refreshToken,"f"),t(this,Ue,"f").setObject("activeLogin",e),t(this,ke,"m",et).call(this,e),n(this,Je,void 0,"f"),await t(this,ke,"m",tt).call(this)}getAccessToken(){return t(this,Ve,"f")}setAccessToken(e){n(this,Ve,e,"f"),n(this,Xe,void 0,"f"),n(this,Ke,void 0,"f"),n(this,Ze,void 0,"f")}getLogins(){return t(this,Ue,"f").getObject("logins")??[]}isLoading(){return!!t(this,Ye,"f")}getProfile(){return t(this,Ke,"f")}async getProfileAsync(){return t(this,Ye,"f")&&await t(this,Ye,"f"),this.getProfile()}getUserConfiguration(){return t(this,Ze,"f")}async download(e,n={}){t(this,Je,"f")&&await t(this,Je,"f"),t(this,ke,"m",dt).call(this,n);return(await t(this,Ie,"f").call(this,e.toString(),n)).blob()}async startPkce(){const e=B();sessionStorage.setItem("pkceState",e);const t=B();sessionStorage.setItem("codeVerifier",t);const n=U(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){const n=new URLSearchParams;if(n.set("grant_type","authorization_code"),n.set("client_id",t(this,He,"f")),n.set("code",e),n.set("redirect_uri",St()),"undefined"!=typeof sessionStorage){const e=sessionStorage.getItem("codeVerifier");e&&n.set("code_verifier",e)}return t(this,ke,"m",yt).call(this,n)}async startClientLogin(e,i){n(this,He,e,"f"),n(this,ze,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,ke,"m",yt).call(this,r)}},e.NotEqualsAtom=Hn,e.NotEquivalentAtom=Gn,e.OperationOutcomeError=le,e.OrAtom=Jn,e.ReadablePromise=ve,e.SymbolAtom=Un,e.UnaryOperatorAtom=_n,e.UnionAtom=$n,e.XorAtom=Yn,e.allOk=ee,e.arrayBufferToBase64=U,e.arrayBufferToHex=M,e.assertOk=function(e,t){if(!de(e)||void 0===t)throw new le(e)},e.badRequest=function(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}},e.booleanToTypedValue=an,e.buildTypeName=Pe,e.calculateAge=b,e.calculateAgeString=function(e,t){const{years:n,months:i,days:r}=b(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=L,e.createReference=x,e.created=te,e.deepClone=function(e){return JSON.parse(JSON.stringify(e))},e.deepEquals=R,e.evalFhirPath=li,e.evalFhirPathTyped=ui,e.fhirPathArrayEquals=fn,e.fhirPathArrayEquivalent=mn,e.fhirPathEquals=yn,e.fhirPathEquivalent=gn,e.fhirPathIs=xn,e.fhirPathNot=hn,e.findObservationInterval=function(e,t,n,i){return e.qualifiedInterval?.find((r=>_(r,t)&&function(e,t,n){return!!e.range&&N(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=>_(e,t)&&n.includes(e.condition)))},e.forbidden=oe,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=m,e.formatCoding=g,e.formatDate=function(e,t,n){if(!e)return"";const i=new Date(e);return d(i)?(i.setUTCHours(0,0,0,0),i.toLocaleDateString(t,{timeZone:"UTC",...n})):""},e.formatDateTime=u,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?y(t.valueQuantity):t.valueCodeableConcept?m(t.valueCodeableConcept):t.valueString?t.valueString:"":""},e.formatPeriod=function(e,t,n){return e&&(e.start||e.end)?u(e.start,t,n)+" - "+u(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(v(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(v(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(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>t.push(function(e){const t=Ti.includes(e.operator)?":"+e.operator:"",n=bi.includes(e.operator)?e.operator:"";return`${e.code}${t}=${n}${encodeURIComponent(e.value)}`}(e)))),e.sortRules&&e.sortRules.length>0&&t.push("_sort="+e.sortRules.map((e=>e.descending?"-"+e.code:e.code)).join(",")),void 0!==e.offset&&t.push("_offset="+e.offset),void 0!==e.count&&t.push("_count="+e.count),void 0!==e.total&&t.push("_total="+e.total),0===t.length?"":(t.sort(),"?"+t.join("&"))},e.formatTime=l,e.formatTiming=function(e){if(!e)return"";const t=[];if(e.repeat?.periodUnit){const n=e.repeat.frequency||1,i=e.repeat.period||1,r=e.repeat.periodUnit;1===n&&1===i?t.push(p[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(L).join(", ")),e.repeat.timeOfDay&&t.push("at "+e.repeat.timeOfDay.map((e=>l(e))).join(", "))}return e.event&&t.push(e.event.map((e=>u(e))).join(", ")),L(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=Re,e.getElementDefinitionTypeName=function(e){const t=e.type?.[0]?.code;return"BackboneElement"===t||"Element"===t?Pe(e.path?.split(".")):t},e.getExpressionForResourceType=Si,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=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?.valueString},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 T(t);for(const e of t){const t=T(e);if(t)return t}}},e.getPropertyDisplayName=function(e){return e.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(Ce).join(" ").replace("_"," ").replace(/\s+/g," ")},e.getQuestionnaireAnswers=function(e){const t={};return P(e.item,t),t},e.getReferenceString=S,e.getResourceTypeSchema=function(e){return Oe.types[e]},e.getResourceTypes=function(){const e=[];for(const[t,n]of Object.entries(Oe.types))De(n)&&e.push(t);return e},e.getSearchParameterDetails=gi,e.getSearchParameters=function(e){return Oe.types[e].searchParams},e.getStatus=function(e){return e.id===z?200:e.id===G?201:e.id===X?304:e.id===Y?401:e.id===K?403:e.id===J?404:e.id===V?410:e.id===Z?429:400},e.getTypedPropertyValue=ln,e.globalSchema=Oe,e.gone=se,e.indexSearchParameter=be,e.indexSearchParameterBundle=function(e){for(const t of e.entry){const e=t.resource;"SearchParameter"===e.resourceType&&be(e)}},e.indexStructureDefinition=Te,e.indexStructureDefinitionBundle=function(e){for(const t of e.entry){const e=t.resource;"StructureDefinition"===e.resourceType&&Te(e)}},e.initFhirPathParserBuilder=ai,e.isEmpty=C,e.isGone=function(e){return e.id===V},e.isLowerCase=function(e){return e===e.toLowerCase()&&e!==e.toUpperCase()},e.isNotFound=function(e){return e.id===J},e.isObject=O,e.isOk=de,e.isOperationOutcome=ce,e.isPeriod=Sn,e.isProfileResource=w,e.isQuantity=wn,e.isQuantityEquivalent=En,e.isResourceType=De,e.isStringArray=k,e.isUUID=function(e){return!!e.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)},e.isValidDate=d,e.matchesRange=N,e.matchesSearchRequest=function(e,t){if(t.resourceType!==e.resourceType)return!1;if(t.filters)for(const n of t.filters)if(!Pi(e,t,n))return!1;return!0},e.normalizeErrorString=function(e){return e?"string"==typeof e?e:e instanceof Error?e.message:ce(e)?e.issue?.[0]?.details?.text??"Unknown error":JSON.stringify(e):"Unknown error"},e.notFound=ie,e.notModified=ne,e.parseFhirPath=di,e.parseJWTPayload=H,e.parseSearchDefinition=function(t){const n=new URL(t,"https://example.com/"),i=n.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let r,o,s,a,c,d;return new URLSearchParams(n.search).forEach(((t,n)=>{"_fields"===n?s=t.split(","):"_offset"===n?a=parseInt(t):"_count"===n?c=parseInt(t):"_total"===n?d=t:"_sort"===n?(o=o||[],o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(t))):(r=r||[],r.push(function(t,n){let i=t,r=e.Operator.EQUALS;for(const e of Ti){const t=i.indexOf(":"+e);-1!==t&&(r=e,i=i.substring(0,t))}for(const e of bi)n.match(new RegExp("^"+e+"\\d"))&&(r=e,n=n.substring(e.length));return{code:i,operator:r,value:n}}(n,t)))})),{resourceType:i,filters:r,fields:s,offset:a,count:c,total:d,sortRules:o}},e.parseSearchRequest=function(e,t){return new Bi(e,t)},e.parseSearchUrl=function(e){const t=e.pathname.split("/").pop();return new Bi(t,Object.fromEntries(e.searchParams.entries()))},e.preciseEquals=function(e,t,n){return W(e,n)===W(t,n)},e.preciseGreaterThan=function(e,t,n){return W(e,n)>W(t,n)},e.preciseGreaterThanOrEquals=Q,e.preciseLessThan=function(e,t,n){return W(e,n)<W(t,n)},e.preciseLessThanOrEquals=j,e.preciseRound=function(e,t){return parseFloat(e.toFixed(t))},e.removeDuplicates=pn,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=D,e.toJsBoolean=dn,e.toTypedValue=cn,e.tokenize=ni,e.tooManyRequests=ae,e.unauthorized=re}));
|
|
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 d(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 d(i)?i.toLocaleTimeString(t,n):""}function u(e,t,n){if(!e)return"";const i=new Date(e);return d(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 p={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 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 m(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=E(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 E(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 T(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function b(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(),d=i.getUTCDate();let l=a-r;(c<o||c===o&&d<s)&&l--;let u=12*a+c-(12*r+o);d<s&&u--;return{years:l,months:u,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){return JSON.stringify(e,A,t?2:void 0)}function A(e,t){return!function(e){return!!e.match(/\d+$/)}(e)&&C(t)?void 0:t}function C(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||(!(!C(e)||!C(t))||!C(e)&&!C(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 k(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 M(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 U(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 L(e){return e.charAt(0).toUpperCase()+e.substring(1)}function _(e,t){return function(e,t){return!e.gender||e.gender===t.gender}(e,t)&&function(e,t){return!e.age||N(b(t.birthDate).years,e.age)}(e,t)}function N(e,t,n){return(void 0===t.low?.value||Q(e,t.low.value,n))&&(void 0===t.high?.value||j(e,t.high.value,n))}function j(e,t,n){return W(e,n)<=W(t,n)}function Q(e,t,n){return W(e,n)>=W(t,n)}function W(e,t){return void 0===t?e:Math.round(e*Math.pow(10,t))}function B(){const e=new Uint32Array(28);return crypto.getRandomValues(e),M(e.buffer)}var q;class ${constructor(){q.set(this,void 0),n(this,q,{},"f")}addEventListener(e,n){t(this,q,"f")[e]||(t(this,q,"f")[e]=[]),t(this,q,"f")[e].push(n)}removeEventListeneer(e,n){const i=t(this,q,"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,q,"f")[e.type];return n&&n.forEach((t=>t.call(this,e))),!e.defaultPrevented}}function F(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 H(e){const[t,n,i]=e.split(".");return F(n)}q=new WeakMap;const z="ok",G="created",V="gone",X="not-modified",J="not-found",Y="unauthorized",K="forbidden",Z="too-many-requests",ee={resourceType:"OperationOutcome",id:z,issue:[{severity:"information",code:"informational",details:{text:"All OK"}}]},te={resourceType:"OperationOutcome",id:G,issue:[{severity:"information",code:"informational",details:{text:"Created"}}]},ne={resourceType:"OperationOutcome",id:X,issue:[{severity:"information",code:"informational",details:{text:"Not Modified"}}]},ie={resourceType:"OperationOutcome",id:J,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},re={resourceType:"OperationOutcome",id:Y,issue:[{severity:"error",code:"login",details:{text:"Unauthorized"}}]},oe={resourceType:"OperationOutcome",id:K,issue:[{severity:"error",code:"forbidden",details:{text:"Forbidden"}}]},se={resourceType:"OperationOutcome",id:V,issue:[{severity:"error",code:"deleted",details:{text:"Gone"}}]},ae={resourceType:"OperationOutcome",id:Z,issue:[{severity:"error",code:"throttled",details:{text:"Too Many Requests"}}]};function ce(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}}function de(e){return"object"==typeof e&&null!==e&&"OperationOutcome"===e.resourceType}function le(e){return e.id===z||e.id===G||e.id===X}class ue extends Error{constructor(e,t){super(e?.issue?.[0].details?.text),this.outcome=e,this.cause=t}}function pe(e){return e instanceof ue?e.outcome:de(e)?e:ce(he(e))}function he(e){return e?"string"==typeof e?e:e instanceof Error?e.message:de(e)?e.issue?.[0]?.details?.text??"Unknown error":JSON.stringify(e):"Unknown error"}var fe,ye,me,ge,ve,xe,we;class Se{constructor(e){this[ve]="ReadablePromise",fe.set(this,void 0),ye.set(this,"pending"),me.set(this,void 0),ge.set(this,void 0),n(this,fe,e.then((e=>(n(this,ye,"success","f"),n(this,me,e,"f"),e)),(e=>{throw n(this,ye,"error","f"),n(this,ge,e,"f"),e})),"f")}isPending(){return"pending"===t(this,ye,"f")}isOk(){return"success"===t(this,ye,"f")}read(){switch(t(this,ye,"f")){case"pending":throw t(this,fe,"f");case"error":throw t(this,ge,"f");default:return t(this,me,"f")}}then(e,n){return t(this,fe,"f").then(e,n)}catch(e){return t(this,fe,"f").catch(e)}finally(e){return t(this,fe,"f").finally(e)}}fe=new WeakMap,ye=new WeakMap,me=new WeakMap,ge=new WeakMap,ve=Symbol.toStringTag;class Ee{constructor(){xe.set(this,void 0),n(this,xe,"undefined"!=typeof localStorage?localStorage:new Te,"f")}clear(){t(this,xe,"f").clear()}getString(e){return t(this,xe,"f").getItem(e)||void 0}setString(e,n){n?t(this,xe,"f").setItem(e,n):t(this,xe,"f").removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?D(t):void 0)}}xe=new WeakMap;class Te{constructor(){we.set(this,void 0),n(this,we,new Map,"f")}get length(){return t(this,we,"f").size}clear(){t(this,we,"f").clear()}getItem(e){return t(this,we,"f").get(e)??null}setItem(e,n){n?t(this,we,"f").set(e,n):t(this,we,"f").delete(e)}removeItem(e){t(this,we,"f").delete(e)}key(e){return Array.from(t(this,we,"f").keys())[e]}}we=new WeakMap;var be,Pe={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 De(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("."),o=Ce(r);let s=Me.types[o];s||(Me.types[o]=s={});s.parentType=s.parentType||Ce(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((e=>function(e){const t=e.path,n=t.split(".");if(1===n.length)return;const i=Ce(n.slice(0,n.length-1)),r=Me.types[i];if(!r)return;const o=n[n.length-1];r.properties[o]=e}(e))))}function Ae(e){if(e.base)for(const t of e.base){const n=Me.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 Ce(e){return 1===e.length?e[0]:e.map(L).join("")}function Re(e){return"http://hl7.org/fhir/StructureDefinition/DomainResource"===e.structureDefinition?.baseDefinition}e.PropertyType=void 0,(be=e.PropertyType||(e.PropertyType={})).Address="Address",be.Age="Age",be.Annotation="Annotation",be.Attachment="Attachment",be.BackboneElement="BackboneElement",be.CodeableConcept="CodeableConcept",be.Coding="Coding",be.ContactDetail="ContactDetail",be.ContactPoint="ContactPoint",be.Contributor="Contributor",be.Count="Count",be.DataRequirement="DataRequirement",be.Distance="Distance",be.Dosage="Dosage",be.Duration="Duration",be.Expression="Expression",be.Extension="Extension",be.HumanName="HumanName",be.Identifier="Identifier",be.MarketingStatus="MarketingStatus",be.Meta="Meta",be.Money="Money",be.Narrative="Narrative",be.ParameterDefinition="ParameterDefinition",be.Period="Period",be.Population="Population",be.ProdCharacteristic="ProdCharacteristic",be.ProductShelfLife="ProductShelfLife",be.Quantity="Quantity",be.Range="Range",be.Ratio="Ratio",be.Reference="Reference",be.RelatedArtifact="RelatedArtifact",be.SampledData="SampledData",be.Signature="Signature",be.SubstanceAmount="SubstanceAmount",be.SystemString="http://hl7.org/fhirpath/System.String",be.Timing="Timing",be.TriggerDefinition="TriggerDefinition",be.UsageContext="UsageContext",be.base64Binary="base64Binary",be.boolean="boolean",be.canonical="canonical",be.code="code",be.date="date",be.dateTime="dateTime",be.decimal="decimal",be.id="id",be.instant="instant",be.integer="integer",be.markdown="markdown",be.oid="oid",be.positiveInt="positiveInt",be.string="string",be.time="time",be.unsignedInt="unsignedInt",be.uri="uri",be.url="url",be.uuid="uuid";const Oe=new Set(["ID","PKCE","JWKS","URI","URL"]);function ke(e){const t=e.toUpperCase();return Oe.has(t)?t:t.charAt(0)+e.slice(1)}function Ie(e,t){const n=Me.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 Ie(Ce(e),t)}return i}}const Me=Pe;var Ue,Le,_e,Ne,je,Qe,We,Be,qe,$e,Fe,He,ze,Ge,Ve,Xe,Je,Ye,Ke,Ze,et,tt,nt,it,rt,ot,st,at,ct,dt,lt,ut,pt,ht,ft,yt,mt,gt,vt,xt,wt;const St={resourceType:"Device",id:"system",deviceName:[{name:"System"}]};function Et(){return"undefined"==typeof window?"":window.location.protocol+"//"+window.location.host+"/"}var Tt,bt,Pt,Dt,At,Ct,Rt,Ot,kt,It,Mt,Ut,Lt,_t,Nt,jt,Qt,Wt,Bt,qt,$t,Ft,Ht,zt,Gt,Vt,Xt,Jt,Yt,Kt,Zt,en;Le=new WeakMap,_e=new WeakMap,Ne=new WeakMap,je=new WeakMap,Qe=new WeakMap,We=new WeakMap,Be=new WeakMap,qe=new WeakMap,$e=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,Ue=new WeakSet,it=function(e){const n=this.getLogins().filter((t=>t.profile?.reference!==e.profile?.reference));n.push(e),t(this,Ne,"f").setObject("logins",n)},rt=async function(){return n(this,et,new Promise(((e,i)=>{this.get("auth/me").then((i=>{n(this,et,void 0,"f"),n(this,tt,i.profile,"f"),n(this,nt,i.config,"f"),this.dispatchEvent({type:"change"}),e(t(this,tt,"f"))})).catch(i)})),"f"),t(this,et,"f")},ot=function(e,n){if(t(this,Qe,"f")<=0||"no-cache"===n?.cache||"reload"===n?.cache)return;const i=t(this,je,"f").get(e);return!i||i.requestTime+t(this,Qe,"f")<Date.now()?void 0:i},st=function(e,n){t(this,Qe,"f")>0&&t(this,je,"f").set(e,{requestTime:Date.now(),value:n})},at=function(e){e?.id&&t(this,Ue,"m",st).call(this,this.fhirUrl(e.resourceType,e.id).toString(),new Se(Promise.resolve(e)))},ct=function(e){t(this,Qe,"f")>0&&t(this,je,"f").delete(e)},dt=async function(e,n,i={}){t(this,Ze,"f")&&await t(this,Ze,"f"),n.startsWith("http")||(n=t(this,We,"f")+n),i.method=e,t(this,Ue,"m",pt).call(this,i);const r=await t(this,Ue,"m",lt).call(this,n,i);if(401===r.status)return t(this,Ue,"m",yt).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 ue(pe(o));return o},lt=async function(e,n){let i;for(let r=0;r<3;r++){if(i=await t(this,Le,"f").call(this,e,n),i.status<500)return i;await new Promise((e=>setTimeout(e,200)))}return i},ut=async function(){const e=[...t(this,Ge,"f")];if(t(this,Ge,"f").length=0,n(this,Je,void 0,"f"),1===e.length){const n=e[0];return void n.resolve(await t(this,Ue,"m",dt).call(this,n.method,t(this,Be,"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&&!le(i.response.outcome)?n.reject(new ue(i.response.outcome)):n.resolve(i?.resource)}},pt=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,Ye,"f")&&(n.Authorization="Bearer "+t(this,Ye,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},ht=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},ft=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))},yt=function(e,n,i){return t(this,Ue,"m",gt).call(this)?t(this,Ue,"m",dt).call(this,e,n,i):(this.clearActiveLogin(),t(this,He,"f")&&t(this,He,"f").call(this),Promise.reject(new Error("Unauthenticated")))},mt=async function(e){const n=await this.ensureCodeChallenge(e||{}),i=new URL(t(this,qe,"f"));i.searchParams.set("response_type","code"),i.searchParams.set("state",sessionStorage.getItem("pkceState")),i.searchParams.set("client_id",n.clientId||t(this,Ve,"f")),i.searchParams.set("redirect_uri",n.redirectUri||Et()),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())},gt=function(){if(t(this,Ze,"f"))return t(this,Ze,"f");if(t(this,Ke,"f")){const e=new URLSearchParams;return e.set("grant_type","refresh_token"),e.set("client_id",t(this,Ve,"f")),e.set("refresh_token",t(this,Ke,"f")),n(this,Ze,t(this,Ue,"m",vt).call(this,e),"f"),t(this,Ze,"f")}return t(this,Ve,"f")&&t(this,Xe,"f")?(n(this,Ze,this.startClientLogin(t(this,Ve,"f"),t(this,Xe,"f")),"f"),t(this,Ze,"f")):void 0},vt=async function(e){const n=await t(this,Le,"f").call(this,t(this,$e,"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,Ue,"m",xt).call(this,i),this.getProfile()},xt=async function(e){const n=e.access_token,i=H(n);if(Date.now()>=1e3*i.exp)throw this.clearActiveLogin(),new Error("Token expired");if(t(this,Ve,"f")&&i.client_id!==t(this,Ve,"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})},wt=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class tn{constructor(e,t){this.operator=e,this.child=t}toString(){return`${this.operator}(${this.child.toString()})`}}class nn{constructor(e,t,n){this.operator=e,this.left=t,this.right=n}toString(){return`${this.left.toString()} ${this.operator} ${this.right.toString()}`}}class rn{constructor(){Tt.set(this,{}),bt.set(this,{})}registerInfix(e,n){return t(this,bt,"f")[e]=n,this}registerPrefix(e,n){return t(this,Tt,"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 on(e,t(this,Tt,"f"),t(this,bt,"f"))}}Tt=new WeakMap,bt=new WeakMap;class on{constructor(e,t,i){Pt.set(this,void 0),Dt.set(this,void 0),At.set(this,void 0),n(this,Pt,e,"f"),n(this,Dt,t,"f"),n(this,At,i,"f")}hasMore(){return t(this,Pt,"f").length>0}match(e){return this.peek()?.id===e&&(this.consume(),!0)}consumeAndParse(e=1/0){const n=this.consume(),i=t(this,Dt,"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,Pt,"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,Pt,"f").shift()}peek(){return t(this,Pt,"f").length>0?t(this,Pt,"f")[0]:void 0}removeComments(){n(this,Pt,t(this,Pt,"f").filter((e=>"Comment"!==e.id)),"f")}getInfixParselet(e){return t(this,At,"f")["Symbol"===e.id?e.value:e.id]}}Pt=new WeakMap,Dt=new WeakMap,At=new WeakMap;const sn=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"];class an{constructor(e,t,i){Ct.add(this),Rt.set(this,void 0),Ot.set(this,void 0),kt.set(this,void 0),It.set(this,[]),Mt.set(this,{index:0,line:1,column:0}),Ut.set(this,[]),n(this,Rt,e,"f"),n(this,Ot,t,"f"),n(this,kt,i,"f")}tokenize(){for(;t(this,Mt,"f").index<t(this,Rt,"f").length;){const e=t(this,Ct,"m",Nt).call(this);e&&t(this,It,"f").push(e)}return t(this,It,"f")}}function cn(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 dn(t){return[{type:e.PropertyType.boolean,value:t}]}function ln(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}:Tn(t)?{type:e.PropertyType.Quantity,value:t}:"object"==typeof t&&"resourceType"in t?{type:t.resourceType,value:t}:{type:e.PropertyType.BackboneElement,value:t}}function un(e){return 0!==e.length&&!!e[0].value}function pn(t,n){if(!t?.value)return;const i=Ie(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]","")+L(n.code);if(i in e.value){r=e.value[i],o=n.code;break}}if(C(r))return;"Element"!==o&&"BackboneElement"!==o||(o=Ce(n.path?.split(".")));return Array.isArray(r)?r.map((e=>hn(e,o))):hn(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+L(t);if(e in i){r=i[e];break}}if(C(r))return;return Array.isArray(r)?r.map(ln):ln(r)}(t,n)}function hn(e,t){return"Resource"===t&&"object"==typeof e&&"resourceType"in e&&(t=e.resourceType),{type:t,value:e}}function fn(e){const t=[];for(const n of e){let e=!1;for(const i of t)if(un(gn(n,i))){e=!0;break}e||t.push(n)}return t}function yn(e){return dn(!un(e))}function mn(e,t){return 0===e.length||0===t.length?[]:e.length!==t.length?dn(!1):dn(e.every(((e,n)=>un(gn(e,t[n])))))}function gn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?dn(Math.abs(n-i)<1e-8):Tn(n)&&Tn(i)?dn(bn(n,i)):dn("object"==typeof n&&"object"==typeof i?Pn(e,t):n===i)}function vn(e,t){return 0===e.length&&0===t.length?dn(!0):e.length!==t.length?dn(!1):(e.sort(wn),t.sort(wn),dn(e.every(((e,n)=>un(xn(e,t[n]))))))}function xn(e,t){const n=e.value,i=t.value;return"number"==typeof n&&"number"==typeof i?dn(Math.abs(n-i)<.01):Tn(n)&&Tn(i)?dn(bn(n,i)):dn("object"==typeof n&&"object"==typeof i?Pn(n,i):"string"==typeof n&&"string"==typeof i?n.toLowerCase()===i.toLowerCase():n===i)}function wn(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 Sn(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 En(n);case"Quantity":return Tn(n);default:return"object"==typeof n&&n?.resourceType===t}}function En(e){return!(!e||"object"!=typeof e||!("start"in e))}function Tn(e){return!(!e||"object"!=typeof e||!("value"in e)||"number"!=typeof e.value)}function bn(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 Pn(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(Dn(n)&&Dn(r)){if(!Pn(n,r))return!1}else if(n!==r)return!1}return!0}function Dn(e){return null!==e&&"object"==typeof e}Rt=new WeakMap,Ot=new WeakMap,kt=new WeakMap,It=new WeakMap,Mt=new WeakMap,Ut=new WeakMap,Ct=new WeakSet,Lt=function(){return t(this,It,"f").slice(-1)[0]},_t=function(){t(this,Ct,"m",Yt).call(this);const e=t(this,Ct,"m",Nt).call(this);return t(this,Ct,"m",Kt).call(this),e},Nt=function(){t(this,Ct,"m",jt).call(this);const e=t(this,Ct,"m",Vt).call(this);if(!e)return;t(this,Ct,"m",Yt).call(this);const n=t(this,Ct,"m",Jt).call(this);return"/"===e&&"*"===n?t(this,Ct,"m",Qt).call(this):"/"===e&&"/"===n?t(this,Ct,"m",Wt).call(this):"'"===e||'"'===e?t(this,Ct,"m",Bt).call(this,e):"`"===e?t(this,Ct,"m",qt).call(this):"@"===e?t(this,Ct,"m",$t).call(this):e.match(/\d/)?t(this,Ct,"m",Ft).call(this):e.match(/\w/)||"$"===e&&n.match(/\w/)?t(this,Ct,"m",Ht).call(this):t(this,Ct,"m",zt).call(this)},jt=function(){t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/\s/)))},Qt=function(){const e=t(this,Mt,"f").index;return t(this,Ct,"m",Gt).call(this,(()=>"*"!==t(this,Ct,"m",Vt).call(this)||"/"!==t(this,Ct,"m",Jt).call(this))),t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",en).call(this,"Comment",t(this,Rt,"f").substring(e,t(this,Mt,"f").index))},Wt=function(){return t(this,Ct,"m",en).call(this,"Comment",t(this,Ct,"m",Gt).call(this,(()=>"\n"!==t(this,Ct,"m",Vt).call(this))))},Bt=function(e){t(this,Ct,"m",Zt).call(this);const n=t(this,Ct,"m",en).call(this,"String",t(this,Ct,"m",Gt).call(this,(()=>"\\"===t(this,Ct,"m",Xt).call(this)||t(this,Ct,"m",Vt).call(this)!==e)));return t(this,Ct,"m",Zt).call(this),n},qt=function(){t(this,Ct,"m",Zt).call(this);const e=t(this,Ct,"m",en).call(this,"Symbol",t(this,Ct,"m",Gt).call(this,(()=>"`"!==t(this,Ct,"m",Vt).call(this))));return t(this,Ct,"m",Zt).call(this),e},$t=function(){t(this,Ct,"m",Zt).call(this);const e=t(this,Mt,"f").index;return t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/[\d-]/))),"T"===t(this,Ct,"m",Vt).call(this)&&(t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/[\d:]/))),"."===t(this,Ct,"m",Vt).call(this)&&t(this,Ct,"m",Jt).call(this).match(/\d/)&&(t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/\d/)))),"Z"===t(this,Ct,"m",Vt).call(this)?t(this,Ct,"m",Zt).call(this):"+"!==t(this,Ct,"m",Vt).call(this)&&"-"!==t(this,Ct,"m",Vt).call(this)||(t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/[\d:]/))))),t(this,Ct,"m",en).call(this,"DateTime",t(this,Rt,"f").substring(e,t(this,Mt,"f").index))},Ft=function(){const e=t(this,Mt,"f").index;let n="Number";return t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/\d/))),"."===t(this,Ct,"m",Vt).call(this)&&t(this,Ct,"m",Jt).call(this).match(/\d/)&&(t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/\d/))))," "===t(this,Ct,"m",Vt).call(this)&&function(e){if(e){if("String"===e.id)return!0;if("Symbol"===e.id&&sn.includes(e.value))return!0}return!1}(t(this,Ct,"m",_t).call(this))&&(n="Quantity",t(this,Ct,"m",Nt).call(this)),t(this,Ct,"m",en).call(this,n,t(this,Rt,"f").substring(e,t(this,Mt,"f").index))},Ht=function(){const e=t(this,Ct,"m",Gt).call(this,(()=>t(this,Ct,"m",Vt).call(this).match(/[$\w]/)));return"."!==t(this,Ct,"m",Lt).call(this)?.value&&t(this,Ot,"f").includes(e)?t(this,Ct,"m",en).call(this,e,e):t(this,Ct,"m",en).call(this,"Symbol",e)},zt=function(){const e=t(this,Ct,"m",Vt).call(this),n=e+t(this,Ct,"m",Jt).call(this);return t(this,kt,"f").includes(n)?(t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",en).call(this,n,n)):(t(this,Ct,"m",Zt).call(this),t(this,Ct,"m",en).call(this,e,e))},Gt=function(e){const n=t(this,Mt,"f").index;for(;t(this,Mt,"f").index<t(this,Rt,"f").length&&e();)t(this,Ct,"m",Zt).call(this);return t(this,Rt,"f").substring(n,t(this,Mt,"f").index)},Vt=function(){return t(this,Rt,"f")[t(this,Mt,"f").index]},Xt=function(){return t(this,Rt,"f")[t(this,Mt,"f").index-1]??""},Jt=function(){return t(this,Rt,"f")[t(this,Mt,"f").index+1]??""},Yt=function(){t(this,Ut,"f").push({...t(this,Mt,"f")})},Kt=function(){const e=t(this,Ut,"f").pop();if(!e)throw new Error("No mark to reset to");t(this,Mt,"f").index=e.index,t(this,Mt,"f").line=e.line,t(this,Mt,"f").column=e.column},Zt=function(){t(this,Mt,"f").index++,"\n"===t(this,Ct,"m",Vt).call(this)?(t(this,Mt,"f").line++,t(this,Mt,"f").column=0):t(this,Mt,"f").column++},en=function(e,n){const i=t(this,Ut,"f").pop();if(!i)throw new Error("No mark for token");return{id:e,value:n,...i}};const An=()=>[],Cn={empty:e=>dn(0===e.length),exists:(e,t)=>dn(t?e.filter((e=>un(t.eval([e])))).length>0:e.length>0),all:(e,t)=>dn(e.every((e=>un(t.eval([e]))))),allTrue:e=>{for(const t of e)if(!t.value)return dn(!1);return dn(!0)},anyTrue:e=>{for(const t of e)if(t.value)return dn(!0);return dn(!1)},allFalse:e=>{for(const t of e)if(t.value)return dn(!1);return dn(!0)},anyFalse:e=>{for(const t of e)if(!t.value)return dn(!0);return dn(!1)},subsetOf:An,supersetOf:An,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=>dn(e.length===Cn.distinct(e).length),where:(e,t)=>e.filter((e=>un(t.eval([e])))),select:(e,t)=>e.map((e=>t.eval([e]))).flat(),repeat:An,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 fn([...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 un(r)?n.eval(e):i?i.eval(e):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:n}]=kn(t,1);if("boolean"==typeof n)return[{type:e.PropertyType.boolean,value:n}];if("number"==typeof n&&(0===n||1===n))return dn(!!n);if("string"==typeof n){const e=n.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(e))return dn(!0);if(["false","f","no","n","0","0.0"].includes(e))return dn(!1)}return[]},convertsToBoolean:e=>0===e.length?[]:dn(1===Cn.toBoolean(e).length),toInteger:t=>{if(0===t.length)return[];const[{value:n}]=kn(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?[]:dn(1===Cn.toInteger(e).length),toDate:t=>{if(0===t.length)return[];const[{value:n}]=kn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.date,value:cn(n)}]:[]},convertsToDate:e=>0===e.length?[]:dn(1===Cn.toDate(e).length),toDateTime:t=>{if(0===t.length)return[];const[{value:n}]=kn(t,1);return"string"==typeof n&&n.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:e.PropertyType.dateTime,value:cn(n)}]:[]},convertsToDateTime:e=>0===e.length?[]:dn(1===Cn.toDateTime(e).length),toDecimal:t=>{if(0===t.length)return[];const[{value:n}]=kn(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?[]:dn(1===Cn.toDecimal(e).length),toQuantity:t=>{if(0===t.length)return[];const[{value:n}]=kn(t,1);return Tn(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?[]:dn(1===Cn.toQuantity(e).length),toString:t=>{if(0===t.length)return[];const[{value:n}]=kn(t,1);return null==n?[]:Tn(n)?[{type:e.PropertyType.string,value:`${n.value} '${n.unit}'`}]:[{type:e.PropertyType.string,value:n.toString()}]},convertsToString:e=>0===e.length?[]:dn(1===Cn.toString(e).length),toTime:t=>{if(0===t.length)return[];const[{value:n}]=kn(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:cn("T"+t[1])}]}return[]},convertsToTime:e=>0===e.length?[]:dn(1===Cn.toTime(e).length),indexOf:(e,t)=>Rn(((e,t)=>e.indexOf(t)),e,t),substring:(e,t,n)=>Rn(((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)=>Rn(((e,t)=>e.startsWith(t)),e,t),endsWith:(e,t)=>Rn(((e,t)=>e.endsWith(t)),e,t),contains:(e,t)=>Rn(((e,t)=>e.includes(t)),e,t),upper:e=>Rn((e=>e.toUpperCase()),e),lower:e=>Rn((e=>e.toLowerCase()),e),replace:(e,t,n)=>Rn(((e,t,n)=>e.replaceAll(t,n)),e,t,n),matches:(e,t)=>Rn(((e,t)=>!!e.match(t)),e,t),replaceMatches:(e,t,n)=>Rn(((e,t,n)=>e.replaceAll(t,n)),e,t,n),length:e=>Rn((e=>e.length),e),toChars:e=>Rn((e=>e?e.split(""):void 0),e),abs:e=>On(Math.abs,e),ceiling:e=>On(Math.ceil,e),exp:e=>On(Math.exp,e),floor:e=>On(Math.floor,e),ln:e=>On(Math.log,e),log:(e,t)=>On(((e,t)=>Math.log(e)/Math.log(t)),e,t),power:(e,t)=>On(Math.pow,e,t),round:e=>On(Math.round,e),sqrt:e=>On(Math.sqrt,e),truncate:e=>On((e=>0|e),e),children:An,descendants:An,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=Cn.toDateTime(n.eval(t));if(0===o.length)throw new Error("Invalid start date");const s=Cn.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=b(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 _n?i=n.name:n instanceof Fn&&(i=n.left.name+"."+n.right.name),i?t.map((t=>({type:e.PropertyType.boolean,value:Sn(t,i)}))):[]},not:t=>Cn.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 ln(e.resource);i=e.reference}if(!i)return{type:e.PropertyType.BackboneElement,value:null};const[r,o]=i.split("/");return{type:e.PropertyType.BackboneElement,value:{resourceType:r,id:o}}})).filter((e=>!!e.value)),as:e=>e,type:t=>t.map((({value:t})=>"boolean"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof t?{type:e.PropertyType.BackboneElement,value:{namespace:"System",name:"Integer"}}:t&&"object"==typeof t&&"resourceType"in 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 Rn(e,t,...n){if(0===t.length)return[];const[{value:i}]=kn(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(ln):[ln(r)]}function On(t,n,...i){if(0===n.length)return[];const[{value:r}]=kn(n,1),o=Tn(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 kn(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 In,Mn;class Un{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 Ln{constructor(e){this.value=e}eval(){return[this.value]}toString(){const e=this.value.value;return"string"==typeof e?`'${e}'`:e.toString()}}class _n{constructor(e){this.name=e,In.add(this)}eval(e){return"$this"===this.name?e:e.map((e=>t(this,In,"m",Mn).call(this,e))).flat().filter((e=>void 0!==e?.value))}toString(){return this.name}}In=new WeakSet,Mn=function(e){const t=e.value;if(t&&"object"==typeof t)return"resourceType"in t&&t.resourceType===this.name?e:pn(e,this.name)};class Nn{eval(){return[]}toString(){return"{}"}}class jn extends tn{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 Qn extends nn{constructor(e,t){super("as",e,t)}eval(e){return Cn.ofType(this.left.eval(e),this.right)}}class Wn extends nn{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=Tn(r)?r.value:r,a=Tn(o)?o.value:o,c=this.impl(s,a);return"boolean"==typeof c?dn(c):Tn(r)?[{type:e.PropertyType.Quantity,value:{...r,value:c}}]:[ln(c)]}}class Bn extends nn{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 qn extends nn{constructor(e,t){super("contains",e,t)}eval(e){const t=this.left.eval(e),n=this.right.eval(e);return dn(t.some((e=>e.value===n[0].value)))}}class $n extends nn{constructor(e,t){super("in",e,t)}eval(e){const t=this.left.eval(e);return dn(this.right.eval(e).some((e=>e.value===t[0].value)))}}class Fn extends nn{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 Hn extends nn{constructor(e,t){super("|",e,t)}eval(e){return fn([...this.left.eval(e),...this.right.eval(e)])}}class zn extends nn{constructor(e,t){super("=",e,t)}eval(e){return mn(this.left.eval(e),this.right.eval(e))}}class Gn extends nn{constructor(e,t){super("!=",e,t)}eval(e){return yn(mn(this.left.eval(e),this.right.eval(e)))}}class Vn extends nn{constructor(e,t){super("~",e,t)}eval(e){return vn(this.left.eval(e),this.right.eval(e))}}class Xn extends nn{constructor(e,t){super("!~",e,t)}eval(e){return yn(vn(this.left.eval(e),this.right.eval(e)))}}class Jn extends nn{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 dn(Sn(t[0],n))}}class Yn extends nn{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?dn(!0):!1===t[0]?.value||!1===n[0]?.value?dn(!1):[]}}class Kn extends nn{constructor(e,t){super("or",e,t)}eval(e){const t=this.left.eval(e);if(un(t))return t;const n=this.right.eval(e);return un(n)?n:[]}}class Zn extends nn{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?dn(!0):!0===i&&!0===r||!1===i&&!1===r?dn(!1):[]}}class ei{constructor(e,t){this.name=e,this.args=t}eval(e){const t=Cn[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 ti{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 ni=["true","false"],ii=["!=","!~","<=",">=","{}","->"];function ri(e){return new an(e,ni,ii).tokenize()}const oi={parse(e){const t=e.consumeAndParse();if(!e.match(")"))throw new Error("Parse error: expected `)` got `"+e.peek()?.value+"`");return t}},si={parse(e,t){const n=e.consumeAndParse();if(!e.match("]"))throw new Error("Parse error: expected `]`");return new ti(t,n)},precedence:2},ai={parse(e,t){if(!(t instanceof _n))throw new Error("Unexpected parentheses");const n=[];for(;!e.match(")");)n.push(e.consumeAndParse()),e.match(",");return new ei(t.name,n)},precedence:0};function ci(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 di(){return(new rn).registerPrefix("String",{parse:(t,n)=>new Ln({type:e.PropertyType.string,value:n.value})}).registerPrefix("DateTime",{parse:(t,n)=>new Ln({type:e.PropertyType.dateTime,value:cn(n.value)})}).registerPrefix("Quantity",{parse:(t,n)=>new Ln({type:e.PropertyType.Quantity,value:ci(n.value)})}).registerPrefix("Number",{parse:(t,n)=>new Ln({type:e.PropertyType.decimal,value:parseFloat(n.value)})}).registerPrefix("true",{parse:()=>new Ln({type:e.PropertyType.boolean,value:!0})}).registerPrefix("false",{parse:()=>new Ln({type:e.PropertyType.boolean,value:!1})}).registerPrefix("Symbol",{parse:(e,t)=>new _n(t.value)}).registerPrefix("{}",{parse:()=>new Nn}).registerPrefix("(",oi).registerInfix("[",si).registerInfix("(",ai).prefix("+",3,((e,t)=>new jn("+",t,(e=>e)))).prefix("-",3,((e,t)=>new Wn("-",t,t,((e,t)=>-t)))).infixLeft(".",1,((e,t,n)=>new Fn(e,n))).infixLeft("/",4,((e,t,n)=>new Wn("/",e,n,((e,t)=>e/t)))).infixLeft("*",4,((e,t,n)=>new Wn("*",e,n,((e,t)=>e*t)))).infixLeft("+",5,((e,t,n)=>new Wn("+",e,n,((e,t)=>e+t)))).infixLeft("-",5,((e,t,n)=>new Wn("-",e,n,((e,t)=>e-t)))).infixLeft("|",7,((e,t,n)=>new Hn(e,n))).infixLeft("=",9,((e,t,n)=>new zn(e,n))).infixLeft("!=",9,((e,t,n)=>new Gn(e,n))).infixLeft("~",9,((e,t,n)=>new Vn(e,n))).infixLeft("!~",9,((e,t,n)=>new Xn(e,n))).infixLeft("<",8,((e,t,n)=>new Wn("<",e,n,((e,t)=>e<t)))).infixLeft("<=",8,((e,t,n)=>new Wn("<=",e,n,((e,t)=>e<=t)))).infixLeft(">",8,((e,t,n)=>new Wn(">",e,n,((e,t)=>e>t)))).infixLeft(">=",8,((e,t,n)=>new Wn(">=",e,n,((e,t)=>e>=t)))).infixLeft("&",5,((e,t,n)=>new Bn(e,n))).infixLeft("and",6,((e,t,n)=>new Yn(e,n))).infixLeft("as",6,((e,t,n)=>new Qn(e,n))).infixLeft("contains",6,((e,t,n)=>new qn(e,n))).infixLeft("div",6,((e,t,n)=>new Wn("div",e,n,((e,t)=>e/t|0)))).infixLeft("in",6,((e,t,n)=>new $n(e,n))).infixLeft("is",6,((e,t,n)=>new Jn(e,n))).infixLeft("mod",6,((e,t,n)=>new Wn("mod",e,n,((e,t)=>e%t)))).infixLeft("or",6,((e,t,n)=>new Kn(e,n))).infixLeft("xor",6,((e,t,n)=>new Zn(e,n)))}const li=di();function ui(e){return new Un(e,li.construct(ri(e)).consumeAndParse())}function pi(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]=ln(n[e]))}return hi(e,n).map((e=>e.value))}function hi(e,t){return ui(e).eval(t)}class fi{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 fi){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 mi(["MSH",this.context.getMsh2(),r,o,n,i,e.toISOString(),"","ACK",e.getTime().toString(),"P",a],this.context),new mi(["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 fi("\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=>mi.parse(e,t))),t)}}class mi{constructor(e,t=new fi){this.context=t,k(e)?this.fields=e.map((e=>gi.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 fi){return new mi(e.split(t.fieldSeparator).map((e=>gi.parse(e,t))),t)}}class gi{constructor(e,t=new fi){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 fi){return new gi(e.split(t.repetitionSeparator).map((e=>e.split(t.componentSeparator))),t)}}var vi;function xi(t,n){let i=Me.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?L(t):t)),"")}(i),o=Ei(t,n.expression)?.split(".");if(!o)return{columnName:r,type:e.SearchParameterType.TEXT};const s=Si(n);let a,c,d=t,l=!1;for(let e=1;e<o.length;e++){if(a=Ie(d,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&&(d=wi(c)?Ce(a.path?.split(".")):c)}const u=Si(n,c),p={columnName:r,type:u,elementDefinition:a,array:l};return function(e,t,n){const i=Me.types[e];i.searchParamsDetails||(i.searchParamsDetails={});i.searchParamsDetails[t]=n}(t,i,p),p}(t,n)),i}function wi(e){return"Element"===e||"BackboneElement"===e}function Si(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 Ei(e,t){const n=t.split(" | ");for(const t of n){if((i=t).includes(" as Period")||i.includes(" as SampledDate"))continue;const n=Ti(t);if(n.startsWith(e+"."))return n}var i}function Ti(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(",".where("];for(const e of n)t.includes(e)&&(t=t.substring(0,t.indexOf(e)));return t}e.SearchParameterType=void 0,(vi=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",vi.NUMBER="NUMBER",vi.QUANTITY="QUANTITY",vi.TEXT="TEXT",vi.REFERENCE="REFERENCE",vi.DATE="DATE",vi.DATETIME="DATETIME",vi.PERIOD="PERIOD";var bi;e.Operator=void 0,(bi=e.Operator||(e.Operator={})).EQUALS="eq",bi.NOT_EQUALS="ne",bi.GREATER_THAN="gt",bi.LESS_THAN="lt",bi.GREATER_THAN_OR_EQUALS="ge",bi.LESS_THAN_OR_EQUALS="le",bi.STARTS_AFTER="sa",bi.ENDS_BEFORE="eb",bi.APPROXIMATELY="ap",bi.CONTAINS="contains",bi.EXACT="exact",bi.TEXT="text",bi.NOT="not",bi.ABOVE="above",bi.BELOW="below",bi.IN="in",bi.NOT_IN="not-in",bi.OF_TYPE="of-type",bi.MISSING="missing";const Pi=[e.Operator.CONTAINS,e.Operator.EXACT,e.Operator.TEXT,e.Operator.NOT,e.Operator.ABOVE,e.Operator.BELOW,e.Operator.IN,e.Operator.NOT_IN,e.Operator.OF_TYPE,e.Operator.MISSING],Di=[e.Operator.NOT_EQUALS,e.Operator.GREATER_THAN,e.Operator.LESS_THAN,e.Operator.GREATER_THAN_OR_EQUALS,e.Operator.LESS_THAN_OR_EQUALS,e.Operator.STARTS_AFTER,e.Operator.ENDS_BEFORE,e.Operator.APPROXIMATELY];function Ai(t,n,i){const r=Me.types[n.resourceType]?.searchParams?.[i.code];switch(r?.type){case"reference":return function(t,n,i){const r=pi(i.expression,t),o=ki(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 Ci(t,i,r);case"token":return function(t,n,i){const r=xi(t.resourceType,i);return r.type===e.SearchParameterType.BOOLEAN?function(e,t,n){const i=pi(n.expression,e),r="true"===t.value,o=i.includes(r);return ki(t.operator)?!o:o}(t,n,i):Ci(t,n,i,!0)}(t,i,r);case"date":return function(e,t,n){const i=pi(n.expression,e),r=t.value.split(","),o=ki(t.operator);for(const e of i)for(const n of r){if(Oi(e,t.operator,n))return!o}return o}(t,i,r)}return!1}function Ci(e,t,n,i){const r=pi(n.expression,e),o=t.value.split(","),s=ki(t.operator);for(const e of r)for(const n of o){if(Ri(e,t.operator,n,i))return!s}return s}function Ri(e,t,n,i){if(i&&n.includes("|")){const[i,r]=n.split("|");return Ri(e,t,i,!1)&&(!r||Ri(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 Oi(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 ki(t){return t===e.Operator.NOT_EQUALS||t===e.Operator.NOT}var Ii,Mi,Ui,Li,_i,Ni,ji,Qi,Wi;const Bi={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},qi={contains:e.Operator.CONTAINS,exact:e.Operator.EXACT,above:e.Operator.ABOVE,below:e.Operator.BELOW,text:e.Operator.TEXT,not:e.Operator.NOT,in:e.Operator.IN,"not-in":e.Operator.NOT_IN,"of-type":e.Operator.OF_TYPE};class $i{constructor(e,n){Ii.add(this),this.resourceType=e,this.filters=[],this.sortRules=[];for(const[e,i]of Object.entries(n))Array.isArray(i)?i.forEach((n=>t(this,Ii,"m",Mi).call(this,e,n))):t(this,Ii,"m",Mi).call(this,e,i??"")}}function Fi(t){const n=t.substring(0,2);return n in Bi?{operator:Bi[n],value:t.substring(2)}:{operator:e.Operator.EQUALS,value:t}}function Hi(t){return qi[t]||e.Operator.EQUALS}Ii=new WeakSet,Mi=function(e,n){let i,r;const o=e.indexOf(":");switch(o>=0?(i=e.substring(0,o),r=e.substring(o+1)):(i=e,r=""),i){case"_sort":t(this,Ii,"m",Ui).call(this,n);break;case"_count":this.count=parseInt(n);break;case"_offset":this.offset=parseInt(n);break;case"_total":this.total=n;break;case"_summary":this.total="estimate",this.count=0;break;case"_revinclude":this.revInclude=n;break;default:{const e=Me.types[this.resourceType]?.searchParams?.[i];e?t(this,Ii,"m",Li).call(this,e,r,n):t(this,Ii,"m",Wi).call(this,i,r,n)}}},Ui=function(e){for(const t of e.split(",")){let e,n=!1;t.startsWith("-")?(e=t.substring(1),n=!0):e=t,this.sortRules.push({code:e,descending:n})}},Li=function(n,i,r){if("missing"!==i)switch(n.type){case"number":case"date":t(this,Ii,"m",_i).call(this,n,r);break;case"string":case"token":case"uri":t(this,Ii,"m",Ni).call(this,n,i,r);break;case"reference":t(this,Ii,"m",ji).call(this,n,r);break;case"quantity":t(this,Ii,"m",Qi).call(this,n,r)}else this.filters.push({code:n.code,operator:e.Operator.MISSING,value:r})},_i=function(e,t){const{operator:n,value:i}=Fi(t);this.filters.push({code:e.code,operator:n,value:i})},Ni=function(e,t,n){this.filters.push({code:e.code,operator:Hi(t),value:n})},ji=function(t,n){this.filters.push({code:t.code,operator:e.Operator.EQUALS,value:n})},Qi=function(e,t){const[n,i,r]=t.split("|"),{operator:o,value:s}=Fi(n);this.filters.push({code:e.code,operator:o,value:s,unitSystem:i,unitCode:r})},Wi=function(t,n,i){let r=e.Operator.EQUALS;if(n)r=n;else for(const e of Object.keys(Bi))i.match(new RegExp("^"+e+"\\d"))&&(r=e,i=i.substring(e.length));this.filters.push({code:t,operator:r,value:i})},e.AndAtom=Yn,e.ArithemticOperatorAtom=Wn,e.AsAtom=Qn,e.ConcatAtom=Bn,e.ContainsAtom=qn,e.DEFAULT_SEARCH_COUNT=20,e.DotAtom=Fn,e.EmptySetAtom=Nn,e.EqualsAtom=zn,e.EquivalentAtom=Vn,e.FHIRPATH_KEYWORDS=ni,e.FHIRPATH_OPERATORS=ii,e.FhirPathAtom=Un,e.FunctionAtom=ei,e.Hl7Context=fi,e.Hl7Field=gi,e.Hl7Message=yi,e.Hl7Segment=mi,e.InAtom=$n,e.IndexerAtom=ti,e.IsAtom=Jn,e.LRUCache=a,e.LiteralAtom=Ln,e.MEDPLUM_VERSION="2.0.5-886af1d8",e.MedplumClient=class extends ${constructor(e){if(super(),Ue.add(this),Le.set(this,void 0),_e.set(this,void 0),Ne.set(this,void 0),je.set(this,void 0),Qe.set(this,void 0),We.set(this,void 0),Be.set(this,void 0),qe.set(this,void 0),$e.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),e?.baseUrl&&!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");n(this,Le,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?.createPdf,"f"),n(this,Ne,new Ee,"f"),n(this,je,new a(e?.resourceCacheSize??1e3),"f"),n(this,Qe,e?.cacheTime??6e4,"f"),n(this,We,function(e){if(!e)return e;return e.endsWith("/")?e:e+"/"}(e?.baseUrl)||"https://api.medplum.com/","f"),n(this,Be,t(this,We,"f")+"fhir/R4/","f"),n(this,Ve,e?.clientId||"","f"),n(this,qe,e?.authorizeUrl||t(this,We,"f")+"oauth2/authorize","f"),n(this,$e,e?.tokenUrl||t(this,We,"f")+"oauth2/token","f"),n(this,Fe,e?.logoutUrl||t(this,We,"f")+"oauth2/logout","f"),n(this,He,e?.onUnauthenticated,"f"),n(this,ze,e?.autoBatchTime??0,"f"),n(this,Ge,[],"f");const i=this.getActiveLogin();i&&(n(this,Ye,i.accessToken,"f"),n(this,Ke,i.refreshToken,"f"),t(this,Ue,"m",rt).call(this).catch(console.log)),t(this,Ue,"m",wt).call(this)}getBaseUrl(){return t(this,We,"f")}clear(){t(this,Ne,"f").clear(),this.clearActiveLogin()}clearActiveLogin(){t(this,Ne,"f").setString("activeLogin",void 0),t(this,je,"f").clear(),n(this,Ye,void 0,"f"),n(this,Ke,void 0,"f"),n(this,tt,void 0,"f"),n(this,nt,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(e){e=e.toString(),t(this,je,"f").delete(e)}invalidateSearches(e){const n="fhir/R4/"+e;for(const e of t(this,je,"f").keys())(e.endsWith(n)||e.includes(n+"?"))&&t(this,je,"f").delete(e)}get(e,i={}){e=e.toString();const r=t(this,Ue,"m",ot).call(this,e,i);if(r)return r.value;let o;o=e.startsWith(t(this,Be,"f"))&&t(this,ze,"f")>0?new Promise(((r,o)=>{t(this,Ge,"f").push({method:"GET",url:e.replace(t(this,Be,"f"),""),options:i,resolve:r,reject:o}),t(this,Je,"f")||n(this,Je,setTimeout((()=>t(this,Ue,"m",ut).call(this)),t(this,ze,"f")),"f")})):t(this,Ue,"m",dt).call(this,"GET",e,i);const s=new Se(o);return t(this,Ue,"m",st).call(this,e,s),s}post(e,n,i,r={}){return e=e.toString(),n&&t(this,Ue,"m",ft).call(this,r,n),i&&t(this,Ue,"m",ht).call(this,r,i),this.invalidateUrl(e),t(this,Ue,"m",dt).call(this,"POST",e,r)}put(e,n,i,r={}){return e=e.toString(),n&&t(this,Ue,"m",ft).call(this,r,n),i&&t(this,Ue,"m",ht).call(this,r,i),this.invalidateUrl(e),t(this,Ue,"m",dt).call(this,"PUT",e,r)}patch(e,n,i={}){return e=e.toString(),t(this,Ue,"m",ft).call(this,i,n),t(this,Ue,"m",ht).call(this,i,"application/json-patch+json"),this.invalidateUrl(e),t(this,Ue,"m",dt).call(this,"PATCH",e,i)}delete(e,n={}){return e=e.toString(),this.invalidateUrl(e),t(this,Ue,"m",dt).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,Ve,"f"),scope:e.scope})}async startGoogleLogin(e){return this.post("auth/google",{...await this.ensureCodeChallenge(e),clientId:e.clientId??t(this,Ve,"f"),scope:e.scope})}async ensureCodeChallenge(e){return e.codeChallenge?e:{...e,...await this.startPkce()}}async signOut(){await this.post(t(this,Fe,"f"),{}),this.clear()}async signInWithRedirect(e){const n=new URLSearchParams(window.location.search).get("code");return n?this.processCode(n):void await t(this,Ue,"m",mt).call(this,e)}signOutWithRedirect(){window.location.assign(t(this,Fe,"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,Be,"f")+e.join("/"))}fhirSearchUrl(e,t){const n=this.fhirUrl(e);return t&&(n.search=t.toString()),n}search(e,n,i={}){const r=this.fhirSearchUrl(e,n),o=r.toString()+"-search",s=t(this,Ue,"m",ot).call(this,o,i);if(s)return s.value;const a=new Se((async()=>{const e=await this.get(r,i);if(e.entry)for(const n of e.entry)t(this,Ue,"m",at).call(this,n.resource);return e})());return t(this,Ue,"m",st).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,Ue,"m",ot).call(this,o,i);if(s)return s.value;const a=new Se(this.search(e,r.searchParams,i).then((e=>e.entry?.[0]?.resource)));return t(this,Ue,"m",st).call(this,o,a),a}searchResources(e,n,i={}){const r=this.fhirSearchUrl(e,n).toString()+"-searchResources",o=t(this,Ue,"m",ot).call(this,r,i);if(o)return o.value;const s=new Se(this.search(e,n,i).then((e=>e.entry?.map((e=>e.resource))??[])));return t(this,Ue,"m",st).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,je,"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 St;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 Se(Promise.reject(new Error("Missing reference")));if("system"===n)return new Se(Promise.resolve(St));const[i,r]=n.split("/");return i&&r?this.readResource(i,r,t):new Se(Promise.reject(new Error("Invalid reference")))}getSchema(){return Me}requestSchema(e){if(e in Me.types)return Promise.resolve(Me);const n=e+"-requestSchema",i=t(this,Ue,"m",ot).call(this,n,void 0);if(i)return i.value;const r=new Se((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)De(e);for(const e of n.data.SearchParameterList)Ae(e);return Me})());return t(this,Ue,"m",st).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,Ye,"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,_e,"f"))throw new Error("PDF creation not enabled");const o=await t(this,_e,"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,Ue,"m",at).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,Ue,"m",ct).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)}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,Ne,"f").getObject("activeLogin")}async setActiveLogin(e){this.clearActiveLogin(),n(this,Ye,e.accessToken,"f"),n(this,Ke,e.refreshToken,"f"),t(this,Ne,"f").setObject("activeLogin",e),t(this,Ue,"m",it).call(this,e),n(this,Ze,void 0,"f"),await t(this,Ue,"m",rt).call(this)}getAccessToken(){return t(this,Ye,"f")}setAccessToken(e){n(this,Ye,e,"f"),n(this,Ke,void 0,"f"),n(this,tt,void 0,"f"),n(this,nt,void 0,"f")}getLogins(){return t(this,Ne,"f").getObject("logins")??[]}isLoading(){return!!t(this,et,"f")}getProfile(){return t(this,tt,"f")}async getProfileAsync(){return t(this,et,"f")&&await t(this,et,"f"),this.getProfile()}getUserConfiguration(){return t(this,nt,"f")}async download(e,n={}){t(this,Ze,"f")&&await t(this,Ze,"f"),t(this,Ue,"m",pt).call(this,n);return(await t(this,Le,"f").call(this,e.toString(),n)).blob()}async startPkce(){const e=B();sessionStorage.setItem("pkceState",e);const t=B();sessionStorage.setItem("codeVerifier",t);const n=U(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){const n=new URLSearchParams;if(n.set("grant_type","authorization_code"),n.set("client_id",t(this,Ve,"f")),n.set("code",e),n.set("redirect_uri",Et()),"undefined"!=typeof sessionStorage){const e=sessionStorage.getItem("codeVerifier");e&&n.set("code_verifier",e)}return t(this,Ue,"m",vt).call(this,n)}async startClientLogin(e,i){n(this,Ve,e,"f"),n(this,Xe,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,Ue,"m",vt).call(this,r)}},e.NotEqualsAtom=Gn,e.NotEquivalentAtom=Xn,e.OperationOutcomeError=ue,e.OrAtom=Kn,e.ReadablePromise=Se,e.SymbolAtom=_n,e.UnaryOperatorAtom=jn,e.UnionAtom=Hn,e.XorAtom=Zn,e.allOk=ee,e.arrayBufferToBase64=U,e.arrayBufferToHex=M,e.assertOk=function(e,t){if(!le(e)||void 0===t)throw new ue(e)},e.badRequest=ce,e.booleanToTypedValue=dn,e.buildTypeName=Ce,e.calculateAge=b,e.calculateAgeString=function(e,t){const{years:n,months:i,days:r}=b(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=L,e.createReference=x,e.created=te,e.deepClone=function(e){return JSON.parse(JSON.stringify(e))},e.deepEquals=R,e.evalFhirPath=pi,e.evalFhirPathTyped=hi,e.fhirPathArrayEquals=mn,e.fhirPathArrayEquivalent=vn,e.fhirPathEquals=gn,e.fhirPathEquivalent=xn,e.fhirPathIs=Sn,e.fhirPathNot=yn,e.findObservationInterval=function(e,t,n,i){return e.qualifiedInterval?.find((r=>_(r,t)&&function(e,t,n){return!!e.range&&N(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=>_(e,t)&&n.includes(e.condition)))},e.forbidden=oe,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=m,e.formatCoding=g,e.formatDate=function(e,t,n){if(!e)return"";const i=new Date(e);return d(i)?(i.setUTCHours(0,0,0,0),i.toLocaleDateString(t,{timeZone:"UTC",...n})):""},e.formatDateTime=u,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?y(t.valueQuantity):t.valueCodeableConcept?m(t.valueCodeableConcept):t.valueString?t.valueString:"":""},e.formatPeriod=function(e,t,n){return e&&(e.start||e.end)?u(e.start,t,n)+" - "+u(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(v(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(v(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(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>t.push(function(e){const t=Pi.includes(e.operator)?":"+e.operator:"",n=Di.includes(e.operator)?e.operator:"";return`${e.code}${t}=${n}${encodeURIComponent(e.value)}`}(e)))),e.sortRules&&e.sortRules.length>0&&t.push("_sort="+e.sortRules.map((e=>e.descending?"-"+e.code:e.code)).join(",")),void 0!==e.offset&&t.push("_offset="+e.offset),void 0!==e.count&&t.push("_count="+e.count),void 0!==e.total&&t.push("_total="+e.total),0===t.length?"":(t.sort(),"?"+t.join("&"))},e.formatTime=l,e.formatTiming=function(e){if(!e)return"";const t=[];if(e.repeat?.periodUnit){const n=e.repeat.frequency||1,i=e.repeat.period||1,r=e.repeat.periodUnit;1===n&&1===i?t.push(p[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(L).join(", ")),e.repeat.timeOfDay&&t.push("at "+e.repeat.timeOfDay.map((e=>l(e))).join(", "))}return e.event&&t.push(e.event.map((e=>u(e))).join(", ")),L(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=Ie,e.getElementDefinitionTypeName=function(e){const t=e.type?.[0]?.code;return"BackboneElement"===t||"Element"===t?Ce(e.path?.split(".")):t},e.getExpressionForResourceType=Ei,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=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?.valueString},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 T(t);for(const e of t){const t=T(e);if(t)return t}}},e.getPropertyDisplayName=function(e){return e.replaceAll("[x]","").split(".").pop().split(/(?=[A-Z])/).map(ke).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 Me.types[e]},e.getResourceTypes=function(){const e=[];for(const[t,n]of Object.entries(Me.types))Re(n)&&e.push(t);return e},e.getSearchParameterDetails=xi,e.getSearchParameters=function(e){return Me.types[e].searchParams},e.getStatus=function(e){return e.id===z?200:e.id===G?201:e.id===X?304:e.id===Y?401:e.id===K?403:e.id===J?404:e.id===V?410:e.id===Z?429:400},e.getTypedPropertyValue=pn,e.globalSchema=Me,e.gone=se,e.indexSearchParameter=Ae,e.indexSearchParameterBundle=function(e){for(const t of e.entry){const e=t.resource;"SearchParameter"===e.resourceType&&Ae(e)}},e.indexStructureDefinition=De,e.indexStructureDefinitionBundle=function(e){for(const t of e.entry){const e=t.resource;"StructureDefinition"===e.resourceType&&De(e)}},e.initFhirPathParserBuilder=di,e.isEmpty=C,e.isGone=function(e){return e.id===V},e.isLowerCase=function(e){return e===e.toLowerCase()&&e!==e.toUpperCase()},e.isNotFound=function(e){return e.id===J},e.isObject=O,e.isOk=le,e.isOperationOutcome=de,e.isPeriod=En,e.isProfileResource=S,e.isQuantity=Tn,e.isQuantityEquivalent=bn,e.isResourceType=Re,e.isStringArray=k,e.isUUID=function(e){return!!e.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)},e.isValidDate=d,e.matchesRange=N,e.matchesSearchRequest=function(e,t){if(t.resourceType!==e.resourceType)return!1;if(t.filters)for(const n of t.filters)if(!Ai(e,t,n))return!1;return!0},e.normalizeErrorString=he,e.normalizeOperationOutcome=pe,e.notFound=ie,e.notModified=ne,e.parseFhirPath=ui,e.parseJWTPayload=H,e.parseSearchDefinition=function(t){const n=new URL(t,"https://example.com/"),i=n.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let r,o,s,a,c,d;return new URLSearchParams(n.search).forEach(((t,n)=>{"_fields"===n?s=t.split(","):"_offset"===n?a=parseInt(t):"_count"===n?c=parseInt(t):"_total"===n?d=t:"_sort"===n?(o=o||[],o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(t))):(r=r||[],r.push(function(t,n){let i=t,r=e.Operator.EQUALS;for(const e of Pi){const t=i.indexOf(":"+e);-1!==t&&(r=e,i=i.substring(0,t))}for(const e of Di)n.match(new RegExp("^"+e+"\\d"))&&(r=e,n=n.substring(e.length));return{code:i,operator:r,value:n}}(n,t)))})),{resourceType:i,filters:r,fields:s,offset:a,count:c,total:d,sortRules:o}},e.parseSearchRequest=function(e,t){return new $i(e,t)},e.parseSearchUrl=function(e){const t=e.pathname.split("/").pop();return new $i(t,Object.fromEntries(e.searchParams.entries()))},e.preciseEquals=function(e,t,n){return W(e,n)===W(t,n)},e.preciseGreaterThan=function(e,t,n){return W(e,n)>W(t,n)},e.preciseGreaterThanOrEquals=Q,e.preciseLessThan=function(e,t,n){return W(e,n)<W(t,n)},e.preciseLessThanOrEquals=j,e.preciseRound=function(e,t){return parseFloat(e.toFixed(t))},e.removeDuplicates=fn,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=D,e.toJsBoolean=un,e.toTypedValue=ln,e.tokenize=ri,e.tooManyRequests=ae,e.unauthorized=re}));
|