Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@medplum/fhirpath

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medplum/fhirpath - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2

2

dist/cjs/index.min.js

@@ -1,2 +0,2 @@

!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.fhirpath={}))}(this,(function(t){"use strict";function e(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function n(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}function r(t){return null==t?[]:Array.isArray(t)?t:[t]}function i(t,e){if(void 0!==t)return Array.isArray(t)?t.map((t=>e(t))).filter((t=>!!t)).flat():e(t)}function s(t){return Array.isArray(t)&&0===t.length}function o(t){return!t||s(t)}function a(t){return Array.isArray(t)?0!==t.length&&!!t[0]:!!t}function c(t){const e=[];for(const n of t){let t=!1;for(const r of e)if(l(n,r)){t=!0;break}t||e.push(n)}return e}function l(t,e){return!(!o(t)||!o(e))||(s(t)||s(e)?[]:"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<1e-8:f(t)&&f(e)?m(t,e):Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every(((t,n)=>l(t,e[n]))):"object"==typeof t&&"object"==typeof e?p(t,e):t===e)}function h(t,e){return!(!o(t)||!o(e))||!s(t)&&!s(e)&&("number"==typeof t&&"number"==typeof e?Math.abs(t-e)<.01:f(t)&&f(e)?m(t,e):Array.isArray(t)&&Array.isArray(e)?(t.sort(),e.sort(),t.length===e.length&&t.every(((t,n)=>l(t,e[n])))):"object"==typeof t&&"object"==typeof e?p(t,e):"string"==typeof t&&"string"==typeof e?t.toLowerCase()===e.toLowerCase():t===e)}function u(t,e){if(null==t)return!1;switch(e){case"Boolean":return"boolean"==typeof t;case"Decimal":case"Integer":return"number"==typeof t;case"Date":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof t&&!!t.match(/^T\d/);case"Period":return!(!(n=t)||"object"!=typeof n||!("start"in n));case"Quantity":return f(t);default:return"object"==typeof t&&(null==t?void 0:t.resourceType)===e}var n}function f(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function m(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 p(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const r of n){const n=t[r],i=e[r];if(g(n)&&g(i)){if(!p(n,i))return!1}else if(n!==i)return!1}return!0}function g(t){return null!==t&&"object"==typeof t}class v{constructor(t,e){this.original=t,this.child=e}eval(t){try{const e=i(t,(t=>this.child.eval(t)));return Array.isArray(e)?e.flat():null==e?[]:[e]}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class d{constructor(t){this.value=t}eval(){return this.value}}class y{constructor(t){this.name=t}eval(t){return"$this"===this.name?t:i(t,(t=>{if(t&&"object"==typeof t){if("resourceType"in t&&t.resourceType===this.name)return t;if(this.name in t)return t[this.name];const e=Object.keys(t).find((t=>t.startsWith(this.name)));if(e)return t[e]}}))}}class w{eval(){return[]}}class b{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class x{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class T{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return f(e)&&f(n)?Object.assign(Object.assign({},e),{value:this.impl(e.value,n.value)}):this.impl(e,n)}}class A{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return f(e)&&f(n)?this.impl(e.value,n.value):this.impl(e,n)}}class E{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t),r=[];function i(t){t&&(Array.isArray(t)?r.push(...t):r.push(t))}return i(e),i(n),r.length>0&&r.every((t=>"string"==typeof t))?r.join(""):r}}class S{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return r(e).includes(n)}}class j{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return r(this.right.eval(t)).includes(e)}}class k{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class M{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let i;return i=void 0!==e&&void 0!==n?[e,n].flat():void 0!==e?r(e):void 0!==n?r(n):[],c(i)}}class L{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(e)&&Array.isArray(n)?l(e.flat(),n):i(e,(t=>l(t,n)))}}class D{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let r;return r=Array.isArray(n)?l(e,n):i(e,(t=>l(t,n))),!a(r)}}class P{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(n)?h(e,n):i(e,(t=>h(t,n)))}}class W{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let r;return r=Array.isArray(n)?h(e,n):i(e,(t=>h(t,n))),!a(r)}}class O{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.right.name;return i(this.left.eval(t),(t=>u(t,e)))}}class I{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0===n||!1!==e&&!1!==n&&[]}}class ${constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(a(e))return e;const n=this.right.eval(t);return a(n)?n:[]}}class C{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0!==n||!0!==e&&!0===n||!(!0===e&&!0===n||!1===e&&!1===n)&&[]}}class F{constructor(t,e,n){this.name=t,this.args=e,this.impl=n}eval(t){return this.impl(r(t),...this.args)}}function z(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 _=()=>[];const B=_,Q=_;const U=_,N=_;function q(t){if(0===t.length)return[];const[e]=nt(t,1);if("boolean"==typeof e)return[e];if("number"==typeof e&&(0===e||1===e))return[!!e];if("string"==typeof e){const t=e.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return[!0];if(["false","f","no","n","0","0.0"].includes(t))return[!1]}return[]}function R(t){if(0===t.length)return[];const[e]=nt(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[parseInt(e,10)]:"boolean"==typeof e?[e?1:0]:[]}function Z(t){if(0===t.length)return[];const[e]=nt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[z(e)]:[]}function H(t){if(0===t.length)return[];const[e]=nt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[z(e)]:[]}function G(t){if(0===t.length)return[];const[e]=nt(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[parseFloat(e)]:"boolean"==typeof e?[e?1:0]:[]}function J(t){if(0===t.length)return[];const[e]=nt(t,1);return f(e)?[e]:"number"==typeof e?[{value:e,unit:"1"}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{value:parseFloat(e),unit:"1"}]:"boolean"==typeof e?[{value:e?1:0,unit:"1"}]:[]}function K(t){if(0===t.length)return[];const[e]=nt(t,1);return null==e?[]:f(e)?[`${e.value} '${e.unit}'`]:[e.toString()]}function V(t){if(0===t.length)return[];const[e]=nt(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[z("T"+t[1])]}return[]}const X=_,Y=_;function tt(t,e,...n){if(0===e.length)return[];const[r]=nt(e,1);if("string"!=typeof r)throw new Error("String function cannot be called with non-string");const i=t(r,...n.map((t=>t&&t.eval(r))));return void 0===i?[]:[i]}function et(t,e,...n){if(0===e.length)return[];const[r]=nt(e,1),i=f(r),s=i?r.value:r;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...n.map((t=>t.eval(void 0))));return i?[Object.assign(Object.assign({},r),{value:o})]:[o]}function nt(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);return t}var rt,it,st,ot,at,ct,lt,ht,ut,ft,mt,pt,gt,vt,dt,yt,wt,bt,xt=Object.freeze({__proto__:null,empty:function(t){return[0===t.length]},exists:function(t,e){return e?[t.filter((t=>a(e.eval(t)))).length>0]:[t.length>0]},all:function(t,e){return[t.every((t=>a(e.eval(t))))]},allTrue:function(t){for(const e of t)if(!e)return[!1];return[!0]},anyTrue:function(t){for(const e of t)if(e)return[!0];return[!1]},allFalse:function(t){for(const e of t)if(e)return[!1];return[!0]},anyFalse:function(t){for(const e of t)if(!e)return[!0];return[!1]},subsetOf:B,supersetOf:Q,count:function(t){return[t.length]},distinct:function(t){return Array.from(new Set(t))},isDistinct:function(t){return[t.length===new Set(t).size]},where:function(t,e){return t.filter((t=>a(e.eval(t))))},select:function(t,e){return r(e.eval(t))},repeat:U,ofType:N,single:function(t){if(t.length>1)throw new Error("Expected input length one for single()");return 0===t.length?[]:t.slice(0,1)},first:function(t){return 0===t.length?[]:[t[0]]},last:function(t){return 0===t.length?[]:[t[t.length-1]]},tail:function(t){return 0===t.length?[]:t.slice(1,t.length)},skip:function(t,e){const n=e.eval(0);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:function(t,e){const n=e.eval(0);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:function(t,e){if(!e)return t;const n=r(e.eval(0));return c(t.filter((t=>n.includes(t))))},exclude:function(t,e){if(!e)return t;const n=r(e.eval(0));return t.filter((t=>!n.includes(t)))},union:function(t,e){return e?c([t,e.eval(0)].flat()):t},combine:function(t,e){return e?[t,e.eval(0)].flat():t},iif:function(t,e,n,i){const s=r(e.eval(t));if(s.length>1||1===s.length&&"boolean"!=typeof s[0])throw new Error("Expected criterion to evaluate to a Boolean");return a(s)?r(n.eval(t)):i?r(i.eval(t)):[]},toBoolean:q,convertsToBoolean:function(t){return 0===t.length?[]:[1===q(t).length]},toInteger:R,convertsToInteger:function(t){return 0===t.length?[]:[1===R(t).length]},toDate:Z,convertsToDate:function(t){return 0===t.length?[]:[1===Z(t).length]},toDateTime:H,convertsToDateTime:function(t){return 0===t.length?[]:[1===H(t).length]},toDecimal:G,convertsToDecimal:function(t){return 0===t.length?[]:[1===G(t).length]},toQuantity:J,convertsToQuantity:function(t){return 0===t.length?[]:[1===J(t).length]},toString:K,convertsToString:function(t){return 0===t.length?[]:[1===K(t).length]},toTime:V,convertsToTime:function(t){return 0===t.length?[]:[1===V(t).length]},indexOf:function(t,e){return tt(((t,e)=>t.indexOf(e)),t,e)},substring:function(t,e,n){return tt(((t,e,n)=>{const r=e,i=n?r+n:t.length;return r<0||r>=t.length?void 0:t.substring(r,i)}),t,e,n)},startsWith:function(t,e){return tt(((t,e)=>t.startsWith(e)),t,e)},endsWith:function(t,e){return tt(((t,e)=>t.endsWith(e)),t,e)},contains:function(t,e){return tt(((t,e)=>t.includes(e)),t,e)},upper:function(t){return tt((t=>t.toUpperCase()),t)},lower:function(t){return tt((t=>t.toLowerCase()),t)},replace:function(t,e,n){return tt(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},matches:function(t,e){return tt(((t,e)=>!!t.match(e)),t,e)},replaceMatches:function(t,e,n){return tt(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},length:function(t){return tt((t=>t.length),t)},toChars:function(t){return tt((t=>t?t.split(""):void 0),t)},abs:function(t){return et(Math.abs,t)},ceiling:function(t){return et(Math.ceil,t)},exp:function(t){return et(Math.exp,t)},floor:function(t){return et(Math.floor,t)},ln:function(t){return et(Math.log,t)},log:function(t,e){return et(((t,e)=>Math.log(t)/Math.log(e)),t,e)},power:function(t,e){return et(Math.pow,t,e)},round:function(t){return et(Math.round,t)},sqrt:function(t){return et(Math.sqrt,t)},truncate:function(t){return et((t=>0|t),t)},children:X,descendants:Y,trace:function(t,e){return console.log("trace",t,e),t},now:function(){return[(new Date).toISOString()]},timeOfDay:function(){return[(new Date).toISOString().substring(11)]},today:function(){return[(new Date).toISOString().substring(0,10)]},is:function(t,e){const n=e.name;return t.map((t=>u(t,n)))},not:function(t){return q(t).map((t=>!t))},resolve:function(t){return t.map((t=>{let e;if("string"==typeof t?e=t:"object"==typeof t&&(e=t.reference),!e)return;const[n,r]=e.split("/");return{resourceType:n,id:r}})).filter((t=>!!t))},as:function(t){return t},type:function(t){return t.map((t=>"boolean"==typeof t?{namespace:"System",name:"Boolean"}:"number"==typeof t?{namespace:"System",name:"Integer"}:t&&"object"==typeof t&&"resourceType"in t?{namespace:"FHIR",name:t.resourceType}:null))},conformsTo:function(t,e){const n=e.eval(void 0);if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>(null==t?void 0:t.resourceType)===r))}});function Tt(t){return new St(t).tokenize()}const At=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],Et=["!=","!~","<=",">=","{}"];class St{constructor(t){rt.add(this),it.set(this,void 0),st.set(this,void 0),n(this,it,t,"f"),n(this,st,0,"f")}tokenize(){const t=[];for(;e(this,st,"f")<e(this,it,"f").length;){const n=e(this,rt,"m",at).call(this);n&&t.push(n)}return t}}function jt(t,e){return{id:t,value:e}}var kt,Mt,Lt,Dt,Pt,Wt,Ot,It,$t;it=new WeakMap,st=new WeakMap,rt=new WeakSet,ot=function(){const t=e(this,st,"f"),r=e(this,rt,"m",at).call(this);return n(this,st,t,"f"),r},at=function(){e(this,rt,"m",ct).call(this);const t=e(this,rt,"m",yt).call(this);if(!t)return;const n=e(this,rt,"m",bt).call(this);return"/"===t&&"*"===n?e(this,rt,"m",lt).call(this):"/"===t&&"/"===n?e(this,rt,"m",ht).call(this):"'"===t?e(this,rt,"m",ut).call(this):"`"===t?e(this,rt,"m",ft).call(this):"@"===t?e(this,rt,"m",mt).call(this):t.match(/\d/)?e(this,rt,"m",pt).call(this):t.match(/\w/)||"$"===t&&n.match(/\w/)?e(this,rt,"m",gt).call(this):e(this,rt,"m",vt).call(this)},ct=function(){return jt("Whitespace",e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/\s/))))},lt=function(){const t=e(this,st,"f");return e(this,rt,"m",dt).call(this,(()=>"*"!==e(this,rt,"m",yt).call(this)||"/"!==e(this,rt,"m",bt).call(this))),n(this,st,e(this,st,"f")+2,"f"),jt("Comment",e(this,it,"f").substring(t,e(this,st,"f")))},ht=function(){return jt("Comment",e(this,rt,"m",dt).call(this,(()=>"\n"!==e(this,rt,"m",yt).call(this))))},ut=function(){var t,r;n(this,st,(t=e(this,st,"f"),++t),"f");const i=jt("String",e(this,rt,"m",dt).call(this,(()=>"\\"===e(this,rt,"m",wt).call(this)||"'"!==e(this,rt,"m",yt).call(this))));return n(this,st,(r=e(this,st,"f"),++r),"f"),i},ft=function(){var t,r;n(this,st,(t=e(this,st,"f"),++t),"f");const i=jt("Symbol",e(this,rt,"m",dt).call(this,(()=>"`"!==e(this,rt,"m",yt).call(this))));return n(this,st,(r=e(this,st,"f"),++r),"f"),i},mt=function(){var t,r,i,s,o;const a=e(this,st,"f");return n(this,st,(t=e(this,st,"f"),++t),"f"),e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/[\d-]/))),"T"===e(this,rt,"m",yt).call(this)&&(n(this,st,(r=e(this,st,"f"),++r),"f"),e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/[\d:]/))),"."===e(this,rt,"m",yt).call(this)&&e(this,rt,"m",bt).call(this).match(/\d/)&&(n(this,st,(i=e(this,st,"f"),++i),"f"),e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/[\d]/)))),"Z"===e(this,rt,"m",yt).call(this)?n(this,st,(s=e(this,st,"f"),++s),"f"):"+"!==e(this,rt,"m",yt).call(this)&&"-"!==e(this,rt,"m",yt).call(this)||(n(this,st,(o=e(this,st,"f"),++o),"f"),e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/[\d:]/))))),jt("DateTime",e(this,it,"f").substring(a+1,e(this,st,"f")))},pt=function(){var t;const r=e(this,st,"f");let i="Number";return e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/\d/))),"."===e(this,rt,"m",yt).call(this)&&e(this,rt,"m",bt).call(this).match(/\d/)&&(n(this,st,(t=e(this,st,"f"),++t),"f"),e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/\d/))))," "===e(this,rt,"m",yt).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&At.includes(t.value))return!0}return!1}(e(this,rt,"m",ot).call(this))&&(i="Quantity",e(this,rt,"m",at).call(this)),jt(i,e(this,it,"f").substring(r,e(this,st,"f")))},gt=function(){return jt("Symbol",e(this,rt,"m",dt).call(this,(()=>e(this,rt,"m",yt).call(this).match(/[$\w]/))))},vt=function(){var t;const r=e(this,rt,"m",yt).call(this),i=r+e(this,rt,"m",bt).call(this);return Et.includes(i)?(n(this,st,e(this,st,"f")+2,"f"),jt(i,i)):(n(this,st,(t=e(this,st,"f"),++t),"f"),jt(r,r))},dt=function(t){var r;const i=e(this,st,"f");for(;e(this,st,"f")<e(this,it,"f").length&&t();)n(this,st,(r=e(this,st,"f"),++r),"f");return e(this,it,"f").substring(i,e(this,st,"f"))},yt=function(){return e(this,it,"f")[e(this,st,"f")]},wt=function(){var t;return null!==(t=e(this,it,"f")[e(this,st,"f")-1])&&void 0!==t?t:""},bt=function(){var t;return null!==(t=e(this,it,"f")[e(this,st,"f")+1])&&void 0!==t?t:""};kt=new WeakMap,Mt=new WeakMap;class Ct{constructor(t,e,r){Lt.add(this),Dt.set(this,void 0),Pt.set(this,void 0),Wt.set(this,void 0),n(this,Dt,t,"f"),n(this,Pt,e,"f"),n(this,Wt,r,"f")}match(t){const n=e(this,Lt,"m",$t).call(this);return(null==n?void 0:n.id)===t&&(e(this,Lt,"m",It).call(this),!0)}parse(t=100){const n=e(this,Lt,"m",It).call(this),r=e(this,Pt,"f")[n.id];if(!r)throw Error(`Parse error at ${n.value}. No matching prefix parselet.`);let i=r.parse(this,n);for(;t>e(this,Lt,"m",Ot).call(this);){const t=e(this,Lt,"m",It).call(this);i=e(this,Wt,"f")[t.id].parse(this,i,t)}return i}}Dt=new WeakMap,Pt=new WeakMap,Wt=new WeakMap,Lt=new WeakSet,Ot=function(){const t=e(this,Lt,"m",$t).call(this);if(!t)return 100;const n=e(this,Wt,"f")[t.id];return n?n.precedence:100},It=function(){if(!e(this,Dt,"f").length)throw Error("Cant consume unknown more tokens.");return e(this,Dt,"f").shift()},$t=function(){return e(this,Dt,"f").length>0?e(this,Dt,"f")[0]:void 0};const Ft={parse(t){const e=t.parse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},zt={parse(t,e){if(!(e instanceof y))throw new Error("Unexpected parentheses");if(!(e.name in xt))throw new Error("Unrecognized function: "+e.name);const n=[];for(;!t.match(")");)n.push(t.parse()),t.match(",");return new F(e.name,n,xt[e.name])},precedence:0};const _t=(new class{constructor(){kt.set(this,{}),Mt.set(this,{})}registerInfix(t,n){return e(this,Mt,"f")[t]=n,this}registerPrefix(t,n){return e(this,kt,"f")[t]=n,this}prefix(t,e,n){return this.registerPrefix(t,{parse(t,r){const i=t.parse(e);return n(r,i)}})}infixLeft(t,e,n){return this.registerInfix(t,{parse(t,r,i){const s=t.parse(e);return n(r,i,s)},precedence:e})}construct(t){return new Ct(Tt(t),e(this,kt,"f"),e(this,Mt,"f"))}}).registerPrefix("String",{parse:(t,e)=>new d(e.value)}).registerPrefix("DateTime",{parse:(t,e)=>new d(z(e.value))}).registerPrefix("Quantity",{parse:(t,e)=>new d(function(t){const e=t.split(" "),n=parseFloat(e[0]);let r=e[1];return r=r&&r.startsWith("'")&&r.endsWith("'")?r.substring(1,r.length-1):"{"+r+"}",{value:n,unit:r}}(e.value))}).registerPrefix("Number",{parse:(t,e)=>new d(parseFloat(e.value))}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new d(!1):"true"===e.value?new d(!0):new y(e.value)}).registerPrefix("{}",{parse:()=>new w}).registerPrefix("(",Ft).registerInfix("(",zt).prefix("+",3,((t,e)=>new b(e,(t=>t)))).prefix("-",3,((t,e)=>new T(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,n)=>new k(t,n))).infixLeft("/",4,((t,e,n)=>new T(t,n,((t,e)=>t/e)))).infixLeft("*",4,((t,e,n)=>new T(t,n,((t,e)=>t*e)))).infixLeft("+",5,((t,e,n)=>new T(t,n,((t,e)=>t+e)))).infixLeft("-",5,((t,e,n)=>new T(t,n,((t,e)=>t-e)))).infixLeft("|",7,((t,e,n)=>new M(t,n))).infixLeft("=",9,((t,e,n)=>new L(t,n))).infixLeft("!=",9,((t,e,n)=>new D(t,n))).infixLeft("~",9,((t,e,n)=>new P(t,n))).infixLeft("!~",9,((t,e,n)=>new W(t,n))).infixLeft("<",8,((t,e,n)=>new A(t,n,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,n)=>new A(t,n,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,n)=>new A(t,n,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,n)=>new A(t,n,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,n)=>new E(t,n))).infixLeft("Symbol",6,((t,e,n)=>{switch(e.value){case"and":return new I(t,n);case"as":return new x(t,n);case"contains":return new S(t,n);case"div":return new T(t,n,((t,e)=>t/e|0));case"in":return new j(t,n);case"is":return new O(t,n);case"mod":return new T(t,n,((t,e)=>t%e));case"or":return new $(t,n);case"xor":return new C(t,n);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function Bt(t){try{return new v(t,_t.construct(t).parse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}t.evalFhirPath=function(t,e){return Bt(t).eval(e)},t.parseFhirPath=Bt,t.tokenize=Tt,Object.defineProperty(t,"__esModule",{value:!0})}));
!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.fhirpath={}))}(this,(function(t){"use strict";function e(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function n(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}function r(t){return null==t?[]:Array.isArray(t)?t:[t]}function i(t,e){if(void 0!==t)return Array.isArray(t)?t.map((t=>e(t))).filter((t=>!!t)).flat():e(t)}function s(t){return Array.isArray(t)&&0===t.length}function o(t){return!t||s(t)}function a(t){return Array.isArray(t)?0!==t.length&&!!t[0]:!!t}function c(t){const e=[];for(const n of t){let t=!1;for(const r of e)if(l(n,r)){t=!0;break}t||e.push(n)}return e}function l(t,e){return!(!o(t)||!o(e))||(s(t)||s(e)?[]:"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<1e-8:f(t)&&f(e)?m(t,e):Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every(((t,n)=>l(t,e[n]))):"object"==typeof t&&"object"==typeof e?p(t,e):t===e)}function h(t,e){return!(!o(t)||!o(e))||!s(t)&&!s(e)&&("number"==typeof t&&"number"==typeof e?Math.abs(t-e)<.01:f(t)&&f(e)?m(t,e):Array.isArray(t)&&Array.isArray(e)?(t.sort(),e.sort(),t.length===e.length&&t.every(((t,n)=>l(t,e[n])))):"object"==typeof t&&"object"==typeof e?p(t,e):"string"==typeof t&&"string"==typeof e?t.toLowerCase()===e.toLowerCase():t===e)}function u(t,e){if(null==t)return!1;switch(e){case"Boolean":return"boolean"==typeof t;case"Decimal":case"Integer":return"number"==typeof t;case"Date":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof t&&!!t.match(/^T\d/);case"Period":return!(!(n=t)||"object"!=typeof n||!("start"in n));case"Quantity":return f(t);default:return"object"==typeof t&&(null==t?void 0:t.resourceType)===e}var n}function f(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function m(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 p(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const r of n){const n=t[r],i=e[r];if(g(n)&&g(i)){if(!p(n,i))return!1}else if(n!==i)return!1}return!0}function g(t){return null!==t&&"object"==typeof t}class v{constructor(t,e){this.original=t,this.child=e}eval(t){try{const e=i(t,(t=>this.child.eval(t)));return Array.isArray(e)?e.flat():null==e?[]:[e]}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class d{constructor(t){this.value=t}eval(){return this.value}}class y{constructor(t){this.name=t}eval(t){return"$this"===this.name?t:i(t,(t=>{if(t&&"object"==typeof t){if("resourceType"in t&&t.resourceType===this.name)return t;if(this.name in t)return t[this.name];const e=Object.keys(t).find((t=>t.startsWith(this.name)));if(e)return t[e]}}))}}class w{eval(){return[]}}class b{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class x{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class T{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return f(e)&&f(n)?Object.assign(Object.assign({},e),{value:this.impl(e.value,n.value)}):this.impl(e,n)}}class A{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return f(e)&&f(n)?this.impl(e.value,n.value):this.impl(e,n)}}class E{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t),r=[];function i(t){t&&(Array.isArray(t)?r.push(...t):r.push(t))}return i(e),i(n),r.length>0&&r.every((t=>"string"==typeof t))?r.join(""):r}}class S{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return r(e).includes(n)}}class P{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return r(this.right.eval(t)).includes(e)}}class j{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class k{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let i;return i=void 0!==e&&void 0!==n?[e,n].flat():void 0!==e?r(e):void 0!==n?r(n):[],c(i)}}class M{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(e)&&Array.isArray(n)?l(e.flat(),n):i(e,(t=>l(t,n)))}}class L{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let r;return r=Array.isArray(n)?l(e,n):i(e,(t=>l(t,n))),!a(r)}}class D{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(n)?h(e,n):i(e,(t=>h(t,n)))}}class W{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let r;return r=Array.isArray(n)?h(e,n):i(e,(t=>h(t,n))),!a(r)}}class O{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.right.name;return i(this.left.eval(t),(t=>u(t,e)))}}class I{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0===n||!1!==e&&!1!==n&&[]}}class ${constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(a(e))return e;const n=this.right.eval(t);return a(n)?n:[]}}class C{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0!==n||!0!==e&&!0===n||!(!0===e&&!0===n||!1===e&&!1===n)&&[]}}class F{constructor(t,e,n){this.name=t,this.args=e,this.impl=n}eval(t){return this.impl(r(t),...this.args)}}class z{constructor(t,e){this.left=t,this.expr=e}eval(t){const e=this.expr.eval(t);if("number"!=typeof e)throw new Error("Invalid indexer expression: should return integer}");const n=this.left.eval(t);return e in n?n[e]:[]}}function _(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 B=()=>[];const Q=B,U=B;const N=B,q=B;function R(t){if(0===t.length)return[];const[e]=rt(t,1);if("boolean"==typeof e)return[e];if("number"==typeof e&&(0===e||1===e))return[!!e];if("string"==typeof e){const t=e.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return[!0];if(["false","f","no","n","0","0.0"].includes(t))return[!1]}return[]}function Z(t){if(0===t.length)return[];const[e]=rt(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[parseInt(e,10)]:"boolean"==typeof e?[e?1:0]:[]}function H(t){if(0===t.length)return[];const[e]=rt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[_(e)]:[]}function G(t){if(0===t.length)return[];const[e]=rt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[_(e)]:[]}function J(t){if(0===t.length)return[];const[e]=rt(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[parseFloat(e)]:"boolean"==typeof e?[e?1:0]:[]}function K(t){if(0===t.length)return[];const[e]=rt(t,1);return f(e)?[e]:"number"==typeof e?[{value:e,unit:"1"}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{value:parseFloat(e),unit:"1"}]:"boolean"==typeof e?[{value:e?1:0,unit:"1"}]:[]}function V(t){if(0===t.length)return[];const[e]=rt(t,1);return null==e?[]:f(e)?[`${e.value} '${e.unit}'`]:[e.toString()]}function X(t){if(0===t.length)return[];const[e]=rt(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[_("T"+t[1])]}return[]}const Y=B,tt=B;function et(t,e,...n){if(0===e.length)return[];const[r]=rt(e,1);if("string"!=typeof r)throw new Error("String function cannot be called with non-string");const i=t(r,...n.map((t=>t&&t.eval(r))));return void 0===i?[]:[i]}function nt(t,e,...n){if(0===e.length)return[];const[r]=rt(e,1),i=f(r),s=i?r.value:r;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...n.map((t=>t.eval(void 0))));return i?[Object.assign(Object.assign({},r),{value:o})]:[o]}function rt(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);return t}var it,st,ot,at,ct,lt,ht,ut,ft,mt,pt,gt,vt,dt,yt,wt,bt,xt,Tt=Object.freeze({__proto__:null,empty:function(t){return[0===t.length]},exists:function(t,e){return e?[t.filter((t=>a(e.eval(t)))).length>0]:[t.length>0]},all:function(t,e){return[t.every((t=>a(e.eval(t))))]},allTrue:function(t){for(const e of t)if(!e)return[!1];return[!0]},anyTrue:function(t){for(const e of t)if(e)return[!0];return[!1]},allFalse:function(t){for(const e of t)if(e)return[!1];return[!0]},anyFalse:function(t){for(const e of t)if(!e)return[!0];return[!1]},subsetOf:Q,supersetOf:U,count:function(t){return[t.length]},distinct:function(t){return Array.from(new Set(t))},isDistinct:function(t){return[t.length===new Set(t).size]},where:function(t,e){return t.filter((t=>a(e.eval(t))))},select:function(t,e){return r(t.map((t=>e.eval(t))).flat())},repeat:N,ofType:q,single:function(t){if(t.length>1)throw new Error("Expected input length one for single()");return 0===t.length?[]:t.slice(0,1)},first:function(t){return 0===t.length?[]:[t[0]]},last:function(t){return 0===t.length?[]:[t[t.length-1]]},tail:function(t){return 0===t.length?[]:t.slice(1,t.length)},skip:function(t,e){const n=e.eval(0);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:function(t,e){const n=e.eval(0);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:function(t,e){if(!e)return t;const n=r(e.eval(0));return c(t.filter((t=>n.includes(t))))},exclude:function(t,e){if(!e)return t;const n=r(e.eval(0));return t.filter((t=>!n.includes(t)))},union:function(t,e){return e?c([t,e.eval(0)].flat()):t},combine:function(t,e){return e?[t,e.eval(0)].flat():t},iif:function(t,e,n,i){const s=r(e.eval(t));if(s.length>1||1===s.length&&"boolean"!=typeof s[0])throw new Error("Expected criterion to evaluate to a Boolean");return a(s)?r(n.eval(t)):i?r(i.eval(t)):[]},toBoolean:R,convertsToBoolean:function(t){return 0===t.length?[]:[1===R(t).length]},toInteger:Z,convertsToInteger:function(t){return 0===t.length?[]:[1===Z(t).length]},toDate:H,convertsToDate:function(t){return 0===t.length?[]:[1===H(t).length]},toDateTime:G,convertsToDateTime:function(t){return 0===t.length?[]:[1===G(t).length]},toDecimal:J,convertsToDecimal:function(t){return 0===t.length?[]:[1===J(t).length]},toQuantity:K,convertsToQuantity:function(t){return 0===t.length?[]:[1===K(t).length]},toString:V,convertsToString:function(t){return 0===t.length?[]:[1===V(t).length]},toTime:X,convertsToTime:function(t){return 0===t.length?[]:[1===X(t).length]},indexOf:function(t,e){return et(((t,e)=>t.indexOf(e)),t,e)},substring:function(t,e,n){return et(((t,e,n)=>{const r=e,i=n?r+n:t.length;return r<0||r>=t.length?void 0:t.substring(r,i)}),t,e,n)},startsWith:function(t,e){return et(((t,e)=>t.startsWith(e)),t,e)},endsWith:function(t,e){return et(((t,e)=>t.endsWith(e)),t,e)},contains:function(t,e){return et(((t,e)=>t.includes(e)),t,e)},upper:function(t){return et((t=>t.toUpperCase()),t)},lower:function(t){return et((t=>t.toLowerCase()),t)},replace:function(t,e,n){return et(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},matches:function(t,e){return et(((t,e)=>!!t.match(e)),t,e)},replaceMatches:function(t,e,n){return et(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},length:function(t){return et((t=>t.length),t)},toChars:function(t){return et((t=>t?t.split(""):void 0),t)},abs:function(t){return nt(Math.abs,t)},ceiling:function(t){return nt(Math.ceil,t)},exp:function(t){return nt(Math.exp,t)},floor:function(t){return nt(Math.floor,t)},ln:function(t){return nt(Math.log,t)},log:function(t,e){return nt(((t,e)=>Math.log(t)/Math.log(e)),t,e)},power:function(t,e){return nt(Math.pow,t,e)},round:function(t){return nt(Math.round,t)},sqrt:function(t){return nt(Math.sqrt,t)},truncate:function(t){return nt((t=>0|t),t)},children:Y,descendants:tt,trace:function(t,e){return console.log("trace",t,e),t},now:function(){return[(new Date).toISOString()]},timeOfDay:function(){return[(new Date).toISOString().substring(11)]},today:function(){return[(new Date).toISOString().substring(0,10)]},is:function(t,e){const n=e.name;return t.map((t=>u(t,n)))},not:function(t){return R(t).map((t=>!t))},resolve:function(t){return t.map((t=>{let e;if("string"==typeof t?e=t:"object"==typeof t&&(e=t.reference),!e)return;const[n,r]=e.split("/");return{resourceType:n,id:r}})).filter((t=>!!t))},as:function(t){return t},type:function(t){return t.map((t=>"boolean"==typeof t?{namespace:"System",name:"Boolean"}:"number"==typeof t?{namespace:"System",name:"Integer"}:t&&"object"==typeof t&&"resourceType"in t?{namespace:"FHIR",name:t.resourceType}:null))},conformsTo:function(t,e){const n=e.eval(void 0);if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>(null==t?void 0:t.resourceType)===r))}});function At(t){return new Pt(t).tokenize()}const Et=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],St=["!=","!~","<=",">=","{}"];class Pt{constructor(t){it.add(this),st.set(this,void 0),ot.set(this,void 0),n(this,st,t,"f"),n(this,ot,0,"f")}tokenize(){const t=[];for(;e(this,ot,"f")<e(this,st,"f").length;){const n=e(this,it,"m",ct).call(this);n&&t.push(n)}return t}}function jt(t,e){return{id:t,value:e}}var kt,Mt,Lt,Dt,Wt,Ot,It,$t,Ct;st=new WeakMap,ot=new WeakMap,it=new WeakSet,at=function(){const t=e(this,ot,"f"),r=e(this,it,"m",ct).call(this);return n(this,ot,t,"f"),r},ct=function(){e(this,it,"m",lt).call(this);const t=e(this,it,"m",wt).call(this);if(!t)return;const n=e(this,it,"m",xt).call(this);return"/"===t&&"*"===n?e(this,it,"m",ht).call(this):"/"===t&&"/"===n?e(this,it,"m",ut).call(this):"'"===t?e(this,it,"m",ft).call(this):"`"===t?e(this,it,"m",mt).call(this):"@"===t?e(this,it,"m",pt).call(this):t.match(/\d/)?e(this,it,"m",gt).call(this):t.match(/\w/)||"$"===t&&n.match(/\w/)?e(this,it,"m",vt).call(this):e(this,it,"m",dt).call(this)},lt=function(){return jt("Whitespace",e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/\s/))))},ht=function(){const t=e(this,ot,"f");return e(this,it,"m",yt).call(this,(()=>"*"!==e(this,it,"m",wt).call(this)||"/"!==e(this,it,"m",xt).call(this))),n(this,ot,e(this,ot,"f")+2,"f"),jt("Comment",e(this,st,"f").substring(t,e(this,ot,"f")))},ut=function(){return jt("Comment",e(this,it,"m",yt).call(this,(()=>"\n"!==e(this,it,"m",wt).call(this))))},ft=function(){var t,r;n(this,ot,(t=e(this,ot,"f"),++t),"f");const i=jt("String",e(this,it,"m",yt).call(this,(()=>"\\"===e(this,it,"m",bt).call(this)||"'"!==e(this,it,"m",wt).call(this))));return n(this,ot,(r=e(this,ot,"f"),++r),"f"),i},mt=function(){var t,r;n(this,ot,(t=e(this,ot,"f"),++t),"f");const i=jt("Symbol",e(this,it,"m",yt).call(this,(()=>"`"!==e(this,it,"m",wt).call(this))));return n(this,ot,(r=e(this,ot,"f"),++r),"f"),i},pt=function(){var t,r,i,s,o;const a=e(this,ot,"f");return n(this,ot,(t=e(this,ot,"f"),++t),"f"),e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/[\d-]/))),"T"===e(this,it,"m",wt).call(this)&&(n(this,ot,(r=e(this,ot,"f"),++r),"f"),e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/[\d:]/))),"."===e(this,it,"m",wt).call(this)&&e(this,it,"m",xt).call(this).match(/\d/)&&(n(this,ot,(i=e(this,ot,"f"),++i),"f"),e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/[\d]/)))),"Z"===e(this,it,"m",wt).call(this)?n(this,ot,(s=e(this,ot,"f"),++s),"f"):"+"!==e(this,it,"m",wt).call(this)&&"-"!==e(this,it,"m",wt).call(this)||(n(this,ot,(o=e(this,ot,"f"),++o),"f"),e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/[\d:]/))))),jt("DateTime",e(this,st,"f").substring(a+1,e(this,ot,"f")))},gt=function(){var t;const r=e(this,ot,"f");let i="Number";return e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/\d/))),"."===e(this,it,"m",wt).call(this)&&e(this,it,"m",xt).call(this).match(/\d/)&&(n(this,ot,(t=e(this,ot,"f"),++t),"f"),e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/\d/))))," "===e(this,it,"m",wt).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&Et.includes(t.value))return!0}return!1}(e(this,it,"m",at).call(this))&&(i="Quantity",e(this,it,"m",ct).call(this)),jt(i,e(this,st,"f").substring(r,e(this,ot,"f")))},vt=function(){return jt("Symbol",e(this,it,"m",yt).call(this,(()=>e(this,it,"m",wt).call(this).match(/[$\w]/))))},dt=function(){var t;const r=e(this,it,"m",wt).call(this),i=r+e(this,it,"m",xt).call(this);return St.includes(i)?(n(this,ot,e(this,ot,"f")+2,"f"),jt(i,i)):(n(this,ot,(t=e(this,ot,"f"),++t),"f"),jt(r,r))},yt=function(t){var r;const i=e(this,ot,"f");for(;e(this,ot,"f")<e(this,st,"f").length&&t();)n(this,ot,(r=e(this,ot,"f"),++r),"f");return e(this,st,"f").substring(i,e(this,ot,"f"))},wt=function(){return e(this,st,"f")[e(this,ot,"f")]},bt=function(){var t;return null!==(t=e(this,st,"f")[e(this,ot,"f")-1])&&void 0!==t?t:""},xt=function(){var t;return null!==(t=e(this,st,"f")[e(this,ot,"f")+1])&&void 0!==t?t:""};kt=new WeakMap,Mt=new WeakMap;class Ft{constructor(t,e,r){Lt.add(this),Dt.set(this,void 0),Wt.set(this,void 0),Ot.set(this,void 0),n(this,Dt,t,"f"),n(this,Wt,e,"f"),n(this,Ot,r,"f")}match(t){const n=e(this,Lt,"m",Ct).call(this);return(null==n?void 0:n.id)===t&&(e(this,Lt,"m",$t).call(this),!0)}consumeAndParse(t=100){const n=e(this,Lt,"m",$t).call(this),r=e(this,Wt,"f")[n.id];if(!r)throw Error(`Parse error at ${n.value}. No matching prefix parselet.`);let i=r.parse(this,n);for(;t>e(this,Lt,"m",It).call(this);){const t=e(this,Lt,"m",$t).call(this);i=e(this,Ot,"f")[t.id].parse(this,i,t)}return i}}Dt=new WeakMap,Wt=new WeakMap,Ot=new WeakMap,Lt=new WeakSet,It=function(){const t=e(this,Lt,"m",Ct).call(this);if(!t)return 100;const n=e(this,Ot,"f")[t.id];return n?n.precedence:100},$t=function(){if(!e(this,Dt,"f").length)throw Error("Cant consume unknown more tokens.");return e(this,Dt,"f").shift()},Ct=function(){return e(this,Dt,"f").length>0?e(this,Dt,"f")[0]:void 0};const zt={parse(t){const e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},_t={parse(t,e){const n=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new z(e,n)},precedence:2},Bt={parse(t,e){if(!(e instanceof y))throw new Error("Unexpected parentheses");if(!(e.name in Tt))throw new Error("Unrecognized function: "+e.name);const n=[];for(;!t.match(")");)n.push(t.consumeAndParse()),t.match(",");return new F(e.name,n,Tt[e.name])},precedence:0};const Qt=(new class{constructor(){kt.set(this,{}),Mt.set(this,{})}registerInfix(t,n){return e(this,Mt,"f")[t]=n,this}registerPrefix(t,n){return e(this,kt,"f")[t]=n,this}prefix(t,e,n){return this.registerPrefix(t,{parse(t,r){const i=t.consumeAndParse(e);return n(r,i)}})}infixLeft(t,e,n){return this.registerInfix(t,{parse(t,r,i){const s=t.consumeAndParse(e);return n(r,i,s)},precedence:e})}construct(t){return new Ft(At(t),e(this,kt,"f"),e(this,Mt,"f"))}}).registerPrefix("String",{parse:(t,e)=>new d(e.value)}).registerPrefix("DateTime",{parse:(t,e)=>new d(_(e.value))}).registerPrefix("Quantity",{parse:(t,e)=>new d(function(t){const e=t.split(" "),n=parseFloat(e[0]);let r=e[1];return r=r&&r.startsWith("'")&&r.endsWith("'")?r.substring(1,r.length-1):"{"+r+"}",{value:n,unit:r}}(e.value))}).registerPrefix("Number",{parse:(t,e)=>new d(parseFloat(e.value))}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new d(!1):"true"===e.value?new d(!0):new y(e.value)}).registerPrefix("{}",{parse:()=>new w}).registerPrefix("(",zt).registerInfix("[",_t).registerInfix("(",Bt).prefix("+",3,((t,e)=>new b(e,(t=>t)))).prefix("-",3,((t,e)=>new T(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,n)=>new j(t,n))).infixLeft("/",4,((t,e,n)=>new T(t,n,((t,e)=>t/e)))).infixLeft("*",4,((t,e,n)=>new T(t,n,((t,e)=>t*e)))).infixLeft("+",5,((t,e,n)=>new T(t,n,((t,e)=>t+e)))).infixLeft("-",5,((t,e,n)=>new T(t,n,((t,e)=>t-e)))).infixLeft("|",7,((t,e,n)=>new k(t,n))).infixLeft("=",9,((t,e,n)=>new M(t,n))).infixLeft("!=",9,((t,e,n)=>new L(t,n))).infixLeft("~",9,((t,e,n)=>new D(t,n))).infixLeft("!~",9,((t,e,n)=>new W(t,n))).infixLeft("<",8,((t,e,n)=>new A(t,n,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,n)=>new A(t,n,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,n)=>new A(t,n,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,n)=>new A(t,n,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,n)=>new E(t,n))).infixLeft("Symbol",6,((t,e,n)=>{switch(e.value){case"and":return new I(t,n);case"as":return new x(t,n);case"contains":return new S(t,n);case"div":return new T(t,n,((t,e)=>t/e|0));case"in":return new P(t,n);case"is":return new O(t,n);case"mod":return new T(t,n,((t,e)=>t%e));case"or":return new $(t,n);case"xor":return new C(t,n);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function Ut(t){try{return new v(t,Qt.construct(t).consumeAndParse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}t.evalFhirPath=function(t,e){return Ut(t).eval(e)},t.parseFhirPath=Ut,t.tokenize=At,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index.min.js.map

@@ -1,2 +0,2 @@

function t(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function e(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}function n(t){return null==t?[]:Array.isArray(t)?t:[t]}function r(t,e){if(void 0!==t)return Array.isArray(t)?t.map((t=>e(t))).filter((t=>!!t)).flat():e(t)}function i(t){return Array.isArray(t)&&0===t.length}function s(t){return!t||i(t)}function o(t){return Array.isArray(t)?0!==t.length&&!!t[0]:!!t}function a(t){const e=[];for(const n of t){let t=!1;for(const r of e)if(c(n,r)){t=!0;break}t||e.push(n)}return e}function c(t,e){return!(!s(t)||!s(e))||(i(t)||i(e)?[]:"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<1e-8:u(t)&&u(e)?f(t,e):Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every(((t,n)=>c(t,e[n]))):"object"==typeof t&&"object"==typeof e?m(t,e):t===e)}function l(t,e){return!(!s(t)||!s(e))||!i(t)&&!i(e)&&("number"==typeof t&&"number"==typeof e?Math.abs(t-e)<.01:u(t)&&u(e)?f(t,e):Array.isArray(t)&&Array.isArray(e)?(t.sort(),e.sort(),t.length===e.length&&t.every(((t,n)=>c(t,e[n])))):"object"==typeof t&&"object"==typeof e?m(t,e):"string"==typeof t&&"string"==typeof e?t.toLowerCase()===e.toLowerCase():t===e)}function h(t,e){if(null==t)return!1;switch(e){case"Boolean":return"boolean"==typeof t;case"Decimal":case"Integer":return"number"==typeof t;case"Date":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof t&&!!t.match(/^T\d/);case"Period":return!(!(n=t)||"object"!=typeof n||!("start"in n));case"Quantity":return u(t);default:return"object"==typeof t&&(null==t?void 0:t.resourceType)===e}var n}function u(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function f(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 m(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const r of n){const n=t[r],i=e[r];if(g(n)&&g(i)){if(!m(n,i))return!1}else if(n!==i)return!1}return!0}function g(t){return null!==t&&"object"==typeof t}class p{constructor(t,e){this.original=t,this.child=e}eval(t){try{const e=r(t,(t=>this.child.eval(t)));return Array.isArray(e)?e.flat():null==e?[]:[e]}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class v{constructor(t){this.value=t}eval(){return this.value}}class d{constructor(t){this.name=t}eval(t){return"$this"===this.name?t:r(t,(t=>{if(t&&"object"==typeof t){if("resourceType"in t&&t.resourceType===this.name)return t;if(this.name in t)return t[this.name];const e=Object.keys(t).find((t=>t.startsWith(this.name)));if(e)return t[e]}}))}}class y{eval(){return[]}}class w{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class b{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class x{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return u(e)&&u(n)?Object.assign(Object.assign({},e),{value:this.impl(e.value,n.value)}):this.impl(e,n)}}class T{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return u(e)&&u(n)?this.impl(e.value,n.value):this.impl(e,n)}}class A{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t),r=[];function i(t){t&&(Array.isArray(t)?r.push(...t):r.push(t))}return i(e),i(n),r.length>0&&r.every((t=>"string"==typeof t))?r.join(""):r}}class E{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return n(e).includes(r)}}class S{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return n(this.right.eval(t)).includes(e)}}class k{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class j{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);let i;return i=void 0!==e&&void 0!==r?[e,r].flat():void 0!==e?n(e):void 0!==r?n(r):[],a(i)}}class L{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(e)&&Array.isArray(n)?c(e.flat(),n):r(e,(t=>c(t,n)))}}class M{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let i;return i=Array.isArray(n)?c(e,n):r(e,(t=>c(t,n))),!o(i)}}class D{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(n)?l(e,n):r(e,(t=>l(t,n)))}}class W{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let i;return i=Array.isArray(n)?l(e,n):r(e,(t=>l(t,n))),!o(i)}}class O{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.right.name;return r(this.left.eval(t),(t=>h(t,e)))}}class P{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0===n||!1!==e&&!1!==n&&[]}}class I{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(o(e))return e;const n=this.right.eval(t);return o(n)?n:[]}}class ${constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0!==n||!0!==e&&!0===n||!(!0===e&&!0===n||!1===e&&!1===n)&&[]}}class C{constructor(t,e,n){this.name=t,this.args=e,this.impl=n}eval(t){return this.impl(n(t),...this.args)}}function F(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 z=()=>[];const B=z,Q=z;const U=z,_=z;function N(t){if(0===t.length)return[];const[e]=et(t,1);if("boolean"==typeof e)return[e];if("number"==typeof e&&(0===e||1===e))return[!!e];if("string"==typeof e){const t=e.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return[!0];if(["false","f","no","n","0","0.0"].includes(t))return[!1]}return[]}function q(t){if(0===t.length)return[];const[e]=et(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[parseInt(e,10)]:"boolean"==typeof e?[e?1:0]:[]}function R(t){if(0===t.length)return[];const[e]=et(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[F(e)]:[]}function Z(t){if(0===t.length)return[];const[e]=et(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[F(e)]:[]}function H(t){if(0===t.length)return[];const[e]=et(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[parseFloat(e)]:"boolean"==typeof e?[e?1:0]:[]}function G(t){if(0===t.length)return[];const[e]=et(t,1);return u(e)?[e]:"number"==typeof e?[{value:e,unit:"1"}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{value:parseFloat(e),unit:"1"}]:"boolean"==typeof e?[{value:e?1:0,unit:"1"}]:[]}function J(t){if(0===t.length)return[];const[e]=et(t,1);return null==e?[]:u(e)?[`${e.value} '${e.unit}'`]:[e.toString()]}function K(t){if(0===t.length)return[];const[e]=et(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[F("T"+t[1])]}return[]}const V=z,X=z;function Y(t,e,...n){if(0===e.length)return[];const[r]=et(e,1);if("string"!=typeof r)throw new Error("String function cannot be called with non-string");const i=t(r,...n.map((t=>t&&t.eval(r))));return void 0===i?[]:[i]}function tt(t,e,...n){if(0===e.length)return[];const[r]=et(e,1),i=u(r),s=i?r.value:r;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...n.map((t=>t.eval(void 0))));return i?[Object.assign(Object.assign({},r),{value:o})]:[o]}function et(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);return t}var nt,rt,it,st,ot,at,ct,lt,ht,ut,ft,mt,gt,pt,vt,dt,yt,wt,bt=Object.freeze({__proto__:null,empty:function(t){return[0===t.length]},exists:function(t,e){return e?[t.filter((t=>o(e.eval(t)))).length>0]:[t.length>0]},all:function(t,e){return[t.every((t=>o(e.eval(t))))]},allTrue:function(t){for(const e of t)if(!e)return[!1];return[!0]},anyTrue:function(t){for(const e of t)if(e)return[!0];return[!1]},allFalse:function(t){for(const e of t)if(e)return[!1];return[!0]},anyFalse:function(t){for(const e of t)if(!e)return[!0];return[!1]},subsetOf:B,supersetOf:Q,count:function(t){return[t.length]},distinct:function(t){return Array.from(new Set(t))},isDistinct:function(t){return[t.length===new Set(t).size]},where:function(t,e){return t.filter((t=>o(e.eval(t))))},select:function(t,e){return n(e.eval(t))},repeat:U,ofType:_,single:function(t){if(t.length>1)throw new Error("Expected input length one for single()");return 0===t.length?[]:t.slice(0,1)},first:function(t){return 0===t.length?[]:[t[0]]},last:function(t){return 0===t.length?[]:[t[t.length-1]]},tail:function(t){return 0===t.length?[]:t.slice(1,t.length)},skip:function(t,e){const n=e.eval(0);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:function(t,e){const n=e.eval(0);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:function(t,e){if(!e)return t;const r=n(e.eval(0));return a(t.filter((t=>r.includes(t))))},exclude:function(t,e){if(!e)return t;const r=n(e.eval(0));return t.filter((t=>!r.includes(t)))},union:function(t,e){return e?a([t,e.eval(0)].flat()):t},combine:function(t,e){return e?[t,e.eval(0)].flat():t},iif:function(t,e,r,i){const s=n(e.eval(t));if(s.length>1||1===s.length&&"boolean"!=typeof s[0])throw new Error("Expected criterion to evaluate to a Boolean");return o(s)?n(r.eval(t)):i?n(i.eval(t)):[]},toBoolean:N,convertsToBoolean:function(t){return 0===t.length?[]:[1===N(t).length]},toInteger:q,convertsToInteger:function(t){return 0===t.length?[]:[1===q(t).length]},toDate:R,convertsToDate:function(t){return 0===t.length?[]:[1===R(t).length]},toDateTime:Z,convertsToDateTime:function(t){return 0===t.length?[]:[1===Z(t).length]},toDecimal:H,convertsToDecimal:function(t){return 0===t.length?[]:[1===H(t).length]},toQuantity:G,convertsToQuantity:function(t){return 0===t.length?[]:[1===G(t).length]},toString:J,convertsToString:function(t){return 0===t.length?[]:[1===J(t).length]},toTime:K,convertsToTime:function(t){return 0===t.length?[]:[1===K(t).length]},indexOf:function(t,e){return Y(((t,e)=>t.indexOf(e)),t,e)},substring:function(t,e,n){return Y(((t,e,n)=>{const r=e,i=n?r+n:t.length;return r<0||r>=t.length?void 0:t.substring(r,i)}),t,e,n)},startsWith:function(t,e){return Y(((t,e)=>t.startsWith(e)),t,e)},endsWith:function(t,e){return Y(((t,e)=>t.endsWith(e)),t,e)},contains:function(t,e){return Y(((t,e)=>t.includes(e)),t,e)},upper:function(t){return Y((t=>t.toUpperCase()),t)},lower:function(t){return Y((t=>t.toLowerCase()),t)},replace:function(t,e,n){return Y(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},matches:function(t,e){return Y(((t,e)=>!!t.match(e)),t,e)},replaceMatches:function(t,e,n){return Y(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},length:function(t){return Y((t=>t.length),t)},toChars:function(t){return Y((t=>t?t.split(""):void 0),t)},abs:function(t){return tt(Math.abs,t)},ceiling:function(t){return tt(Math.ceil,t)},exp:function(t){return tt(Math.exp,t)},floor:function(t){return tt(Math.floor,t)},ln:function(t){return tt(Math.log,t)},log:function(t,e){return tt(((t,e)=>Math.log(t)/Math.log(e)),t,e)},power:function(t,e){return tt(Math.pow,t,e)},round:function(t){return tt(Math.round,t)},sqrt:function(t){return tt(Math.sqrt,t)},truncate:function(t){return tt((t=>0|t),t)},children:V,descendants:X,trace:function(t,e){return console.log("trace",t,e),t},now:function(){return[(new Date).toISOString()]},timeOfDay:function(){return[(new Date).toISOString().substring(11)]},today:function(){return[(new Date).toISOString().substring(0,10)]},is:function(t,e){const n=e.name;return t.map((t=>h(t,n)))},not:function(t){return N(t).map((t=>!t))},resolve:function(t){return t.map((t=>{let e;if("string"==typeof t?e=t:"object"==typeof t&&(e=t.reference),!e)return;const[n,r]=e.split("/");return{resourceType:n,id:r}})).filter((t=>!!t))},as:function(t){return t},type:function(t){return t.map((t=>"boolean"==typeof t?{namespace:"System",name:"Boolean"}:"number"==typeof t?{namespace:"System",name:"Integer"}:t&&"object"==typeof t&&"resourceType"in t?{namespace:"FHIR",name:t.resourceType}:null))},conformsTo:function(t,e){const n=e.eval(void 0);if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>(null==t?void 0:t.resourceType)===r))}});function xt(t){return new Et(t).tokenize()}const Tt=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],At=["!=","!~","<=",">=","{}"];class Et{constructor(t){nt.add(this),rt.set(this,void 0),it.set(this,void 0),e(this,rt,t,"f"),e(this,it,0,"f")}tokenize(){const e=[];for(;t(this,it,"f")<t(this,rt,"f").length;){const n=t(this,nt,"m",ot).call(this);n&&e.push(n)}return e}}function St(t,e){return{id:t,value:e}}var kt,jt,Lt,Mt,Dt,Wt,Ot,Pt,It;rt=new WeakMap,it=new WeakMap,nt=new WeakSet,st=function(){const n=t(this,it,"f"),r=t(this,nt,"m",ot).call(this);return e(this,it,n,"f"),r},ot=function(){t(this,nt,"m",at).call(this);const e=t(this,nt,"m",dt).call(this);if(!e)return;const n=t(this,nt,"m",wt).call(this);return"/"===e&&"*"===n?t(this,nt,"m",ct).call(this):"/"===e&&"/"===n?t(this,nt,"m",lt).call(this):"'"===e?t(this,nt,"m",ht).call(this):"`"===e?t(this,nt,"m",ut).call(this):"@"===e?t(this,nt,"m",ft).call(this):e.match(/\d/)?t(this,nt,"m",mt).call(this):e.match(/\w/)||"$"===e&&n.match(/\w/)?t(this,nt,"m",gt).call(this):t(this,nt,"m",pt).call(this)},at=function(){return St("Whitespace",t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/\s/))))},ct=function(){const n=t(this,it,"f");return t(this,nt,"m",vt).call(this,(()=>"*"!==t(this,nt,"m",dt).call(this)||"/"!==t(this,nt,"m",wt).call(this))),e(this,it,t(this,it,"f")+2,"f"),St("Comment",t(this,rt,"f").substring(n,t(this,it,"f")))},lt=function(){return St("Comment",t(this,nt,"m",vt).call(this,(()=>"\n"!==t(this,nt,"m",dt).call(this))))},ht=function(){var n,r;e(this,it,(n=t(this,it,"f"),++n),"f");const i=St("String",t(this,nt,"m",vt).call(this,(()=>"\\"===t(this,nt,"m",yt).call(this)||"'"!==t(this,nt,"m",dt).call(this))));return e(this,it,(r=t(this,it,"f"),++r),"f"),i},ut=function(){var n,r;e(this,it,(n=t(this,it,"f"),++n),"f");const i=St("Symbol",t(this,nt,"m",vt).call(this,(()=>"`"!==t(this,nt,"m",dt).call(this))));return e(this,it,(r=t(this,it,"f"),++r),"f"),i},ft=function(){var n,r,i,s,o;const a=t(this,it,"f");return e(this,it,(n=t(this,it,"f"),++n),"f"),t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/[\d-]/))),"T"===t(this,nt,"m",dt).call(this)&&(e(this,it,(r=t(this,it,"f"),++r),"f"),t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/[\d:]/))),"."===t(this,nt,"m",dt).call(this)&&t(this,nt,"m",wt).call(this).match(/\d/)&&(e(this,it,(i=t(this,it,"f"),++i),"f"),t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/[\d]/)))),"Z"===t(this,nt,"m",dt).call(this)?e(this,it,(s=t(this,it,"f"),++s),"f"):"+"!==t(this,nt,"m",dt).call(this)&&"-"!==t(this,nt,"m",dt).call(this)||(e(this,it,(o=t(this,it,"f"),++o),"f"),t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/[\d:]/))))),St("DateTime",t(this,rt,"f").substring(a+1,t(this,it,"f")))},mt=function(){var n;const r=t(this,it,"f");let i="Number";return t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/\d/))),"."===t(this,nt,"m",dt).call(this)&&t(this,nt,"m",wt).call(this).match(/\d/)&&(e(this,it,(n=t(this,it,"f"),++n),"f"),t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/\d/))))," "===t(this,nt,"m",dt).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&Tt.includes(t.value))return!0}return!1}(t(this,nt,"m",st).call(this))&&(i="Quantity",t(this,nt,"m",ot).call(this)),St(i,t(this,rt,"f").substring(r,t(this,it,"f")))},gt=function(){return St("Symbol",t(this,nt,"m",vt).call(this,(()=>t(this,nt,"m",dt).call(this).match(/[$\w]/))))},pt=function(){var n;const r=t(this,nt,"m",dt).call(this),i=r+t(this,nt,"m",wt).call(this);return At.includes(i)?(e(this,it,t(this,it,"f")+2,"f"),St(i,i)):(e(this,it,(n=t(this,it,"f"),++n),"f"),St(r,r))},vt=function(n){var r;const i=t(this,it,"f");for(;t(this,it,"f")<t(this,rt,"f").length&&n();)e(this,it,(r=t(this,it,"f"),++r),"f");return t(this,rt,"f").substring(i,t(this,it,"f"))},dt=function(){return t(this,rt,"f")[t(this,it,"f")]},yt=function(){var e;return null!==(e=t(this,rt,"f")[t(this,it,"f")-1])&&void 0!==e?e:""},wt=function(){var e;return null!==(e=t(this,rt,"f")[t(this,it,"f")+1])&&void 0!==e?e:""};kt=new WeakMap,jt=new WeakMap;class $t{constructor(t,n,r){Lt.add(this),Mt.set(this,void 0),Dt.set(this,void 0),Wt.set(this,void 0),e(this,Mt,t,"f"),e(this,Dt,n,"f"),e(this,Wt,r,"f")}match(e){const n=t(this,Lt,"m",It).call(this);return(null==n?void 0:n.id)===e&&(t(this,Lt,"m",Pt).call(this),!0)}parse(e=100){const n=t(this,Lt,"m",Pt).call(this),r=t(this,Dt,"f")[n.id];if(!r)throw Error(`Parse error at ${n.value}. No matching prefix parselet.`);let i=r.parse(this,n);for(;e>t(this,Lt,"m",Ot).call(this);){const e=t(this,Lt,"m",Pt).call(this);i=t(this,Wt,"f")[e.id].parse(this,i,e)}return i}}Mt=new WeakMap,Dt=new WeakMap,Wt=new WeakMap,Lt=new WeakSet,Ot=function(){const e=t(this,Lt,"m",It).call(this);if(!e)return 100;const n=t(this,Wt,"f")[e.id];return n?n.precedence:100},Pt=function(){if(!t(this,Mt,"f").length)throw Error("Cant consume unknown more tokens.");return t(this,Mt,"f").shift()},It=function(){return t(this,Mt,"f").length>0?t(this,Mt,"f")[0]:void 0};const Ct={parse(t){const e=t.parse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},Ft={parse(t,e){if(!(e instanceof d))throw new Error("Unexpected parentheses");if(!(e.name in bt))throw new Error("Unrecognized function: "+e.name);const n=[];for(;!t.match(")");)n.push(t.parse()),t.match(",");return new C(e.name,n,bt[e.name])},precedence:0};const zt=(new class{constructor(){kt.set(this,{}),jt.set(this,{})}registerInfix(e,n){return t(this,jt,"f")[e]=n,this}registerPrefix(e,n){return t(this,kt,"f")[e]=n,this}prefix(t,e,n){return this.registerPrefix(t,{parse(t,r){const i=t.parse(e);return n(r,i)}})}infixLeft(t,e,n){return this.registerInfix(t,{parse(t,r,i){const s=t.parse(e);return n(r,i,s)},precedence:e})}construct(e){return new $t(xt(e),t(this,kt,"f"),t(this,jt,"f"))}}).registerPrefix("String",{parse:(t,e)=>new v(e.value)}).registerPrefix("DateTime",{parse:(t,e)=>new v(F(e.value))}).registerPrefix("Quantity",{parse:(t,e)=>new v(function(t){const e=t.split(" "),n=parseFloat(e[0]);let r=e[1];return r=r&&r.startsWith("'")&&r.endsWith("'")?r.substring(1,r.length-1):"{"+r+"}",{value:n,unit:r}}(e.value))}).registerPrefix("Number",{parse:(t,e)=>new v(parseFloat(e.value))}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new v(!1):"true"===e.value?new v(!0):new d(e.value)}).registerPrefix("{}",{parse:()=>new y}).registerPrefix("(",Ct).registerInfix("(",Ft).prefix("+",3,((t,e)=>new w(e,(t=>t)))).prefix("-",3,((t,e)=>new x(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,n)=>new k(t,n))).infixLeft("/",4,((t,e,n)=>new x(t,n,((t,e)=>t/e)))).infixLeft("*",4,((t,e,n)=>new x(t,n,((t,e)=>t*e)))).infixLeft("+",5,((t,e,n)=>new x(t,n,((t,e)=>t+e)))).infixLeft("-",5,((t,e,n)=>new x(t,n,((t,e)=>t-e)))).infixLeft("|",7,((t,e,n)=>new j(t,n))).infixLeft("=",9,((t,e,n)=>new L(t,n))).infixLeft("!=",9,((t,e,n)=>new M(t,n))).infixLeft("~",9,((t,e,n)=>new D(t,n))).infixLeft("!~",9,((t,e,n)=>new W(t,n))).infixLeft("<",8,((t,e,n)=>new T(t,n,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,n)=>new T(t,n,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,n)=>new T(t,n,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,n)=>new T(t,n,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,n)=>new A(t,n))).infixLeft("Symbol",6,((t,e,n)=>{switch(e.value){case"and":return new P(t,n);case"as":return new b(t,n);case"contains":return new E(t,n);case"div":return new x(t,n,((t,e)=>t/e|0));case"in":return new S(t,n);case"is":return new O(t,n);case"mod":return new x(t,n,((t,e)=>t%e));case"or":return new I(t,n);case"xor":return new $(t,n);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function Bt(t){try{return new p(t,zt.construct(t).parse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}function Qt(t,e){return Bt(t).eval(e)}export{Qt as evalFhirPath,Bt as parseFhirPath,xt as tokenize};
function t(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function e(t,e,n,r,i){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!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"===r?i.call(t,n):i?i.value=n:e.set(t,n),n}function n(t){return null==t?[]:Array.isArray(t)?t:[t]}function r(t,e){if(void 0!==t)return Array.isArray(t)?t.map((t=>e(t))).filter((t=>!!t)).flat():e(t)}function i(t){return Array.isArray(t)&&0===t.length}function s(t){return!t||i(t)}function o(t){return Array.isArray(t)?0!==t.length&&!!t[0]:!!t}function c(t){const e=[];for(const n of t){let t=!1;for(const r of e)if(a(n,r)){t=!0;break}t||e.push(n)}return e}function a(t,e){return!(!s(t)||!s(e))||(i(t)||i(e)?[]:"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<1e-8:u(t)&&u(e)?f(t,e):Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every(((t,n)=>a(t,e[n]))):"object"==typeof t&&"object"==typeof e?m(t,e):t===e)}function l(t,e){return!(!s(t)||!s(e))||!i(t)&&!i(e)&&("number"==typeof t&&"number"==typeof e?Math.abs(t-e)<.01:u(t)&&u(e)?f(t,e):Array.isArray(t)&&Array.isArray(e)?(t.sort(),e.sort(),t.length===e.length&&t.every(((t,n)=>a(t,e[n])))):"object"==typeof t&&"object"==typeof e?m(t,e):"string"==typeof t&&"string"==typeof e?t.toLowerCase()===e.toLowerCase():t===e)}function h(t,e){if(null==t)return!1;switch(e){case"Boolean":return"boolean"==typeof t;case"Decimal":case"Integer":return"number"==typeof t;case"Date":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?/);case"DateTime":return"string"==typeof t&&!!t.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);case"Time":return"string"==typeof t&&!!t.match(/^T\d/);case"Period":return!(!(n=t)||"object"!=typeof n||!("start"in n));case"Quantity":return u(t);default:return"object"==typeof t&&(null==t?void 0:t.resourceType)===e}var n}function u(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function f(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 m(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const r of n){const n=t[r],i=e[r];if(g(n)&&g(i)){if(!m(n,i))return!1}else if(n!==i)return!1}return!0}function g(t){return null!==t&&"object"==typeof t}class p{constructor(t,e){this.original=t,this.child=e}eval(t){try{const e=r(t,(t=>this.child.eval(t)));return Array.isArray(e)?e.flat():null==e?[]:[e]}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class v{constructor(t){this.value=t}eval(){return this.value}}class d{constructor(t){this.name=t}eval(t){return"$this"===this.name?t:r(t,(t=>{if(t&&"object"==typeof t){if("resourceType"in t&&t.resourceType===this.name)return t;if(this.name in t)return t[this.name];const e=Object.keys(t).find((t=>t.startsWith(this.name)));if(e)return t[e]}}))}}class y{eval(){return[]}}class w{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class b{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class x{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return u(e)&&u(n)?Object.assign(Object.assign({},e),{value:this.impl(e.value,n.value)}):this.impl(e,n)}}class A{constructor(t,e,n){this.left=t,this.right=e,this.impl=n}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return u(e)&&u(n)?this.impl(e.value,n.value):this.impl(e,n)}}class T{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t),r=[];function i(t){t&&(Array.isArray(t)?r.push(...t):r.push(t))}return i(e),i(n),r.length>0&&r.every((t=>"string"==typeof t))?r.join(""):r}}class E{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return n(e).includes(r)}}class S{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);return n(this.right.eval(t)).includes(e)}}class P{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class k{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);let i;return i=void 0!==e&&void 0!==r?[e,r].flat():void 0!==e?n(e):void 0!==r?n(r):[],c(i)}}class j{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(e)&&Array.isArray(n)?a(e.flat(),n):r(e,(t=>a(t,n)))}}class L{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let i;return i=Array.isArray(n)?a(e,n):r(e,(t=>a(t,n))),!o(i)}}class M{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return Array.isArray(n)?l(e,n):r(e,(t=>l(t,n)))}}class D{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);let i;return i=Array.isArray(n)?l(e,n):r(e,(t=>l(t,n))),!o(i)}}class W{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.right.name;return r(this.left.eval(t),(t=>h(t,e)))}}class O{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0===n||!1!==e&&!1!==n&&[]}}class I{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(o(e))return e;const n=this.right.eval(t);return o(n)?n:[]}}class ${constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),n=this.right.eval(t);return!0===e&&!0!==n||!0!==e&&!0===n||!(!0===e&&!0===n||!1===e&&!1===n)&&[]}}class C{constructor(t,e,n){this.name=t,this.args=e,this.impl=n}eval(t){return this.impl(n(t),...this.args)}}class F{constructor(t,e){this.left=t,this.expr=e}eval(t){const e=this.expr.eval(t);if("number"!=typeof e)throw new Error("Invalid indexer expression: should return integer}");const n=this.left.eval(t);return e in n?n[e]:[]}}function z(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 B=()=>[];const Q=B,U=B;const _=B,N=B;function q(t){if(0===t.length)return[];const[e]=nt(t,1);if("boolean"==typeof e)return[e];if("number"==typeof e&&(0===e||1===e))return[!!e];if("string"==typeof e){const t=e.toLowerCase();if(["true","t","yes","y","1","1.0"].includes(t))return[!0];if(["false","f","no","n","0","0.0"].includes(t))return[!1]}return[]}function R(t){if(0===t.length)return[];const[e]=nt(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[parseInt(e,10)]:"boolean"==typeof e?[e?1:0]:[]}function Z(t){if(0===t.length)return[];const[e]=nt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[z(e)]:[]}function H(t){if(0===t.length)return[];const[e]=nt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[z(e)]:[]}function G(t){if(0===t.length)return[];const[e]=nt(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?$/)?[parseFloat(e)]:"boolean"==typeof e?[e?1:0]:[]}function J(t){if(0===t.length)return[];const[e]=nt(t,1);return u(e)?[e]:"number"==typeof e?[{value:e,unit:"1"}]:"string"==typeof e&&e.match(/^-?\d{1,9}(\.\d{1,9})?/)?[{value:parseFloat(e),unit:"1"}]:"boolean"==typeof e?[{value:e?1:0,unit:"1"}]:[]}function K(t){if(0===t.length)return[];const[e]=nt(t,1);return null==e?[]:u(e)?[`${e.value} '${e.unit}'`]:[e.toString()]}function V(t){if(0===t.length)return[];const[e]=nt(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[z("T"+t[1])]}return[]}const X=B,Y=B;function tt(t,e,...n){if(0===e.length)return[];const[r]=nt(e,1);if("string"!=typeof r)throw new Error("String function cannot be called with non-string");const i=t(r,...n.map((t=>t&&t.eval(r))));return void 0===i?[]:[i]}function et(t,e,...n){if(0===e.length)return[];const[r]=nt(e,1),i=u(r),s=i?r.value:r;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...n.map((t=>t.eval(void 0))));return i?[Object.assign(Object.assign({},r),{value:o})]:[o]}function nt(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);return t}var rt,it,st,ot,ct,at,lt,ht,ut,ft,mt,gt,pt,vt,dt,yt,wt,bt,xt=Object.freeze({__proto__:null,empty:function(t){return[0===t.length]},exists:function(t,e){return e?[t.filter((t=>o(e.eval(t)))).length>0]:[t.length>0]},all:function(t,e){return[t.every((t=>o(e.eval(t))))]},allTrue:function(t){for(const e of t)if(!e)return[!1];return[!0]},anyTrue:function(t){for(const e of t)if(e)return[!0];return[!1]},allFalse:function(t){for(const e of t)if(e)return[!1];return[!0]},anyFalse:function(t){for(const e of t)if(!e)return[!0];return[!1]},subsetOf:Q,supersetOf:U,count:function(t){return[t.length]},distinct:function(t){return Array.from(new Set(t))},isDistinct:function(t){return[t.length===new Set(t).size]},where:function(t,e){return t.filter((t=>o(e.eval(t))))},select:function(t,e){return n(t.map((t=>e.eval(t))).flat())},repeat:_,ofType:N,single:function(t){if(t.length>1)throw new Error("Expected input length one for single()");return 0===t.length?[]:t.slice(0,1)},first:function(t){return 0===t.length?[]:[t[0]]},last:function(t){return 0===t.length?[]:[t[t.length-1]]},tail:function(t){return 0===t.length?[]:t.slice(1,t.length)},skip:function(t,e){const n=e.eval(0);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:function(t,e){const n=e.eval(0);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:function(t,e){if(!e)return t;const r=n(e.eval(0));return c(t.filter((t=>r.includes(t))))},exclude:function(t,e){if(!e)return t;const r=n(e.eval(0));return t.filter((t=>!r.includes(t)))},union:function(t,e){return e?c([t,e.eval(0)].flat()):t},combine:function(t,e){return e?[t,e.eval(0)].flat():t},iif:function(t,e,r,i){const s=n(e.eval(t));if(s.length>1||1===s.length&&"boolean"!=typeof s[0])throw new Error("Expected criterion to evaluate to a Boolean");return o(s)?n(r.eval(t)):i?n(i.eval(t)):[]},toBoolean:q,convertsToBoolean:function(t){return 0===t.length?[]:[1===q(t).length]},toInteger:R,convertsToInteger:function(t){return 0===t.length?[]:[1===R(t).length]},toDate:Z,convertsToDate:function(t){return 0===t.length?[]:[1===Z(t).length]},toDateTime:H,convertsToDateTime:function(t){return 0===t.length?[]:[1===H(t).length]},toDecimal:G,convertsToDecimal:function(t){return 0===t.length?[]:[1===G(t).length]},toQuantity:J,convertsToQuantity:function(t){return 0===t.length?[]:[1===J(t).length]},toString:K,convertsToString:function(t){return 0===t.length?[]:[1===K(t).length]},toTime:V,convertsToTime:function(t){return 0===t.length?[]:[1===V(t).length]},indexOf:function(t,e){return tt(((t,e)=>t.indexOf(e)),t,e)},substring:function(t,e,n){return tt(((t,e,n)=>{const r=e,i=n?r+n:t.length;return r<0||r>=t.length?void 0:t.substring(r,i)}),t,e,n)},startsWith:function(t,e){return tt(((t,e)=>t.startsWith(e)),t,e)},endsWith:function(t,e){return tt(((t,e)=>t.endsWith(e)),t,e)},contains:function(t,e){return tt(((t,e)=>t.includes(e)),t,e)},upper:function(t){return tt((t=>t.toUpperCase()),t)},lower:function(t){return tt((t=>t.toLowerCase()),t)},replace:function(t,e,n){return tt(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},matches:function(t,e){return tt(((t,e)=>!!t.match(e)),t,e)},replaceMatches:function(t,e,n){return tt(((t,e,n)=>t.replaceAll(e,n)),t,e,n)},length:function(t){return tt((t=>t.length),t)},toChars:function(t){return tt((t=>t?t.split(""):void 0),t)},abs:function(t){return et(Math.abs,t)},ceiling:function(t){return et(Math.ceil,t)},exp:function(t){return et(Math.exp,t)},floor:function(t){return et(Math.floor,t)},ln:function(t){return et(Math.log,t)},log:function(t,e){return et(((t,e)=>Math.log(t)/Math.log(e)),t,e)},power:function(t,e){return et(Math.pow,t,e)},round:function(t){return et(Math.round,t)},sqrt:function(t){return et(Math.sqrt,t)},truncate:function(t){return et((t=>0|t),t)},children:X,descendants:Y,trace:function(t,e){return console.log("trace",t,e),t},now:function(){return[(new Date).toISOString()]},timeOfDay:function(){return[(new Date).toISOString().substring(11)]},today:function(){return[(new Date).toISOString().substring(0,10)]},is:function(t,e){const n=e.name;return t.map((t=>h(t,n)))},not:function(t){return q(t).map((t=>!t))},resolve:function(t){return t.map((t=>{let e;if("string"==typeof t?e=t:"object"==typeof t&&(e=t.reference),!e)return;const[n,r]=e.split("/");return{resourceType:n,id:r}})).filter((t=>!!t))},as:function(t){return t},type:function(t){return t.map((t=>"boolean"==typeof t?{namespace:"System",name:"Boolean"}:"number"==typeof t?{namespace:"System",name:"Integer"}:t&&"object"==typeof t&&"resourceType"in t?{namespace:"FHIR",name:t.resourceType}:null))},conformsTo:function(t,e){const n=e.eval(void 0);if(!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const r=n.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>(null==t?void 0:t.resourceType)===r))}});function At(t){return new St(t).tokenize()}const Tt=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],Et=["!=","!~","<=",">=","{}"];class St{constructor(t){rt.add(this),it.set(this,void 0),st.set(this,void 0),e(this,it,t,"f"),e(this,st,0,"f")}tokenize(){const e=[];for(;t(this,st,"f")<t(this,it,"f").length;){const n=t(this,rt,"m",ct).call(this);n&&e.push(n)}return e}}function Pt(t,e){return{id:t,value:e}}var kt,jt,Lt,Mt,Dt,Wt,Ot,It,$t;it=new WeakMap,st=new WeakMap,rt=new WeakSet,ot=function(){const n=t(this,st,"f"),r=t(this,rt,"m",ct).call(this);return e(this,st,n,"f"),r},ct=function(){t(this,rt,"m",at).call(this);const e=t(this,rt,"m",yt).call(this);if(!e)return;const n=t(this,rt,"m",bt).call(this);return"/"===e&&"*"===n?t(this,rt,"m",lt).call(this):"/"===e&&"/"===n?t(this,rt,"m",ht).call(this):"'"===e?t(this,rt,"m",ut).call(this):"`"===e?t(this,rt,"m",ft).call(this):"@"===e?t(this,rt,"m",mt).call(this):e.match(/\d/)?t(this,rt,"m",gt).call(this):e.match(/\w/)||"$"===e&&n.match(/\w/)?t(this,rt,"m",pt).call(this):t(this,rt,"m",vt).call(this)},at=function(){return Pt("Whitespace",t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/\s/))))},lt=function(){const n=t(this,st,"f");return t(this,rt,"m",dt).call(this,(()=>"*"!==t(this,rt,"m",yt).call(this)||"/"!==t(this,rt,"m",bt).call(this))),e(this,st,t(this,st,"f")+2,"f"),Pt("Comment",t(this,it,"f").substring(n,t(this,st,"f")))},ht=function(){return Pt("Comment",t(this,rt,"m",dt).call(this,(()=>"\n"!==t(this,rt,"m",yt).call(this))))},ut=function(){var n,r;e(this,st,(n=t(this,st,"f"),++n),"f");const i=Pt("String",t(this,rt,"m",dt).call(this,(()=>"\\"===t(this,rt,"m",wt).call(this)||"'"!==t(this,rt,"m",yt).call(this))));return e(this,st,(r=t(this,st,"f"),++r),"f"),i},ft=function(){var n,r;e(this,st,(n=t(this,st,"f"),++n),"f");const i=Pt("Symbol",t(this,rt,"m",dt).call(this,(()=>"`"!==t(this,rt,"m",yt).call(this))));return e(this,st,(r=t(this,st,"f"),++r),"f"),i},mt=function(){var n,r,i,s,o;const c=t(this,st,"f");return e(this,st,(n=t(this,st,"f"),++n),"f"),t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/[\d-]/))),"T"===t(this,rt,"m",yt).call(this)&&(e(this,st,(r=t(this,st,"f"),++r),"f"),t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/[\d:]/))),"."===t(this,rt,"m",yt).call(this)&&t(this,rt,"m",bt).call(this).match(/\d/)&&(e(this,st,(i=t(this,st,"f"),++i),"f"),t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/[\d]/)))),"Z"===t(this,rt,"m",yt).call(this)?e(this,st,(s=t(this,st,"f"),++s),"f"):"+"!==t(this,rt,"m",yt).call(this)&&"-"!==t(this,rt,"m",yt).call(this)||(e(this,st,(o=t(this,st,"f"),++o),"f"),t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/[\d:]/))))),Pt("DateTime",t(this,it,"f").substring(c+1,t(this,st,"f")))},gt=function(){var n;const r=t(this,st,"f");let i="Number";return t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/\d/))),"."===t(this,rt,"m",yt).call(this)&&t(this,rt,"m",bt).call(this).match(/\d/)&&(e(this,st,(n=t(this,st,"f"),++n),"f"),t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/\d/))))," "===t(this,rt,"m",yt).call(this)&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&Tt.includes(t.value))return!0}return!1}(t(this,rt,"m",ot).call(this))&&(i="Quantity",t(this,rt,"m",ct).call(this)),Pt(i,t(this,it,"f").substring(r,t(this,st,"f")))},pt=function(){return Pt("Symbol",t(this,rt,"m",dt).call(this,(()=>t(this,rt,"m",yt).call(this).match(/[$\w]/))))},vt=function(){var n;const r=t(this,rt,"m",yt).call(this),i=r+t(this,rt,"m",bt).call(this);return Et.includes(i)?(e(this,st,t(this,st,"f")+2,"f"),Pt(i,i)):(e(this,st,(n=t(this,st,"f"),++n),"f"),Pt(r,r))},dt=function(n){var r;const i=t(this,st,"f");for(;t(this,st,"f")<t(this,it,"f").length&&n();)e(this,st,(r=t(this,st,"f"),++r),"f");return t(this,it,"f").substring(i,t(this,st,"f"))},yt=function(){return t(this,it,"f")[t(this,st,"f")]},wt=function(){var e;return null!==(e=t(this,it,"f")[t(this,st,"f")-1])&&void 0!==e?e:""},bt=function(){var e;return null!==(e=t(this,it,"f")[t(this,st,"f")+1])&&void 0!==e?e:""};kt=new WeakMap,jt=new WeakMap;class Ct{constructor(t,n,r){Lt.add(this),Mt.set(this,void 0),Dt.set(this,void 0),Wt.set(this,void 0),e(this,Mt,t,"f"),e(this,Dt,n,"f"),e(this,Wt,r,"f")}match(e){const n=t(this,Lt,"m",$t).call(this);return(null==n?void 0:n.id)===e&&(t(this,Lt,"m",It).call(this),!0)}consumeAndParse(e=100){const n=t(this,Lt,"m",It).call(this),r=t(this,Dt,"f")[n.id];if(!r)throw Error(`Parse error at ${n.value}. No matching prefix parselet.`);let i=r.parse(this,n);for(;e>t(this,Lt,"m",Ot).call(this);){const e=t(this,Lt,"m",It).call(this);i=t(this,Wt,"f")[e.id].parse(this,i,e)}return i}}Mt=new WeakMap,Dt=new WeakMap,Wt=new WeakMap,Lt=new WeakSet,Ot=function(){const e=t(this,Lt,"m",$t).call(this);if(!e)return 100;const n=t(this,Wt,"f")[e.id];return n?n.precedence:100},It=function(){if(!t(this,Mt,"f").length)throw Error("Cant consume unknown more tokens.");return t(this,Mt,"f").shift()},$t=function(){return t(this,Mt,"f").length>0?t(this,Mt,"f")[0]:void 0};const Ft={parse(t){const e=t.consumeAndParse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},zt={parse(t,e){const n=t.consumeAndParse();if(!t.match("]"))throw new Error("Parse error: expected `]`");return new F(e,n)},precedence:2},Bt={parse(t,e){if(!(e instanceof d))throw new Error("Unexpected parentheses");if(!(e.name in xt))throw new Error("Unrecognized function: "+e.name);const n=[];for(;!t.match(")");)n.push(t.consumeAndParse()),t.match(",");return new C(e.name,n,xt[e.name])},precedence:0};const Qt=(new class{constructor(){kt.set(this,{}),jt.set(this,{})}registerInfix(e,n){return t(this,jt,"f")[e]=n,this}registerPrefix(e,n){return t(this,kt,"f")[e]=n,this}prefix(t,e,n){return this.registerPrefix(t,{parse(t,r){const i=t.consumeAndParse(e);return n(r,i)}})}infixLeft(t,e,n){return this.registerInfix(t,{parse(t,r,i){const s=t.consumeAndParse(e);return n(r,i,s)},precedence:e})}construct(e){return new Ct(At(e),t(this,kt,"f"),t(this,jt,"f"))}}).registerPrefix("String",{parse:(t,e)=>new v(e.value)}).registerPrefix("DateTime",{parse:(t,e)=>new v(z(e.value))}).registerPrefix("Quantity",{parse:(t,e)=>new v(function(t){const e=t.split(" "),n=parseFloat(e[0]);let r=e[1];return r=r&&r.startsWith("'")&&r.endsWith("'")?r.substring(1,r.length-1):"{"+r+"}",{value:n,unit:r}}(e.value))}).registerPrefix("Number",{parse:(t,e)=>new v(parseFloat(e.value))}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new v(!1):"true"===e.value?new v(!0):new d(e.value)}).registerPrefix("{}",{parse:()=>new y}).registerPrefix("(",Ft).registerInfix("[",zt).registerInfix("(",Bt).prefix("+",3,((t,e)=>new w(e,(t=>t)))).prefix("-",3,((t,e)=>new x(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,n)=>new P(t,n))).infixLeft("/",4,((t,e,n)=>new x(t,n,((t,e)=>t/e)))).infixLeft("*",4,((t,e,n)=>new x(t,n,((t,e)=>t*e)))).infixLeft("+",5,((t,e,n)=>new x(t,n,((t,e)=>t+e)))).infixLeft("-",5,((t,e,n)=>new x(t,n,((t,e)=>t-e)))).infixLeft("|",7,((t,e,n)=>new k(t,n))).infixLeft("=",9,((t,e,n)=>new j(t,n))).infixLeft("!=",9,((t,e,n)=>new L(t,n))).infixLeft("~",9,((t,e,n)=>new M(t,n))).infixLeft("!~",9,((t,e,n)=>new D(t,n))).infixLeft("<",8,((t,e,n)=>new A(t,n,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,n)=>new A(t,n,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,n)=>new A(t,n,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,n)=>new A(t,n,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,n)=>new T(t,n))).infixLeft("Symbol",6,((t,e,n)=>{switch(e.value){case"and":return new O(t,n);case"as":return new b(t,n);case"contains":return new E(t,n);case"div":return new x(t,n,((t,e)=>t/e|0));case"in":return new S(t,n);case"is":return new W(t,n);case"mod":return new x(t,n,((t,e)=>t%e));case"or":return new I(t,n);case"xor":return new $(t,n);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function Ut(t){try{return new p(t,Qt.construct(t).consumeAndParse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}function _t(t,e){return Ut(t).eval(e)}export{_t as evalFhirPath,Ut as parseFhirPath,At as tokenize};
//# sourceMappingURL=index.min.js.map

@@ -145,1 +145,7 @@ import { Quantity } from '@medplum/fhirtypes';

}
export declare class IndexerAtom implements Atom {
readonly left: Atom;
readonly expr: Atom;
constructor(left: Atom, expr: Atom);
eval(context: unknown): unknown;
}
{
"name": "@medplum/fhirpath",
"version": "0.9.1",
"version": "0.9.2",
"description": "Medplum FHIRPath Library",

@@ -20,4 +20,4 @@ "author": "Medplum <hello@medplum.com>",

"devDependencies": {
"@medplum/definitions": "0.9.1",
"@medplum/fhirtypes": "0.9.1"
"@medplum/definitions": "0.9.2",
"@medplum/fhirtypes": "0.9.2"
},

@@ -24,0 +24,0 @@ "main": "dist/cjs/index.js",

@@ -7,4 +7,6 @@ # Medplum FHIRPath Library

Add as a dependency:
```bash
npm install --save-dev @medplum/fhirpath
npm install @medplum/fhirpath
```

@@ -14,3 +16,3 @@

```typescript
```ts
import { Patient } from '@medplum/fhirtypes';

@@ -33,4 +35,8 @@ import { evalFhirPath } from '@medplum/fhirpath';

## About Medplum
Medplum is a healthcare platform that helps you quickly develop high-quality compliant applications. Medplum includes a FHIR server, React component library, and developer app.
## License
Apache 2.0. Copyright &copy; Medplum 2022

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc