@medplum/core 0.9.16 → 0.9.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- function t(t,e,n,i){return new(n||(n=Promise))((function(r,s){function o(t){try{l(i.next(t))}catch(t){s(t)}}function a(t){try{l(i.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}l((i=i.apply(t,e||[])).next())}))}function e(t,e,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function n(t,e,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 e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(t,n):r?r.value=n:e.set(t,n),n}var i,r,s,o;class a{constructor(t=10){i.add(this),r.set(this,void 0),s.set(this,void 0),n(this,r,t,"f"),n(this,s,new Map,"f")}clear(){e(this,s,"f").clear()}get(t){const n=e(this,s,"f").get(t);return n&&(e(this,s,"f").delete(t),e(this,s,"f").set(t,n)),n}set(t,n){e(this,s,"f").has(t)?e(this,s,"f").delete(t):e(this,s,"f").size>=e(this,r,"f")&&e(this,s,"f").delete(e(this,i,"m",o).call(this)),e(this,s,"f").set(t,n)}delete(t){e(this,s,"f").delete(t)}keys(){return e(this,s,"f").keys()}}function l(t,e){const n=[];return t.line&&n.push(...t.line),t.city&&n.push(t.city),t.state&&n.push(t.state),t.postalCode&&n.push(t.postalCode),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&n.push("["+t.use+"]"),n.join(", ").trim()}function c(t,e){const n=[];return t.prefix&&((null==e?void 0:e.all)||(null==e?void 0:e.prefix))&&n.push(...t.prefix),t.given&&n.push(...t.given),t.family&&n.push(t.family),t.suffix&&((null==e?void 0:e.all)||(null==e?void 0:e.suffix))&&n.push(...t.suffix),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&n.push("["+t.use+"]"),n.join(" ").trim()}function u(t){const e=[];return t.given&&e.push(...t.given),e.join(" ").trim()}function h(t){return t.family||""}function f(t){const e=d(t),n=g(t);return n===e?{reference:e}:{reference:e,display:n}}function d(t){return t.resourceType+"/"+t.id}function v(t){var e;return null===(e=null==t?void 0:t.reference)||void 0===e?void 0:e.split("/")[1]}function p(t){return"Patient"===t.resourceType||"Practitioner"===t.resourceType||"RelatedPerson"===t.resourceType}function g(t){var e,n;if(p(t)){const e=function(t){const e=t.name;if(e&&e.length>0)return c(e[0]);return}(t);if(e)return e}if("Device"===t.resourceType){const e=function(t){const e=t.deviceName;if(e&&e.length>0)return e[0].name;return}(t);if(e)return e}return"Observation"===t.resourceType&&"code"in t&&(null===(e=t.code)||void 0===e?void 0:e.text)?null===(n=t.code)||void 0===n?void 0:n.text:"User"===t.resourceType&&t.email?t.email:"name"in t&&t.name&&"string"==typeof t.name?t.name:d(t)}function m(t){if(p(t)){const e=t.photo;if(e)for(const t of e){const e=y(t);if(e)return e}}if("Bot"===t.resourceType&&t.photo){const e=y(t.photo);if(e)return e}}function y(t){if(t.url&&t.contentType&&t.contentType.startsWith("image/"))return t.url}function w(t){return t?new Date(t):void 0}function b(t,e){const n=new Date(t);n.setUTCHours(0,0,0,0);const i=e?new Date(e):new Date;i.setUTCHours(0,0,0,0);const r=n.getUTCFullYear(),s=n.getUTCMonth(),o=n.getUTCDate(),a=i.getUTCFullYear(),l=i.getUTCMonth(),c=i.getUTCDate();let u=a-r;(l<s||l===s&&c<o)&&u--;let h=12*a+l-(12*r+s);c<o&&h--;return{years:u,months:h,days:Math.floor((i.getTime()-n.getTime())/864e5)}}function T(t,e){const{years:n,months:i,days:r}=b(t,e);return n>=2?n.toString().padStart(3,"0")+"Y":i>=1?i.toString().padStart(3,"0")+"M":r.toString().padStart(3,"0")+"D"}function E(t){const e={};return S(t.item,e),e}function S(t,e){if(t)for(const n of t)n.linkId&&n.answer&&n.answer.length>0&&(e[n.linkId]=n.answer[0]),S(n.item,e)}function A(t,e){const n=t.identifier;if(!n)return;const i=Array.isArray(n)?n:[n];for(const t of i)if(t.system===e)return t.value}function k(t,...e){var n;let i=t;for(let t=0;t<e.length&&i;t++)i=null===(n=null==i?void 0:i.extension)||void 0===n?void 0:n.find((n=>n.url===e[t]));return null==i?void 0:i.valueString}function x(t,e){return JSON.stringify(t,P,e?2:void 0)}function P(t,e){return!function(t){return!!t.match(/\d+$/)}(t)&&O(e)?void 0:e}function O(t){if(null==t)return!0;const e=typeof t;return"string"===e&&""===t||"object"===e&&0===Object.keys(t).length}function U(t,e,n){return t===e||(!(!O(t)||!O(e))||!O(t)&&!O(e)&&(Array.isArray(t)&&Array.isArray(e)?function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!U(t[n],e[n]))return!1;return!0}(t,e):!Array.isArray(t)&&!Array.isArray(e)&&(R(t)&&R(e)?function(t,e,n){const i=new Set;Object.keys(t).forEach((t=>i.add(t))),Object.keys(e).forEach((t=>i.add(t))),"meta"===n&&(i.delete("versionId"),i.delete("lastUpdated"),i.delete("author"));for(const n of i){if(!U(t[n],e[n],n))return!1}return!0}(t,e,n):(R(t)||R(e),!1))))}function M(t){return!!t.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)}function R(t){return null!==t&&"object"==typeof t}function C(t){return t.every((t=>"string"==typeof t))}r=new WeakMap,s=new WeakMap,i=new WeakSet,o=function(){return e(this,s,"f").keys().next().value};const L=[];for(let t=0;t<256;t++)L.push(t.toString(16).padStart(2,"0"));function D(t){const e=new Uint8Array(t),n=new Array(e.length);for(let t=0;t<e.length;t++)n[t]=L[e[t]];return n.join("")}function _(t){const e=new Uint8Array(t),n=[];for(let t=0;t<e.length;t++)n[t]=String.fromCharCode(e[t]);return window.btoa(n.join(""))}function I(t){return t.charAt(0).toUpperCase()+t.substring(1)}function j(t){return t===t.toLowerCase()}function W(t,e){var n,i;return null===(i=null===(n=null==t?void 0:t.coding)||void 0===n?void 0:n.find((t=>t.system===e)))||void 0===i?void 0:i.code}function N(t,e,n){var i,r;t.coding||(t.coding=[]);const s=null===(i=t.coding)||void 0===i?void 0:i.find((t=>t.system===e));s?s.code=n:null===(r=t.coding)||void 0===r||r.push({system:e,code:n})}function B(t,e,n,i){var r;return null===(r=t.qualifiedInterval)||void 0===r?void 0:r.find((r=>{var s;return function(t,e){return function(t,e){return!t.gender||t.gender===e.gender}(t,e)&&function(t,e){return!t.age||Q(b(e.birthDate).years,t.age)}(t,e)}(r,e)&&function(t,e,n){return!!t.range&&Q(e,t.range,n)}(r,n,null===(s=t.quantitativeDetails)||void 0===s?void 0:s.decimalPrecision)&&(void 0===i||r.category===i)}))}function Q(t,e,n){var i,r;return(void 0===(null===(i=e.low)||void 0===i?void 0:i.value)||X(t,e.low.value,n))&&(void 0===(null===(r=e.high)||void 0===r?void 0:r.value)||q(t,e.high.value,n))}function $(t,e,n){return n?Math.abs(t-e)<Math.pow(10,-n):t===e}function F(t,e,n){return n?t<e&&Math.abs(t-e)>Math.pow(10,-n):t<e}function H(t,e,n){return n?t>e&&Math.abs(t-e)>Math.pow(10,-n):t>e}function q(t,e,n){return F(t,e,n)||$(t,e,n)}function X(t,e,n){return H(t,e,n)||$(t,e,n)}function z(){const t=new Uint32Array(28);return crypto.getRandomValues(t),D(t.buffer)}var Y,V,G,K,J,Z,tt,et,nt,it,rt,st,ot,at,lt,ct,ut,ht,ft,dt,vt,pt,gt,mt,yt,wt,bt,Tt,Et,St,At,kt,xt,Pt,Ot,Ut,Mt,Rt,Ct,Lt,Dt,_t,It;function jt(t){const e=function(t){if("undefined"!=typeof window)return window.atob(t);if("undefined"!=typeof Buffer)return Buffer.from(t,"base64").toString("binary");throw new Error("Unable to decode base64")}(t.replace(/-/g,"+").replace(/_/g,"/")),n=Array.from(e).reduce(((t,e)=>`${t}%${("00"+e.charCodeAt(0).toString(16)).slice(-2)}`),""),i=decodeURIComponent(n);return JSON.parse(i)}Y=new WeakMap;class Wt{constructor(t){this[Z]="ReadablePromise",V.set(this,void 0),G.set(this,"pending"),K.set(this,void 0),J.set(this,void 0),n(this,V,t.then((t=>(n(this,G,"success","f"),n(this,K,t,"f"),t)),(t=>{throw n(this,G,"error","f"),n(this,J,t,"f"),t})),"f")}isPending(){return"pending"===e(this,G,"f")}read(){switch(e(this,G,"f")){case"pending":throw e(this,V,"f");case"error":throw e(this,J,"f");default:return e(this,K,"f")}}then(t,n){return e(this,V,"f").then(t,n)}catch(t){return e(this,V,"f").catch(t)}finally(t){return e(this,V,"f").finally(t)}}V=new WeakMap,G=new WeakMap,K=new WeakMap,J=new WeakMap,Z=Symbol.toStringTag;class Nt{constructor(){tt.set(this,void 0),n(this,tt,"undefined"!=typeof localStorage?localStorage:new Bt,"f")}clear(){e(this,tt,"f").clear()}getString(t){return e(this,tt,"f").getItem(t)||void 0}setString(t,n){n?e(this,tt,"f").setItem(t,n):e(this,tt,"f").removeItem(t)}getObject(t){const e=this.getString(t);return e?JSON.parse(e):void 0}setObject(t,e){this.setString(t,e?x(e):void 0)}}tt=new WeakMap;class Bt{constructor(){et.set(this,void 0),n(this,et,new Map,"f")}get length(){return e(this,et,"f").size}clear(){e(this,et,"f").clear()}getItem(t){var n;return null!==(n=e(this,et,"f").get(t))&&void 0!==n?n:null}setItem(t,n){n?e(this,et,"f").set(t,n):e(this,et,"f").delete(t)}removeItem(t){e(this,et,"f").delete(t)}key(t){return Array.from(e(this,et,"f").keys())[t]}}function Qt(){return{types:{}}}function $t(t,e){return{display:t,description:e,properties:{},searchParams:{_lastUpdated:{base:[t],code:"_lastUpdated",type:"date",expression:t+".meta.lastUpdated"}}}}function Ft(t,e){var n;const i=e.name;if(!i)return;t.types[i]=$t(i,e.description);const r=null===(n=e.snapshot)||void 0===n?void 0:n.element;if(r){const e=r.filter((t=>t.path!==i&&t.path));e.forEach((e=>function(t,e){var n,i;const r=e.path,s=null===(i=null===(n=e.type)||void 0===n?void 0:n[0])||void 0===i?void 0:i.code;if("Element"!==s&&"BackboneElement"!==s)return;const o=r.split("."),a=qt(o);a in t.types||(t.types[a]=$t(a,e.definition),t.types[a].parentType=qt(o.slice(0,o.length-1)))}(t,e))),e.forEach((e=>function(t,e){const n=e.path.split(".");if(1===n.length)return;const i=qt(n.slice(0,n.length-1)),r=t.types[i],s=n[n.length-1];r.properties[s]=e}(t,e)))}}function Ht(t,e){if(e.base)for(const n of e.base){const i=t.types[n];i&&(i.searchParams||(i.searchParams={}),i.searchParams[e.code]=e)}}function qt(t){return t.map(I).join("")}function Xt(t){const e=t.path.replaceAll("[x]","").split(".").pop();return"id"===e?"ID":e.split(/(?=[A-Z])/).map(I).join(" ").replace("_"," ").replace(/\s+/g," ")}et=new WeakMap,function(t){t.Address="Address",t.Age="Age",t.Annotation="Annotation",t.Attachment="Attachment",t.BackboneElement="BackboneElement",t.CodeableConcept="CodeableConcept",t.Coding="Coding",t.ContactDetail="ContactDetail",t.ContactPoint="ContactPoint",t.Contributor="Contributor",t.Count="Count",t.DataRequirement="DataRequirement",t.Distance="Distance",t.Dosage="Dosage",t.Duration="Duration",t.Expression="Expression",t.Extension="Extension",t.HumanName="HumanName",t.Identifier="Identifier",t.MarketingStatus="MarketingStatus",t.Meta="Meta",t.Money="Money",t.Narrative="Narrative",t.ParameterDefinition="ParameterDefinition",t.Period="Period",t.Population="Population",t.ProdCharacteristic="ProdCharacteristic",t.ProductShelfLife="ProductShelfLife",t.Quantity="Quantity",t.Range="Range",t.Ratio="Ratio",t.Reference="Reference",t.RelatedArtifact="RelatedArtifact",t.Resource="Resource",t.SampledData="SampledData",t.Signature="Signature",t.SubstanceAmount="SubstanceAmount",t.SystemString="http://hl7.org/fhirpath/System.String",t.Timing="Timing",t.TriggerDefinition="TriggerDefinition",t.UsageContext="UsageContext",t.base64Binary="base64Binary",t.boolean="boolean",t.canonical="canonical",t.code="code",t.date="date",t.dateTime="dateTime",t.decimal="decimal",t.id="id",t.instant="instant",t.integer="integer",t.markdown="markdown",t.oid="oid",t.positiveInt="positiveInt",t.string="string",t.time="time",t.unsignedInt="unsignedInt",t.uri="uri",t.url="url",t.uuid="uuid"}(nt||(nt={}));const zt="launch/patient openid fhirUser offline_access user/*.*";class Yt extends class{constructor(){Y.set(this,void 0),n(this,Y,{},"f")}addEventListener(t,n){e(this,Y,"f")[t]||(e(this,Y,"f")[t]=[]),e(this,Y,"f")[t].push(n)}removeEventListeneer(t,n){const i=e(this,Y,"f")[t];if(i)for(let t=0;t<i.length;t++)if(i[t]===n)return void i.splice(t,1)}dispatchEvent(t){const n=e(this,Y,"f")[t.type];return n&&n.forEach((e=>e.call(this,t))),!t.defaultPrevented}}{constructor(t){var i,r;if(super(),it.add(this),rt.set(this,void 0),st.set(this,void 0),ot.set(this,void 0),at.set(this,void 0),lt.set(this,void 0),ct.set(this,void 0),ut.set(this,void 0),ht.set(this,void 0),ft.set(this,void 0),dt.set(this,void 0),vt.set(this,void 0),pt.set(this,void 0),gt.set(this,void 0),mt.set(this,void 0),yt.set(this,void 0),wt.set(this,void 0),bt.set(this,void 0),Tt.set(this,void 0),null==t?void 0:t.baseUrl){if(!t.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");if(!t.baseUrl.endsWith("/"))throw new Error("Base URL must end with a trailing slash")}n(this,rt,(null==t?void 0:t.fetch)||window.fetch.bind(window),"f"),n(this,st,null==t?void 0:t.createPdf,"f"),n(this,ot,new Nt,"f"),n(this,at,{types:{}},"f"),n(this,lt,new a(null!==(i=null==t?void 0:t.resourceCacheSize)&&void 0!==i?i:1e3),"f"),n(this,ct,null!==(r=null==t?void 0:t.cacheTime)&&void 0!==r?r:1e4,"f"),n(this,ut,(null==t?void 0:t.baseUrl)||"https://api.medplum.com/","f"),n(this,ht,(null==t?void 0:t.clientId)||"","f"),n(this,ft,(null==t?void 0:t.authorizeUrl)||e(this,ut,"f")+"oauth2/authorize","f"),n(this,dt,(null==t?void 0:t.tokenUrl)||e(this,ut,"f")+"oauth2/token","f"),n(this,vt,(null==t?void 0:t.logoutUrl)||e(this,ut,"f")+"oauth2/logout","f"),n(this,pt,null==t?void 0:t.onUnauthenticated,"f");const s=this.getActiveLogin();s&&(n(this,gt,s.accessToken,"f"),n(this,mt,s.refreshToken,"f"),e(this,it,"m",St).call(this).catch(console.log)),e(this,it,"m",It).call(this)}getBaseUrl(){return e(this,ut,"f")}clear(){e(this,ot,"f").clear(),e(this,lt,"f").clear(),n(this,gt,void 0,"f"),n(this,mt,void 0,"f"),n(this,bt,void 0,"f"),n(this,Tt,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(t){t=t.toString(),e(this,lt,"f").delete(t)}invalidateSearches(t){const n="fhir/R4/"+t;for(const t of e(this,lt,"f").keys())(t.endsWith(n)||t.includes(n+"?"))&&e(this,lt,"f").delete(t)}get(t,n={}){t=t.toString();const i=e(this,it,"m",At).call(this,t,n);if(i)return i.value;const r=new Wt(e(this,it,"m",xt).call(this,"GET",t,n));return e(this,it,"m",kt).call(this,t,r),r}post(t,n,i,r={}){return t=t.toString(),n&&e(this,it,"m",Ut).call(this,r,n),i&&e(this,it,"m",Ot).call(this,r,i),this.invalidateUrl(t),e(this,it,"m",xt).call(this,"POST",t,r)}put(t,n,i,r={}){return t=t.toString(),n&&e(this,it,"m",Ut).call(this,r,n),i&&e(this,it,"m",Ot).call(this,r,i),this.invalidateUrl(t),e(this,it,"m",xt).call(this,"PUT",t,r)}patch(t,n,i={}){return t=t.toString(),e(this,it,"m",Ut).call(this,i,n),e(this,it,"m",Ot).call(this,i,"application/json-patch+json"),this.invalidateUrl(t),e(this,it,"m",xt).call(this,"PATCH",t,i)}delete(t,n={}){return t=t.toString(),this.invalidateUrl(t),e(this,it,"m",xt).call(this,"DELETE",t,n)}register(e){return t(this,void 0,void 0,(function*(){const t=yield this.post("auth/register",e);yield this.setActiveLogin(t)}))}startLogin(n){return t(this,void 0,void 0,(function*(){return yield e(this,it,"m",Rt).call(this),this.post("auth/login",Object.assign(Object.assign({},n),{clientId:e(this,ht,"f"),scope:zt,codeChallengeMethod:"S256",codeChallenge:e(this,ot,"f").getString("codeChallenge")}))}))}startGoogleLogin(n){return t(this,void 0,void 0,(function*(){return yield e(this,it,"m",Rt).call(this),this.post("auth/google",n)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const t=new URLSearchParams(window.location.search).get("code");return t?this.processCode(t):void e(this,it,"m",Ct).call(this)}signOutWithRedirect(){window.location.assign(e(this,vt,"f"))}fhirUrl(...t){return new URL(e(this,ut,"f")+"fhir/R4/"+t.join("/"))}fhirSearchUrl(t,e){const n=this.fhirUrl(t);return e&&(n.search=e.toString()),n}search(t,e,n={}){return this.get(this.fhirSearchUrl(t,e),n)}searchOne(t,n,i={}){const r=this.fhirSearchUrl(t,n);r.searchParams.set("_count","1"),r.searchParams.sort();const s=r.toString()+"-searchOne",o=e(this,it,"m",At).call(this,s,i);if(o)return o.value;const a=new Wt(this.search(t,r.searchParams,i).then((t=>{var e,n;return null===(n=null===(e=t.entry)||void 0===e?void 0:e[0])||void 0===n?void 0:n.resource})));return e(this,it,"m",kt).call(this,s,a),a}searchResources(t,n,i={}){const r=this.fhirSearchUrl(t,n).toString()+"-searchResources",s=e(this,it,"m",At).call(this,r,i);if(s)return s.value;const o=new Wt(this.search(t,n,i).then((t=>{var e,n;return null!==(n=null===(e=t.entry)||void 0===e?void 0:e.map((t=>t.resource)))&&void 0!==n?n:[]})));return e(this,it,"m",kt).call(this,r,o),o}searchValueSet(t,e,n={}){const i=this.fhirUrl("ValueSet","$expand");return i.searchParams.set("url",t),i.searchParams.set("filter",e),this.get(i.toString(),n)}getCached(t,n){var i;const r=null===(i=e(this,lt,"f").get(this.fhirUrl(t,n).toString()))||void 0===i?void 0:i.value;return r&&!r.isPending()?r.read():void 0}getCachedReference(t){const e=t.reference;if(!e)return;const[n,i]=e.split("/");return n&&i?this.getCached(n,i):void 0}readResource(t,e){return this.get(this.fhirUrl(t,e))}readReference(t){const e=null==t?void 0:t.reference;if(!e)return new Wt(Promise.reject(new Error("Missing reference")));const[n,i]=e.split("/");return n&&i?this.readResource(n,i):new Wt(Promise.reject(new Error("Invalid reference")))}getSchema(){return e(this,at,"f")}requestSchema(n){return t(this,void 0,void 0,(function*(){if(n in e(this,at,"f").types)return Promise.resolve(e(this,at,"f"));const t=`{\n StructureDefinitionList(name: "${n}") {\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: "${n}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),i=yield this.graphql(t);for(const t of i.data.StructureDefinitionList)Ft(e(this,at,"f"),t);for(const t of i.data.SearchParameterList)Ht(e(this,at,"f"),t);return e(this,at,"f")}))}readHistory(t,e){return this.get(this.fhirUrl(t,e,"_history"))}readVersion(t,e,n){return this.get(this.fhirUrl(t,e,"_history",n))}readPatientEverything(t){return this.get(this.fhirUrl("Patient",t,"$everything"))}createResource(t){if(!t.resourceType)throw new Error("Missing resourceType");return this.invalidateSearches(t.resourceType),this.post(this.fhirUrl(t.resourceType),t)}createResourceIfNoneExist(e,n){var i;return t(this,void 0,void 0,(function*(){return null!==(i=yield this.searchOne(e.resourceType,n))&&void 0!==i?i:this.createResource(e)}))}createBinary(t,e,n){const i=this.fhirUrl("Binary");return e&&i.searchParams.set("_filename",e),this.post(i,t,n)}createPdf(n,i,r,s){return t(this,void 0,void 0,(function*(){if(!e(this,st,"f"))throw new Error("PDF creation not enabled");const t=yield e(this,st,"f").call(this,n,r,s);return this.createBinary(t,i,"application/pdf")}))}createComment(t,e){const n=this.getProfile();let i,r;return"Encounter"===t.resourceType&&(i=f(t),r=t.subject),"ServiceRequest"===t.resourceType&&(i=t.encounter,r=t.subject),"Patient"===t.resourceType&&(r=f(t)),this.createResource({resourceType:"Communication",basedOn:[f(t)],encounter:i,subject:r,sender:n?f(n):void 0,sent:(new Date).toISOString(),payload:[{contentString:e}]})}updateResource(t){if(!t.resourceType)throw new Error("Missing resourceType");if(!t.id)throw new Error("Missing id");return this.invalidateSearches(t.resourceType),this.put(this.fhirUrl(t.resourceType,t.id),t)}patchResource(t,e,n){return this.invalidateSearches(t),this.patch(this.fhirUrl(t,e),n)}deleteResource(t,e){return this.invalidateSearches(t),this.delete(this.fhirUrl(t,e))}sendEmail(t){return this.post("email/v1/send",t,"application/json")}graphql(t,e){return this.post(this.fhirUrl("$graphql"),{query:t},"application/json",e)}getActiveLogin(){return e(this,ot,"f").getObject("activeLogin")}setActiveLogin(i){return t(this,void 0,void 0,(function*(){n(this,gt,i.accessToken,"f"),n(this,mt,i.refreshToken,"f"),n(this,bt,void 0,"f"),n(this,Tt,void 0,"f"),e(this,ot,"f").setObject("activeLogin",i),e(this,it,"m",Et).call(this,i),e(this,lt,"f").clear(),n(this,yt,void 0,"f"),yield e(this,it,"m",St).call(this)}))}getAccessToken(){return e(this,gt,"f")}setAccessToken(t){n(this,gt,t,"f"),n(this,mt,void 0,"f"),n(this,bt,void 0,"f"),n(this,Tt,void 0,"f")}getLogins(){var t;return null!==(t=e(this,ot,"f").getObject("logins"))&&void 0!==t?t:[]}isLoading(){return!!e(this,wt,"f")}getProfile(){return e(this,bt,"f")}getProfileAsync(){return t(this,void 0,void 0,(function*(){return e(this,wt,"f")&&(yield e(this,wt,"f")),this.getProfile()}))}getUserConfiguration(){return e(this,Tt,"f")}download(n,i={}){return t(this,void 0,void 0,(function*(){e(this,yt,"f")&&(yield e(this,yt,"f")),e(this,it,"m",Pt).call(this,i);return(yield e(this,rt,"f").call(this,n.toString(),i)).blob()}))}processCode(t){if(!e(this,ot,"f").getString("pkceState"))throw this.clear(),new Error("Invalid PCKE state");const n=e(this,ot,"f").getString("codeVerifier");if(!n)throw this.clear(),new Error("Invalid PCKE code verifier");const i=new URLSearchParams;return i.set("grant_type","authorization_code"),i.set("client_id",e(this,ht,"f")),i.set("code_verifier",n),i.set("code",t),i.set("redirect_uri",Vt()),e(this,it,"m",Dt).call(this,i)}startClientLogin(n,i){return t(this,void 0,void 0,(function*(){const t=new URLSearchParams;return t.set("grant_type","client_credentials"),t.set("client_id",n),t.set("client_secret",i),e(this,it,"m",Dt).call(this,t)}))}}function Vt(){return window.location.protocol+"//"+window.location.host+"/"}function Gt(t){return[{type:nt.boolean,value:t}]}function Kt(t){return Number.isSafeInteger(t)?{type:nt.integer,value:t}:"number"==typeof t?{type:nt.decimal,value:t}:"boolean"==typeof t?{type:nt.boolean,value:t}:"string"==typeof t?{type:nt.string,value:t}:oe(t)?{type:nt.Quantity,value:t}:{type:nt.BackboneElement,value:t}}function Jt(t){return 0!==t.length&&!!t[0].value}function Zt(t){const e=[];for(const n of t){let t=!1;for(const i of e)if(Jt(ne(n,i))){t=!0;break}t||e.push(n)}return e}function te(t){return Gt(!Jt(t))}function ee(t,e){return 0===t.length||0===e.length?[]:t.length!==e.length?Gt(!1):Gt(t.every(((t,n)=>Jt(ne(t,e[n])))))}function ne(t,e){const n=t.value,i=e.value;return"number"==typeof n&&"number"==typeof i?Gt(Math.abs(n-i)<1e-8):oe(n)&&oe(i)?Gt(ae(n,i)):Gt("object"==typeof n&&"object"==typeof i?le(t,e):n===i)}function ie(t,e){return 0===t.length&&0===e.length?Gt(!0):t.length!==e.length?Gt(!1):(t.sort(re),e.sort(re),Gt(t.every(((t,n)=>Jt(function(t,e){const n=t.value,i=e.value;if("number"==typeof n&&"number"==typeof i)return Gt(Math.abs(n-i)<.01);if(oe(n)&&oe(i))return Gt(ae(n,i));if("object"==typeof n&&"object"==typeof i)return Gt(le(n,i));if("string"==typeof n&&"string"==typeof i)return Gt(n.toLowerCase()===i.toLowerCase());return Gt(n===i)}(t,e[n]))))))}function re(t,e){const n=t.value,i=e.value;return"number"==typeof n&&"number"==typeof i?n-i:"string"==typeof n&&"string"==typeof i?n.localeCompare(i):0}function se(t,e){const{value:n}=t;if(null==n)return!1;switch(e){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!(!(i=n)||"object"!=typeof i||!("start"in i));case"Quantity":return oe(n);default:return"object"==typeof n&&(null==n?void 0:n.resourceType)===e}var i}function oe(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function ae(t,e){return Math.abs(t.value-e.value)<.01&&(t.unit===e.unit||t.code===e.code||t.unit===e.code||t.code===e.unit)}function le(t,e){const n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!1;for(const i of n){const n=t[i],r=e[i];if(ce(n)&&ce(r)){if(!le(n,r))return!1}else if(n!==r)return!1}return!0}function ce(t){return null!==t&&"object"==typeof t}var ue,he;rt=new WeakMap,st=new WeakMap,ot=new WeakMap,at=new WeakMap,lt=new WeakMap,ct=new WeakMap,ut=new WeakMap,ht=new WeakMap,ft=new WeakMap,dt=new WeakMap,vt=new WeakMap,pt=new WeakMap,gt=new WeakMap,mt=new WeakMap,yt=new WeakMap,wt=new WeakMap,bt=new WeakMap,Tt=new WeakMap,it=new WeakSet,Et=function(t){const n=this.getLogins().filter((e=>{var n,i;return(null===(n=e.profile)||void 0===n?void 0:n.reference)!==(null===(i=t.profile)||void 0===i?void 0:i.reference)}));n.push(t),e(this,ot,"f").setObject("logins",n)},St=function(){return t(this,void 0,void 0,(function*(){return n(this,wt,new Promise(((t,i)=>{this.get("auth/me").then((i=>{n(this,wt,void 0,"f"),n(this,bt,i.profile,"f"),n(this,Tt,i.config,"f"),this.dispatchEvent({type:"change"}),t(e(this,bt,"f"))})).catch(i)})),"f"),e(this,wt,"f")}))},At=function(t,n){if(e(this,ct,"f")<=0||"no-cache"===(null==n?void 0:n.cache)||"reload"===(null==n?void 0:n.cache))return;const i=e(this,lt,"f").get(t);return!i||i.requestTime+e(this,ct,"f")<Date.now()?void 0:i},kt=function(t,n){e(this,ct,"f")>0&&e(this,lt,"f").set(t,{requestTime:Date.now(),value:n})},xt=function(n,i,r={}){return t(this,void 0,void 0,(function*(){e(this,yt,"f")&&(yield e(this,yt,"f")),i.startsWith("http")||(i=e(this,ut,"f")+i),r.method=n,e(this,it,"m",Pt).call(this,r);const t=yield e(this,rt,"f").call(this,i,r);if(401===t.status)return e(this,it,"m",Mt).call(this,n,i,r);if(204===t.status||304===t.status)return;const s=yield t.json();if(t.status>=400)throw s;return s}))},Pt=function(t){t.headers||(t.headers={});const n=t.headers;n["Content-Type"]||(n["Content-Type"]="application/fhir+json"),e(this,gt,"f")&&(n.Authorization="Bearer "+e(this,gt,"f")),t.cache||(t.cache="no-cache"),t.credentials||(t.credentials="include")},Ot=function(t,e){t.headers||(t.headers={});t.headers["Content-Type"]=e},Ut=function(t,e){"string"==typeof e||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Uint8Array&&e instanceof Uint8Array?t.body=e:e&&(t.body=JSON.stringify(e))},Mt=function(n,i,r){return t(this,void 0,void 0,(function*(){return e(this,it,"m",Lt).call(this).then((()=>e(this,it,"m",xt).call(this,n,i,r))).catch((t=>(this.clear(),e(this,pt,"f")&&e(this,pt,"f").call(this),Promise.reject(t))))}))},Rt=function(){return t(this,void 0,void 0,(function*(){const n=z();e(this,ot,"f").setString("pkceState",n);const i=z();e(this,ot,"f").setString("codeVerifier",i);const r=_(yield function(e){return t(this,void 0,void 0,(function*(){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}))}(i)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");e(this,ot,"f").setString("codeChallenge",r)}))},Ct=function(){e(this,it,"m",Rt).call(this);const t=new URL(e(this,ft,"f"));t.searchParams.set("response_type","code"),t.searchParams.set("state",e(this,ot,"f").getString("pkceState")),t.searchParams.set("client_id",e(this,ht,"f")),t.searchParams.set("redirect_uri",Vt()),t.searchParams.set("scope",zt),t.searchParams.set("code_challenge_method","S256"),t.searchParams.set("code_challenge",e(this,ot,"f").getString("codeChallenge")),window.location.assign(t.toString())},Lt=function(){return t(this,void 0,void 0,(function*(){if(e(this,yt,"f"))return e(this,yt,"f");if(!e(this,mt,"f"))throw this.clear(),new Error("Invalid refresh token");const t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("client_id",e(this,ht,"f")),t.set("refresh_token",e(this,mt,"f")),n(this,yt,e(this,it,"m",Dt).call(this,t),"f"),yield e(this,yt,"f")}))},Dt=function(n){return t(this,void 0,void 0,(function*(){return e(this,rt,"f").call(this,e(this,dt,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n}).then((t=>{if(!t.ok)throw new Error("Failed to fetch tokens");return t.json()})).then((t=>e(this,it,"m",_t).call(this,t))).then((()=>this.getProfile()))}))},_t=function(n){return t(this,void 0,void 0,(function*(){const t=n.access_token,i=function(t){const[e,n,i]=t.split(".");return jt(n)}(t);if(Date.now()>=1e3*i.exp)throw this.clear(),new Error("Token expired");if(e(this,ht,"f")&&i.client_id!==e(this,ht,"f"))throw this.clear(),new Error("Token was not issued for this audience");yield this.setActiveLogin({accessToken:t,refreshToken:n.refresh_token,project:n.project,profile:n.profile})}))},It=function(){try{window.addEventListener("storage",(t=>{null!==t.key&&"activeLogin"!==t.key||window.location.reload()}))}catch(t){}};class fe{constructor(t,e){this.original=t,this.child=e}eval(t){try{return t.length>0?t.map((t=>this.child.eval([t]))).flat():this.child.eval(t)}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class de{constructor(t){this.value=t}eval(){return[this.value]}}class ve{constructor(t){this.name=t,ue.add(this)}eval(t){return"$this"===this.name?t:t.map((t=>e(this,ue,"m",he).call(this,t))).flat().filter((t=>void 0!==(null==t?void 0:t.value)))}}ue=new WeakSet,he=function(t){const e=t.value;if(!e||"object"!=typeof e)return;if("resourceType"in e&&e.resourceType===this.name)return t;let n;if(this.name in e)n=e[this.name];else{const t=Object.keys(e).find((t=>t.startsWith(this.name)));t&&(n=e[t])}return void 0!==n?Array.isArray(n)?n.map(Kt):[Kt(n)]:void 0};class pe{eval(){return[]}}class ge{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class me{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class ye{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t);if(1!==e.length)return[];const n=this.right.eval(t);if(1!==n.length)return[];const i=e[0].value,r=n[0].value,s=oe(i)?i.value:i,o=oe(r)?r.value:r,a=this.impl(s,o);return"boolean"==typeof a?Gt(a):oe(i)?[{type:nt.Quantity,value:Object.assign(Object.assign({},i),{value:a})}]:[Kt(a)]}}class we{constructor(t,e){this.left=t,this.right=e}eval(t){const e=[...this.left.eval(t),...this.right.eval(t)];return e.length>0&&e.every((t=>"string"==typeof t.value))?[{type:nt.string,value:e.map((t=>t.value)).join("")}]:e}}class be{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Gt(e.some((t=>t.value===n[0].value)))}}class Te{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return Gt(this.right.eval(t).some((t=>t.value===e[0].value)))}}class Ee{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class Se{constructor(t,e){this.left=t,this.right=e}eval(t){return Zt([...this.left.eval(t),...this.right.eval(t)])}}class Ae{constructor(t,e){this.left=t,this.right=e}eval(t){return ee(this.left.eval(t),this.right.eval(t))}}class ke{constructor(t,e){this.left=t,this.right=e}eval(t){return te(ee(this.left.eval(t),this.right.eval(t)))}}class xe{constructor(t,e){this.left=t,this.right=e}eval(t){return ie(this.left.eval(t),this.right.eval(t))}}class Pe{constructor(t,e){this.left=t,this.right=e}eval(t){return te(ie(this.left.eval(t),this.right.eval(t)))}}class Oe{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(1!==e.length)return[];const n=this.right.name;return Gt(se(e[0],n))}}class Ue{constructor(t,e){this.left=t,this.right=e}eval(t){var e,n,i,r;const s=this.left.eval(t),o=this.right.eval(t);return!0===(null===(e=s[0])||void 0===e?void 0:e.value)&&!0===(null===(n=o[0])||void 0===n?void 0:n.value)?Gt(!0):!1===(null===(i=s[0])||void 0===i?void 0:i.value)||!1===(null===(r=o[0])||void 0===r?void 0:r.value)?Gt(!1):[]}}class Me{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(Jt(e))return e;const n=this.right.eval(t);return Jt(n)?n:[]}}class Re{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);if(0===e.length&&0===n.length)return[];const i=0===e.length?null:e[0].value,r=0===n.length?null:n[0].value;return!0===i&&!0!==r||!0!==i&&!0===r?Gt(!0):!0===i&&!0===r||!1===i&&!1===r?Gt(!1):[]}}class Ce{constructor(t,e,n){this.name=t,this.args=e,this.impl=n}eval(t){return this.impl(t,...this.args)}}class Le{constructor(t,e){this.left=t,this.expr=e}eval(t){const e=this.expr.eval(t);if(1!==e.length)return[];const n=e[0].value;if("number"!=typeof n)throw new Error("Invalid indexer expression: should return integer}");const i=this.left.eval(t);return n in i?[i[n]]:[]}}function De(t){if(t.startsWith("T"))return t+"T00:00:00.000Z".substring(t.length);if(t.length<=10)return t;try{return new Date(t).toISOString()}catch(e){return t}}const _e=()=>[],Ie={empty:t=>Gt(0===t.length),exists:(t,e)=>Gt(e?t.filter((t=>Jt(e.eval([t])))).length>0:t.length>0),all:(t,e)=>Gt(t.every((t=>Jt(e.eval([t]))))),allTrue:t=>{for(const e of t)if(!e.value)return Gt(!1);return Gt(!0)},anyTrue:t=>{for(const e of t)if(e.value)return Gt(!0);return Gt(!1)},allFalse:t=>{for(const e of t)if(e.value)return Gt(!1);return Gt(!0)},anyFalse:t=>{for(const e of t)if(!e.value)return Gt(!0);return Gt(!1)},subsetOf:_e,supersetOf:_e,count:t=>[{type:nt.integer,value:t.length}],distinct:t=>{const e=[];for(const n of t)e.some((t=>t.value===n.value))||e.push(n);return e},isDistinct:t=>Gt(t.length===Ie.distinct(t).length),where:(t,e)=>t.filter((t=>Jt(e.eval([t])))),select:(t,e)=>t.map((t=>e.eval([t]))).flat(),repeat:_e,ofType:_e,single:t=>{if(t.length>1)throw new Error("Expected input length one for single()");return 0===t.length?[]:t.slice(0,1)},first:t=>0===t.length?[]:t.slice(0,1),last:t=>0===t.length?[]:t.slice(t.length-1,t.length),tail:t=>0===t.length?[]:t.slice(1,t.length),skip:(t,e)=>{var n;const i=null===(n=e.eval([])[0])||void 0===n?void 0:n.value;if("number"!=typeof i)throw new Error("Expected a number for skip(num)");return i>=t.length?[]:i<=0?t:t.slice(i,t.length)},take:(t,e)=>{var n;const i=null===(n=e.eval([])[0])||void 0===n?void 0:n.value;if("number"!=typeof i)throw new Error("Expected a number for take(num)");return i>=t.length?t:i<=0?[]:t.slice(0,i)},intersect:(t,e)=>{if(!e)return t;const n=e.eval([]),i=[];for(const e of t)!i.some((t=>t.value===e.value))&&n.some((t=>t.value===e.value))&&i.push(e);return i},exclude:(t,e)=>{if(!e)return t;const n=e.eval([]),i=[];for(const e of t)n.some((t=>t.value===e.value))||i.push(e);return i},union:(t,e)=>{if(!e)return t;const n=e.eval([]);return Zt([...t,...n])},combine:(t,e)=>{if(!e)return t;const n=e.eval([]);return[...t,...n]},iif:(t,e,n,i)=>{const r=e.eval(t);if(r.length>1||1===r.length&&"boolean"!=typeof r[0].value)throw new Error("Expected criterion to evaluate to a Boolean");return Jt(r)?n.eval(t):i?i.eval(t):[]},toBoolean:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);if("boolean"==typeof e)return[{type:nt.boolean,value:e}];if("number"==typeof e&&(0===e||1===e))return Gt(!!e);if("string"==typeof e){const t=e.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return Gt(!0);if(["false","f","no","n","0","0.0"].includes(t))return Gt(!1)}return[]},convertsToBoolean:t=>0===t.length?[]:Gt(1===Ie.toBoolean(t).length),toInteger:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);return"number"==typeof e?[{type:nt.integer,value:e}]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[{type:nt.integer,value:parseInt(e,10)}]:"boolean"==typeof e?[{type:nt.integer,value:e?1:0}]:[]},convertsToInteger:t=>0===t.length?[]:Gt(1===Ie.toInteger(t).length),toDate:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:nt.date,value:De(e)}]:[]},convertsToDate:t=>0===t.length?[]:Gt(1===Ie.toDate(t).length),toDateTime:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:nt.dateTime,value:De(e)}]:[]},convertsToDateTime:t=>0===t.length?[]:Gt(1===Ie.toDateTime(t).length),toDecimal:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);return"number"==typeof e?[{type:nt.decimal,value:e}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:nt.decimal,value:parseFloat(e)}]:"boolean"==typeof e?[{type:nt.decimal,value:e?1:0}]:[]},convertsToDecimal:t=>0===t.length?[]:Gt(1===Ie.toDecimal(t).length),toQuantity:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);return oe(e)?[{type:nt.Quantity,value:e}]:"number"==typeof e?[{type:nt.Quantity,value:{value:e,unit:"1"}}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:nt.Quantity,value:{value:parseFloat(e),unit:"1"}}]:"boolean"==typeof e?[{type:nt.Quantity,value:{value:e?1:0,unit:"1"}}]:[]},convertsToQuantity:t=>0===t.length?[]:Gt(1===Ie.toQuantity(t).length),toString:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);return null==e?[]:oe(e)?[{type:nt.string,value:`${e.value} '${e.unit}'`}]:[{type:nt.string,value:e.toString()}]},convertsToString:t=>0===t.length?[]:Gt(1===Ie.toString(t).length),toTime:t=>{if(0===t.length)return[];const[{value:e}]=Ne(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[{type:nt.time,value:De("T"+t[1])}]}return[]},convertsToTime:t=>0===t.length?[]:Gt(1===Ie.toTime(t).length),indexOf:(t,e)=>je(((t,e)=>t.indexOf(e)),t,e),substring:(t,e,n)=>je(((t,e,n)=>{const i=e,r=n?i+n:t.length;return i<0||i>=t.length?void 0:t.substring(i,r)}),t,e,n),startsWith:(t,e)=>je(((t,e)=>t.startsWith(e)),t,e),endsWith:(t,e)=>je(((t,e)=>t.endsWith(e)),t,e),contains:(t,e)=>je(((t,e)=>t.includes(e)),t,e),upper:t=>je((t=>t.toUpperCase()),t),lower:t=>je((t=>t.toLowerCase()),t),replace:(t,e,n)=>je(((t,e,n)=>t.replaceAll(e,n)),t,e,n),matches:(t,e)=>je(((t,e)=>!!t.match(e)),t,e),replaceMatches:(t,e,n)=>je(((t,e,n)=>t.replaceAll(e,n)),t,e,n),length:t=>je((t=>t.length),t),toChars:t=>je((t=>t?t.split(""):void 0),t),abs:t=>We(Math.abs,t),ceiling:t=>We(Math.ceil,t),exp:t=>We(Math.exp,t),floor:t=>We(Math.floor,t),ln:t=>We(Math.log,t),log:(t,e)=>We(((t,e)=>Math.log(t)/Math.log(e)),t,e),power:(t,e)=>We(Math.pow,t,e),round:t=>We(Math.round,t),sqrt:t=>We(Math.sqrt,t),truncate:t=>We((t=>0|t),t),children:_e,descendants:_e,trace:(t,e)=>(console.log("trace",t,e),t),now:()=>[{type:nt.dateTime,value:(new Date).toISOString()}],timeOfDay:()=>[{type:nt.time,value:(new Date).toISOString().substring(11)}],today:()=>[{type:nt.date,value:(new Date).toISOString().substring(0,10)}],between:(t,e,n,i)=>{const r=Ie.toDateTime(e.eval(t));if(0===r.length)throw new Error("Invalid start date");const s=Ie.toDateTime(n.eval(t));if(0===s.length)throw new Error("Invalid end date");const o=i.eval(t)[0].value;if("years"!==o&&"months"!==o&&"days"!==o)throw new Error("Invalid units");const a=b(r[0].value,s[0].value);return[{type:nt.Quantity,value:{value:a[o],unit:o}}]},is:(t,e)=>{let n="";return e instanceof ve?n=e.name:e instanceof Ee&&(n=e.left.name+"."+e.right.name),n?t.map((t=>({type:nt.boolean,value:se(t,n)}))):[]},not:t=>Ie.toBoolean(t).map((t=>({type:nt.boolean,value:!t.value}))),resolve:t=>t.map((t=>{const e=t.value;let n;if("string"==typeof e)n=e;else if("object"==typeof e){const t=e;if(t.resource)return{type:nt.BackboneElement,value:t.resource};n=t.reference}if(!n)return{type:nt.BackboneElement,value:null};const[i,r]=n.split("/");return{type:nt.BackboneElement,value:{resourceType:i,id:r}}})).filter((t=>!!t.value)),as:t=>t,type:t=>t.map((({value:t})=>"boolean"==typeof t?{type:nt.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof t?{type:nt.BackboneElement,value:{namespace:"System",name:"Integer"}}:t&&"object"==typeof t&&"resourceType"in t?{type:nt.BackboneElement,value:{namespace:"FHIR",name:t.resourceType}}:{type:nt.BackboneElement,value:null})),conformsTo:(t,e)=>{const n=e.eval([])[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 t.map((t=>{var e;return{type:nt.boolean,value:(null===(e=t.value)||void 0===e?void 0:e.resourceType)===i}}))}};function je(t,e,...n){if(0===e.length)return[];const[{value:i}]=Ne(e,1);if("string"!=typeof i)throw new Error("String function cannot be called with non-string");const r=t(i,...n.map((t=>{var n,i;return t&&(null===(i=null===(n=t.eval(e))||void 0===n?void 0:n[0])||void 0===i?void 0:i.value)})));return void 0===r?[]:Array.isArray(r)?r.map(Kt):[Kt(r)]}function We(t,e,...n){if(0===e.length)return[];const[{value:i}]=Ne(e,1),r=oe(i),s=r?i.value:i;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...n.map((t=>{var e,n;return null===(n=null===(e=t.eval([]))||void 0===e?void 0:e[0])||void 0===n?void 0:n.value})));return[{type:r?nt.Quantity:e[0].type,value:r?Object.assign(Object.assign({},i),{value:o}):o}]}function Ne(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);for(const e of t)if(null==e)throw new Error("Expected non-null argument");return t}var Be,Qe,$e,Fe,He,qe,Xe,ze,Ye,Ve,Ge,Ke,Je,Ze,tn,en,nn,rn;function sn(t){return new ln(t).tokenize()}const on=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],an=["!=","!~","<=",">=","{}"];class ln{constructor(t){Be.add(this),Qe.set(this,void 0),$e.set(this,void 0),n(this,Qe,t,"f"),n(this,$e,0,"f")}tokenize(){const t=[];for(;e(this,$e,"f")<e(this,Qe,"f").length;){const n=e(this,Be,"m",He).call(this);n&&t.push(n)}return t}}function cn(t,e){return{id:t,value:e}}var un,hn,fn,dn,vn,pn,gn,mn,yn;Qe=new WeakMap,$e=new WeakMap,Be=new WeakSet,Fe=function(){const t=e(this,$e,"f"),i=e(this,Be,"m",He).call(this);return n(this,$e,t,"f"),i},He=function(){e(this,Be,"m",qe).call(this);const t=e(this,Be,"m",en).call(this);if(!t)return;const n=e(this,Be,"m",rn).call(this);return"/"===t&&"*"===n?e(this,Be,"m",Xe).call(this):"/"===t&&"/"===n?e(this,Be,"m",ze).call(this):"'"===t?e(this,Be,"m",Ye).call(this):"`"===t?e(this,Be,"m",Ve).call(this):"@"===t?e(this,Be,"m",Ge).call(this):t.match(/\d/)?e(this,Be,"m",Ke).call(this):t.match(/\w/)||"$"===t&&n.match(/\w/)?e(this,Be,"m",Je).call(this):e(this,Be,"m",Ze).call(this)},qe=function(){return cn("Whitespace",e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/\s/))))},Xe=function(){const t=e(this,$e,"f");return e(this,Be,"m",tn).call(this,(()=>"*"!==e(this,Be,"m",en).call(this)||"/"!==e(this,Be,"m",rn).call(this))),n(this,$e,e(this,$e,"f")+2,"f"),cn("Comment",e(this,Qe,"f").substring(t,e(this,$e,"f")))},ze=function(){return cn("Comment",e(this,Be,"m",tn).call(this,(()=>"\n"!==e(this,Be,"m",en).call(this))))},Ye=function(){var t,i;n(this,$e,(t=e(this,$e,"f"),++t),"f");const r=cn("String",e(this,Be,"m",tn).call(this,(()=>"\\"===e(this,Be,"m",nn).call(this)||"'"!==e(this,Be,"m",en).call(this))));return n(this,$e,(i=e(this,$e,"f"),++i),"f"),r},Ve=function(){var t,i;n(this,$e,(t=e(this,$e,"f"),++t),"f");const r=cn("Symbol",e(this,Be,"m",tn).call(this,(()=>"`"!==e(this,Be,"m",en).call(this))));return n(this,$e,(i=e(this,$e,"f"),++i),"f"),r},Ge=function(){var t,i,r,s,o;const a=e(this,$e,"f");return n(this,$e,(t=e(this,$e,"f"),++t),"f"),e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/[\d-]/))),"T"===e(this,Be,"m",en).call(this)&&(n(this,$e,(i=e(this,$e,"f"),++i),"f"),e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/[\d:]/))),"."===e(this,Be,"m",en).call(this)&&e(this,Be,"m",rn).call(this).match(/\d/)&&(n(this,$e,(r=e(this,$e,"f"),++r),"f"),e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/[\d]/)))),"Z"===e(this,Be,"m",en).call(this)?n(this,$e,(s=e(this,$e,"f"),++s),"f"):"+"!==e(this,Be,"m",en).call(this)&&"-"!==e(this,Be,"m",en).call(this)||(n(this,$e,(o=e(this,$e,"f"),++o),"f"),e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/[\d:]/))))),cn("DateTime",e(this,Qe,"f").substring(a+1,e(this,$e,"f")))},Ke=function(){var t;const i=e(this,$e,"f");let r="Number";return e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/\d/))),"."===e(this,Be,"m",en).call(this)&&e(this,Be,"m",rn).call(this).match(/\d/)&&(n(this,$e,(t=e(this,$e,"f"),++t),"f"),e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/\d/))))," "===e(this,Be,"m",en).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&on.includes(t.value))return!0}return!1}(e(this,Be,"m",Fe).call(this))&&(r="Quantity",e(this,Be,"m",He).call(this)),cn(r,e(this,Qe,"f").substring(i,e(this,$e,"f")))},Je=function(){return cn("Symbol",e(this,Be,"m",tn).call(this,(()=>e(this,Be,"m",en).call(this).match(/[$\w]/))))},Ze=function(){var t;const i=e(this,Be,"m",en).call(this),r=i+e(this,Be,"m",rn).call(this);return an.includes(r)?(n(this,$e,e(this,$e,"f")+2,"f"),cn(r,r)):(n(this,$e,(t=e(this,$e,"f"),++t),"f"),cn(i,i))},tn=function(t){var i;const r=e(this,$e,"f");for(;e(this,$e,"f")<e(this,Qe,"f").length&&t();)n(this,$e,(i=e(this,$e,"f"),++i),"f");return e(this,Qe,"f").substring(r,e(this,$e,"f"))},en=function(){return e(this,Qe,"f")[e(this,$e,"f")]},nn=function(){var t;return null!==(t=e(this,Qe,"f")[e(this,$e,"f")-1])&&void 0!==t?t:""},rn=function(){var t;return null!==(t=e(this,Qe,"f")[e(this,$e,"f")+1])&&void 0!==t?t:""};un=new WeakMap,hn=new WeakMap;class wn{constructor(t,e,i){fn.add(this),dn.set(this,void 0),vn.set(this,void 0),pn.set(this,void 0),n(this,dn,t,"f"),n(this,vn,e,"f"),n(this,pn,i,"f")}match(t){const n=e(this,fn,"m",yn).call(this);return(null==n?void 0:n.id)===t&&(e(this,fn,"m",mn).call(this),!0)}consumeAndParse(t=100){const n=e(this,fn,"m",mn).call(this),i=e(this,vn,"f")[n.id];if(!i)throw Error(`Parse error at ${n.value}. No matching prefix parselet.`);let r=i.parse(this,n);for(;t>e(this,fn,"m",gn).call(this);){const t=e(this,fn,"m",mn).call(this);r=e(this,pn,"f")[t.id].parse(this,r,t)}return r}}dn=new WeakMap,vn=new WeakMap,pn=new WeakMap,fn=new WeakSet,gn=function(){const t=e(this,fn,"m",yn).call(this);if(!t)return 100;const n=e(this,pn,"f")[t.id];return n?n.precedence:100},mn=function(){if(!e(this,dn,"f").length)throw Error("Cant consume unknown more tokens.");return e(this,dn,"f").shift()},yn=function(){return e(this,dn,"f").length>0?e(this,dn,"f")[0]:void 0};const bn={parse(t){const e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},Tn={parse(t,e){const n=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new Le(e,n)},precedence:2},En={parse(t,e){if(!(e instanceof ve))throw new Error("Unexpected parentheses");if(!(e.name in Ie))throw new Error("Unrecognized function: "+e.name);const n=[];for(;!t.match(")");)n.push(t.consumeAndParse()),t.match(",");return new Ce(e.name,n,Ie[e.name])},precedence:0};function Sn(t){const e=t.split(" "),n=parseFloat(e[0]);let i=e[1];return i=i&&i.startsWith("'")&&i.endsWith("'")?i.substring(1,i.length-1):"{"+i+"}",{value:n,unit:i}}const An=(new class{constructor(){un.set(this,{}),hn.set(this,{})}registerInfix(t,n){return e(this,hn,"f")[t]=n,this}registerPrefix(t,n){return e(this,un,"f")[t]=n,this}prefix(t,e,n){return this.registerPrefix(t,{parse(t,i){const r=t.consumeAndParse(e);return n(i,r)}})}infixLeft(t,e,n){return this.registerInfix(t,{parse(t,i,r){const s=t.consumeAndParse(e);return n(i,r,s)},precedence:e})}construct(t){return new wn(sn(t),e(this,un,"f"),e(this,hn,"f"))}}).registerPrefix("String",{parse:(t,e)=>new de({type:nt.string,value:e.value})}).registerPrefix("DateTime",{parse:(t,e)=>new de({type:nt.dateTime,value:De(e.value)})}).registerPrefix("Quantity",{parse:(t,e)=>new de({type:nt.Quantity,value:Sn(e.value)})}).registerPrefix("Number",{parse:(t,e)=>new de({type:nt.decimal,value:parseFloat(e.value)})}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new de({type:nt.boolean,value:!1}):"true"===e.value?new de({type:nt.boolean,value:!0}):new ve(e.value)}).registerPrefix("{}",{parse:()=>new pe}).registerPrefix("(",bn).registerInfix("[",Tn).registerInfix("(",En).prefix("+",3,((t,e)=>new ge(e,(t=>t)))).prefix("-",3,((t,e)=>new ye(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,n)=>new Ee(t,n))).infixLeft("/",4,((t,e,n)=>new ye(t,n,((t,e)=>t/e)))).infixLeft("*",4,((t,e,n)=>new ye(t,n,((t,e)=>t*e)))).infixLeft("+",5,((t,e,n)=>new ye(t,n,((t,e)=>t+e)))).infixLeft("-",5,((t,e,n)=>new ye(t,n,((t,e)=>t-e)))).infixLeft("|",7,((t,e,n)=>new Se(t,n))).infixLeft("=",9,((t,e,n)=>new Ae(t,n))).infixLeft("!=",9,((t,e,n)=>new ke(t,n))).infixLeft("~",9,((t,e,n)=>new xe(t,n))).infixLeft("!~",9,((t,e,n)=>new Pe(t,n))).infixLeft("<",8,((t,e,n)=>new ye(t,n,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,n)=>new ye(t,n,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,n)=>new ye(t,n,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,n)=>new ye(t,n,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,n)=>new we(t,n))).infixLeft("Symbol",6,((t,e,n)=>{switch(e.value){case"and":return new Ue(t,n);case"as":return new me(t,n);case"contains":return new be(t,n);case"div":return new ye(t,n,((t,e)=>t/e|0));case"in":return new Te(t,n);case"is":return new Oe(t,n);case"mod":return new ye(t,n,((t,e)=>t%e));case"or":return new Me(t,n);case"xor":return new Re(t,n);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function kn(t){try{return new fe(t,An.construct(t).consumeAndParse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}function xn(t,e){Array.isArray(e)||(e=[e]);const n=Array.isArray(e)?e:[e];for(let t=0;t<n.length;t++){const e=n[t];"object"==typeof e&&"type"in e&&"value"in e||(n[t]={type:nt.BackboneElement,value:e})}return kn(t).eval(n).map((t=>t.value))}const Pn="\r",On="|",Un="^";class Mn{constructor(t){this.segments=t}get(t){return"number"==typeof t?this.segments[t]:this.segments.find((e=>e.name===t))}getAll(t){return this.segments.filter((e=>e.name===t))}toString(){return this.segments.map((t=>t.toString())).join("\r")}buildAck(){var t,e,n,i,r,s;const o=new Date,a=this.get("MSH"),l=(null===(t=null==a?void 0:a.get(2))||void 0===t?void 0:t.toString())||"",c=(null===(e=null==a?void 0:a.get(3))||void 0===e?void 0:e.toString())||"",u=(null===(n=null==a?void 0:a.get(4))||void 0===n?void 0:n.toString())||"",h=(null===(i=null==a?void 0:a.get(5))||void 0===i?void 0:i.toString())||"",f=(null===(r=null==a?void 0:a.get(9))||void 0===r?void 0:r.toString())||"",d=(null===(s=null==a?void 0:a.get(12))||void 0===s?void 0:s.toString())||"2.5.1";return new Mn([new Rn(["MSH","^~\\&",u,h,l,c,o.toISOString(),"","ACK",o.getTime().toString(),"P",d]),new Rn(["MSA","AA",f,"OK"])])}static parse(t){if(!t.startsWith("MSH|^~\\&")){const t=new Error("Invalid HL7 message");throw t.type="entity.parse.failed",t}return new Mn(t.split(/[\r\n]+/).map((t=>Rn.parse(t))))}}class Rn{constructor(t){C(t)?this.fields=t.map((t=>Cn.parse(t))):this.fields=t,this.name=this.fields[0].components[0]}get(t){return this.fields[t]}toString(){return this.fields.map((t=>t.toString())).join("|")}static parse(t){return new Rn(t.split("|").map((t=>Cn.parse(t))))}}class Cn{constructor(t){this.components=t}get(t){return this.components[t]}toString(){return this.components.join("^")}static parse(t){return new Cn(t.split("^"))}}const Ln={resourceType:"OperationOutcome",id:"ok",issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},Dn={resourceType:"OperationOutcome",id:"created",issue:[{severity:"information",code:"information",details:{text:"Created"}}]},_n={resourceType:"OperationOutcome",id:"not-modified",issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},In={resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},jn={resourceType:"OperationOutcome",id:"gone",issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},Wn={resourceType:"OperationOutcome",id:"access-denied",issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function Nn(t,e){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:t},expression:e?[e]:void 0}]}}function Bn(t){return"ok"===t.id||"created"===t.id||"not-modified"===t.id}function Qn(t){return"not-found"===t.id}function $n(t){return"gone"===t.id}function Fn(t){return"ok"===t.id?200:"created"===t.id?201:"not-modified"===t.id?304:"access-denied"===t.id?403:"not-found"===t.id?404:"gone"===t.id?410:400}function Hn(t,e){if(!Bn(t)||void 0===e)throw new qn(t)}class qn extends Error{constructor(t){var e,n;super(null===(n=null===(e=null==t?void 0:t.issue)||void 0===e?void 0:e[0].details)||void 0===n?void 0:n.text),this.outcome=t}}const Xn=20;var zn;!function(t){t.EQUALS="eq",t.NOT_EQUALS="ne",t.GREATER_THAN="gt",t.LESS_THAN="lt",t.GREATER_THAN_OR_EQUALS="ge",t.LESS_THAN_OR_EQUALS="le",t.STARTS_AFTER="sa",t.ENDS_BEFORE="eb",t.APPROXIMATELY="ap",t.CONTAINS="contains",t.EXACT="exact",t.TEXT="text",t.ABOVE="above",t.BELOW="below",t.IN="in",t.NOT_IN="not-in",t.OF_TYPE="of-type"}(zn||(zn={}));const Yn=[zn.CONTAINS,zn.EXACT,zn.TEXT,zn.ABOVE,zn.BELOW,zn.IN,zn.NOT_IN,zn.OF_TYPE],Vn=[zn.NOT_EQUALS,zn.GREATER_THAN,zn.LESS_THAN,zn.GREATER_THAN_OR_EQUALS,zn.LESS_THAN_OR_EQUALS,zn.STARTS_AFTER,zn.ENDS_BEFORE,zn.APPROXIMATELY];function Gn(t){const e=new URL(t,"https://example.com/"),n=e.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let i,r,s,o,a,l;return new URLSearchParams(e.search).forEach(((t,e)=>{"_fields"===e?s=t.split(","):"_offset"===e?o=parseInt(t):"_count"===e?a=parseInt(t):"_total"===e?l=t:"_sort"===e?(r=r||[],r.push(function(t){return t.startsWith("-")?{code:t.substring(1),descending:!0}:{code:t}}(t))):(i=i||[],i.push(function(t,e){let n=t,i=zn.EQUALS;for(const t of Yn){const e=n.indexOf(":"+t);-1!==e&&(i=t,n=n.substring(0,e))}for(const t of Vn)e.match(new RegExp("^"+t+"\\d"))&&(i=t,e=e.substring(t.length));return{code:n,operator:i,value:e}}(e,t)))})),{resourceType:n,filters:i,fields:s,offset:o,count:a,total:l,sortRules:r}}function Kn(t){const e=[];return t.fields&&e.push("_fields="+t.fields.join(",")),t.filters&&t.filters.forEach((t=>e.push(function(t){const e=Yn.includes(t.operator)?":"+t.operator:"",n=Vn.includes(t.operator)?t.operator:"";return`${t.code}${e}=${n}${encodeURIComponent(t.value)}`}(t)))),t.sortRules&&t.sortRules.length>0&&e.push(function(t){if(!t||0===t.length)return"";return"_sort="+t.map((t=>t.descending?"-"+t.code:t.code)).join(",")}(t.sortRules)),void 0!==t.offset&&e.push("_offset="+t.offset),void 0!==t.count&&e.push("_count="+t.count),void 0!==t.total&&e.push("_total="+t.total),0===e.length?"":(e.sort(),"?"+e.join("&"))}var Jn;function Zn(t,e,n){var i,r,s,o;if("_lastUpdated"===n.code)return{columnName:"lastUpdated",type:Jn.DATETIME};const a=n.code.split("-").reduce(((t,e,n)=>t+(n?I(e):e)),"");const l=null===(i=ti(e,n.expression))||void 0===i?void 0:i.split(".");if(!l)return{columnName:a,type:Jn.TEXT};let c,u,h=e,f=!1;for(let e=1;e<l.length;e++){const n=l[e];if(c=null===(s=null===(r=t.types[h])||void 0===r?void 0:r.properties)||void 0===s?void 0:s[n],!c)return{columnName:a,type:Jn.TEXT,array:f};if("*"===c.max&&(f=!0),u=null===(o=c.type)||void 0===o?void 0:o[0].code,!u)return{columnName:a,type:Jn.TEXT,array:f};e<l.length-1&&("Element"===u||"BackboneElement"===u?h+=I(n):h=u)}const d=function(t,e){let n=Jn.TEXT;switch(t.type){case"date":n=e===nt.dateTime||e===nt.instant?Jn.DATETIME:Jn.DATE;break;case"number":n=Jn.NUMBER;break;case"quantity":n=Jn.QUANTITY;break;case"reference":n=Jn.REFERENCE;break;case"token":"boolean"===e&&(n=Jn.BOOLEAN)}return n}(n,u);return{columnName:a,type:d,elementDefinition:c,array:f}}function ti(t,e){const n=e.split(" | ");for(const e of n){const n=ei(e);if(n.startsWith(t+"."))return n}}function ei(t){let e=t.trim();return e.startsWith("(")&&e.endsWith(")")&&(e=e.substring(1,e.length-1)),e.includes(" as ")&&(e=e.substring(0,e.indexOf(" as "))),e.includes(".where(")&&(e=e.substring(0,e.indexOf(".where("))),e}!function(t){t.BOOLEAN="BOOLEAN",t.NUMBER="NUMBER",t.QUANTITY="QUANTITY",t.TEXT="TEXT",t.REFERENCE="REFERENCE",t.DATE="DATE",t.DATETIME="DATETIME",t.PERIOD="PERIOD"}(Jn||(Jn={}));export{Un as COMPONENT_SEPARATOR,Xn as DEFAULT_SEARCH_COUNT,On as FIELD_SEPARATOR,Cn as Hl7Field,Mn as Hl7Message,Rn as Hl7Segment,a as LRUCache,Yt as MedplumClient,qn as OperationOutcomeError,zn as Operator,nt as PropertyType,Wt as ReadablePromise,Pn as SEGMENT_SEPARATOR,Jn as SearchParameterType,Wn as accessDenied,Ln as allOk,_ as arrayBufferToBase64,D as arrayBufferToHex,Hn as assertOk,Nn as badRequest,qt as buildTypeName,b as calculateAge,T as calculateAgeString,I as capitalize,f as createReference,Qt as createSchema,$t as createTypeSchema,Dn as created,U as deepEquals,xn as evalFhirPath,B as findObservationInterval,l as formatAddress,h as formatFamilyName,u as formatGivenName,c as formatHumanName,Kn as formatSearchQuery,W as getCodeBySystem,w as getDateProperty,g as getDisplayString,ti as getExpressionForResourceType,k as getExtensionValue,A as getIdentifier,m as getImageSrc,Xt as getPropertyDisplayName,E as getQuestionnaireAnswers,d as getReferenceString,Zn as getSearchParameterDetails,Fn as getStatus,jn as gone,Ht as indexSearchParameter,Ft as indexStructureDefinition,$n as isGone,j as isLowerCase,Qn as isNotFound,R as isObject,Bn as isOk,p as isProfileResource,C as isStringArray,M as isUUID,Q as matchesRange,In as notFound,_n as notModified,kn as parseFhirPath,Gn as parseSearchDefinition,$ as preciseEquals,H as preciseGreaterThan,X as preciseGreaterThanOrEquals,F as preciseLessThan,q as preciseLessThanOrEquals,v as resolveId,N as setCodeBySystem,x as stringify,sn as tokenize};
1
+ function e(e,t,i,n){return new(i||(i=Promise))((function(o,r){function a(e){try{c(n.next(e))}catch(e){r(e)}}function s(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))}function t(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}function i(e,t,i,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(e,i):o?o.value=i:t.set(e,i),i}var n,o,r,a;class s{constructor(e=10){n.add(this),o.set(this,void 0),r.set(this,void 0),i(this,o,e,"f"),i(this,r,new Map,"f")}clear(){t(this,r,"f").clear()}get(e){const i=t(this,r,"f").get(e);return i&&(t(this,r,"f").delete(e),t(this,r,"f").set(e,i)),i}set(e,i){t(this,r,"f").has(e)?t(this,r,"f").delete(e):t(this,r,"f").size>=t(this,o,"f")&&t(this,r,"f").delete(t(this,n,"m",a).call(this)),t(this,r,"f").set(e,i)}delete(e){t(this,r,"f").delete(e)}keys(){return t(this,r,"f").keys()}}function c(e,t){const i=[];return e.line&&i.push(...e.line),e.city&&i.push(e.city),e.state&&i.push(e.state),e.postalCode&&i.push(e.postalCode),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&i.push("["+e.use+"]"),i.join(", ").trim()}function d(e,t){const i=[];return e.prefix&&((null==t?void 0:t.all)||(null==t?void 0:t.prefix))&&i.push(...e.prefix),e.given&&i.push(...e.given),e.family&&i.push(e.family),e.suffix&&((null==t?void 0:t.all)||(null==t?void 0:t.suffix))&&i.push(...e.suffix),e.use&&((null==t?void 0:t.all)||(null==t?void 0:t.use))&&i.push("["+e.use+"]"),i.join(" ").trim()}function l(e){const t=[];return e.given&&t.push(...e.given),t.join(" ").trim()}function u(e){return e.family||""}function m(e){const t=p(e),i=y(e);return i===t?{reference:t}:{reference:t,display:i}}function p(e){return e.resourceType+"/"+e.id}function h(e){var t;return null===(t=null==e?void 0:e.reference)||void 0===t?void 0:t.split("/")[1]}function f(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function y(e){var t,i;if(f(e)){const t=function(e){const t=e.name;if(t&&t.length>0)return d(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&&(null===(t=e.code)||void 0===t?void 0:t.text)?null===(i=e.code)||void 0===i?void 0:i.text:"User"===e.resourceType&&e.email?e.email:"name"in e&&e.name&&"string"==typeof e.name?e.name:p(e)}function g(e){if(f(e)){const t=e.photo;if(t)for(const e of t){const t=x(e);if(t)return t}}if("Bot"===e.resourceType&&e.photo){const t=x(e.photo);if(t)return t}}function x(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function v(e){return e?new Date(e):void 0}function w(e,t){const i=new Date(e);i.setUTCHours(0,0,0,0);const n=t?new Date(t):new Date;n.setUTCHours(0,0,0,0);const o=i.getUTCFullYear(),r=i.getUTCMonth(),a=i.getUTCDate(),s=n.getUTCFullYear(),c=n.getUTCMonth(),d=n.getUTCDate();let l=s-o;(c<r||c===r&&d<a)&&l--;let u=12*s+c-(12*o+r);d<a&&u--;return{years:l,months:u,days:Math.floor((n.getTime()-i.getTime())/864e5)}}function E(e,t){const{years:i,months:n,days:o}=w(e,t);return i>=2?i.toString().padStart(3,"0")+"Y":n>=1?n.toString().padStart(3,"0")+"M":o.toString().padStart(3,"0")+"D"}function S(e){const t={};return b(e.item,t),t}function b(e,t){if(e)for(const i of e)i.linkId&&i.answer&&i.answer.length>0&&(t[i.linkId]=i.answer[0]),b(i.item,t)}function D(e,t){const i=e.identifier;if(!i)return;const n=Array.isArray(i)?i:[i];for(const e of n)if(e.system===t)return e.value}function T(e,...t){var i;let n=e;for(let e=0;e<t.length&&n;e++)n=null===(i=null==n?void 0:n.extension)||void 0===i?void 0:i.find((i=>i.url===t[e]));return null==n?void 0:n.valueString}function C(e,t){return JSON.stringify(e,P,t?2:void 0)}function P(e,t){return!function(e){return!!e.match(/\d+$/)}(e)&&A(t)?void 0:t}function A(e){if(null==e)return!0;const t=typeof e;return"string"===t&&""===e||"object"===t&&0===Object.keys(e).length}function R(e,t,i){return e===t||(!(!A(e)||!A(t))||!A(e)&&!A(t)&&(Array.isArray(e)&&Array.isArray(t)?function(e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!R(e[i],t[i]))return!1;return!0}(e,t):!Array.isArray(e)&&!Array.isArray(t)&&(I(e)&&I(t)?function(e,t,i){const n=new Set;Object.keys(e).forEach((e=>n.add(e))),Object.keys(t).forEach((e=>n.add(e))),"meta"===i&&(n.delete("versionId"),n.delete("lastUpdated"),n.delete("author"));for(const i of n){if(!R(e[i],t[i],i))return!1}return!0}(e,t,i):(I(e)||I(t),!1))))}function k(e){return!!e.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)}function I(e){return null!==e&&"object"==typeof e}function M(e){return e.every((e=>"string"==typeof e))}o=new WeakMap,r=new WeakMap,n=new WeakSet,a=function(){return t(this,r,"f").keys().next().value};const O=[];for(let e=0;e<256;e++)O.push(e.toString(16).padStart(2,"0"));function U(e){const t=new Uint8Array(e),i=new Array(t.length);for(let e=0;e<t.length;e++)i[e]=O[t[e]];return i.join("")}function L(e){const t=new Uint8Array(e),i=[];for(let e=0;e<t.length;e++)i[e]=String.fromCharCode(t[e]);return window.btoa(i.join(""))}function j(e){return e.charAt(0).toUpperCase()+e.substring(1)}function N(e){return e===e.toLowerCase()}function _(e,t){var i,n;return null===(n=null===(i=null==e?void 0:e.coding)||void 0===i?void 0:i.find((e=>e.system===t)))||void 0===n?void 0:n.code}function Q(e,t,i){var n,o;e.coding||(e.coding=[]);const r=null===(n=e.coding)||void 0===n?void 0:n.find((e=>e.system===t));r?r.code=i:null===(o=e.coding)||void 0===o||o.push({system:t,code:i})}function W(e,t,i,n){var o;return null===(o=e.qualifiedInterval)||void 0===o?void 0:o.find((o=>{var r;return function(e,t){return function(e,t){return!e.gender||e.gender===t.gender}(e,t)&&function(e,t){return!e.age||B(w(t.birthDate).years,e.age)}(e,t)}(o,t)&&function(e,t,i){return!!e.range&&B(t,e.range,i)}(o,i,null===(r=e.quantitativeDetails)||void 0===r?void 0:r.decimalPrecision)&&(void 0===n||o.category===n)}))}function B(e,t,i){var n,o;return(void 0===(null===(n=t.low)||void 0===n?void 0:n.value)||z(e,t.low.value,i))&&(void 0===(null===(o=t.high)||void 0===o?void 0:o.value)||H(e,t.high.value,i))}function q(e,t,i){return i?Math.abs(e-t)<Math.pow(10,-i):e===t}function F(e,t,i){return i?e<t&&Math.abs(e-t)>Math.pow(10,-i):e<t}function $(e,t,i){return i?e>t&&Math.abs(e-t)>Math.pow(10,-i):e>t}function H(e,t,i){return F(e,t,i)||q(e,t,i)}function z(e,t,i){return $(e,t,i)||q(e,t,i)}function V(){const e=new Uint32Array(28);return crypto.getRandomValues(e),U(e.buffer)}var G,X,Y,K,J,Z,ee,te;function ie(e){const t=function(e){if("undefined"!=typeof window)return window.atob(e);if("undefined"!=typeof Buffer)return Buffer.from(e,"base64").toString("binary");throw new Error("Unable to decode base64")}(e.replace(/-/g,"+").replace(/_/g,"/")),i=Array.from(t).reduce(((e,t)=>`${e}%${("00"+t.charCodeAt(0).toString(16)).slice(-2)}`),""),n=decodeURIComponent(i);return JSON.parse(n)}G=new WeakMap;class ne{constructor(e){this[Z]="ReadablePromise",X.set(this,void 0),Y.set(this,"pending"),K.set(this,void 0),J.set(this,void 0),i(this,X,e.then((e=>(i(this,Y,"success","f"),i(this,K,e,"f"),e)),(e=>{throw i(this,Y,"error","f"),i(this,J,e,"f"),e})),"f")}isPending(){return"pending"===t(this,Y,"f")}isOk(){return"success"===t(this,Y,"f")}read(){switch(t(this,Y,"f")){case"pending":throw t(this,X,"f");case"error":throw t(this,J,"f");default:return t(this,K,"f")}}then(e,i){return t(this,X,"f").then(e,i)}catch(e){return t(this,X,"f").catch(e)}finally(e){return t(this,X,"f").finally(e)}}X=new WeakMap,Y=new WeakMap,K=new WeakMap,J=new WeakMap,Z=Symbol.toStringTag;class oe{constructor(){ee.set(this,void 0),i(this,ee,"undefined"!=typeof localStorage?localStorage:new re,"f")}clear(){t(this,ee,"f").clear()}getString(e){return t(this,ee,"f").getItem(e)||void 0}setString(e,i){i?t(this,ee,"f").setItem(e,i):t(this,ee,"f").removeItem(e)}getObject(e){const t=this.getString(e);return t?JSON.parse(t):void 0}setObject(e,t){this.setString(e,t?C(t):void 0)}}ee=new WeakMap;class re{constructor(){te.set(this,void 0),i(this,te,new Map,"f")}get length(){return t(this,te,"f").size}clear(){t(this,te,"f").clear()}getItem(e){var i;return null!==(i=t(this,te,"f").get(e))&&void 0!==i?i:null}setItem(e,i){i?t(this,te,"f").set(e,i):t(this,te,"f").delete(e)}removeItem(e){t(this,te,"f").delete(e)}key(e){return Array.from(t(this,te,"f").keys())[e]}}te=new WeakMap;var ae,se={types:{Element:{display:"Element",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]}}},BackboneElement:{display:"BackboneElement",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]}}},Address:{display:"Address",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},use:{min:0,max:"1",type:[{code:"code"}]},type:{min:0,max:"1",type:[{code:"code"}]},text:{min:0,max:"1",type:[{code:"string"}]},line:{min:0,max:"*",type:[{code:"string"}]},city:{min:0,max:"1",type:[{code:"string"}]},district:{min:0,max:"1",type:[{code:"string"}]},state:{min:0,max:"1",type:[{code:"string"}]},postalCode:{min:0,max:"1",type:[{code:"string"}]},country:{min:0,max:"1",type:[{code:"string"}]},period:{min:0,max:"1",type:[{code:"Period"}]}}},Age:{display:"Age",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},value:{min:0,max:"1",type:[{code:"decimal"}]},comparator:{min:0,max:"1",type:[{code:"code"}]},unit:{min:0,max:"1",type:[{code:"string"}]},system:{min:0,max:"1",type:[{code:"uri"}]},code:{min:0,max:"1",type:[{code:"code"}]}}},Annotation:{display:"Annotation",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},"author[x]":{min:0,max:"1",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:{min:0,max:"1",type:[{code:"dateTime"}]},text:{min:1,max:"1",type:[{code:"markdown"}]}}},Attachment:{display:"Attachment",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},contentType:{min:0,max:"1",type:[{code:"code"}]},language:{min:0,max:"1",type:[{code:"code"}]},data:{min:0,max:"1",type:[{code:"base64Binary"}]},url:{min:0,max:"1",type:[{code:"url"}]},size:{min:0,max:"1",type:[{code:"unsignedInt"}]},hash:{min:0,max:"1",type:[{code:"base64Binary"}]},title:{min:0,max:"1",type:[{code:"string"}]},creation:{min:0,max:"1",type:[{code:"dateTime"}]}}},CodeableConcept:{display:"CodeableConcept",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},coding:{min:0,max:"*",type:[{code:"Coding"}]},text:{min:0,max:"1",type:[{code:"string"}]}}},Coding:{display:"Coding",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},system:{min:0,max:"1",type:[{code:"uri"}]},version:{min:0,max:"1",type:[{code:"string"}]},code:{min:0,max:"1",type:[{code:"code"}]},display:{min:0,max:"1",type:[{code:"string"}]},userSelected:{min:0,max:"1",type:[{code:"boolean"}]}}},ContactDetail:{display:"ContactDetail",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},name:{min:0,max:"1",type:[{code:"string"}]},telecom:{min:0,max:"*",type:[{code:"ContactPoint"}]}}},ContactPoint:{display:"ContactPoint",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},system:{min:0,max:"1",type:[{code:"code"}]},value:{min:0,max:"1",type:[{code:"string"}]},use:{min:0,max:"1",type:[{code:"code"}]},rank:{min:0,max:"1",type:[{code:"positiveInt"}]},period:{min:0,max:"1",type:[{code:"Period"}]}}},Contributor:{display:"Contributor",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},type:{min:1,max:"1",type:[{code:"code"}]},name:{min:1,max:"1",type:[{code:"string"}]},contact:{min:0,max:"*",type:[{code:"ContactDetail"}]}}},Count:{display:"Count",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},value:{min:0,max:"1",type:[{code:"decimal"}]},comparator:{min:0,max:"1",type:[{code:"code"}]},unit:{min:0,max:"1",type:[{code:"string"}]},system:{min:0,max:"1",type:[{code:"uri"}]},code:{min:0,max:"1",type:[{code:"code"}]}}},DataRequirement:{display:"DataRequirement",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},type:{min:1,max:"1",type:[{code:"code"}]},profile:{min:0,max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},"subject[x]":{min:0,max:"1",type:[{code:"CodeableConcept"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Group"]}]},mustSupport:{min:0,max:"*",type:[{code:"string"}]},codeFilter:{min:0,max:"*",type:[{code:"Element"}]},dateFilter:{min:0,max:"*",type:[{code:"Element"}]},limit:{min:0,max:"1",type:[{code:"positiveInt"}]},sort:{min:0,max:"*",type:[{code:"Element"}]}}},DataRequirementCodeFilter:{display:"DataRequirementCodeFilter",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},path:{min:0,max:"1",type:[{code:"string"}]},searchParam:{min:0,max:"1",type:[{code:"string"}]},valueSet:{min:0,max:"1",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]},code:{min:0,max:"*",type:[{code:"Coding"}]}},parentType:"DataRequirement"},DataRequirementDateFilter:{display:"DataRequirementDateFilter",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},path:{min:0,max:"1",type:[{code:"string"}]},searchParam:{min:0,max:"1",type:[{code:"string"}]},"value[x]":{min:0,max:"1",type:[{code:"dateTime"},{code:"Period"},{code:"Duration"}]}},parentType:"DataRequirement"},DataRequirementSort:{display:"DataRequirementSort",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},path:{min:1,max:"1",type:[{code:"string"}]},direction:{min:1,max:"1",type:[{code:"code"}]}},parentType:"DataRequirement"},Distance:{display:"Distance",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},value:{min:0,max:"1",type:[{code:"decimal"}]},comparator:{min:0,max:"1",type:[{code:"code"}]},unit:{min:0,max:"1",type:[{code:"string"}]},system:{min:0,max:"1",type:[{code:"uri"}]},code:{min:0,max:"1",type:[{code:"code"}]}}},Dosage:{display:"Dosage",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},sequence:{min:0,max:"1",type:[{code:"integer"}]},text:{min:0,max:"1",type:[{code:"string"}]},additionalInstruction:{min:0,max:"*",type:[{code:"CodeableConcept"}]},patientInstruction:{min:0,max:"1",type:[{code:"string"}]},timing:{min:0,max:"1",type:[{code:"Timing"}]},"asNeeded[x]":{min:0,max:"1",type:[{code:"boolean"},{code:"CodeableConcept"}]},site:{min:0,max:"1",type:[{code:"CodeableConcept"}]},route:{min:0,max:"1",type:[{code:"CodeableConcept"}]},method:{min:0,max:"1",type:[{code:"CodeableConcept"}]},doseAndRate:{min:0,max:"*",type:[{code:"Element"}]},maxDosePerPeriod:{min:0,max:"1",type:[{code:"Ratio"}]},maxDosePerAdministration:{min:0,max:"1",type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},maxDosePerLifetime:{min:0,max:"1",type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},DosageDoseAndRate:{display:"DosageDoseAndRate",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},type:{min:0,max:"1",type:[{code:"CodeableConcept"}]},"dose[x]":{min:0,max:"1",type:[{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},"rate[x]":{min:0,max:"1",type:[{code:"Ratio"},{code:"Range"},{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}},parentType:"Dosage"},Duration:{display:"Duration",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},value:{min:0,max:"1",type:[{code:"decimal"}]},comparator:{min:0,max:"1",type:[{code:"code"}]},unit:{min:0,max:"1",type:[{code:"string"}]},system:{min:0,max:"1",type:[{code:"uri"}]},code:{min:0,max:"1",type:[{code:"code"}]}}},ElementDefinition:{display:"ElementDefinition",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},path:{min:1,max:"1",type:[{code:"string"}]},representation:{min:0,max:"*",type:[{code:"code"}]},sliceName:{min:0,max:"1",type:[{code:"string"}]},sliceIsConstraining:{min:0,max:"1",type:[{code:"boolean"}]},label:{min:0,max:"1",type:[{code:"string"}]},code:{min:0,max:"*",type:[{code:"Coding"}]},slicing:{min:0,max:"1",type:[{code:"Element"}]},short:{min:0,max:"1",type:[{code:"string"}]},definition:{min:0,max:"1",type:[{code:"markdown"}]},comment:{min:0,max:"1",type:[{code:"markdown"}]},requirements:{min:0,max:"1",type:[{code:"markdown"}]},alias:{min:0,max:"*",type:[{code:"string"}]},min:{min:0,max:"1",type:[{code:"unsignedInt"}]},max:{min:0,max:"1",type:[{code:"string"}]},base:{min:0,max:"1",type:[{code:"Element"}]},contentReference:{min:0,max:"1",type:[{code:"uri"}]},type:{min:0,max:"*",type:[{code:"Element"}]},"defaultValue[x]":{min:0,max:"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"}]},meaningWhenMissing:{min:0,max:"1",type:[{code:"markdown"}]},orderMeaning:{min:0,max:"1",type:[{code:"string"}]},"fixed[x]":{min:0,max:"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"}]},"pattern[x]":{min:0,max:"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"}]},example:{min:0,max:"*",type:[{code:"Element"}]},"minValue[x]":{min:0,max:"1",type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},"maxValue[x]":{min:0,max:"1",type:[{code:"date"},{code:"dateTime"},{code:"instant"},{code:"time"},{code:"decimal"},{code:"integer"},{code:"positiveInt"},{code:"unsignedInt"},{code:"Quantity"}]},maxLength:{min:0,max:"1",type:[{code:"integer"}]},condition:{min:0,max:"*",type:[{code:"id"}]},constraint:{min:0,max:"*",type:[{code:"Element"}]},mustSupport:{min:0,max:"1",type:[{code:"boolean"}]},isModifier:{min:0,max:"1",type:[{code:"boolean"}]},isModifierReason:{min:0,max:"1",type:[{code:"string"}]},isSummary:{min:0,max:"1",type:[{code:"boolean"}]},binding:{min:0,max:"1",type:[{code:"Element"}]},mapping:{min:0,max:"*",type:[{code:"Element"}]}}},ElementDefinitionSlicing:{display:"ElementDefinitionSlicing",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},discriminator:{min:0,max:"*",type:[{code:"Element"}]},description:{min:0,max:"1",type:[{code:"string"}]},ordered:{min:0,max:"1",type:[{code:"boolean"}]},rules:{min:1,max:"1",type:[{code:"code"}]}},parentType:"ElementDefinition"},ElementDefinitionSlicingDiscriminator:{display:"ElementDefinitionSlicingDiscriminator",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},type:{min:1,max:"1",type:[{code:"code"}]},path:{min:1,max:"1",type:[{code:"string"}]}},parentType:"ElementDefinitionSlicing"},ElementDefinitionBase:{display:"ElementDefinitionBase",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},path:{min:1,max:"1",type:[{code:"string"}]},min:{min:1,max:"1",type:[{code:"unsignedInt"}]},max:{min:1,max:"1",type:[{code:"string"}]}},parentType:"ElementDefinition"},ElementDefinitionType:{display:"ElementDefinitionType",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},code:{min:1,max:"1",type:[{code:"uri"}]},profile:{min:0,max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},targetProfile:{min:0,max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition","http://hl7.org/fhir/StructureDefinition/ImplementationGuide"]}]},aggregation:{min:0,max:"*",type:[{code:"code"}]},versioning:{min:0,max:"1",type:[{code:"code"}]}},parentType:"ElementDefinition"},ElementDefinitionExample:{display:"ElementDefinitionExample",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},label:{min:1,max:"1",type:[{code:"string"}]},"value[x]":{min:1,max:"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"}]}},parentType:"ElementDefinition"},ElementDefinitionConstraint:{display:"ElementDefinitionConstraint",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},key:{min:1,max:"1",type:[{code:"id"}]},requirements:{min:0,max:"1",type:[{code:"string"}]},severity:{min:1,max:"1",type:[{code:"code"}]},human:{min:1,max:"1",type:[{code:"string"}]},expression:{min:0,max:"1",type:[{code:"string"}]},xpath:{min:0,max:"1",type:[{code:"string"}]},source:{min:0,max:"1",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}},parentType:"ElementDefinition"},ElementDefinitionBinding:{display:"ElementDefinitionBinding",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},strength:{min:1,max:"1",type:[{code:"code"}]},description:{min:0,max:"1",type:[{code:"string"}]},valueSet:{min:0,max:"1",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/ValueSet"]}]}},parentType:"ElementDefinition"},ElementDefinitionMapping:{display:"ElementDefinitionMapping",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},identity:{min:1,max:"1",type:[{code:"id"}]},language:{min:0,max:"1",type:[{code:"code"}]},map:{min:1,max:"1",type:[{code:"string"}]},comment:{min:0,max:"1",type:[{code:"string"}]}},parentType:"ElementDefinition"},Expression:{display:"Expression",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},description:{min:0,max:"1",type:[{code:"string"}]},name:{min:0,max:"1",type:[{code:"id"}]},language:{min:1,max:"1",type:[{code:"code"}]},expression:{min:0,max:"1",type:[{code:"string"}]},reference:{min:0,max:"1",type:[{code:"uri"}]}}},Extension:{display:"Extension",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},url:{min:1,max:"1",type:[{code:"string"}]},"value[x]":{min:0,max:"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"}]}}},HumanName:{display:"HumanName",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},use:{min:0,max:"1",type:[{code:"code"}]},text:{min:0,max:"1",type:[{code:"string"}]},family:{min:0,max:"1",type:[{code:"string"}]},given:{min:0,max:"*",type:[{code:"string"}]},prefix:{min:0,max:"*",type:[{code:"string"}]},suffix:{min:0,max:"*",type:[{code:"string"}]},period:{min:0,max:"1",type:[{code:"Period"}]}}},Identifier:{display:"Identifier",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},use:{min:0,max:"1",type:[{code:"code"}]},type:{min:0,max:"1",type:[{code:"CodeableConcept"}]},system:{min:0,max:"1",type:[{code:"uri"}]},value:{min:0,max:"1",type:[{code:"string"}]},period:{min:0,max:"1",type:[{code:"Period"}]},assigner:{min:0,max:"1",type:[{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Organization"]}]}}},MarketingStatus:{display:"MarketingStatus",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},country:{min:1,max:"1",type:[{code:"CodeableConcept"}]},jurisdiction:{min:0,max:"1",type:[{code:"CodeableConcept"}]},status:{min:1,max:"1",type:[{code:"CodeableConcept"}]},dateRange:{min:1,max:"1",type:[{code:"Period"}]},restoreDate:{min:0,max:"1",type:[{code:"dateTime"}]}}},Meta:{display:"Meta",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},versionId:{min:0,max:"1",type:[{code:"id"}]},lastUpdated:{min:0,max:"1",type:[{code:"instant"}]},source:{min:0,max:"1",type:[{code:"uri"}]},profile:{min:0,max:"*",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]},security:{min:0,max:"*",type:[{code:"Coding"}]},tag:{min:0,max:"*",type:[{code:"Coding"}]},project:{min:0,max:"1",type:[{code:"uri"}]},author:{min:0,max:"1",type:[{code:"Reference"}]},account:{min:0,max:"1",type:[{code:"Reference"}]}}},Money:{display:"Money",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},value:{min:0,max:"1",type:[{code:"decimal"}]},currency:{min:0,max:"1",type:[{code:"code"}]}}},Narrative:{display:"Narrative",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},status:{min:1,max:"1",type:[{code:"code"}]},div:{min:1,max:"1",type:[{code:"xhtml"}]}}},ParameterDefinition:{display:"ParameterDefinition",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},name:{min:0,max:"1",type:[{code:"code"}]},use:{min:1,max:"1",type:[{code:"code"}]},min:{min:0,max:"1",type:[{code:"integer"}]},max:{min:0,max:"1",type:[{code:"string"}]},documentation:{min:0,max:"1",type:[{code:"string"}]},type:{min:1,max:"1",type:[{code:"code"}]},profile:{min:0,max:"1",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/StructureDefinition"]}]}}},Period:{display:"Period",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},start:{min:0,max:"1",type:[{code:"dateTime"}]},end:{min:0,max:"1",type:[{code:"dateTime"}]}}},Population:{display:"Population",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},"age[x]":{min:0,max:"1",type:[{code:"Range"},{code:"CodeableConcept"}]},gender:{min:0,max:"1",type:[{code:"CodeableConcept"}]},race:{min:0,max:"1",type:[{code:"CodeableConcept"}]},physiologicalCondition:{min:0,max:"1",type:[{code:"CodeableConcept"}]}}},ProdCharacteristic:{display:"ProdCharacteristic",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},height:{min:0,max:"1",type:[{code:"Quantity"}]},width:{min:0,max:"1",type:[{code:"Quantity"}]},depth:{min:0,max:"1",type:[{code:"Quantity"}]},weight:{min:0,max:"1",type:[{code:"Quantity"}]},nominalVolume:{min:0,max:"1",type:[{code:"Quantity"}]},externalDiameter:{min:0,max:"1",type:[{code:"Quantity"}]},shape:{min:0,max:"1",type:[{code:"string"}]},color:{min:0,max:"*",type:[{code:"string"}]},imprint:{min:0,max:"*",type:[{code:"string"}]},image:{min:0,max:"*",type:[{code:"Attachment"}]},scoring:{min:0,max:"1",type:[{code:"CodeableConcept"}]}}},ProductShelfLife:{display:"ProductShelfLife",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},identifier:{min:0,max:"1",type:[{code:"Identifier"}]},type:{min:1,max:"1",type:[{code:"CodeableConcept"}]},period:{min:1,max:"1",type:[{code:"Quantity"}]},specialPrecautionsForStorage:{min:0,max:"*",type:[{code:"CodeableConcept"}]}}},Quantity:{display:"Quantity",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},value:{min:0,max:"1",type:[{code:"decimal"}]},comparator:{min:0,max:"0",type:[{code:"code"}]},unit:{min:0,max:"1",type:[{code:"string"}]},system:{min:0,max:"1",type:[{code:"uri"}]},code:{min:0,max:"1",type:[{code:"code"}]}}},Range:{display:"Range",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},low:{min:0,max:"1",type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},high:{min:0,max:"1",type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]}}},Ratio:{display:"Ratio",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},numerator:{min:0,max:"1",type:[{code:"Quantity"}]},denominator:{min:0,max:"1",type:[{code:"Quantity"}]}}},Reference:{display:"Reference",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},reference:{min:0,max:"1",type:[{code:"string"}]},type:{min:0,max:"1",type:[{code:"uri"}]},identifier:{min:0,max:"1",type:[{code:"Identifier"}]},display:{min:0,max:"1",type:[{code:"string"}]}}},RelatedArtifact:{display:"RelatedArtifact",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},type:{min:1,max:"1",type:[{code:"code"}]},label:{min:0,max:"1",type:[{code:"string"}]},display:{min:0,max:"1",type:[{code:"string"}]},citation:{min:0,max:"1",type:[{code:"markdown"}]},url:{min:0,max:"1",type:[{code:"url"}]},document:{min:0,max:"1",type:[{code:"Attachment"}]},resource:{min:0,max:"1",type:[{code:"canonical",targetProfile:["http://hl7.org/fhir/StructureDefinition/Resource"]}]}}},SampledData:{display:"SampledData",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},origin:{min:1,max:"1",type:[{code:"Quantity",profile:["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"]}]},period:{min:1,max:"1",type:[{code:"decimal"}]},factor:{min:0,max:"1",type:[{code:"decimal"}]},lowerLimit:{min:0,max:"1",type:[{code:"decimal"}]},upperLimit:{min:0,max:"1",type:[{code:"decimal"}]},dimensions:{min:1,max:"1",type:[{code:"positiveInt"}]},data:{min:0,max:"1",type:[{code:"string"}]}}},Signature:{display:"Signature",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},type:{min:1,max:"*",type:[{code:"Coding"}]},when:{min:1,max:"1",type:[{code:"instant"}]},who:{min:1,max:"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:{min:0,max:"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"]}]},targetFormat:{min:0,max:"1",type:[{code:"code"}]},sigFormat:{min:0,max:"1",type:[{code:"code"}]},data:{min:0,max:"1",type:[{code:"base64Binary"}]}}},SubstanceAmount:{display:"SubstanceAmount",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},"amount[x]":{min:0,max:"1",type:[{code:"Quantity"},{code:"Range"},{code:"string"}]},amountType:{min:0,max:"1",type:[{code:"CodeableConcept"}]},amountText:{min:0,max:"1",type:[{code:"string"}]},referenceRange:{min:0,max:"1",type:[{code:"Element"}]}}},SubstanceAmountReferenceRange:{display:"SubstanceAmountReferenceRange",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},lowLimit:{min:0,max:"1",type:[{code:"Quantity"}]},highLimit:{min:0,max:"1",type:[{code:"Quantity"}]}},parentType:"SubstanceAmount"},Timing:{display:"Timing",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},modifierExtension:{min:0,max:"*",type:[{code:"Extension"}]},event:{min:0,max:"*",type:[{code:"dateTime"}]},repeat:{min:0,max:"1",type:[{code:"Element"}]},code:{min:0,max:"1",type:[{code:"CodeableConcept"}]}}},TimingRepeat:{display:"TimingRepeat",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},"bounds[x]":{min:0,max:"1",type:[{code:"Duration"},{code:"Range"},{code:"Period"}]},count:{min:0,max:"1",type:[{code:"positiveInt"}]},countMax:{min:0,max:"1",type:[{code:"positiveInt"}]},duration:{min:0,max:"1",type:[{code:"decimal"}]},durationMax:{min:0,max:"1",type:[{code:"decimal"}]},durationUnit:{min:0,max:"1",type:[{code:"code"}]},frequency:{min:0,max:"1",type:[{code:"positiveInt"}]},frequencyMax:{min:0,max:"1",type:[{code:"positiveInt"}]},period:{min:0,max:"1",type:[{code:"decimal"}]},periodMax:{min:0,max:"1",type:[{code:"decimal"}]},periodUnit:{min:0,max:"1",type:[{code:"code"}]},dayOfWeek:{min:0,max:"*",type:[{code:"code"}]},timeOfDay:{min:0,max:"*",type:[{code:"time"}]},when:{min:0,max:"*",type:[{code:"code"}]},offset:{min:0,max:"1",type:[{code:"unsignedInt"}]}},parentType:"Timing"},TriggerDefinition:{display:"TriggerDefinition",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},type:{min:1,max:"1",type:[{code:"code"}]},name:{min:0,max:"1",type:[{code:"string"}]},"timing[x]":{min:0,max:"1",type:[{code:"Timing"},{code:"Reference",targetProfile:["http://hl7.org/fhir/StructureDefinition/Schedule"]},{code:"date"},{code:"dateTime"}]},data:{min:0,max:"*",type:[{code:"DataRequirement"}]},condition:{min:0,max:"1",type:[{code:"Expression"}]}}},UsageContext:{display:"UsageContext",properties:{id:{min:0,max:"1",type:[{code:"string"}]},extension:{min:0,max:"*",type:[{code:"Extension"}]},code:{min:1,max:"1",type:[{code:"Coding"}]},"value[x]":{min:1,max:"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"]}]}}}}};function ce(){return{types:{}}}function de(e,t){return{display:e,description:t,properties:{},searchParams:{_lastUpdated:{base:[e],code:"_lastUpdated",type:"date",expression:e+".meta.lastUpdated"}}}}function le(e){for(const t of e.entry){const e=t.resource;"StructureDefinition"===e.resourceType&&ue(fe,e)}}function ue(e,t){var i;const n=t.name;if(!n)return;n in e.types||(e.types[n]=de(n,t.description));const o=null===(i=t.snapshot)||void 0===i?void 0:i.element;if(o){const t=o.filter((e=>e.path!==n&&e.path));t.forEach((t=>function(e,t){var i,n;const o=t.path,r=null===(n=null===(i=t.type)||void 0===i?void 0:i[0])||void 0===n?void 0:n.code;if("Element"!==r&&"BackboneElement"!==r)return;const a=o.split("."),s=pe(a);s in e.types||(e.types[s]=de(s,t.definition),e.types[s].parentType=pe(a.slice(0,a.length-1)))}(e,t))),t.forEach((t=>function(e,t){const i=t.path.split(".");if(1===i.length)return;const n=pe(i.slice(0,i.length-1)),o=e.types[n];if(!o)return;const r=i[i.length-1];o.properties[r]=t}(e,t)))}}function me(e,t){if(t.base)for(const i of t.base){const n=e.types[i];n&&(n.searchParams||(n.searchParams={}),n.searchParams[t.code]=t)}}function pe(e){return e.map(j).join("")}function he(e){const t=e.replaceAll("[x]","").split(".").pop();return"id"===t?"ID":t.split(/(?=[A-Z])/).map(j).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"}(ae||(ae={}));const fe=se;var ye,ge,xe,ve,we,Ee,Se,be,De,Te,Ce,Pe,Ae,Re,ke,Ie,Me,Oe,Ue,Le,je,Ne,_e,Qe,We,Be,qe,Fe,$e,He,ze,Ve,Ge;const Xe="launch/patient openid fhirUser offline_access user/*.*";class Ye extends class{constructor(){G.set(this,void 0),i(this,G,{},"f")}addEventListener(e,i){t(this,G,"f")[e]||(t(this,G,"f")[e]=[]),t(this,G,"f")[e].push(i)}removeEventListeneer(e,i){const n=t(this,G,"f")[e];if(n)for(let e=0;e<n.length;e++)if(n[e]===i)return void n.splice(e,1)}dispatchEvent(e){const i=t(this,G,"f")[e.type];return i&&i.forEach((t=>t.call(this,e))),!e.defaultPrevented}}{constructor(e){var n,o;if(super(),ye.add(this),ge.set(this,void 0),xe.set(this,void 0),ve.set(this,void 0),we.set(this,void 0),Ee.set(this,void 0),Se.set(this,void 0),be.set(this,void 0),De.set(this,void 0),Te.set(this,void 0),Ce.set(this,void 0),Pe.set(this,void 0),Ae.set(this,void 0),Re.set(this,void 0),ke.set(this,void 0),Ie.set(this,void 0),Me.set(this,void 0),Oe.set(this,void 0),null==e?void 0:e.baseUrl){if(!e.baseUrl.startsWith("http"))throw new Error("Base URL must start with http or https");if(!e.baseUrl.endsWith("/"))throw new Error("Base URL must end with a trailing slash")}i(this,ge,(null==e?void 0:e.fetch)||window.fetch.bind(window),"f"),i(this,xe,null==e?void 0:e.createPdf,"f"),i(this,ve,new oe,"f"),i(this,we,new s(null!==(n=null==e?void 0:e.resourceCacheSize)&&void 0!==n?n:1e3),"f"),i(this,Ee,null!==(o=null==e?void 0:e.cacheTime)&&void 0!==o?o:1e4,"f"),i(this,Se,(null==e?void 0:e.baseUrl)||"https://api.medplum.com/","f"),i(this,be,(null==e?void 0:e.clientId)||"","f"),i(this,De,(null==e?void 0:e.authorizeUrl)||t(this,Se,"f")+"oauth2/authorize","f"),i(this,Te,(null==e?void 0:e.tokenUrl)||t(this,Se,"f")+"oauth2/token","f"),i(this,Ce,(null==e?void 0:e.logoutUrl)||t(this,Se,"f")+"oauth2/logout","f"),i(this,Pe,null==e?void 0:e.onUnauthenticated,"f");const r=this.getActiveLogin();r&&(i(this,Ae,r.accessToken,"f"),i(this,Re,r.refreshToken,"f"),t(this,ye,"m",Le).call(this).catch(console.log)),t(this,ye,"m",Ge).call(this)}getBaseUrl(){return t(this,Se,"f")}clear(){t(this,ve,"f").clear(),t(this,we,"f").clear(),i(this,Ae,void 0,"f"),i(this,Re,void 0,"f"),i(this,Me,void 0,"f"),i(this,Oe,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(e){e=e.toString(),t(this,we,"f").delete(e)}invalidateSearches(e){const i="fhir/R4/"+e;for(const e of t(this,we,"f").keys())(e.endsWith(i)||e.includes(i+"?"))&&t(this,we,"f").delete(e)}get(e,i={}){e=e.toString();const n=t(this,ye,"m",je).call(this,e,i);if(n)return n.value;const o=new ne(t(this,ye,"m",_e).call(this,"GET",e,i));return t(this,ye,"m",Ne).call(this,e,o),o}post(e,i,n,o={}){return e=e.toString(),i&&t(this,ye,"m",Be).call(this,o,i),n&&t(this,ye,"m",We).call(this,o,n),this.invalidateUrl(e),t(this,ye,"m",_e).call(this,"POST",e,o)}put(e,i,n,o={}){return e=e.toString(),i&&t(this,ye,"m",Be).call(this,o,i),n&&t(this,ye,"m",We).call(this,o,n),this.invalidateUrl(e),t(this,ye,"m",_e).call(this,"PUT",e,o)}patch(e,i,n={}){return e=e.toString(),t(this,ye,"m",Be).call(this,n,i),t(this,ye,"m",We).call(this,n,"application/json-patch+json"),this.invalidateUrl(e),t(this,ye,"m",_e).call(this,"PATCH",e,n)}delete(e,i={}){return e=e.toString(),this.invalidateUrl(e),t(this,ye,"m",_e).call(this,"DELETE",e,i)}register(t){return e(this,void 0,void 0,(function*(){const e=yield this.post("auth/register",t);yield this.setActiveLogin(e)}))}startLogin(i){return e(this,void 0,void 0,(function*(){return yield t(this,ye,"m",Fe).call(this),this.post("auth/login",Object.assign(Object.assign({},i),{clientId:t(this,be,"f"),scope:Xe,codeChallengeMethod:"S256",codeChallenge:t(this,ve,"f").getString("codeChallenge")}))}))}startGoogleLogin(i){return e(this,void 0,void 0,(function*(){return yield t(this,ye,"m",Fe).call(this),this.post("auth/google",i)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const e=new URLSearchParams(window.location.search).get("code");return e?this.processCode(e):void t(this,ye,"m",$e).call(this)}signOutWithRedirect(){window.location.assign(t(this,Ce,"f"))}fhirUrl(...e){return new URL(t(this,Se,"f")+"fhir/R4/"+e.join("/"))}fhirSearchUrl(e,t){const i=this.fhirUrl(e);return t&&(i.search=t.toString()),i}search(e,t,i={}){return this.get(this.fhirSearchUrl(e,t),i)}searchOne(e,i,n={}){const o=this.fhirSearchUrl(e,i);o.searchParams.set("_count","1"),o.searchParams.sort();const r=o.toString()+"-searchOne",a=t(this,ye,"m",je).call(this,r,n);if(a)return a.value;const s=new ne(this.search(e,o.searchParams,n).then((e=>{var t,i;return null===(i=null===(t=e.entry)||void 0===t?void 0:t[0])||void 0===i?void 0:i.resource})));return t(this,ye,"m",Ne).call(this,r,s),s}searchResources(e,i,n={}){const o=this.fhirSearchUrl(e,i).toString()+"-searchResources",r=t(this,ye,"m",je).call(this,o,n);if(r)return r.value;const a=new ne(this.search(e,i,n).then((e=>{var t,i;return null!==(i=null===(t=e.entry)||void 0===t?void 0:t.map((e=>e.resource)))&&void 0!==i?i:[]})));return t(this,ye,"m",Ne).call(this,o,a),a}searchValueSet(e,t,i={}){const n=this.fhirUrl("ValueSet","$expand");return n.searchParams.set("url",e),n.searchParams.set("filter",t),this.get(n.toString(),i)}getCached(e,i){var n;const o=null===(n=t(this,we,"f").get(this.fhirUrl(e,i).toString()))||void 0===n?void 0:n.value;return o&&o.isOk()?o.read():void 0}getCachedReference(e){const t=e.reference;if(!t)return;const[i,n]=t.split("/");return i&&n?this.getCached(i,n):void 0}readResource(e,t){return this.get(this.fhirUrl(e,t))}readReference(e){const t=null==e?void 0:e.reference;if(!t)return new ne(Promise.reject(new Error("Missing reference")));const[i,n]=t.split("/");return i&&n?this.readResource(i,n):new ne(Promise.reject(new Error("Invalid reference")))}getSchema(){return fe}requestSchema(t){return e(this,void 0,void 0,(function*(){if(t in fe.types)return fe;const e=`{\n StructureDefinitionList(name: "${t}") {\n name,\n description,\n snapshot {\n element {\n id,\n path,\n min,\n max,\n type {\n code,\n targetProfile\n },\n binding {\n valueSet\n },\n definition\n }\n }\n }\n SearchParameterList(base: "${t}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),i=yield this.graphql(e);for(const e of i.data.StructureDefinitionList)ue(fe,e);for(const e of i.data.SearchParameterList)me(fe,e);return fe}))}readHistory(e,t){return this.get(this.fhirUrl(e,t,"_history"))}readVersion(e,t,i){return this.get(this.fhirUrl(e,t,"_history",i))}readPatientEverything(e){return this.get(this.fhirUrl("Patient",e,"$everything"))}createResource(e){if(!e.resourceType)throw new Error("Missing resourceType");return this.invalidateSearches(e.resourceType),this.post(this.fhirUrl(e.resourceType),e)}createResourceIfNoneExist(t,i){var n;return e(this,void 0,void 0,(function*(){return null!==(n=yield this.searchOne(t.resourceType,i))&&void 0!==n?n:this.createResource(t)}))}createBinary(e,t,i){const n=this.fhirUrl("Binary");return t&&n.searchParams.set("_filename",t),this.post(n,e,i)}createPdf(i,n,o,r){return e(this,void 0,void 0,(function*(){if(!t(this,xe,"f"))throw new Error("PDF creation not enabled");const e=yield t(this,xe,"f").call(this,i,o,r);return this.createBinary(e,n,"application/pdf")}))}createComment(e,t){const i=this.getProfile();let n,o;return"Encounter"===e.resourceType&&(n=m(e),o=e.subject),"ServiceRequest"===e.resourceType&&(n=e.encounter,o=e.subject),"Patient"===e.resourceType&&(o=m(e)),this.createResource({resourceType:"Communication",basedOn:[m(e)],encounter:n,subject:o,sender:i?m(i):void 0,sent:(new Date).toISOString(),payload:[{contentString:t}]})}updateResource(e){if(!e.resourceType)throw new Error("Missing resourceType");if(!e.id)throw new Error("Missing id");return this.invalidateSearches(e.resourceType),this.put(this.fhirUrl(e.resourceType,e.id),e)}patchResource(e,t,i){return this.invalidateSearches(e),this.patch(this.fhirUrl(e,t),i)}deleteResource(e,t){return this.invalidateSearches(e),this.delete(this.fhirUrl(e,t))}sendEmail(e){return this.post("email/v1/send",e,"application/json")}graphql(e,t,i,n){return this.post(this.fhirUrl("$graphql"),{query:e,operationName:t,variables:i},"application/json",n)}getActiveLogin(){return t(this,ve,"f").getObject("activeLogin")}setActiveLogin(n){return e(this,void 0,void 0,(function*(){i(this,Ae,n.accessToken,"f"),i(this,Re,n.refreshToken,"f"),i(this,Me,void 0,"f"),i(this,Oe,void 0,"f"),t(this,ve,"f").setObject("activeLogin",n),t(this,ye,"m",Ue).call(this,n),t(this,we,"f").clear(),i(this,ke,void 0,"f"),yield t(this,ye,"m",Le).call(this)}))}getAccessToken(){return t(this,Ae,"f")}setAccessToken(e){i(this,Ae,e,"f"),i(this,Re,void 0,"f"),i(this,Me,void 0,"f"),i(this,Oe,void 0,"f")}getLogins(){var e;return null!==(e=t(this,ve,"f").getObject("logins"))&&void 0!==e?e:[]}isLoading(){return!!t(this,Ie,"f")}getProfile(){return t(this,Me,"f")}getProfileAsync(){return e(this,void 0,void 0,(function*(){return t(this,Ie,"f")&&(yield t(this,Ie,"f")),this.getProfile()}))}getUserConfiguration(){return t(this,Oe,"f")}download(i,n={}){return e(this,void 0,void 0,(function*(){t(this,ke,"f")&&(yield t(this,ke,"f")),t(this,ye,"m",Qe).call(this,n);return(yield t(this,ge,"f").call(this,i.toString(),n)).blob()}))}processCode(e){if(!t(this,ve,"f").getString("pkceState"))throw this.clear(),new Error("Invalid PCKE state");const i=t(this,ve,"f").getString("codeVerifier");if(!i)throw this.clear(),new Error("Invalid PCKE code verifier");const n=new URLSearchParams;return n.set("grant_type","authorization_code"),n.set("client_id",t(this,be,"f")),n.set("code_verifier",i),n.set("code",e),n.set("redirect_uri",Ke()),t(this,ye,"m",ze).call(this,n)}startClientLogin(i,n){return e(this,void 0,void 0,(function*(){const e=new URLSearchParams;return e.set("grant_type","client_credentials"),e.set("client_id",i),e.set("client_secret",n),t(this,ye,"m",ze).call(this,e)}))}}function Ke(){return window.location.protocol+"//"+window.location.host+"/"}function Je(e){return[{type:ae.boolean,value:e}]}function Ze(e){return null==e?{type:"undefined",value:void 0}:Number.isSafeInteger(e)?{type:ae.integer,value:e}:"number"==typeof e?{type:ae.decimal,value:e}:"boolean"==typeof e?{type:ae.boolean,value:e}:"string"==typeof e?{type:ae.string,value:e}:ut(e)?{type:ae.Quantity,value:e}:"object"==typeof e&&"resourceType"in e?{type:e.resourceType,value:e}:{type:ae.BackboneElement,value:e}}function et(e){return 0!==e.length&&!!e[0].value}function tt(e,t){if(!(null==e?void 0:e.value))return;const i=fe.types[e.type];if(i){const n=function(e,t,i){var n;const o=null!==(n=i.properties[t])&&void 0!==n?n:i.properties[t+"[x]"];if(!o)return;const r=o.type;if(!r||0===r.length)return;let a,s,c="undefined";if(1===r.length)a=t,s=e.value[t],c=r[0].code;else for(const i of r){const n=t.replace("[x]","")+j(i.code);if(n in e.value){a=n,s=e.value[n],c=i.code;break}}if(void 0===s)return;"BackboneElement"===c&&(c=pe([e.type,a]));return Array.isArray(s)?s.map((e=>({value:e,type:c}))):{value:s,type:c}}(e,t,i);if(n)return n}return function(e,t){const i=e.value;if(!i||"object"!=typeof i)return;let n;if(t in i)n=i[t];else{const e=Object.keys(i).find((e=>e.startsWith(t)));e&&(n=i[e])}if(void 0===n)return;return Array.isArray(n)?n.map(Ze):Ze(n)}(e,t)}function it(e){const t=[];for(const i of e){let e=!1;for(const n of t)if(et(rt(i,n))){e=!0;break}e||t.push(i)}return t}function nt(e){return Je(!et(e))}function ot(e,t){return 0===e.length||0===t.length?[]:e.length!==t.length?Je(!1):Je(e.every(((e,i)=>et(rt(e,t[i])))))}function rt(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?Je(Math.abs(i-n)<1e-8):ut(i)&&ut(n)?Je(mt(i,n)):Je("object"==typeof i&&"object"==typeof n?pt(e,t):i===n)}function at(e,t){return 0===e.length&&0===t.length?Je(!0):e.length!==t.length?Je(!1):(e.sort(ct),t.sort(ct),Je(e.every(((e,i)=>et(st(e,t[i]))))))}function st(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?Je(Math.abs(i-n)<.01):ut(i)&&ut(n)?Je(mt(i,n)):Je("object"==typeof i&&"object"==typeof n?pt(i,n):"string"==typeof i&&"string"==typeof n?i.toLowerCase()===n.toLowerCase():i===n)}function ct(e,t){const i=e.value,n=t.value;return"number"==typeof i&&"number"==typeof n?i-n:"string"==typeof i&&"string"==typeof n?i.localeCompare(n):0}function dt(e,t){const{value:i}=e;if(null==i)return!1;switch(t){case"Boolean":return"boolean"==typeof i;case"Decimal":case"Integer":return"number"==typeof i;case"Date":return"string"==typeof i&&!!i.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof i&&!!i.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof i&&!!i.match(/^T\d/);case"Period":return lt(i);case"Quantity":return ut(i);default:return"object"==typeof i&&(null==i?void 0:i.resourceType)===t}}function lt(e){return!(!e||"object"!=typeof e||!("start"in e))}function ut(e){return!(!e||"object"!=typeof e||!("value"in e)||"number"!=typeof e.value)}function mt(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 pt(e,t){const i=Object.keys(e),n=Object.keys(t);if(i.length!==n.length)return!1;for(const n of i){const i=e[n],o=t[n];if(ht(i)&&ht(o)){if(!pt(i,o))return!1}else if(i!==o)return!1}return!0}function ht(e){return null!==e&&"object"==typeof e}var ft,yt;ge=new WeakMap,xe=new WeakMap,ve=new WeakMap,we=new WeakMap,Ee=new WeakMap,Se=new WeakMap,be=new WeakMap,De=new WeakMap,Te=new WeakMap,Ce=new WeakMap,Pe=new WeakMap,Ae=new WeakMap,Re=new WeakMap,ke=new WeakMap,Ie=new WeakMap,Me=new WeakMap,Oe=new WeakMap,ye=new WeakSet,Ue=function(e){const i=this.getLogins().filter((t=>{var i,n;return(null===(i=t.profile)||void 0===i?void 0:i.reference)!==(null===(n=e.profile)||void 0===n?void 0:n.reference)}));i.push(e),t(this,ve,"f").setObject("logins",i)},Le=function(){return e(this,void 0,void 0,(function*(){return i(this,Ie,new Promise(((e,n)=>{this.get("auth/me").then((n=>{i(this,Ie,void 0,"f"),i(this,Me,n.profile,"f"),i(this,Oe,n.config,"f"),this.dispatchEvent({type:"change"}),e(t(this,Me,"f"))})).catch(n)})),"f"),t(this,Ie,"f")}))},je=function(e,i){if(t(this,Ee,"f")<=0||"no-cache"===(null==i?void 0:i.cache)||"reload"===(null==i?void 0:i.cache))return;const n=t(this,we,"f").get(e);return!n||n.requestTime+t(this,Ee,"f")<Date.now()?void 0:n},Ne=function(e,i){t(this,Ee,"f")>0&&t(this,we,"f").set(e,{requestTime:Date.now(),value:i})},_e=function(i,n,o={}){return e(this,void 0,void 0,(function*(){t(this,ke,"f")&&(yield t(this,ke,"f")),n.startsWith("http")||(n=t(this,Se,"f")+n),o.method=i,t(this,ye,"m",Qe).call(this,o);const e=yield t(this,ge,"f").call(this,n,o);if(401===e.status)return t(this,ye,"m",qe).call(this,i,n,o);if(204===e.status||304===e.status)return;const r=yield e.json();if(e.status>=400)throw r;return r}))},Qe=function(e){e.headers||(e.headers={});const i=e.headers;i["Content-Type"]||(i["Content-Type"]="application/fhir+json"),t(this,Ae,"f")&&(i.Authorization="Bearer "+t(this,Ae,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},We=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},Be=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))},qe=function(i,n,o){return e(this,void 0,void 0,(function*(){return t(this,ye,"m",He).call(this).then((()=>t(this,ye,"m",_e).call(this,i,n,o))).catch((e=>(this.clear(),t(this,Pe,"f")&&t(this,Pe,"f").call(this),Promise.reject(e))))}))},Fe=function(){return e(this,void 0,void 0,(function*(){const i=V();t(this,ve,"f").setString("pkceState",i);const n=V();t(this,ve,"f").setString("codeVerifier",n);const o=L(yield function(t){return e(this,void 0,void 0,(function*(){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(t))}))}(n)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");t(this,ve,"f").setString("codeChallenge",o)}))},$e=function(){t(this,ye,"m",Fe).call(this);const e=new URL(t(this,De,"f"));e.searchParams.set("response_type","code"),e.searchParams.set("state",t(this,ve,"f").getString("pkceState")),e.searchParams.set("client_id",t(this,be,"f")),e.searchParams.set("redirect_uri",Ke()),e.searchParams.set("scope",Xe),e.searchParams.set("code_challenge_method","S256"),e.searchParams.set("code_challenge",t(this,ve,"f").getString("codeChallenge")),window.location.assign(e.toString())},He=function(){return e(this,void 0,void 0,(function*(){if(t(this,ke,"f"))return t(this,ke,"f");if(!t(this,Re,"f"))throw this.clear(),new Error("Invalid refresh token");const e=new URLSearchParams;e.set("grant_type","refresh_token"),e.set("client_id",t(this,be,"f")),e.set("refresh_token",t(this,Re,"f")),i(this,ke,t(this,ye,"m",ze).call(this,e),"f"),yield t(this,ke,"f")}))},ze=function(i){return e(this,void 0,void 0,(function*(){return t(this,ge,"f").call(this,t(this,Te,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:i}).then((e=>{if(!e.ok)throw new Error("Failed to fetch tokens");return e.json()})).then((e=>t(this,ye,"m",Ve).call(this,e))).then((()=>this.getProfile()))}))},Ve=function(i){return e(this,void 0,void 0,(function*(){const e=i.access_token,n=function(e){const[t,i,n]=e.split(".");return ie(i)}(e);if(Date.now()>=1e3*n.exp)throw this.clear(),new Error("Token expired");if(t(this,be,"f")&&n.client_id!==t(this,be,"f"))throw this.clear(),new Error("Token was not issued for this audience");yield this.setActiveLogin({accessToken:e,refreshToken:i.refresh_token,project:i.project,profile:i.profile})}))},Ge=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class gt{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}`)}}}class xt{constructor(e){this.value=e}eval(){return[this.value]}}class vt{constructor(e){this.name=e,ft.add(this)}eval(e){return"$this"===this.name?e:e.map((e=>t(this,ft,"m",yt).call(this,e))).flat().filter((e=>void 0!==(null==e?void 0:e.value)))}}ft=new WeakSet,yt=function(e){const t=e.value;if(t&&"object"==typeof t)return"resourceType"in t&&t.resourceType===this.name?e:tt(e,this.name)};class wt{eval(){return[]}}class Et{constructor(e,t){this.child=e,this.impl=t}eval(e){return this.impl(this.child.eval(e))}}class St{constructor(e,t){this.left=e,this.right=t}eval(e){return this.left.eval(e)}}class bt{constructor(e,t,i){this.left=e,this.right=t,this.impl=i}eval(e){const t=this.left.eval(e);if(1!==t.length)return[];const i=this.right.eval(e);if(1!==i.length)return[];const n=t[0].value,o=i[0].value,r=ut(n)?n.value:n,a=ut(o)?o.value:o,s=this.impl(r,a);return"boolean"==typeof s?Je(s):ut(n)?[{type:ae.Quantity,value:Object.assign(Object.assign({},n),{value:s})}]:[Ze(s)]}}class Dt{constructor(e,t){this.left=e,this.right=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:ae.string,value:t.map((e=>e.value)).join("")}]:t}}class Tt{constructor(e,t){this.left=e,this.right=t}eval(e){const t=this.left.eval(e),i=this.right.eval(e);return Je(t.some((e=>e.value===i[0].value)))}}class Ct{constructor(e,t){this.left=e,this.right=t}eval(e){const t=this.left.eval(e);return Je(this.right.eval(e).some((e=>e.value===t[0].value)))}}class Pt{constructor(e,t){this.left=e,this.right=t}eval(e){return this.right.eval(this.left.eval(e))}}class At{constructor(e,t){this.left=e,this.right=t}eval(e){return it([...this.left.eval(e),...this.right.eval(e)])}}class Rt{constructor(e,t){this.left=e,this.right=t}eval(e){return ot(this.left.eval(e),this.right.eval(e))}}class kt{constructor(e,t){this.left=e,this.right=t}eval(e){return nt(ot(this.left.eval(e),this.right.eval(e)))}}class It{constructor(e,t){this.left=e,this.right=t}eval(e){return at(this.left.eval(e),this.right.eval(e))}}class Mt{constructor(e,t){this.left=e,this.right=t}eval(e){return nt(at(this.left.eval(e),this.right.eval(e)))}}class Ot{constructor(e,t){this.left=e,this.right=t}eval(e){const t=this.left.eval(e);if(1!==t.length)return[];const i=this.right.name;return Je(dt(t[0],i))}}class Ut{constructor(e,t){this.left=e,this.right=t}eval(e){var t,i,n,o;const r=this.left.eval(e),a=this.right.eval(e);return!0===(null===(t=r[0])||void 0===t?void 0:t.value)&&!0===(null===(i=a[0])||void 0===i?void 0:i.value)?Je(!0):!1===(null===(n=r[0])||void 0===n?void 0:n.value)||!1===(null===(o=a[0])||void 0===o?void 0:o.value)?Je(!1):[]}}class Lt{constructor(e,t){this.left=e,this.right=t}eval(e){const t=this.left.eval(e);if(et(t))return t;const i=this.right.eval(e);return et(i)?i:[]}}class jt{constructor(e,t){this.left=e,this.right=t}eval(e){const t=this.left.eval(e),i=this.right.eval(e);if(0===t.length&&0===i.length)return[];const n=0===t.length?null:t[0].value,o=0===i.length?null:i[0].value;return!0===n&&!0!==o||!0!==n&&!0===o?Je(!0):!0===n&&!0===o||!1===n&&!1===o?Je(!1):[]}}class Nt{constructor(e,t,i){this.name=e,this.args=t,this.impl=i}eval(e){return this.impl(e,...this.args)}}class _t{constructor(e,t){this.left=e,this.expr=t}eval(e){const t=this.expr.eval(e);if(1!==t.length)return[];const i=t[0].value;if("number"!=typeof i)throw new Error("Invalid indexer expression: should return integer}");const n=this.left.eval(e);return i in n?[n[i]]:[]}}function Qt(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}}const Wt=()=>[],Bt={empty:e=>Je(0===e.length),exists:(e,t)=>Je(t?e.filter((e=>et(t.eval([e])))).length>0:e.length>0),all:(e,t)=>Je(e.every((e=>et(t.eval([e]))))),allTrue:e=>{for(const t of e)if(!t.value)return Je(!1);return Je(!0)},anyTrue:e=>{for(const t of e)if(t.value)return Je(!0);return Je(!1)},allFalse:e=>{for(const t of e)if(t.value)return Je(!1);return Je(!0)},anyFalse:e=>{for(const t of e)if(!t.value)return Je(!0);return Je(!1)},subsetOf:Wt,supersetOf:Wt,count:e=>[{type:ae.integer,value:e.length}],distinct:e=>{const t=[];for(const i of e)t.some((e=>e.value===i.value))||t.push(i);return t},isDistinct:e=>Je(e.length===Bt.distinct(e).length),where:(e,t)=>e.filter((e=>et(t.eval([e])))),select:(e,t)=>e.map((e=>t.eval([e]))).flat(),repeat:Wt,ofType:Wt,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)=>{var i;const n=null===(i=t.eval(e)[0])||void 0===i?void 0:i.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)=>{var i;const n=null===(i=t.eval(e)[0])||void 0===i?void 0:i.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 i=t.eval(e),n=[];for(const t of e)!n.some((e=>e.value===t.value))&&i.some((e=>e.value===t.value))&&n.push(t);return n},exclude:(e,t)=>{if(!t)return e;const i=t.eval(e),n=[];for(const t of e)i.some((e=>e.value===t.value))||n.push(t);return n},union:(e,t)=>{if(!t)return e;const i=t.eval(e);return it([...e,...i])},combine:(e,t)=>{if(!t)return e;const i=t.eval(e);return[...e,...i]},iif:(e,t,i,n)=>{const o=t.eval(e);if(o.length>1||1===o.length&&"boolean"!=typeof o[0].value)throw new Error("Expected criterion to evaluate to a Boolean");return et(o)?i.eval(e):n?n.eval(e):[]},toBoolean:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);if("boolean"==typeof t)return[{type:ae.boolean,value:t}];if("number"==typeof t&&(0===t||1===t))return Je(!!t);if("string"==typeof t){const e=t.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(e))return Je(!0);if(["false","f","no","n","0","0.0"].includes(e))return Je(!1)}return[]},convertsToBoolean:e=>0===e.length?[]:Je(1===Bt.toBoolean(e).length),toInteger:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);return"number"==typeof t?[{type:ae.integer,value:t}]:"string"==typeof t&&t.match(/^[+-]?\d+$/)?[{type:ae.integer,value:parseInt(t,10)}]:"boolean"==typeof t?[{type:ae.integer,value:t?1:0}]:[]},convertsToInteger:e=>0===e.length?[]:Je(1===Bt.toInteger(e).length),toDate:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);return"string"==typeof t&&t.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:ae.date,value:Qt(t)}]:[]},convertsToDate:e=>0===e.length?[]:Je(1===Bt.toDate(e).length),toDateTime:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);return"string"==typeof t&&t.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:ae.dateTime,value:Qt(t)}]:[]},convertsToDateTime:e=>0===e.length?[]:Je(1===Bt.toDateTime(e).length),toDecimal:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);return"number"==typeof t?[{type:ae.decimal,value:t}]:"string"==typeof t&&t.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:ae.decimal,value:parseFloat(t)}]:"boolean"==typeof t?[{type:ae.decimal,value:t?1:0}]:[]},convertsToDecimal:e=>0===e.length?[]:Je(1===Bt.toDecimal(e).length),toQuantity:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);return ut(t)?[{type:ae.Quantity,value:t}]:"number"==typeof t?[{type:ae.Quantity,value:{value:t,unit:"1"}}]:"string"==typeof t&&t.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:ae.Quantity,value:{value:parseFloat(t),unit:"1"}}]:"boolean"==typeof t?[{type:ae.Quantity,value:{value:t?1:0,unit:"1"}}]:[]},convertsToQuantity:e=>0===e.length?[]:Je(1===Bt.toQuantity(e).length),toString:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);return null==t?[]:ut(t)?[{type:ae.string,value:`${t.value} '${t.unit}'`}]:[{type:ae.string,value:t.toString()}]},convertsToString:e=>0===e.length?[]:Je(1===Bt.toString(e).length),toTime:e=>{if(0===e.length)return[];const[{value:t}]=$t(e,1);if("string"==typeof t){const e=t.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(e)return[{type:ae.time,value:Qt("T"+e[1])}]}return[]},convertsToTime:e=>0===e.length?[]:Je(1===Bt.toTime(e).length),indexOf:(e,t)=>qt(((e,t)=>e.indexOf(t)),e,t),substring:(e,t,i)=>qt(((e,t,i)=>{const n=t,o=i?n+i:e.length;return n<0||n>=e.length?void 0:e.substring(n,o)}),e,t,i),startsWith:(e,t)=>qt(((e,t)=>e.startsWith(t)),e,t),endsWith:(e,t)=>qt(((e,t)=>e.endsWith(t)),e,t),contains:(e,t)=>qt(((e,t)=>e.includes(t)),e,t),upper:e=>qt((e=>e.toUpperCase()),e),lower:e=>qt((e=>e.toLowerCase()),e),replace:(e,t,i)=>qt(((e,t,i)=>e.replaceAll(t,i)),e,t,i),matches:(e,t)=>qt(((e,t)=>!!e.match(t)),e,t),replaceMatches:(e,t,i)=>qt(((e,t,i)=>e.replaceAll(t,i)),e,t,i),length:e=>qt((e=>e.length),e),toChars:e=>qt((e=>e?e.split(""):void 0),e),abs:e=>Ft(Math.abs,e),ceiling:e=>Ft(Math.ceil,e),exp:e=>Ft(Math.exp,e),floor:e=>Ft(Math.floor,e),ln:e=>Ft(Math.log,e),log:(e,t)=>Ft(((e,t)=>Math.log(e)/Math.log(t)),e,t),power:(e,t)=>Ft(Math.pow,e,t),round:e=>Ft(Math.round,e),sqrt:e=>Ft(Math.sqrt,e),truncate:e=>Ft((e=>0|e),e),children:Wt,descendants:Wt,trace:(e,t)=>(console.log("trace",e,t),e),now:()=>[{type:ae.dateTime,value:(new Date).toISOString()}],timeOfDay:()=>[{type:ae.time,value:(new Date).toISOString().substring(11)}],today:()=>[{type:ae.date,value:(new Date).toISOString().substring(0,10)}],between:(e,t,i,n)=>{var o;const r=Bt.toDateTime(t.eval(e));if(0===r.length)throw new Error("Invalid start date");const a=Bt.toDateTime(i.eval(e));if(0===a.length)throw new Error("Invalid end date");const s=null===(o=n.eval(e)[0])||void 0===o?void 0:o.value;if("years"!==s&&"months"!==s&&"days"!==s)throw new Error("Invalid units");const c=w(r[0].value,a[0].value);return[{type:ae.Quantity,value:{value:c[s],unit:s}}]},is:(e,t)=>{let i="";return t instanceof vt?i=t.name:t instanceof Pt&&(i=t.left.name+"."+t.right.name),i?e.map((e=>({type:ae.boolean,value:dt(e,i)}))):[]},not:e=>Bt.toBoolean(e).map((e=>({type:ae.boolean,value:!e.value}))),resolve:e=>e.map((e=>{const t=e.value;let i;if("string"==typeof t)i=t;else if("object"==typeof t){const e=t;if(e.resource)return Ze(e.resource);i=e.reference}if(!i)return{type:ae.BackboneElement,value:null};const[n,o]=i.split("/");return{type:ae.BackboneElement,value:{resourceType:n,id:o}}})).filter((e=>!!e.value)),as:e=>e,type:e=>e.map((({value:e})=>"boolean"==typeof e?{type:ae.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof e?{type:ae.BackboneElement,value:{namespace:"System",name:"Integer"}}:e&&"object"==typeof e&&"resourceType"in e?{type:ae.BackboneElement,value:{namespace:"FHIR",name:e.resourceType}}:{type:ae.BackboneElement,value:null})),conformsTo:(e,t)=>{const i=t.eval(e)[0].value;if(!i.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const n=i.replace("http://hl7.org/fhir/StructureDefinition/","");return e.map((e=>{var t;return{type:ae.boolean,value:(null===(t=e.value)||void 0===t?void 0:t.resourceType)===n}}))}};function qt(e,t,...i){if(0===t.length)return[];const[{value:n}]=$t(t,1);if("string"!=typeof n)throw new Error("String function cannot be called with non-string");const o=e(n,...i.map((e=>{var i,n;return e&&(null===(n=null===(i=e.eval(t))||void 0===i?void 0:i[0])||void 0===n?void 0:n.value)})));return void 0===o?[]:Array.isArray(o)?o.map(Ze):[Ze(o)]}function Ft(e,t,...i){if(0===t.length)return[];const[{value:n}]=$t(t,1),o=ut(n),r=o?n.value:n;if("number"!=typeof r)throw new Error("Math function cannot be called with non-number");const a=e(r,...i.map((e=>{var i,n;return null===(n=null===(i=e.eval(t))||void 0===i?void 0:i[0])||void 0===n?void 0:n.value})));return[{type:o?ae.Quantity:t[0].type,value:o?Object.assign(Object.assign({},n),{value:a}):a}]}function $t(e,t){if(e.length!==t)throw new Error(`Expected ${t} arguments`);for(const t of e)if(null==t)throw new Error("Expected non-null argument");return e}var Ht,zt,Vt,Gt,Xt,Yt,Kt,Jt,Zt,ei,ti,ii,ni,oi,ri,ai,si,ci;function di(e){return new mi(e).tokenize()}const li=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],ui=["!=","!~","<=",">=","{}"];class mi{constructor(e){Ht.add(this),zt.set(this,void 0),Vt.set(this,void 0),i(this,zt,e,"f"),i(this,Vt,0,"f")}tokenize(){const e=[];for(;t(this,Vt,"f")<t(this,zt,"f").length;){const i=t(this,Ht,"m",Xt).call(this);i&&e.push(i)}return e}}function pi(e,t){return{id:e,value:t}}var hi,fi,yi,gi,xi,vi,wi,Ei,Si;zt=new WeakMap,Vt=new WeakMap,Ht=new WeakSet,Gt=function(){const e=t(this,Vt,"f"),n=t(this,Ht,"m",Xt).call(this);return i(this,Vt,e,"f"),n},Xt=function(){t(this,Ht,"m",Yt).call(this);const e=t(this,Ht,"m",ai).call(this);if(!e)return;const i=t(this,Ht,"m",ci).call(this);return"/"===e&&"*"===i?t(this,Ht,"m",Kt).call(this):"/"===e&&"/"===i?t(this,Ht,"m",Jt).call(this):"'"===e?t(this,Ht,"m",Zt).call(this):"`"===e?t(this,Ht,"m",ei).call(this):"@"===e?t(this,Ht,"m",ti).call(this):e.match(/\d/)?t(this,Ht,"m",ii).call(this):e.match(/\w/)||"$"===e&&i.match(/\w/)?t(this,Ht,"m",ni).call(this):t(this,Ht,"m",oi).call(this)},Yt=function(){return pi("Whitespace",t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/\s/))))},Kt=function(){const e=t(this,Vt,"f");return t(this,Ht,"m",ri).call(this,(()=>"*"!==t(this,Ht,"m",ai).call(this)||"/"!==t(this,Ht,"m",ci).call(this))),i(this,Vt,t(this,Vt,"f")+2,"f"),pi("Comment",t(this,zt,"f").substring(e,t(this,Vt,"f")))},Jt=function(){return pi("Comment",t(this,Ht,"m",ri).call(this,(()=>"\n"!==t(this,Ht,"m",ai).call(this))))},Zt=function(){var e,n;i(this,Vt,(e=t(this,Vt,"f"),++e),"f");const o=pi("String",t(this,Ht,"m",ri).call(this,(()=>"\\"===t(this,Ht,"m",si).call(this)||"'"!==t(this,Ht,"m",ai).call(this))));return i(this,Vt,(n=t(this,Vt,"f"),++n),"f"),o},ei=function(){var e,n;i(this,Vt,(e=t(this,Vt,"f"),++e),"f");const o=pi("Symbol",t(this,Ht,"m",ri).call(this,(()=>"`"!==t(this,Ht,"m",ai).call(this))));return i(this,Vt,(n=t(this,Vt,"f"),++n),"f"),o},ti=function(){var e,n,o,r,a;const s=t(this,Vt,"f");return i(this,Vt,(e=t(this,Vt,"f"),++e),"f"),t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/[\d-]/))),"T"===t(this,Ht,"m",ai).call(this)&&(i(this,Vt,(n=t(this,Vt,"f"),++n),"f"),t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/[\d:]/))),"."===t(this,Ht,"m",ai).call(this)&&t(this,Ht,"m",ci).call(this).match(/\d/)&&(i(this,Vt,(o=t(this,Vt,"f"),++o),"f"),t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/[\d]/)))),"Z"===t(this,Ht,"m",ai).call(this)?i(this,Vt,(r=t(this,Vt,"f"),++r),"f"):"+"!==t(this,Ht,"m",ai).call(this)&&"-"!==t(this,Ht,"m",ai).call(this)||(i(this,Vt,(a=t(this,Vt,"f"),++a),"f"),t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/[\d:]/))))),pi("DateTime",t(this,zt,"f").substring(s+1,t(this,Vt,"f")))},ii=function(){var e;const n=t(this,Vt,"f");let o="Number";return t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/\d/))),"."===t(this,Ht,"m",ai).call(this)&&t(this,Ht,"m",ci).call(this).match(/\d/)&&(i(this,Vt,(e=t(this,Vt,"f"),++e),"f"),t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/\d/))))," "===t(this,Ht,"m",ai).call(this)&&function(e){if(e){if("String"===e.id)return!0;if("Symbol"===e.id&&li.includes(e.value))return!0}return!1}(t(this,Ht,"m",Gt).call(this))&&(o="Quantity",t(this,Ht,"m",Xt).call(this)),pi(o,t(this,zt,"f").substring(n,t(this,Vt,"f")))},ni=function(){return pi("Symbol",t(this,Ht,"m",ri).call(this,(()=>t(this,Ht,"m",ai).call(this).match(/[$\w]/))))},oi=function(){var e;const n=t(this,Ht,"m",ai).call(this),o=n+t(this,Ht,"m",ci).call(this);return ui.includes(o)?(i(this,Vt,t(this,Vt,"f")+2,"f"),pi(o,o)):(i(this,Vt,(e=t(this,Vt,"f"),++e),"f"),pi(n,n))},ri=function(e){var n;const o=t(this,Vt,"f");for(;t(this,Vt,"f")<t(this,zt,"f").length&&e();)i(this,Vt,(n=t(this,Vt,"f"),++n),"f");return t(this,zt,"f").substring(o,t(this,Vt,"f"))},ai=function(){return t(this,zt,"f")[t(this,Vt,"f")]},si=function(){var e;return null!==(e=t(this,zt,"f")[t(this,Vt,"f")-1])&&void 0!==e?e:""},ci=function(){var e;return null!==(e=t(this,zt,"f")[t(this,Vt,"f")+1])&&void 0!==e?e:""};hi=new WeakMap,fi=new WeakMap;class bi{constructor(e,t,n){yi.add(this),gi.set(this,void 0),xi.set(this,void 0),vi.set(this,void 0),i(this,gi,e,"f"),i(this,xi,t,"f"),i(this,vi,n,"f")}match(e){const i=t(this,yi,"m",Si).call(this);return(null==i?void 0:i.id)===e&&(t(this,yi,"m",Ei).call(this),!0)}consumeAndParse(e=100){const i=t(this,yi,"m",Ei).call(this),n=t(this,xi,"f")[i.id];if(!n)throw Error(`Parse error at ${i.value}. No matching prefix parselet.`);let o=n.parse(this,i);for(;e>t(this,yi,"m",wi).call(this);){const e=t(this,yi,"m",Ei).call(this);o=t(this,vi,"f")[e.id].parse(this,o,e)}return o}}gi=new WeakMap,xi=new WeakMap,vi=new WeakMap,yi=new WeakSet,wi=function(){const e=t(this,yi,"m",Si).call(this);if(!e)return 100;const i=t(this,vi,"f")[e.id];return i?i.precedence:100},Ei=function(){if(!t(this,gi,"f").length)throw Error("Cant consume unknown more tokens.");return t(this,gi,"f").shift()},Si=function(){return t(this,gi,"f").length>0?t(this,gi,"f")[0]:void 0};const Di={parse(e){const t=e.consumeAndParse();if(!e.match(")"))throw new Error("Parse error: expected `)`");return t}},Ti={parse(e,t){const i=e.consumeAndParse();if(!e.match("]"))throw new Error("Parse error: expected `]`");return new _t(t,i)},precedence:2},Ci={parse(e,t){if(!(t instanceof vt))throw new Error("Unexpected parentheses");if(!(t.name in Bt))throw new Error("Unrecognized function: "+t.name);const i=[];for(;!e.match(")");)i.push(e.consumeAndParse()),e.match(",");return new Nt(t.name,i,Bt[t.name])},precedence:0};function Pi(e){const t=e.split(" "),i=parseFloat(t[0]);let n=t[1];return n=n&&n.startsWith("'")&&n.endsWith("'")?n.substring(1,n.length-1):"{"+n+"}",{value:i,unit:n}}const Ai=(new class{constructor(){hi.set(this,{}),fi.set(this,{})}registerInfix(e,i){return t(this,fi,"f")[e]=i,this}registerPrefix(e,i){return t(this,hi,"f")[e]=i,this}prefix(e,t,i){return this.registerPrefix(e,{parse(e,n){const o=e.consumeAndParse(t);return i(n,o)}})}infixLeft(e,t,i){return this.registerInfix(e,{parse(e,n,o){const r=e.consumeAndParse(t);return i(n,o,r)},precedence:t})}construct(e){return new bi(di(e),t(this,hi,"f"),t(this,fi,"f"))}}).registerPrefix("String",{parse:(e,t)=>new xt({type:ae.string,value:t.value})}).registerPrefix("DateTime",{parse:(e,t)=>new xt({type:ae.dateTime,value:Qt(t.value)})}).registerPrefix("Quantity",{parse:(e,t)=>new xt({type:ae.Quantity,value:Pi(t.value)})}).registerPrefix("Number",{parse:(e,t)=>new xt({type:ae.decimal,value:parseFloat(t.value)})}).registerPrefix("Symbol",{parse:(e,t)=>"false"===t.value?new xt({type:ae.boolean,value:!1}):"true"===t.value?new xt({type:ae.boolean,value:!0}):new vt(t.value)}).registerPrefix("{}",{parse:()=>new wt}).registerPrefix("(",Di).registerInfix("[",Ti).registerInfix("(",Ci).prefix("+",3,((e,t)=>new Et(t,(e=>e)))).prefix("-",3,((e,t)=>new bt(t,t,((e,t)=>-t)))).infixLeft(".",1,((e,t,i)=>new Pt(e,i))).infixLeft("/",4,((e,t,i)=>new bt(e,i,((e,t)=>e/t)))).infixLeft("*",4,((e,t,i)=>new bt(e,i,((e,t)=>e*t)))).infixLeft("+",5,((e,t,i)=>new bt(e,i,((e,t)=>e+t)))).infixLeft("-",5,((e,t,i)=>new bt(e,i,((e,t)=>e-t)))).infixLeft("|",7,((e,t,i)=>new At(e,i))).infixLeft("=",9,((e,t,i)=>new Rt(e,i))).infixLeft("!=",9,((e,t,i)=>new kt(e,i))).infixLeft("~",9,((e,t,i)=>new It(e,i))).infixLeft("!~",9,((e,t,i)=>new Mt(e,i))).infixLeft("<",8,((e,t,i)=>new bt(e,i,((e,t)=>e<t)))).infixLeft("<=",8,((e,t,i)=>new bt(e,i,((e,t)=>e<=t)))).infixLeft(">",8,((e,t,i)=>new bt(e,i,((e,t)=>e>t)))).infixLeft(">=",8,((e,t,i)=>new bt(e,i,((e,t)=>e>=t)))).infixLeft("&",5,((e,t,i)=>new Dt(e,i))).infixLeft("Symbol",6,((e,t,i)=>{switch(t.value){case"and":return new Ut(e,i);case"as":return new St(e,i);case"contains":return new Tt(e,i);case"div":return new bt(e,i,((e,t)=>e/t|0));case"in":return new Ct(e,i);case"is":return new Ot(e,i);case"mod":return new bt(e,i,((e,t)=>e%t));case"or":return new Lt(e,i);case"xor":return new jt(e,i);default:throw new Error("Cannot use "+t.value+" as infix operator")}}));function Ri(e){try{return new gt(e,Ai.construct(e).consumeAndParse())}catch(t){throw new Error(`FhirPathError on "${e}": ${t}`)}}function ki(e,t){const i=Array.isArray(t)?t:[t];for(let e=0;e<i.length;e++){const t=i[e];"object"==typeof t&&"type"in t&&"value"in t||(i[e]=Ze(i[e]))}return Ii(e,i).map((e=>e.value))}function Ii(e,t){return Ri(e).eval(t)}const Mi="\r",Oi="|",Ui="^";class Li{constructor(e){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("\r")}buildAck(){var e,t,i,n,o,r;const a=new Date,s=this.get("MSH"),c=(null===(e=null==s?void 0:s.get(2))||void 0===e?void 0:e.toString())||"",d=(null===(t=null==s?void 0:s.get(3))||void 0===t?void 0:t.toString())||"",l=(null===(i=null==s?void 0:s.get(4))||void 0===i?void 0:i.toString())||"",u=(null===(n=null==s?void 0:s.get(5))||void 0===n?void 0:n.toString())||"",m=(null===(o=null==s?void 0:s.get(9))||void 0===o?void 0:o.toString())||"",p=(null===(r=null==s?void 0:s.get(12))||void 0===r?void 0:r.toString())||"2.5.1";return new Li([new ji(["MSH","^~\\&",l,u,c,d,a.toISOString(),"","ACK",a.getTime().toString(),"P",p]),new ji(["MSA","AA",m,"OK"])])}static parse(e){if(!e.startsWith("MSH|^~\\&")){const e=new Error("Invalid HL7 message");throw e.type="entity.parse.failed",e}return new Li(e.split(/[\r\n]+/).map((e=>ji.parse(e))))}}class ji{constructor(e){M(e)?this.fields=e.map((e=>Ni.parse(e))):this.fields=e,this.name=this.fields[0].components[0]}get(e){return this.fields[e]}toString(){return this.fields.map((e=>e.toString())).join("|")}static parse(e){return new ji(e.split("|").map((e=>Ni.parse(e))))}}class Ni{constructor(e){this.components=e}get(e){return this.components[e]}toString(){return this.components.join("^")}static parse(e){return new Ni(e.split("^"))}}const _i={resourceType:"OperationOutcome",id:"ok",issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},Qi={resourceType:"OperationOutcome",id:"created",issue:[{severity:"information",code:"information",details:{text:"Created"}}]},Wi={resourceType:"OperationOutcome",id:"not-modified",issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},Bi={resourceType:"OperationOutcome",id:"not-found",issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},qi={resourceType:"OperationOutcome",id:"gone",issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},Fi={resourceType:"OperationOutcome",id:"access-denied",issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function $i(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}}function Hi(e){return"ok"===e.id||"created"===e.id||"not-modified"===e.id}function zi(e){return"not-found"===e.id}function Vi(e){return"gone"===e.id}function Gi(e){return"ok"===e.id?200:"created"===e.id?201:"not-modified"===e.id?304:"access-denied"===e.id?403:"not-found"===e.id?404:"gone"===e.id?410:400}function Xi(e,t){if(!Hi(e)||void 0===t)throw new Yi(e)}class Yi extends Error{constructor(e){var t,i;super(null===(i=null===(t=null==e?void 0:e.issue)||void 0===t?void 0:t[0].details)||void 0===i?void 0:i.text),this.outcome=e}}const Ki=20;var Ji;!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"}(Ji||(Ji={}));const Zi=[Ji.CONTAINS,Ji.EXACT,Ji.TEXT,Ji.NOT,Ji.ABOVE,Ji.BELOW,Ji.IN,Ji.NOT_IN,Ji.OF_TYPE,Ji.MISSING],en=[Ji.NOT_EQUALS,Ji.GREATER_THAN,Ji.LESS_THAN,Ji.GREATER_THAN_OR_EQUALS,Ji.LESS_THAN_OR_EQUALS,Ji.STARTS_AFTER,Ji.ENDS_BEFORE,Ji.APPROXIMATELY];function tn(e){const t=new URL(e,"https://example.com/"),i=t.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let n,o,r,a,s,c;return new URLSearchParams(t.search).forEach(((e,t)=>{"_fields"===t?r=e.split(","):"_offset"===t?a=parseInt(e):"_count"===t?s=parseInt(e):"_total"===t?c=e:"_sort"===t?(o=o||[],o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(e))):(n=n||[],n.push(function(e,t){let i=e,n=Ji.EQUALS;for(const e of Zi){const t=i.indexOf(":"+e);-1!==t&&(n=e,i=i.substring(0,t))}for(const e of en)t.match(new RegExp("^"+e+"\\d"))&&(n=e,t=t.substring(e.length));return{code:i,operator:n,value:t}}(t,e)))})),{resourceType:i,filters:n,fields:r,offset:a,count:s,total:c,sortRules:o}}function nn(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>t.push(function(e){const t=Zi.includes(e.operator)?":"+e.operator:"",i=en.includes(e.operator)?e.operator:"";return`${e.code}${t}=${i}${encodeURIComponent(e.value)}`}(e)))),e.sortRules&&e.sortRules.length>0&&t.push(function(e){if(!e||0===e.length)return"";return"_sort="+e.map((e=>e.descending?"-"+e.code:e.code)).join(",")}(e.sortRules)),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("&"))}var on;function rn(e,t,i){var n,o,r,a,s,c,d;if("_lastUpdated"===i.code)return{columnName:"lastUpdated",type:on.DATETIME};const l=i.code.split("-").reduce(((e,t,i)=>e+(i?j(t):t)),"");const u=null===(n=sn(t,i.expression))||void 0===n?void 0:n.split(".");if(!u)return{columnName:l,type:on.TEXT};const m=an(i);let p,h,f=t,y=!1;for(let n=1;n<u.length;n++){const g=u[n];if(p=null!==(a=null===(r=null===(o=e.types[f])||void 0===o?void 0:o.properties)||void 0===r?void 0:r[g])&&void 0!==a?a:null===(c=null===(s=e.types[f])||void 0===s?void 0:s.properties)||void 0===c?void 0:c[g+"[x]"],!p)throw new Error(`Element definition not found for ${t} ${i.code}`);if("*"===p.max&&(y=!0),h=null===(d=p.type)||void 0===d?void 0:d[0].code,!h)return{columnName:l,type:m,array:y};n<u.length-1&&("Element"===h||"BackboneElement"===h?f+=j(g):f=h)}return{columnName:l,type:an(i,h),elementDefinition:p,array:y}}function an(e,t){let i=on.TEXT;switch(e.type){case"date":i=t===ae.dateTime||t===ae.instant?on.DATETIME:on.DATE;break;case"number":i=on.NUMBER;break;case"quantity":i=on.QUANTITY;break;case"reference":i=on.REFERENCE;break;case"token":"boolean"===t&&(i=on.BOOLEAN)}return i}function sn(e,t){const i=t.split(" | ");for(const t of i){if((n=t).includes(" as Period")||n.includes(" as SampledDate"))continue;const i=cn(t);if(i.startsWith(e+"."))return i}var n}function cn(e){let t=e.trim();t.startsWith("(")&&t.endsWith(")")&&(t=t.substring(1,t.length-1)),t.includes("[0]")&&(t=t.replaceAll("[0]",""));const i=[" != "," as ",".as(",".exists(",".where("];for(const e of i)t.includes(e)&&(t=t.substring(0,t.indexOf(e)));return t}!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"}(on||(on={}));export{Ut as AndAtom,bt as ArithemticOperatorAtom,St as AsAtom,Ui as COMPONENT_SEPARATOR,Dt as ConcatAtom,Tt as ContainsAtom,Ki as DEFAULT_SEARCH_COUNT,Pt as DotAtom,wt as EmptySetAtom,Rt as EqualsAtom,It as EquivalentAtom,Oi as FIELD_SEPARATOR,gt as FhirPathAtom,Nt as FunctionAtom,Ni as Hl7Field,Li as Hl7Message,ji as Hl7Segment,Ct as InAtom,_t as IndexerAtom,Ot as IsAtom,s as LRUCache,xt as LiteralAtom,Ye as MedplumClient,kt as NotEqualsAtom,Mt as NotEquivalentAtom,Yi as OperationOutcomeError,Ji as Operator,Lt as OrAtom,ae as PropertyType,ne as ReadablePromise,Mi as SEGMENT_SEPARATOR,on as SearchParameterType,vt as SymbolAtom,Et as UnaryOperatorAtom,At as UnionAtom,jt as XorAtom,Fi as accessDenied,_i as allOk,L as arrayBufferToBase64,U as arrayBufferToHex,Xi as assertOk,$i as badRequest,Je as booleanToTypedValue,pe as buildTypeName,w as calculateAge,E as calculateAgeString,j as capitalize,m as createReference,ce as createSchema,de as createTypeSchema,Qi as created,R as deepEquals,ki as evalFhirPath,Ii as evalFhirPathTyped,ot as fhirPathArrayEquals,at as fhirPathArrayEquivalent,rt as fhirPathEquals,st as fhirPathEquivalent,dt as fhirPathIs,nt as fhirPathNot,W as findObservationInterval,c as formatAddress,u as formatFamilyName,l as formatGivenName,d as formatHumanName,nn as formatSearchQuery,_ as getCodeBySystem,v as getDateProperty,y as getDisplayString,sn as getExpressionForResourceType,T as getExtensionValue,D as getIdentifier,g as getImageSrc,he as getPropertyDisplayName,S as getQuestionnaireAnswers,p as getReferenceString,rn as getSearchParameterDetails,Gi as getStatus,tt as getTypedPropertyValue,fe as globalSchema,qi as gone,me as indexSearchParameter,ue as indexStructureDefinition,le as indexStructureDefinitionBundle,Vi as isGone,N as isLowerCase,zi as isNotFound,I as isObject,Hi as isOk,lt as isPeriod,f as isProfileResource,ut as isQuantity,mt as isQuantityEquivalent,M as isStringArray,k as isUUID,B as matchesRange,Bi as notFound,Wi as notModified,Ri as parseFhirPath,tn as parseSearchDefinition,q as preciseEquals,$ as preciseGreaterThan,z as preciseGreaterThanOrEquals,F as preciseLessThan,H as preciseLessThanOrEquals,it as removeDuplicates,h as resolveId,Q as setCodeBySystem,C as stringify,et as toJsBoolean,Ze as toTypedValue,di as tokenize};
2
2
  //# sourceMappingURL=index.min.js.map