@medplum/core 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/cjs/client.d.ts +22 -6
- package/dist/cjs/format.d.ts +2 -1
- package/dist/cjs/{index.js → index.cjs} +355 -376
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.min.cjs +1 -0
- package/dist/cjs/search.d.ts +2 -1
- package/dist/cjs/utils.d.ts +8 -1
- package/dist/esm/{base-schema.json.js → base-schema.json.mjs} +1 -1
- package/dist/esm/{base-schema.json.js.map → base-schema.json.mjs.map} +1 -1
- package/dist/esm/{cache.js → cache.mjs} +2 -2
- package/dist/esm/cache.mjs.map +1 -0
- package/dist/esm/client.d.ts +22 -6
- package/dist/esm/{client.js → client.mjs} +256 -260
- package/dist/esm/client.mjs.map +1 -0
- package/dist/esm/{crypto.js → crypto.mjs} +4 -7
- package/dist/esm/crypto.mjs.map +1 -0
- package/dist/esm/{eventtarget.js → eventtarget.mjs} +2 -2
- package/dist/esm/eventtarget.mjs.map +1 -0
- package/dist/esm/fhirlexer/{parse.js → parse.mjs} +5 -6
- package/dist/esm/fhirlexer/parse.mjs.map +1 -0
- package/dist/esm/fhirlexer/{tokenize.js → tokenize.mjs} +11 -11
- package/dist/esm/fhirlexer/tokenize.mjs.map +1 -0
- package/dist/esm/fhirpath/{atoms.js → atoms.mjs} +11 -12
- package/dist/esm/fhirpath/atoms.mjs.map +1 -0
- package/dist/esm/fhirpath/{date.js → date.mjs} +1 -1
- package/dist/esm/fhirpath/date.mjs.map +1 -0
- package/dist/esm/fhirpath/{functions.js → functions.mjs} +16 -22
- package/dist/esm/fhirpath/functions.mjs.map +1 -0
- package/dist/esm/fhirpath/{parse.js → parse.mjs} +9 -10
- package/dist/esm/fhirpath/parse.mjs.map +1 -0
- package/dist/esm/fhirpath/{tokenize.js → tokenize.mjs} +3 -3
- package/dist/esm/fhirpath/tokenize.mjs.map +1 -0
- package/dist/esm/fhirpath/{utils.js → utils.mjs} +6 -7
- package/dist/esm/fhirpath/utils.mjs.map +1 -0
- package/dist/esm/format.d.ts +2 -1
- package/dist/esm/{format.js → format.mjs} +29 -21
- package/dist/esm/format.mjs.map +1 -0
- package/dist/esm/{hl7.js → hl7.mjs} +8 -9
- package/dist/esm/hl7.mjs.map +1 -0
- package/dist/esm/index.min.mjs +1 -0
- package/dist/esm/{index.js → index.mjs} +17 -17
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/{jwt.js → jwt.mjs} +1 -1
- package/dist/esm/jwt.mjs.map +1 -0
- package/dist/esm/{match.js → match.mjs} +12 -13
- package/dist/esm/match.mjs.map +1 -0
- package/dist/esm/node_modules/tslib/{tslib.es6.js → tslib.es6.mjs} +2 -12
- package/dist/esm/node_modules/tslib/tslib.es6.mjs.map +1 -0
- package/dist/esm/{outcomes.js → outcomes.mjs} +3 -5
- package/dist/esm/outcomes.mjs.map +1 -0
- package/dist/esm/{readablepromise.js → readablepromise.mjs} +2 -2
- package/dist/esm/readablepromise.mjs.map +1 -0
- package/dist/esm/search.d.ts +2 -1
- package/dist/esm/{search.js → search.mjs} +1 -1
- package/dist/esm/search.mjs.map +1 -0
- package/dist/esm/{searchparams.js → searchparams.mjs} +8 -9
- package/dist/esm/searchparams.mjs.map +1 -0
- package/dist/esm/{storage.js → storage.mjs} +4 -5
- package/dist/esm/storage.mjs.map +1 -0
- package/dist/esm/{types.js → types.mjs} +6 -9
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/utils.d.ts +8 -1
- package/dist/esm/{utils.js → utils.mjs} +31 -27
- package/dist/esm/utils.mjs.map +1 -0
- package/package.json +5 -5
- package/rollup.config.mjs +6 -7
- package/dist/cjs/fhirmapper/testall.d.ts +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/index.min.js +0 -2
- package/dist/cjs/index.min.js.map +0 -1
- package/dist/esm/cache.js.map +0 -1
- package/dist/esm/client.js.map +0 -1
- package/dist/esm/crypto.js.map +0 -1
- package/dist/esm/eventtarget.js.map +0 -1
- package/dist/esm/fhirlexer/parse.js.map +0 -1
- package/dist/esm/fhirlexer/tokenize.js.map +0 -1
- package/dist/esm/fhirmapper/testall.d.ts +0 -1
- package/dist/esm/fhirpath/atoms.js.map +0 -1
- package/dist/esm/fhirpath/date.js.map +0 -1
- package/dist/esm/fhirpath/functions.js.map +0 -1
- package/dist/esm/fhirpath/parse.js.map +0 -1
- package/dist/esm/fhirpath/tokenize.js.map +0 -1
- package/dist/esm/fhirpath/utils.js.map +0 -1
- package/dist/esm/format.js.map +0 -1
- package/dist/esm/hl7.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.min.js +0 -2
- package/dist/esm/index.min.js.map +0 -1
- package/dist/esm/jwt.js.map +0 -1
- package/dist/esm/match.js.map +0 -1
- package/dist/esm/node_modules/tslib/tslib.es6.js.map +0 -1
- package/dist/esm/outcomes.js.map +0 -1
- package/dist/esm/readablepromise.js.map +0 -1
- package/dist/esm/search.js.map +0 -1
- package/dist/esm/searchparams.js.map +0 -1
- package/dist/esm/storage.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
- 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 && (
|
|
125
|
+
if (address.use && (options?.all || options?.use)) {
|
|
136
126
|
builder.push('[' + address.use + ']');
|
|
137
127
|
}
|
|
138
|
-
return builder.join(
|
|
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 &&
|
|
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 &&
|
|
147
|
+
if (name.suffix && options?.suffix !== false) {
|
|
158
148
|
builder.push(...name.suffix);
|
|
159
149
|
}
|
|
160
|
-
if (name.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,
|
|
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 (
|
|
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 =
|
|
345
|
-
const high =
|
|
346
|
-
if (!range || (
|
|
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 (
|
|
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 (
|
|
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 (
|
|
364
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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 &&
|
|
531
|
+
if ('code' in resource && resource.code?.text) {
|
|
536
532
|
return resource.code.text;
|
|
537
533
|
}
|
|
538
534
|
}
|
|
@@ -717,14 +713,28 @@
|
|
|
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 =
|
|
720
|
+
curr = curr?.extension?.find((e) => e.url === urls[i]);
|
|
726
721
|
}
|
|
727
|
-
return curr
|
|
722
|
+
return curr?.valueString;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Returns an extension by extension URLs.
|
|
726
|
+
* @param resource The base resource.
|
|
727
|
+
* @param urls Array of extension URLs. Each entry represents a nested extension.
|
|
728
|
+
* @returns The extension object if found; undefined otherwise.
|
|
729
|
+
*/
|
|
730
|
+
function getExtension(resource, ...urls) {
|
|
731
|
+
// Let curr be the current resource or extension. Extensions can be nested.
|
|
732
|
+
let curr = resource;
|
|
733
|
+
// For each of the urls, try to find a matching nested extension.
|
|
734
|
+
for (let i = 0; i < urls.length && curr; i++) {
|
|
735
|
+
curr = curr?.extension?.find((e) => e.url === urls[i]);
|
|
736
|
+
}
|
|
737
|
+
return curr;
|
|
728
738
|
}
|
|
729
739
|
/**
|
|
730
740
|
* FHIR JSON stringify.
|
|
@@ -915,8 +925,7 @@
|
|
|
915
925
|
* @returns The code if found; otherwise undefined.
|
|
916
926
|
*/
|
|
917
927
|
function getCodeBySystem(concept, system) {
|
|
918
|
-
|
|
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;
|
|
928
|
+
return concept?.coding?.find((coding) => coding.system === system)?.code;
|
|
920
929
|
}
|
|
921
930
|
/**
|
|
922
931
|
* Sets a code for a given system within a given codeable concept.
|
|
@@ -925,16 +934,15 @@
|
|
|
925
934
|
* @param code The code value.
|
|
926
935
|
*/
|
|
927
936
|
function setCodeBySystem(concept, system, code) {
|
|
928
|
-
var _a, _b;
|
|
929
937
|
if (!concept.coding) {
|
|
930
938
|
concept.coding = [];
|
|
931
939
|
}
|
|
932
|
-
const coding =
|
|
940
|
+
const coding = concept.coding?.find((c) => c.system === system);
|
|
933
941
|
if (coding) {
|
|
934
942
|
coding.code = code;
|
|
935
943
|
}
|
|
936
944
|
else {
|
|
937
|
-
|
|
945
|
+
concept.coding?.push({ system, code });
|
|
938
946
|
}
|
|
939
947
|
}
|
|
940
948
|
/**
|
|
@@ -945,13 +953,9 @@
|
|
|
945
953
|
* @returns The observation interval if found; otherwise undefined.
|
|
946
954
|
*/
|
|
947
955
|
function findObservationInterval(definition, patient, value, category) {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
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
|
-
});
|
|
956
|
+
return definition.qualifiedInterval?.find((interval) => observationIntervalMatchesPatient(interval, patient) &&
|
|
957
|
+
observationIntervalMatchesValue(interval, value, definition.quantitativeDetails?.decimalPrecision) &&
|
|
958
|
+
(category === undefined || interval.category === category));
|
|
955
959
|
}
|
|
956
960
|
/**
|
|
957
961
|
* Tries to find an observation reference range for the given patient and condition names.
|
|
@@ -961,8 +965,7 @@
|
|
|
961
965
|
* @returns The observation interval if found; otherwise undefined.
|
|
962
966
|
*/
|
|
963
967
|
function findObservationReferenceRange(definition, patient, names) {
|
|
964
|
-
|
|
965
|
-
return (_a = definition.qualifiedInterval) === null || _a === void 0 ? void 0 : _a.find((interval) => observationIntervalMatchesPatient(interval, patient) && names.includes(interval.condition));
|
|
968
|
+
return definition.qualifiedInterval?.find((interval) => observationIntervalMatchesPatient(interval, patient) && names.includes(interval.condition));
|
|
966
969
|
}
|
|
967
970
|
/**
|
|
968
971
|
* Returns true if the patient matches the observation interval.
|
|
@@ -1009,9 +1012,8 @@
|
|
|
1009
1012
|
* @returns True if the value is within the range.
|
|
1010
1013
|
*/
|
|
1011
1014
|
function matchesRange(value, range, precision) {
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
(((_b = range.high) === null || _b === void 0 ? void 0 : _b.value) === undefined || preciseLessThanOrEquals(value, range.high.value, precision)));
|
|
1015
|
+
return ((range.low?.value === undefined || preciseGreaterThanOrEquals(value, range.low.value, precision)) &&
|
|
1016
|
+
(range.high?.value === undefined || preciseLessThanOrEquals(value, range.high.value, precision)));
|
|
1015
1017
|
}
|
|
1016
1018
|
/**
|
|
1017
1019
|
* Returns the input number rounded to the specified number of digits.
|
|
@@ -1098,10 +1100,8 @@
|
|
|
1098
1100
|
* Encrypts a string with SHA256 encryption.
|
|
1099
1101
|
* @param str
|
|
1100
1102
|
*/
|
|
1101
|
-
function encryptSHA256(str) {
|
|
1102
|
-
return
|
|
1103
|
-
return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
|
|
1104
|
-
});
|
|
1103
|
+
async function encryptSHA256(str) {
|
|
1104
|
+
return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
|
|
1105
1105
|
}
|
|
1106
1106
|
|
|
1107
1107
|
/*
|
|
@@ -1317,8 +1317,7 @@
|
|
|
1317
1317
|
* Returns the current value associated with the given key, or null if the given key does not exist.
|
|
1318
1318
|
*/
|
|
1319
1319
|
getItem(key) {
|
|
1320
|
-
|
|
1321
|
-
return (_a = __classPrivateFieldGet(this, _MemoryStorage_data, "f").get(key)) !== null && _a !== void 0 ? _a : null;
|
|
1320
|
+
return __classPrivateFieldGet(this, _MemoryStorage_data, "f").get(key) ?? null;
|
|
1322
1321
|
}
|
|
1323
1322
|
/**
|
|
1324
1323
|
* 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 +6318,11 @@
|
|
|
6319
6318
|
* @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
|
|
6320
6319
|
*/
|
|
6321
6320
|
function indexStructureDefinition(structureDefinition) {
|
|
6322
|
-
var _a;
|
|
6323
6321
|
const typeName = structureDefinition.name;
|
|
6324
6322
|
if (!typeName) {
|
|
6325
6323
|
return;
|
|
6326
6324
|
}
|
|
6327
|
-
const elements =
|
|
6325
|
+
const elements = structureDefinition.snapshot?.element;
|
|
6328
6326
|
if (elements) {
|
|
6329
6327
|
// First pass, build types
|
|
6330
6328
|
elements.forEach((element) => indexType(structureDefinition, element));
|
|
@@ -6341,9 +6339,8 @@
|
|
|
6341
6339
|
* @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
|
|
6342
6340
|
*/
|
|
6343
6341
|
function indexType(structureDefinition, elementDefinition) {
|
|
6344
|
-
var _a, _b;
|
|
6345
6342
|
const path = elementDefinition.path;
|
|
6346
|
-
const typeCode =
|
|
6343
|
+
const typeCode = elementDefinition.type?.[0]?.code;
|
|
6347
6344
|
if (typeCode !== undefined && typeCode !== 'Element' && typeCode !== 'BackboneElement') {
|
|
6348
6345
|
return;
|
|
6349
6346
|
}
|
|
@@ -6460,12 +6457,11 @@
|
|
|
6460
6457
|
* @returns The element definition if found.
|
|
6461
6458
|
*/
|
|
6462
6459
|
function getElementDefinition(typeName, propertyName) {
|
|
6463
|
-
var _a;
|
|
6464
6460
|
const typeSchema = globalSchema.types[typeName];
|
|
6465
6461
|
if (!typeSchema) {
|
|
6466
6462
|
return undefined;
|
|
6467
6463
|
}
|
|
6468
|
-
const property =
|
|
6464
|
+
const property = typeSchema.properties[propertyName] ?? typeSchema.properties[propertyName + '[x]'];
|
|
6469
6465
|
if (!property) {
|
|
6470
6466
|
return undefined;
|
|
6471
6467
|
}
|
|
@@ -6487,7 +6483,7 @@
|
|
|
6487
6483
|
// PKCE auth based on:
|
|
6488
6484
|
// https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
|
|
6489
6485
|
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 = "
|
|
6486
|
+
const MEDPLUM_VERSION = "2.0.0-7fe99080";
|
|
6491
6487
|
const DEFAULT_BASE_URL = 'https://api.medplum.com/';
|
|
6492
6488
|
const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
|
|
6493
6489
|
const DEFAULT_CACHE_TIME = 60000; // 60 seconds
|
|
@@ -6548,7 +6544,6 @@
|
|
|
6548
6544
|
*/
|
|
6549
6545
|
class MedplumClient extends EventTarget {
|
|
6550
6546
|
constructor(options) {
|
|
6551
|
-
var _a, _b;
|
|
6552
6547
|
super();
|
|
6553
6548
|
_MedplumClient_instances.add(this);
|
|
6554
6549
|
_MedplumClient_fetch.set(this, void 0);
|
|
@@ -6569,22 +6564,22 @@
|
|
|
6569
6564
|
_MedplumClient_profilePromise.set(this, void 0);
|
|
6570
6565
|
_MedplumClient_profile.set(this, void 0);
|
|
6571
6566
|
_MedplumClient_config.set(this, void 0);
|
|
6572
|
-
if (options
|
|
6567
|
+
if (options?.baseUrl) {
|
|
6573
6568
|
if (!options.baseUrl.startsWith('http')) {
|
|
6574
6569
|
throw new Error('Base URL must start with http or https');
|
|
6575
6570
|
}
|
|
6576
6571
|
}
|
|
6577
|
-
__classPrivateFieldSet(this, _MedplumClient_fetch,
|
|
6578
|
-
__classPrivateFieldSet(this, _MedplumClient_createPdf, options
|
|
6572
|
+
__classPrivateFieldSet(this, _MedplumClient_fetch, options?.fetch || window.fetch.bind(window), "f");
|
|
6573
|
+
__classPrivateFieldSet(this, _MedplumClient_createPdf, options?.createPdf, "f");
|
|
6579
6574
|
__classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
|
|
6580
|
-
__classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache(
|
|
6581
|
-
__classPrivateFieldSet(this, _MedplumClient_cacheTime,
|
|
6582
|
-
__classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options
|
|
6583
|
-
__classPrivateFieldSet(this, _MedplumClient_clientId,
|
|
6584
|
-
__classPrivateFieldSet(this, _MedplumClient_authorizeUrl,
|
|
6585
|
-
__classPrivateFieldSet(this, _MedplumClient_tokenUrl,
|
|
6586
|
-
__classPrivateFieldSet(this, _MedplumClient_logoutUrl,
|
|
6587
|
-
__classPrivateFieldSet(this, _MedplumClient_onUnauthenticated, options
|
|
6575
|
+
__classPrivateFieldSet(this, _MedplumClient_requestCache, new LRUCache(options?.resourceCacheSize ?? DEFAULT_RESOURCE_CACHE_SIZE), "f");
|
|
6576
|
+
__classPrivateFieldSet(this, _MedplumClient_cacheTime, options?.cacheTime ?? DEFAULT_CACHE_TIME, "f");
|
|
6577
|
+
__classPrivateFieldSet(this, _MedplumClient_baseUrl, ensureTrailingSlash(options?.baseUrl) || DEFAULT_BASE_URL, "f");
|
|
6578
|
+
__classPrivateFieldSet(this, _MedplumClient_clientId, options?.clientId || '', "f");
|
|
6579
|
+
__classPrivateFieldSet(this, _MedplumClient_authorizeUrl, options?.authorizeUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
|
|
6580
|
+
__classPrivateFieldSet(this, _MedplumClient_tokenUrl, options?.tokenUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
|
|
6581
|
+
__classPrivateFieldSet(this, _MedplumClient_logoutUrl, options?.logoutUrl || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/logout', "f");
|
|
6582
|
+
__classPrivateFieldSet(this, _MedplumClient_onUnauthenticated, options?.onUnauthenticated, "f");
|
|
6588
6583
|
const activeLogin = this.getActiveLogin();
|
|
6589
6584
|
if (activeLogin) {
|
|
6590
6585
|
__classPrivateFieldSet(this, _MedplumClient_accessToken, activeLogin.accessToken, "f");
|
|
@@ -6609,6 +6604,15 @@
|
|
|
6609
6604
|
*/
|
|
6610
6605
|
clear() {
|
|
6611
6606
|
__classPrivateFieldGet(this, _MedplumClient_storage, "f").clear();
|
|
6607
|
+
this.clearActiveLogin();
|
|
6608
|
+
}
|
|
6609
|
+
/**
|
|
6610
|
+
* Clears the active login from local storage.
|
|
6611
|
+
* Does not clear all local storage (such as other logins).
|
|
6612
|
+
* @category Authentication
|
|
6613
|
+
*/
|
|
6614
|
+
clearActiveLogin() {
|
|
6615
|
+
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('activeLogin', undefined);
|
|
6612
6616
|
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").clear();
|
|
6613
6617
|
__classPrivateFieldSet(this, _MedplumClient_accessToken, undefined, "f");
|
|
6614
6618
|
__classPrivateFieldSet(this, _MedplumClient_refreshToken, undefined, "f");
|
|
@@ -6759,10 +6763,12 @@
|
|
|
6759
6763
|
* @param newUserRequest Register request including email and password.
|
|
6760
6764
|
* @returns Promise to the authentication response.
|
|
6761
6765
|
*/
|
|
6762
|
-
startNewUser(newUserRequest) {
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
+
async startNewUser(newUserRequest) {
|
|
6767
|
+
const { codeChallengeMethod, codeChallenge } = await this.startPkce();
|
|
6768
|
+
return this.post('auth/newuser', {
|
|
6769
|
+
...newUserRequest,
|
|
6770
|
+
codeChallengeMethod,
|
|
6771
|
+
codeChallenge,
|
|
6766
6772
|
});
|
|
6767
6773
|
}
|
|
6768
6774
|
/**
|
|
@@ -6773,10 +6779,8 @@
|
|
|
6773
6779
|
* @param newProjectRequest Register request including email and password.
|
|
6774
6780
|
* @returns Promise to the authentication response.
|
|
6775
6781
|
*/
|
|
6776
|
-
startNewProject(newProjectRequest) {
|
|
6777
|
-
return
|
|
6778
|
-
return this.post('auth/newproject', newProjectRequest);
|
|
6779
|
-
});
|
|
6782
|
+
async startNewProject(newProjectRequest) {
|
|
6783
|
+
return this.post('auth/newproject', newProjectRequest);
|
|
6780
6784
|
}
|
|
6781
6785
|
/**
|
|
6782
6786
|
* Initiates a new patient flow.
|
|
@@ -6786,10 +6790,8 @@
|
|
|
6786
6790
|
* @param newPatientRequest Register request including email and password.
|
|
6787
6791
|
* @returns Promise to the authentication response.
|
|
6788
6792
|
*/
|
|
6789
|
-
startNewPatient(newPatientRequest) {
|
|
6790
|
-
return
|
|
6791
|
-
return this.post('auth/newpatient', newPatientRequest);
|
|
6792
|
-
});
|
|
6793
|
+
async startNewPatient(newPatientRequest) {
|
|
6794
|
+
return this.post('auth/newpatient', newPatientRequest);
|
|
6793
6795
|
}
|
|
6794
6796
|
/**
|
|
6795
6797
|
* Initiates a user login flow.
|
|
@@ -6797,12 +6799,11 @@
|
|
|
6797
6799
|
* @param loginRequest Login request including email and password.
|
|
6798
6800
|
* @returns Promise to the authentication response.
|
|
6799
6801
|
*/
|
|
6800
|
-
startLogin(loginRequest) {
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
codeChallenge }));
|
|
6802
|
+
async startLogin(loginRequest) {
|
|
6803
|
+
return this.post('auth/login', {
|
|
6804
|
+
...(await this.ensureCodeChallenge(loginRequest)),
|
|
6805
|
+
clientId: loginRequest.clientId ?? __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
|
|
6806
|
+
scope: loginRequest.scope,
|
|
6806
6807
|
});
|
|
6807
6808
|
}
|
|
6808
6809
|
/**
|
|
@@ -6813,29 +6814,26 @@
|
|
|
6813
6814
|
* @param loginRequest Login request including Google credential response.
|
|
6814
6815
|
* @returns Promise to the authentication response.
|
|
6815
6816
|
*/
|
|
6816
|
-
startGoogleLogin(loginRequest) {
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
codeChallenge }));
|
|
6817
|
+
async startGoogleLogin(loginRequest) {
|
|
6818
|
+
return this.post('auth/google', {
|
|
6819
|
+
...(await this.ensureCodeChallenge(loginRequest)),
|
|
6820
|
+
clientId: loginRequest.clientId ?? __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
|
|
6821
|
+
scope: loginRequest.scope,
|
|
6822
6822
|
});
|
|
6823
6823
|
}
|
|
6824
|
-
|
|
6824
|
+
/**
|
|
6825
|
+
* Returns the PKCE code challenge and method.
|
|
6826
|
+
* If the login request already includes a code challenge, it is returned.
|
|
6827
|
+
* Otherwise, a new PKCE code challenge is generated.
|
|
6828
|
+
* @category Authentication
|
|
6829
|
+
* @param loginRequest The original login request.
|
|
6830
|
+
* @returns The PKCE code challenge and method.
|
|
6831
|
+
*/
|
|
6832
|
+
async ensureCodeChallenge(loginRequest) {
|
|
6825
6833
|
if (loginRequest.codeChallenge) {
|
|
6826
|
-
return
|
|
6827
|
-
codeChallenge: loginRequest.codeChallenge,
|
|
6828
|
-
codeChallengeMethod: loginRequest.codeChallengeMethod,
|
|
6829
|
-
};
|
|
6834
|
+
return loginRequest;
|
|
6830
6835
|
}
|
|
6831
|
-
|
|
6832
|
-
if (codeChallenge) {
|
|
6833
|
-
return {
|
|
6834
|
-
codeChallenge,
|
|
6835
|
-
codeChallengeMethod: 'S256',
|
|
6836
|
-
};
|
|
6837
|
-
}
|
|
6838
|
-
return {};
|
|
6836
|
+
return { ...loginRequest, ...(await this.startPkce()) };
|
|
6839
6837
|
}
|
|
6840
6838
|
/**
|
|
6841
6839
|
* Signs out locally.
|
|
@@ -6850,19 +6848,18 @@
|
|
|
6850
6848
|
* Returns true if the user is signed in.
|
|
6851
6849
|
* This may result in navigating away to the sign in page.
|
|
6852
6850
|
* @category Authentication
|
|
6851
|
+
* @param loginParams Optional login parameters.
|
|
6853
6852
|
*/
|
|
6854
|
-
signInWithRedirect() {
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
}
|
|
6865
|
-
});
|
|
6853
|
+
async signInWithRedirect(loginParams) {
|
|
6854
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
6855
|
+
const code = urlParams.get('code');
|
|
6856
|
+
if (!code) {
|
|
6857
|
+
await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this, loginParams);
|
|
6858
|
+
return undefined;
|
|
6859
|
+
}
|
|
6860
|
+
else {
|
|
6861
|
+
return this.processCode(code);
|
|
6862
|
+
}
|
|
6866
6863
|
}
|
|
6867
6864
|
/**
|
|
6868
6865
|
* Tries to sign out the user.
|
|
@@ -6978,7 +6975,7 @@
|
|
|
6978
6975
|
if (cached) {
|
|
6979
6976
|
return cached.value;
|
|
6980
6977
|
}
|
|
6981
|
-
const promise = new ReadablePromise(this.search(resourceType, url.searchParams, options).then((b) =>
|
|
6978
|
+
const promise = new ReadablePromise(this.search(resourceType, url.searchParams, options).then((b) => b.entry?.[0]?.resource));
|
|
6982
6979
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
6983
6980
|
return promise;
|
|
6984
6981
|
}
|
|
@@ -7011,7 +7008,7 @@
|
|
|
7011
7008
|
if (cached) {
|
|
7012
7009
|
return cached.value;
|
|
7013
7010
|
}
|
|
7014
|
-
const promise = new ReadablePromise(this.search(resourceType, query, options).then((b) =>
|
|
7011
|
+
const promise = new ReadablePromise(this.search(resourceType, query, options).then((b) => b.entry?.map((e) => e.resource) ?? []));
|
|
7015
7012
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setCacheEntry).call(this, cacheKey, promise);
|
|
7016
7013
|
return promise;
|
|
7017
7014
|
}
|
|
@@ -7039,8 +7036,7 @@
|
|
|
7039
7036
|
* @returns The resource if it is available in the cache; undefined otherwise.
|
|
7040
7037
|
*/
|
|
7041
7038
|
getCached(resourceType, id) {
|
|
7042
|
-
|
|
7043
|
-
const cached = (_a = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString())) === null || _a === void 0 ? void 0 : _a.value;
|
|
7039
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString())?.value;
|
|
7044
7040
|
return cached && cached.isOk() ? cached.read() : undefined;
|
|
7045
7041
|
}
|
|
7046
7042
|
/**
|
|
@@ -7103,7 +7099,7 @@
|
|
|
7103
7099
|
* @returns The resource if available; undefined otherwise.
|
|
7104
7100
|
*/
|
|
7105
7101
|
readReference(reference, options = {}) {
|
|
7106
|
-
const refString = reference
|
|
7102
|
+
const refString = reference?.reference;
|
|
7107
7103
|
if (!refString) {
|
|
7108
7104
|
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
7109
7105
|
}
|
|
@@ -7131,12 +7127,11 @@
|
|
|
7131
7127
|
* @param resourceType The FHIR resource type.
|
|
7132
7128
|
* @returns Promise to a schema with the requested resource type.
|
|
7133
7129
|
*/
|
|
7134
|
-
requestSchema(resourceType) {
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
const query = `{
|
|
7130
|
+
async requestSchema(resourceType) {
|
|
7131
|
+
if (resourceType in globalSchema.types) {
|
|
7132
|
+
return globalSchema;
|
|
7133
|
+
}
|
|
7134
|
+
const query = `{
|
|
7140
7135
|
StructureDefinitionList(name: "${resourceType}") {
|
|
7141
7136
|
name,
|
|
7142
7137
|
description,
|
|
@@ -7165,15 +7160,14 @@
|
|
|
7165
7160
|
target
|
|
7166
7161
|
}
|
|
7167
7162
|
}`.replace(/\s+/g, ' ');
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
});
|
|
7163
|
+
const response = (await this.graphql(query));
|
|
7164
|
+
for (const structureDefinition of response.data.StructureDefinitionList) {
|
|
7165
|
+
indexStructureDefinition(structureDefinition);
|
|
7166
|
+
}
|
|
7167
|
+
for (const searchParameter of response.data.SearchParameterList) {
|
|
7168
|
+
indexSearchParameter(searchParameter);
|
|
7169
|
+
}
|
|
7170
|
+
return globalSchema;
|
|
7177
7171
|
}
|
|
7178
7172
|
/**
|
|
7179
7173
|
* Reads resource history by resource type and ID.
|
|
@@ -7311,11 +7305,8 @@
|
|
|
7311
7305
|
* @param query The search query for an equivalent resource (should not include resource type or "?").
|
|
7312
7306
|
* @returns The result of the create operation.
|
|
7313
7307
|
*/
|
|
7314
|
-
createResourceIfNoneExist(resource, query) {
|
|
7315
|
-
|
|
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
|
-
});
|
|
7308
|
+
async createResourceIfNoneExist(resource, query) {
|
|
7309
|
+
return ((await this.searchOne(resource.resourceType, query)) ?? this.createResource(resource));
|
|
7319
7310
|
}
|
|
7320
7311
|
/**
|
|
7321
7312
|
* Creates a FHIR `Binary` resource with the provided data content.
|
|
@@ -7402,14 +7393,12 @@
|
|
|
7402
7393
|
* @param docDefinition The PDF document definition.
|
|
7403
7394
|
* @returns The result of the create operation.
|
|
7404
7395
|
*/
|
|
7405
|
-
createPdf(docDefinition, filename, tableLayouts, fonts) {
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
return this.createBinary(blob, filename, 'application/pdf');
|
|
7412
|
-
});
|
|
7396
|
+
async createPdf(docDefinition, filename, tableLayouts, fonts) {
|
|
7397
|
+
if (!__classPrivateFieldGet(this, _MedplumClient_createPdf, "f")) {
|
|
7398
|
+
throw new Error('PDF creation not enabled');
|
|
7399
|
+
}
|
|
7400
|
+
const blob = await __classPrivateFieldGet(this, _MedplumClient_createPdf, "f").call(this, docDefinition, tableLayouts, fonts);
|
|
7401
|
+
return this.createBinary(blob, filename, 'application/pdf');
|
|
7413
7402
|
}
|
|
7414
7403
|
/**
|
|
7415
7404
|
* Creates a FHIR `Communication` resource with the provided data content.
|
|
@@ -7471,20 +7460,18 @@
|
|
|
7471
7460
|
* @param resource The FHIR resource to update.
|
|
7472
7461
|
* @returns The result of the update operation.
|
|
7473
7462
|
*/
|
|
7474
|
-
updateResource(resource) {
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
return result !== null && result !== void 0 ? result : resource;
|
|
7487
|
-
});
|
|
7463
|
+
async updateResource(resource) {
|
|
7464
|
+
if (!resource.resourceType) {
|
|
7465
|
+
throw new Error('Missing resourceType');
|
|
7466
|
+
}
|
|
7467
|
+
if (!resource.id) {
|
|
7468
|
+
throw new Error('Missing id');
|
|
7469
|
+
}
|
|
7470
|
+
this.invalidateSearches(resource.resourceType);
|
|
7471
|
+
const result = await this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
|
|
7472
|
+
// On 304 not modified, result will be undefined
|
|
7473
|
+
// Return the user input instead
|
|
7474
|
+
return result ?? resource;
|
|
7488
7475
|
}
|
|
7489
7476
|
/**
|
|
7490
7477
|
* Updates a FHIR resource using JSONPatch operations.
|
|
@@ -7719,18 +7706,14 @@
|
|
|
7719
7706
|
/**
|
|
7720
7707
|
* @category Authentication
|
|
7721
7708
|
*/
|
|
7722
|
-
setActiveLogin(login) {
|
|
7723
|
-
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
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
|
-
});
|
|
7709
|
+
async setActiveLogin(login) {
|
|
7710
|
+
this.clearActiveLogin();
|
|
7711
|
+
__classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
|
|
7712
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshToken, login.refreshToken, "f");
|
|
7713
|
+
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('activeLogin', login);
|
|
7714
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addLogin).call(this, login);
|
|
7715
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshPromise, undefined, "f");
|
|
7716
|
+
await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
|
|
7734
7717
|
}
|
|
7735
7718
|
/**
|
|
7736
7719
|
* @category Authentication
|
|
@@ -7751,8 +7734,7 @@
|
|
|
7751
7734
|
* @category Authentication
|
|
7752
7735
|
*/
|
|
7753
7736
|
getLogins() {
|
|
7754
|
-
|
|
7755
|
-
return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
|
|
7737
|
+
return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins') ?? [];
|
|
7756
7738
|
}
|
|
7757
7739
|
/**
|
|
7758
7740
|
* @category Authentication
|
|
@@ -7769,13 +7751,11 @@
|
|
|
7769
7751
|
/**
|
|
7770
7752
|
* @category User Profile
|
|
7771
7753
|
*/
|
|
7772
|
-
getProfileAsync() {
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
return this.getProfile();
|
|
7778
|
-
});
|
|
7754
|
+
async getProfileAsync() {
|
|
7755
|
+
if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
|
|
7756
|
+
await __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
7757
|
+
}
|
|
7758
|
+
return this.getProfile();
|
|
7779
7759
|
}
|
|
7780
7760
|
/**
|
|
7781
7761
|
* @category User Profile
|
|
@@ -7790,30 +7770,27 @@
|
|
|
7790
7770
|
* @param url The URL to request.
|
|
7791
7771
|
* @returns Promise to the response body as a blob.
|
|
7792
7772
|
*/
|
|
7793
|
-
download(url, options = {}) {
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
return response.blob();
|
|
7801
|
-
});
|
|
7773
|
+
async download(url, options = {}) {
|
|
7774
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
7775
|
+
await __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
7776
|
+
}
|
|
7777
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
7778
|
+
const response = await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url.toString(), options);
|
|
7779
|
+
return response.blob();
|
|
7802
7780
|
}
|
|
7803
7781
|
/**
|
|
7804
7782
|
* Starts a new PKCE flow.
|
|
7805
7783
|
* These PKCE values are stateful, and must survive redirects and page refreshes.
|
|
7806
7784
|
*/
|
|
7807
|
-
startPkce() {
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
});
|
|
7785
|
+
async startPkce() {
|
|
7786
|
+
const pkceState = getRandomString();
|
|
7787
|
+
sessionStorage.setItem('pkceState', pkceState);
|
|
7788
|
+
const codeVerifier = getRandomString();
|
|
7789
|
+
sessionStorage.setItem('codeVerifier', codeVerifier);
|
|
7790
|
+
const arrayHash = await encryptSHA256(codeVerifier);
|
|
7791
|
+
const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
7792
|
+
sessionStorage.setItem('codeChallenge', codeChallenge);
|
|
7793
|
+
return { codeChallengeMethod: 'S256', codeChallenge };
|
|
7817
7794
|
}
|
|
7818
7795
|
/**
|
|
7819
7796
|
* Processes an OAuth authorization code.
|
|
@@ -7840,39 +7817,35 @@
|
|
|
7840
7817
|
* @param clientSecret The client secret.
|
|
7841
7818
|
* @returns Promise that resolves to the client profile.
|
|
7842
7819
|
*/
|
|
7843
|
-
startClientLogin(clientId, clientSecret) {
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
|
|
7852
|
-
});
|
|
7820
|
+
async startClientLogin(clientId, clientSecret) {
|
|
7821
|
+
__classPrivateFieldSet(this, _MedplumClient_clientId, clientId, "f");
|
|
7822
|
+
__classPrivateFieldSet(this, _MedplumClient_clientSecret, clientSecret, "f");
|
|
7823
|
+
const formBody = new URLSearchParams();
|
|
7824
|
+
formBody.set('grant_type', 'client_credentials');
|
|
7825
|
+
formBody.set('client_id', clientId);
|
|
7826
|
+
formBody.set('client_secret', clientSecret);
|
|
7827
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
|
|
7853
7828
|
}
|
|
7854
7829
|
}
|
|
7855
7830
|
_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) =>
|
|
7831
|
+
const logins = this.getLogins().filter((login) => login.profile?.reference !== newLogin.profile?.reference);
|
|
7857
7832
|
logins.push(newLogin);
|
|
7858
7833
|
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('logins', logins);
|
|
7859
|
-
}, _MedplumClient_refreshProfile = function _MedplumClient_refreshProfile() {
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
7873
|
-
});
|
|
7834
|
+
}, _MedplumClient_refreshProfile = async function _MedplumClient_refreshProfile() {
|
|
7835
|
+
__classPrivateFieldSet(this, _MedplumClient_profilePromise, new Promise((resolve, reject) => {
|
|
7836
|
+
this.get('auth/me')
|
|
7837
|
+
.then((result) => {
|
|
7838
|
+
__classPrivateFieldSet(this, _MedplumClient_profilePromise, undefined, "f");
|
|
7839
|
+
__classPrivateFieldSet(this, _MedplumClient_profile, result.profile, "f");
|
|
7840
|
+
__classPrivateFieldSet(this, _MedplumClient_config, result.config, "f");
|
|
7841
|
+
this.dispatchEvent({ type: 'change' });
|
|
7842
|
+
resolve(__classPrivateFieldGet(this, _MedplumClient_profile, "f"));
|
|
7843
|
+
})
|
|
7844
|
+
.catch(reject);
|
|
7845
|
+
}), "f");
|
|
7846
|
+
return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
|
|
7874
7847
|
}, _MedplumClient_getCacheEntry = function _MedplumClient_getCacheEntry(key, options) {
|
|
7875
|
-
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") <= 0 ||
|
|
7848
|
+
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") <= 0 || options?.cache === 'no-cache' || options?.cache === 'reload') {
|
|
7876
7849
|
return undefined;
|
|
7877
7850
|
}
|
|
7878
7851
|
const entry = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(key);
|
|
@@ -7884,31 +7857,37 @@
|
|
|
7884
7857
|
if (__classPrivateFieldGet(this, _MedplumClient_cacheTime, "f") > 0) {
|
|
7885
7858
|
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(key, { requestTime: Date.now(), value });
|
|
7886
7859
|
}
|
|
7887
|
-
}, _MedplumClient_request =
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7860
|
+
}, _MedplumClient_request =
|
|
7861
|
+
/**
|
|
7862
|
+
* Makes an HTTP request.
|
|
7863
|
+
* @param {string} method
|
|
7864
|
+
* @param {string} url
|
|
7865
|
+
* @param {string=} contentType
|
|
7866
|
+
* @param {Object=} body
|
|
7867
|
+
*/
|
|
7868
|
+
async function _MedplumClient_request(method, url, options = {}) {
|
|
7869
|
+
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
7870
|
+
await __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
7871
|
+
}
|
|
7872
|
+
if (!url.startsWith('http')) {
|
|
7873
|
+
url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
|
|
7874
|
+
}
|
|
7875
|
+
options.method = method;
|
|
7876
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
7877
|
+
const response = await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
|
|
7878
|
+
if (response.status === 401) {
|
|
7879
|
+
// Refresh and try again
|
|
7880
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, options);
|
|
7881
|
+
}
|
|
7882
|
+
if (response.status === 204 || response.status === 304) {
|
|
7883
|
+
// No content or change
|
|
7884
|
+
return undefined;
|
|
7885
|
+
}
|
|
7886
|
+
const obj = await response.json();
|
|
7887
|
+
if (response.status >= 400) {
|
|
7888
|
+
throw obj;
|
|
7889
|
+
}
|
|
7890
|
+
return obj;
|
|
7912
7891
|
}, _MedplumClient_addFetchOptionsDefaults = function _MedplumClient_addFetchOptionsDefaults(options) {
|
|
7913
7892
|
if (!options.headers) {
|
|
7914
7893
|
options.headers = {};
|
|
@@ -7947,23 +7926,28 @@
|
|
|
7947
7926
|
if (__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)) {
|
|
7948
7927
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, options);
|
|
7949
7928
|
}
|
|
7950
|
-
this.
|
|
7929
|
+
this.clearActiveLogin();
|
|
7951
7930
|
if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
|
|
7952
7931
|
__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f").call(this);
|
|
7953
7932
|
}
|
|
7954
7933
|
return Promise.reject(new Error('Unauthenticated'));
|
|
7955
|
-
}, _MedplumClient_requestAuthorization =
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7934
|
+
}, _MedplumClient_requestAuthorization =
|
|
7935
|
+
/**
|
|
7936
|
+
* Redirects the user to the login screen for authorization.
|
|
7937
|
+
* Clears all auth state including local storage and session storage.
|
|
7938
|
+
* See: https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint
|
|
7939
|
+
*/
|
|
7940
|
+
async function _MedplumClient_requestAuthorization(loginParams) {
|
|
7941
|
+
const loginRequest = await this.ensureCodeChallenge(loginParams || {});
|
|
7942
|
+
const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
|
|
7943
|
+
url.searchParams.set('response_type', 'code');
|
|
7944
|
+
url.searchParams.set('state', sessionStorage.getItem('pkceState'));
|
|
7945
|
+
url.searchParams.set('client_id', loginRequest.clientId || __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
7946
|
+
url.searchParams.set('redirect_uri', loginRequest.redirectUri || getBaseUrl());
|
|
7947
|
+
url.searchParams.set('code_challenge_method', loginRequest.codeChallengeMethod);
|
|
7948
|
+
url.searchParams.set('code_challenge', loginRequest.codeChallenge);
|
|
7949
|
+
url.searchParams.set('scope', loginRequest.scope || 'openid profile');
|
|
7950
|
+
window.location.assign(url.toString());
|
|
7967
7951
|
}, _MedplumClient_refresh = function _MedplumClient_refresh() {
|
|
7968
7952
|
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
7969
7953
|
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
@@ -7981,43 +7965,51 @@
|
|
|
7981
7965
|
return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
7982
7966
|
}
|
|
7983
7967
|
return undefined;
|
|
7984
|
-
}, _MedplumClient_fetchTokens =
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
return response.json();
|
|
7997
|
-
})
|
|
7998
|
-
.then((tokens) => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_verifyTokens).call(this, tokens))
|
|
7999
|
-
.then(() => this.getProfile());
|
|
7968
|
+
}, _MedplumClient_fetchTokens =
|
|
7969
|
+
/**
|
|
7970
|
+
* Makes a POST request to the tokens endpoint.
|
|
7971
|
+
* See: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
|
|
7972
|
+
* @param formBody Token parameters in URL encoded format.
|
|
7973
|
+
*/
|
|
7974
|
+
async function _MedplumClient_fetchTokens(formBody) {
|
|
7975
|
+
const response = await __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
|
|
7976
|
+
method: 'POST',
|
|
7977
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
7978
|
+
body: formBody,
|
|
7979
|
+
credentials: 'include',
|
|
8000
7980
|
});
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
7981
|
+
if (!response.ok) {
|
|
7982
|
+
this.clearActiveLogin();
|
|
7983
|
+
throw new Error('Failed to fetch tokens');
|
|
7984
|
+
}
|
|
7985
|
+
const tokens = await response.json();
|
|
7986
|
+
await __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_verifyTokens).call(this, tokens);
|
|
7987
|
+
return this.getProfile();
|
|
7988
|
+
}, _MedplumClient_verifyTokens =
|
|
7989
|
+
/**
|
|
7990
|
+
* Verifies the tokens received from the auth server.
|
|
7991
|
+
* Validates the JWT against the JWKS.
|
|
7992
|
+
* See: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
|
|
7993
|
+
* @param tokens
|
|
7994
|
+
*/
|
|
7995
|
+
async function _MedplumClient_verifyTokens(tokens) {
|
|
7996
|
+
const token = tokens.access_token;
|
|
7997
|
+
// Verify token has not expired
|
|
7998
|
+
const tokenPayload = parseJWTPayload(token);
|
|
7999
|
+
if (Date.now() >= tokenPayload.exp * 1000) {
|
|
8000
|
+
this.clearActiveLogin();
|
|
8001
|
+
throw new Error('Token expired');
|
|
8002
|
+
}
|
|
8003
|
+
// Verify app_client_id
|
|
8004
|
+
if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
|
|
8005
|
+
this.clearActiveLogin();
|
|
8006
|
+
throw new Error('Token was not issued for this audience');
|
|
8007
|
+
}
|
|
8008
|
+
return this.setActiveLogin({
|
|
8009
|
+
accessToken: token,
|
|
8010
|
+
refreshToken: tokens.refresh_token,
|
|
8011
|
+
project: tokens.project,
|
|
8012
|
+
profile: tokens.profile,
|
|
8021
8013
|
});
|
|
8022
8014
|
}, _MedplumClient_setupStorageListener = function _MedplumClient_setupStorageListener() {
|
|
8023
8015
|
try {
|
|
@@ -8117,7 +8109,7 @@
|
|
|
8117
8109
|
}
|
|
8118
8110
|
match(expected) {
|
|
8119
8111
|
const token = this.peek();
|
|
8120
|
-
if (
|
|
8112
|
+
if (token?.id !== expected) {
|
|
8121
8113
|
return false;
|
|
8122
8114
|
}
|
|
8123
8115
|
this.consume();
|
|
@@ -8149,15 +8141,14 @@
|
|
|
8149
8141
|
return Infinity;
|
|
8150
8142
|
}
|
|
8151
8143
|
consume(expectedId, expectedValue) {
|
|
8152
|
-
var _a, _b;
|
|
8153
8144
|
if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
|
|
8154
8145
|
throw Error('Cant consume unknown more tokens.');
|
|
8155
8146
|
}
|
|
8156
|
-
if (expectedId &&
|
|
8147
|
+
if (expectedId && this.peek()?.id !== expectedId) {
|
|
8157
8148
|
const actual = this.peek();
|
|
8158
8149
|
throw Error(`Expected ${expectedId} but got "${actual.id}" at line ${actual.line} column ${actual.column}.`);
|
|
8159
8150
|
}
|
|
8160
|
-
if (expectedValue &&
|
|
8151
|
+
if (expectedValue && this.peek()?.value !== expectedValue) {
|
|
8161
8152
|
const actual = this.peek();
|
|
8162
8153
|
throw Error(`Expected "${expectedValue}" but got "${actual.value}" at line ${actual.line} column ${actual.column}.`);
|
|
8163
8154
|
}
|
|
@@ -8313,9 +8304,8 @@
|
|
|
8313
8304
|
}
|
|
8314
8305
|
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
8306
|
}, _Tokenizer_consumeSymbol = function _Tokenizer_consumeSymbol() {
|
|
8316
|
-
var _a;
|
|
8317
8307
|
const value = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/));
|
|
8318
|
-
if (
|
|
8308
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prevToken).call(this)?.value !== '.' && __classPrivateFieldGet(this, _Tokenizer_keywords, "f").includes(value)) {
|
|
8319
8309
|
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, value, value);
|
|
8320
8310
|
}
|
|
8321
8311
|
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_buildToken).call(this, 'Symbol', value);
|
|
@@ -8339,13 +8329,11 @@
|
|
|
8339
8329
|
}, _Tokenizer_curr = function _Tokenizer_curr() {
|
|
8340
8330
|
return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index];
|
|
8341
8331
|
}, _Tokenizer_prev = function _Tokenizer_prev() {
|
|
8342
|
-
|
|
8343
|
-
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1]) !== null && _a !== void 0 ? _a : '';
|
|
8332
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index - 1] ?? '';
|
|
8344
8333
|
}, _Tokenizer_peek = function _Tokenizer_peek() {
|
|
8345
|
-
|
|
8346
|
-
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1]) !== null && _a !== void 0 ? _a : '';
|
|
8334
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f").index + 1] ?? '';
|
|
8347
8335
|
}, _Tokenizer_mark = function _Tokenizer_mark() {
|
|
8348
|
-
__classPrivateFieldGet(this, _Tokenizer_markStack, "f").push(
|
|
8336
|
+
__classPrivateFieldGet(this, _Tokenizer_markStack, "f").push({ ...__classPrivateFieldGet(this, _Tokenizer_pos, "f") });
|
|
8349
8337
|
}, _Tokenizer_reset = function _Tokenizer_reset() {
|
|
8350
8338
|
const mark = __classPrivateFieldGet(this, _Tokenizer_markStack, "f").pop();
|
|
8351
8339
|
if (!mark) {
|
|
@@ -8368,8 +8356,11 @@
|
|
|
8368
8356
|
if (!mark) {
|
|
8369
8357
|
throw new Error('No mark for token');
|
|
8370
8358
|
}
|
|
8371
|
-
return
|
|
8372
|
-
|
|
8359
|
+
return {
|
|
8360
|
+
id,
|
|
8361
|
+
value,
|
|
8362
|
+
...mark,
|
|
8363
|
+
};
|
|
8373
8364
|
};
|
|
8374
8365
|
function isUnitToken(token) {
|
|
8375
8366
|
if (token) {
|
|
@@ -8465,7 +8456,7 @@
|
|
|
8465
8456
|
* @returns The value of the property and the property type.
|
|
8466
8457
|
*/
|
|
8467
8458
|
function getTypedPropertyValue(input, path) {
|
|
8468
|
-
if (!
|
|
8459
|
+
if (!input?.value) {
|
|
8469
8460
|
return undefined;
|
|
8470
8461
|
}
|
|
8471
8462
|
const elementDefinition = getElementDefinition(input.type, path);
|
|
@@ -8485,7 +8476,6 @@
|
|
|
8485
8476
|
* @returns The value of the property and the property type.
|
|
8486
8477
|
*/
|
|
8487
8478
|
function getTypedPropertyValueWithSchema(input, path, property) {
|
|
8488
|
-
var _a;
|
|
8489
8479
|
const types = property.type;
|
|
8490
8480
|
if (!types || types.length === 0) {
|
|
8491
8481
|
return undefined;
|
|
@@ -8510,7 +8500,7 @@
|
|
|
8510
8500
|
return undefined;
|
|
8511
8501
|
}
|
|
8512
8502
|
if (resultType === 'Element' || resultType === 'BackboneElement') {
|
|
8513
|
-
resultType = buildTypeName(
|
|
8503
|
+
resultType = buildTypeName(property.path?.split('.'));
|
|
8514
8504
|
}
|
|
8515
8505
|
if (Array.isArray(resultValue)) {
|
|
8516
8506
|
return resultValue.map((element) => toTypedValueWithType(element, resultType));
|
|
@@ -8721,7 +8711,7 @@
|
|
|
8721
8711
|
case 'Quantity':
|
|
8722
8712
|
return isQuantity(value);
|
|
8723
8713
|
default:
|
|
8724
|
-
return typeof value === 'object' &&
|
|
8714
|
+
return typeof value === 'object' && value?.resourceType === desiredType;
|
|
8725
8715
|
}
|
|
8726
8716
|
}
|
|
8727
8717
|
/**
|
|
@@ -9110,8 +9100,7 @@
|
|
|
9110
9100
|
* @returns A collection containing all but the first item in the input collection.
|
|
9111
9101
|
*/
|
|
9112
9102
|
skip: (input, num) => {
|
|
9113
|
-
|
|
9114
|
-
const numValue = (_a = num.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
|
|
9103
|
+
const numValue = num.eval(input)[0]?.value;
|
|
9115
9104
|
if (typeof numValue !== 'number') {
|
|
9116
9105
|
throw new Error('Expected a number for skip(num)');
|
|
9117
9106
|
}
|
|
@@ -9135,8 +9124,7 @@
|
|
|
9135
9124
|
* @returns A collection containing the first num items in the input collection.
|
|
9136
9125
|
*/
|
|
9137
9126
|
take: (input, num) => {
|
|
9138
|
-
|
|
9139
|
-
const numValue = (_a = num.eval(input)[0]) === null || _a === void 0 ? void 0 : _a.value;
|
|
9127
|
+
const numValue = num.eval(input)[0]?.value;
|
|
9140
9128
|
if (typeof numValue !== 'number') {
|
|
9141
9129
|
throw new Error('Expected a number for take(num)');
|
|
9142
9130
|
}
|
|
@@ -10080,7 +10068,6 @@
|
|
|
10080
10068
|
* IBM FHIR PR: https://github.com/IBM/FHIR/pull/1023
|
|
10081
10069
|
*/
|
|
10082
10070
|
between: (input, startAtom, endAtom, unitsAtom) => {
|
|
10083
|
-
var _a;
|
|
10084
10071
|
const startDate = functions.toDateTime(startAtom.eval(input));
|
|
10085
10072
|
if (startDate.length === 0) {
|
|
10086
10073
|
throw new Error('Invalid start date');
|
|
@@ -10089,7 +10076,7 @@
|
|
|
10089
10076
|
if (endDate.length === 0) {
|
|
10090
10077
|
throw new Error('Invalid end date');
|
|
10091
10078
|
}
|
|
10092
|
-
const unit =
|
|
10079
|
+
const unit = unitsAtom.eval(input)[0]?.value;
|
|
10093
10080
|
if (unit !== 'years' && unit !== 'months' && unit !== 'days') {
|
|
10094
10081
|
throw new Error('Invalid units');
|
|
10095
10082
|
}
|
|
@@ -10220,13 +10207,10 @@
|
|
|
10220
10207
|
throw new Error('Expected a StructureDefinition URL');
|
|
10221
10208
|
}
|
|
10222
10209
|
const expectedResourceType = system.replace('http://hl7.org/fhir/StructureDefinition/', '');
|
|
10223
|
-
return input.map((value) => {
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
|
|
10227
|
-
value: ((_a = value.value) === null || _a === void 0 ? void 0 : _a.resourceType) === expectedResourceType,
|
|
10228
|
-
});
|
|
10229
|
-
});
|
|
10210
|
+
return input.map((value) => ({
|
|
10211
|
+
type: exports.PropertyType.boolean,
|
|
10212
|
+
value: value.value?.resourceType === expectedResourceType,
|
|
10213
|
+
}));
|
|
10230
10214
|
},
|
|
10231
10215
|
};
|
|
10232
10216
|
/*
|
|
@@ -10240,7 +10224,7 @@
|
|
|
10240
10224
|
if (typeof value !== 'string') {
|
|
10241
10225
|
throw new Error('String function cannot be called with non-string');
|
|
10242
10226
|
}
|
|
10243
|
-
const result = func(value, ...argsAtoms.map((atom) =>
|
|
10227
|
+
const result = func(value, ...argsAtoms.map((atom) => atom && atom.eval(input)?.[0]?.value));
|
|
10244
10228
|
if (result === undefined) {
|
|
10245
10229
|
return [];
|
|
10246
10230
|
}
|
|
@@ -10259,9 +10243,9 @@
|
|
|
10259
10243
|
if (typeof numberInput !== 'number') {
|
|
10260
10244
|
throw new Error('Math function cannot be called with non-number');
|
|
10261
10245
|
}
|
|
10262
|
-
const result = func(numberInput, ...argsAtoms.map((atom) =>
|
|
10246
|
+
const result = func(numberInput, ...argsAtoms.map((atom) => atom.eval(input)?.[0]?.value));
|
|
10263
10247
|
const type = quantity ? exports.PropertyType.Quantity : input[0].type;
|
|
10264
|
-
const returnValue = quantity ?
|
|
10248
|
+
const returnValue = quantity ? { ...value, value: result } : result;
|
|
10265
10249
|
return [{ type, value: returnValue }];
|
|
10266
10250
|
}
|
|
10267
10251
|
function validateInput(input, count) {
|
|
@@ -10326,7 +10310,7 @@
|
|
|
10326
10310
|
return context
|
|
10327
10311
|
.map((e) => __classPrivateFieldGet(this, _SymbolAtom_instances, "m", _SymbolAtom_evalValue).call(this, e))
|
|
10328
10312
|
.flat()
|
|
10329
|
-
.filter((e) =>
|
|
10313
|
+
.filter((e) => e?.value !== undefined);
|
|
10330
10314
|
}
|
|
10331
10315
|
toString() {
|
|
10332
10316
|
return this.name;
|
|
@@ -10393,7 +10377,7 @@
|
|
|
10393
10377
|
return booleanToTypedValue(result);
|
|
10394
10378
|
}
|
|
10395
10379
|
else if (isQuantity(leftValue)) {
|
|
10396
|
-
return [{ type: exports.PropertyType.Quantity, value:
|
|
10380
|
+
return [{ type: exports.PropertyType.Quantity, value: { ...leftValue, value: result } }];
|
|
10397
10381
|
}
|
|
10398
10382
|
else {
|
|
10399
10383
|
return [toTypedValue(result)];
|
|
@@ -10519,13 +10503,12 @@
|
|
|
10519
10503
|
super('and', left, right);
|
|
10520
10504
|
}
|
|
10521
10505
|
eval(context) {
|
|
10522
|
-
var _a, _b, _c, _d;
|
|
10523
10506
|
const leftValue = this.left.eval(context);
|
|
10524
10507
|
const rightValue = this.right.eval(context);
|
|
10525
|
-
if (
|
|
10508
|
+
if (leftValue[0]?.value === true && rightValue[0]?.value === true) {
|
|
10526
10509
|
return booleanToTypedValue(true);
|
|
10527
10510
|
}
|
|
10528
|
-
if (
|
|
10511
|
+
if (leftValue[0]?.value === false || rightValue[0]?.value === false) {
|
|
10529
10512
|
return booleanToTypedValue(false);
|
|
10530
10513
|
}
|
|
10531
10514
|
return [];
|
|
@@ -10623,10 +10606,9 @@
|
|
|
10623
10606
|
|
|
10624
10607
|
const PARENTHESES_PARSELET = {
|
|
10625
10608
|
parse(parser) {
|
|
10626
|
-
var _a;
|
|
10627
10609
|
const expr = parser.consumeAndParse();
|
|
10628
10610
|
if (!parser.match(')')) {
|
|
10629
|
-
throw new Error('Parse error: expected `)` got `' +
|
|
10611
|
+
throw new Error('Parse error: expected `)` got `' + parser.peek()?.value + '`');
|
|
10630
10612
|
}
|
|
10631
10613
|
return expr;
|
|
10632
10614
|
},
|
|
@@ -10833,15 +10815,14 @@
|
|
|
10833
10815
|
* @returns The HL7 "ACK" message.
|
|
10834
10816
|
*/
|
|
10835
10817
|
buildAck() {
|
|
10836
|
-
var _a, _b, _c, _d, _e, _f;
|
|
10837
10818
|
const now = new Date();
|
|
10838
10819
|
const msh = this.get('MSH');
|
|
10839
|
-
const sendingApp =
|
|
10840
|
-
const sendingFacility =
|
|
10841
|
-
const receivingApp =
|
|
10842
|
-
const receivingFacility =
|
|
10843
|
-
const controlId =
|
|
10844
|
-
const versionId =
|
|
10820
|
+
const sendingApp = msh?.get(2)?.toString() || '';
|
|
10821
|
+
const sendingFacility = msh?.get(3)?.toString() || '';
|
|
10822
|
+
const receivingApp = msh?.get(4)?.toString() || '';
|
|
10823
|
+
const receivingFacility = msh?.get(5)?.toString() || '';
|
|
10824
|
+
const controlId = msh?.get(9)?.toString() || '';
|
|
10825
|
+
const versionId = msh?.get(12)?.toString() || '2.5.1';
|
|
10845
10826
|
return new Hl7Message([
|
|
10846
10827
|
new Hl7Segment([
|
|
10847
10828
|
'MSH',
|
|
@@ -11203,8 +11184,7 @@
|
|
|
11203
11184
|
* @returns The search parameter type details.
|
|
11204
11185
|
*/
|
|
11205
11186
|
function getSearchParameterDetails(resourceType, searchParam) {
|
|
11206
|
-
|
|
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];
|
|
11187
|
+
let result = globalSchema.types[resourceType]?.searchParamsDetails?.[searchParam.code];
|
|
11208
11188
|
if (!result) {
|
|
11209
11189
|
result = buildSearchParamterDetails(resourceType, searchParam);
|
|
11210
11190
|
}
|
|
@@ -11218,13 +11198,12 @@
|
|
|
11218
11198
|
typeSchema.searchParamsDetails[code] = details;
|
|
11219
11199
|
}
|
|
11220
11200
|
function buildSearchParamterDetails(resourceType, searchParam) {
|
|
11221
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
11222
11201
|
if (searchParam.code === '_lastUpdated') {
|
|
11223
11202
|
return { columnName: 'lastUpdated', type: exports.SearchParameterType.DATETIME };
|
|
11224
11203
|
}
|
|
11225
11204
|
const code = searchParam.code;
|
|
11226
11205
|
const columnName = convertCodeToColumnName(code);
|
|
11227
|
-
const expression =
|
|
11206
|
+
const expression = getExpressionForResourceType(resourceType, searchParam.expression)?.split('.');
|
|
11228
11207
|
if (!expression) {
|
|
11229
11208
|
// This happens on compound types
|
|
11230
11209
|
// In the future, explore returning multiple column definitions
|
|
@@ -11238,14 +11217,15 @@
|
|
|
11238
11217
|
for (let i = 1; i < expression.length; i++) {
|
|
11239
11218
|
const propertyName = expression[i];
|
|
11240
11219
|
elementDefinition =
|
|
11241
|
-
|
|
11220
|
+
globalSchema.types[baseType]?.properties?.[propertyName] ??
|
|
11221
|
+
globalSchema.types[baseType]?.properties?.[propertyName + '[x]'];
|
|
11242
11222
|
if (!elementDefinition) {
|
|
11243
11223
|
throw new Error(`Element definition not found for ${resourceType} ${searchParam.code}`);
|
|
11244
11224
|
}
|
|
11245
11225
|
if (elementDefinition.max === '*') {
|
|
11246
11226
|
array = true;
|
|
11247
11227
|
}
|
|
11248
|
-
propertyType =
|
|
11228
|
+
propertyType = elementDefinition.type?.[0].code;
|
|
11249
11229
|
if (!propertyType) {
|
|
11250
11230
|
// This happens when one of parent properties uses contentReference
|
|
11251
11231
|
// In the future, explore following the reference
|
|
@@ -11360,9 +11340,8 @@
|
|
|
11360
11340
|
* @returns True if the resource satisfies the search filter.
|
|
11361
11341
|
*/
|
|
11362
11342
|
function matchesSearchFilter(resource, searchRequest, filter) {
|
|
11363
|
-
|
|
11364
|
-
|
|
11365
|
-
switch (searchParam === null || searchParam === void 0 ? void 0 : searchParam.type) {
|
|
11343
|
+
const searchParam = globalSchema.types[searchRequest.resourceType]?.searchParams?.[filter.code];
|
|
11344
|
+
switch (searchParam?.type) {
|
|
11366
11345
|
case 'reference':
|
|
11367
11346
|
return matchesReferenceFilter(resource, filter, searchParam);
|
|
11368
11347
|
case 'string':
|
|
@@ -11393,7 +11372,7 @@
|
|
|
11393
11372
|
// In previous versions, the resource type was not required in compartment values
|
|
11394
11373
|
// So, "123" would match "Patient/123"
|
|
11395
11374
|
// We need to maintain this behavior for backwards compatibility
|
|
11396
|
-
match = references.some((reference) => reference
|
|
11375
|
+
match = references.some((reference) => reference?.endsWith('/' + filterValue));
|
|
11397
11376
|
}
|
|
11398
11377
|
if (match) {
|
|
11399
11378
|
return !negated;
|
|
@@ -11661,8 +11640,7 @@
|
|
|
11661
11640
|
}
|
|
11662
11641
|
class OperationOutcomeError extends Error {
|
|
11663
11642
|
constructor(outcome) {
|
|
11664
|
-
|
|
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);
|
|
11643
|
+
super(outcome?.issue?.[0].details?.text);
|
|
11666
11644
|
this.outcome = outcome;
|
|
11667
11645
|
}
|
|
11668
11646
|
}
|
|
@@ -11672,7 +11650,6 @@
|
|
|
11672
11650
|
* @returns A display string for the error.
|
|
11673
11651
|
*/
|
|
11674
11652
|
function normalizeErrorString(error) {
|
|
11675
|
-
var _a, _b, _c, _d;
|
|
11676
11653
|
if (!error) {
|
|
11677
11654
|
return 'Unknown error';
|
|
11678
11655
|
}
|
|
@@ -11684,7 +11661,7 @@
|
|
|
11684
11661
|
}
|
|
11685
11662
|
if (typeof error === 'object' && 'resourceType' in error) {
|
|
11686
11663
|
const outcome = error;
|
|
11687
|
-
return
|
|
11664
|
+
return outcome.issue?.[0]?.details?.text ?? 'Unknown error';
|
|
11688
11665
|
}
|
|
11689
11666
|
return JSON.stringify(error);
|
|
11690
11667
|
}
|
|
@@ -11757,6 +11734,7 @@
|
|
|
11757
11734
|
exports.formatFamilyName = formatFamilyName;
|
|
11758
11735
|
exports.formatGivenName = formatGivenName;
|
|
11759
11736
|
exports.formatHumanName = formatHumanName;
|
|
11737
|
+
exports.formatMoney = formatMoney;
|
|
11760
11738
|
exports.formatObservationValue = formatObservationValue;
|
|
11761
11739
|
exports.formatPeriod = formatPeriod;
|
|
11762
11740
|
exports.formatQuantity = formatQuantity;
|
|
@@ -11769,6 +11747,7 @@
|
|
|
11769
11747
|
exports.getDisplayString = getDisplayString;
|
|
11770
11748
|
exports.getElementDefinition = getElementDefinition;
|
|
11771
11749
|
exports.getExpressionForResourceType = getExpressionForResourceType;
|
|
11750
|
+
exports.getExtension = getExtension;
|
|
11772
11751
|
exports.getExtensionValue = getExtensionValue;
|
|
11773
11752
|
exports.getIdentifier = getIdentifier;
|
|
11774
11753
|
exports.getImageSrc = getImageSrc;
|
|
@@ -11823,4 +11802,4 @@
|
|
|
11823
11802
|
exports.unauthorized = unauthorized;
|
|
11824
11803
|
|
|
11825
11804
|
}));
|
|
11826
|
-
//# sourceMappingURL=index.
|
|
11805
|
+
//# sourceMappingURL=index.cjs.map
|