@medplum/core 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +9 -7
  2. package/dist/cjs/client.d.ts +1 -0
  3. package/dist/cjs/fhirlexer/parse.d.ts +18 -2
  4. package/dist/cjs/fhirmapper/parse.d.ts +2 -2
  5. package/dist/cjs/fhirpath/atoms.d.ts +28 -53
  6. package/dist/cjs/fhirpath/parse.d.ts +37 -0
  7. package/dist/cjs/format.d.ts +2 -1
  8. package/dist/cjs/{index.js → index.cjs} +999 -996
  9. package/dist/cjs/index.cjs.map +1 -0
  10. package/dist/cjs/index.min.cjs +1 -0
  11. package/dist/cjs/search.d.ts +2 -1
  12. package/dist/esm/{base-schema.json.js → base-schema.json.mjs} +1 -1
  13. package/dist/esm/{base-schema.json.js.map → base-schema.json.mjs.map} +1 -1
  14. package/dist/esm/{cache.js → cache.mjs} +2 -2
  15. package/dist/esm/cache.mjs.map +1 -0
  16. package/dist/esm/client.d.ts +1 -0
  17. package/dist/esm/{client.js → client.mjs} +264 -268
  18. package/dist/esm/client.mjs.map +1 -0
  19. package/dist/esm/{crypto.js → crypto.mjs} +4 -7
  20. package/dist/esm/crypto.mjs.map +1 -0
  21. package/dist/esm/{eventtarget.js → eventtarget.mjs} +2 -2
  22. package/dist/esm/eventtarget.mjs.map +1 -0
  23. package/dist/esm/fhirlexer/parse.d.ts +18 -2
  24. package/dist/esm/fhirlexer/{parse.js → parse.mjs} +35 -10
  25. package/dist/esm/fhirlexer/parse.mjs.map +1 -0
  26. package/dist/esm/fhirlexer/{tokenize.js → tokenize.mjs} +12 -12
  27. package/dist/esm/fhirlexer/tokenize.mjs.map +1 -0
  28. package/dist/esm/fhirmapper/parse.d.ts +2 -2
  29. package/dist/esm/fhirpath/atoms.d.ts +28 -53
  30. package/dist/esm/fhirpath/{atoms.js → atoms.mjs} +79 -62
  31. package/dist/esm/fhirpath/atoms.mjs.map +1 -0
  32. package/dist/esm/fhirpath/{date.js → date.mjs} +1 -1
  33. package/dist/esm/fhirpath/date.mjs.map +1 -0
  34. package/dist/esm/fhirpath/{functions.js → functions.mjs} +16 -22
  35. package/dist/esm/fhirpath/functions.mjs.map +1 -0
  36. package/dist/esm/fhirpath/parse.d.ts +37 -0
  37. package/dist/esm/fhirpath/{parse.js → parse.mjs} +38 -42
  38. package/dist/esm/fhirpath/parse.mjs.map +1 -0
  39. package/dist/esm/fhirpath/{tokenize.js → tokenize.mjs} +4 -4
  40. package/dist/esm/fhirpath/tokenize.mjs.map +1 -0
  41. package/dist/esm/fhirpath/{utils.js → utils.mjs} +6 -7
  42. package/dist/esm/fhirpath/utils.mjs.map +1 -0
  43. package/dist/esm/format.d.ts +2 -1
  44. package/dist/esm/{format.js → format.mjs} +29 -21
  45. package/dist/esm/format.mjs.map +1 -0
  46. package/dist/esm/{hl7.js → hl7.mjs} +8 -9
  47. package/dist/esm/hl7.mjs.map +1 -0
  48. package/dist/esm/index.min.mjs +1 -0
  49. package/dist/esm/{index.js → index.mjs} +17 -17
  50. package/dist/esm/index.mjs.map +1 -0
  51. package/dist/esm/{jwt.js → jwt.mjs} +1 -1
  52. package/dist/esm/jwt.mjs.map +1 -0
  53. package/dist/esm/{match.js → match.mjs} +12 -13
  54. package/dist/esm/match.mjs.map +1 -0
  55. package/dist/esm/node_modules/tslib/{tslib.es6.js → tslib.es6.mjs} +2 -12
  56. package/dist/esm/node_modules/tslib/tslib.es6.mjs.map +1 -0
  57. package/dist/esm/{outcomes.js → outcomes.mjs} +3 -5
  58. package/dist/esm/outcomes.mjs.map +1 -0
  59. package/dist/esm/{readablepromise.js → readablepromise.mjs} +2 -2
  60. package/dist/esm/readablepromise.mjs.map +1 -0
  61. package/dist/esm/search.d.ts +2 -1
  62. package/dist/esm/{search.js → search.mjs} +1 -1
  63. package/dist/esm/search.mjs.map +1 -0
  64. package/dist/esm/{searchparams.js → searchparams.mjs} +8 -9
  65. package/dist/esm/searchparams.mjs.map +1 -0
  66. package/dist/esm/{storage.js → storage.mjs} +4 -5
  67. package/dist/esm/storage.mjs.map +1 -0
  68. package/dist/esm/{types.js → types.mjs} +6 -9
  69. package/dist/esm/types.mjs.map +1 -0
  70. package/dist/esm/{utils.js → utils.mjs} +15 -26
  71. package/dist/esm/utils.mjs.map +1 -0
  72. package/package.json +5 -5
  73. package/rollup.config.mjs +6 -7
  74. package/dist/cjs/fhirmapper/atoms.d.ts +0 -67
  75. package/dist/cjs/fhirmapper/testall.d.ts +0 -1
  76. package/dist/cjs/index.js.map +0 -1
  77. package/dist/cjs/index.min.js +0 -2
  78. package/dist/cjs/index.min.js.map +0 -1
  79. package/dist/esm/cache.js.map +0 -1
  80. package/dist/esm/client.js.map +0 -1
  81. package/dist/esm/crypto.js.map +0 -1
  82. package/dist/esm/eventtarget.js.map +0 -1
  83. package/dist/esm/fhirlexer/parse.js.map +0 -1
  84. package/dist/esm/fhirlexer/tokenize.js.map +0 -1
  85. package/dist/esm/fhirmapper/atoms.d.ts +0 -67
  86. package/dist/esm/fhirmapper/testall.d.ts +0 -1
  87. package/dist/esm/fhirpath/atoms.js.map +0 -1
  88. package/dist/esm/fhirpath/date.js.map +0 -1
  89. package/dist/esm/fhirpath/functions.js.map +0 -1
  90. package/dist/esm/fhirpath/parse.js.map +0 -1
  91. package/dist/esm/fhirpath/tokenize.js.map +0 -1
  92. package/dist/esm/fhirpath/utils.js.map +0 -1
  93. package/dist/esm/format.js.map +0 -1
  94. package/dist/esm/hl7.js.map +0 -1
  95. package/dist/esm/index.js.map +0 -1
  96. package/dist/esm/index.min.js +0 -2
  97. package/dist/esm/index.min.js.map +0 -1
  98. package/dist/esm/jwt.js.map +0 -1
  99. package/dist/esm/match.js.map +0 -1
  100. package/dist/esm/node_modules/tslib/tslib.es6.js.map +0 -1
  101. package/dist/esm/outcomes.js.map +0 -1
  102. package/dist/esm/readablepromise.js.map +0 -1
  103. package/dist/esm/search.js.map +0 -1
  104. package/dist/esm/searchparams.js.map +0 -1
  105. package/dist/esm/storage.js.map +0 -1
  106. package/dist/esm/types.js.map +0 -1
  107. package/dist/esm/utils.js.map +0 -1
@@ -19,16 +19,6 @@
19
19
  PERFORMANCE OF THIS SOFTWARE.
20
20
  ***************************************************************************** */
21
21
 
22
- function __awaiter(thisArg, _arguments, P, generator) {
23
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
- step((generator = generator.apply(thisArg, _arguments || [])).next());
29
- });
30
- }
31
-
32
22
  function __classPrivateFieldGet(receiver, state, kind, f) {
33
23
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
34
24
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
@@ -132,10 +122,10 @@
132
122
  }
133
123
  builder.push(cityStateZip.join(', '));
134
124
  }
135
- if (address.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
125
+ if (address.use && (options?.all || options?.use)) {
136
126
  builder.push('[' + address.use + ']');
137
127
  }
138
- return builder.join((options === null || options === void 0 ? void 0 : options.lineSeparator) || ', ').trim();
128
+ return builder.join(options?.lineSeparator || ', ').trim();
139
129
  }
140
130
  /**
141
131
  * Formats a FHIR HumanName as a string.
@@ -145,7 +135,7 @@
145
135
  */
146
136
  function formatHumanName(name, options) {
147
137
  const builder = [];
148
- if (name.prefix && (options === null || options === void 0 ? void 0 : options.prefix) !== false) {
138
+ if (name.prefix && options?.prefix !== false) {
149
139
  builder.push(...name.prefix);
150
140
  }
151
141
  if (name.given) {
@@ -154,10 +144,10 @@
154
144
  if (name.family) {
155
145
  builder.push(name.family);
156
146
  }
157
- if (name.suffix && (options === null || options === void 0 ? void 0 : options.suffix) !== false) {
147
+ if (name.suffix && options?.suffix !== false) {
158
148
  builder.push(...name.suffix);
159
149
  }
160
- if (name.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
150
+ if (name.use && (options?.all || options?.use)) {
161
151
  builder.push('[' + name.use + ']');
162
152
  }
163
153
  return builder.join(' ').trim();
@@ -208,7 +198,7 @@
208
198
  return '';
209
199
  }
210
200
  d.setUTCHours(0, 0, 0, 0);
211
- return d.toLocaleDateString(locales, Object.assign({ timeZone: 'UTC' }, options));
201
+ return d.toLocaleDateString(locales, { timeZone: 'UTC', ...options });
212
202
  }
213
203
  /**
214
204
  * Formats a FHIR time string as a human readable string.
@@ -292,12 +282,11 @@
292
282
  * @returns The formatted timing string.
293
283
  */
294
284
  function formatTiming(timing) {
295
- var _a;
296
285
  if (!timing) {
297
286
  return '';
298
287
  }
299
288
  const builder = [];
300
- if ((_a = timing.repeat) === null || _a === void 0 ? void 0 : _a.periodUnit) {
289
+ if (timing.repeat?.periodUnit) {
301
290
  const frequency = timing.repeat.frequency || 1;
302
291
  const period = timing.repeat.period || 1;
303
292
  const periodUnit = timing.repeat.periodUnit;
@@ -337,31 +326,30 @@
337
326
  * @returns A human-readable string representation of the Range
338
327
  */
339
328
  function formatRange(range, precision, exclusive = false) {
340
- var _a, _b, _c, _d;
341
329
  if (exclusive && precision === undefined) {
342
330
  throw new Error('Precision must be specified for exclusive ranges');
343
331
  }
344
- const low = (range === null || range === void 0 ? void 0 : range.low) && Object.assign({}, range.low);
345
- const high = (range === null || range === void 0 ? void 0 : range.high) && Object.assign({}, range.high);
346
- if (!range || ((low === null || low === void 0 ? void 0 : low.value) === undefined && (high === null || high === void 0 ? void 0 : high.value) === undefined)) {
332
+ const low = range?.low && { ...range.low };
333
+ const high = range?.high && { ...range.high };
334
+ if (!range || (low?.value === undefined && high?.value === undefined)) {
347
335
  return '';
348
336
  }
349
- if (((_a = range.low) === null || _a === void 0 ? void 0 : _a.value) !== undefined && ((_b = range.high) === null || _b === void 0 ? void 0 : _b.value) === undefined) {
337
+ if (range.low?.value !== undefined && range.high?.value === undefined) {
350
338
  if (exclusive && precision !== undefined) {
351
339
  range.low.value = preciseDecrement(range.low.value, precision);
352
340
  return `> ${formatQuantity(range.low, precision)}`;
353
341
  }
354
342
  return `>= ${formatQuantity(range.low, precision)}`;
355
343
  }
356
- if (((_c = range.low) === null || _c === void 0 ? void 0 : _c.value) === undefined && ((_d = range.high) === null || _d === void 0 ? void 0 : _d.value) !== undefined) {
344
+ if (range.low?.value === undefined && range.high?.value !== undefined) {
357
345
  if (exclusive && precision !== undefined) {
358
346
  range.high.value = preciseIncrement(range.high.value, precision);
359
347
  return `< ${formatQuantity(range.high, precision)}`;
360
348
  }
361
349
  return `<= ${formatQuantity(range.high, precision)}`;
362
350
  }
363
- if ((low === null || low === void 0 ? void 0 : low.unit) === (high === null || high === void 0 ? void 0 : high.unit)) {
364
- low === null || low === void 0 ? true : delete low.unit;
351
+ if (low?.unit === high?.unit) {
352
+ delete low?.unit;
365
353
  }
366
354
  return `${formatQuantity(low, precision)} - ${formatQuantity(high, precision)}`;
367
355
  }
@@ -395,6 +383,16 @@
395
383
  }
396
384
  return result.join('').trim();
397
385
  }
386
+ function formatMoney(money) {
387
+ if (money?.value === undefined) {
388
+ return '';
389
+ }
390
+ return money.value.toLocaleString(undefined, {
391
+ style: 'currency',
392
+ currency: money.currency || 'USD',
393
+ currencyDisplay: 'narrowSymbol',
394
+ });
395
+ }
398
396
  /**
399
397
  * Formats a CodeableConcept element as a string.
400
398
  * @param codeableConcept A FHIR CodeableConcept element
@@ -418,7 +416,7 @@
418
416
  * @returns The coding as a string.
419
417
  */
420
418
  function formatCoding(coding) {
421
- return (coding === null || coding === void 0 ? void 0 : coding.display) || (coding === null || coding === void 0 ? void 0 : coding.code) || '';
419
+ return coding?.display || coding?.code || '';
422
420
  }
423
421
  /**
424
422
  * Formats a FHIR Observation resource value as a string.
@@ -432,7 +430,7 @@
432
430
  if ('component' in obs) {
433
431
  return obs.component.map((c) => formatObservationValue(c)).join(' / ');
434
432
  }
435
- if (obs === null || obs === void 0 ? void 0 : obs.valueQuantity) {
433
+ if (obs?.valueQuantity) {
436
434
  return formatQuantity(obs.valueQuantity);
437
435
  }
438
436
  if (obs.valueCodeableConcept) {
@@ -499,8 +497,7 @@
499
497
  * @returns The ID portion of a reference.
500
498
  */
501
499
  function resolveId(reference) {
502
- var _a;
503
- return (_a = reference === null || reference === void 0 ? void 0 : reference.reference) === null || _a === void 0 ? void 0 : _a.split('/')[1];
500
+ return reference?.reference?.split('/')[1];
504
501
  }
505
502
  /**
506
503
  * Returns true if the resource is a "ProfileResource".
@@ -518,7 +515,6 @@
518
515
  * @return Human friendly display string.
519
516
  */
520
517
  function getDisplayString(resource) {
521
- var _a;
522
518
  if (isProfileResource(resource)) {
523
519
  const profileName = getProfileResourceDisplayString(resource);
524
520
  if (profileName) {
@@ -532,7 +528,7 @@
532
528
  }
533
529
  }
534
530
  if (resource.resourceType === 'Observation') {
535
- if ('code' in resource && ((_a = resource.code) === null || _a === void 0 ? void 0 : _a.text)) {
531
+ if ('code' in resource && resource.code?.text) {
536
532
  return resource.code.text;
537
533
  }
538
534
  }
@@ -717,14 +713,13 @@
717
713
  * @returns The extension value if found; undefined otherwise.
718
714
  */
719
715
  function getExtensionValue(resource, ...urls) {
720
- var _a;
721
716
  // Let curr be the current resource or extension. Extensions can be nested.
722
717
  let curr = resource;
723
718
  // For each of the urls, try to find a matching nested extension.
724
719
  for (let i = 0; i < urls.length && curr; i++) {
725
- curr = (_a = curr === null || curr === void 0 ? void 0 : curr.extension) === null || _a === void 0 ? void 0 : _a.find((e) => e.url === urls[i]);
720
+ curr = curr?.extension?.find((e) => e.url === urls[i]);
726
721
  }
727
- return curr === null || curr === void 0 ? void 0 : curr.valueString;
722
+ return curr?.valueString;
728
723
  }
729
724
  /**
730
725
  * FHIR JSON stringify.
@@ -915,8 +910,7 @@
915
910
  * @returns The code if found; otherwise undefined.
916
911
  */
917
912
  function getCodeBySystem(concept, system) {
918
- var _a, _b;
919
- return (_b = (_a = concept === null || concept === void 0 ? void 0 : concept.coding) === null || _a === void 0 ? void 0 : _a.find((coding) => coding.system === system)) === null || _b === void 0 ? void 0 : _b.code;
913
+ return concept?.coding?.find((coding) => coding.system === system)?.code;
920
914
  }
921
915
  /**
922
916
  * Sets a code for a given system within a given codeable concept.
@@ -925,16 +919,15 @@
925
919
  * @param code The code value.
926
920
  */
927
921
  function setCodeBySystem(concept, system, code) {
928
- var _a, _b;
929
922
  if (!concept.coding) {
930
923
  concept.coding = [];
931
924
  }
932
- const coding = (_a = concept.coding) === null || _a === void 0 ? void 0 : _a.find((c) => c.system === system);
925
+ const coding = concept.coding?.find((c) => c.system === system);
933
926
  if (coding) {
934
927
  coding.code = code;
935
928
  }
936
929
  else {
937
- (_b = concept.coding) === null || _b === void 0 ? void 0 : _b.push({ system, code });
930
+ concept.coding?.push({ system, code });
938
931
  }
939
932
  }
940
933
  /**
@@ -945,13 +938,9 @@
945
938
  * @returns The observation interval if found; otherwise undefined.
946
939
  */
947
940
  function findObservationInterval(definition, patient, value, category) {
948
- var _a;
949
- return (_a = definition.qualifiedInterval) === null || _a === void 0 ? void 0 : _a.find((interval) => {
950
- var _a;
951
- return observationIntervalMatchesPatient(interval, patient) &&
952
- observationIntervalMatchesValue(interval, value, (_a = definition.quantitativeDetails) === null || _a === void 0 ? void 0 : _a.decimalPrecision) &&
953
- (category === undefined || interval.category === category);
954
- });
941
+ return definition.qualifiedInterval?.find((interval) => observationIntervalMatchesPatient(interval, patient) &&
942
+ observationIntervalMatchesValue(interval, value, definition.quantitativeDetails?.decimalPrecision) &&
943
+ (category === undefined || interval.category === category));
955
944
  }
956
945
  /**
957
946
  * Tries to find an observation reference range for the given patient and condition names.
@@ -961,8 +950,7 @@
961
950
  * @returns The observation interval if found; otherwise undefined.
962
951
  */
963
952
  function findObservationReferenceRange(definition, patient, names) {
964
- var _a;
965
- return (_a = definition.qualifiedInterval) === null || _a === void 0 ? void 0 : _a.find((interval) => observationIntervalMatchesPatient(interval, patient) && names.includes(interval.condition));
953
+ return definition.qualifiedInterval?.find((interval) => observationIntervalMatchesPatient(interval, patient) && names.includes(interval.condition));
966
954
  }
967
955
  /**
968
956
  * Returns true if the patient matches the observation interval.
@@ -1009,9 +997,8 @@
1009
997
  * @returns True if the value is within the range.
1010
998
  */
1011
999
  function matchesRange(value, range, precision) {
1012
- var _a, _b;
1013
- return ((((_a = range.low) === null || _a === void 0 ? void 0 : _a.value) === undefined || preciseGreaterThanOrEquals(value, range.low.value, precision)) &&
1014
- (((_b = range.high) === null || _b === void 0 ? void 0 : _b.value) === undefined || preciseLessThanOrEquals(value, range.high.value, precision)));
1000
+ return ((range.low?.value === undefined || preciseGreaterThanOrEquals(value, range.low.value, precision)) &&
1001
+ (range.high?.value === undefined || preciseLessThanOrEquals(value, range.high.value, precision)));
1015
1002
  }
1016
1003
  /**
1017
1004
  * Returns the input number rounded to the specified number of digits.
@@ -1098,10 +1085,8 @@
1098
1085
  * Encrypts a string with SHA256 encryption.
1099
1086
  * @param str
1100
1087
  */
1101
- function encryptSHA256(str) {
1102
- return __awaiter(this, void 0, void 0, function* () {
1103
- return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
1104
- });
1088
+ async function encryptSHA256(str) {
1089
+ return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
1105
1090
  }
1106
1091
 
1107
1092
  /*
@@ -1317,8 +1302,7 @@
1317
1302
  * Returns the current value associated with the given key, or null if the given key does not exist.
1318
1303
  */
1319
1304
  getItem(key) {
1320
- var _a;
1321
- return (_a = __classPrivateFieldGet(this, _MemoryStorage_data, "f").get(key)) !== null && _a !== void 0 ? _a : null;
1305
+ return __classPrivateFieldGet(this, _MemoryStorage_data, "f").get(key) ?? null;
1322
1306
  }
1323
1307
  /**
1324
1308
  * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
@@ -6319,12 +6303,11 @@
6319
6303
  * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6320
6304
  */
6321
6305
  function indexStructureDefinition(structureDefinition) {
6322
- var _a;
6323
6306
  const typeName = structureDefinition.name;
6324
6307
  if (!typeName) {
6325
6308
  return;
6326
6309
  }
6327
- const elements = (_a = structureDefinition.snapshot) === null || _a === void 0 ? void 0 : _a.element;
6310
+ const elements = structureDefinition.snapshot?.element;
6328
6311
  if (elements) {
6329
6312
  // First pass, build types
6330
6313
  elements.forEach((element) => indexType(structureDefinition, element));
@@ -6341,9 +6324,8 @@
6341
6324
  * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
6342
6325
  */
6343
6326
  function indexType(structureDefinition, elementDefinition) {
6344
- var _a, _b;
6345
6327
  const path = elementDefinition.path;
6346
- const typeCode = (_b = (_a = elementDefinition.type) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code;
6328
+ const typeCode = elementDefinition.type?.[0]?.code;
6347
6329
  if (typeCode !== undefined && typeCode !== 'Element' && typeCode !== 'BackboneElement') {
6348
6330
  return;
6349
6331
  }
@@ -6460,12 +6442,11 @@
6460
6442
  * @returns The element definition if found.
6461
6443
  */
6462
6444
  function getElementDefinition(typeName, propertyName) {
6463
- var _a;
6464
6445
  const typeSchema = globalSchema.types[typeName];
6465
6446
  if (!typeSchema) {
6466
6447
  return undefined;
6467
6448
  }
6468
- const property = (_a = typeSchema.properties[propertyName]) !== null && _a !== void 0 ? _a : typeSchema.properties[propertyName + '[x]'];
6449
+ const property = typeSchema.properties[propertyName] ?? typeSchema.properties[propertyName + '[x]'];
6469
6450
  if (!property) {
6470
6451
  return undefined;
6471
6452
  }
@@ -6486,8 +6467,8 @@
6486
6467
 
6487
6468
  // PKCE auth based on:
6488
6469
  // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
6489
- var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
6490
- const MEDPLUM_VERSION = "1.0.4-6dbdb7f6";
6470
+ var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_createPdf, _MedplumClient_storage, _MedplumClient_requestCache, _MedplumClient_cacheTime, _MedplumClient_baseUrl, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_clientId, _MedplumClient_clientSecret, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_getCacheEntry, _MedplumClient_setCacheEntry, _MedplumClient_request, _MedplumClient_addFetchOptionsDefaults, _MedplumClient_setRequestContentType, _MedplumClient_setRequestBody, _MedplumClient_handleUnauthenticated, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
6471
+ const MEDPLUM_VERSION = "1.0.6-5860113c";
6491
6472
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
6492
6473
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
6493
6474
  const DEFAULT_CACHE_TIME = 60000; // 60 seconds
@@ -6548,7 +6529,6 @@
6548
6529
  */
6549
6530
  class MedplumClient extends EventTarget {
6550
6531
  constructor(options) {
6551
- var _a, _b;
6552
6532
  super();
6553
6533
  _MedplumClient_instances.add(this);
6554
6534
  _MedplumClient_fetch.set(this, void 0);
@@ -6557,33 +6537,34 @@
6557
6537
  _MedplumClient_requestCache.set(this, void 0);
6558
6538
  _MedplumClient_cacheTime.set(this, void 0);
6559
6539
  _MedplumClient_baseUrl.set(this, void 0);
6560
- _MedplumClient_clientId.set(this, void 0);
6561
6540
  _MedplumClient_authorizeUrl.set(this, void 0);
6562
6541
  _MedplumClient_tokenUrl.set(this, void 0);
6563
6542
  _MedplumClient_logoutUrl.set(this, void 0);
6564
6543
  _MedplumClient_onUnauthenticated.set(this, void 0);
6544
+ _MedplumClient_clientId.set(this, void 0);
6545
+ _MedplumClient_clientSecret.set(this, void 0);
6565
6546
  _MedplumClient_accessToken.set(this, void 0);
6566
6547
  _MedplumClient_refreshToken.set(this, void 0);
6567
6548
  _MedplumClient_refreshPromise.set(this, void 0);
6568
6549
  _MedplumClient_profilePromise.set(this, void 0);
6569
6550
  _MedplumClient_profile.set(this, void 0);
6570
6551
  _MedplumClient_config.set(this, void 0);
6571
- if (options === null || options === void 0 ? void 0 : options.baseUrl) {
6552
+ if (options?.baseUrl) {
6572
6553
  if (!options.baseUrl.startsWith('http')) {
6573
6554
  throw new Error('Base URL must start with http or https');
6574
6555
  }
6575
6556
  }
6576
- __classPrivateFieldSet(this, _MedplumClient_fetch, (options === null || options === void 0 ? void 0 : options.fetch) || window.fetch.bind(window), "f");
6577
- __classPrivateFieldSet(this, _MedplumClient_createPdf, options === null || options === void 0 ? void 0 : options.createPdf, "f");
6557
+ __classPrivateFieldSet(this, _MedplumClient_fetch, options?.fetch || window.fetch.bind(window), "f");
6558
+ __classPrivateFieldSet(this, _MedplumClient_createPdf, options?.createPdf, "f");
6578
6559
  __classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
6579
- __classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache((_a = options === null || options === void 0 ? void 0 : options.resourceCacheSize) !== null && _a !== void 0 ? _a : DEFAULT_RESOURCE_CACHE_SIZE), "f");
6580
- __classPrivateFieldSet(this, _MedplumClient_cacheTime, (_b = options === null || options === void 0 ? void 0 : options.cacheTime) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TIME, "f");
6581
- __classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
6582
- __classPrivateFieldSet(this, _MedplumClient_clientId, (options === null || options === void 0 ? void 0 : options.clientId) || '', "f");
6583
- __classPrivateFieldSet(this, _MedplumClient_authorizeUrl, (options === null || options === void 0 ? void 0 : options.authorizeUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
6584
- __classPrivateFieldSet(this, _MedplumClient_tokenUrl, (options === null || options === void 0 ? void 0 : options.tokenUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
6585
- __classPrivateFieldSet(this, _MedplumClient_logoutUrl, (options === null || options === void 0 ? void 0 : options.logoutUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/logout', "f");
6586
- __classPrivateFieldSet(this, _MedplumClient_onUnauthenticated, options === null || options === void 0 ? void 0 : options.onUnauthenticated, "f");
6560
+ __classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache(options?.resourceCacheSize ?? DEFAULT_RESOURCE_CACHE_SIZE), "f");
6561
+ __classPrivateFieldSet(this, _MedplumClient_cacheTime, options?.cacheTime ?? DEFAULT_CACHE_TIME, "f");
6562
+ __classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options?.baseUrl) || DEFAULT_BASE_URL, "f");
6563
+ __classPrivateFieldSet(this, _MedplumClient_clientId, options?.clientId || '', "f");
6564
+ __classPrivateFieldSet(this, _MedplumClient_authorizeUrl, options?.authorizeUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
6565
+ __classPrivateFieldSet(this, _MedplumClient_tokenUrl, options?.tokenUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
6566
+ __classPrivateFieldSet(this, _MedplumClient_logoutUrl, options?.logoutUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/logout', "f");
6567
+ __classPrivateFieldSet(this, _MedplumClient_onUnauthenticated, options?.onUnauthenticated, "f");
6587
6568
  const activeLogin = this.getActiveLogin();
6588
6569
  if (activeLogin) {
6589
6570
  __classPrivateFieldSet(this, _MedplumClient_accessToken, activeLogin.accessToken, "f");
@@ -6758,10 +6739,12 @@
6758
6739
  * @param newUserRequest Register request including email and password.
6759
6740
  * @returns Promise to the authentication response.
6760
6741
  */
6761
- startNewUser(newUserRequest) {
6762
- return __awaiter(this, void 0, void 0, function* () {
6763
- yield this.startPkce();
6764
- return this.post('auth/newuser', Object.assign(Object.assign({}, newUserRequest), { codeChallengeMethod: 'S256', codeChallenge: sessionStorage.getItem('codeChallenge') }));
6742
+ async startNewUser(newUserRequest) {
6743
+ await this.startPkce();
6744
+ return this.post('auth/newuser', {
6745
+ ...newUserRequest,
6746
+ codeChallengeMethod: 'S256',
6747
+ codeChallenge: sessionStorage.getItem('codeChallenge'),
6765
6748
  });
6766
6749
  }
6767
6750
  /**
@@ -6772,10 +6755,8 @@
6772
6755
  * @param newProjectRequest Register request including email and password.
6773
6756
  * @returns Promise to the authentication response.
6774
6757
  */
6775
- startNewProject(newProjectRequest) {
6776
- return __awaiter(this, void 0, void 0, function* () {
6777
- return this.post('auth/newproject', newProjectRequest);
6778
- });
6758
+ async startNewProject(newProjectRequest) {
6759
+ return this.post('auth/newproject', newProjectRequest);
6779
6760
  }
6780
6761
  /**
6781
6762
  * Initiates a new patient flow.
@@ -6785,10 +6766,8 @@
6785
6766
  * @param newPatientRequest Register request including email and password.
6786
6767
  * @returns Promise to the authentication response.
6787
6768
  */
6788
- startNewPatient(newPatientRequest) {
6789
- return __awaiter(this, void 0, void 0, function* () {
6790
- return this.post('auth/newpatient', newPatientRequest);
6791
- });
6769
+ async startNewPatient(newPatientRequest) {
6770
+ return this.post('auth/newpatient', newPatientRequest);
6792
6771
  }
6793
6772
  /**
6794
6773
  * Initiates a user login flow.
@@ -6796,12 +6775,14 @@
6796
6775
  * @param loginRequest Login request including email and password.
6797
6776
  * @returns Promise to the authentication response.
6798
6777
  */
6799
- startLogin(loginRequest) {
6800
- var _a;
6801
- return __awaiter(this, void 0, void 0, function* () {
6802
- const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
6803
- return this.post('auth/login', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: loginRequest.scope, codeChallengeMethod,
6804
- codeChallenge }));
6778
+ async startLogin(loginRequest) {
6779
+ const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
6780
+ return this.post('auth/login', {
6781
+ ...loginRequest,
6782
+ clientId: loginRequest.clientId ?? __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
6783
+ scope: loginRequest.scope,
6784
+ codeChallengeMethod,
6785
+ codeChallenge,
6805
6786
  });
6806
6787
  }
6807
6788
  /**
@@ -6812,12 +6793,14 @@
6812
6793
  * @param loginRequest Login request including Google credential response.
6813
6794
  * @returns Promise to the authentication response.
6814
6795
  */
6815
- startGoogleLogin(loginRequest) {
6816
- var _a;
6817
- return __awaiter(this, void 0, void 0, function* () {
6818
- const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
6819
- return this.post('auth/google', Object.assign(Object.assign({}, loginRequest), { clientId: (_a = loginRequest.clientId) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: loginRequest.scope, codeChallengeMethod,
6820
- codeChallenge }));
6796
+ async startGoogleLogin(loginRequest) {
6797
+ const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
6798
+ return this.post('auth/google', {
6799
+ ...loginRequest,
6800
+ clientId: loginRequest.clientId ?? __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
6801
+ scope: loginRequest.scope,
6802
+ codeChallengeMethod,
6803
+ codeChallenge,
6821
6804
  });
6822
6805
  }
6823
6806
  getCodeChallenge(loginRequest) {
@@ -6850,18 +6833,16 @@
6850
6833
  * This may result in navigating away to the sign in page.
6851
6834
  * @category Authentication
6852
6835
  */
6853
- signInWithRedirect() {
6854
- return __awaiter(this, void 0, void 0, function* () {
6855
- const urlParams = new URLSearchParams(window.location.search);
6856
- const code = urlParams.get('code');
6857
- if (!code) {
6858
- yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
6859
- return undefined;
6860
- }
6861
- else {
6862
- return this.processCode(code);
6863
- }
6864
- });
6836
+ async signInWithRedirect() {
6837
+ const urlParams = new URLSearchParams(window.location.search);
6838
+ const code = urlParams.get('code');
6839
+ if (!code) {
6840
+ await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
6841
+ return undefined;
6842
+ }
6843
+ else {
6844
+ return this.processCode(code);
6845
+ }
6865
6846
  }
6866
6847
  /**
6867
6848
  * Tries to sign out the user.
@@ -6977,7 +6958,7 @@
6977
6958
  if (cached) {
6978
6959
  return cached.value;
6979
6960
  }
6980
- const promise = new ReadablePromise(this.search(resourceType, url.searchParams, options).then((b) => { var _a, _b; return (_b = (_a = b.entry) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.resource; }));
6961
+ const promise = new ReadablePromise(this.search(resourceType, url.searchParams, options).then((b) => b.entry?.[0]?.resource));
6981
6962
  __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
6982
6963
  return promise;
6983
6964
  }
@@ -7010,7 +6991,7 @@
7010
6991
  if (cached) {
7011
6992
  return cached.value;
7012
6993
  }
7013
- const promise = new ReadablePromise(this.search(resourceType, query, options).then((b) => { var _a, _b; return (_b = (_a = b.entry) === null || _a === void 0 ? void 0 : _a.map((e) => e.resource)) !== null && _b !== void 0 ? _b : []; }));
6994
+ const promise = new ReadablePromise(this.search(resourceType, query, options).then((b) => b.entry?.map((e) => e.resource) ?? []));
7014
6995
  __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
7015
6996
  return promise;
7016
6997
  }
@@ -7038,8 +7019,7 @@
7038
7019
  * @returns The resource if it is available in the cache; undefined otherwise.
7039
7020
  */
7040
7021
  getCached(resourceType, id) {
7041
- var _a;
7042
- const cached = (_a = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString())) === null || _a === void 0 ? void 0 : _a.value;
7022
+ const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString())?.value;
7043
7023
  return cached && cached.isOk() ? cached.read() : undefined;
7044
7024
  }
7045
7025
  /**
@@ -7102,7 +7082,7 @@
7102
7082
  * @returns The resource if available; undefined otherwise.
7103
7083
  */
7104
7084
  readReference(reference, options = {}) {
7105
- const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
7085
+ const refString = reference?.reference;
7106
7086
  if (!refString) {
7107
7087
  return new ReadablePromise(Promise.reject(new Error('Missing reference')));
7108
7088
  }
@@ -7130,12 +7110,11 @@
7130
7110
  * @param resourceType The FHIR resource type.
7131
7111
  * @returns Promise to a schema with the requested resource type.
7132
7112
  */
7133
- requestSchema(resourceType) {
7134
- return __awaiter(this, void 0, void 0, function* () {
7135
- if (resourceType in globalSchema.types) {
7136
- return globalSchema;
7137
- }
7138
- const query = `{
7113
+ async requestSchema(resourceType) {
7114
+ if (resourceType in globalSchema.types) {
7115
+ return globalSchema;
7116
+ }
7117
+ const query = `{
7139
7118
  StructureDefinitionList(name: "${resourceType}") {
7140
7119
  name,
7141
7120
  description,
@@ -7164,15 +7143,14 @@
7164
7143
  target
7165
7144
  }
7166
7145
  }`.replace(/\s+/g, ' ');
7167
- const response = (yield this.graphql(query));
7168
- for (const structureDefinition of response.data.StructureDefinitionList) {
7169
- indexStructureDefinition(structureDefinition);
7170
- }
7171
- for (const searchParameter of response.data.SearchParameterList) {
7172
- indexSearchParameter(searchParameter);
7173
- }
7174
- return globalSchema;
7175
- });
7146
+ const response = (await this.graphql(query));
7147
+ for (const structureDefinition of response.data.StructureDefinitionList) {
7148
+ indexStructureDefinition(structureDefinition);
7149
+ }
7150
+ for (const searchParameter of response.data.SearchParameterList) {
7151
+ indexSearchParameter(searchParameter);
7152
+ }
7153
+ return globalSchema;
7176
7154
  }
7177
7155
  /**
7178
7156
  * Reads resource history by resource type and ID.
@@ -7310,11 +7288,8 @@
7310
7288
  * @param query The search query for an equivalent resource (should not include resource type or "?").
7311
7289
  * @returns The result of the create operation.
7312
7290
  */
7313
- createResourceIfNoneExist(resource, query) {
7314
- var _a;
7315
- return __awaiter(this, void 0, void 0, function* () {
7316
- return ((_a = (yield this.searchOne(resource.resourceType, query))) !== null && _a !== void 0 ? _a : this.createResource(resource));
7317
- });
7291
+ async createResourceIfNoneExist(resource, query) {
7292
+ return ((await this.searchOne(resource.resourceType, query)) ?? this.createResource(resource));
7318
7293
  }
7319
7294
  /**
7320
7295
  * Creates a FHIR `Binary` resource with the provided data content.
@@ -7401,14 +7376,12 @@
7401
7376
  * @param docDefinition The PDF document definition.
7402
7377
  * @returns The result of the create operation.
7403
7378
  */
7404
- createPdf(docDefinition, filename, tableLayouts, fonts) {
7405
- return __awaiter(this, void 0, void 0, function* () {
7406
- if (!__classPrivateFieldGet(this, _MedplumClient_createPdf, "f")) {
7407
- throw new Error('PDF creation not enabled');
7408
- }
7409
- const blob = yield __classPrivateFieldGet(this, _MedplumClient_createPdf, "f").call(this, docDefinition, tableLayouts, fonts);
7410
- return this.createBinary(blob, filename, 'application/pdf');
7411
- });
7379
+ async createPdf(docDefinition, filename, tableLayouts, fonts) {
7380
+ if (!__classPrivateFieldGet(this, _MedplumClient_createPdf, "f")) {
7381
+ throw new Error('PDF creation not enabled');
7382
+ }
7383
+ const blob = await __classPrivateFieldGet(this, _MedplumClient_createPdf, "f").call(this, docDefinition, tableLayouts, fonts);
7384
+ return this.createBinary(blob, filename, 'application/pdf');
7412
7385
  }
7413
7386
  /**
7414
7387
  * Creates a FHIR `Communication` resource with the provided data content.
@@ -7470,20 +7443,18 @@
7470
7443
  * @param resource The FHIR resource to update.
7471
7444
  * @returns The result of the update operation.
7472
7445
  */
7473
- updateResource(resource) {
7474
- return __awaiter(this, void 0, void 0, function* () {
7475
- if (!resource.resourceType) {
7476
- throw new Error('Missing resourceType');
7477
- }
7478
- if (!resource.id) {
7479
- throw new Error('Missing id');
7480
- }
7481
- this.invalidateSearches(resource.resourceType);
7482
- const result = yield this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
7483
- // On 304 not modified, result will be undefined
7484
- // Return the user input instead
7485
- return result !== null && result !== void 0 ? result : resource;
7486
- });
7446
+ async updateResource(resource) {
7447
+ if (!resource.resourceType) {
7448
+ throw new Error('Missing resourceType');
7449
+ }
7450
+ if (!resource.id) {
7451
+ throw new Error('Missing id');
7452
+ }
7453
+ this.invalidateSearches(resource.resourceType);
7454
+ const result = await this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
7455
+ // On 304 not modified, result will be undefined
7456
+ // Return the user input instead
7457
+ return result ?? resource;
7487
7458
  }
7488
7459
  /**
7489
7460
  * Updates a FHIR resource using JSONPatch operations.
@@ -7718,18 +7689,16 @@
7718
7689
  /**
7719
7690
  * @category Authentication
7720
7691
  */
7721
- setActiveLogin(login) {
7722
- return __awaiter(this, void 0, void 0, function* () {
7723
- __classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
7724
- __classPrivateFieldSet(this, _MedplumClient_refreshToken, login.refreshToken, "f");
7725
- __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
7726
- __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
7727
- __classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('activeLogin', login);
7728
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addLogin).call(this, login);
7729
- __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").clear();
7730
- __classPrivateFieldSet(this, _MedplumClient_refreshPromise, undefined, "f");
7731
- yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
7732
- });
7692
+ async setActiveLogin(login) {
7693
+ __classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
7694
+ __classPrivateFieldSet(this, _MedplumClient_refreshToken, login.refreshToken, "f");
7695
+ __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
7696
+ __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
7697
+ __classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('activeLogin', login);
7698
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addLogin).call(this, login);
7699
+ __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").clear();
7700
+ __classPrivateFieldSet(this, _MedplumClient_refreshPromise, undefined, "f");
7701
+ await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
7733
7702
  }
7734
7703
  /**
7735
7704
  * @category Authentication
@@ -7750,8 +7719,7 @@
7750
7719
  * @category Authentication
7751
7720
  */
7752
7721
  getLogins() {
7753
- var _a;
7754
- return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
7722
+ return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins') ?? [];
7755
7723
  }
7756
7724
  /**
7757
7725
  * @category Authentication
@@ -7768,13 +7736,11 @@
7768
7736
  /**
7769
7737
  * @category User Profile
7770
7738
  */
7771
- getProfileAsync() {
7772
- return __awaiter(this, void 0, void 0, function* () {
7773
- if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
7774
- yield __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7775
- }
7776
- return this.getProfile();
7777
- });
7739
+ async getProfileAsync() {
7740
+ if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
7741
+ await __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7742
+ }
7743
+ return this.getProfile();
7778
7744
  }
7779
7745
  /**
7780
7746
  * @category User Profile
@@ -7789,30 +7755,26 @@
7789
7755
  * @param url The URL to request.
7790
7756
  * @returns Promise to the response body as a blob.
7791
7757
  */
7792
- download(url, options = {}) {
7793
- return __awaiter(this, void 0, void 0, function* () {
7794
- if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7795
- yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7796
- }
7797
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
7798
- const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url.toString(), options);
7799
- return response.blob();
7800
- });
7758
+ async download(url, options = {}) {
7759
+ if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7760
+ await __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7761
+ }
7762
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
7763
+ const response = await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url.toString(), options);
7764
+ return response.blob();
7801
7765
  }
7802
7766
  /**
7803
7767
  * Starts a new PKCE flow.
7804
7768
  * These PKCE values are stateful, and must survive redirects and page refreshes.
7805
7769
  */
7806
- startPkce() {
7807
- return __awaiter(this, void 0, void 0, function* () {
7808
- const pkceState = getRandomString();
7809
- sessionStorage.setItem('pkceState', pkceState);
7810
- const codeVerifier = getRandomString();
7811
- sessionStorage.setItem('codeVerifier', codeVerifier);
7812
- const arrayHash = yield encryptSHA256(codeVerifier);
7813
- const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
7814
- sessionStorage.setItem('codeChallenge', codeChallenge);
7815
- });
7770
+ async startPkce() {
7771
+ const pkceState = getRandomString();
7772
+ sessionStorage.setItem('pkceState', pkceState);
7773
+ const codeVerifier = getRandomString();
7774
+ sessionStorage.setItem('codeVerifier', codeVerifier);
7775
+ const arrayHash = await encryptSHA256(codeVerifier);
7776
+ const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
7777
+ sessionStorage.setItem('codeChallenge', codeChallenge);
7816
7778
  }
7817
7779
  /**
7818
7780
  * Processes an OAuth authorization code.
@@ -7839,37 +7801,35 @@
7839
7801
  * @param clientSecret The client secret.
7840
7802
  * @returns Promise that resolves to the client profile.
7841
7803
  */
7842
- startClientLogin(clientId, clientSecret) {
7843
- return __awaiter(this, void 0, void 0, function* () {
7844
- const formBody = new URLSearchParams();
7845
- formBody.set('grant_type', 'client_credentials');
7846
- formBody.set('client_id', clientId);
7847
- formBody.set('client_secret', clientSecret);
7848
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
7849
- });
7804
+ async startClientLogin(clientId, clientSecret) {
7805
+ __classPrivateFieldSet(this, _MedplumClient_clientId, clientId, "f");
7806
+ __classPrivateFieldSet(this, _MedplumClient_clientSecret, clientSecret, "f");
7807
+ const formBody = new URLSearchParams();
7808
+ formBody.set('grant_type', 'client_credentials');
7809
+ formBody.set('client_id', clientId);
7810
+ formBody.set('client_secret', clientSecret);
7811
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
7850
7812
  }
7851
7813
  }
7852
- _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_cacheTime = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = new WeakMap(), _MedplumClient_accessToken = new WeakMap(), _MedplumClient_refreshToken = new WeakMap(), _MedplumClient_refreshPromise = new WeakMap(), _MedplumClient_profilePromise = new WeakMap(), _MedplumClient_profile = new WeakMap(), _MedplumClient_config = new WeakMap(), _MedplumClient_instances = new WeakSet(), _MedplumClient_addLogin = function _MedplumClient_addLogin(newLogin) {
7853
- const logins = this.getLogins().filter((login) => { var _a, _b; return ((_a = login.profile) === null || _a === void 0 ? void 0 : _a.reference) !== ((_b = newLogin.profile) === null || _b === void 0 ? void 0 : _b.reference); });
7814
+ _MedplumClient_fetch = new WeakMap(), _MedplumClient_createPdf = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_requestCache = new WeakMap(), _MedplumClient_cacheTime = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_clientSecret = new WeakMap(), _MedplumClient_accessToken = new WeakMap(), _MedplumClient_refreshToken = new WeakMap(), _MedplumClient_refreshPromise = new WeakMap(), _MedplumClient_profilePromise = new WeakMap(), _MedplumClient_profile = new WeakMap(), _MedplumClient_config = new WeakMap(), _MedplumClient_instances = new WeakSet(), _MedplumClient_addLogin = function _MedplumClient_addLogin(newLogin) {
7815
+ const logins = this.getLogins().filter((login) => login.profile?.reference !== newLogin.profile?.reference);
7854
7816
  logins.push(newLogin);
7855
7817
  __classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('logins', logins);
7856
- }, _MedplumClient_refreshProfile = function _MedplumClient_refreshProfile() {
7857
- return __awaiter(this, void 0, void 0, function* () {
7858
- __classPrivateFieldSet(this, _MedplumClient_profilePromise, new Promise((resolve, reject) => {
7859
- this.get('auth/me')
7860
- .then((result) => {
7861
- __classPrivateFieldSet(this, _MedplumClient_profilePromise, undefined, "f");
7862
- __classPrivateFieldSet(this, _MedplumClient_profile, result.profile, "f");
7863
- __classPrivateFieldSet(this, _MedplumClient_config, result.config, "f");
7864
- this.dispatchEvent({ type: 'change' });
7865
- resolve(__classPrivateFieldGet(this, _MedplumClient_profile, "f"));
7866
- })
7867
- .catch(reject);
7868
- }), "f");
7869
- return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7870
- });
7818
+ }, _MedplumClient_refreshProfile = async function _MedplumClient_refreshProfile() {
7819
+ __classPrivateFieldSet(this, _MedplumClient_profilePromise, new Promise((resolve, reject) => {
7820
+ this.get('auth/me')
7821
+ .then((result) => {
7822
+ __classPrivateFieldSet(this, _MedplumClient_profilePromise, undefined, "f");
7823
+ __classPrivateFieldSet(this, _MedplumClient_profile, result.profile, "f");
7824
+ __classPrivateFieldSet(this, _MedplumClient_config, result.config, "f");
7825
+ this.dispatchEvent({ type: 'change' });
7826
+ resolve(__classPrivateFieldGet(this, _MedplumClient_profile, "f"));
7827
+ })
7828
+ .catch(reject);
7829
+ }), "f");
7830
+ return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7871
7831
  }, _MedplumClient_getCacheEntry = function _MedplumClient_getCacheEntry(key, options) {
7872
- if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") <= 0 || (options === null || options === void 0 ? void 0 : options.cache) === 'no-cache' || (options === null || options === void 0 ? void 0 : options.cache) === 'reload') {
7832
+ if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") <= 0 || options?.cache === 'no-cache' || options?.cache === 'reload') {
7873
7833
  return undefined;
7874
7834
  }
7875
7835
  const entry = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(key);
@@ -7881,31 +7841,37 @@
7881
7841
  if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
7882
7842
  __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(key, { requestTime: Date.now(), value });
7883
7843
  }
7884
- }, _MedplumClient_request = function _MedplumClient_request(method, url, options = {}) {
7885
- return __awaiter(this, void 0, void 0, function* () {
7886
- if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7887
- yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7888
- }
7889
- if (!url.startsWith('http')) {
7890
- url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
7891
- }
7892
- options.method = method;
7893
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
7894
- const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
7895
- if (response.status === 401) {
7896
- // Refresh and try again
7897
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
7898
- }
7899
- if (response.status === 204 || response.status === 304) {
7900
- // No content or change
7901
- return undefined;
7902
- }
7903
- const obj = yield response.json();
7904
- if (response.status >= 400) {
7905
- throw obj;
7906
- }
7907
- return obj;
7908
- });
7844
+ }, _MedplumClient_request =
7845
+ /**
7846
+ * Makes an HTTP request.
7847
+ * @param {string} method
7848
+ * @param {string} url
7849
+ * @param {string=} contentType
7850
+ * @param {Object=} body
7851
+ */
7852
+ async function _MedplumClient_request(method, url, options = {}) {
7853
+ if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7854
+ await __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7855
+ }
7856
+ if (!url.startsWith('http')) {
7857
+ url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
7858
+ }
7859
+ options.method = method;
7860
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
7861
+ const response = await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
7862
+ if (response.status === 401) {
7863
+ // Refresh and try again
7864
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
7865
+ }
7866
+ if (response.status === 204 || response.status === 304) {
7867
+ // No content or change
7868
+ return undefined;
7869
+ }
7870
+ const obj = await response.json();
7871
+ if (response.status >= 400) {
7872
+ throw obj;
7873
+ }
7874
+ return obj;
7909
7875
  }, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
7910
7876
  if (!options.headers) {
7911
7877
  options.headers = {};
@@ -7941,82 +7907,93 @@
7941
7907
  options.body = JSON.stringify(data);
7942
7908
  }
7943
7909
  }, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, options) {
7944
- return __awaiter(this, void 0, void 0, function* () {
7945
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)
7946
- .then(() => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, options))
7947
- .catch((error) => {
7948
- this.clear();
7949
- if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
7950
- __classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f").call(this);
7951
- }
7952
- return Promise.reject(error);
7953
- });
7954
- });
7955
- }, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
7956
- return __awaiter(this, void 0, void 0, function* () {
7957
- yield this.startPkce();
7958
- const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
7959
- url.searchParams.set('response_type', 'code');
7960
- url.searchParams.set('state', sessionStorage.getItem('pkceState'));
7961
- url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
7962
- url.searchParams.set('redirect_uri', getBaseUrl());
7963
- url.searchParams.set('code_challenge_method', 'S256');
7964
- url.searchParams.set('code_challenge', sessionStorage.getItem('codeChallenge'));
7965
- window.location.assign(url.toString());
7966
- });
7910
+ if (__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)) {
7911
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, options);
7912
+ }
7913
+ this.clear();
7914
+ if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
7915
+ __classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f").call(this);
7916
+ }
7917
+ return Promise.reject(new Error('Unauthenticated'));
7918
+ }, _MedplumClient_requestAuthorization =
7919
+ /**
7920
+ * Redirects the user to the login screen for authorization.
7921
+ * Clears all auth state including local storage and session storage.
7922
+ * See: https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint
7923
+ */
7924
+ async function _MedplumClient_requestAuthorization() {
7925
+ await this.startPkce();
7926
+ const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
7927
+ url.searchParams.set('response_type', 'code');
7928
+ url.searchParams.set('state', sessionStorage.getItem('pkceState'));
7929
+ url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
7930
+ url.searchParams.set('redirect_uri', getBaseUrl());
7931
+ url.searchParams.set('code_challenge_method', 'S256');
7932
+ url.searchParams.set('code_challenge', sessionStorage.getItem('codeChallenge'));
7933
+ window.location.assign(url.toString());
7967
7934
  }, _MedplumClient_refresh = function _MedplumClient_refresh() {
7968
- return __awaiter(this, void 0, void 0, function* () {
7969
- if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7970
- return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7971
- }
7972
- if (!__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
7973
- this.clear();
7974
- throw new Error('Invalid refresh token');
7975
- }
7935
+ if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7936
+ return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7937
+ }
7938
+ if (__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
7976
7939
  const formBody = new URLSearchParams();
7977
7940
  formBody.set('grant_type', 'refresh_token');
7978
7941
  formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
7979
7942
  formBody.set('refresh_token', __classPrivateFieldGet(this, _MedplumClient_refreshToken, "f"));
7980
7943
  __classPrivateFieldSet(this, _MedplumClient_refreshPromise, __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody), "f");
7981
- yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7982
- });
7983
- }, _MedplumClient_fetchTokens = function _MedplumClient_fetchTokens(formBody) {
7984
- return __awaiter(this, void 0, void 0, function* () {
7985
- return __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
7986
- method: 'POST',
7987
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
7988
- body: formBody,
7989
- credentials: 'include',
7990
- })
7991
- .then((response) => {
7992
- if (!response.ok) {
7993
- throw new Error('Failed to fetch tokens');
7994
- }
7995
- return response.json();
7996
- })
7997
- .then((tokens) => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_verifyTokens).call(this, tokens))
7998
- .then(() => this.getProfile());
7999
- });
8000
- }, _MedplumClient_verifyTokens = function _MedplumClient_verifyTokens(tokens) {
8001
- return __awaiter(this, void 0, void 0, function* () {
8002
- const token = tokens.access_token;
8003
- // Verify token has not expired
8004
- const tokenPayload = parseJWTPayload(token);
8005
- if (Date.now() >= tokenPayload.exp * 1000) {
8006
- this.clear();
8007
- throw new Error('Token expired');
8008
- }
8009
- // Verify app_client_id
8010
- if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
8011
- this.clear();
8012
- throw new Error('Token was not issued for this audience');
8013
- }
8014
- yield this.setActiveLogin({
8015
- accessToken: token,
8016
- refreshToken: tokens.refresh_token,
8017
- project: tokens.project,
8018
- profile: tokens.profile,
8019
- });
7944
+ return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7945
+ }
7946
+ if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && __classPrivateFieldGet(this, _MedplumClient_clientSecret, "f")) {
7947
+ __classPrivateFieldSet(this, _MedplumClient_refreshPromise, this.startClientLogin(__classPrivateFieldGet(this, _MedplumClient_clientId, "f"), __classPrivateFieldGet(this, _MedplumClient_clientSecret, "f")), "f");
7948
+ return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7949
+ }
7950
+ return undefined;
7951
+ }, _MedplumClient_fetchTokens =
7952
+ /**
7953
+ * Makes a POST request to the tokens endpoint.
7954
+ * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
7955
+ * @param formBody Token parameters in URL encoded format.
7956
+ */
7957
+ async function _MedplumClient_fetchTokens(formBody) {
7958
+ return __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
7959
+ method: 'POST',
7960
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
7961
+ body: formBody,
7962
+ credentials: 'include',
7963
+ })
7964
+ .then((response) => {
7965
+ if (!response.ok) {
7966
+ throw new Error('Failed to fetch tokens');
7967
+ }
7968
+ return response.json();
7969
+ })
7970
+ .then((tokens) => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_verifyTokens).call(this, tokens))
7971
+ .then(() => this.getProfile());
7972
+ }, _MedplumClient_verifyTokens =
7973
+ /**
7974
+ * Verifies the tokens received from the auth server.
7975
+ * Validates the JWT against the JWKS.
7976
+ * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
7977
+ * @param tokens
7978
+ */
7979
+ async function _MedplumClient_verifyTokens(tokens) {
7980
+ const token = tokens.access_token;
7981
+ // Verify token has not expired
7982
+ const tokenPayload = parseJWTPayload(token);
7983
+ if (Date.now() >= tokenPayload.exp * 1000) {
7984
+ this.clear();
7985
+ throw new Error('Token expired');
7986
+ }
7987
+ // Verify app_client_id
7988
+ if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
7989
+ this.clear();
7990
+ throw new Error('Token was not issued for this audience');
7991
+ }
7992
+ await this.setActiveLogin({
7993
+ accessToken: token,
7994
+ refreshToken: tokens.refresh_token,
7995
+ project: tokens.project,
7996
+ profile: tokens.profile,
8020
7997
  });
8021
7998
  }, _MedplumClient_setupStorageListener = function _MedplumClient_setupStorageListener() {
8022
7999
  try {
@@ -8047,110 +8024,443 @@
8047
8024
  return url.endsWith('/') ? url : url + '/';
8048
8025
  }
8049
8026
 
8050
- function parseDateString(str) {
8051
- if (str.startsWith('T')) {
8052
- // If a time string,
8053
- // then normalize to full length.
8054
- return str + 'T00:00:00.000Z'.substring(str.length);
8027
+ var _ParserBuilder_prefixParselets, _ParserBuilder_infixParselets, _Parser_tokens, _Parser_prefixParselets, _Parser_infixParselets;
8028
+ class PrefixOperatorAtom {
8029
+ constructor(operator, child) {
8030
+ this.operator = operator;
8031
+ this.child = child;
8055
8032
  }
8056
- if (str.length <= 10) {
8057
- // If a local date (i.e., "2021-01-01"),
8058
- // then return as-is.
8059
- return str;
8033
+ toString() {
8034
+ return `${this.operator}(${this.child.toString()})`;
8060
8035
  }
8061
- try {
8062
- // Try to normalize to UTC
8063
- return new Date(str).toISOString();
8036
+ }
8037
+ class InfixOperatorAtom {
8038
+ constructor(operator, left, right) {
8039
+ this.operator = operator;
8040
+ this.left = left;
8041
+ this.right = right;
8064
8042
  }
8065
- catch (e) {
8066
- // Fallback to original input
8067
- // This happens on unsupported time formats such as "2021-01-01T12"
8068
- return str;
8043
+ toString() {
8044
+ return `${this.left.toString()} ${this.operator} ${this.right.toString()}`;
8069
8045
  }
8070
8046
  }
8071
-
8072
- /**
8073
- * Returns a single element array with a typed boolean value.
8074
- * @param value The primitive boolean value.
8075
- * @returns Single element array with a typed boolean value.
8076
- */
8077
- function booleanToTypedValue(value) {
8078
- return [{ type: exports.PropertyType.boolean, value }];
8079
- }
8080
- /**
8081
- * Returns a "best guess" TypedValue for a given value.
8082
- * @param value The unknown value to check.
8083
- * @returns A "best guess" TypedValue for the given value.
8084
- */
8085
- function toTypedValue(value) {
8086
- if (value === null || value === undefined) {
8087
- return { type: 'undefined', value: undefined };
8047
+ class ParserBuilder {
8048
+ constructor() {
8049
+ _ParserBuilder_prefixParselets.set(this, {});
8050
+ _ParserBuilder_infixParselets.set(this, {});
8088
8051
  }
8089
- else if (Number.isSafeInteger(value)) {
8090
- return { type: exports.PropertyType.integer, value };
8052
+ registerInfix(tokenType, parselet) {
8053
+ __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f")[tokenType] = parselet;
8054
+ return this;
8091
8055
  }
8092
- else if (typeof value === 'number') {
8093
- return { type: exports.PropertyType.decimal, value };
8056
+ registerPrefix(tokenType, parselet) {
8057
+ __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f")[tokenType] = parselet;
8058
+ return this;
8094
8059
  }
8095
- else if (typeof value === 'boolean') {
8096
- return { type: exports.PropertyType.boolean, value };
8060
+ prefix(tokenType, precedence, builder) {
8061
+ return this.registerPrefix(tokenType, {
8062
+ parse(parser, token) {
8063
+ const right = parser.consumeAndParse(precedence);
8064
+ return builder(token, right);
8065
+ },
8066
+ });
8097
8067
  }
8098
- else if (typeof value === 'string') {
8099
- return { type: exports.PropertyType.string, value };
8068
+ infixLeft(tokenType, precedence, builder) {
8069
+ return this.registerInfix(tokenType, {
8070
+ parse(parser, left, token) {
8071
+ const right = parser.consumeAndParse(precedence);
8072
+ return builder(left, token, right);
8073
+ },
8074
+ precedence,
8075
+ });
8100
8076
  }
8101
- else if (isQuantity(value)) {
8102
- return { type: exports.PropertyType.Quantity, value };
8077
+ construct(input) {
8078
+ return new Parser(input, __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f"), __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f"));
8103
8079
  }
8104
- else if (typeof value === 'object' && 'resourceType' in value) {
8105
- return { type: value.resourceType, value };
8080
+ }
8081
+ _ParserBuilder_prefixParselets = new WeakMap(), _ParserBuilder_infixParselets = new WeakMap();
8082
+ class Parser {
8083
+ constructor(tokens, prefixParselets, infixParselets) {
8084
+ _Parser_tokens.set(this, void 0);
8085
+ _Parser_prefixParselets.set(this, void 0);
8086
+ _Parser_infixParselets.set(this, void 0);
8087
+ __classPrivateFieldSet(this, _Parser_tokens, tokens, "f");
8088
+ __classPrivateFieldSet(this, _Parser_prefixParselets, prefixParselets, "f");
8089
+ __classPrivateFieldSet(this, _Parser_infixParselets, infixParselets, "f");
8106
8090
  }
8107
- else {
8108
- return { type: exports.PropertyType.BackboneElement, value };
8091
+ hasMore() {
8092
+ return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0;
8109
8093
  }
8110
- }
8111
- /**
8112
- * Converts unknown object into a JavaScript boolean.
8113
- * Note that this is different than the FHIRPath "toBoolean",
8114
- * which has particular semantics around arrays, empty arrays, and type conversions.
8115
- * @param obj Any value or array of values.
8116
- * @returns The converted boolean value according to FHIRPath rules.
8117
- */
8118
- function toJsBoolean(obj) {
8119
- return obj.length === 0 ? false : !!obj[0].value;
8120
- }
8121
- /**
8122
- * Returns the value of the property and the property type.
8123
- * Some property definitions support multiple types.
8124
- * For example, "Observation.value[x]" can be "valueString", "valueInteger", "valueQuantity", etc.
8125
- * According to the spec, there can only be one property for a given element definition.
8126
- * This function returns the value and the type.
8127
- * @param input The base context (FHIR resource or backbone element).
8128
- * @param path The property path.
8129
- * @returns The value of the property and the property type.
8130
- */
8131
- function getTypedPropertyValue(input, path) {
8132
- if (!(input === null || input === void 0 ? void 0 : input.value)) {
8133
- return undefined;
8094
+ match(expected) {
8095
+ const token = this.peek();
8096
+ if (token?.id !== expected) {
8097
+ return false;
8098
+ }
8099
+ this.consume();
8100
+ return true;
8134
8101
  }
8135
- const elementDefinition = getElementDefinition(input.type, path);
8136
- if (elementDefinition) {
8137
- const typedResult = getTypedPropertyValueWithSchema(input, path, elementDefinition);
8138
- if (typedResult) {
8139
- return typedResult;
8102
+ consumeAndParse(precedence = Infinity) {
8103
+ const token = this.consume();
8104
+ const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
8105
+ if (!prefix) {
8106
+ throw Error(`Parse error at "${token.value}" (line ${token.line}, column ${token.column}). No matching prefix parselet.`);
8107
+ }
8108
+ let left = prefix.parse(this, token);
8109
+ while (precedence > this.getPrecedence()) {
8110
+ const next = this.consume();
8111
+ const infix = this.getInfixParselet(next);
8112
+ left = infix.parse(this, left, next);
8140
8113
  }
8114
+ return left;
8141
8115
  }
8142
- return getTypedPropertyValueWithoutSchema(input, path);
8143
- }
8144
- /**
8145
- * Returns the value of the property and the property type using a type schema.
8146
- * @param input The base context (FHIR resource or backbone element).
8147
- * @param path The property path.
8148
- * @param property The property element definition.
8149
- * @returns The value of the property and the property type.
8150
- */
8151
- function getTypedPropertyValueWithSchema(input, path, property) {
8152
- var _a;
8153
- const types = property.type;
8116
+ getPrecedence() {
8117
+ const nextToken = this.peek();
8118
+ if (!nextToken) {
8119
+ return Infinity;
8120
+ }
8121
+ const parser = this.getInfixParselet(nextToken);
8122
+ if (parser) {
8123
+ return parser.precedence;
8124
+ }
8125
+ return Infinity;
8126
+ }
8127
+ consume(expectedId, expectedValue) {
8128
+ if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
8129
+ throw Error('Cant consume unknown more tokens.');
8130
+ }
8131
+ if (expectedId && this.peek()?.id !== expectedId) {
8132
+ const actual = this.peek();
8133
+ throw Error(`Expected ${expectedId} but got "${actual.id}" at line ${actual.line} column ${actual.column}.`);
8134
+ }
8135
+ if (expectedValue && this.peek()?.value !== expectedValue) {
8136
+ const actual = this.peek();
8137
+ throw Error(`Expected "${expectedValue}" but got "${actual.value}" at line ${actual.line} column ${actual.column}.`);
8138
+ }
8139
+ return __classPrivateFieldGet(this, _Parser_tokens, "f").shift();
8140
+ }
8141
+ peek() {
8142
+ return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0 ? __classPrivateFieldGet(this, _Parser_tokens, "f")[0] : undefined;
8143
+ }
8144
+ removeComments() {
8145
+ __classPrivateFieldSet(this, _Parser_tokens, __classPrivateFieldGet(this, _Parser_tokens, "f").filter((t) => t.id !== 'Comment'), "f");
8146
+ }
8147
+ getInfixParselet(token) {
8148
+ return __classPrivateFieldGet(this, _Parser_infixParselets, "f")[token.id === 'Symbol' ? token.value : token.id];
8149
+ }
8150
+ }
8151
+ _Parser_tokens = new WeakMap(), _Parser_prefixParselets = new WeakMap(), _Parser_infixParselets = new WeakMap();
8152
+
8153
+ var _Tokenizer_instances, _Tokenizer_str, _Tokenizer_keywords, _Tokenizer_operators, _Tokenizer_result, _Tokenizer_pos, _Tokenizer_markStack, _Tokenizer_prevToken, _Tokenizer_peekToken, _Tokenizer_consumeToken, _Tokenizer_consumeWhitespace, _Tokenizer_consumeMultiLineComment, _Tokenizer_consumeSingleLineComment, _Tokenizer_consumeString, _Tokenizer_consumeBacktickSymbol, _Tokenizer_consumeDateTime, _Tokenizer_consumeNumber, _Tokenizer_consumeSymbol, _Tokenizer_consumeOperator, _Tokenizer_consumeWhile, _Tokenizer_curr, _Tokenizer_prev, _Tokenizer_peek, _Tokenizer_mark, _Tokenizer_reset, _Tokenizer_advance, _Tokenizer_buildToken;
8154
+ const STANDARD_UNITS = [
8155
+ 'year',
8156
+ 'years',
8157
+ 'month',
8158
+ 'months',
8159
+ 'week',
8160
+ 'weeks',
8161
+ 'day',
8162
+ 'days',
8163
+ 'hour',
8164
+ 'hours',
8165
+ 'minute',
8166
+ 'minutes',
8167
+ 'second',
8168
+ 'seconds',
8169
+ 'millisecond',
8170
+ 'milliseconds',
8171
+ ];
8172
+ class Tokenizer {
8173
+ constructor(str, keywords, operators) {
8174
+ _Tokenizer_instances.add(this);
8175
+ _Tokenizer_str.set(this, void 0);
8176
+ _Tokenizer_keywords.set(this, void 0);
8177
+ _Tokenizer_operators.set(this, void 0);
8178
+ _Tokenizer_result.set(this, []);
8179
+ _Tokenizer_pos.set(this, { index: 0, line: 1, column: 0 });
8180
+ _Tokenizer_markStack.set(this, []);
8181
+ __classPrivateFieldSet(this, _Tokenizer_str, str, "f");
8182
+ __classPrivateFieldSet(this, _Tokenizer_keywords, keywords, "f");
8183
+ __classPrivateFieldSet(this, _Tokenizer_operators, operators, "f");
8184
+ }
8185
+ tokenize() {
8186
+ while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length) {
8187
+ const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
8188
+ if (token) {
8189
+ __classPrivateFieldGet(this, _Tokenizer_result, "f").push(token);
8190
+ }
8191
+ }
8192
+ return __classPrivateFieldGet(this, _Tokenizer_result, "f");
8193
+ }
8194
+ }
8195
+ _Tokenizer_str = new WeakMap(), _Tokenizer_keywords = new WeakMap(), _Tokenizer_operators = new WeakMap(), _Tokenizer_result = new WeakMap(), _Tokenizer_pos = new WeakMap(), _Tokenizer_markStack = new WeakMap(), _Tokenizer_instances = new WeakSet(), _Tokenizer_prevToken = function _Tokenizer_prevToken() {
8196
+ return __classPrivateFieldGet(this, _Tokenizer_result, "f").slice(-1)[0];
8197
+ }, _Tokenizer_peekToken = function _Tokenizer_peekToken() {
8198
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
8199
+ const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
8200
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_reset).call(this);
8201
+ return token;
8202
+ }, _Tokenizer_consumeToken = function _Tokenizer_consumeToken() {
8203
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhitespace).call(this);
8204
+ const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
8205
+ if (!c) {
8206
+ return undefined;
8207
+ }
8208
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
8209
+ const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
8210
+ if (c === '/' && next === '*') {
8211
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeMultiLineComment).call(this);
8212
+ }
8213
+ if (c === '/' && next === '/') {
8214
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSingleLineComment).call(this);
8215
+ }
8216
+ if (c === "'" || c === '"') {
8217
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeString).call(this, c);
8218
+ }
8219
+ if (c === '`') {
8220
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeBacktickSymbol).call(this);
8221
+ }
8222
+ if (c === '@') {
8223
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeDateTime).call(this);
8224
+ }
8225
+ if (c.match(/\d/)) {
8226
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeNumber).call(this);
8227
+ }
8228
+ if (c.match(/\w/)) {
8229
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
8230
+ }
8231
+ if (c === '$' && next.match(/\w/)) {
8232
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
8233
+ }
8234
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeOperator).call(this);
8235
+ }, _Tokenizer_consumeWhitespace = function _Tokenizer_consumeWhitespace() {
8236
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\s/));
8237
+ }, _Tokenizer_consumeMultiLineComment = function _Tokenizer_consumeMultiLineComment() {
8238
+ const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
8239
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '*' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this) !== '/');
8240
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8241
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8242
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
8243
+ }, _Tokenizer_consumeSingleLineComment = function _Tokenizer_consumeSingleLineComment() {
8244
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '\n'));
8245
+ }, _Tokenizer_consumeString = function _Tokenizer_consumeString(endChar) {
8246
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8247
+ const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'String', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prev).call(this) === '\\' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== endChar));
8248
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8249
+ return result;
8250
+ }, _Tokenizer_consumeBacktickSymbol = function _Tokenizer_consumeBacktickSymbol() {
8251
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8252
+ const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '`'));
8253
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8254
+ return result;
8255
+ }, _Tokenizer_consumeDateTime = function _Tokenizer_consumeDateTime() {
8256
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this); // Consume "@"
8257
+ const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
8258
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d-]/));
8259
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'T') {
8260
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8261
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
8262
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
8263
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8264
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
8265
+ }
8266
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'Z') {
8267
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8268
+ }
8269
+ else if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '+' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '-') {
8270
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8271
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
8272
+ }
8273
+ }
8274
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'DateTime', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
8275
+ }, _Tokenizer_consumeNumber = function _Tokenizer_consumeNumber() {
8276
+ const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
8277
+ let id = 'Number';
8278
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
8279
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
8280
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8281
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
8282
+ }
8283
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === ' ') {
8284
+ if (isUnitToken(__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peekToken).call(this))) {
8285
+ id = 'Quantity';
8286
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
8287
+ }
8288
+ }
8289
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, id, __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
8290
+ }, _Tokenizer_consumeSymbol = function _Tokenizer_consumeSymbol() {
8291
+ const value = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/));
8292
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prevToken).call(this)?.value !== '.' && __classPrivateFieldGet(this, _Tokenizer_keywords, "f").includes(value)) {
8293
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, value, value);
8294
+ }
8295
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', value);
8296
+ }, _Tokenizer_consumeOperator = function _Tokenizer_consumeOperator() {
8297
+ const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
8298
+ const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
8299
+ const twoCharOp = c + next;
8300
+ if (__classPrivateFieldGet(this, _Tokenizer_operators, "f").includes(twoCharOp)) {
8301
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8302
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8303
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, twoCharOp, twoCharOp);
8304
+ }
8305
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8306
+ return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, c, c);
8307
+ }, _Tokenizer_consumeWhile = function _Tokenizer_consumeWhile(condition) {
8308
+ const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
8309
+ while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length && condition()) {
8310
+ __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
8311
+ }
8312
+ return __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index);
8313
+ }, _Tokenizer_curr = function _Tokenizer_curr() {
8314
+ return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index];
8315
+ }, _Tokenizer_prev = function _Tokenizer_prev() {
8316
+ return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1] ?? '';
8317
+ }, _Tokenizer_peek = function _Tokenizer_peek() {
8318
+ return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1] ?? '';
8319
+ }, _Tokenizer_mark = function _Tokenizer_mark() {
8320
+ __classPrivateFieldGet(this, _Tokenizer_markStack, "f").push({ ...__classPrivateFieldGet(this, _Tokenizer_pos, "f") });
8321
+ }, _Tokenizer_reset = function _Tokenizer_reset() {
8322
+ const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
8323
+ if (!mark) {
8324
+ throw new Error('No mark to reset to');
8325
+ }
8326
+ __classPrivateFieldGet(this, _Tokenizer_pos, "f").index = mark.index;
8327
+ __classPrivateFieldGet(this, _Tokenizer_pos, "f").line = mark.line;
8328
+ __classPrivateFieldGet(this, _Tokenizer_pos, "f").column = mark.column;
8329
+ }, _Tokenizer_advance = function _Tokenizer_advance() {
8330
+ __classPrivateFieldGet(this, _Tokenizer_pos, "f").index++;
8331
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '\n') {
8332
+ __classPrivateFieldGet(this, _Tokenizer_pos, "f").line++;
8333
+ __classPrivateFieldGet(this, _Tokenizer_pos, "f").column = 0;
8334
+ }
8335
+ else {
8336
+ __classPrivateFieldGet(this, _Tokenizer_pos, "f").column++;
8337
+ }
8338
+ }, _Tokenizer_buildToken = function _Tokenizer_buildToken(id, value) {
8339
+ const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
8340
+ if (!mark) {
8341
+ throw new Error('No mark for token');
8342
+ }
8343
+ return {
8344
+ id,
8345
+ value,
8346
+ ...mark,
8347
+ };
8348
+ };
8349
+ function isUnitToken(token) {
8350
+ if (token) {
8351
+ if (token.id === 'String') {
8352
+ return true;
8353
+ }
8354
+ if (token.id === 'Symbol' && STANDARD_UNITS.includes(token.value)) {
8355
+ return true;
8356
+ }
8357
+ }
8358
+ return false;
8359
+ }
8360
+
8361
+ function parseDateString(str) {
8362
+ if (str.startsWith('T')) {
8363
+ // If a time string,
8364
+ // then normalize to full length.
8365
+ return str + 'T00:00:00.000Z'.substring(str.length);
8366
+ }
8367
+ if (str.length <= 10) {
8368
+ // If a local date (i.e., "2021-01-01"),
8369
+ // then return as-is.
8370
+ return str;
8371
+ }
8372
+ try {
8373
+ // Try to normalize to UTC
8374
+ return new Date(str).toISOString();
8375
+ }
8376
+ catch (e) {
8377
+ // Fallback to original input
8378
+ // This happens on unsupported time formats such as "2021-01-01T12"
8379
+ return str;
8380
+ }
8381
+ }
8382
+
8383
+ /**
8384
+ * Returns a single element array with a typed boolean value.
8385
+ * @param value The primitive boolean value.
8386
+ * @returns Single element array with a typed boolean value.
8387
+ */
8388
+ function booleanToTypedValue(value) {
8389
+ return [{ type: exports.PropertyType.boolean, value }];
8390
+ }
8391
+ /**
8392
+ * Returns a "best guess" TypedValue for a given value.
8393
+ * @param value The unknown value to check.
8394
+ * @returns A "best guess" TypedValue for the given value.
8395
+ */
8396
+ function toTypedValue(value) {
8397
+ if (value === null || value === undefined) {
8398
+ return { type: 'undefined', value: undefined };
8399
+ }
8400
+ else if (Number.isSafeInteger(value)) {
8401
+ return { type: exports.PropertyType.integer, value };
8402
+ }
8403
+ else if (typeof value === 'number') {
8404
+ return { type: exports.PropertyType.decimal, value };
8405
+ }
8406
+ else if (typeof value === 'boolean') {
8407
+ return { type: exports.PropertyType.boolean, value };
8408
+ }
8409
+ else if (typeof value === 'string') {
8410
+ return { type: exports.PropertyType.string, value };
8411
+ }
8412
+ else if (isQuantity(value)) {
8413
+ return { type: exports.PropertyType.Quantity, value };
8414
+ }
8415
+ else if (typeof value === 'object' && 'resourceType' in value) {
8416
+ return { type: value.resourceType, value };
8417
+ }
8418
+ else {
8419
+ return { type: exports.PropertyType.BackboneElement, value };
8420
+ }
8421
+ }
8422
+ /**
8423
+ * Converts unknown object into a JavaScript boolean.
8424
+ * Note that this is different than the FHIRPath "toBoolean",
8425
+ * which has particular semantics around arrays, empty arrays, and type conversions.
8426
+ * @param obj Any value or array of values.
8427
+ * @returns The converted boolean value according to FHIRPath rules.
8428
+ */
8429
+ function toJsBoolean(obj) {
8430
+ return obj.length === 0 ? false : !!obj[0].value;
8431
+ }
8432
+ /**
8433
+ * Returns the value of the property and the property type.
8434
+ * Some property definitions support multiple types.
8435
+ * For example, "Observation.value[x]" can be "valueString", "valueInteger", "valueQuantity", etc.
8436
+ * According to the spec, there can only be one property for a given element definition.
8437
+ * This function returns the value and the type.
8438
+ * @param input The base context (FHIR resource or backbone element).
8439
+ * @param path The property path.
8440
+ * @returns The value of the property and the property type.
8441
+ */
8442
+ function getTypedPropertyValue(input, path) {
8443
+ if (!input?.value) {
8444
+ return undefined;
8445
+ }
8446
+ const elementDefinition = getElementDefinition(input.type, path);
8447
+ if (elementDefinition) {
8448
+ const typedResult = getTypedPropertyValueWithSchema(input, path, elementDefinition);
8449
+ if (typedResult) {
8450
+ return typedResult;
8451
+ }
8452
+ }
8453
+ return getTypedPropertyValueWithoutSchema(input, path);
8454
+ }
8455
+ /**
8456
+ * Returns the value of the property and the property type using a type schema.
8457
+ * @param input The base context (FHIR resource or backbone element).
8458
+ * @param path The property path.
8459
+ * @param property The property element definition.
8460
+ * @returns The value of the property and the property type.
8461
+ */
8462
+ function getTypedPropertyValueWithSchema(input, path, property) {
8463
+ const types = property.type;
8154
8464
  if (!types || types.length === 0) {
8155
8465
  return undefined;
8156
8466
  }
@@ -8174,7 +8484,7 @@
8174
8484
  return undefined;
8175
8485
  }
8176
8486
  if (resultType === 'Element' || resultType === 'BackboneElement') {
8177
- resultType = buildTypeName((_a = property.path) === null || _a === void 0 ? void 0 : _a.split('.'));
8487
+ resultType = buildTypeName(property.path?.split('.'));
8178
8488
  }
8179
8489
  if (Array.isArray(resultValue)) {
8180
8490
  return resultValue.map((element) => toTypedValueWithType(element, resultType));
@@ -8385,7 +8695,7 @@
8385
8695
  case 'Quantity':
8386
8696
  return isQuantity(value);
8387
8697
  default:
8388
- return typeof value === 'object' && (value === null || value === void 0 ? void 0 : value.resourceType) === desiredType;
8698
+ return typeof value === 'object' && value?.resourceType === desiredType;
8389
8699
  }
8390
8700
  }
8391
8701
  /**
@@ -8774,8 +9084,7 @@
8774
9084
  * @returns A collection containing all but the first item in the input collection.
8775
9085
  */
8776
9086
  skip: (input, num) => {
8777
- var _a;
8778
- const numValue = (_a = num.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
9087
+ const numValue = num.eval(input)[0]?.value;
8779
9088
  if (typeof numValue !== 'number') {
8780
9089
  throw new Error('Expected a number for skip(num)');
8781
9090
  }
@@ -8799,8 +9108,7 @@
8799
9108
  * @returns A collection containing the first num items in the input collection.
8800
9109
  */
8801
9110
  take: (input, num) => {
8802
- var _a;
8803
- const numValue = (_a = num.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
9111
+ const numValue = num.eval(input)[0]?.value;
8804
9112
  if (typeof numValue !== 'number') {
8805
9113
  throw new Error('Expected a number for take(num)');
8806
9114
  }
@@ -9744,7 +10052,6 @@
9744
10052
  * IBM FHIR PR: https://github.com/IBM/FHIR/pull/1023
9745
10053
  */
9746
10054
  between: (input, startAtom, endAtom, unitsAtom) => {
9747
- var _a;
9748
10055
  const startDate = functions.toDateTime(startAtom.eval(input));
9749
10056
  if (startDate.length === 0) {
9750
10057
  throw new Error('Invalid start date');
@@ -9753,7 +10060,7 @@
9753
10060
  if (endDate.length === 0) {
9754
10061
  throw new Error('Invalid end date');
9755
10062
  }
9756
- const unit = (_a = unitsAtom.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
10063
+ const unit = unitsAtom.eval(input)[0]?.value;
9757
10064
  if (unit !== 'years' && unit !== 'months' && unit !== 'days') {
9758
10065
  throw new Error('Invalid units');
9759
10066
  }
@@ -9884,13 +10191,10 @@
9884
10191
  throw new Error('Expected a StructureDefinition URL');
9885
10192
  }
9886
10193
  const expectedResourceType = system.replace('http://hl7.org/fhir/StructureDefinition/', '');
9887
- return input.map((value) => {
9888
- var _a;
9889
- return ({
9890
- type: exports.PropertyType.boolean,
9891
- value: ((_a = value.value) === null || _a === void 0 ? void 0 : _a.resourceType) === expectedResourceType,
9892
- });
9893
- });
10194
+ return input.map((value) => ({
10195
+ type: exports.PropertyType.boolean,
10196
+ value: value.value?.resourceType === expectedResourceType,
10197
+ }));
9894
10198
  },
9895
10199
  };
9896
10200
  /*
@@ -9904,7 +10208,7 @@
9904
10208
  if (typeof value !== 'string') {
9905
10209
  throw new Error('String function cannot be called with non-string');
9906
10210
  }
9907
- const result = func(value, ...argsAtoms.map((atom) => { var _a, _b; return atom && ((_b = (_a = atom.eval(input)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value); }));
10211
+ const result = func(value, ...argsAtoms.map((atom) => atom && atom.eval(input)?.[0]?.value));
9908
10212
  if (result === undefined) {
9909
10213
  return [];
9910
10214
  }
@@ -9923,9 +10227,9 @@
9923
10227
  if (typeof numberInput !== 'number') {
9924
10228
  throw new Error('Math function cannot be called with non-number');
9925
10229
  }
9926
- const result = func(numberInput, ...argsAtoms.map((atom) => { var _a, _b; return (_b = (_a = atom.eval(input)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value; }));
10230
+ const result = func(numberInput, ...argsAtoms.map((atom) => atom.eval(input)?.[0]?.value));
9927
10231
  const type = quantity ? exports.PropertyType.Quantity : input[0].type;
9928
- const returnValue = quantity ? Object.assign(Object.assign({}, value), { value: result }) : result;
10232
+ const returnValue = quantity ? { ...value, value: result } : result;
9929
10233
  return [{ type, value: returnValue }];
9930
10234
  }
9931
10235
  function validateInput(input, count) {
@@ -9959,6 +10263,9 @@
9959
10263
  throw new Error(`FhirPathError on "${this.original}": ${error}`);
9960
10264
  }
9961
10265
  }
10266
+ toString() {
10267
+ return this.child.toString();
10268
+ }
9962
10269
  }
9963
10270
  class LiteralAtom {
9964
10271
  constructor(value) {
@@ -9967,6 +10274,13 @@
9967
10274
  eval() {
9968
10275
  return [this.value];
9969
10276
  }
10277
+ toString() {
10278
+ const value = this.value.value;
10279
+ if (typeof value === 'string') {
10280
+ return `'${value}'`;
10281
+ }
10282
+ return value.toString();
10283
+ }
9970
10284
  }
9971
10285
  class SymbolAtom {
9972
10286
  constructor(name) {
@@ -9980,7 +10294,10 @@
9980
10294
  return context
9981
10295
  .map((e) => __classPrivateFieldGet(this, _SymbolAtom_instances, "m", _SymbolAtom_evalValue).call(this, e))
9982
10296
  .flat()
9983
- .filter((e) => (e === null || e === void 0 ? void 0 : e.value) !== undefined);
10297
+ .filter((e) => e?.value !== undefined);
10298
+ }
10299
+ toString() {
10300
+ return this.name;
9984
10301
  }
9985
10302
  }
9986
10303
  _SymbolAtom_instances = new WeakSet(), _SymbolAtom_evalValue = function _SymbolAtom_evalValue(typedValue) {
@@ -9992,587 +10309,280 @@
9992
10309
  return typedValue;
9993
10310
  }
9994
10311
  return getTypedPropertyValue(typedValue, this.name);
9995
- };
9996
- class EmptySetAtom {
9997
- eval() {
9998
- return [];
9999
- }
10000
- }
10001
- class UnaryOperatorAtom {
10002
- constructor(child, impl) {
10003
- this.child = child;
10004
- this.impl = impl;
10005
- }
10006
- eval(context) {
10007
- return this.impl(this.child.eval(context));
10008
- }
10009
- }
10010
- class AsAtom {
10011
- constructor(left, right) {
10012
- this.left = left;
10013
- this.right = right;
10014
- }
10015
- eval(context) {
10016
- return functions.ofType(this.left.eval(context), this.right);
10017
- }
10018
- }
10019
- class ArithemticOperatorAtom {
10020
- constructor(left, right, impl) {
10021
- this.left = left;
10022
- this.right = right;
10023
- this.impl = impl;
10024
- }
10025
- eval(context) {
10026
- const leftEvalResult = this.left.eval(context);
10027
- if (leftEvalResult.length !== 1) {
10028
- return [];
10029
- }
10030
- const rightEvalResult = this.right.eval(context);
10031
- if (rightEvalResult.length !== 1) {
10032
- return [];
10033
- }
10034
- const leftValue = leftEvalResult[0].value;
10035
- const rightValue = rightEvalResult[0].value;
10036
- const leftNumber = isQuantity(leftValue) ? leftValue.value : leftValue;
10037
- const rightNumber = isQuantity(rightValue) ? rightValue.value : rightValue;
10038
- const result = this.impl(leftNumber, rightNumber);
10039
- if (typeof result === 'boolean') {
10040
- return booleanToTypedValue(result);
10041
- }
10042
- else if (isQuantity(leftValue)) {
10043
- return [{ type: exports.PropertyType.Quantity, value: Object.assign(Object.assign({}, leftValue), { value: result }) }];
10044
- }
10045
- else {
10046
- return [toTypedValue(result)];
10047
- }
10048
- }
10049
- }
10050
- class ConcatAtom {
10051
- constructor(left, right) {
10052
- this.left = left;
10053
- this.right = right;
10054
- }
10055
- eval(context) {
10056
- const leftValue = this.left.eval(context);
10057
- const rightValue = this.right.eval(context);
10058
- const result = [...leftValue, ...rightValue];
10059
- if (result.length > 0 && result.every((e) => typeof e.value === 'string')) {
10060
- return [{ type: exports.PropertyType.string, value: result.map((e) => e.value).join('') }];
10061
- }
10062
- return result;
10063
- }
10064
- }
10065
- class ContainsAtom {
10066
- constructor(left, right) {
10067
- this.left = left;
10068
- this.right = right;
10069
- }
10070
- eval(context) {
10071
- const leftValue = this.left.eval(context);
10072
- const rightValue = this.right.eval(context);
10073
- return booleanToTypedValue(leftValue.some((e) => e.value === rightValue[0].value));
10074
- }
10075
- }
10076
- class InAtom {
10077
- constructor(left, right) {
10078
- this.left = left;
10079
- this.right = right;
10080
- }
10081
- eval(context) {
10082
- const leftValue = this.left.eval(context);
10083
- const rightValue = this.right.eval(context);
10084
- return booleanToTypedValue(rightValue.some((e) => e.value === leftValue[0].value));
10085
- }
10086
- }
10087
- class DotAtom {
10088
- constructor(left, right) {
10089
- this.left = left;
10090
- this.right = right;
10091
- }
10092
- eval(context) {
10093
- return this.right.eval(this.left.eval(context));
10094
- }
10095
- }
10096
- class UnionAtom {
10097
- constructor(left, right) {
10098
- this.left = left;
10099
- this.right = right;
10100
- }
10101
- eval(context) {
10102
- const leftResult = this.left.eval(context);
10103
- const rightResult = this.right.eval(context);
10104
- return removeDuplicates([...leftResult, ...rightResult]);
10105
- }
10106
- }
10107
- class EqualsAtom {
10108
- constructor(left, right) {
10109
- this.left = left;
10110
- this.right = right;
10111
- }
10112
- eval(context) {
10113
- const leftValue = this.left.eval(context);
10114
- const rightValue = this.right.eval(context);
10115
- return fhirPathArrayEquals(leftValue, rightValue);
10116
- }
10117
- }
10118
- class NotEqualsAtom {
10119
- constructor(left, right) {
10120
- this.left = left;
10121
- this.right = right;
10312
+ };
10313
+ class EmptySetAtom {
10314
+ eval() {
10315
+ return [];
10122
10316
  }
10123
- eval(context) {
10124
- const leftValue = this.left.eval(context);
10125
- const rightValue = this.right.eval(context);
10126
- return fhirPathNot(fhirPathArrayEquals(leftValue, rightValue));
10317
+ toString() {
10318
+ return '{}';
10127
10319
  }
10128
10320
  }
10129
- class EquivalentAtom {
10130
- constructor(left, right) {
10131
- this.left = left;
10132
- this.right = right;
10321
+ class UnaryOperatorAtom extends PrefixOperatorAtom {
10322
+ constructor(operator, child, impl) {
10323
+ super(operator, child);
10324
+ this.impl = impl;
10133
10325
  }
10134
10326
  eval(context) {
10135
- const leftValue = this.left.eval(context);
10136
- const rightValue = this.right.eval(context);
10137
- return fhirPathArrayEquivalent(leftValue, rightValue);
10327
+ return this.impl(this.child.eval(context));
10328
+ }
10329
+ toString() {
10330
+ return this.child.toString();
10138
10331
  }
10139
10332
  }
10140
- class NotEquivalentAtom {
10333
+ class AsAtom extends InfixOperatorAtom {
10141
10334
  constructor(left, right) {
10142
- this.left = left;
10143
- this.right = right;
10335
+ super('as', left, right);
10144
10336
  }
10145
10337
  eval(context) {
10146
- const leftValue = this.left.eval(context);
10147
- const rightValue = this.right.eval(context);
10148
- return fhirPathNot(fhirPathArrayEquivalent(leftValue, rightValue));
10338
+ return functions.ofType(this.left.eval(context), this.right);
10149
10339
  }
10150
10340
  }
10151
- class IsAtom {
10152
- constructor(left, right) {
10153
- this.left = left;
10154
- this.right = right;
10341
+ class ArithemticOperatorAtom extends InfixOperatorAtom {
10342
+ constructor(operator, left, right, impl) {
10343
+ super(operator, left, right);
10344
+ this.impl = impl;
10155
10345
  }
10156
10346
  eval(context) {
10157
- const leftValue = this.left.eval(context);
10158
- if (leftValue.length !== 1) {
10347
+ const leftEvalResult = this.left.eval(context);
10348
+ if (leftEvalResult.length !== 1) {
10159
10349
  return [];
10160
10350
  }
10161
- const typeName = this.right.name;
10162
- return booleanToTypedValue(fhirPathIs(leftValue[0], typeName));
10351
+ const rightEvalResult = this.right.eval(context);
10352
+ if (rightEvalResult.length !== 1) {
10353
+ return [];
10354
+ }
10355
+ const leftValue = leftEvalResult[0].value;
10356
+ const rightValue = rightEvalResult[0].value;
10357
+ const leftNumber = isQuantity(leftValue) ? leftValue.value : leftValue;
10358
+ const rightNumber = isQuantity(rightValue) ? rightValue.value : rightValue;
10359
+ const result = this.impl(leftNumber, rightNumber);
10360
+ if (typeof result === 'boolean') {
10361
+ return booleanToTypedValue(result);
10362
+ }
10363
+ else if (isQuantity(leftValue)) {
10364
+ return [{ type: exports.PropertyType.Quantity, value: { ...leftValue, value: result } }];
10365
+ }
10366
+ else {
10367
+ return [toTypedValue(result)];
10368
+ }
10163
10369
  }
10164
10370
  }
10165
- /**
10166
- * 6.5.1. and
10167
- * Returns true if both operands evaluate to true,
10168
- * false if either operand evaluates to false,
10169
- * and the empty collection otherwise.
10170
- */
10171
- class AndAtom {
10371
+ class ConcatAtom extends InfixOperatorAtom {
10172
10372
  constructor(left, right) {
10173
- this.left = left;
10174
- this.right = right;
10373
+ super('&', left, right);
10175
10374
  }
10176
10375
  eval(context) {
10177
- var _a, _b, _c, _d;
10178
10376
  const leftValue = this.left.eval(context);
10179
10377
  const rightValue = this.right.eval(context);
10180
- if (((_a = leftValue[0]) === null || _a === void 0 ? void 0 : _a.value) === true && ((_b = rightValue[0]) === null || _b === void 0 ? void 0 : _b.value) === true) {
10181
- return booleanToTypedValue(true);
10182
- }
10183
- if (((_c = leftValue[0]) === null || _c === void 0 ? void 0 : _c.value) === false || ((_d = rightValue[0]) === null || _d === void 0 ? void 0 : _d.value) === false) {
10184
- return booleanToTypedValue(false);
10378
+ const result = [...leftValue, ...rightValue];
10379
+ if (result.length > 0 && result.every((e) => typeof e.value === 'string')) {
10380
+ return [{ type: exports.PropertyType.string, value: result.map((e) => e.value).join('') }];
10185
10381
  }
10186
- return [];
10382
+ return result;
10187
10383
  }
10188
10384
  }
10189
- class OrAtom {
10385
+ class ContainsAtom extends InfixOperatorAtom {
10190
10386
  constructor(left, right) {
10191
- this.left = left;
10192
- this.right = right;
10387
+ super('contains', left, right);
10193
10388
  }
10194
10389
  eval(context) {
10195
10390
  const leftValue = this.left.eval(context);
10196
- if (toJsBoolean(leftValue)) {
10197
- return leftValue;
10198
- }
10199
10391
  const rightValue = this.right.eval(context);
10200
- if (toJsBoolean(rightValue)) {
10201
- return rightValue;
10202
- }
10203
- return [];
10392
+ return booleanToTypedValue(leftValue.some((e) => e.value === rightValue[0].value));
10204
10393
  }
10205
10394
  }
10206
- /**
10207
- * 6.5.4. xor
10208
- * Returns true if exactly one of the operands evaluates to true,
10209
- * false if either both operands evaluate to true or both operands evaluate to false,
10210
- * and the empty collection otherwise.
10211
- */
10212
- class XorAtom {
10395
+ class InAtom extends InfixOperatorAtom {
10213
10396
  constructor(left, right) {
10214
- this.left = left;
10215
- this.right = right;
10216
- }
10217
- eval(context) {
10218
- const leftResult = this.left.eval(context);
10219
- const rightResult = this.right.eval(context);
10220
- if (leftResult.length === 0 && rightResult.length === 0) {
10221
- return [];
10222
- }
10223
- const leftValue = leftResult.length === 0 ? null : leftResult[0].value;
10224
- const rightValue = rightResult.length === 0 ? null : rightResult[0].value;
10225
- if ((leftValue === true && rightValue !== true) || (leftValue !== true && rightValue === true)) {
10226
- return booleanToTypedValue(true);
10227
- }
10228
- if ((leftValue === true && rightValue === true) || (leftValue === false && rightValue === false)) {
10229
- return booleanToTypedValue(false);
10230
- }
10231
- return [];
10232
- }
10233
- }
10234
- class FunctionAtom {
10235
- constructor(name, args, impl) {
10236
- this.name = name;
10237
- this.args = args;
10238
- this.impl = impl;
10397
+ super('in', left, right);
10239
10398
  }
10240
10399
  eval(context) {
10241
- return this.impl(context, ...this.args);
10400
+ const leftValue = this.left.eval(context);
10401
+ const rightValue = this.right.eval(context);
10402
+ return booleanToTypedValue(rightValue.some((e) => e.value === leftValue[0].value));
10242
10403
  }
10243
10404
  }
10244
- class IndexerAtom {
10245
- constructor(left, expr) {
10246
- this.left = left;
10247
- this.expr = expr;
10405
+ class DotAtom extends InfixOperatorAtom {
10406
+ constructor(left, right) {
10407
+ super('.', left, right);
10248
10408
  }
10249
10409
  eval(context) {
10250
- const evalResult = this.expr.eval(context);
10251
- if (evalResult.length !== 1) {
10252
- return [];
10253
- }
10254
- const index = evalResult[0].value;
10255
- if (typeof index !== 'number') {
10256
- throw new Error(`Invalid indexer expression: should return integer}`);
10257
- }
10258
- const leftResult = this.left.eval(context);
10259
- if (!(index in leftResult)) {
10260
- return [];
10261
- }
10262
- return [leftResult[index]];
10263
- }
10264
- }
10265
-
10266
- var _ParserBuilder_prefixParselets, _ParserBuilder_infixParselets, _Parser_tokens, _Parser_prefixParselets, _Parser_infixParselets;
10267
- class ParserBuilder {
10268
- constructor() {
10269
- _ParserBuilder_prefixParselets.set(this, {});
10270
- _ParserBuilder_infixParselets.set(this, {});
10271
- }
10272
- registerInfix(tokenType, parselet) {
10273
- __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f")[tokenType] = parselet;
10274
- return this;
10275
- }
10276
- registerPrefix(tokenType, parselet) {
10277
- __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f")[tokenType] = parselet;
10278
- return this;
10279
- }
10280
- prefix(tokenType, precedence, builder) {
10281
- return this.registerPrefix(tokenType, {
10282
- parse(parser, token) {
10283
- const right = parser.consumeAndParse(precedence);
10284
- return builder(token, right);
10285
- },
10286
- });
10287
- }
10288
- infixLeft(tokenType, precedence, builder) {
10289
- return this.registerInfix(tokenType, {
10290
- parse(parser, left, token) {
10291
- const right = parser.consumeAndParse(precedence);
10292
- return builder(left, token, right);
10293
- },
10294
- precedence,
10295
- });
10296
- }
10297
- construct(input) {
10298
- return new Parser(input, __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f"), __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f"));
10299
- }
10300
- }
10301
- _ParserBuilder_prefixParselets = new WeakMap(), _ParserBuilder_infixParselets = new WeakMap();
10302
- class Parser {
10303
- constructor(tokens, prefixParselets, infixParselets) {
10304
- _Parser_tokens.set(this, void 0);
10305
- _Parser_prefixParselets.set(this, void 0);
10306
- _Parser_infixParselets.set(this, void 0);
10307
- __classPrivateFieldSet(this, _Parser_tokens, tokens, "f");
10308
- __classPrivateFieldSet(this, _Parser_prefixParselets, prefixParselets, "f");
10309
- __classPrivateFieldSet(this, _Parser_infixParselets, infixParselets, "f");
10310
- }
10311
- hasMore() {
10312
- return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0;
10313
- }
10314
- match(expected) {
10315
- const token = this.peek();
10316
- if ((token === null || token === void 0 ? void 0 : token.id) !== expected) {
10317
- return false;
10318
- }
10319
- this.consume();
10320
- return true;
10321
- }
10322
- consumeAndParse(precedence = Infinity) {
10323
- const token = this.consume();
10324
- const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
10325
- if (!prefix) {
10326
- throw Error(`Parse error at "${token.value}" (line ${token.line}, column ${token.column}). No matching prefix parselet.`);
10327
- }
10328
- let left = prefix.parse(this, token);
10329
- while (precedence > this.getPrecedence()) {
10330
- const next = this.consume();
10331
- const infix = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[next.id];
10332
- left = infix.parse(this, left, next);
10333
- }
10334
- return left;
10335
- }
10336
- getPrecedence() {
10337
- const nextToken = this.peek();
10338
- if (!nextToken) {
10339
- return Infinity;
10340
- }
10341
- const parser = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[nextToken.id];
10342
- if (parser) {
10343
- return parser.precedence;
10344
- }
10345
- return Infinity;
10346
- }
10347
- consume(expected) {
10348
- var _a;
10349
- if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
10350
- throw Error('Cant consume unknown more tokens.');
10351
- }
10352
- if (expected && ((_a = this.peek()) === null || _a === void 0 ? void 0 : _a.id) !== expected) {
10353
- const actual = this.peek();
10354
- throw Error(`Expected ${expected} but got "${actual.value}" at line ${actual.line} column ${actual.column}.`);
10355
- }
10356
- return __classPrivateFieldGet(this, _Parser_tokens, "f").shift();
10357
- }
10358
- peek() {
10359
- return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0 ? __classPrivateFieldGet(this, _Parser_tokens, "f")[0] : undefined;
10360
- }
10361
- removeComments() {
10362
- __classPrivateFieldSet(this, _Parser_tokens, __classPrivateFieldGet(this, _Parser_tokens, "f").filter((t) => t.id !== 'Comment'), "f");
10363
- }
10364
- }
10365
- _Parser_tokens = new WeakMap(), _Parser_prefixParselets = new WeakMap(), _Parser_infixParselets = new WeakMap();
10366
-
10367
- var _Tokenizer_instances, _Tokenizer_str, _Tokenizer_keywords, _Tokenizer_operators, _Tokenizer_result, _Tokenizer_pos, _Tokenizer_markStack, _Tokenizer_prevToken, _Tokenizer_peekToken, _Tokenizer_consumeToken, _Tokenizer_consumeWhitespace, _Tokenizer_consumeMultiLineComment, _Tokenizer_consumeSingleLineComment, _Tokenizer_consumeString, _Tokenizer_consumeBacktickSymbol, _Tokenizer_consumeDateTime, _Tokenizer_consumeNumber, _Tokenizer_consumeSymbol, _Tokenizer_consumeOperator, _Tokenizer_consumeWhile, _Tokenizer_curr, _Tokenizer_prev, _Tokenizer_peek, _Tokenizer_mark, _Tokenizer_reset, _Tokenizer_advance, _Tokenizer_buildToken;
10368
- const STANDARD_UNITS = [
10369
- 'year',
10370
- 'years',
10371
- 'month',
10372
- 'months',
10373
- 'week',
10374
- 'weeks',
10375
- 'day',
10376
- 'days',
10377
- 'hour',
10378
- 'hours',
10379
- 'minute',
10380
- 'minutes',
10381
- 'second',
10382
- 'seconds',
10383
- 'millisecond',
10384
- 'milliseconds',
10385
- ];
10386
- class Tokenizer {
10387
- constructor(str, keywords, operators) {
10388
- _Tokenizer_instances.add(this);
10389
- _Tokenizer_str.set(this, void 0);
10390
- _Tokenizer_keywords.set(this, void 0);
10391
- _Tokenizer_operators.set(this, void 0);
10392
- _Tokenizer_result.set(this, []);
10393
- _Tokenizer_pos.set(this, { index: 0, line: 0, column: 0 });
10394
- _Tokenizer_markStack.set(this, []);
10395
- __classPrivateFieldSet(this, _Tokenizer_str, str, "f");
10396
- __classPrivateFieldSet(this, _Tokenizer_keywords, keywords, "f");
10397
- __classPrivateFieldSet(this, _Tokenizer_operators, operators, "f");
10410
+ return this.right.eval(this.left.eval(context));
10398
10411
  }
10399
- tokenize() {
10400
- while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length) {
10401
- const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
10402
- if (token) {
10403
- __classPrivateFieldGet(this, _Tokenizer_result, "f").push(token);
10404
- }
10405
- }
10406
- return __classPrivateFieldGet(this, _Tokenizer_result, "f");
10412
+ toString() {
10413
+ return `${this.left.toString()}.${this.right.toString()}`;
10407
10414
  }
10408
10415
  }
10409
- _Tokenizer_str = new WeakMap(), _Tokenizer_keywords = new WeakMap(), _Tokenizer_operators = new WeakMap(), _Tokenizer_result = new WeakMap(), _Tokenizer_pos = new WeakMap(), _Tokenizer_markStack = new WeakMap(), _Tokenizer_instances = new WeakSet(), _Tokenizer_prevToken = function _Tokenizer_prevToken() {
10410
- return __classPrivateFieldGet(this, _Tokenizer_result, "f").slice(-1)[0];
10411
- }, _Tokenizer_peekToken = function _Tokenizer_peekToken() {
10412
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
10413
- const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
10414
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_reset).call(this);
10415
- return token;
10416
- }, _Tokenizer_consumeToken = function _Tokenizer_consumeToken() {
10417
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhitespace).call(this);
10418
- const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
10419
- if (!c) {
10420
- return undefined;
10416
+ class UnionAtom extends InfixOperatorAtom {
10417
+ constructor(left, right) {
10418
+ super('|', left, right);
10421
10419
  }
10422
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_mark).call(this);
10423
- const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
10424
- if (c === '/' && next === '*') {
10425
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeMultiLineComment).call(this);
10420
+ eval(context) {
10421
+ const leftResult = this.left.eval(context);
10422
+ const rightResult = this.right.eval(context);
10423
+ return removeDuplicates([...leftResult, ...rightResult]);
10426
10424
  }
10427
- if (c === '/' && next === '/') {
10428
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSingleLineComment).call(this);
10425
+ }
10426
+ class EqualsAtom extends InfixOperatorAtom {
10427
+ constructor(left, right) {
10428
+ super('=', left, right);
10429
10429
  }
10430
- if (c === "'" || c === '"') {
10431
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeString).call(this, c);
10430
+ eval(context) {
10431
+ const leftValue = this.left.eval(context);
10432
+ const rightValue = this.right.eval(context);
10433
+ return fhirPathArrayEquals(leftValue, rightValue);
10432
10434
  }
10433
- if (c === '`') {
10434
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeBacktickSymbol).call(this);
10435
+ }
10436
+ class NotEqualsAtom extends InfixOperatorAtom {
10437
+ constructor(left, right) {
10438
+ super('!=', left, right);
10435
10439
  }
10436
- if (c === '@') {
10437
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeDateTime).call(this);
10440
+ eval(context) {
10441
+ const leftValue = this.left.eval(context);
10442
+ const rightValue = this.right.eval(context);
10443
+ return fhirPathNot(fhirPathArrayEquals(leftValue, rightValue));
10438
10444
  }
10439
- if (c.match(/\d/)) {
10440
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeNumber).call(this);
10445
+ }
10446
+ class EquivalentAtom extends InfixOperatorAtom {
10447
+ constructor(left, right) {
10448
+ super('~', left, right);
10441
10449
  }
10442
- if (c.match(/\w/)) {
10443
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
10450
+ eval(context) {
10451
+ const leftValue = this.left.eval(context);
10452
+ const rightValue = this.right.eval(context);
10453
+ return fhirPathArrayEquivalent(leftValue, rightValue);
10444
10454
  }
10445
- if (c === '$' && next.match(/\w/)) {
10446
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
10455
+ }
10456
+ class NotEquivalentAtom extends InfixOperatorAtom {
10457
+ constructor(left, right) {
10458
+ super('!~', left, right);
10447
10459
  }
10448
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeOperator).call(this);
10449
- }, _Tokenizer_consumeWhitespace = function _Tokenizer_consumeWhitespace() {
10450
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\s/));
10451
- }, _Tokenizer_consumeMultiLineComment = function _Tokenizer_consumeMultiLineComment() {
10452
- const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
10453
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '*' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this) !== '/');
10454
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10455
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10456
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
10457
- }, _Tokenizer_consumeSingleLineComment = function _Tokenizer_consumeSingleLineComment() {
10458
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Comment', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '\n'));
10459
- }, _Tokenizer_consumeString = function _Tokenizer_consumeString(endChar) {
10460
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10461
- const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'String', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prev).call(this) === '\\' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== endChar));
10462
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10463
- return result;
10464
- }, _Tokenizer_consumeBacktickSymbol = function _Tokenizer_consumeBacktickSymbol() {
10465
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10466
- const result = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '`'));
10467
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10468
- return result;
10469
- }, _Tokenizer_consumeDateTime = function _Tokenizer_consumeDateTime() {
10470
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this); // Consume "@"
10471
- const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
10472
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d-]/));
10473
- if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'T') {
10474
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10475
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
10476
- if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
10477
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10478
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
10460
+ eval(context) {
10461
+ const leftValue = this.left.eval(context);
10462
+ const rightValue = this.right.eval(context);
10463
+ return fhirPathNot(fhirPathArrayEquivalent(leftValue, rightValue));
10464
+ }
10465
+ }
10466
+ class IsAtom extends InfixOperatorAtom {
10467
+ constructor(left, right) {
10468
+ super('is', left, right);
10469
+ }
10470
+ eval(context) {
10471
+ const leftValue = this.left.eval(context);
10472
+ if (leftValue.length !== 1) {
10473
+ return [];
10479
10474
  }
10480
- if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'Z') {
10481
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10475
+ const typeName = this.right.name;
10476
+ return booleanToTypedValue(fhirPathIs(leftValue[0], typeName));
10477
+ }
10478
+ }
10479
+ /**
10480
+ * 6.5.1. and
10481
+ * Returns true if both operands evaluate to true,
10482
+ * false if either operand evaluates to false,
10483
+ * and the empty collection otherwise.
10484
+ */
10485
+ class AndAtom extends InfixOperatorAtom {
10486
+ constructor(left, right) {
10487
+ super('and', left, right);
10488
+ }
10489
+ eval(context) {
10490
+ const leftValue = this.left.eval(context);
10491
+ const rightValue = this.right.eval(context);
10492
+ if (leftValue[0]?.value === true && rightValue[0]?.value === true) {
10493
+ return booleanToTypedValue(true);
10482
10494
  }
10483
- else if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '+' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '-') {
10484
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10485
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
10495
+ if (leftValue[0]?.value === false || rightValue[0]?.value === false) {
10496
+ return booleanToTypedValue(false);
10486
10497
  }
10498
+ return [];
10487
10499
  }
10488
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'DateTime', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
10489
- }, _Tokenizer_consumeNumber = function _Tokenizer_consumeNumber() {
10490
- const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
10491
- let id = 'Number';
10492
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
10493
- if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
10494
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10495
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
10500
+ }
10501
+ class OrAtom extends InfixOperatorAtom {
10502
+ constructor(left, right) {
10503
+ super('or', left, right);
10496
10504
  }
10497
- if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === ' ') {
10498
- if (isUnitToken(__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peekToken).call(this))) {
10499
- id = 'Quantity';
10500
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
10505
+ eval(context) {
10506
+ const leftValue = this.left.eval(context);
10507
+ if (toJsBoolean(leftValue)) {
10508
+ return leftValue;
10501
10509
  }
10510
+ const rightValue = this.right.eval(context);
10511
+ if (toJsBoolean(rightValue)) {
10512
+ return rightValue;
10513
+ }
10514
+ return [];
10502
10515
  }
10503
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, id, __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index));
10504
- }, _Tokenizer_consumeSymbol = function _Tokenizer_consumeSymbol() {
10505
- var _a;
10506
- const value = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/));
10507
- if (((_a = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prevToken).call(this)) === null || _a === void 0 ? void 0 : _a.value) !== '.' && __classPrivateFieldGet(this, _Tokenizer_keywords, "f").includes(value)) {
10508
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, value, value);
10509
- }
10510
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', value);
10511
- }, _Tokenizer_consumeOperator = function _Tokenizer_consumeOperator() {
10512
- const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
10513
- const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
10514
- const twoCharOp = c + next;
10515
- if (__classPrivateFieldGet(this, _Tokenizer_operators, "f").includes(twoCharOp)) {
10516
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10517
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10518
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, twoCharOp, twoCharOp);
10516
+ }
10517
+ /**
10518
+ * 6.5.4. xor
10519
+ * Returns true if exactly one of the operands evaluates to true,
10520
+ * false if either both operands evaluate to true or both operands evaluate to false,
10521
+ * and the empty collection otherwise.
10522
+ */
10523
+ class XorAtom extends InfixOperatorAtom {
10524
+ constructor(left, right) {
10525
+ super('xor', left, right);
10519
10526
  }
10520
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10521
- return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, c, c);
10522
- }, _Tokenizer_consumeWhile = function _Tokenizer_consumeWhile(condition) {
10523
- const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f").index;
10524
- while (__classPrivateFieldGet(this, _Tokenizer_pos, "f").index < __classPrivateFieldGet(this, _Tokenizer_str, "f").length && condition()) {
10525
- __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_advance).call(this);
10527
+ eval(context) {
10528
+ const leftResult = this.left.eval(context);
10529
+ const rightResult = this.right.eval(context);
10530
+ if (leftResult.length === 0 && rightResult.length === 0) {
10531
+ return [];
10532
+ }
10533
+ const leftValue = leftResult.length === 0 ? null : leftResult[0].value;
10534
+ const rightValue = rightResult.length === 0 ? null : rightResult[0].value;
10535
+ if ((leftValue === true && rightValue !== true) || (leftValue !== true && rightValue === true)) {
10536
+ return booleanToTypedValue(true);
10537
+ }
10538
+ if ((leftValue === true && rightValue === true) || (leftValue === false && rightValue === false)) {
10539
+ return booleanToTypedValue(false);
10540
+ }
10541
+ return [];
10526
10542
  }
10527
- return __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f").index);
10528
- }, _Tokenizer_curr = function _Tokenizer_curr() {
10529
- return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index];
10530
- }, _Tokenizer_prev = function _Tokenizer_prev() {
10531
- var _a;
10532
- return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1]) !== null && _a !== void 0 ? _a : '';
10533
- }, _Tokenizer_peek = function _Tokenizer_peek() {
10534
- var _a;
10535
- return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1]) !== null && _a !== void 0 ? _a : '';
10536
- }, _Tokenizer_mark = function _Tokenizer_mark() {
10537
- __classPrivateFieldGet(this, _Tokenizer_markStack, "f").push(Object.assign({}, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
10538
- }, _Tokenizer_reset = function _Tokenizer_reset() {
10539
- const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
10540
- if (!mark) {
10541
- throw new Error('No mark to reset to');
10543
+ }
10544
+ class FunctionAtom {
10545
+ constructor(name, args) {
10546
+ this.name = name;
10547
+ this.args = args;
10542
10548
  }
10543
- __classPrivateFieldGet(this, _Tokenizer_pos, "f").index = mark.index;
10544
- __classPrivateFieldGet(this, _Tokenizer_pos, "f").line = mark.line;
10545
- __classPrivateFieldGet(this, _Tokenizer_pos, "f").column = mark.column;
10546
- }, _Tokenizer_advance = function _Tokenizer_advance() {
10547
- __classPrivateFieldGet(this, _Tokenizer_pos, "f").index++;
10548
- if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '\n') {
10549
- __classPrivateFieldGet(this, _Tokenizer_pos, "f").line++;
10550
- __classPrivateFieldGet(this, _Tokenizer_pos, "f").column = 0;
10549
+ eval(context) {
10550
+ const impl = functions[this.name];
10551
+ if (!impl) {
10552
+ throw new Error('Unrecognized function: ' + this.name);
10553
+ }
10554
+ return impl(context, ...this.args);
10551
10555
  }
10552
- else {
10553
- __classPrivateFieldGet(this, _Tokenizer_pos, "f").column++;
10556
+ toString() {
10557
+ return `${this.name}(${this.args.map((arg) => arg.toString()).join(', ')})`;
10554
10558
  }
10555
- }, _Tokenizer_buildToken = function _Tokenizer_buildToken(id, value) {
10556
- const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
10557
- if (!mark) {
10558
- throw new Error('No mark for token');
10559
+ }
10560
+ class IndexerAtom {
10561
+ constructor(left, expr) {
10562
+ this.left = left;
10563
+ this.expr = expr;
10559
10564
  }
10560
- return Object.assign({ id,
10561
- value }, mark);
10562
- };
10563
- function isUnitToken(token) {
10564
- if (token) {
10565
- if (token.id === 'String') {
10566
- return true;
10565
+ eval(context) {
10566
+ const evalResult = this.expr.eval(context);
10567
+ if (evalResult.length !== 1) {
10568
+ return [];
10567
10569
  }
10568
- if (token.id === 'Symbol' && STANDARD_UNITS.includes(token.value)) {
10569
- return true;
10570
+ const index = evalResult[0].value;
10571
+ if (typeof index !== 'number') {
10572
+ throw new Error(`Invalid indexer expression: should return integer}`);
10573
+ }
10574
+ const leftResult = this.left.eval(context);
10575
+ if (!(index in leftResult)) {
10576
+ return [];
10570
10577
  }
10578
+ return [leftResult[index]];
10579
+ }
10580
+ toString() {
10581
+ return `${this.left.toString()}[${this.expr.toString()}]`;
10571
10582
  }
10572
- return false;
10573
10583
  }
10574
10584
 
10575
- const FHIRPATH_KEYWORDS = ['true', 'false', 'and', 'as', 'contains', 'div', 'in', 'is', 'mod', 'or', 'xor'];
10585
+ const FHIRPATH_KEYWORDS = ['true', 'false'];
10576
10586
  const FHIRPATH_OPERATORS = ['!=', '!~', '<=', '>=', '{}', '->'];
10577
10587
  function tokenize(str) {
10578
10588
  return new Tokenizer(str, FHIRPATH_KEYWORDS, FHIRPATH_OPERATORS).tokenize();
@@ -10582,7 +10592,7 @@
10582
10592
  parse(parser) {
10583
10593
  const expr = parser.consumeAndParse();
10584
10594
  if (!parser.match(')')) {
10585
- throw new Error('Parse error: expected `)`');
10595
+ throw new Error('Parse error: expected `)` got `' + parser.peek()?.value + '`');
10586
10596
  }
10587
10597
  return expr;
10588
10598
  },
@@ -10595,24 +10605,21 @@
10595
10605
  }
10596
10606
  return new IndexerAtom(left, expr);
10597
10607
  },
10598
- precedence: 2 /* Precedence.Indexer */,
10608
+ precedence: 2 /* OperatorPrecedence.Indexer */,
10599
10609
  };
10600
10610
  const FUNCTION_CALL_PARSELET = {
10601
10611
  parse(parser, left) {
10602
10612
  if (!(left instanceof SymbolAtom)) {
10603
10613
  throw new Error('Unexpected parentheses');
10604
10614
  }
10605
- if (!(left.name in functions)) {
10606
- throw new Error('Unrecognized function: ' + left.name);
10607
- }
10608
10615
  const args = [];
10609
10616
  while (!parser.match(')')) {
10610
10617
  args.push(parser.consumeAndParse());
10611
10618
  parser.match(',');
10612
10619
  }
10613
- return new FunctionAtom(left.name, args, functions[left.name]);
10620
+ return new FunctionAtom(left.name, args); //, functions[left.name]);
10614
10621
  },
10615
- precedence: 0 /* Precedence.FunctionCall */,
10622
+ precedence: 0 /* OperatorPrecedence.FunctionCall */,
10616
10623
  };
10617
10624
  function parseQuantity(str) {
10618
10625
  const parts = str.split(' ');
@@ -10647,32 +10654,32 @@
10647
10654
  .registerPrefix('(', PARENTHESES_PARSELET)
10648
10655
  .registerInfix('[', INDEXER_PARSELET)
10649
10656
  .registerInfix('(', FUNCTION_CALL_PARSELET)
10650
- .prefix('+', 3 /* Precedence.UnaryAdd */, (_, right) => new UnaryOperatorAtom(right, (x) => x))
10651
- .prefix('-', 3 /* Precedence.UnarySubtract */, (_, right) => new ArithemticOperatorAtom(right, right, (_, y) => -y))
10652
- .infixLeft('.', 1 /* Precedence.Dot */, (left, _, right) => new DotAtom(left, right))
10653
- .infixLeft('/', 4 /* Precedence.Divide */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x / y))
10654
- .infixLeft('*', 4 /* Precedence.Multiply */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x * y))
10655
- .infixLeft('+', 5 /* Precedence.Add */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x + y))
10656
- .infixLeft('-', 5 /* Precedence.Subtract */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x - y))
10657
- .infixLeft('|', 7 /* Precedence.Union */, (left, _, right) => new UnionAtom(left, right))
10658
- .infixLeft('=', 9 /* Precedence.Equals */, (left, _, right) => new EqualsAtom(left, right))
10659
- .infixLeft('!=', 9 /* Precedence.Equals */, (left, _, right) => new NotEqualsAtom(left, right))
10660
- .infixLeft('~', 9 /* Precedence.Equivalent */, (left, _, right) => new EquivalentAtom(left, right))
10661
- .infixLeft('!~', 9 /* Precedence.NotEquivalent */, (left, _, right) => new NotEquivalentAtom(left, right))
10662
- .infixLeft('<', 8 /* Precedence.LessThan */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x < y))
10663
- .infixLeft('<=', 8 /* Precedence.LessThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x <= y))
10664
- .infixLeft('>', 8 /* Precedence.GreaterThan */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x > y))
10665
- .infixLeft('>=', 8 /* Precedence.GreaterThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x >= y))
10666
- .infixLeft('&', 5 /* Precedence.Ampersand */, (left, _, right) => new ConcatAtom(left, right))
10667
- .infixLeft('and', 6 /* Precedence.Is */, (left, _, right) => new AndAtom(left, right))
10668
- .infixLeft('as', 6 /* Precedence.Is */, (left, _, right) => new AsAtom(left, right))
10669
- .infixLeft('contains', 6 /* Precedence.Is */, (left, _, right) => new ContainsAtom(left, right))
10670
- .infixLeft('div', 6 /* Precedence.Is */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => (x / y) | 0))
10671
- .infixLeft('in', 6 /* Precedence.Is */, (left, _, right) => new InAtom(left, right))
10672
- .infixLeft('is', 6 /* Precedence.Is */, (left, _, right) => new IsAtom(left, right))
10673
- .infixLeft('mod', 6 /* Precedence.Is */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x % y))
10674
- .infixLeft('or', 6 /* Precedence.Is */, (left, _, right) => new OrAtom(left, right))
10675
- .infixLeft('xor', 6 /* Precedence.Is */, (left, _, right) => new XorAtom(left, right));
10657
+ .prefix('+', 3 /* OperatorPrecedence.UnaryAdd */, (_, right) => new UnaryOperatorAtom('+', right, (x) => x))
10658
+ .prefix('-', 3 /* OperatorPrecedence.UnarySubtract */, (_, right) => new ArithemticOperatorAtom('-', right, right, (_, y) => -y))
10659
+ .infixLeft('.', 1 /* OperatorPrecedence.Dot */, (left, _, right) => new DotAtom(left, right))
10660
+ .infixLeft('/', 4 /* OperatorPrecedence.Divide */, (left, _, right) => new ArithemticOperatorAtom('/', left, right, (x, y) => x / y))
10661
+ .infixLeft('*', 4 /* OperatorPrecedence.Multiply */, (left, _, right) => new ArithemticOperatorAtom('*', left, right, (x, y) => x * y))
10662
+ .infixLeft('+', 5 /* OperatorPrecedence.Add */, (left, _, right) => new ArithemticOperatorAtom('+', left, right, (x, y) => x + y))
10663
+ .infixLeft('-', 5 /* OperatorPrecedence.Subtract */, (left, _, right) => new ArithemticOperatorAtom('-', left, right, (x, y) => x - y))
10664
+ .infixLeft('|', 7 /* OperatorPrecedence.Union */, (left, _, right) => new UnionAtom(left, right))
10665
+ .infixLeft('=', 9 /* OperatorPrecedence.Equals */, (left, _, right) => new EqualsAtom(left, right))
10666
+ .infixLeft('!=', 9 /* OperatorPrecedence.Equals */, (left, _, right) => new NotEqualsAtom(left, right))
10667
+ .infixLeft('~', 9 /* OperatorPrecedence.Equivalent */, (left, _, right) => new EquivalentAtom(left, right))
10668
+ .infixLeft('!~', 9 /* OperatorPrecedence.NotEquivalent */, (left, _, right) => new NotEquivalentAtom(left, right))
10669
+ .infixLeft('<', 8 /* OperatorPrecedence.LessThan */, (left, _, right) => new ArithemticOperatorAtom('<', left, right, (x, y) => x < y))
10670
+ .infixLeft('<=', 8 /* OperatorPrecedence.LessThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom('<=', left, right, (x, y) => x <= y))
10671
+ .infixLeft('>', 8 /* OperatorPrecedence.GreaterThan */, (left, _, right) => new ArithemticOperatorAtom('>', left, right, (x, y) => x > y))
10672
+ .infixLeft('>=', 8 /* OperatorPrecedence.GreaterThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom('>=', left, right, (x, y) => x >= y))
10673
+ .infixLeft('&', 5 /* OperatorPrecedence.Ampersand */, (left, _, right) => new ConcatAtom(left, right))
10674
+ .infixLeft('and', 6 /* OperatorPrecedence.Is */, (left, _, right) => new AndAtom(left, right))
10675
+ .infixLeft('as', 6 /* OperatorPrecedence.Is */, (left, _, right) => new AsAtom(left, right))
10676
+ .infixLeft('contains', 6 /* OperatorPrecedence.Is */, (left, _, right) => new ContainsAtom(left, right))
10677
+ .infixLeft('div', 6 /* OperatorPrecedence.Is */, (left, _, right) => new ArithemticOperatorAtom('div', left, right, (x, y) => (x / y) | 0))
10678
+ .infixLeft('in', 6 /* OperatorPrecedence.Is */, (left, _, right) => new InAtom(left, right))
10679
+ .infixLeft('is', 6 /* OperatorPrecedence.Is */, (left, _, right) => new IsAtom(left, right))
10680
+ .infixLeft('mod', 6 /* OperatorPrecedence.Is */, (left, _, right) => new ArithemticOperatorAtom('mod', left, right, (x, y) => x % y))
10681
+ .infixLeft('or', 6 /* OperatorPrecedence.Is */, (left, _, right) => new OrAtom(left, right))
10682
+ .infixLeft('xor', 6 /* OperatorPrecedence.Is */, (left, _, right) => new XorAtom(left, right));
10676
10683
  }
10677
10684
  const fhirPathParserBuilder = initFhirPathParserBuilder();
10678
10685
  /**
@@ -10792,15 +10799,14 @@
10792
10799
  * @returns The HL7 "ACK" message.
10793
10800
  */
10794
10801
  buildAck() {
10795
- var _a, _b, _c, _d, _e, _f;
10796
10802
  const now = new Date();
10797
10803
  const msh = this.get('MSH');
10798
- const sendingApp = ((_a = msh === null || msh === void 0 ? void 0 : msh.get(2)) === null || _a === void 0 ? void 0 : _a.toString()) || '';
10799
- const sendingFacility = ((_b = msh === null || msh === void 0 ? void 0 : msh.get(3)) === null || _b === void 0 ? void 0 : _b.toString()) || '';
10800
- const receivingApp = ((_c = msh === null || msh === void 0 ? void 0 : msh.get(4)) === null || _c === void 0 ? void 0 : _c.toString()) || '';
10801
- const receivingFacility = ((_d = msh === null || msh === void 0 ? void 0 : msh.get(5)) === null || _d === void 0 ? void 0 : _d.toString()) || '';
10802
- const controlId = ((_e = msh === null || msh === void 0 ? void 0 : msh.get(9)) === null || _e === void 0 ? void 0 : _e.toString()) || '';
10803
- const versionId = ((_f = msh === null || msh === void 0 ? void 0 : msh.get(12)) === null || _f === void 0 ? void 0 : _f.toString()) || '2.5.1';
10804
+ const sendingApp = msh?.get(2)?.toString() || '';
10805
+ const sendingFacility = msh?.get(3)?.toString() || '';
10806
+ const receivingApp = msh?.get(4)?.toString() || '';
10807
+ const receivingFacility = msh?.get(5)?.toString() || '';
10808
+ const controlId = msh?.get(9)?.toString() || '';
10809
+ const versionId = msh?.get(12)?.toString() || '2.5.1';
10804
10810
  return new Hl7Message([
10805
10811
  new Hl7Segment([
10806
10812
  'MSH',
@@ -11162,8 +11168,7 @@
11162
11168
  * @returns The search parameter type details.
11163
11169
  */
11164
11170
  function getSearchParameterDetails(resourceType, searchParam) {
11165
- var _a, _b;
11166
- let result = (_b = (_a = globalSchema.types[resourceType]) === null || _a === void 0 ? void 0 : _a.searchParamsDetails) === null || _b === void 0 ? void 0 : _b[searchParam.code];
11171
+ let result = globalSchema.types[resourceType]?.searchParamsDetails?.[searchParam.code];
11167
11172
  if (!result) {
11168
11173
  result = buildSearchParamterDetails(resourceType, searchParam);
11169
11174
  }
@@ -11177,13 +11182,12 @@
11177
11182
  typeSchema.searchParamsDetails[code] = details;
11178
11183
  }
11179
11184
  function buildSearchParamterDetails(resourceType, searchParam) {
11180
- var _a, _b, _c, _d, _e, _f, _g;
11181
11185
  if (searchParam.code === '_lastUpdated') {
11182
11186
  return { columnName: 'lastUpdated', type: exports.SearchParameterType.DATETIME };
11183
11187
  }
11184
11188
  const code = searchParam.code;
11185
11189
  const columnName = convertCodeToColumnName(code);
11186
- const expression = (_a = getExpressionForResourceType(resourceType, searchParam.expression)) === null || _a === void 0 ? void 0 : _a.split('.');
11190
+ const expression = getExpressionForResourceType(resourceType, searchParam.expression)?.split('.');
11187
11191
  if (!expression) {
11188
11192
  // This happens on compound types
11189
11193
  // In the future, explore returning multiple column definitions
@@ -11197,14 +11201,15 @@
11197
11201
  for (let i = 1; i < expression.length; i++) {
11198
11202
  const propertyName = expression[i];
11199
11203
  elementDefinition =
11200
- (_d = (_c = (_b = globalSchema.types[baseType]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c[propertyName]) !== null && _d !== void 0 ? _d : (_f = (_e = globalSchema.types[baseType]) === null || _e === void 0 ? void 0 : _e.properties) === null || _f === void 0 ? void 0 : _f[propertyName + '[x]'];
11204
+ globalSchema.types[baseType]?.properties?.[propertyName] ??
11205
+ globalSchema.types[baseType]?.properties?.[propertyName + '[x]'];
11201
11206
  if (!elementDefinition) {
11202
11207
  throw new Error(`Element definition not found for ${resourceType} ${searchParam.code}`);
11203
11208
  }
11204
11209
  if (elementDefinition.max === '*') {
11205
11210
  array = true;
11206
11211
  }
11207
- propertyType = (_g = elementDefinition.type) === null || _g === void 0 ? void 0 : _g[0].code;
11212
+ propertyType = elementDefinition.type?.[0].code;
11208
11213
  if (!propertyType) {
11209
11214
  // This happens when one of parent properties uses contentReference
11210
11215
  // In the future, explore following the reference
@@ -11319,9 +11324,8 @@
11319
11324
  * @returns True if the resource satisfies the search filter.
11320
11325
  */
11321
11326
  function matchesSearchFilter(resource, searchRequest, filter) {
11322
- var _a, _b;
11323
- const searchParam = (_b = (_a = globalSchema.types[searchRequest.resourceType]) === null || _a === void 0 ? void 0 : _a.searchParams) === null || _b === void 0 ? void 0 : _b[filter.code];
11324
- switch (searchParam === null || searchParam === void 0 ? void 0 : searchParam.type) {
11327
+ const searchParam = globalSchema.types[searchRequest.resourceType]?.searchParams?.[filter.code];
11328
+ switch (searchParam?.type) {
11325
11329
  case 'reference':
11326
11330
  return matchesReferenceFilter(resource, filter, searchParam);
11327
11331
  case 'string':
@@ -11352,7 +11356,7 @@
11352
11356
  // In previous versions, the resource type was not required in compartment values
11353
11357
  // So, "123" would match "Patient/123"
11354
11358
  // We need to maintain this behavior for backwards compatibility
11355
- match = references.some((reference) => reference === null || reference === void 0 ? void 0 : reference.endsWith('/' + filterValue));
11359
+ match = references.some((reference) => reference?.endsWith('/' + filterValue));
11356
11360
  }
11357
11361
  if (match) {
11358
11362
  return !negated;
@@ -11620,8 +11624,7 @@
11620
11624
  }
11621
11625
  class OperationOutcomeError extends Error {
11622
11626
  constructor(outcome) {
11623
- var _a, _b;
11624
- super((_b = (_a = outcome === null || outcome === void 0 ? void 0 : outcome.issue) === null || _a === void 0 ? void 0 : _a[0].details) === null || _b === void 0 ? void 0 : _b.text);
11627
+ super(outcome?.issue?.[0].details?.text);
11625
11628
  this.outcome = outcome;
11626
11629
  }
11627
11630
  }
@@ -11631,7 +11634,6 @@
11631
11634
  * @returns A display string for the error.
11632
11635
  */
11633
11636
  function normalizeErrorString(error) {
11634
- var _a, _b, _c, _d;
11635
11637
  if (!error) {
11636
11638
  return 'Unknown error';
11637
11639
  }
@@ -11643,7 +11645,7 @@
11643
11645
  }
11644
11646
  if (typeof error === 'object' && 'resourceType' in error) {
11645
11647
  const outcome = error;
11646
- return (_d = (_c = (_b = (_a = outcome.issue) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.details) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : 'Unknown error';
11648
+ return outcome.issue?.[0]?.details?.text ?? 'Unknown error';
11647
11649
  }
11648
11650
  return JSON.stringify(error);
11649
11651
  }
@@ -11716,6 +11718,7 @@
11716
11718
  exports.formatFamilyName = formatFamilyName;
11717
11719
  exports.formatGivenName = formatGivenName;
11718
11720
  exports.formatHumanName = formatHumanName;
11721
+ exports.formatMoney = formatMoney;
11719
11722
  exports.formatObservationValue = formatObservationValue;
11720
11723
  exports.formatPeriod = formatPeriod;
11721
11724
  exports.formatQuantity = formatQuantity;
@@ -11782,4 +11785,4 @@
11782
11785
  exports.unauthorized = unauthorized;
11783
11786
 
11784
11787
  }));
11785
- //# sourceMappingURL=index.js.map
11788
+ //# sourceMappingURL=index.cjs.map