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