@medplum/core 1.0.5 → 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 (95) hide show
  1. package/README.md +9 -7
  2. package/dist/cjs/format.d.ts +2 -1
  3. package/dist/cjs/{index.js → index.cjs} +325 -363
  4. package/dist/cjs/index.cjs.map +1 -0
  5. package/dist/cjs/index.min.cjs +1 -0
  6. package/dist/cjs/search.d.ts +2 -1
  7. package/dist/esm/{base-schema.json.js → base-schema.json.mjs} +1 -1
  8. package/dist/esm/{base-schema.json.js.map → base-schema.json.mjs.map} +1 -1
  9. package/dist/esm/{cache.js → cache.mjs} +2 -2
  10. package/dist/esm/cache.mjs.map +1 -0
  11. package/dist/esm/{client.js → client.mjs} +241 -246
  12. package/dist/esm/client.mjs.map +1 -0
  13. package/dist/esm/{crypto.js → crypto.mjs} +4 -7
  14. package/dist/esm/crypto.mjs.map +1 -0
  15. package/dist/esm/{eventtarget.js → eventtarget.mjs} +2 -2
  16. package/dist/esm/eventtarget.mjs.map +1 -0
  17. package/dist/esm/fhirlexer/{parse.js → parse.mjs} +5 -6
  18. package/dist/esm/fhirlexer/parse.mjs.map +1 -0
  19. package/dist/esm/fhirlexer/{tokenize.js → tokenize.mjs} +11 -11
  20. package/dist/esm/fhirlexer/tokenize.mjs.map +1 -0
  21. package/dist/esm/fhirpath/{atoms.js → atoms.mjs} +11 -12
  22. package/dist/esm/fhirpath/atoms.mjs.map +1 -0
  23. package/dist/esm/fhirpath/{date.js → date.mjs} +1 -1
  24. package/dist/esm/fhirpath/date.mjs.map +1 -0
  25. package/dist/esm/fhirpath/{functions.js → functions.mjs} +16 -22
  26. package/dist/esm/fhirpath/functions.mjs.map +1 -0
  27. package/dist/esm/fhirpath/{parse.js → parse.mjs} +9 -10
  28. package/dist/esm/fhirpath/parse.mjs.map +1 -0
  29. package/dist/esm/fhirpath/{tokenize.js → tokenize.mjs} +3 -3
  30. package/dist/esm/fhirpath/tokenize.mjs.map +1 -0
  31. package/dist/esm/fhirpath/{utils.js → utils.mjs} +6 -7
  32. package/dist/esm/fhirpath/utils.mjs.map +1 -0
  33. package/dist/esm/format.d.ts +2 -1
  34. package/dist/esm/{format.js → format.mjs} +29 -21
  35. package/dist/esm/format.mjs.map +1 -0
  36. package/dist/esm/{hl7.js → hl7.mjs} +8 -9
  37. package/dist/esm/hl7.mjs.map +1 -0
  38. package/dist/esm/index.min.mjs +1 -0
  39. package/dist/esm/{index.js → index.mjs} +17 -17
  40. package/dist/esm/index.mjs.map +1 -0
  41. package/dist/esm/{jwt.js → jwt.mjs} +1 -1
  42. package/dist/esm/jwt.mjs.map +1 -0
  43. package/dist/esm/{match.js → match.mjs} +12 -13
  44. package/dist/esm/match.mjs.map +1 -0
  45. package/dist/esm/node_modules/tslib/{tslib.es6.js → tslib.es6.mjs} +2 -12
  46. package/dist/esm/node_modules/tslib/tslib.es6.mjs.map +1 -0
  47. package/dist/esm/{outcomes.js → outcomes.mjs} +3 -5
  48. package/dist/esm/outcomes.mjs.map +1 -0
  49. package/dist/esm/{readablepromise.js → readablepromise.mjs} +2 -2
  50. package/dist/esm/readablepromise.mjs.map +1 -0
  51. package/dist/esm/search.d.ts +2 -1
  52. package/dist/esm/{search.js → search.mjs} +1 -1
  53. package/dist/esm/search.mjs.map +1 -0
  54. package/dist/esm/{searchparams.js → searchparams.mjs} +8 -9
  55. package/dist/esm/searchparams.mjs.map +1 -0
  56. package/dist/esm/{storage.js → storage.mjs} +4 -5
  57. package/dist/esm/storage.mjs.map +1 -0
  58. package/dist/esm/{types.js → types.mjs} +6 -9
  59. package/dist/esm/types.mjs.map +1 -0
  60. package/dist/esm/{utils.js → utils.mjs} +15 -26
  61. package/dist/esm/utils.mjs.map +1 -0
  62. package/package.json +5 -5
  63. package/rollup.config.mjs +6 -7
  64. package/dist/cjs/fhirmapper/testall.d.ts +0 -1
  65. package/dist/cjs/index.js.map +0 -1
  66. package/dist/cjs/index.min.js +0 -2
  67. package/dist/cjs/index.min.js.map +0 -1
  68. package/dist/esm/cache.js.map +0 -1
  69. package/dist/esm/client.js.map +0 -1
  70. package/dist/esm/crypto.js.map +0 -1
  71. package/dist/esm/eventtarget.js.map +0 -1
  72. package/dist/esm/fhirlexer/parse.js.map +0 -1
  73. package/dist/esm/fhirlexer/tokenize.js.map +0 -1
  74. package/dist/esm/fhirmapper/testall.d.ts +0 -1
  75. package/dist/esm/fhirpath/atoms.js.map +0 -1
  76. package/dist/esm/fhirpath/date.js.map +0 -1
  77. package/dist/esm/fhirpath/functions.js.map +0 -1
  78. package/dist/esm/fhirpath/parse.js.map +0 -1
  79. package/dist/esm/fhirpath/tokenize.js.map +0 -1
  80. package/dist/esm/fhirpath/utils.js.map +0 -1
  81. package/dist/esm/format.js.map +0 -1
  82. package/dist/esm/hl7.js.map +0 -1
  83. package/dist/esm/index.js.map +0 -1
  84. package/dist/esm/index.min.js +0 -2
  85. package/dist/esm/index.min.js.map +0 -1
  86. package/dist/esm/jwt.js.map +0 -1
  87. package/dist/esm/match.js.map +0 -1
  88. package/dist/esm/node_modules/tslib/tslib.es6.js.map +0 -1
  89. package/dist/esm/outcomes.js.map +0 -1
  90. package/dist/esm/readablepromise.js.map +0 -1
  91. package/dist/esm/search.js.map +0 -1
  92. package/dist/esm/searchparams.js.map +0 -1
  93. package/dist/esm/storage.js.map +0 -1
  94. package/dist/esm/types.js.map +0 -1
  95. 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
  }
@@ -6487,7 +6468,7 @@
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
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;
6490
- const MEDPLUM_VERSION = "1.0.5-53328b63";
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);
@@ -6569,22 +6549,22 @@
6569
6549
  _MedplumClient_profilePromise.set(this, void 0);
6570
6550
  _MedplumClient_profile.set(this, void 0);
6571
6551
  _MedplumClient_config.set(this, void 0);
6572
- if (options === null || options === void 0 ? void 0 : options.baseUrl) {
6552
+ if (options?.baseUrl) {
6573
6553
  if (!options.baseUrl.startsWith('http')) {
6574
6554
  throw new Error('Base URL must start with http or https');
6575
6555
  }
6576
6556
  }
6577
- __classPrivateFieldSet(this, _MedplumClient_fetch, (options === null || options === void 0 ? void 0 : options.fetch) || window.fetch.bind(window), "f");
6578
- __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");
6579
6559
  __classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
6580
- __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");
6581
- __classPrivateFieldSet(this, _MedplumClient_cacheTime, (_b = options === null || options === void 0 ? void 0 : options.cacheTime) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TIME, "f");
6582
- __classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
6583
- __classPrivateFieldSet(this, _MedplumClient_clientId, (options === null || options === void 0 ? void 0 : options.clientId) || '', "f");
6584
- __classPrivateFieldSet(this, _MedplumClient_authorizeUrl, (options === null || options === void 0 ? void 0 : options.authorizeUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
6585
- __classPrivateFieldSet(this, _MedplumClient_tokenUrl, (options === null || options === void 0 ? void 0 : options.tokenUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
6586
- __classPrivateFieldSet(this, _MedplumClient_logoutUrl, (options === null || options === void 0 ? void 0 : options.logoutUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/logout', "f");
6587
- __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");
6588
6568
  const activeLogin = this.getActiveLogin();
6589
6569
  if (activeLogin) {
6590
6570
  __classPrivateFieldSet(this, _MedplumClient_accessToken, activeLogin.accessToken, "f");
@@ -6759,10 +6739,12 @@
6759
6739
  * @param newUserRequest Register request including email and password.
6760
6740
  * @returns Promise to the authentication response.
6761
6741
  */
6762
- startNewUser(newUserRequest) {
6763
- return __awaiter(this, void 0, void 0, function* () {
6764
- yield this.startPkce();
6765
- 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'),
6766
6748
  });
6767
6749
  }
6768
6750
  /**
@@ -6773,10 +6755,8 @@
6773
6755
  * @param newProjectRequest Register request including email and password.
6774
6756
  * @returns Promise to the authentication response.
6775
6757
  */
6776
- startNewProject(newProjectRequest) {
6777
- return __awaiter(this, void 0, void 0, function* () {
6778
- return this.post('auth/newproject', newProjectRequest);
6779
- });
6758
+ async startNewProject(newProjectRequest) {
6759
+ return this.post('auth/newproject', newProjectRequest);
6780
6760
  }
6781
6761
  /**
6782
6762
  * Initiates a new patient flow.
@@ -6786,10 +6766,8 @@
6786
6766
  * @param newPatientRequest Register request including email and password.
6787
6767
  * @returns Promise to the authentication response.
6788
6768
  */
6789
- startNewPatient(newPatientRequest) {
6790
- return __awaiter(this, void 0, void 0, function* () {
6791
- return this.post('auth/newpatient', newPatientRequest);
6792
- });
6769
+ async startNewPatient(newPatientRequest) {
6770
+ return this.post('auth/newpatient', newPatientRequest);
6793
6771
  }
6794
6772
  /**
6795
6773
  * Initiates a user login flow.
@@ -6797,12 +6775,14 @@
6797
6775
  * @param loginRequest Login request including email and password.
6798
6776
  * @returns Promise to the authentication response.
6799
6777
  */
6800
- startLogin(loginRequest) {
6801
- var _a;
6802
- return __awaiter(this, void 0, void 0, function* () {
6803
- const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
6804
- 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,
6805
- 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,
6806
6786
  });
6807
6787
  }
6808
6788
  /**
@@ -6813,12 +6793,14 @@
6813
6793
  * @param loginRequest Login request including Google credential response.
6814
6794
  * @returns Promise to the authentication response.
6815
6795
  */
6816
- startGoogleLogin(loginRequest) {
6817
- var _a;
6818
- return __awaiter(this, void 0, void 0, function* () {
6819
- const { codeChallenge, codeChallengeMethod } = this.getCodeChallenge(loginRequest);
6820
- 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,
6821
- 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,
6822
6804
  });
6823
6805
  }
6824
6806
  getCodeChallenge(loginRequest) {
@@ -6851,18 +6833,16 @@
6851
6833
  * This may result in navigating away to the sign in page.
6852
6834
  * @category Authentication
6853
6835
  */
6854
- signInWithRedirect() {
6855
- return __awaiter(this, void 0, void 0, function* () {
6856
- const urlParams = new URLSearchParams(window.location.search);
6857
- const code = urlParams.get('code');
6858
- if (!code) {
6859
- yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
6860
- return undefined;
6861
- }
6862
- else {
6863
- return this.processCode(code);
6864
- }
6865
- });
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
+ }
6866
6846
  }
6867
6847
  /**
6868
6848
  * Tries to sign out the user.
@@ -6978,7 +6958,7 @@
6978
6958
  if (cached) {
6979
6959
  return cached.value;
6980
6960
  }
6981
- 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));
6982
6962
  __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
6983
6963
  return promise;
6984
6964
  }
@@ -7011,7 +6991,7 @@
7011
6991
  if (cached) {
7012
6992
  return cached.value;
7013
6993
  }
7014
- 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) ?? []));
7015
6995
  __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
7016
6996
  return promise;
7017
6997
  }
@@ -7039,8 +7019,7 @@
7039
7019
  * @returns The resource if it is available in the cache; undefined otherwise.
7040
7020
  */
7041
7021
  getCached(resourceType, id) {
7042
- var _a;
7043
- 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;
7044
7023
  return cached && cached.isOk() ? cached.read() : undefined;
7045
7024
  }
7046
7025
  /**
@@ -7103,7 +7082,7 @@
7103
7082
  * @returns The resource if available; undefined otherwise.
7104
7083
  */
7105
7084
  readReference(reference, options = {}) {
7106
- const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
7085
+ const refString = reference?.reference;
7107
7086
  if (!refString) {
7108
7087
  return new ReadablePromise(Promise.reject(new Error('Missing reference')));
7109
7088
  }
@@ -7131,12 +7110,11 @@
7131
7110
  * @param resourceType The FHIR resource type.
7132
7111
  * @returns Promise to a schema with the requested resource type.
7133
7112
  */
7134
- requestSchema(resourceType) {
7135
- return __awaiter(this, void 0, void 0, function* () {
7136
- if (resourceType in globalSchema.types) {
7137
- return globalSchema;
7138
- }
7139
- const query = `{
7113
+ async requestSchema(resourceType) {
7114
+ if (resourceType in globalSchema.types) {
7115
+ return globalSchema;
7116
+ }
7117
+ const query = `{
7140
7118
  StructureDefinitionList(name: "${resourceType}") {
7141
7119
  name,
7142
7120
  description,
@@ -7165,15 +7143,14 @@
7165
7143
  target
7166
7144
  }
7167
7145
  }`.replace(/\s+/g, ' ');
7168
- const response = (yield this.graphql(query));
7169
- for (const structureDefinition of response.data.StructureDefinitionList) {
7170
- indexStructureDefinition(structureDefinition);
7171
- }
7172
- for (const searchParameter of response.data.SearchParameterList) {
7173
- indexSearchParameter(searchParameter);
7174
- }
7175
- return globalSchema;
7176
- });
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;
7177
7154
  }
7178
7155
  /**
7179
7156
  * Reads resource history by resource type and ID.
@@ -7311,11 +7288,8 @@
7311
7288
  * @param query The search query for an equivalent resource (should not include resource type or "?").
7312
7289
  * @returns The result of the create operation.
7313
7290
  */
7314
- createResourceIfNoneExist(resource, query) {
7315
- var _a;
7316
- return __awaiter(this, void 0, void 0, function* () {
7317
- return ((_a = (yield this.searchOne(resource.resourceType, query))) !== null && _a !== void 0 ? _a : this.createResource(resource));
7318
- });
7291
+ async createResourceIfNoneExist(resource, query) {
7292
+ return ((await this.searchOne(resource.resourceType, query)) ?? this.createResource(resource));
7319
7293
  }
7320
7294
  /**
7321
7295
  * Creates a FHIR `Binary` resource with the provided data content.
@@ -7402,14 +7376,12 @@
7402
7376
  * @param docDefinition The PDF document definition.
7403
7377
  * @returns The result of the create operation.
7404
7378
  */
7405
- createPdf(docDefinition, filename, tableLayouts, fonts) {
7406
- return __awaiter(this, void 0, void 0, function* () {
7407
- if (!__classPrivateFieldGet(this, _MedplumClient_createPdf, "f")) {
7408
- throw new Error('PDF creation not enabled');
7409
- }
7410
- const blob = yield __classPrivateFieldGet(this, _MedplumClient_createPdf, "f").call(this, docDefinition, tableLayouts, fonts);
7411
- return this.createBinary(blob, filename, 'application/pdf');
7412
- });
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');
7413
7385
  }
7414
7386
  /**
7415
7387
  * Creates a FHIR `Communication` resource with the provided data content.
@@ -7471,20 +7443,18 @@
7471
7443
  * @param resource The FHIR resource to update.
7472
7444
  * @returns The result of the update operation.
7473
7445
  */
7474
- updateResource(resource) {
7475
- return __awaiter(this, void 0, void 0, function* () {
7476
- if (!resource.resourceType) {
7477
- throw new Error('Missing resourceType');
7478
- }
7479
- if (!resource.id) {
7480
- throw new Error('Missing id');
7481
- }
7482
- this.invalidateSearches(resource.resourceType);
7483
- const result = yield this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
7484
- // On 304 not modified, result will be undefined
7485
- // Return the user input instead
7486
- return result !== null && result !== void 0 ? result : resource;
7487
- });
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;
7488
7458
  }
7489
7459
  /**
7490
7460
  * Updates a FHIR resource using JSONPatch operations.
@@ -7719,18 +7689,16 @@
7719
7689
  /**
7720
7690
  * @category Authentication
7721
7691
  */
7722
- setActiveLogin(login) {
7723
- return __awaiter(this, void 0, void 0, function* () {
7724
- __classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
7725
- __classPrivateFieldSet(this, _MedplumClient_refreshToken, login.refreshToken, "f");
7726
- __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
7727
- __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
7728
- __classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('activeLogin', login);
7729
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addLogin).call(this, login);
7730
- __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").clear();
7731
- __classPrivateFieldSet(this, _MedplumClient_refreshPromise, undefined, "f");
7732
- yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
7733
- });
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);
7734
7702
  }
7735
7703
  /**
7736
7704
  * @category Authentication
@@ -7751,8 +7719,7 @@
7751
7719
  * @category Authentication
7752
7720
  */
7753
7721
  getLogins() {
7754
- var _a;
7755
- return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
7722
+ return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins') ?? [];
7756
7723
  }
7757
7724
  /**
7758
7725
  * @category Authentication
@@ -7769,13 +7736,11 @@
7769
7736
  /**
7770
7737
  * @category User Profile
7771
7738
  */
7772
- getProfileAsync() {
7773
- return __awaiter(this, void 0, void 0, function* () {
7774
- if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
7775
- yield __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7776
- }
7777
- return this.getProfile();
7778
- });
7739
+ async getProfileAsync() {
7740
+ if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
7741
+ await __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7742
+ }
7743
+ return this.getProfile();
7779
7744
  }
7780
7745
  /**
7781
7746
  * @category User Profile
@@ -7790,30 +7755,26 @@
7790
7755
  * @param url The URL to request.
7791
7756
  * @returns Promise to the response body as a blob.
7792
7757
  */
7793
- download(url, options = {}) {
7794
- return __awaiter(this, void 0, void 0, function* () {
7795
- if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7796
- yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7797
- }
7798
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
7799
- const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url.toString(), options);
7800
- return response.blob();
7801
- });
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();
7802
7765
  }
7803
7766
  /**
7804
7767
  * Starts a new PKCE flow.
7805
7768
  * These PKCE values are stateful, and must survive redirects and page refreshes.
7806
7769
  */
7807
- startPkce() {
7808
- return __awaiter(this, void 0, void 0, function* () {
7809
- const pkceState = getRandomString();
7810
- sessionStorage.setItem('pkceState', pkceState);
7811
- const codeVerifier = getRandomString();
7812
- sessionStorage.setItem('codeVerifier', codeVerifier);
7813
- const arrayHash = yield encryptSHA256(codeVerifier);
7814
- const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
7815
- sessionStorage.setItem('codeChallenge', codeChallenge);
7816
- });
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);
7817
7778
  }
7818
7779
  /**
7819
7780
  * Processes an OAuth authorization code.
@@ -7840,39 +7801,35 @@
7840
7801
  * @param clientSecret The client secret.
7841
7802
  * @returns Promise that resolves to the client profile.
7842
7803
  */
7843
- startClientLogin(clientId, clientSecret) {
7844
- return __awaiter(this, void 0, void 0, function* () {
7845
- __classPrivateFieldSet(this, _MedplumClient_clientId, clientId, "f");
7846
- __classPrivateFieldSet(this, _MedplumClient_clientSecret, clientSecret, "f");
7847
- const formBody = new URLSearchParams();
7848
- formBody.set('grant_type', 'client_credentials');
7849
- formBody.set('client_id', clientId);
7850
- formBody.set('client_secret', clientSecret);
7851
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
7852
- });
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);
7853
7812
  }
7854
7813
  }
7855
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) {
7856
- 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); });
7815
+ const logins = this.getLogins().filter((login) => login.profile?.reference !== newLogin.profile?.reference);
7857
7816
  logins.push(newLogin);
7858
7817
  __classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('logins', logins);
7859
- }, _MedplumClient_refreshProfile = function _MedplumClient_refreshProfile() {
7860
- return __awaiter(this, void 0, void 0, function* () {
7861
- __classPrivateFieldSet(this, _MedplumClient_profilePromise, new Promise((resolve, reject) => {
7862
- this.get('auth/me')
7863
- .then((result) => {
7864
- __classPrivateFieldSet(this, _MedplumClient_profilePromise, undefined, "f");
7865
- __classPrivateFieldSet(this, _MedplumClient_profile, result.profile, "f");
7866
- __classPrivateFieldSet(this, _MedplumClient_config, result.config, "f");
7867
- this.dispatchEvent({ type: 'change' });
7868
- resolve(__classPrivateFieldGet(this, _MedplumClient_profile, "f"));
7869
- })
7870
- .catch(reject);
7871
- }), "f");
7872
- return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
7873
- });
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");
7874
7831
  }, _MedplumClient_getCacheEntry = function _MedplumClient_getCacheEntry(key, options) {
7875
- 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') {
7876
7833
  return undefined;
7877
7834
  }
7878
7835
  const entry = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(key);
@@ -7884,31 +7841,37 @@
7884
7841
  if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
7885
7842
  __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(key, { requestTime: Date.now(), value });
7886
7843
  }
7887
- }, _MedplumClient_request = function _MedplumClient_request(method, url, options = {}) {
7888
- return __awaiter(this, void 0, void 0, function* () {
7889
- if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7890
- yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7891
- }
7892
- if (!url.startsWith('http')) {
7893
- url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
7894
- }
7895
- options.method = method;
7896
- __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
7897
- const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
7898
- if (response.status === 401) {
7899
- // Refresh and try again
7900
- return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
7901
- }
7902
- if (response.status === 204 || response.status === 304) {
7903
- // No content or change
7904
- return undefined;
7905
- }
7906
- const obj = yield response.json();
7907
- if (response.status >= 400) {
7908
- throw obj;
7909
- }
7910
- return obj;
7911
- });
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;
7912
7875
  }, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
7913
7876
  if (!options.headers) {
7914
7877
  options.headers = {};
@@ -7952,18 +7915,22 @@
7952
7915
  __classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f").call(this);
7953
7916
  }
7954
7917
  return Promise.reject(new Error('Unauthenticated'));
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
- });
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
7935
  if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
7969
7936
  return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
@@ -7981,43 +7948,52 @@
7981
7948
  return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
7982
7949
  }
7983
7950
  return undefined;
7984
- }, _MedplumClient_fetchTokens = function _MedplumClient_fetchTokens(formBody) {
7985
- return __awaiter(this, void 0, void 0, function* () {
7986
- return __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
7987
- method: 'POST',
7988
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
7989
- body: formBody,
7990
- credentials: 'include',
7991
- })
7992
- .then((response) => {
7993
- if (!response.ok) {
7994
- throw new Error('Failed to fetch tokens');
7995
- }
7996
- return response.json();
7997
- })
7998
- .then((tokens) => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_verifyTokens).call(this, tokens))
7999
- .then(() => this.getProfile());
8000
- });
8001
- }, _MedplumClient_verifyTokens = function _MedplumClient_verifyTokens(tokens) {
8002
- return __awaiter(this, void 0, void 0, function* () {
8003
- const token = tokens.access_token;
8004
- // Verify token has not expired
8005
- const tokenPayload = parseJWTPayload(token);
8006
- if (Date.now() >= tokenPayload.exp * 1000) {
8007
- this.clear();
8008
- throw new Error('Token expired');
8009
- }
8010
- // Verify app_client_id
8011
- if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
8012
- this.clear();
8013
- throw new Error('Token was not issued for this audience');
8014
- }
8015
- yield this.setActiveLogin({
8016
- accessToken: token,
8017
- refreshToken: tokens.refresh_token,
8018
- project: tokens.project,
8019
- profile: tokens.profile,
8020
- });
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,
8021
7997
  });
8022
7998
  }, _MedplumClient_setupStorageListener = function _MedplumClient_setupStorageListener() {
8023
7999
  try {
@@ -8117,7 +8093,7 @@
8117
8093
  }
8118
8094
  match(expected) {
8119
8095
  const token = this.peek();
8120
- if ((token === null || token === void 0 ? void 0 : token.id) !== expected) {
8096
+ if (token?.id !== expected) {
8121
8097
  return false;
8122
8098
  }
8123
8099
  this.consume();
@@ -8149,15 +8125,14 @@
8149
8125
  return Infinity;
8150
8126
  }
8151
8127
  consume(expectedId, expectedValue) {
8152
- var _a, _b;
8153
8128
  if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
8154
8129
  throw Error('Cant consume unknown more tokens.');
8155
8130
  }
8156
- if (expectedId && ((_a = this.peek()) === null || _a === void 0 ? void 0 : _a.id) !== expectedId) {
8131
+ if (expectedId && this.peek()?.id !== expectedId) {
8157
8132
  const actual = this.peek();
8158
8133
  throw Error(`Expected ${expectedId} but got "${actual.id}" at line ${actual.line} column ${actual.column}.`);
8159
8134
  }
8160
- if (expectedValue && ((_b = this.peek()) === null || _b === void 0 ? void 0 : _b.value) !== expectedValue) {
8135
+ if (expectedValue && this.peek()?.value !== expectedValue) {
8161
8136
  const actual = this.peek();
8162
8137
  throw Error(`Expected "${expectedValue}" but got "${actual.value}" at line ${actual.line} column ${actual.column}.`);
8163
8138
  }
@@ -8313,9 +8288,8 @@
8313
8288
  }
8314
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));
8315
8290
  }, _Tokenizer_consumeSymbol = function _Tokenizer_consumeSymbol() {
8316
- var _a;
8317
8291
  const value = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/));
8318
- 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)) {
8292
+ if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prevToken).call(this)?.value !== '.' && __classPrivateFieldGet(this, _Tokenizer_keywords, "f").includes(value)) {
8319
8293
  return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, value, value);
8320
8294
  }
8321
8295
  return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', value);
@@ -8339,13 +8313,11 @@
8339
8313
  }, _Tokenizer_curr = function _Tokenizer_curr() {
8340
8314
  return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index];
8341
8315
  }, _Tokenizer_prev = function _Tokenizer_prev() {
8342
- var _a;
8343
- return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1]) !== null && _a !== void 0 ? _a : '';
8316
+ return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1] ?? '';
8344
8317
  }, _Tokenizer_peek = function _Tokenizer_peek() {
8345
- var _a;
8346
- return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1]) !== null && _a !== void 0 ? _a : '';
8318
+ return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1] ?? '';
8347
8319
  }, _Tokenizer_mark = function _Tokenizer_mark() {
8348
- __classPrivateFieldGet(this, _Tokenizer_markStack, "f").push(Object.assign({}, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
8320
+ __classPrivateFieldGet(this, _Tokenizer_markStack, "f").push({ ...__classPrivateFieldGet(this, _Tokenizer_pos, "f") });
8349
8321
  }, _Tokenizer_reset = function _Tokenizer_reset() {
8350
8322
  const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
8351
8323
  if (!mark) {
@@ -8368,8 +8340,11 @@
8368
8340
  if (!mark) {
8369
8341
  throw new Error('No mark for token');
8370
8342
  }
8371
- return Object.assign({ id,
8372
- value }, mark);
8343
+ return {
8344
+ id,
8345
+ value,
8346
+ ...mark,
8347
+ };
8373
8348
  };
8374
8349
  function isUnitToken(token) {
8375
8350
  if (token) {
@@ -8465,7 +8440,7 @@
8465
8440
  * @returns The value of the property and the property type.
8466
8441
  */
8467
8442
  function getTypedPropertyValue(input, path) {
8468
- if (!(input === null || input === void 0 ? void 0 : input.value)) {
8443
+ if (!input?.value) {
8469
8444
  return undefined;
8470
8445
  }
8471
8446
  const elementDefinition = getElementDefinition(input.type, path);
@@ -8485,7 +8460,6 @@
8485
8460
  * @returns The value of the property and the property type.
8486
8461
  */
8487
8462
  function getTypedPropertyValueWithSchema(input, path, property) {
8488
- var _a;
8489
8463
  const types = property.type;
8490
8464
  if (!types || types.length === 0) {
8491
8465
  return undefined;
@@ -8510,7 +8484,7 @@
8510
8484
  return undefined;
8511
8485
  }
8512
8486
  if (resultType === 'Element' || resultType === 'BackboneElement') {
8513
- resultType = buildTypeName((_a = property.path) === null || _a === void 0 ? void 0 : _a.split('.'));
8487
+ resultType = buildTypeName(property.path?.split('.'));
8514
8488
  }
8515
8489
  if (Array.isArray(resultValue)) {
8516
8490
  return resultValue.map((element) => toTypedValueWithType(element, resultType));
@@ -8721,7 +8695,7 @@
8721
8695
  case 'Quantity':
8722
8696
  return isQuantity(value);
8723
8697
  default:
8724
- return typeof value === 'object' && (value === null || value === void 0 ? void 0 : value.resourceType) === desiredType;
8698
+ return typeof value === 'object' && value?.resourceType === desiredType;
8725
8699
  }
8726
8700
  }
8727
8701
  /**
@@ -9110,8 +9084,7 @@
9110
9084
  * @returns A collection containing all but the first item in the input collection.
9111
9085
  */
9112
9086
  skip: (input, num) => {
9113
- var _a;
9114
- const numValue = (_a = num.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
9087
+ const numValue = num.eval(input)[0]?.value;
9115
9088
  if (typeof numValue !== 'number') {
9116
9089
  throw new Error('Expected a number for skip(num)');
9117
9090
  }
@@ -9135,8 +9108,7 @@
9135
9108
  * @returns A collection containing the first num items in the input collection.
9136
9109
  */
9137
9110
  take: (input, num) => {
9138
- var _a;
9139
- const numValue = (_a = num.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
9111
+ const numValue = num.eval(input)[0]?.value;
9140
9112
  if (typeof numValue !== 'number') {
9141
9113
  throw new Error('Expected a number for take(num)');
9142
9114
  }
@@ -10080,7 +10052,6 @@
10080
10052
  * IBM FHIR PR: https://github.com/IBM/FHIR/pull/1023
10081
10053
  */
10082
10054
  between: (input, startAtom, endAtom, unitsAtom) => {
10083
- var _a;
10084
10055
  const startDate = functions.toDateTime(startAtom.eval(input));
10085
10056
  if (startDate.length === 0) {
10086
10057
  throw new Error('Invalid start date');
@@ -10089,7 +10060,7 @@
10089
10060
  if (endDate.length === 0) {
10090
10061
  throw new Error('Invalid end date');
10091
10062
  }
10092
- const unit = (_a = unitsAtom.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
10063
+ const unit = unitsAtom.eval(input)[0]?.value;
10093
10064
  if (unit !== 'years' && unit !== 'months' && unit !== 'days') {
10094
10065
  throw new Error('Invalid units');
10095
10066
  }
@@ -10220,13 +10191,10 @@
10220
10191
  throw new Error('Expected a StructureDefinition URL');
10221
10192
  }
10222
10193
  const expectedResourceType = system.replace('http://hl7.org/fhir/StructureDefinition/', '');
10223
- return input.map((value) => {
10224
- var _a;
10225
- return ({
10226
- type: exports.PropertyType.boolean,
10227
- value: ((_a = value.value) === null || _a === void 0 ? void 0 : _a.resourceType) === expectedResourceType,
10228
- });
10229
- });
10194
+ return input.map((value) => ({
10195
+ type: exports.PropertyType.boolean,
10196
+ value: value.value?.resourceType === expectedResourceType,
10197
+ }));
10230
10198
  },
10231
10199
  };
10232
10200
  /*
@@ -10240,7 +10208,7 @@
10240
10208
  if (typeof value !== 'string') {
10241
10209
  throw new Error('String function cannot be called with non-string');
10242
10210
  }
10243
- 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));
10244
10212
  if (result === undefined) {
10245
10213
  return [];
10246
10214
  }
@@ -10259,9 +10227,9 @@
10259
10227
  if (typeof numberInput !== 'number') {
10260
10228
  throw new Error('Math function cannot be called with non-number');
10261
10229
  }
10262
- 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));
10263
10231
  const type = quantity ? exports.PropertyType.Quantity : input[0].type;
10264
- const returnValue = quantity ? Object.assign(Object.assign({}, value), { value: result }) : result;
10232
+ const returnValue = quantity ? { ...value, value: result } : result;
10265
10233
  return [{ type, value: returnValue }];
10266
10234
  }
10267
10235
  function validateInput(input, count) {
@@ -10326,7 +10294,7 @@
10326
10294
  return context
10327
10295
  .map((e) => __classPrivateFieldGet(this, _SymbolAtom_instances, "m", _SymbolAtom_evalValue).call(this, e))
10328
10296
  .flat()
10329
- .filter((e) => (e === null || e === void 0 ? void 0 : e.value) !== undefined);
10297
+ .filter((e) => e?.value !== undefined);
10330
10298
  }
10331
10299
  toString() {
10332
10300
  return this.name;
@@ -10393,7 +10361,7 @@
10393
10361
  return booleanToTypedValue(result);
10394
10362
  }
10395
10363
  else if (isQuantity(leftValue)) {
10396
- return [{ type: exports.PropertyType.Quantity, value: Object.assign(Object.assign({}, leftValue), { value: result }) }];
10364
+ return [{ type: exports.PropertyType.Quantity, value: { ...leftValue, value: result } }];
10397
10365
  }
10398
10366
  else {
10399
10367
  return [toTypedValue(result)];
@@ -10519,13 +10487,12 @@
10519
10487
  super('and', left, right);
10520
10488
  }
10521
10489
  eval(context) {
10522
- var _a, _b, _c, _d;
10523
10490
  const leftValue = this.left.eval(context);
10524
10491
  const rightValue = this.right.eval(context);
10525
- 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) {
10492
+ if (leftValue[0]?.value === true && rightValue[0]?.value === true) {
10526
10493
  return booleanToTypedValue(true);
10527
10494
  }
10528
- 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) {
10495
+ if (leftValue[0]?.value === false || rightValue[0]?.value === false) {
10529
10496
  return booleanToTypedValue(false);
10530
10497
  }
10531
10498
  return [];
@@ -10623,10 +10590,9 @@
10623
10590
 
10624
10591
  const PARENTHESES_PARSELET = {
10625
10592
  parse(parser) {
10626
- var _a;
10627
10593
  const expr = parser.consumeAndParse();
10628
10594
  if (!parser.match(')')) {
10629
- throw new Error('Parse error: expected `)` got `' + ((_a = parser.peek()) === null || _a === void 0 ? void 0 : _a.value) + '`');
10595
+ throw new Error('Parse error: expected `)` got `' + parser.peek()?.value + '`');
10630
10596
  }
10631
10597
  return expr;
10632
10598
  },
@@ -10833,15 +10799,14 @@
10833
10799
  * @returns The HL7 "ACK" message.
10834
10800
  */
10835
10801
  buildAck() {
10836
- var _a, _b, _c, _d, _e, _f;
10837
10802
  const now = new Date();
10838
10803
  const msh = this.get('MSH');
10839
- const sendingApp = ((_a = msh === null || msh === void 0 ? void 0 : msh.get(2)) === null || _a === void 0 ? void 0 : _a.toString()) || '';
10840
- const sendingFacility = ((_b = msh === null || msh === void 0 ? void 0 : msh.get(3)) === null || _b === void 0 ? void 0 : _b.toString()) || '';
10841
- const receivingApp = ((_c = msh === null || msh === void 0 ? void 0 : msh.get(4)) === null || _c === void 0 ? void 0 : _c.toString()) || '';
10842
- const receivingFacility = ((_d = msh === null || msh === void 0 ? void 0 : msh.get(5)) === null || _d === void 0 ? void 0 : _d.toString()) || '';
10843
- const controlId = ((_e = msh === null || msh === void 0 ? void 0 : msh.get(9)) === null || _e === void 0 ? void 0 : _e.toString()) || '';
10844
- 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';
10845
10810
  return new Hl7Message([
10846
10811
  new Hl7Segment([
10847
10812
  'MSH',
@@ -11203,8 +11168,7 @@
11203
11168
  * @returns The search parameter type details.
11204
11169
  */
11205
11170
  function getSearchParameterDetails(resourceType, searchParam) {
11206
- var _a, _b;
11207
- 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];
11208
11172
  if (!result) {
11209
11173
  result = buildSearchParamterDetails(resourceType, searchParam);
11210
11174
  }
@@ -11218,13 +11182,12 @@
11218
11182
  typeSchema.searchParamsDetails[code] = details;
11219
11183
  }
11220
11184
  function buildSearchParamterDetails(resourceType, searchParam) {
11221
- var _a, _b, _c, _d, _e, _f, _g;
11222
11185
  if (searchParam.code === '_lastUpdated') {
11223
11186
  return { columnName: 'lastUpdated', type: exports.SearchParameterType.DATETIME };
11224
11187
  }
11225
11188
  const code = searchParam.code;
11226
11189
  const columnName = convertCodeToColumnName(code);
11227
- const expression = (_a = getExpressionForResourceType(resourceType, searchParam.expression)) === null || _a === void 0 ? void 0 : _a.split('.');
11190
+ const expression = getExpressionForResourceType(resourceType, searchParam.expression)?.split('.');
11228
11191
  if (!expression) {
11229
11192
  // This happens on compound types
11230
11193
  // In the future, explore returning multiple column definitions
@@ -11238,14 +11201,15 @@
11238
11201
  for (let i = 1; i < expression.length; i++) {
11239
11202
  const propertyName = expression[i];
11240
11203
  elementDefinition =
11241
- (_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]'];
11242
11206
  if (!elementDefinition) {
11243
11207
  throw new Error(`Element definition not found for ${resourceType} ${searchParam.code}`);
11244
11208
  }
11245
11209
  if (elementDefinition.max === '*') {
11246
11210
  array = true;
11247
11211
  }
11248
- propertyType = (_g = elementDefinition.type) === null || _g === void 0 ? void 0 : _g[0].code;
11212
+ propertyType = elementDefinition.type?.[0].code;
11249
11213
  if (!propertyType) {
11250
11214
  // This happens when one of parent properties uses contentReference
11251
11215
  // In the future, explore following the reference
@@ -11360,9 +11324,8 @@
11360
11324
  * @returns True if the resource satisfies the search filter.
11361
11325
  */
11362
11326
  function matchesSearchFilter(resource, searchRequest, filter) {
11363
- var _a, _b;
11364
- 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];
11365
- switch (searchParam === null || searchParam === void 0 ? void 0 : searchParam.type) {
11327
+ const searchParam = globalSchema.types[searchRequest.resourceType]?.searchParams?.[filter.code];
11328
+ switch (searchParam?.type) {
11366
11329
  case 'reference':
11367
11330
  return matchesReferenceFilter(resource, filter, searchParam);
11368
11331
  case 'string':
@@ -11393,7 +11356,7 @@
11393
11356
  // In previous versions, the resource type was not required in compartment values
11394
11357
  // So, "123" would match "Patient/123"
11395
11358
  // We need to maintain this behavior for backwards compatibility
11396
- match = references.some((reference) => reference === null || reference === void 0 ? void 0 : reference.endsWith('/' + filterValue));
11359
+ match = references.some((reference) => reference?.endsWith('/' + filterValue));
11397
11360
  }
11398
11361
  if (match) {
11399
11362
  return !negated;
@@ -11661,8 +11624,7 @@
11661
11624
  }
11662
11625
  class OperationOutcomeError extends Error {
11663
11626
  constructor(outcome) {
11664
- var _a, _b;
11665
- 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);
11666
11628
  this.outcome = outcome;
11667
11629
  }
11668
11630
  }
@@ -11672,7 +11634,6 @@
11672
11634
  * @returns A display string for the error.
11673
11635
  */
11674
11636
  function normalizeErrorString(error) {
11675
- var _a, _b, _c, _d;
11676
11637
  if (!error) {
11677
11638
  return 'Unknown error';
11678
11639
  }
@@ -11684,7 +11645,7 @@
11684
11645
  }
11685
11646
  if (typeof error === 'object' && 'resourceType' in error) {
11686
11647
  const outcome = error;
11687
- 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';
11688
11649
  }
11689
11650
  return JSON.stringify(error);
11690
11651
  }
@@ -11757,6 +11718,7 @@
11757
11718
  exports.formatFamilyName = formatFamilyName;
11758
11719
  exports.formatGivenName = formatGivenName;
11759
11720
  exports.formatHumanName = formatHumanName;
11721
+ exports.formatMoney = formatMoney;
11760
11722
  exports.formatObservationValue = formatObservationValue;
11761
11723
  exports.formatPeriod = formatPeriod;
11762
11724
  exports.formatQuantity = formatQuantity;
@@ -11823,4 +11785,4 @@
11823
11785
  exports.unauthorized = unauthorized;
11824
11786
 
11825
11787
  }));
11826
- //# sourceMappingURL=index.js.map
11788
+ //# sourceMappingURL=index.cjs.map