@medplum/core 0.9.5 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -23
- package/cody-pdf-test.js +32 -0
- package/dist/cjs/index.js +2992 -240
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/cjs/package.json +1 -0
- package/dist/esm/index.js +2987 -239
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/package.json +1 -0
- package/dist/types/cache.d.ts +22 -0
- package/dist/types/client.d.ts +202 -81
- package/dist/types/fhirpath/atoms.d.ts +148 -0
- package/dist/types/fhirpath/date.d.ts +1 -0
- package/dist/types/fhirpath/functions.d.ts +5 -0
- package/dist/types/fhirpath/index.d.ts +2 -0
- package/dist/types/fhirpath/parse.d.ts +17 -0
- package/dist/types/fhirpath/tokenize.d.ts +5 -0
- package/dist/types/fhirpath/utils.d.ts +84 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/pdf.d.ts +5 -0
- package/dist/types/utils.d.ts +12 -0
- package/document.pdf +0 -0
- package/package.json +10 -3
- package/test.pdf +1 -0
- package/test2.pdf +1 -0
- package/test3.pdf.txt +1 -0
- package/test4.pdf +1 -0
- package/test5.pdf +0 -0
- package/test7-2.pdf +1 -0
- package/test7.pdf +1 -0
- package/test8-2.pdf +0 -0
- package/{dist/types/fix-ro-iddentifiers.d.ts → test8.pdf} +0 -0
- package/wget-log +6 -0
package/dist/cjs/index.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).medplum=e.medplum||{},e.medplum.core={}))}(this,(function(e){"use strict";function t(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function i(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 n(e,t,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(e,i):r?r.value=i:t.set(e,i),i}var r,o,s,a;class c{constructor(e=10){r.add(this),o.set(this,void 0),s.set(this,void 0),n(this,o,e,"f"),n(this,s,new Map,"f")}clear(){i(this,s,"f").clear()}get(e){const t=i(this,s,"f").get(e);return t&&(i(this,s,"f").delete(e),i(this,s,"f").set(e,t)),t}set(e,t){i(this,s,"f").has(e)?i(this,s,"f").delete(e):i(this,s,"f").size>=i(this,o,"f")&&i(this,s,"f").delete(i(this,r,"m",a).call(this)),i(this,s,"f").set(e,t)}delete(e){i(this,s,"f").delete(e)}}function l(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 u(e){return e.resourceType+"/"+e.id}function h(e){return"Patient"===e.resourceType||"Practitioner"===e.resourceType||"RelatedPerson"===e.resourceType}function d(e){var t,i;if(h(e)){const t=function(e){const t=e.name;if(t&&t.length>0)return l(t[0]);return}(e);if(t)return t}if("Device"===e.resourceType){const t=function(e){const t=e.deviceName;if(t&&t.length>0)return t[0].name;return}(e);if(t)return t}return"Observation"===e.resourceType&&"code"in e&&(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:u(e)}function f(e){if(e.url&&e.contentType&&e.contentType.startsWith("image/"))return e.url}function p(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 r=i.getUTCFullYear(),o=i.getUTCMonth(),s=i.getUTCDate(),a=n.getUTCFullYear(),c=n.getUTCMonth(),l=n.getUTCDate();let u=a-r;(c<o||c===o&&l<s)&&u--;let h=12*a+c-(12*r+o);l<s&&h--;return{years:u,months:h,days:Math.floor((n.getTime()-i.getTime())/864e5)}}function m(e,t){if(e)for(const i of e)i.linkId&&i.answer&&i.answer.length>0&&(t[i.linkId]=i.answer[0]),m(i.item,t)}function g(e,t){return JSON.stringify(e,v,t?2:void 0)}function v(e,t){return!function(e){return!!e.match(/\d+$/)}(e)&&y(t)?void 0:t}function y(e){if(null==e)return!0;const t=typeof e;return"string"===t&&""===e||"object"===t&&0===Object.keys(e).length}function T(e,t,i){return e===t||(!(!y(e)||!y(t))||!y(e)&&!y(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(!T(e[i],t[i]))return!1;return!0}(e,t):!Array.isArray(e)&&!Array.isArray(t)&&(w(e)&&w(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(!T(e[i],t[i],i))return!1}return!0}(e,t,i):(w(e)||w(t),!1))))}function w(e){return null!==e&&"object"==typeof e}function S(e){return e.every((e=>"string"==typeof e))}o=new WeakMap,s=new WeakMap,r=new WeakSet,a=function(){return i(this,s,"f").keys().next().value};const E=[];for(let e=0;e<256;e++)E.push(e.toString(16).padStart(2,"0"));function R(e){const t=new Uint8Array(e),i=new Array(t.length);for(let e=0;e<t.length;e++)i[e]=E[t[e]];return i.join("")}function A(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 O(e){return e.charAt(0).toUpperCase()+e.substring(1)}function P(){const e=new Uint32Array(28);return crypto.getRandomValues(e),R(e.buffer)}var U;function C(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)}U=new WeakMap;const b="ok",k="created",_="gone",I="not-modified",M="not-found",N="access-denied",x={resourceType:"OperationOutcome",id:b,issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},L={resourceType:"OperationOutcome",id:k,issue:[{severity:"information",code:"information",details:{text:"Created"}}]},j={resourceType:"OperationOutcome",id:I,issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},D={resourceType:"OperationOutcome",id:M,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},W={resourceType:"OperationOutcome",id:_,issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},B={resourceType:"OperationOutcome",id:N,issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function H(e){return e.id===b||e.id===k||e.id===I}class F 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}}var $,Q,X,q,G;class Y{constructor(e){this[G]="ReadablePromise",$.set(this,void 0),Q.set(this,"pending"),X.set(this,void 0),q.set(this,void 0),n(this,$,e.then((e=>(n(this,Q,"success","f"),n(this,X,e,"f"),e)),(e=>{throw n(this,Q,"error","f"),n(this,q,e,"f"),e})),"f")}isPending(){return"pending"===i(this,Q,"f")}read(){switch(i(this,Q,"f")){case"pending":throw i(this,$,"f");case"error":throw i(this,q,"f");default:return i(this,X,"f")}}then(e,t){return i(this,$,"f").then(e,t)}catch(e){return i(this,$,"f").catch(e)}finally(e){return i(this,$,"f").finally(e)}}$=new WeakMap,Q=new WeakMap,X=new WeakMap,q=new WeakMap,G=Symbol.toStringTag;var z;e.Operator=void 0,(z=e.Operator||(e.Operator={})).EQUALS="eq",z.NOT_EQUALS="ne",z.GREATER_THAN="gt",z.LESS_THAN="lt",z.GREATER_THAN_OR_EQUALS="ge",z.LESS_THAN_OR_EQUALS="le",z.STARTS_AFTER="sa",z.ENDS_BEFORE="eb",z.APPROXIMATELY="ap",z.CONTAINS="contains",z.EXACT="exact",z.TEXT="text",z.ABOVE="above",z.BELOW="below",z.IN="in",z.NOT_IN="not-in",z.OF_TYPE="of-type";const V=[e.Operator.CONTAINS,e.Operator.EXACT,e.Operator.TEXT,e.Operator.ABOVE,e.Operator.BELOW,e.Operator.IN,e.Operator.NOT_IN,e.Operator.OF_TYPE],K=[e.Operator.NOT_EQUALS,e.Operator.GREATER_THAN,e.Operator.LESS_THAN,e.Operator.GREATER_THAN_OR_EQUALS,e.Operator.LESS_THAN_OR_EQUALS,e.Operator.STARTS_AFTER,e.Operator.ENDS_BEFORE,e.Operator.APPROXIMATELY];function J(t){const i=new URL(t,"https://example.com/"),n=i.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let r,o,s,a,c,l;return new URLSearchParams(i.search).forEach(((t,i)=>{"_fields"===i?s=t.split(","):"_offset"===i?a=parseInt(t):"_count"===i?c=parseInt(t):"_total"===i?l=t:"_sort"===i?(o=o||[],o.push(function(e){return e.startsWith("-")?{code:e.substring(1),descending:!0}:{code:e}}(t))):(r=r||[],r.push(function(t,i){let n=t,r=e.Operator.EQUALS;for(const e of V){const t=n.indexOf(":"+e);-1!==t&&(r=e,n=n.substring(0,t))}for(const e of K)i.match(new RegExp("^"+e+"\\d"))&&(r=e,i=i.substring(e.length));return{code:n,operator:r,value:i}}(i,t)))})),{resourceType:n,filters:r,fields:s,offset:a,count:c,total:l,sortRules:o}}function Z(e){const t=[];return e.fields&&t.push("_fields="+e.fields.join(",")),e.filters&&e.filters.forEach((e=>t.push(function(e){const t=V.includes(e.operator)?":"+e.operator:"",i=K.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="+encodeURIComponent(e.total)),0===t.length?"":(t.sort(),"?"+t.join("&"))}var ee,te,ie,ne,re,oe,se,ae,ce,le,ue,he,de,fe,pe,me,ge,ve,ye,Te,we,Se,Ee,Re,Ae,Oe,Pe,Ue,Ce,be,ke,_e,Ie;class Me{constructor(){ee.set(this,void 0),n(this,ee,"undefined"!=typeof localStorage?localStorage:new Ne,"f")}clear(){i(this,ee,"f").clear()}getString(e){return i(this,ee,"f").getItem(e)||void 0}setString(e,t){t?i(this,ee,"f").setItem(e,t):i(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?g(t):void 0)}}ee=new WeakMap;class Ne{constructor(){te.set(this,void 0),n(this,te,new Map,"f")}get length(){return i(this,te,"f").size}clear(){i(this,te,"f").clear()}getItem(e){var t;return null!==(t=i(this,te,"f").get(e))&&void 0!==t?t:null}setItem(e,t){t?i(this,te,"f").set(e,t):i(this,te,"f").delete(e)}removeItem(e){i(this,te,"f").delete(e)}key(e){return Array.from(i(this,te,"f").keys())[e]}}function xe(){return{types:{}}}function Le(e,t){return{display:e,description:t,properties:{},searchParams:{_lastUpdated:{base:[e],code:"_lastUpdated",type:"date",expression:e+".meta.lastUpdated"}}}}function je(e,t){var i;const n=t.name;if(!n)return;e.types[n]=Le(n,t.description);const r=null===(i=t.snapshot)||void 0===i?void 0:i.element;if(r){const t=r.filter((e=>e.path!==n&&e.path));t.forEach((t=>function(e,t){var i,n;const r=t.path,o=null===(n=null===(i=t.type)||void 0===i?void 0:i[0])||void 0===n?void 0:n.code;if("Element"!==o&&"BackboneElement"!==o)return;const s=r.split("."),a=We(s);a in e.types||(e.types[a]=Le(a,t.definition),e.types[a].parentType=We(s.slice(0,s.length-1)))}(e,t))),t.forEach((t=>function(e,t){const i=t.path.split(".");if(1===i.length)return;const n=We(i.slice(0,i.length-1)),r=e.types[n],o=i[i.length-1];r.properties[o]=t}(e,t)))}}function De(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 We(e){return e.map(O).join("")}te=new WeakMap,e.PropertyType=void 0,(ie=e.PropertyType||(e.PropertyType={})).Address="Address",ie.Age="Age",ie.Annotation="Annotation",ie.Attachment="Attachment",ie.BackboneElement="BackboneElement",ie.CodeableConcept="CodeableConcept",ie.Coding="Coding",ie.ContactDetail="ContactDetail",ie.ContactPoint="ContactPoint",ie.Contributor="Contributor",ie.Count="Count",ie.DataRequirement="DataRequirement",ie.Distance="Distance",ie.Dosage="Dosage",ie.Duration="Duration",ie.Expression="Expression",ie.Extension="Extension",ie.HumanName="HumanName",ie.Identifier="Identifier",ie.MarketingStatus="MarketingStatus",ie.Meta="Meta",ie.Money="Money",ie.Narrative="Narrative",ie.ParameterDefinition="ParameterDefinition",ie.Period="Period",ie.Population="Population",ie.ProdCharacteristic="ProdCharacteristic",ie.ProductShelfLife="ProductShelfLife",ie.Quantity="Quantity",ie.Range="Range",ie.Ratio="Ratio",ie.Reference="Reference",ie.RelatedArtifact="RelatedArtifact",ie.Resource="Resource",ie.SampledData="SampledData",ie.Signature="Signature",ie.SubstanceAmount="SubstanceAmount",ie.SystemString="http://hl7.org/fhirpath/System.String",ie.Timing="Timing",ie.TriggerDefinition="TriggerDefinition",ie.UsageContext="UsageContext",ie.base64Binary="base64Binary",ie.boolean="boolean",ie.canonical="canonical",ie.code="code",ie.date="date",ie.dateTime="dateTime",ie.decimal="decimal",ie.id="id",ie.instant="instant",ie.integer="integer",ie.markdown="markdown",ie.oid="oid",ie.positiveInt="positiveInt",ie.string="string",ie.time="time",ie.unsignedInt="unsignedInt",ie.uri="uri",ie.url="url",ie.uuid="uuid";const Be="launch/patient openid fhirUser offline_access user/*.*";function He(){return window.location.protocol+"//"+window.location.host+"/"}re=new WeakMap,oe=new WeakMap,se=new WeakMap,ae=new WeakMap,ce=new WeakMap,le=new WeakMap,ue=new WeakMap,he=new WeakMap,de=new WeakMap,fe=new WeakMap,pe=new WeakMap,me=new WeakMap,ge=new WeakMap,ve=new WeakMap,ye=new WeakMap,Te=new WeakMap,ne=new WeakSet,we=function(e){const t=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)}));t.push(e),i(this,oe,"f").setObject("logins",t)},Se=function(){return t(this,void 0,void 0,(function*(){return n(this,ve,new Promise(((e,t)=>{this.get("auth/me").then((t=>{n(this,ve,void 0,"f"),n(this,ye,t.profile,"f"),n(this,Te,t.config,"f"),this.dispatchEvent({type:"change"}),e(i(this,ye,"f"))})).catch(t)})),"f"),i(this,ve,"f")}))},Ee=function(e,n,r={}){return t(this,void 0,void 0,(function*(){i(this,ge,"f")&&(yield i(this,ge,"f")),n.startsWith("http")||(n=i(this,ce,"f")+n),r.method=e,i(this,ne,"m",Re).call(this,r);const t=yield i(this,re,"f").call(this,n,r);if(401===t.status)return i(this,ne,"m",Pe).call(this,e,n,r);if(204===t.status||304===t.status)return;const o=yield t.json();return"OperationOutcome"!==(null==o?void 0:o.resourceType)||H(o)?o:Promise.reject(o)}))},Re=function(e){e.headers||(e.headers={});const t=e.headers;t["Content-Type"]||(t["Content-Type"]="application/fhir+json"),i(this,pe,"f")&&(t.Authorization="Bearer "+i(this,pe,"f")),e.cache||(e.cache="no-cache"),e.credentials||(e.credentials="include")},Ae=function(e,t){e.headers||(e.headers={});e.headers["Content-Type"]=t},Oe=function(e,t){"string"==typeof t||"undefined"!=typeof File&&t instanceof File?e.body=t:t&&(e.body=g(t))},Pe=function(e,n,r){return t(this,void 0,void 0,(function*(){return i(this,ne,"m",be).call(this).then((()=>i(this,ne,"m",Ee).call(this,e,n,r))).catch((e=>(this.clear(),i(this,fe,"f")&&i(this,fe,"f").call(this),Promise.reject(e))))}))},Ue=function(){return t(this,void 0,void 0,(function*(){const e=P();i(this,oe,"f").setString("pkceState",e);const n=P();i(this,oe,"f").setString("codeVerifier",n);const r=A(yield function(e){return t(this,void 0,void 0,(function*(){return crypto.subtle.digest("SHA-256",(new TextEncoder).encode(e))}))}(n)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");i(this,oe,"f").setString("codeChallenge",r)}))},Ce=function(){return t(this,void 0,void 0,(function*(){if(!i(this,ue,"f"))return Promise.reject("Missing authorize URL");i(this,ne,"m",Ue).call(this),window.location.assign(i(this,ue,"f")+"?response_type=code&state="+encodeURIComponent(i(this,oe,"f").getString("pkceState"))+"&client_id="+encodeURIComponent(i(this,le,"f"))+"&redirect_uri="+encodeURIComponent(He())+"&scope="+encodeURIComponent(Be)+"&code_challenge_method=S256&code_challenge="+encodeURIComponent(i(this,oe,"f").getString("codeChallenge")))}))},be=function(){return t(this,void 0,void 0,(function*(){return i(this,ge,"f")?i(this,ge,"f"):i(this,me,"f")?(n(this,ge,i(this,ne,"m",ke).call(this,"grant_type=refresh_token&client_id="+encodeURIComponent(i(this,le,"f"))+"&refresh_token="+encodeURIComponent(i(this,me,"f"))),"f"),void(yield i(this,ge,"f"))):(this.clear(),Promise.reject("Invalid refresh token"))}))},ke=function(e){return t(this,void 0,void 0,(function*(){return i(this,he,"f")?i(this,re,"f").call(this,i(this,he,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e}).then((e=>e.ok?e.json():Promise.reject("Failed to fetch tokens"))).then((e=>i(this,ne,"m",_e).call(this,e))).then((()=>this.getProfile())):Promise.reject("Missing token URL")}))},_e=function(e){return t(this,void 0,void 0,(function*(){const t=e.access_token,n=function(e){const[t,i,n]=e.split(".");return C(i)}(t);return Date.now()>=1e3*n.exp?(this.clear(),Promise.reject("Token expired")):i(this,le,"f")&&n.client_id!==i(this,le,"f")?(this.clear(),Promise.reject("Token was not issued for this audience")):void(yield this.setActiveLogin({accessToken:t,refreshToken:e.refresh_token,project:e.project,profile:e.profile}))}))},Ie=function(){try{window.addEventListener("storage",(e=>{null!==e.key&&"activeLogin"!==e.key||window.location.reload()}))}catch(e){}};class Fe{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,r,o;const s=new Date,a=this.get("MSH"),c=(null===(e=null==a?void 0:a.get(2))||void 0===e?void 0:e.toString())||"",l=(null===(t=null==a?void 0:a.get(3))||void 0===t?void 0:t.toString())||"",u=(null===(i=null==a?void 0:a.get(4))||void 0===i?void 0:i.toString())||"",h=(null===(n=null==a?void 0:a.get(5))||void 0===n?void 0:n.toString())||"",d=(null===(r=null==a?void 0:a.get(9))||void 0===r?void 0:r.toString())||"",f=(null===(o=null==a?void 0:a.get(12))||void 0===o?void 0:o.toString())||"2.5.1";return new Fe([new $e(["MSH","^~\\&",u,h,c,l,s.toISOString(),"","ACK",s.getTime().toString(),"P",f]),new $e(["MSA","AA",d,"OK"])])}static parse(e){if(!e.startsWith("MSH|^~\\&")){const e=new Error("Invalid HL7 message");throw e.type="entity.parse.failed",e}return new Fe(e.split(/[\r\n]+/).map((e=>$e.parse(e))))}}class $e{constructor(e){S(e)?this.fields=e.map((e=>Qe.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 $e(e.split("|").map((e=>Qe.parse(e))))}}class Qe{constructor(e){this.components=e}get(e){return this.components[e]}toString(){return this.components.join("^")}static parse(e){return new Qe(e.split("^"))}}var Xe;function qe(e,t){const i=t.split(" | ");for(const t of i){const i=Ge(t);if(i.startsWith(e+"."))return i}}function Ge(e){let t=e.trim();return t.startsWith("(")&&t.endsWith(")")&&(t=t.substring(1,t.length-1)),t.includes(" as ")&&(t=t.substring(0,t.indexOf(" as "))),t.includes(".where(")&&(t=t.substring(0,t.indexOf(".where("))),t}e.SearchParameterType=void 0,(Xe=e.SearchParameterType||(e.SearchParameterType={})).BOOLEAN="BOOLEAN",Xe.NUMBER="NUMBER",Xe.QUANTITY="QUANTITY",Xe.TEXT="TEXT",Xe.REFERENCE="REFERENCE",Xe.DATE="DATE",Xe.DATETIME="DATETIME",Xe.PERIOD="PERIOD",e.COMPONENT_SEPARATOR="^",e.DEFAULT_SEARCH_COUNT=20,e.FIELD_SEPARATOR="|",e.Hl7Field=Qe,e.Hl7Message=Fe,e.Hl7Segment=$e,e.LRUCache=c,e.MedplumClient=class extends class{constructor(){U.set(this,void 0),n(this,U,{},"f")}addEventListener(e,t){i(this,U,"f")[e]||(i(this,U,"f")[e]=[]),i(this,U,"f")[e].push(t)}removeEventListeneer(e,t){const n=i(this,U,"f")[e];if(n)for(let e=0;e<n.length;e++)if(n[e]===t)return void n.splice(e,1)}dispatchEvent(e){const t=i(this,U,"f")[e.type];return t&&t.forEach((t=>t.call(this,e))),!e.defaultPrevented}}{constructor(e){var t;if(super(),ne.add(this),re.set(this,void 0),oe.set(this,void 0),se.set(this,void 0),ae.set(this,void 0),ce.set(this,void 0),le.set(this,void 0),ue.set(this,void 0),he.set(this,void 0),de.set(this,void 0),fe.set(this,void 0),pe.set(this,void 0),me.set(this,void 0),ge.set(this,void 0),ve.set(this,void 0),ye.set(this,void 0),Te.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")}n(this,re,(null==e?void 0:e.fetch)||window.fetch.bind(window),"f"),n(this,oe,new Me,"f"),n(this,se,{types:{}},"f"),n(this,ae,new c(null!==(t=null==e?void 0:e.resourceCacheSize)&&void 0!==t?t:1e3),"f"),n(this,ce,(null==e?void 0:e.baseUrl)||"https://api.medplum.com/","f"),n(this,le,(null==e?void 0:e.clientId)||"","f"),n(this,ue,(null==e?void 0:e.authorizeUrl)||i(this,ce,"f")+"oauth2/authorize","f"),n(this,he,(null==e?void 0:e.tokenUrl)||i(this,ce,"f")+"oauth2/token","f"),n(this,de,(null==e?void 0:e.logoutUrl)||i(this,ce,"f")+"oauth2/logout","f"),n(this,fe,null==e?void 0:e.onUnauthenticated,"f");const r=this.getActiveLogin();r&&(n(this,pe,r.accessToken,"f"),n(this,me,r.refreshToken,"f"),i(this,ne,"m",Se).call(this).catch(console.log)),i(this,ne,"m",Ie).call(this)}clear(){i(this,oe,"f").clear(),i(this,ae,"f").clear(),n(this,pe,void 0,"f"),n(this,me,void 0,"f"),n(this,ye,void 0,"f"),n(this,Te,void 0,"f"),this.dispatchEvent({type:"change"})}get(e,t={}){if(!(null==t?void 0:t.cache)){const t=i(this,ae,"f").get(e);if(t)return t}const n=new Y(i(this,ne,"m",Ee).call(this,"GET",e,t));return i(this,ae,"f").set(e,n),n}post(e,t,n,r={}){return t&&i(this,ne,"m",Oe).call(this,r,t),n&&i(this,ne,"m",Ae).call(this,r,n),i(this,ae,"f").delete(e),i(this,ne,"m",Ee).call(this,"POST",e,r)}put(e,t,n,r={}){return t&&i(this,ne,"m",Oe).call(this,r,t),n&&i(this,ne,"m",Ae).call(this,r,n),i(this,ae,"f").delete(e),i(this,ne,"m",Ee).call(this,"PUT",e,r)}patch(e,t,n={}){return i(this,ne,"m",Oe).call(this,n,t),i(this,ne,"m",Ae).call(this,n,"application/json-patch+json"),i(this,ae,"f").delete(e),i(this,ne,"m",Ee).call(this,"PATCH",e,n)}delete(e,t={}){return i(this,ae,"f").delete(e),i(this,ne,"m",Ee).call(this,"DELETE",e,t)}register(e){return t(this,void 0,void 0,(function*(){const t=yield this.post("auth/register",e);yield this.setActiveLogin(t)}))}startLogin(e,n,r){return t(this,void 0,void 0,(function*(){return yield i(this,ne,"m",Ue).call(this),this.post("auth/login",{clientId:i(this,le,"f"),scope:Be,codeChallengeMethod:"S256",codeChallenge:i(this,oe,"f").getString("codeChallenge"),email:e,password:n,remember:!!r})}))}startGoogleLogin(e){return t(this,void 0,void 0,(function*(){return yield i(this,ne,"m",Ue).call(this),this.post("auth/google",e)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const e=new URLSearchParams(window.location.search).get("code");return e?this.processCode(e):void i(this,ne,"m",Ce).call(this)}signOutWithRedirect(){window.location.assign(i(this,de,"f"))}fhirUrl(...e){const t=[i(this,ce,"f"),"fhir/R4"];return e.forEach((e=>t.push("/",encodeURIComponent(e)))),t.join("")}search(e,t={}){return this.get("string"==typeof e?"fhir/R4/"+e:this.fhirUrl(e.resourceType)+Z(e),t)}searchOne(e,i={}){var n,r;return t(this,void 0,void 0,(function*(){const t="string"==typeof e?J(e):e;t.count=1;const o=yield this.search(t,i);return null===(r=null===(n=o.entry)||void 0===n?void 0:n[0])||void 0===r?void 0:r.resource}))}searchResources(e,i={}){var n,r;return t(this,void 0,void 0,(function*(){const t=yield this.search(e,i);return null!==(r=null===(n=t.entry)||void 0===n?void 0:n.map((e=>e.resource)))&&void 0!==r?r:[]}))}searchValueSet(e,t,i={}){return this.get(this.fhirUrl("ValueSet","$expand")+`?url=${encodeURIComponent(e)}`+`&filter=${encodeURIComponent(t)}`,i)}getCached(e,t){const n=i(this,ae,"f").get(this.fhirUrl(e,t));return n&&!n.isPending()?n.read():void 0}getCachedReference(e){const t=e.reference,[i,n]=t.split("/");return this.getCached(i,n)}readResource(e,t){return this.get(this.fhirUrl(e,t))}readCached(e,t){return this.get(this.fhirUrl(e,t))}readReference(e){const t=null==e?void 0:e.reference;if(!t)return new Y(Promise.reject("Missing reference"));const[i,n]=t.split("/");return this.readResource(i,n)}readCachedReference(e){const t=null==e?void 0:e.reference;if(!t)return new Y(Promise.reject("Missing reference"));const[i,n]=t.split("/");return this.readCached(i,n)}getSchema(){return i(this,se,"f")}requestSchema(e){return t(this,void 0,void 0,(function*(){if(e in i(this,se,"f").types)return Promise.resolve(i(this,se,"f"));const t=`{\n StructureDefinitionList(name: "${encodeURIComponent(e)}") {\n name,\n description,\n snapshot {\n element {\n id,\n path,\n min,\n max,\n type {\n code,\n targetProfile\n },\n binding {\n valueSet\n },\n definition\n }\n }\n }\n SearchParameterList(base: "${encodeURIComponent(e)}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),n=yield this.graphql(t);for(const e of n.data.StructureDefinitionList)je(i(this,se,"f"),e);for(const e of n.data.SearchParameterList)De(i(this,se,"f"),e);return i(this,se,"f")}))}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){return e.resourceType?this.post(this.fhirUrl(e.resourceType),e):Promise.reject("Missing resourceType")}createResourceIfNoneExist(e,i){var n;return t(this,void 0,void 0,(function*(){return null!==(n=yield this.searchOne(`${e.resourceType}?${i}`))&&void 0!==n?n:this.createResource(e)}))}createBinary(e,t,i){let n=this.fhirUrl("Binary");return t&&(n+="?_filename="+encodeURIComponent(t)),this.post(n,e,i)}createPdf(e,t){let i=this.fhirUrl("Binary")+"/$pdf";return t&&(i+="?_filename="+encodeURIComponent(t)),this.post(i,e,"application/json")}updateResource(e){return e.resourceType?e.id?this.put(this.fhirUrl(e.resourceType,e.id),e):Promise.reject("Missing id"):Promise.reject("Missing resourceType")}patchResource(e,t,i){return this.patch(this.fhirUrl(e,t),i)}deleteResource(e,t){return this.delete(this.fhirUrl(e,t))}graphql(e,t){return this.post(this.fhirUrl("$graphql"),{query:e},"application/json",t)}getActiveLogin(){return i(this,oe,"f").getObject("activeLogin")}setActiveLogin(e){return t(this,void 0,void 0,(function*(){n(this,pe,e.accessToken,"f"),n(this,me,e.refreshToken,"f"),n(this,ye,void 0,"f"),n(this,Te,void 0,"f"),i(this,oe,"f").setObject("activeLogin",e),i(this,ne,"m",we).call(this,e),i(this,ae,"f").clear(),n(this,ge,void 0,"f"),yield i(this,ne,"m",Se).call(this)}))}setAccessToken(e){n(this,pe,e,"f"),n(this,me,void 0,"f"),n(this,ye,void 0,"f"),n(this,Te,void 0,"f")}getLogins(){var e;return null!==(e=i(this,oe,"f").getObject("logins"))&&void 0!==e?e:[]}isLoading(){return!!i(this,ve,"f")}getProfile(){return i(this,ye,"f")}getProfileAsync(){return t(this,void 0,void 0,(function*(){return i(this,ve,"f")&&(yield i(this,ve,"f")),this.getProfile()}))}getUserConfiguration(){return i(this,Te,"f")}download(e,n={}){return t(this,void 0,void 0,(function*(){i(this,ge,"f")&&(yield i(this,ge,"f")),i(this,ne,"m",Re).call(this,n);return(yield i(this,re,"f").call(this,e,n)).blob()}))}processCode(e){if(!i(this,oe,"f").getString("pkceState"))return this.clear(),Promise.reject("Invalid PCKE state");const t=i(this,oe,"f").getString("codeVerifier");return t?i(this,ne,"m",ke).call(this,"grant_type=authorization_code"+(i(this,le,"f")?"&client_id="+encodeURIComponent(i(this,le,"f")):"")+"&code_verifier="+encodeURIComponent(t)+"&redirect_uri="+encodeURIComponent(He())+"&code="+encodeURIComponent(e)):(this.clear(),Promise.reject("Invalid PCKE code verifier"))}clientCredentials(e,n){return t(this,void 0,void 0,(function*(){return i(this,ne,"m",ke).call(this,"grant_type=client_credentials&client_id="+encodeURIComponent(e)+"&client_secret="+encodeURIComponent(n))}))}},e.OperationOutcomeError=F,e.ReadablePromise=Y,e.SEGMENT_SEPARATOR="\r",e.accessDenied=B,e.allOk=x,e.arrayBufferToBase64=A,e.arrayBufferToHex=R,e.assertOk=function(e,t){if(!H(e)||void 0===t)throw new F(e)},e.badRequest=function(e,t){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:e},expression:t?[t]:void 0}]}},e.buildTypeName=We,e.calculateAge=p,e.calculateAgeString=function(e,t){const{years:i,months:n,days:r}=p(e,t);return i>=2?i.toString().padStart(3,"0")+"Y":n>=1?n.toString().padStart(3,"0")+"M":r.toString().padStart(3,"0")+"D"},e.capitalize=O,e.createReference=function(e){const t=u(e),i=d(e);return i===t?{reference:t}:{reference:t,display:i}},e.createSchema=xe,e.createTypeSchema=Le,e.created=L,e.deepEquals=T,e.formatAddress=function(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()},e.formatFamilyName=function(e){return e.family||""},e.formatGivenName=function(e){const t=[];return e.given&&t.push(...e.given),t.join(" ").trim()},e.formatHumanName=l,e.formatSearchQuery=Z,e.getDateProperty=function(e){return e?new Date(e):void 0},e.getDisplayString=d,e.getExpressionForResourceType=qe,e.getExtensionValue=function(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},e.getImageSrc=function(e){if(h(e)){const t=e.photo;if(t)for(const e of t){const t=f(e);if(t)return t}}if("Bot"===e.resourceType&&e.photo){const t=f(e.photo);if(t)return t}},e.getPropertyDisplayName=function(e){const t=e.path.replaceAll("[x]","").split(".").pop();return"id"===t?"ID":t.split(/(?=[A-Z])/).map(O).join(" ").replace("_"," ").replace(/\s+/g," ")},e.getQuestionnaireAnswers=function(e){const t={};return m(e.item,t),t},e.getReferenceString=u,e.getSearchParameterDetails=function(t,i,n){var r,o,s,a;if("_lastUpdated"===n.code)return{columnName:"lastUpdated",type:e.SearchParameterType.DATETIME};const c=n.code.split("-").reduce(((e,t,i)=>e+(i?O(t):t)),""),l=null===(r=qe(i,n.expression))||void 0===r?void 0:r.split(".");if(!l)return{columnName:c,type:e.SearchParameterType.TEXT};let u,h,d=i,f=!1;for(let i=1;i<l.length;i++){const n=l[i];if(u=null===(s=null===(o=t.types[d])||void 0===o?void 0:o.properties)||void 0===s?void 0:s[n],!u)return{columnName:c,type:e.SearchParameterType.TEXT,array:f};if("*"===u.max&&(f=!0),h=null===(a=u.type)||void 0===a?void 0:a[0].code,!h)return{columnName:c,type:e.SearchParameterType.TEXT,array:f};i<l.length-1&&("Element"===h||"BackboneElement"===h?d+=O(n):d=h)}const p=function(t,i){let n=e.SearchParameterType.TEXT;switch(t.type){case"date":n=e.SearchParameterType.DATE;break;case"number":n=e.SearchParameterType.NUMBER;break;case"quantity":n=e.SearchParameterType.QUANTITY;break;case"reference":n=e.SearchParameterType.REFERENCE;break;case"token":"boolean"===i&&(n=e.SearchParameterType.BOOLEAN)}return n}(n,h);return{columnName:c,type:p,elementDefinition:u,array:f}},e.getStatus=function(e){return e.id===b?200:e.id===k?201:e.id===I?304:e.id===N?403:e.id===M?404:e.id===_?410:400},e.gone=W,e.indexSearchParameter=De,e.indexStructureDefinition=je,e.isGone=function(e){return e.id===_},e.isLowerCase=function(e){return e===e.toLowerCase()},e.isNotFound=function(e){return e.id===M},e.isObject=w,e.isOk=H,e.isProfileResource=h,e.isStringArray=S,e.isUUID=function(e){return!!e.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)},e.notFound=D,e.notModified=j,e.parseSearchDefinition=J,e.resolveId=function(e){var t;return null===(t=null==e?void 0:e.reference)||void 0===t?void 0:t.split("/")[1]},e.stringify=g,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).medplum=t.medplum||{},t.medplum.core={}))}(this,(function(t){"use strict";function e(t,e,r,n){return new(r||(r=Promise))((function(i,s){function o(t){try{l(n.next(t))}catch(t){s(t)}}function a(t){try{l(n.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,a)}l((n=n.apply(t,e||[])).next())}))}function r(t,e,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}function n(t,e,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(t,r):i?i.value=r:e.set(t,r),r}var i,s,o,a;class l{constructor(t=10){i.add(this),s.set(this,void 0),o.set(this,void 0),n(this,s,t,"f"),n(this,o,new Map,"f")}clear(){r(this,o,"f").clear()}get(t){const e=r(this,o,"f").get(t);return e&&(r(this,o,"f").delete(t),r(this,o,"f").set(t,e)),e}set(t,e){r(this,o,"f").has(t)?r(this,o,"f").delete(t):r(this,o,"f").size>=r(this,s,"f")&&r(this,o,"f").delete(r(this,i,"m",a).call(this)),r(this,o,"f").set(t,e)}delete(t){r(this,o,"f").delete(t)}keys(){return r(this,o,"f").keys()}}function c(t,e){const r=[];return t.prefix&&((null==e?void 0:e.all)||(null==e?void 0:e.prefix))&&r.push(...t.prefix),t.given&&r.push(...t.given),t.family&&r.push(t.family),t.suffix&&((null==e?void 0:e.all)||(null==e?void 0:e.suffix))&&r.push(...t.suffix),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&r.push("["+t.use+"]"),r.join(" ").trim()}function u(t){const e=h(t),r=d(t);return r===e?{reference:e}:{reference:e,display:r}}function h(t){return t.resourceType+"/"+t.id}function f(t){return"Patient"===t.resourceType||"Practitioner"===t.resourceType||"RelatedPerson"===t.resourceType}function d(t){var e,r;if(f(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===(r=t.code)||void 0===r?void 0:r.text:"User"===t.resourceType&&t.email?t.email:"name"in t&&t.name&&"string"==typeof t.name?t.name:h(t)}function p(t){if(t.url&&t.contentType&&t.contentType.startsWith("image/"))return t.url}function v(t,e){const r=new Date(t);r.setUTCHours(0,0,0,0);const n=e?new Date(e):new Date;n.setUTCHours(0,0,0,0);const i=r.getUTCFullYear(),s=r.getUTCMonth(),o=r.getUTCDate(),a=n.getUTCFullYear(),l=n.getUTCMonth(),c=n.getUTCDate();let u=a-i;(l<s||l===s&&c<o)&&u--;let h=12*a+l-(12*i+s);c<o&&h--;return{years:u,months:h,days:Math.floor((n.getTime()-r.getTime())/864e5)}}function m(t,e){if(t)for(const r of t)r.linkId&&r.answer&&r.answer.length>0&&(e[r.linkId]=r.answer[0]),m(r.item,e)}function g(t,e){return JSON.stringify(t,y,e?2:void 0)}function y(t,e){return!function(t){return!!t.match(/\d+$/)}(t)&&w(e)?void 0:e}function w(t){if(null==t)return!0;const e=typeof t;return"string"===e&&""===t||"object"===e&&0===Object.keys(t).length}function T(t,e,r){return t===e||(!(!w(t)||!w(e))||!w(t)&&!w(e)&&(Array.isArray(t)&&Array.isArray(e)?function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!T(t[r],e[r]))return!1;return!0}(t,e):!Array.isArray(t)&&!Array.isArray(e)&&(S(t)&&S(e)?function(t,e,r){const n=new Set;Object.keys(t).forEach((t=>n.add(t))),Object.keys(e).forEach((t=>n.add(t))),"meta"===r&&(n.delete("versionId"),n.delete("lastUpdated"),n.delete("author"));for(const r of n){if(!T(t[r],e[r],r))return!1}return!0}(t,e,r):(S(t)||S(e),!1))))}function S(t){return null!==t&&"object"==typeof t}function b(t){return t.every((t=>"string"==typeof t))}s=new WeakMap,o=new WeakMap,i=new WeakSet,a=function(){return r(this,o,"f").keys().next().value};const E=[];for(let t=0;t<256;t++)E.push(t.toString(16).padStart(2,"0"));function P(t){const e=new Uint8Array(t),r=new Array(e.length);for(let t=0;t<e.length;t++)r[t]=E[e[t]];return r.join("")}function A(t){const e=new Uint8Array(t),r=[];for(let t=0;t<e.length;t++)r[t]=String.fromCharCode(e[t]);return window.btoa(r.join(""))}function O(t){return t.charAt(0).toUpperCase()+t.substring(1)}function k(){const t=new Uint32Array(28);return crypto.getRandomValues(t),P(t.buffer)}var x;function R(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,"/")),r=Array.from(e).reduce(((t,e)=>`${t}%${("00"+e.charCodeAt(0).toString(16)).slice(-2)}`),""),n=decodeURIComponent(r);return JSON.parse(n)}x=new WeakMap;const U="ok",M="created",C="gone",L="not-modified",D="not-found",I="access-denied",_={resourceType:"OperationOutcome",id:U,issue:[{severity:"information",code:"information",details:{text:"All OK"}}]},j={resourceType:"OperationOutcome",id:M,issue:[{severity:"information",code:"information",details:{text:"Created"}}]},N={resourceType:"OperationOutcome",id:L,issue:[{severity:"information",code:"information",details:{text:"Not Modified"}}]},W={resourceType:"OperationOutcome",id:D,issue:[{severity:"error",code:"not-found",details:{text:"Not found"}}]},B={resourceType:"OperationOutcome",id:C,issue:[{severity:"error",code:"gone",details:{text:"Gone"}}]},H={resourceType:"OperationOutcome",id:I,issue:[{severity:"error",code:"access-denied",details:{text:"Access Denied"}}]};function F(t){return t.id===U||t.id===M||t.id===L}class Q extends Error{constructor(t){var e,r;super(null===(r=null===(e=null==t?void 0:t.issue)||void 0===e?void 0:e[0].details)||void 0===r?void 0:r.text),this.outcome=t}}function $(t,r,n){return e(this,void 0,void 0,(function*(){return t.pageSize=t.pageSize||"LETTER",t.pageMargins=t.pageMargins||[60,60,60,60],t.pageOrientation=t.pageOrientation||"portrait",t.defaultStyle=t.defaultStyle||{},t.defaultStyle.font=t.defaultStyle.font||"Helvetica",t.defaultStyle.fontSize=t.defaultStyle.fontSize||11,t.defaultStyle.lineHeight=t.defaultStyle.lineHeight||2,"undefined"==typeof pdfMake?function(t,r,n){return e(this,void 0,void 0,(function*(){return n||(n={Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"},Roboto:{normal:"https://static.medplum.com/fonts/Roboto-Regular.ttf",bold:"https://static.medplum.com/fonts/Roboto-Medium.ttf",italics:"https://static.medplum.com/fonts/Roboto-Italic.ttf",bolditalics:"https://static.medplum.com/fonts/Roboto-MediumItalic.ttf"},Avenir:{normal:"https://static.medplum.com/fonts/avenir.ttf"}}),new Promise(((e,i)=>{const s=new(require("pdfmake"))(n).createPdfKitDocument(t,{tableLayouts:r}),o=[];s.on("data",(t=>o.push(t))),s.on("end",(()=>e(Buffer.concat(o)))),s.on("error",i),s.end()}))}))}(t,r,n):function(t,r,n){return e(this,void 0,void 0,(function*(){return n||(n={Helvetica:{normal:"https://static.medplum.com/fonts/Helvetica.ttf",bold:"https://static.medplum.com/fonts/Helvetica-bold.ttf",italics:"https://static.medplum.com/fonts/Helvetica-italic.ttf",bolditalics:"https://static.medplum.com/fonts/Helvetica-bold-italic.ttf"},Roboto:{normal:"https://static.medplum.com/fonts/Roboto-Regular.ttf",bold:"https://static.medplum.com/fonts/Roboto-Medium.ttf",italics:"https://static.medplum.com/fonts/Roboto-Italic.ttf",bolditalics:"https://static.medplum.com/fonts/Roboto-MediumItalic.ttf"},Avenir:{normal:"https://static.medplum.com/fonts/avenir.ttf"}}),new Promise((e=>{pdfMake.createPdf(t,r,n).getBlob(e)}))}))}(t,r,n)}))}var q,z,X,G,Y;class V{constructor(t){this[Y]="ReadablePromise",q.set(this,void 0),z.set(this,"pending"),X.set(this,void 0),G.set(this,void 0),n(this,q,t.then((t=>(n(this,z,"success","f"),n(this,X,t,"f"),t)),(t=>{throw n(this,z,"error","f"),n(this,G,t,"f"),t})),"f")}isPending(){return"pending"===r(this,z,"f")}read(){switch(r(this,z,"f")){case"pending":throw r(this,q,"f");case"error":throw r(this,G,"f");default:return r(this,X,"f")}}then(t,e){return r(this,q,"f").then(t,e)}catch(t){return r(this,q,"f").catch(t)}finally(t){return r(this,q,"f").finally(t)}}q=new WeakMap,z=new WeakMap,X=new WeakMap,G=new WeakMap,Y=Symbol.toStringTag;var K;t.Operator=void 0,(K=t.Operator||(t.Operator={})).EQUALS="eq",K.NOT_EQUALS="ne",K.GREATER_THAN="gt",K.LESS_THAN="lt",K.GREATER_THAN_OR_EQUALS="ge",K.LESS_THAN_OR_EQUALS="le",K.STARTS_AFTER="sa",K.ENDS_BEFORE="eb",K.APPROXIMATELY="ap",K.CONTAINS="contains",K.EXACT="exact",K.TEXT="text",K.ABOVE="above",K.BELOW="below",K.IN="in",K.NOT_IN="not-in",K.OF_TYPE="of-type";const J=[t.Operator.CONTAINS,t.Operator.EXACT,t.Operator.TEXT,t.Operator.ABOVE,t.Operator.BELOW,t.Operator.IN,t.Operator.NOT_IN,t.Operator.OF_TYPE],Z=[t.Operator.NOT_EQUALS,t.Operator.GREATER_THAN,t.Operator.LESS_THAN,t.Operator.GREATER_THAN_OR_EQUALS,t.Operator.LESS_THAN_OR_EQUALS,t.Operator.STARTS_AFTER,t.Operator.ENDS_BEFORE,t.Operator.APPROXIMATELY];function tt(e){const r=new URL(e,"https://example.com/"),n=r.pathname.replace(/(^\/)|(\/$)/g,"").split("/").pop();let i,s,o,a,l,c;return new URLSearchParams(r.search).forEach(((e,r)=>{"_fields"===r?o=e.split(","):"_offset"===r?a=parseInt(e):"_count"===r?l=parseInt(e):"_total"===r?c=e:"_sort"===r?(s=s||[],s.push(function(t){return t.startsWith("-")?{code:t.substring(1),descending:!0}:{code:t}}(e))):(i=i||[],i.push(function(e,r){let n=e,i=t.Operator.EQUALS;for(const t of J){const e=n.indexOf(":"+t);-1!==e&&(i=t,n=n.substring(0,e))}for(const t of Z)r.match(new RegExp("^"+t+"\\d"))&&(i=t,r=r.substring(t.length));return{code:n,operator:i,value:r}}(r,e)))})),{resourceType:n,filters:i,fields:o,offset:a,count:l,total:c,sortRules:s}}function et(t){const e=[];return t.fields&&e.push("_fields="+t.fields.join(",")),t.filters&&t.filters.forEach((t=>e.push(function(t){const e=J.includes(t.operator)?":"+t.operator:"",r=Z.includes(t.operator)?t.operator:"";return`${t.code}${e}=${r}${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 rt,nt,it,st,ot,at,lt,ct,ut,ht,ft,dt,pt,vt,mt,gt,yt,wt,Tt,St,bt,Et,Pt,At,Ot,kt,xt,Rt,Ut,Mt,Ct,Lt,Dt;class It{constructor(){rt.set(this,void 0),n(this,rt,"undefined"!=typeof localStorage?localStorage:new _t,"f")}clear(){r(this,rt,"f").clear()}getString(t){return r(this,rt,"f").getItem(t)||void 0}setString(t,e){e?r(this,rt,"f").setItem(t,e):r(this,rt,"f").removeItem(t)}getObject(t){const e=this.getString(t);return e?JSON.parse(e):void 0}setObject(t,e){this.setString(t,e?g(e):void 0)}}rt=new WeakMap;class _t{constructor(){nt.set(this,void 0),n(this,nt,new Map,"f")}get length(){return r(this,nt,"f").size}clear(){r(this,nt,"f").clear()}getItem(t){var e;return null!==(e=r(this,nt,"f").get(t))&&void 0!==e?e:null}setItem(t,e){e?r(this,nt,"f").set(t,e):r(this,nt,"f").delete(t)}removeItem(t){r(this,nt,"f").delete(t)}key(t){return Array.from(r(this,nt,"f").keys())[t]}}function jt(){return{types:{}}}function Nt(t,e){return{display:t,description:e,properties:{},searchParams:{_lastUpdated:{base:[t],code:"_lastUpdated",type:"date",expression:t+".meta.lastUpdated"}}}}function Wt(t,e){var r;const n=e.name;if(!n)return;t.types[n]=Nt(n,e.description);const i=null===(r=e.snapshot)||void 0===r?void 0:r.element;if(i){const e=i.filter((t=>t.path!==n&&t.path));e.forEach((e=>function(t,e){var r,n;const i=e.path,s=null===(n=null===(r=e.type)||void 0===r?void 0:r[0])||void 0===n?void 0:n.code;if("Element"!==s&&"BackboneElement"!==s)return;const o=i.split("."),a=Ht(o);a in t.types||(t.types[a]=Nt(a,e.definition),t.types[a].parentType=Ht(o.slice(0,o.length-1)))}(t,e))),e.forEach((e=>function(t,e){const r=e.path.split(".");if(1===r.length)return;const n=Ht(r.slice(0,r.length-1)),i=t.types[n],s=r[r.length-1];i.properties[s]=e}(t,e)))}}function Bt(t,e){if(e.base)for(const r of e.base){const n=t.types[r];n&&(n.searchParams||(n.searchParams={}),n.searchParams[e.code]=e)}}function Ht(t){return t.map(O).join("")}nt=new WeakMap,t.PropertyType=void 0,(it=t.PropertyType||(t.PropertyType={})).Address="Address",it.Age="Age",it.Annotation="Annotation",it.Attachment="Attachment",it.BackboneElement="BackboneElement",it.CodeableConcept="CodeableConcept",it.Coding="Coding",it.ContactDetail="ContactDetail",it.ContactPoint="ContactPoint",it.Contributor="Contributor",it.Count="Count",it.DataRequirement="DataRequirement",it.Distance="Distance",it.Dosage="Dosage",it.Duration="Duration",it.Expression="Expression",it.Extension="Extension",it.HumanName="HumanName",it.Identifier="Identifier",it.MarketingStatus="MarketingStatus",it.Meta="Meta",it.Money="Money",it.Narrative="Narrative",it.ParameterDefinition="ParameterDefinition",it.Period="Period",it.Population="Population",it.ProdCharacteristic="ProdCharacteristic",it.ProductShelfLife="ProductShelfLife",it.Quantity="Quantity",it.Range="Range",it.Ratio="Ratio",it.Reference="Reference",it.RelatedArtifact="RelatedArtifact",it.Resource="Resource",it.SampledData="SampledData",it.Signature="Signature",it.SubstanceAmount="SubstanceAmount",it.SystemString="http://hl7.org/fhirpath/System.String",it.Timing="Timing",it.TriggerDefinition="TriggerDefinition",it.UsageContext="UsageContext",it.base64Binary="base64Binary",it.boolean="boolean",it.canonical="canonical",it.code="code",it.date="date",it.dateTime="dateTime",it.decimal="decimal",it.id="id",it.instant="instant",it.integer="integer",it.markdown="markdown",it.oid="oid",it.positiveInt="positiveInt",it.string="string",it.time="time",it.unsignedInt="unsignedInt",it.uri="uri",it.url="url",it.uuid="uuid";const Ft="launch/patient openid fhirUser offline_access user/*.*";function Qt(){return window.location.protocol+"//"+window.location.host+"/"}function $t(e){return[{type:t.PropertyType.boolean,value:e}]}function qt(e){return Number.isSafeInteger(e)?{type:t.PropertyType.integer,value:e}:"number"==typeof e?{type:t.PropertyType.decimal,value:e}:"boolean"==typeof e?{type:t.PropertyType.boolean,value:e}:"string"==typeof e?{type:t.PropertyType.string,value:e}:te(e)?{type:t.PropertyType.Quantity,value:e}:{type:t.PropertyType.BackboneElement,value:e}}function zt(t){return 0!==t.length&&!!t[0].value}function Xt(t){const e=[];for(const r of t){let t=!1;for(const n of e)if(zt(Vt(r,n))){t=!0;break}t||e.push(r)}return e}function Gt(t){return $t(!zt(t))}function Yt(t,e){return 0===t.length||0===e.length?[]:t.length!==e.length?$t(!1):$t(t.every(((t,r)=>zt(Vt(t,e[r])))))}function Vt(t,e){const r=t.value,n=e.value;return"number"==typeof r&&"number"==typeof n?$t(Math.abs(r-n)<1e-8):te(r)&&te(n)?$t(ee(r,n)):$t("object"==typeof r&&"object"==typeof n?re(t,e):r===n)}function Kt(t,e){return 0===t.length&&0===e.length?$t(!0):t.length!==e.length?$t(!1):(t.sort(Jt),e.sort(Jt),$t(t.every(((t,r)=>zt(function(t,e){const r=t.value,n=e.value;if("number"==typeof r&&"number"==typeof n)return $t(Math.abs(r-n)<.01);if(te(r)&&te(n))return $t(ee(r,n));if("object"==typeof r&&"object"==typeof n)return $t(re(r,n));if("string"==typeof r&&"string"==typeof n)return $t(r.toLowerCase()===n.toLowerCase());return $t(r===n)}(t,e[r]))))))}function Jt(t,e){const r=t.value,n=e.value;return"number"==typeof r&&"number"==typeof n?r-n:"string"==typeof r&&"string"==typeof n?r.localeCompare(n):0}function Zt(t,e){const{value:r}=t;if(null==r)return!1;switch(e){case"Boolean":return"boolean"==typeof r;case"Decimal":case"Integer":return"number"==typeof r;case"Date":return"string"==typeof r&&!!r.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof r&&!!r.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof r&&!!r.match(/^T\d/);case"Period":return!(!(n=r)||"object"!=typeof n||!("start"in n));case"Quantity":return te(r);default:return"object"==typeof r&&(null==r?void 0:r.resourceType)===e}var n}function te(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function ee(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 re(t,e){const r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(const n of r){const r=t[n],i=e[n];if(ne(r)&&ne(i)){if(!re(r,i))return!1}else if(r!==i)return!1}return!0}function ne(t){return null!==t&&"object"==typeof t}var ie,se;ot=new WeakMap,at=new WeakMap,lt=new WeakMap,ct=new WeakMap,ut=new WeakMap,ht=new WeakMap,ft=new WeakMap,dt=new WeakMap,pt=new WeakMap,vt=new WeakMap,mt=new WeakMap,gt=new WeakMap,yt=new WeakMap,wt=new WeakMap,Tt=new WeakMap,St=new WeakMap,st=new WeakSet,bt=function(t){const e=this.getLogins().filter((e=>{var r,n;return(null===(r=e.profile)||void 0===r?void 0:r.reference)!==(null===(n=t.profile)||void 0===n?void 0:n.reference)}));e.push(t),r(this,at,"f").setObject("logins",e)},Et=function(){return e(this,void 0,void 0,(function*(){return n(this,wt,new Promise(((t,e)=>{this.get("auth/me").then((e=>{n(this,wt,void 0,"f"),n(this,Tt,e.profile,"f"),n(this,St,e.config,"f"),this.dispatchEvent({type:"change"}),t(r(this,Tt,"f"))})).catch(e)})),"f"),r(this,wt,"f")}))},Pt=function(t,n,i={}){return e(this,void 0,void 0,(function*(){r(this,yt,"f")&&(yield r(this,yt,"f")),n.startsWith("http")||(n=r(this,ut,"f")+n),i.method=t,r(this,st,"m",At).call(this,i);const e=yield r(this,ot,"f").call(this,n,i);if(401===e.status)return r(this,st,"m",xt).call(this,t,n,i);if(204===e.status||304===e.status)return;const s=yield e.json();return"OperationOutcome"!==(null==s?void 0:s.resourceType)||F(s)?s:Promise.reject(s)}))},At=function(t){t.headers||(t.headers={});const e=t.headers;e["Content-Type"]||(e["Content-Type"]="application/fhir+json"),r(this,mt,"f")&&(e.Authorization="Bearer "+r(this,mt,"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},kt=function(t,e){"string"==typeof e||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof Buffer&&e instanceof Buffer||"undefined"!=typeof File&&e instanceof File?t.body=e:e&&(t.body=JSON.stringify(e))},xt=function(t,n,i){return e(this,void 0,void 0,(function*(){return r(this,st,"m",Mt).call(this).then((()=>r(this,st,"m",Pt).call(this,t,n,i))).catch((t=>(this.clear(),r(this,vt,"f")&&r(this,vt,"f").call(this),Promise.reject(t))))}))},Rt=function(){return e(this,void 0,void 0,(function*(){const t=k();r(this,at,"f").setString("pkceState",t);const n=k();r(this,at,"f").setString("codeVerifier",n);const i=A(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,"");r(this,at,"f").setString("codeChallenge",i)}))},Ut=function(){r(this,st,"m",Rt).call(this);const t=new URL(r(this,ft,"f"));t.searchParams.set("response_type","code"),t.searchParams.set("state",r(this,at,"f").getString("pkceState")),t.searchParams.set("client_id",r(this,ht,"f")),t.searchParams.set("redirect_uri",Qt()),t.searchParams.set("scope",Ft),t.searchParams.set("code_challenge_method","S256"),t.searchParams.set("code_challenge",r(this,at,"f").getString("codeChallenge")),window.location.assign(t.toString())},Mt=function(){return e(this,void 0,void 0,(function*(){if(r(this,yt,"f"))return r(this,yt,"f");if(!r(this,gt,"f"))throw this.clear(),new Error("Invalid refresh token");const t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("client_id",r(this,ht,"f")),t.set("refresh_token",r(this,gt,"f")),n(this,yt,r(this,st,"m",Ct).call(this,t),"f"),yield r(this,yt,"f")}))},Ct=function(t){return e(this,void 0,void 0,(function*(){return r(this,ot,"f").call(this,r(this,dt,"f"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:t}).then((t=>{if(!t.ok)throw new Error("Failed to fetch tokens");return t.json()})).then((t=>r(this,st,"m",Lt).call(this,t))).then((()=>this.getProfile()))}))},Lt=function(t){return e(this,void 0,void 0,(function*(){const e=t.access_token,n=function(t){const[e,r,n]=t.split(".");return R(r)}(e);if(Date.now()>=1e3*n.exp)throw this.clear(),new Error("Token expired");if(r(this,ht,"f")&&n.client_id!==r(this,ht,"f"))throw this.clear(),new Error("Token was not issued for this audience");yield this.setActiveLogin({accessToken:e,refreshToken:t.refresh_token,project:t.project,profile:t.profile})}))},Dt=function(){try{window.addEventListener("storage",(t=>{null!==t.key&&"activeLogin"!==t.key||window.location.reload()}))}catch(t){}};class oe{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 ae{constructor(t){this.value=t}eval(){return[this.value]}}class le{constructor(t){this.name=t,ie.add(this)}eval(t){return"$this"===this.name?t:t.map((t=>r(this,ie,"m",se).call(this,t))).flat().filter((t=>void 0!==(null==t?void 0:t.value)))}}ie=new WeakSet,se=function(t){const e=t.value;if(!e||"object"!=typeof e)return;if("resourceType"in e&&e.resourceType===this.name)return t;let r;if(this.name in e)r=e[this.name];else{const t=Object.keys(e).find((t=>t.startsWith(this.name)));t&&(r=e[t])}return void 0!==r?Array.isArray(r)?r.map(qt):[qt(r)]:void 0};class ce{eval(){return[]}}class ue{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class he{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class fe{constructor(t,e,r){this.left=t,this.right=e,this.impl=r}eval(e){const r=this.left.eval(e);if(1!==r.length)return[];const n=this.right.eval(e);if(1!==n.length)return[];const i=r[0].value,s=n[0].value,o=te(i)?i.value:i,a=te(s)?s.value:s,l=this.impl(o,a);return"boolean"==typeof l?$t(l):te(i)?[{type:t.PropertyType.Quantity,value:Object.assign(Object.assign({},i),{value:l})}]:[qt(l)]}}class de{constructor(t,e){this.left=t,this.right=e}eval(e){const r=[...this.left.eval(e),...this.right.eval(e)];return r.length>0&&r.every((t=>"string"==typeof t.value))?[{type:t.PropertyType.string,value:r.map((t=>t.value)).join("")}]:r}}class pe{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return $t(e.some((t=>t.value===r[0].value)))}}class ve{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return $t(this.right.eval(t).some((t=>t.value===e[0].value)))}}class me{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class ge{constructor(t,e){this.left=t,this.right=e}eval(t){return Xt([...this.left.eval(t),...this.right.eval(t)])}}class ye{constructor(t,e){this.left=t,this.right=e}eval(t){return Yt(this.left.eval(t),this.right.eval(t))}}class we{constructor(t,e){this.left=t,this.right=e}eval(t){return Gt(Yt(this.left.eval(t),this.right.eval(t)))}}class Te{constructor(t,e){this.left=t,this.right=e}eval(t){return Kt(this.left.eval(t),this.right.eval(t))}}class Se{constructor(t,e){this.left=t,this.right=e}eval(t){return Gt(Kt(this.left.eval(t),this.right.eval(t)))}}class be{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(1!==e.length)return[];const r=this.right.name;return $t(Zt(e[0],r))}}class Ee{constructor(t,e){this.left=t,this.right=e}eval(t){var e,r,n,i;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===(r=o[0])||void 0===r?void 0:r.value)?$t(!0):!1===(null===(n=s[0])||void 0===n?void 0:n.value)||!1===(null===(i=o[0])||void 0===i?void 0:i.value)?$t(!1):[]}}class Pe{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(zt(e))return e;const r=this.right.eval(t);return zt(r)?r:[]}}class Ae{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);if(0===e.length&&0===r.length)return[];const n=0===e.length?null:e[0].value,i=0===r.length?null:r[0].value;return!0===n&&!0!==i||!0!==n&&!0===i?$t(!0):!0===n&&!0===i||!1===n&&!1===i?$t(!1):[]}}class Oe{constructor(t,e,r){this.name=t,this.args=e,this.impl=r}eval(t){return this.impl(t,...this.args)}}class ke{constructor(t,e){this.left=t,this.expr=e}eval(t){const e=this.expr.eval(t);if(1!==e.length)return[];const r=e[0].value;if("number"!=typeof r)throw new Error("Invalid indexer expression: should return integer}");const n=this.left.eval(t);return r in n?[n[r]]:[]}}function xe(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 Re=()=>[],Ue={empty:t=>$t(0===t.length),exists:(t,e)=>$t(e?t.filter((t=>zt(e.eval([t])))).length>0:t.length>0),all:(t,e)=>$t(t.every((t=>zt(e.eval([t]))))),allTrue:t=>{for(const e of t)if(!e.value)return $t(!1);return $t(!0)},anyTrue:t=>{for(const e of t)if(e.value)return $t(!0);return $t(!1)},allFalse:t=>{for(const e of t)if(e.value)return $t(!1);return $t(!0)},anyFalse:t=>{for(const e of t)if(!e.value)return $t(!0);return $t(!1)},subsetOf:Re,supersetOf:Re,count:e=>[{type:t.PropertyType.integer,value:e.length}],distinct:t=>{const e=[];for(const r of t)e.some((t=>t.value===r.value))||e.push(r);return e},isDistinct:t=>$t(t.length===Ue.distinct(t).length),where:(t,e)=>t.filter((t=>zt(e.eval([t])))),select:(t,e)=>t.map((t=>e.eval([t]))).flat(),repeat:Re,ofType:Re,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 r;const n=null===(r=e.eval([])[0])||void 0===r?void 0:r.value;if("number"!=typeof n)throw new Error("Expected a number for skip(num)");return n>=t.length?[]:n<=0?t:t.slice(n,t.length)},take:(t,e)=>{var r;const n=null===(r=e.eval([])[0])||void 0===r?void 0:r.value;if("number"!=typeof n)throw new Error("Expected a number for take(num)");return n>=t.length?t:n<=0?[]:t.slice(0,n)},intersect:(t,e)=>{if(!e)return t;const r=e.eval([]),n=[];for(const e of t)!n.some((t=>t.value===e.value))&&r.some((t=>t.value===e.value))&&n.push(e);return n},exclude:(t,e)=>{if(!e)return t;const r=e.eval([]),n=[];for(const e of t)r.some((t=>t.value===e.value))||n.push(e);return n},union:(t,e)=>{if(!e)return t;const r=e.eval([]);return Xt([...t,...r])},combine:(t,e)=>{if(!e)return t;const r=e.eval([]);return[...t,...r]},iif:(t,e,r,n)=>{const i=e.eval(t);if(i.length>1||1===i.length&&"boolean"!=typeof i[0].value)throw new Error("Expected criterion to evaluate to a Boolean");return zt(i)?r.eval(t):n?n.eval(t):[]},toBoolean:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);if("boolean"==typeof r)return[{type:t.PropertyType.boolean,value:r}];if("number"==typeof r&&(0===r||1===r))return $t(!!r);if("string"==typeof r){const t=r.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return $t(!0);if(["false","f","no","n","0","0.0"].includes(t))return $t(!1)}return[]},convertsToBoolean:t=>0===t.length?[]:$t(1===Ue.toBoolean(t).length),toInteger:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);return"number"==typeof r?[{type:t.PropertyType.integer,value:r}]:"string"==typeof r&&r.match(/^[+-]?\d+$/)?[{type:t.PropertyType.integer,value:parseInt(r,10)}]:"boolean"==typeof r?[{type:t.PropertyType.integer,value:r?1:0}]:[]},convertsToInteger:t=>0===t.length?[]:$t(1===Ue.toInteger(t).length),toDate:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);return"string"==typeof r&&r.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:t.PropertyType.date,value:xe(r)}]:[]},convertsToDate:t=>0===t.length?[]:$t(1===Ue.toDate(t).length),toDateTime:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);return"string"==typeof r&&r.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[{type:t.PropertyType.dateTime,value:xe(r)}]:[]},convertsToDateTime:t=>0===t.length?[]:$t(1===Ue.toDateTime(t).length),toDecimal:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);return"number"==typeof r?[{type:t.PropertyType.decimal,value:r}]:"string"==typeof r&&r.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[{type:t.PropertyType.decimal,value:parseFloat(r)}]:"boolean"==typeof r?[{type:t.PropertyType.decimal,value:r?1:0}]:[]},convertsToDecimal:t=>0===t.length?[]:$t(1===Ue.toDecimal(t).length),toQuantity:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);return te(r)?[{type:t.PropertyType.Quantity,value:r}]:"number"==typeof r?[{type:t.PropertyType.Quantity,value:{value:r,unit:"1"}}]:"string"==typeof r&&r.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{type:t.PropertyType.Quantity,value:{value:parseFloat(r),unit:"1"}}]:"boolean"==typeof r?[{type:t.PropertyType.Quantity,value:{value:r?1:0,unit:"1"}}]:[]},convertsToQuantity:t=>0===t.length?[]:$t(1===Ue.toQuantity(t).length),toString:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);return null==r?[]:te(r)?[{type:t.PropertyType.string,value:`${r.value} '${r.unit}'`}]:[{type:t.PropertyType.string,value:r.toString()}]},convertsToString:t=>0===t.length?[]:$t(1===Ue.toString(t).length),toTime:e=>{if(0===e.length)return[];const[{value:r}]=Le(e,1);if("string"==typeof r){const e=r.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(e)return[{type:t.PropertyType.time,value:xe("T"+e[1])}]}return[]},convertsToTime:t=>0===t.length?[]:$t(1===Ue.toTime(t).length),indexOf:(t,e)=>Me(((t,e)=>t.indexOf(e)),t,e),substring:(t,e,r)=>Me(((t,e,r)=>{const n=e,i=r?n+r:t.length;return n<0||n>=t.length?void 0:t.substring(n,i)}),t,e,r),startsWith:(t,e)=>Me(((t,e)=>t.startsWith(e)),t,e),endsWith:(t,e)=>Me(((t,e)=>t.endsWith(e)),t,e),contains:(t,e)=>Me(((t,e)=>t.includes(e)),t,e),upper:t=>Me((t=>t.toUpperCase()),t),lower:t=>Me((t=>t.toLowerCase()),t),replace:(t,e,r)=>Me(((t,e,r)=>t.replaceAll(e,r)),t,e,r),matches:(t,e)=>Me(((t,e)=>!!t.match(e)),t,e),replaceMatches:(t,e,r)=>Me(((t,e,r)=>t.replaceAll(e,r)),t,e,r),length:t=>Me((t=>t.length),t),toChars:t=>Me((t=>t?t.split(""):void 0),t),abs:t=>Ce(Math.abs,t),ceiling:t=>Ce(Math.ceil,t),exp:t=>Ce(Math.exp,t),floor:t=>Ce(Math.floor,t),ln:t=>Ce(Math.log,t),log:(t,e)=>Ce(((t,e)=>Math.log(t)/Math.log(e)),t,e),power:(t,e)=>Ce(Math.pow,t,e),round:t=>Ce(Math.round,t),sqrt:t=>Ce(Math.sqrt,t),truncate:t=>Ce((t=>0|t),t),children:Re,descendants:Re,trace:(t,e)=>(console.log("trace",t,e),t),now:()=>[{type:t.PropertyType.dateTime,value:(new Date).toISOString()}],timeOfDay:()=>[{type:t.PropertyType.time,value:(new Date).toISOString().substring(11)}],today:()=>[{type:t.PropertyType.date,value:(new Date).toISOString().substring(0,10)}],between:(e,r,n,i)=>{const s=Ue.toDateTime(r.eval(e));if(0===s.length)throw new Error("Invalid start date");const o=Ue.toDateTime(n.eval(e));if(0===o.length)throw new Error("Invalid end date");const a=i.eval(e)[0].value;if("years"!==a&&"months"!==a&&"days"!==a)throw new Error("Invalid units");const l=v(s[0].value,o[0].value);return[{type:t.PropertyType.Quantity,value:{value:l[a],unit:a}}]},is:(e,r)=>{let n="";return r instanceof le?n=r.name:r instanceof me&&(n=r.left.name+"."+r.right.name),n?e.map((e=>({type:t.PropertyType.boolean,value:Zt(e,n)}))):[]},not:e=>Ue.toBoolean(e).map((e=>({type:t.PropertyType.boolean,value:!e.value}))),resolve:e=>e.map((e=>{const r=e.value;let n;if("string"==typeof r)n=r;else if("object"==typeof r){const e=r;if(e.resource)return{type:t.PropertyType.BackboneElement,value:e.resource};n=e.reference}if(!n)return{type:t.PropertyType.BackboneElement,value:null};const[i,s]=n.split("/");return{type:t.PropertyType.BackboneElement,value:{resourceType:i,id:s}}})).filter((t=>!!t.value)),as:t=>t,type:e=>e.map((({value:e})=>"boolean"==typeof e?{type:t.PropertyType.BackboneElement,value:{namespace:"System",name:"Boolean"}}:"number"==typeof e?{type:t.PropertyType.BackboneElement,value:{namespace:"System",name:"Integer"}}:e&&"object"==typeof e&&"resourceType"in e?{type:t.PropertyType.BackboneElement,value:{namespace:"FHIR",name:e.resourceType}}:{type:t.PropertyType.BackboneElement,value:null})),conformsTo:(e,r)=>{const n=r.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 e.map((e=>{var r;return{type:t.PropertyType.boolean,value:(null===(r=e.value)||void 0===r?void 0:r.resourceType)===i}}))}};function Me(t,e,...r){if(0===e.length)return[];const[{value:n}]=Le(e,1);if("string"!=typeof n)throw new Error("String function cannot be called with non-string");const i=t(n,...r.map((t=>{var r,n;return t&&(null===(n=null===(r=t.eval(e))||void 0===r?void 0:r[0])||void 0===n?void 0:n.value)})));return void 0===i?[]:Array.isArray(i)?i.map(qt):[qt(i)]}function Ce(e,r,...n){if(0===r.length)return[];const[{value:i}]=Le(r,1),s=te(i),o=s?i.value:i;if("number"!=typeof o)throw new Error("Math function cannot be called with non-number");const a=e(o,...n.map((t=>{var e,r;return null===(r=null===(e=t.eval([]))||void 0===e?void 0:e[0])||void 0===r?void 0:r.value})));return[{type:s?t.PropertyType.Quantity:r[0].type,value:s?Object.assign(Object.assign({},i),{value:a}):a}]}function Le(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 De,Ie,_e,je,Ne,We,Be,He,Fe,Qe,$e,qe,ze,Xe,Ge,Ye,Ve,Ke;function Je(t){return new er(t).tokenize()}const Ze=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],tr=["!=","!~","<=",">=","{}"];class er{constructor(t){De.add(this),Ie.set(this,void 0),_e.set(this,void 0),n(this,Ie,t,"f"),n(this,_e,0,"f")}tokenize(){const t=[];for(;r(this,_e,"f")<r(this,Ie,"f").length;){const e=r(this,De,"m",Ne).call(this);e&&t.push(e)}return t}}function rr(t,e){return{id:t,value:e}}var nr,ir,sr,or,ar,lr,cr,ur,hr;Ie=new WeakMap,_e=new WeakMap,De=new WeakSet,je=function(){const t=r(this,_e,"f"),e=r(this,De,"m",Ne).call(this);return n(this,_e,t,"f"),e},Ne=function(){r(this,De,"m",We).call(this);const t=r(this,De,"m",Ye).call(this);if(!t)return;const e=r(this,De,"m",Ke).call(this);return"/"===t&&"*"===e?r(this,De,"m",Be).call(this):"/"===t&&"/"===e?r(this,De,"m",He).call(this):"'"===t?r(this,De,"m",Fe).call(this):"`"===t?r(this,De,"m",Qe).call(this):"@"===t?r(this,De,"m",$e).call(this):t.match(/\d/)?r(this,De,"m",qe).call(this):t.match(/\w/)||"$"===t&&e.match(/\w/)?r(this,De,"m",ze).call(this):r(this,De,"m",Xe).call(this)},We=function(){return rr("Whitespace",r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/\s/))))},Be=function(){const t=r(this,_e,"f");return r(this,De,"m",Ge).call(this,(()=>"*"!==r(this,De,"m",Ye).call(this)||"/"!==r(this,De,"m",Ke).call(this))),n(this,_e,r(this,_e,"f")+2,"f"),rr("Comment",r(this,Ie,"f").substring(t,r(this,_e,"f")))},He=function(){return rr("Comment",r(this,De,"m",Ge).call(this,(()=>"\n"!==r(this,De,"m",Ye).call(this))))},Fe=function(){var t,e;n(this,_e,(t=r(this,_e,"f"),++t),"f");const i=rr("String",r(this,De,"m",Ge).call(this,(()=>"\\"===r(this,De,"m",Ve).call(this)||"'"!==r(this,De,"m",Ye).call(this))));return n(this,_e,(e=r(this,_e,"f"),++e),"f"),i},Qe=function(){var t,e;n(this,_e,(t=r(this,_e,"f"),++t),"f");const i=rr("Symbol",r(this,De,"m",Ge).call(this,(()=>"`"!==r(this,De,"m",Ye).call(this))));return n(this,_e,(e=r(this,_e,"f"),++e),"f"),i},$e=function(){var t,e,i,s,o;const a=r(this,_e,"f");return n(this,_e,(t=r(this,_e,"f"),++t),"f"),r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/[\d-]/))),"T"===r(this,De,"m",Ye).call(this)&&(n(this,_e,(e=r(this,_e,"f"),++e),"f"),r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/[\d:]/))),"."===r(this,De,"m",Ye).call(this)&&r(this,De,"m",Ke).call(this).match(/\d/)&&(n(this,_e,(i=r(this,_e,"f"),++i),"f"),r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/[\d]/)))),"Z"===r(this,De,"m",Ye).call(this)?n(this,_e,(s=r(this,_e,"f"),++s),"f"):"+"!==r(this,De,"m",Ye).call(this)&&"-"!==r(this,De,"m",Ye).call(this)||(n(this,_e,(o=r(this,_e,"f"),++o),"f"),r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/[\d:]/))))),rr("DateTime",r(this,Ie,"f").substring(a+1,r(this,_e,"f")))},qe=function(){var t;const e=r(this,_e,"f");let i="Number";return r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/\d/))),"."===r(this,De,"m",Ye).call(this)&&r(this,De,"m",Ke).call(this).match(/\d/)&&(n(this,_e,(t=r(this,_e,"f"),++t),"f"),r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/\d/))))," "===r(this,De,"m",Ye).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&Ze.includes(t.value))return!0}return!1}(r(this,De,"m",je).call(this))&&(i="Quantity",r(this,De,"m",Ne).call(this)),rr(i,r(this,Ie,"f").substring(e,r(this,_e,"f")))},ze=function(){return rr("Symbol",r(this,De,"m",Ge).call(this,(()=>r(this,De,"m",Ye).call(this).match(/[$\w]/))))},Xe=function(){var t;const e=r(this,De,"m",Ye).call(this),i=e+r(this,De,"m",Ke).call(this);return tr.includes(i)?(n(this,_e,r(this,_e,"f")+2,"f"),rr(i,i)):(n(this,_e,(t=r(this,_e,"f"),++t),"f"),rr(e,e))},Ge=function(t){var e;const i=r(this,_e,"f");for(;r(this,_e,"f")<r(this,Ie,"f").length&&t();)n(this,_e,(e=r(this,_e,"f"),++e),"f");return r(this,Ie,"f").substring(i,r(this,_e,"f"))},Ye=function(){return r(this,Ie,"f")[r(this,_e,"f")]},Ve=function(){var t;return null!==(t=r(this,Ie,"f")[r(this,_e,"f")-1])&&void 0!==t?t:""},Ke=function(){var t;return null!==(t=r(this,Ie,"f")[r(this,_e,"f")+1])&&void 0!==t?t:""};nr=new WeakMap,ir=new WeakMap;class fr{constructor(t,e,r){sr.add(this),or.set(this,void 0),ar.set(this,void 0),lr.set(this,void 0),n(this,or,t,"f"),n(this,ar,e,"f"),n(this,lr,r,"f")}match(t){const e=r(this,sr,"m",hr).call(this);return(null==e?void 0:e.id)===t&&(r(this,sr,"m",ur).call(this),!0)}consumeAndParse(t=100){const e=r(this,sr,"m",ur).call(this),n=r(this,ar,"f")[e.id];if(!n)throw Error(`Parse error at ${e.value}. No matching prefix parselet.`);let i=n.parse(this,e);for(;t>r(this,sr,"m",cr).call(this);){const t=r(this,sr,"m",ur).call(this);i=r(this,lr,"f")[t.id].parse(this,i,t)}return i}}or=new WeakMap,ar=new WeakMap,lr=new WeakMap,sr=new WeakSet,cr=function(){const t=r(this,sr,"m",hr).call(this);if(!t)return 100;const e=r(this,lr,"f")[t.id];return e?e.precedence:100},ur=function(){if(!r(this,or,"f").length)throw Error("Cant consume unknown more tokens.");return r(this,or,"f").shift()},hr=function(){return r(this,or,"f").length>0?r(this,or,"f")[0]:void 0};const dr={parse(t){const e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},pr={parse(t,e){const r=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new ke(e,r)},precedence:2},vr={parse(t,e){if(!(e instanceof le))throw new Error("Unexpected parentheses");if(!(e.name in Ue))throw new Error("Unrecognized function: "+e.name);const r=[];for(;!t.match(")");)r.push(t.consumeAndParse()),t.match(",");return new Oe(e.name,r,Ue[e.name])},precedence:0};function mr(t){const e=t.split(" "),r=parseFloat(e[0]);let n=e[1];return n=n&&n.startsWith("'")&&n.endsWith("'")?n.substring(1,n.length-1):"{"+n+"}",{value:r,unit:n}}const gr=(new class{constructor(){nr.set(this,{}),ir.set(this,{})}registerInfix(t,e){return r(this,ir,"f")[t]=e,this}registerPrefix(t,e){return r(this,nr,"f")[t]=e,this}prefix(t,e,r){return this.registerPrefix(t,{parse(t,n){const i=t.consumeAndParse(e);return r(n,i)}})}infixLeft(t,e,r){return this.registerInfix(t,{parse(t,n,i){const s=t.consumeAndParse(e);return r(n,i,s)},precedence:e})}construct(t){return new fr(Je(t),r(this,nr,"f"),r(this,ir,"f"))}}).registerPrefix("String",{parse:(e,r)=>new ae({type:t.PropertyType.string,value:r.value})}).registerPrefix("DateTime",{parse:(e,r)=>new ae({type:t.PropertyType.dateTime,value:xe(r.value)})}).registerPrefix("Quantity",{parse:(e,r)=>new ae({type:t.PropertyType.Quantity,value:mr(r.value)})}).registerPrefix("Number",{parse:(e,r)=>new ae({type:t.PropertyType.decimal,value:parseFloat(r.value)})}).registerPrefix("Symbol",{parse:(e,r)=>"false"===r.value?new ae({type:t.PropertyType.boolean,value:!1}):"true"===r.value?new ae({type:t.PropertyType.boolean,value:!0}):new le(r.value)}).registerPrefix("{}",{parse:()=>new ce}).registerPrefix("(",dr).registerInfix("[",pr).registerInfix("(",vr).prefix("+",3,((t,e)=>new ue(e,(t=>t)))).prefix("-",3,((t,e)=>new fe(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,r)=>new me(t,r))).infixLeft("/",4,((t,e,r)=>new fe(t,r,((t,e)=>t/e)))).infixLeft("*",4,((t,e,r)=>new fe(t,r,((t,e)=>t*e)))).infixLeft("+",5,((t,e,r)=>new fe(t,r,((t,e)=>t+e)))).infixLeft("-",5,((t,e,r)=>new fe(t,r,((t,e)=>t-e)))).infixLeft("|",7,((t,e,r)=>new ge(t,r))).infixLeft("=",9,((t,e,r)=>new ye(t,r))).infixLeft("!=",9,((t,e,r)=>new we(t,r))).infixLeft("~",9,((t,e,r)=>new Te(t,r))).infixLeft("!~",9,((t,e,r)=>new Se(t,r))).infixLeft("<",8,((t,e,r)=>new fe(t,r,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,r)=>new fe(t,r,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,r)=>new fe(t,r,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,r)=>new fe(t,r,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,r)=>new de(t,r))).infixLeft("Symbol",6,((t,e,r)=>{switch(e.value){case"and":return new Ee(t,r);case"as":return new he(t,r);case"contains":return new pe(t,r);case"div":return new fe(t,r,((t,e)=>t/e|0));case"in":return new ve(t,r);case"is":return new be(t,r);case"mod":return new fe(t,r,((t,e)=>t%e));case"or":return new Pe(t,r);case"xor":return new Ae(t,r);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function yr(t){try{return new oe(t,gr.construct(t).consumeAndParse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}class wr{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,r,n,i,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===(r=null==a?void 0:a.get(4))||void 0===r?void 0:r.toString())||"",h=(null===(n=null==a?void 0:a.get(5))||void 0===n?void 0:n.toString())||"",f=(null===(i=null==a?void 0:a.get(9))||void 0===i?void 0:i.toString())||"",d=(null===(s=null==a?void 0:a.get(12))||void 0===s?void 0:s.toString())||"2.5.1";return new wr([new Tr(["MSH","^~\\&",u,h,l,c,o.toISOString(),"","ACK",o.getTime().toString(),"P",d]),new Tr(["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 wr(t.split(/[\r\n]+/).map((t=>Tr.parse(t))))}}class Tr{constructor(t){b(t)?this.fields=t.map((t=>Sr.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 Tr(t.split("|").map((t=>Sr.parse(t))))}}class Sr{constructor(t){this.components=t}get(t){return this.components[t]}toString(){return this.components.join("^")}static parse(t){return new Sr(t.split("^"))}}var br;function Er(t,e){const r=e.split(" | ");for(const e of r){const r=Pr(e);if(r.startsWith(t+"."))return r}}function Pr(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}t.SearchParameterType=void 0,(br=t.SearchParameterType||(t.SearchParameterType={})).BOOLEAN="BOOLEAN",br.NUMBER="NUMBER",br.QUANTITY="QUANTITY",br.TEXT="TEXT",br.REFERENCE="REFERENCE",br.DATE="DATE",br.DATETIME="DATETIME",br.PERIOD="PERIOD",t.COMPONENT_SEPARATOR="^",t.DEFAULT_SEARCH_COUNT=20,t.FIELD_SEPARATOR="|",t.Hl7Field=Sr,t.Hl7Message=wr,t.Hl7Segment=Tr,t.LRUCache=l,t.MedplumClient=class extends class{constructor(){x.set(this,void 0),n(this,x,{},"f")}addEventListener(t,e){r(this,x,"f")[t]||(r(this,x,"f")[t]=[]),r(this,x,"f")[t].push(e)}removeEventListeneer(t,e){const n=r(this,x,"f")[t];if(n)for(let t=0;t<n.length;t++)if(n[t]===e)return void n.splice(t,1)}dispatchEvent(t){const e=r(this,x,"f")[t.type];return e&&e.forEach((e=>e.call(this,t))),!t.defaultPrevented}}{constructor(t){var e;if(super(),st.add(this),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),pt.set(this,void 0),vt.set(this,void 0),mt.set(this,void 0),gt.set(this,void 0),yt.set(this,void 0),wt.set(this,void 0),Tt.set(this,void 0),St.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,ot,(null==t?void 0:t.fetch)||window.fetch.bind(window),"f"),n(this,at,new It,"f"),n(this,lt,{types:{}},"f"),n(this,ct,new l(null!==(e=null==t?void 0:t.resourceCacheSize)&&void 0!==e?e:1e3),"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)||r(this,ut,"f")+"oauth2/authorize","f"),n(this,dt,(null==t?void 0:t.tokenUrl)||r(this,ut,"f")+"oauth2/token","f"),n(this,pt,(null==t?void 0:t.logoutUrl)||r(this,ut,"f")+"oauth2/logout","f"),n(this,vt,null==t?void 0:t.onUnauthenticated,"f");const i=this.getActiveLogin();i&&(n(this,mt,i.accessToken,"f"),n(this,gt,i.refreshToken,"f"),r(this,st,"m",Et).call(this).catch(console.log)),r(this,st,"m",Dt).call(this)}getBaseUrl(){return r(this,ut,"f")}clear(){r(this,at,"f").clear(),r(this,ct,"f").clear(),n(this,mt,void 0,"f"),n(this,gt,void 0,"f"),n(this,Tt,void 0,"f"),n(this,St,void 0,"f"),this.dispatchEvent({type:"change"})}invalidateUrl(t){t=t.toString(),r(this,ct,"f").delete(t)}invalidateSearches(t){const e="fhir/R4/"+t;for(const t of r(this,ct,"f").keys())(t.endsWith(e)||t.includes(e+"?"))&&r(this,ct,"f").delete(t)}get(t,e={}){if(t=t.toString(),!(null==e?void 0:e.cache)){const e=r(this,ct,"f").get(t);if(e)return e}const n=new V(r(this,st,"m",Pt).call(this,"GET",t,e));return r(this,ct,"f").set(t,n),n}post(t,e,n,i={}){return t=t.toString(),e&&r(this,st,"m",kt).call(this,i,e),n&&r(this,st,"m",Ot).call(this,i,n),this.invalidateUrl(t),r(this,st,"m",Pt).call(this,"POST",t,i)}put(t,e,n,i={}){return t=t.toString(),e&&r(this,st,"m",kt).call(this,i,e),n&&r(this,st,"m",Ot).call(this,i,n),this.invalidateUrl(t),r(this,st,"m",Pt).call(this,"PUT",t,i)}patch(t,e,n={}){return t=t.toString(),r(this,st,"m",kt).call(this,n,e),r(this,st,"m",Ot).call(this,n,"application/json-patch+json"),this.invalidateUrl(t),r(this,st,"m",Pt).call(this,"PATCH",t,n)}delete(t,e={}){return t=t.toString(),this.invalidateUrl(t),r(this,st,"m",Pt).call(this,"DELETE",t,e)}register(t){return e(this,void 0,void 0,(function*(){const e=yield this.post("auth/register",t);yield this.setActiveLogin(e)}))}startLogin(t){return e(this,void 0,void 0,(function*(){return yield r(this,st,"m",Rt).call(this),this.post("auth/login",Object.assign(Object.assign({},t),{clientId:r(this,ht,"f"),scope:Ft,codeChallengeMethod:"S256",codeChallenge:r(this,at,"f").getString("codeChallenge")}))}))}startGoogleLogin(t){return e(this,void 0,void 0,(function*(){return yield r(this,st,"m",Rt).call(this),this.post("auth/google",t)}))}signOut(){return this.clear(),Promise.resolve()}signInWithRedirect(){const t=new URLSearchParams(window.location.search).get("code");return t?this.processCode(t):void r(this,st,"m",Ut).call(this)}signOutWithRedirect(){window.location.assign(r(this,pt,"f"))}fhirUrl(...t){return new URL(r(this,ut,"f")+"fhir/R4/"+t.join("/"))}fhirSearchUrl(t){if("string"==typeof t)return this.fhirUrl(t);const e=this.fhirUrl(t.resourceType);return e.search=et(t),e}search(t,e={}){return this.get(this.fhirSearchUrl(t),e)}searchOne(t,e={}){const n="string"==typeof t?tt(t):t;n.count=1;const i=this.fhirSearchUrl(t).toString()+"-searchOne";if(!(null==e?void 0:e.cache)){const t=r(this,ct,"f").get(i);if(t)return t}const s=new V(this.search(n,e).then((t=>{var e,r;return null===(r=null===(e=t.entry)||void 0===e?void 0:e[0])||void 0===r?void 0:r.resource})));return r(this,ct,"f").set(i,s),s}searchResources(t,e={}){const n=this.fhirSearchUrl(t).toString()+"-searchResources";if(!(null==e?void 0:e.cache)){const t=r(this,ct,"f").get(n);if(t)return t}const i=new V(this.search(t,e).then((t=>{var e,r;return null!==(r=null===(e=t.entry)||void 0===e?void 0:e.map((t=>t.resource)))&&void 0!==r?r:[]})));return r(this,ct,"f").set(n,i),i}searchValueSet(t,e,r={}){const n=this.fhirUrl("ValueSet","$expand");return n.searchParams.set("url",t),n.searchParams.set("filter",e),this.get(n.toString(),r)}getCached(t,e){const n=r(this,ct,"f").get(this.fhirUrl(t,e).toString());return n&&!n.isPending()?n.read():void 0}getCachedReference(t){const e=t.reference,[r,n]=e.split("/");return this.getCached(r,n)}readResource(t,e){return this.get(this.fhirUrl(t,e))}readReference(t){const e=null==t?void 0:t.reference;if(!e)return new V(Promise.reject(new Error("Missing reference")));const[r,n]=e.split("/");return this.readResource(r,n)}getSchema(){return r(this,lt,"f")}requestSchema(t){return e(this,void 0,void 0,(function*(){if(t in r(this,lt,"f").types)return Promise.resolve(r(this,lt,"f"));const e=`{\n StructureDefinitionList(name: "${t}") {\n name,\n description,\n snapshot {\n element {\n id,\n path,\n min,\n max,\n type {\n code,\n targetProfile\n },\n binding {\n valueSet\n },\n definition\n }\n }\n }\n SearchParameterList(base: "${t}", _count: 100) {\n base,\n code,\n type,\n expression,\n target\n }\n }`.replace(/\s+/g," "),n=yield this.graphql(e);for(const t of n.data.StructureDefinitionList)Wt(r(this,lt,"f"),t);for(const t of n.data.SearchParameterList)Bt(r(this,lt,"f"),t);return r(this,lt,"f")}))}readHistory(t,e){return this.get(this.fhirUrl(t,e,"_history"))}readVersion(t,e,r){return this.get(this.fhirUrl(t,e,"_history",r))}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(t,r){var n;return e(this,void 0,void 0,(function*(){return null!==(n=yield this.searchOne(`${t.resourceType}?${r}`))&&void 0!==n?n:this.createResource(t)}))}createBinary(t,e,r){const n=this.fhirUrl("Binary");return e&&n.searchParams.set("_filename",e),this.post(n,t,r)}createPdf(t,r,n,i){return e(this,void 0,void 0,(function*(){const e=yield $(t,n,i);return this.createBinary(e,r,"application/pdf")}))}createComment(t,e){const r=this.getProfile();let n,i;return"Encounter"===t.resourceType&&(n=u(t),i=t.subject),"ServiceRequest"===t.resourceType&&(n=t.encounter,i=t.subject),"Patient"===t.resourceType&&(i=u(t)),this.createResource({resourceType:"Communication",basedOn:[u(t)],encounter:n,subject:i,sender:r?u(r):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,r){return this.invalidateSearches(t),this.patch(this.fhirUrl(t,e),r)}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 r(this,at,"f").getObject("activeLogin")}setActiveLogin(t){return e(this,void 0,void 0,(function*(){n(this,mt,t.accessToken,"f"),n(this,gt,t.refreshToken,"f"),n(this,Tt,void 0,"f"),n(this,St,void 0,"f"),r(this,at,"f").setObject("activeLogin",t),r(this,st,"m",bt).call(this,t),r(this,ct,"f").clear(),n(this,yt,void 0,"f"),yield r(this,st,"m",Et).call(this)}))}getAccessToken(){return r(this,mt,"f")}setAccessToken(t){n(this,mt,t,"f"),n(this,gt,void 0,"f"),n(this,Tt,void 0,"f"),n(this,St,void 0,"f")}getLogins(){var t;return null!==(t=r(this,at,"f").getObject("logins"))&&void 0!==t?t:[]}isLoading(){return!!r(this,wt,"f")}getProfile(){return r(this,Tt,"f")}getProfileAsync(){return e(this,void 0,void 0,(function*(){return r(this,wt,"f")&&(yield r(this,wt,"f")),this.getProfile()}))}getUserConfiguration(){return r(this,St,"f")}download(t,n={}){return e(this,void 0,void 0,(function*(){r(this,yt,"f")&&(yield r(this,yt,"f")),r(this,st,"m",At).call(this,n);return(yield r(this,ot,"f").call(this,t.toString(),n)).blob()}))}processCode(t){if(!r(this,at,"f").getString("pkceState"))throw this.clear(),new Error("Invalid PCKE state");const e=r(this,at,"f").getString("codeVerifier");if(!e)throw this.clear(),new Error("Invalid PCKE code verifier");const n=new URLSearchParams;return n.set("grant_type","authorization_code"),n.set("client_id",r(this,ht,"f")),n.set("code_verifier",e),n.set("code",t),n.set("redirect_uri",Qt()),r(this,st,"m",Ct).call(this,n)}startClientLogin(t,n){return e(this,void 0,void 0,(function*(){const e=new URLSearchParams;return e.set("grant_type","client_credentials"),e.set("client_id",t),e.set("client_secret",n),r(this,st,"m",Ct).call(this,e)}))}},t.OperationOutcomeError=Q,t.ReadablePromise=V,t.SEGMENT_SEPARATOR="\r",t.accessDenied=H,t.allOk=_,t.arrayBufferToBase64=A,t.arrayBufferToHex=P,t.assertOk=function(t,e){if(!F(t)||void 0===e)throw new Q(t)},t.badRequest=function(t,e){return{resourceType:"OperationOutcome",issue:[{severity:"error",code:"invalid",details:{text:t},expression:e?[e]:void 0}]}},t.buildTypeName=Ht,t.calculateAge=v,t.calculateAgeString=function(t,e){const{years:r,months:n,days:i}=v(t,e);return r>=2?r.toString().padStart(3,"0")+"Y":n>=1?n.toString().padStart(3,"0")+"M":i.toString().padStart(3,"0")+"D"},t.capitalize=O,t.createReference=u,t.createSchema=jt,t.createTypeSchema=Nt,t.created=j,t.deepEquals=T,t.evalFhirPath=function(e,r){Array.isArray(r)||(r=[r]);const n=Array.isArray(r)?r:[r];for(let e=0;e<n.length;e++){const r=n[e];"object"==typeof r&&"type"in r&&"value"in r||(n[e]={type:t.PropertyType.BackboneElement,value:r})}return yr(e).eval(n).map((t=>t.value))},t.formatAddress=function(t,e){const r=[];return t.line&&r.push(...t.line),t.city&&r.push(t.city),t.state&&r.push(t.state),t.postalCode&&r.push(t.postalCode),t.use&&((null==e?void 0:e.all)||(null==e?void 0:e.use))&&r.push("["+t.use+"]"),r.join(", ").trim()},t.formatFamilyName=function(t){return t.family||""},t.formatGivenName=function(t){const e=[];return t.given&&e.push(...t.given),e.join(" ").trim()},t.formatHumanName=c,t.formatSearchQuery=et,t.getDateProperty=function(t){return t?new Date(t):void 0},t.getDisplayString=d,t.getExpressionForResourceType=Er,t.getExtensionValue=function(t,...e){var r;let n=t;for(let t=0;t<e.length&&n;t++)n=null===(r=null==n?void 0:n.extension)||void 0===r?void 0:r.find((r=>r.url===e[t]));return null==n?void 0:n.valueString},t.getIdentifier=function(t,e){const r=t.identifier;if(!r)return;const n=Array.isArray(r)?r:[r];for(const t of n)if(t.system===e)return t.value},t.getImageSrc=function(t){if(f(t)){const e=t.photo;if(e)for(const t of e){const e=p(t);if(e)return e}}if("Bot"===t.resourceType&&t.photo){const e=p(t.photo);if(e)return e}},t.getPropertyDisplayName=function(t){const e=t.path.replaceAll("[x]","").split(".").pop();return"id"===e?"ID":e.split(/(?=[A-Z])/).map(O).join(" ").replace("_"," ").replace(/\s+/g," ")},t.getQuestionnaireAnswers=function(t){const e={};return m(t.item,e),e},t.getReferenceString=h,t.getSearchParameterDetails=function(e,r,n){var i,s,o,a;if("_lastUpdated"===n.code)return{columnName:"lastUpdated",type:t.SearchParameterType.DATETIME};const l=n.code.split("-").reduce(((t,e,r)=>t+(r?O(e):e)),""),c=null===(i=Er(r,n.expression))||void 0===i?void 0:i.split(".");if(!c)return{columnName:l,type:t.SearchParameterType.TEXT};let u,h,f=r,d=!1;for(let r=1;r<c.length;r++){const n=c[r];if(u=null===(o=null===(s=e.types[f])||void 0===s?void 0:s.properties)||void 0===o?void 0:o[n],!u)return{columnName:l,type:t.SearchParameterType.TEXT,array:d};if("*"===u.max&&(d=!0),h=null===(a=u.type)||void 0===a?void 0:a[0].code,!h)return{columnName:l,type:t.SearchParameterType.TEXT,array:d};r<c.length-1&&("Element"===h||"BackboneElement"===h?f+=O(n):f=h)}const p=function(e,r){let n=t.SearchParameterType.TEXT;switch(e.type){case"date":n=r===t.PropertyType.dateTime||r===t.PropertyType.instant?t.SearchParameterType.DATETIME:t.SearchParameterType.DATE;break;case"number":n=t.SearchParameterType.NUMBER;break;case"quantity":n=t.SearchParameterType.QUANTITY;break;case"reference":n=t.SearchParameterType.REFERENCE;break;case"token":"boolean"===r&&(n=t.SearchParameterType.BOOLEAN)}return n}(n,h);return{columnName:l,type:p,elementDefinition:u,array:d}},t.getStatus=function(t){return t.id===U?200:t.id===M?201:t.id===L?304:t.id===I?403:t.id===D?404:t.id===C?410:400},t.gone=B,t.indexSearchParameter=Bt,t.indexStructureDefinition=Wt,t.isGone=function(t){return t.id===C},t.isLowerCase=function(t){return t===t.toLowerCase()},t.isNotFound=function(t){return t.id===D},t.isObject=S,t.isOk=F,t.isProfileResource=f,t.isStringArray=b,t.isUUID=function(t){return!!t.match(/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/i)},t.notFound=W,t.notModified=N,t.parseFhirPath=yr,t.parseSearchDefinition=tt,t.resolveId=function(t){var e;return null===(e=null==t?void 0:t.reference)||void 0===e?void 0:e.split("/")[1]},t.stringify=g,t.tokenize=Je,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=index.min.js.map
|