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