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.4.0 to 0.4.1

16

dist/cjs/index.min.js

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

!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){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 n(t){return Array.isArray(t)&&0===t.length}function i(t){return!t||n(t)}function s(t){return Array.isArray(t)?0!==t.length&&!!t[0]:!!t}function o(t){const e=[];for(const r of t){let t=!1;for(const n of e)if(u(r,n)){t=!0;break}t||e.push(r)}return e}function u(t,e){return!(!i(t)||!i(e))||(n(t)||n(e)?[]:"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<1e-8:h(t)&&h(e)?l(t,e):Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every(((t,r)=>u(t,e[r]))):"object"==typeof t&&"object"==typeof e?f(t,e):t===e)}function c(t,e){return!(!i(t)||!i(e))||!n(t)&&!n(e)&&("number"==typeof t&&"number"==typeof e?Math.abs(t-e)<.01:h(t)&&h(e)?l(t,e):Array.isArray(t)&&Array.isArray(e)?(t.sort(),e.sort(),t.length===e.length&&t.every(((t,r)=>u(t,e[r])))):"object"==typeof t&&"object"==typeof e?f(t,e):"string"==typeof t&&"string"==typeof e?t.toLowerCase()===e.toLowerCase():t===e)}function a(t,e){var r,n;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 h(t);default:return"object"==typeof t&&(null===(r=t)||void 0===r?void 0:r.resourceType)===e}}function h(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function l(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 f(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(p(r)&&p(i)){if(!f(r,i))return!1}else if(r!==i)return!1}return!0}function p(t){return null!==t&&"object"==typeof t}class m{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 g{constructor(t){this.value=t}eval(){return this.value}}class v{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 d{eval(){return[]}}class y{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class w{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class b{constructor(t,e,r){this.left=t,this.right=e,this.impl=r}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return h(e)&&h(r)?Object.assign(Object.assign({},e),{value:this.impl(e.value,r.value)}):this.impl(e,r)}}class x{constructor(t,e,r){this.left=t,this.right=e,this.impl=r}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return h(e)&&h(r)?this.impl(e.value,r.value):this.impl(e,r)}}class T{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t),n=[];function i(t){t&&(Array.isArray(t)?n.push(...t):n.push(t))}return i(e),i(r),n.length>0&&n.every((t=>"string"==typeof t))?n.join(""):n}}class k{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.left.eval(t),n=this.right.eval(t);return e(r).includes(n)}}class S{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.left.eval(t);return e(this.right.eval(t)).includes(r)}}class A{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class P{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.left.eval(t),n=this.right.eval(t);let i;return i=void 0!==r&&void 0!==n?[r,n].flat():void 0!==r?e(r):void 0!==n?e(n):[],o(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)?u(e.flat(),n):r(e,(t=>u(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)?u(e,n):r(e,(t=>u(t,n))),!s(i)}}class E{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)?c(e,n):r(e,(t=>c(t,n)))}}class j{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))),!s(i)}}class D{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.right.name;return r(this.left.eval(t),(t=>a(t,e)))}}class O{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return!0===e&&!0===r||!1!==e&&!1!==r&&[]}}class M{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(s(e))return e;const r=this.right.eval(t);return s(r)?r:[]}}class C{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return!0===e&&!0!==r||!0!==e&&!0===r||!(!0===e&&!0===r||!1===e&&!1===r)&&[]}}class I{constructor(t,e,r){this.name=t,this.args=e,this.impl=r}eval(t){return this.impl(e(t),...this.args)}}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 F=()=>[];const B=F,z=F;const _=F,N=F;function Q(t){if(0===t.length)return[];const[e]=tt(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 U(t){if(0===t.length)return[];const[e]=tt(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[parseInt(e,10)]:"boolean"==typeof e?[e?1:0]:[]}function q(t){if(0===t.length)return[];const[e]=tt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[$(e)]:[]}function R(t){if(0===t.length)return[];const[e]=tt(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[$(e)]:[]}function Z(t){if(0===t.length)return[];const[e]=tt(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 H(t){if(0===t.length)return[];const[e]=tt(t,1);return h(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 G(t){if(0===t.length)return[];const[e]=tt(t,1);return null==e?[]:h(e)?[`${e.value} '${e.unit}'`]:[e.toString()]}function J(t){if(0===t.length)return[];const[e]=tt(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 K=F,V=F;function X(t,e,...r){if(0===e.length)return[];const[n]=tt(e,1);if("string"!=typeof n)throw new Error("String function cannot be called with non-string");const i=t(n,...r.map((t=>t&&t.eval(n))));return void 0===i?[]:[i]}function Y(t,e,...r){if(0===e.length)return[];const[n]=tt(e,1),i=h(n),s=i?n.value:n;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...r.map((t=>t.eval(void 0))));return i?[Object.assign(Object.assign({},n),{value:o})]:[o]}function tt(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);return t}var et=Object.freeze({__proto__:null,empty:function(t){return[0===t.length]},exists:function(t,e){return e?[t.filter((t=>s(e.eval(t)))).length>0]:[t.length>0]},all:function(t,e){return[t.every((t=>s(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:z,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=>s(e.eval(t))))},select:function(t,r){return e(r.eval(t))},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 r=e.eval(0);if("number"!=typeof r)throw new Error("Expected a number for skip(num)");return r>=t.length?[]:r<=0?t:t.slice(r,t.length)},take:function(t,e){const r=e.eval(0);if("number"!=typeof r)throw new Error("Expected a number for take(num)");return r>=t.length?t:r<=0?[]:t.slice(0,r)},intersect:function(t,r){if(!r)return t;const n=e(r.eval(0));return o(t.filter((t=>n.includes(t))))},exclude:function(t,r){if(!r)return t;const n=e(r.eval(0));return t.filter((t=>!n.includes(t)))},union:function(t,e){return e?o([t,e.eval(0)].flat()):t},combine:function(t,e){return e?[t,e.eval(0)].flat():t},iif:function(t,r,n,i){const o=e(r.eval(t));if(o.length>1||1===o.length&&"boolean"!=typeof o[0])throw new Error("Expected criterion to evaluate to a Boolean");return s(o)?e(n.eval(t)):i?e(i.eval(t)):[]},toBoolean:Q,convertsToBoolean:function(t){return 0===t.length?[]:[1===Q(t).length]},toInteger:U,convertsToInteger:function(t){return 0===t.length?[]:[1===U(t).length]},toDate:q,convertsToDate:function(t){return 0===t.length?[]:[1===q(t).length]},toDateTime:R,convertsToDateTime:function(t){return 0===t.length?[]:[1===R(t).length]},toDecimal:Z,convertsToDecimal:function(t){return 0===t.length?[]:[1===Z(t).length]},toQuantity:H,convertsToQuantity:function(t){return 0===t.length?[]:[1===H(t).length]},toString:G,convertsToString:function(t){return 0===t.length?[]:[1===G(t).length]},toTime:J,convertsToTime:function(t){return 0===t.length?[]:[1===J(t).length]},indexOf:function(t,e){return X(((t,e)=>t.indexOf(e)),t,e)},substring:function(t,e,r){return X(((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:function(t,e){return X(((t,e)=>t.startsWith(e)),t,e)},endsWith:function(t,e){return X(((t,e)=>t.endsWith(e)),t,e)},contains:function(t,e){return X(((t,e)=>t.includes(e)),t,e)},upper:function(t){return X((t=>t.toUpperCase()),t)},lower:function(t){return X((t=>t.toLowerCase()),t)},replace:function(t,e,r){return X(((t,e,r)=>t.replaceAll(e,r)),t,e,r)},matches:function(t,e){return X(((t,e)=>!!t.match(e)),t,e)},replaceMatches:function(t,e,r){return X(((t,e,r)=>t.replaceAll(e,r)),t,e,r)},length:function(t){return X((t=>t.length),t)},toChars:function(t){return X((t=>t?t.split(""):void 0),t)},abs:function(t){return Y(Math.abs,t)},ceiling:function(t){return Y(Math.ceil,t)},exp:function(t){return Y(Math.exp,t)},floor:function(t){return Y(Math.floor,t)},ln:function(t){return Y(Math.log,t)},log:function(t,e){return Y(((t,e)=>Math.log(t)/Math.log(e)),t,e)},power:function(t,e){return Y(Math.pow,t,e)},round:function(t){return Y(Math.round,t)},sqrt:function(t){return Y(Math.sqrt,t)},truncate:function(t){return Y((t=>0|t),t)},children:K,descendants:V,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 r=e.name;return t.map((t=>a(t,r)))},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[r,n]=e.split("/");return{resourceType:r,id:n}})).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 r=e.eval(void 0);if(!r.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const n=r.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>{var e;return(null===(e=t)||void 0===e?void 0:e.resourceType)===n}))}});function rt(t){return new st(t).tokenize()}const nt=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],it=["!=","!~","<=",">=","{}"];class st{constructor(t){this.str=t,this.pos=0}tokenize(){const t=[];for(;this.pos<this.str.length;){const e=this.consumeToken();e&&t.push(e)}return t}peekToken(){const t=this.pos,e=this.consumeToken();return this.pos=t,e}consumeToken(){this.consumeWhitespace();const t=this.curr();if(!t)return;const e=this.peek();return"/"===t&&"*"===e?this.consumeMultiLineComment():"/"===t&&"/"===e?this.consumeSingleLineComment():"'"===t?this.consumeString():"`"===t?this.consumeBacktickSymbol():"@"===t?this.consumeDateTime():t.match(/\d/)?this.consumeNumber():t.match(/\w/)||"$"===t&&e.match(/\w/)?this.consumeSymbol():this.consumeOperator()}consumeWhitespace(){return ot("Whitespace",this.consumeWhile((()=>this.curr().match(/\s/))))}consumeMultiLineComment(){const t=this.pos;return this.consumeWhile((()=>"*"!==this.curr()||"/"!==this.peek())),this.pos+=2,ot("Comment",this.str.substring(t,this.pos))}consumeSingleLineComment(){return ot("Comment",this.consumeWhile((()=>"\n"!==this.curr())))}consumeString(){this.pos++;const t=ot("String",this.consumeWhile((()=>"\\"===this.prev()||"'"!==this.curr())));return this.pos++,t}consumeBacktickSymbol(){this.pos++;const t=ot("Symbol",this.consumeWhile((()=>"`"!==this.curr())));return this.pos++,t}consumeDateTime(){const t=this.pos;return this.pos++,this.consumeWhile((()=>this.curr().match(/[\d-]/))),"T"===this.curr()&&(this.pos++,this.consumeWhile((()=>this.curr().match(/[\d:]/))),"."===this.curr()&&this.peek().match(/\d/)&&(this.pos++,this.consumeWhile((()=>this.curr().match(/[\d]/)))),"Z"===this.curr()?this.pos++:"+"!==this.curr()&&"-"!==this.curr()||(this.pos++,this.consumeWhile((()=>this.curr().match(/[\d:]/))))),ot("DateTime",this.str.substring(t+1,this.pos))}consumeNumber(){const t=this.pos;let e="Number";return this.consumeWhile((()=>this.curr().match(/\d/))),"."===this.curr()&&this.peek().match(/\d/)&&(this.pos++,this.consumeWhile((()=>this.curr().match(/\d/))))," "===this.curr()&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&nt.includes(t.value))return!0}return!1}(this.peekToken())&&(e="Quantity",this.consumeToken()),ot(e,this.str.substring(t,this.pos))}consumeSymbol(){return ot("Symbol",this.consumeWhile((()=>this.curr().match(/[$\w]/))))}consumeOperator(){const t=this.curr(),e=t+this.peek();return it.includes(e)?(this.pos+=2,ot(e,e)):(this.pos++,ot(t,t))}consumeWhile(t){const e=this.pos;for(;this.pos<this.str.length&&t();)this.pos++;return this.str.substring(e,this.pos)}curr(){return this.str[this.pos]}prev(){var t;return null!==(t=this.str[this.pos-1])&&void 0!==t?t:""}peek(){var t;return null!==(t=this.str[this.pos+1])&&void 0!==t?t:""}}function ot(t,e){return{id:t,value:e}}class ut{constructor(t,e,r){this.tokens=t,this.prefixParselets=e,this.infixParselets=r}match(t){const e=this.look();return(null==e?void 0:e.id)===t&&(this.consume(),!0)}parse(t=100){const e=this.consume(),r=this.prefixParselets[e.id];if(!r)throw Error(`Parse error at ${e.value}. No matching prefix parselet.`);let n=r.parse(this,e);for(;t>this.getPrecedence();){const t=this.consume();n=this.infixParselets[t.id].parse(this,n,t)}return n}getPrecedence(){const t=this.look();if(!t)return 100;const e=this.infixParselets[t.id];return e?e.precedence:100}consume(){if(!this.tokens.length)throw Error("Cant consume unknown more tokens.");return this.tokens.shift()}look(){return this.tokens.length>0?this.tokens[0]:void 0}}const ct={parse(t){const e=t.parse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},at={parse(t,e){if(!(e instanceof v))throw new Error("Unexpected parentheses");if(!(e.name in et))throw new Error("Unrecognized function: "+e.name);const r=[];for(;!t.match(")");)r.push(t.parse()),t.match(",");return new I(e.name,r,et[e.name])},precedence:0};const ht=(new class{constructor(){this.prefixParselets={},this.infixParselets={}}registerInfix(t,e){return this.infixParselets[t]=e,this}registerPrefix(t,e){return this.prefixParselets[t]=e,this}prefix(t,e,r){return this.registerPrefix(t,{parse(t,n){const i=t.parse(e);return r(n,i)}})}infixLeft(t,e,r){return this.registerInfix(t,{parse(t,n,i){const s=t.parse(e);return r(n,i,s)},precedence:e})}construct(t){return new ut(rt(t),this.prefixParselets,this.infixParselets)}}).registerPrefix("String",{parse:(t,e)=>new g(e.value)}).registerPrefix("DateTime",{parse:(t,e)=>new g($(e.value))}).registerPrefix("Quantity",{parse:(t,e)=>new g(function(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}}(e.value))}).registerPrefix("Number",{parse:(t,e)=>new g(parseFloat(e.value))}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new g(!1):"true"===e.value?new g(!0):new v(e.value)}).registerPrefix("{}",{parse:()=>new d}).registerPrefix("(",ct).registerInfix("(",at).prefix("+",3,((t,e)=>new y(e,(t=>t)))).prefix("-",3,((t,e)=>new b(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,r)=>new A(t,r))).infixLeft("/",4,((t,e,r)=>new b(t,r,((t,e)=>t/e)))).infixLeft("*",4,((t,e,r)=>new b(t,r,((t,e)=>t*e)))).infixLeft("+",5,((t,e,r)=>new b(t,r,((t,e)=>t+e)))).infixLeft("-",5,((t,e,r)=>new b(t,r,((t,e)=>t-e)))).infixLeft("|",7,((t,e,r)=>new P(t,r))).infixLeft("=",9,((t,e,r)=>new L(t,r))).infixLeft("!=",9,((t,e,r)=>new W(t,r))).infixLeft("~",9,((t,e,r)=>new E(t,r))).infixLeft("!~",9,((t,e,r)=>new j(t,r))).infixLeft("<",8,((t,e,r)=>new x(t,r,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,r)=>new x(t,r,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,r)=>new x(t,r,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,r)=>new x(t,r,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,r)=>new T(t,r))).infixLeft("Symbol",6,((t,e,r)=>{switch(e.value){case"and":return new O(t,r);case"as":return new w(t,r);case"contains":return new k(t,r);case"div":return new b(t,r,((t,e)=>t/e|0));case"in":return new S(t,r);case"is":return new D(t,r);case"mod":return new b(t,r,((t,e)=>t%e));case"or":return new M(t,r);case"xor":return new C(t,r);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function lt(t){try{return new m(t,ht.construct(t).parse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}t.evalFhirPath=function(t,e){return lt(t).eval(e)},t.parseFhirPath=lt,t.tokenize=rt,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";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */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){var n,r;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!(!(r=t)||"object"!=typeof r||!("start"in r));case"Quantity":return f(t);default:return"object"==typeof t&&(null===(n=t)||void 0===n?void 0:n.resourceType)===e}}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=>{var e;return(null===(e=t)||void 0===e?void 0:e.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})}));
//# sourceMappingURL=index.min.js.map

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

function t(t){return null==t?[]:Array.isArray(t)?t:[t]}function e(t,e){if(void 0!==t)return Array.isArray(t)?t.map((t=>e(t))).filter((t=>!!t)).flat():e(t)}function r(t){return Array.isArray(t)&&0===t.length}function n(t){return!t||r(t)}function i(t){return Array.isArray(t)?0!==t.length&&!!t[0]:!!t}function s(t){const e=[];for(const r of t){let t=!1;for(const n of e)if(o(r,n)){t=!0;break}t||e.push(r)}return e}function o(t,e){return!(!n(t)||!n(e))||(r(t)||r(e)?[]:"number"==typeof t&&"number"==typeof e?Math.abs(t-e)<1e-8:a(t)&&a(e)?h(t,e):Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every(((t,r)=>o(t,e[r]))):"object"==typeof t&&"object"==typeof e?l(t,e):t===e)}function u(t,e){return!(!n(t)||!n(e))||!r(t)&&!r(e)&&("number"==typeof t&&"number"==typeof e?Math.abs(t-e)<.01:a(t)&&a(e)?h(t,e):Array.isArray(t)&&Array.isArray(e)?(t.sort(),e.sort(),t.length===e.length&&t.every(((t,r)=>o(t,e[r])))):"object"==typeof t&&"object"==typeof e?l(t,e):"string"==typeof t&&"string"==typeof e?t.toLowerCase()===e.toLowerCase():t===e)}function c(t,e){var r,n;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 a(t);default:return"object"==typeof t&&(null===(r=t)||void 0===r?void 0:r.resourceType)===e}}function a(t){return!(!t||"object"!=typeof t||!("value"in t)||"number"!=typeof t.value)}function h(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 l(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(f(r)&&f(i)){if(!l(r,i))return!1}else if(r!==i)return!1}return!0}function f(t){return null!==t&&"object"==typeof t}class p{constructor(t,e){this.original=t,this.child=e}eval(t){try{const r=e(t,(t=>this.child.eval(t)));return Array.isArray(r)?r.flat():null==r?[]:[r]}catch(t){throw new Error(`FhirPathError on "${this.original}": ${t}`)}}}class m{constructor(t){this.value=t}eval(){return this.value}}class g{constructor(t){this.name=t}eval(t){return"$this"===this.name?t:e(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 v{eval(){return[]}}class y{constructor(t,e){this.child=t,this.impl=e}eval(t){return this.impl(this.child.eval(t))}}class d{constructor(t,e){this.left=t,this.right=e}eval(t){return this.left.eval(t)}}class w{constructor(t,e,r){this.left=t,this.right=e,this.impl=r}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return a(e)&&a(r)?Object.assign(Object.assign({},e),{value:this.impl(e.value,r.value)}):this.impl(e,r)}}class b{constructor(t,e,r){this.left=t,this.right=e,this.impl=r}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return a(e)&&a(r)?this.impl(e.value,r.value):this.impl(e,r)}}class x{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t),n=[];function i(t){t&&(Array.isArray(t)?n.push(...t):n.push(t))}return i(e),i(r),n.length>0&&n.every((t=>"string"==typeof t))?n.join(""):n}}class T{constructor(t,e){this.left=t,this.right=e}eval(e){const r=this.left.eval(e),n=this.right.eval(e);return t(r).includes(n)}}class k{constructor(t,e){this.left=t,this.right=e}eval(e){const r=this.left.eval(e);return t(this.right.eval(e)).includes(r)}}class S{constructor(t,e){this.left=t,this.right=e}eval(t){return this.right.eval(this.left.eval(t))}}class A{constructor(t,e){this.left=t,this.right=e}eval(e){const r=this.left.eval(e),n=this.right.eval(e);let i;return i=void 0!==r&&void 0!==n?[r,n].flat():void 0!==r?t(r):void 0!==n?t(n):[],s(i)}}class P{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.left.eval(t),n=this.right.eval(t);return Array.isArray(r)&&Array.isArray(n)?o(r.flat(),n):e(r,(t=>o(t,n)))}}class L{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.left.eval(t),n=this.right.eval(t);let s;return s=Array.isArray(n)?o(r,n):e(r,(t=>o(t,n))),!i(s)}}class W{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.left.eval(t),n=this.right.eval(t);return Array.isArray(n)?u(r,n):e(r,(t=>u(t,n)))}}class E{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.left.eval(t),n=this.right.eval(t);let s;return s=Array.isArray(n)?u(r,n):e(r,(t=>u(t,n))),!i(s)}}class D{constructor(t,e){this.left=t,this.right=e}eval(t){const r=this.right.name;return e(this.left.eval(t),(t=>c(t,r)))}}class j{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return!0===e&&!0===r||!1!==e&&!1!==r&&[]}}class O{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t);if(i(e))return e;const r=this.right.eval(t);return i(r)?r:[]}}class M{constructor(t,e){this.left=t,this.right=e}eval(t){const e=this.left.eval(t),r=this.right.eval(t);return!0===e&&!0!==r||!0!==e&&!0===r||!(!0===e&&!0===r||!1===e&&!1===r)&&[]}}class C{constructor(t,e,r){this.name=t,this.args=e,this.impl=r}eval(e){return this.impl(t(e),...this.args)}}function I(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 F=$,B=$;const z=$,N=$;function Q(t){if(0===t.length)return[];const[e]=Y(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 U(t){if(0===t.length)return[];const[e]=Y(t,1);return"number"==typeof e?[e]:"string"==typeof e&&e.match(/^[+-]?\d+$/)?[parseInt(e,10)]:"boolean"==typeof e?[e?1:0]:[]}function _(t){if(0===t.length)return[];const[e]=Y(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[I(e)]:[]}function q(t){if(0===t.length)return[];const[e]=Y(t,1);return"string"==typeof e&&e.match(/^\d{4}(-\d{2}(-\d{2})?)?/)?[I(e)]:[]}function R(t){if(0===t.length)return[];const[e]=Y(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 Z(t){if(0===t.length)return[];const[e]=Y(t,1);return a(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 H(t){if(0===t.length)return[];const[e]=Y(t,1);return null==e?[]:a(e)?[`${e.value} '${e.unit}'`]:[e.toString()]}function G(t){if(0===t.length)return[];const[e]=Y(t,1);if("string"==typeof e){const t=e.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);if(t)return[I("T"+t[1])]}return[]}const J=$,K=$;function V(t,e,...r){if(0===e.length)return[];const[n]=Y(e,1);if("string"!=typeof n)throw new Error("String function cannot be called with non-string");const i=t(n,...r.map((t=>t&&t.eval(n))));return void 0===i?[]:[i]}function X(t,e,...r){if(0===e.length)return[];const[n]=Y(e,1),i=a(n),s=i?n.value:n;if("number"!=typeof s)throw new Error("Math function cannot be called with non-number");const o=t(s,...r.map((t=>t.eval(void 0))));return i?[Object.assign(Object.assign({},n),{value:o})]:[o]}function Y(t,e){if(t.length!==e)throw new Error(`Expected ${e} arguments`);return t}var tt=Object.freeze({__proto__:null,empty:function(t){return[0===t.length]},exists:function(t,e){return e?[t.filter((t=>i(e.eval(t)))).length>0]:[t.length>0]},all:function(t,e){return[t.every((t=>i(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:F,supersetOf:B,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=>i(e.eval(t))))},select:function(e,r){return t(r.eval(e))},repeat:z,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 r=e.eval(0);if("number"!=typeof r)throw new Error("Expected a number for skip(num)");return r>=t.length?[]:r<=0?t:t.slice(r,t.length)},take:function(t,e){const r=e.eval(0);if("number"!=typeof r)throw new Error("Expected a number for take(num)");return r>=t.length?t:r<=0?[]:t.slice(0,r)},intersect:function(e,r){if(!r)return e;const n=t(r.eval(0));return s(e.filter((t=>n.includes(t))))},exclude:function(e,r){if(!r)return e;const n=t(r.eval(0));return e.filter((t=>!n.includes(t)))},union:function(t,e){return e?s([t,e.eval(0)].flat()):t},combine:function(t,e){return e?[t,e.eval(0)].flat():t},iif:function(e,r,n,s){const o=t(r.eval(e));if(o.length>1||1===o.length&&"boolean"!=typeof o[0])throw new Error("Expected criterion to evaluate to a Boolean");return i(o)?t(n.eval(e)):s?t(s.eval(e)):[]},toBoolean:Q,convertsToBoolean:function(t){return 0===t.length?[]:[1===Q(t).length]},toInteger:U,convertsToInteger:function(t){return 0===t.length?[]:[1===U(t).length]},toDate:_,convertsToDate:function(t){return 0===t.length?[]:[1===_(t).length]},toDateTime:q,convertsToDateTime:function(t){return 0===t.length?[]:[1===q(t).length]},toDecimal:R,convertsToDecimal:function(t){return 0===t.length?[]:[1===R(t).length]},toQuantity:Z,convertsToQuantity:function(t){return 0===t.length?[]:[1===Z(t).length]},toString:H,convertsToString:function(t){return 0===t.length?[]:[1===H(t).length]},toTime:G,convertsToTime:function(t){return 0===t.length?[]:[1===G(t).length]},indexOf:function(t,e){return V(((t,e)=>t.indexOf(e)),t,e)},substring:function(t,e,r){return V(((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:function(t,e){return V(((t,e)=>t.startsWith(e)),t,e)},endsWith:function(t,e){return V(((t,e)=>t.endsWith(e)),t,e)},contains:function(t,e){return V(((t,e)=>t.includes(e)),t,e)},upper:function(t){return V((t=>t.toUpperCase()),t)},lower:function(t){return V((t=>t.toLowerCase()),t)},replace:function(t,e,r){return V(((t,e,r)=>t.replaceAll(e,r)),t,e,r)},matches:function(t,e){return V(((t,e)=>!!t.match(e)),t,e)},replaceMatches:function(t,e,r){return V(((t,e,r)=>t.replaceAll(e,r)),t,e,r)},length:function(t){return V((t=>t.length),t)},toChars:function(t){return V((t=>t?t.split(""):void 0),t)},abs:function(t){return X(Math.abs,t)},ceiling:function(t){return X(Math.ceil,t)},exp:function(t){return X(Math.exp,t)},floor:function(t){return X(Math.floor,t)},ln:function(t){return X(Math.log,t)},log:function(t,e){return X(((t,e)=>Math.log(t)/Math.log(e)),t,e)},power:function(t,e){return X(Math.pow,t,e)},round:function(t){return X(Math.round,t)},sqrt:function(t){return X(Math.sqrt,t)},truncate:function(t){return X((t=>0|t),t)},children:J,descendants:K,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 r=e.name;return t.map((t=>c(t,r)))},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[r,n]=e.split("/");return{resourceType:r,id:n}})).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 r=e.eval(void 0);if(!r.startsWith("http://hl7.org/fhir/StructureDefinition/"))throw new Error("Expected a StructureDefinition URL");const n=r.replace("http://hl7.org/fhir/StructureDefinition/","");return t.map((t=>{var e;return(null===(e=t)||void 0===e?void 0:e.resourceType)===n}))}});function et(t){return new it(t).tokenize()}const rt=["year","years","month","months","week","weeks","day","days","hour","hours","minute","minutes","second","seconds","millisecond","milliseconds"],nt=["!=","!~","<=",">=","{}"];class it{constructor(t){this.str=t,this.pos=0}tokenize(){const t=[];for(;this.pos<this.str.length;){const e=this.consumeToken();e&&t.push(e)}return t}peekToken(){const t=this.pos,e=this.consumeToken();return this.pos=t,e}consumeToken(){this.consumeWhitespace();const t=this.curr();if(!t)return;const e=this.peek();return"/"===t&&"*"===e?this.consumeMultiLineComment():"/"===t&&"/"===e?this.consumeSingleLineComment():"'"===t?this.consumeString():"`"===t?this.consumeBacktickSymbol():"@"===t?this.consumeDateTime():t.match(/\d/)?this.consumeNumber():t.match(/\w/)||"$"===t&&e.match(/\w/)?this.consumeSymbol():this.consumeOperator()}consumeWhitespace(){return st("Whitespace",this.consumeWhile((()=>this.curr().match(/\s/))))}consumeMultiLineComment(){const t=this.pos;return this.consumeWhile((()=>"*"!==this.curr()||"/"!==this.peek())),this.pos+=2,st("Comment",this.str.substring(t,this.pos))}consumeSingleLineComment(){return st("Comment",this.consumeWhile((()=>"\n"!==this.curr())))}consumeString(){this.pos++;const t=st("String",this.consumeWhile((()=>"\\"===this.prev()||"'"!==this.curr())));return this.pos++,t}consumeBacktickSymbol(){this.pos++;const t=st("Symbol",this.consumeWhile((()=>"`"!==this.curr())));return this.pos++,t}consumeDateTime(){const t=this.pos;return this.pos++,this.consumeWhile((()=>this.curr().match(/[\d-]/))),"T"===this.curr()&&(this.pos++,this.consumeWhile((()=>this.curr().match(/[\d:]/))),"."===this.curr()&&this.peek().match(/\d/)&&(this.pos++,this.consumeWhile((()=>this.curr().match(/[\d]/)))),"Z"===this.curr()?this.pos++:"+"!==this.curr()&&"-"!==this.curr()||(this.pos++,this.consumeWhile((()=>this.curr().match(/[\d:]/))))),st("DateTime",this.str.substring(t+1,this.pos))}consumeNumber(){const t=this.pos;let e="Number";return this.consumeWhile((()=>this.curr().match(/\d/))),"."===this.curr()&&this.peek().match(/\d/)&&(this.pos++,this.consumeWhile((()=>this.curr().match(/\d/))))," "===this.curr()&&function(t){if(t){if("String"===t.id)return!0;if("Symbol"===t.id&&rt.includes(t.value))return!0}return!1}(this.peekToken())&&(e="Quantity",this.consumeToken()),st(e,this.str.substring(t,this.pos))}consumeSymbol(){return st("Symbol",this.consumeWhile((()=>this.curr().match(/[$\w]/))))}consumeOperator(){const t=this.curr(),e=t+this.peek();return nt.includes(e)?(this.pos+=2,st(e,e)):(this.pos++,st(t,t))}consumeWhile(t){const e=this.pos;for(;this.pos<this.str.length&&t();)this.pos++;return this.str.substring(e,this.pos)}curr(){return this.str[this.pos]}prev(){var t;return null!==(t=this.str[this.pos-1])&&void 0!==t?t:""}peek(){var t;return null!==(t=this.str[this.pos+1])&&void 0!==t?t:""}}function st(t,e){return{id:t,value:e}}class ot{constructor(t,e,r){this.tokens=t,this.prefixParselets=e,this.infixParselets=r}match(t){const e=this.look();return(null==e?void 0:e.id)===t&&(this.consume(),!0)}parse(t=100){const e=this.consume(),r=this.prefixParselets[e.id];if(!r)throw Error(`Parse error at ${e.value}. No matching prefix parselet.`);let n=r.parse(this,e);for(;t>this.getPrecedence();){const t=this.consume();n=this.infixParselets[t.id].parse(this,n,t)}return n}getPrecedence(){const t=this.look();if(!t)return 100;const e=this.infixParselets[t.id];return e?e.precedence:100}consume(){if(!this.tokens.length)throw Error("Cant consume unknown more tokens.");return this.tokens.shift()}look(){return this.tokens.length>0?this.tokens[0]:void 0}}const ut={parse(t){const e=t.parse();if(!t.match(")"))throw new Error("Parse error: expected `)`");return e}},ct={parse(t,e){if(!(e instanceof g))throw new Error("Unexpected parentheses");if(!(e.name in tt))throw new Error("Unrecognized function: "+e.name);const r=[];for(;!t.match(")");)r.push(t.parse()),t.match(",");return new C(e.name,r,tt[e.name])},precedence:0};const at=(new class{constructor(){this.prefixParselets={},this.infixParselets={}}registerInfix(t,e){return this.infixParselets[t]=e,this}registerPrefix(t,e){return this.prefixParselets[t]=e,this}prefix(t,e,r){return this.registerPrefix(t,{parse(t,n){const i=t.parse(e);return r(n,i)}})}infixLeft(t,e,r){return this.registerInfix(t,{parse(t,n,i){const s=t.parse(e);return r(n,i,s)},precedence:e})}construct(t){return new ot(et(t),this.prefixParselets,this.infixParselets)}}).registerPrefix("String",{parse:(t,e)=>new m(e.value)}).registerPrefix("DateTime",{parse:(t,e)=>new m(I(e.value))}).registerPrefix("Quantity",{parse:(t,e)=>new m(function(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}}(e.value))}).registerPrefix("Number",{parse:(t,e)=>new m(parseFloat(e.value))}).registerPrefix("Symbol",{parse:(t,e)=>"false"===e.value?new m(!1):"true"===e.value?new m(!0):new g(e.value)}).registerPrefix("{}",{parse:()=>new v}).registerPrefix("(",ut).registerInfix("(",ct).prefix("+",3,((t,e)=>new y(e,(t=>t)))).prefix("-",3,((t,e)=>new w(e,e,((t,e)=>-e)))).infixLeft(".",1,((t,e,r)=>new S(t,r))).infixLeft("/",4,((t,e,r)=>new w(t,r,((t,e)=>t/e)))).infixLeft("*",4,((t,e,r)=>new w(t,r,((t,e)=>t*e)))).infixLeft("+",5,((t,e,r)=>new w(t,r,((t,e)=>t+e)))).infixLeft("-",5,((t,e,r)=>new w(t,r,((t,e)=>t-e)))).infixLeft("|",7,((t,e,r)=>new A(t,r))).infixLeft("=",9,((t,e,r)=>new P(t,r))).infixLeft("!=",9,((t,e,r)=>new L(t,r))).infixLeft("~",9,((t,e,r)=>new W(t,r))).infixLeft("!~",9,((t,e,r)=>new E(t,r))).infixLeft("<",8,((t,e,r)=>new b(t,r,((t,e)=>t<e)))).infixLeft("<=",8,((t,e,r)=>new b(t,r,((t,e)=>t<=e)))).infixLeft(">",8,((t,e,r)=>new b(t,r,((t,e)=>t>e)))).infixLeft(">=",8,((t,e,r)=>new b(t,r,((t,e)=>t>=e)))).infixLeft("&",5,((t,e,r)=>new x(t,r))).infixLeft("Symbol",6,((t,e,r)=>{switch(e.value){case"and":return new j(t,r);case"as":return new d(t,r);case"contains":return new T(t,r);case"div":return new w(t,r,((t,e)=>t/e|0));case"in":return new k(t,r);case"is":return new D(t,r);case"mod":return new w(t,r,((t,e)=>t%e));case"or":return new O(t,r);case"xor":return new M(t,r);default:throw new Error("Cannot use "+e.value+" as infix operator")}}));function ht(t){try{return new p(t,at.construct(t).parse())}catch(e){throw new Error(`FhirPathError on "${t}": ${e}`)}}function lt(t,e){return ht(t).eval(e)}export{lt as evalFhirPath,ht as parseFhirPath,et as tokenize};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
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){var n,r;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!(!(r=t)||"object"!=typeof r||!("start"in r));case"Quantity":return u(t);default:return"object"==typeof t&&(null===(n=t)||void 0===n?void 0:n.resourceType)===e}}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=>{var e;return(null===(e=t)||void 0===e?void 0:e.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};
//# sourceMappingURL=index.min.js.map

6

package.json
{
"name": "@medplum/fhirpath",
"version": "0.4.0",
"version": "0.4.1",
"description": "Medplum FHIRPath Library",

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

"devDependencies": {
"@medplum/definitions": "0.4.0",
"@medplum/fhirtypes": "0.4.0"
"@medplum/definitions": "0.4.1",
"@medplum/fhirtypes": "0.4.1"
},

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

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