@medplum/core 0.9.5 → 0.9.8
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 +3 -23
- package/cody-pdf-test.js +32 -0
- package/dist/cjs/index.js +2992 -240
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/cjs/package.json +1 -0
- package/dist/esm/index.js +2987 -239
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/package.json +1 -0
- package/dist/types/cache.d.ts +22 -0
- package/dist/types/client.d.ts +202 -81
- package/dist/types/fhirpath/atoms.d.ts +148 -0
- package/dist/types/fhirpath/date.d.ts +1 -0
- package/dist/types/fhirpath/functions.d.ts +5 -0
- package/dist/types/fhirpath/index.d.ts +2 -0
- package/dist/types/fhirpath/parse.d.ts +17 -0
- package/dist/types/fhirpath/tokenize.d.ts +5 -0
- package/dist/types/fhirpath/utils.d.ts +84 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/pdf.d.ts +5 -0
- package/dist/types/utils.d.ts +12 -0
- package/document.pdf +0 -0
- package/package.json +10 -3
- package/test.pdf +1 -0
- package/test2.pdf +1 -0
- package/test3.pdf.txt +1 -0
- package/test4.pdf +1 -0
- package/test5.pdf +0 -0
- package/test7-2.pdf +1 -0
- package/test7.pdf +1 -0
- package/test8-2.pdf +0 -0
- package/{dist/types/fix-ro-iddentifiers.d.ts → test8.pdf} +0 -0
- package/wget-log +6 -0
package/dist/esm/index.js
CHANGED
|
@@ -49,9 +49,17 @@ class LRUCache {
|
|
|
49
49
|
__classPrivateFieldSet(this, _LRUCache_max, max, "f");
|
|
50
50
|
__classPrivateFieldSet(this, _LRUCache_cache, new Map(), "f");
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Deletes all values from the cache.
|
|
54
|
+
*/
|
|
52
55
|
clear() {
|
|
53
56
|
__classPrivateFieldGet(this, _LRUCache_cache, "f").clear();
|
|
54
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the value for the given key.
|
|
60
|
+
* @param key The key to retrieve.
|
|
61
|
+
* @returns The value if found; undefined otherwise.
|
|
62
|
+
*/
|
|
55
63
|
get(key) {
|
|
56
64
|
const item = __classPrivateFieldGet(this, _LRUCache_cache, "f").get(key);
|
|
57
65
|
if (item) {
|
|
@@ -60,6 +68,11 @@ class LRUCache {
|
|
|
60
68
|
}
|
|
61
69
|
return item;
|
|
62
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Sets the value for the given key.
|
|
73
|
+
* @param key The key to set.
|
|
74
|
+
* @param val The value to set.
|
|
75
|
+
*/
|
|
63
76
|
set(key, val) {
|
|
64
77
|
if (__classPrivateFieldGet(this, _LRUCache_cache, "f").has(key)) {
|
|
65
78
|
__classPrivateFieldGet(this, _LRUCache_cache, "f").delete(key);
|
|
@@ -69,9 +82,20 @@ class LRUCache {
|
|
|
69
82
|
}
|
|
70
83
|
__classPrivateFieldGet(this, _LRUCache_cache, "f").set(key, val);
|
|
71
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Deletes the value for the given key.
|
|
87
|
+
* @param key The key to delete.
|
|
88
|
+
*/
|
|
72
89
|
delete(key) {
|
|
73
90
|
__classPrivateFieldGet(this, _LRUCache_cache, "f").delete(key);
|
|
74
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the list of all keys in the cache.
|
|
94
|
+
* @returns The array of keys in the cache.
|
|
95
|
+
*/
|
|
96
|
+
keys() {
|
|
97
|
+
return __classPrivateFieldGet(this, _LRUCache_cache, "f").keys();
|
|
98
|
+
}
|
|
75
99
|
}
|
|
76
100
|
_LRUCache_max = new WeakMap(), _LRUCache_cache = new WeakMap(), _LRUCache_instances = new WeakSet(), _LRUCache_first = function _LRUCache_first() {
|
|
77
101
|
// This works because the Map class maintains ordered keys.
|
|
@@ -337,6 +361,30 @@ function buildQuestionnaireAnswerItems(items, result) {
|
|
|
337
361
|
}
|
|
338
362
|
}
|
|
339
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* Returns the resource identifier for the given system.
|
|
366
|
+
*
|
|
367
|
+
* If multiple identifiers exist with the same system, the first one is returned.
|
|
368
|
+
*
|
|
369
|
+
* If the system is not found, then returns undefined.
|
|
370
|
+
*
|
|
371
|
+
* @param resource The resource to check.
|
|
372
|
+
* @param system The identifier system.
|
|
373
|
+
* @returns The identifier value if found; otherwise undefined.
|
|
374
|
+
*/
|
|
375
|
+
function getIdentifier(resource, system) {
|
|
376
|
+
const identifiers = resource.identifier;
|
|
377
|
+
if (!identifiers) {
|
|
378
|
+
return undefined;
|
|
379
|
+
}
|
|
380
|
+
const array = Array.isArray(identifiers) ? identifiers : [identifiers];
|
|
381
|
+
for (const identifier of array) {
|
|
382
|
+
if (identifier.system === system) {
|
|
383
|
+
return identifier.value;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
340
388
|
/**
|
|
341
389
|
* Returns an extension value by extension URLs.
|
|
342
390
|
* @param resource The base resource.
|
|
@@ -402,7 +450,7 @@ function isEmpty(v) {
|
|
|
402
450
|
* @param object2 The second object.
|
|
403
451
|
* @returns True if the objects are equal.
|
|
404
452
|
*/
|
|
405
|
-
function deepEquals(object1, object2, path) {
|
|
453
|
+
function deepEquals$1(object1, object2, path) {
|
|
406
454
|
if (object1 === object2) {
|
|
407
455
|
return true;
|
|
408
456
|
}
|
|
@@ -418,10 +466,10 @@ function deepEquals(object1, object2, path) {
|
|
|
418
466
|
if (Array.isArray(object1) || Array.isArray(object2)) {
|
|
419
467
|
return false;
|
|
420
468
|
}
|
|
421
|
-
if (isObject(object1) && isObject(object2)) {
|
|
469
|
+
if (isObject$1(object1) && isObject$1(object2)) {
|
|
422
470
|
return deepEqualsObject(object1, object2, path);
|
|
423
471
|
}
|
|
424
|
-
if (isObject(object1) || isObject(object2)) {
|
|
472
|
+
if (isObject$1(object1) || isObject$1(object2)) {
|
|
425
473
|
return false;
|
|
426
474
|
}
|
|
427
475
|
return false;
|
|
@@ -431,7 +479,7 @@ function deepEqualsArray(array1, array2) {
|
|
|
431
479
|
return false;
|
|
432
480
|
}
|
|
433
481
|
for (let i = 0; i < array1.length; i++) {
|
|
434
|
-
if (!deepEquals(array1[i], array2[i])) {
|
|
482
|
+
if (!deepEquals$1(array1[i], array2[i])) {
|
|
435
483
|
return false;
|
|
436
484
|
}
|
|
437
485
|
}
|
|
@@ -449,7 +497,7 @@ function deepEqualsObject(object1, object2, path) {
|
|
|
449
497
|
for (const key of keySet) {
|
|
450
498
|
const val1 = object1[key];
|
|
451
499
|
const val2 = object2[key];
|
|
452
|
-
if (!deepEquals(val1, val2, key)) {
|
|
500
|
+
if (!deepEquals$1(val1, val2, key)) {
|
|
453
501
|
return false;
|
|
454
502
|
}
|
|
455
503
|
}
|
|
@@ -468,7 +516,7 @@ function isUUID(input) {
|
|
|
468
516
|
* @param object The candidate object.
|
|
469
517
|
* @returns True if the input is a non-null non-undefined object.
|
|
470
518
|
*/
|
|
471
|
-
function isObject(obj) {
|
|
519
|
+
function isObject$1(obj) {
|
|
472
520
|
return obj !== null && typeof obj === 'object';
|
|
473
521
|
}
|
|
474
522
|
/**
|
|
@@ -756,6 +804,91 @@ class OperationOutcomeError extends Error {
|
|
|
756
804
|
}
|
|
757
805
|
}
|
|
758
806
|
|
|
807
|
+
/*
|
|
808
|
+
* This file attempts a unified "generatePdf" function that works both client-side and server-side.
|
|
809
|
+
* On client-side, it checks for a global "pdfMake" variable.
|
|
810
|
+
* On server-side, it dynamically loads "pdfmake" from the node_modules.
|
|
811
|
+
*/
|
|
812
|
+
function generatePdf(docDefinition, tableLayouts, fonts) {
|
|
813
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
814
|
+
// Setup sane defaults
|
|
815
|
+
// See: https://pdfmake.github.io/docs/0.1/document-definition-object/styling/
|
|
816
|
+
docDefinition.pageSize = docDefinition.pageSize || 'LETTER';
|
|
817
|
+
docDefinition.pageMargins = docDefinition.pageMargins || [60, 60, 60, 60];
|
|
818
|
+
docDefinition.pageOrientation = docDefinition.pageOrientation || 'portrait';
|
|
819
|
+
docDefinition.defaultStyle = docDefinition.defaultStyle || {};
|
|
820
|
+
docDefinition.defaultStyle.font = docDefinition.defaultStyle.font || 'Helvetica';
|
|
821
|
+
docDefinition.defaultStyle.fontSize = docDefinition.defaultStyle.fontSize || 11;
|
|
822
|
+
docDefinition.defaultStyle.lineHeight = docDefinition.defaultStyle.lineHeight || 2.0;
|
|
823
|
+
if (typeof pdfMake === 'undefined') {
|
|
824
|
+
return generatePdfServerSide(docDefinition, tableLayouts, fonts);
|
|
825
|
+
}
|
|
826
|
+
else {
|
|
827
|
+
return generatePdfClientSide(docDefinition, tableLayouts, fonts);
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
function generatePdfServerSide(docDefinition, tableLayouts, fonts) {
|
|
832
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
833
|
+
if (!fonts) {
|
|
834
|
+
fonts = {
|
|
835
|
+
Helvetica: {
|
|
836
|
+
normal: 'Helvetica',
|
|
837
|
+
bold: 'Helvetica-Bold',
|
|
838
|
+
italics: 'Helvetica-Oblique',
|
|
839
|
+
bolditalics: 'Helvetica-BoldOblique',
|
|
840
|
+
},
|
|
841
|
+
Roboto: {
|
|
842
|
+
normal: 'https://static.medplum.com/fonts/Roboto-Regular.ttf',
|
|
843
|
+
bold: 'https://static.medplum.com/fonts/Roboto-Medium.ttf',
|
|
844
|
+
italics: 'https://static.medplum.com/fonts/Roboto-Italic.ttf',
|
|
845
|
+
bolditalics: 'https://static.medplum.com/fonts/Roboto-MediumItalic.ttf',
|
|
846
|
+
},
|
|
847
|
+
Avenir: {
|
|
848
|
+
normal: 'https://static.medplum.com/fonts/avenir.ttf',
|
|
849
|
+
},
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
return new Promise((resolve, reject) => {
|
|
853
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
854
|
+
const PdfPrinter = require('pdfmake');
|
|
855
|
+
const printer = new PdfPrinter(fonts);
|
|
856
|
+
const pdfDoc = printer.createPdfKitDocument(docDefinition, { tableLayouts });
|
|
857
|
+
const chunks = [];
|
|
858
|
+
pdfDoc.on('data', (chunk) => chunks.push(chunk));
|
|
859
|
+
pdfDoc.on('end', () => resolve(Buffer.concat(chunks)));
|
|
860
|
+
pdfDoc.on('error', reject);
|
|
861
|
+
pdfDoc.end();
|
|
862
|
+
});
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
function generatePdfClientSide(docDefinition, tableLayouts, fonts) {
|
|
866
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
867
|
+
if (!fonts) {
|
|
868
|
+
fonts = {
|
|
869
|
+
Helvetica: {
|
|
870
|
+
normal: 'https://static.medplum.com/fonts/Helvetica.ttf',
|
|
871
|
+
bold: 'https://static.medplum.com/fonts/Helvetica-bold.ttf',
|
|
872
|
+
italics: 'https://static.medplum.com/fonts/Helvetica-italic.ttf',
|
|
873
|
+
bolditalics: 'https://static.medplum.com/fonts/Helvetica-bold-italic.ttf',
|
|
874
|
+
},
|
|
875
|
+
Roboto: {
|
|
876
|
+
normal: 'https://static.medplum.com/fonts/Roboto-Regular.ttf',
|
|
877
|
+
bold: 'https://static.medplum.com/fonts/Roboto-Medium.ttf',
|
|
878
|
+
italics: 'https://static.medplum.com/fonts/Roboto-Italic.ttf',
|
|
879
|
+
bolditalics: 'https://static.medplum.com/fonts/Roboto-MediumItalic.ttf',
|
|
880
|
+
},
|
|
881
|
+
Avenir: {
|
|
882
|
+
normal: 'https://static.medplum.com/fonts/avenir.ttf',
|
|
883
|
+
},
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
return new Promise((resolve) => {
|
|
887
|
+
pdfMake.createPdf(docDefinition, tableLayouts, fonts).getBlob(resolve);
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
|
|
759
892
|
var _ReadablePromise_suspender, _ReadablePromise_status, _ReadablePromise_response, _ReadablePromise_error, _a;
|
|
760
893
|
/**
|
|
761
894
|
* The ReadablePromise class wraps a request promise suitable for React Suspense.
|
|
@@ -1012,7 +1145,7 @@ function formatSearchQuery(definition) {
|
|
|
1012
1145
|
params.push('_count=' + definition.count);
|
|
1013
1146
|
}
|
|
1014
1147
|
if (definition.total !== undefined) {
|
|
1015
|
-
params.push('_total=' +
|
|
1148
|
+
params.push('_total=' + definition.total);
|
|
1016
1149
|
}
|
|
1017
1150
|
if (params.length === 0) {
|
|
1018
1151
|
return '';
|
|
@@ -1373,7 +1506,6 @@ const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
|
1373
1506
|
* const bundle = await medplum.search('Patient?name=Alice');
|
|
1374
1507
|
* console.log(bundle.total);
|
|
1375
1508
|
* ```
|
|
1376
|
-
*
|
|
1377
1509
|
*/
|
|
1378
1510
|
class MedplumClient extends EventTarget {
|
|
1379
1511
|
constructor(options) {
|
|
@@ -1422,6 +1554,15 @@ class MedplumClient extends EventTarget {
|
|
|
1422
1554
|
}
|
|
1423
1555
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setupStorageListener).call(this);
|
|
1424
1556
|
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Returns the current base URL for all API requests.
|
|
1559
|
+
* By default, this is set to `https://api.medplum.com/`.
|
|
1560
|
+
* This can be overridden by setting the `baseUrl` option when creating the client.
|
|
1561
|
+
* @returns The current base URL for all API requests.
|
|
1562
|
+
*/
|
|
1563
|
+
getBaseUrl() {
|
|
1564
|
+
return __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f");
|
|
1565
|
+
}
|
|
1425
1566
|
/**
|
|
1426
1567
|
* Clears all auth state including local storage and session storage.
|
|
1427
1568
|
*/
|
|
@@ -1434,6 +1575,26 @@ class MedplumClient extends EventTarget {
|
|
|
1434
1575
|
__classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
|
|
1435
1576
|
this.dispatchEvent({ type: 'change' });
|
|
1436
1577
|
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Invalidates any cached values or cached requests for the given URL.
|
|
1580
|
+
* @param url The URL to invalidate.
|
|
1581
|
+
*/
|
|
1582
|
+
invalidateUrl(url) {
|
|
1583
|
+
url = url.toString();
|
|
1584
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").delete(url);
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Invalidates all cached search results or cached requests for the given resourceType.
|
|
1588
|
+
* @param resourceType The resource type to invalidate.
|
|
1589
|
+
*/
|
|
1590
|
+
invalidateSearches(resourceType) {
|
|
1591
|
+
const url = 'fhir/R4/' + resourceType;
|
|
1592
|
+
for (const key of __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").keys()) {
|
|
1593
|
+
if (key.endsWith(url) || key.includes(url + '?')) {
|
|
1594
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").delete(key);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1437
1598
|
/**
|
|
1438
1599
|
* Makes an HTTP GET request to the specified URL.
|
|
1439
1600
|
*
|
|
@@ -1446,6 +1607,7 @@ class MedplumClient extends EventTarget {
|
|
|
1446
1607
|
* @returns Promise to the response content.
|
|
1447
1608
|
*/
|
|
1448
1609
|
get(url, options = {}) {
|
|
1610
|
+
url = url.toString();
|
|
1449
1611
|
if (!(options === null || options === void 0 ? void 0 : options.cache)) {
|
|
1450
1612
|
const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(url);
|
|
1451
1613
|
if (cached) {
|
|
@@ -1470,13 +1632,14 @@ class MedplumClient extends EventTarget {
|
|
|
1470
1632
|
* @returns Promise to the response content.
|
|
1471
1633
|
*/
|
|
1472
1634
|
post(url, body, contentType, options = {}) {
|
|
1635
|
+
url = url.toString();
|
|
1473
1636
|
if (body) {
|
|
1474
1637
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, body);
|
|
1475
1638
|
}
|
|
1476
1639
|
if (contentType) {
|
|
1477
1640
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, contentType);
|
|
1478
1641
|
}
|
|
1479
|
-
|
|
1642
|
+
this.invalidateUrl(url);
|
|
1480
1643
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'POST', url, options);
|
|
1481
1644
|
}
|
|
1482
1645
|
/**
|
|
@@ -1493,13 +1656,14 @@ class MedplumClient extends EventTarget {
|
|
|
1493
1656
|
* @returns Promise to the response content.
|
|
1494
1657
|
*/
|
|
1495
1658
|
put(url, body, contentType, options = {}) {
|
|
1659
|
+
url = url.toString();
|
|
1496
1660
|
if (body) {
|
|
1497
1661
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, body);
|
|
1498
1662
|
}
|
|
1499
1663
|
if (contentType) {
|
|
1500
1664
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, contentType);
|
|
1501
1665
|
}
|
|
1502
|
-
|
|
1666
|
+
this.invalidateUrl(url);
|
|
1503
1667
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PUT', url, options);
|
|
1504
1668
|
}
|
|
1505
1669
|
/**
|
|
@@ -1515,9 +1679,10 @@ class MedplumClient extends EventTarget {
|
|
|
1515
1679
|
* @returns Promise to the response content.
|
|
1516
1680
|
*/
|
|
1517
1681
|
patch(url, operations, options = {}) {
|
|
1682
|
+
url = url.toString();
|
|
1518
1683
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestBody).call(this, options, operations);
|
|
1519
1684
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setRequestContentType).call(this, options, PATCH_CONTENT_TYPE);
|
|
1520
|
-
|
|
1685
|
+
this.invalidateUrl(url);
|
|
1521
1686
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PATCH', url, options);
|
|
1522
1687
|
}
|
|
1523
1688
|
/**
|
|
@@ -1532,7 +1697,8 @@ class MedplumClient extends EventTarget {
|
|
|
1532
1697
|
* @returns Promise to the response content.
|
|
1533
1698
|
*/
|
|
1534
1699
|
delete(url, options = {}) {
|
|
1535
|
-
|
|
1700
|
+
url = url.toString();
|
|
1701
|
+
this.invalidateUrl(url);
|
|
1536
1702
|
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'DELETE', url, options);
|
|
1537
1703
|
}
|
|
1538
1704
|
/**
|
|
@@ -1548,23 +1714,13 @@ class MedplumClient extends EventTarget {
|
|
|
1548
1714
|
}
|
|
1549
1715
|
/**
|
|
1550
1716
|
* Initiates a user login flow.
|
|
1551
|
-
* @param
|
|
1552
|
-
* @param password The password of the user.
|
|
1553
|
-
* @param remember Optional flag to remember the user.
|
|
1717
|
+
* @param loginRequest Login request including email and password.
|
|
1554
1718
|
* @returns Promise to the authentication response.
|
|
1555
1719
|
*/
|
|
1556
|
-
startLogin(
|
|
1720
|
+
startLogin(loginRequest) {
|
|
1557
1721
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1558
1722
|
yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
|
|
1559
|
-
return this.post('auth/login', {
|
|
1560
|
-
clientId: __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
|
|
1561
|
-
scope: DEFAULT_SCOPE,
|
|
1562
|
-
codeChallengeMethod: 'S256',
|
|
1563
|
-
codeChallenge: __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'),
|
|
1564
|
-
email,
|
|
1565
|
-
password,
|
|
1566
|
-
remember: !!remember,
|
|
1567
|
-
});
|
|
1723
|
+
return this.post('auth/login', Object.assign(Object.assign({}, loginRequest), { clientId: __classPrivateFieldGet(this, _MedplumClient_clientId, "f"), scope: DEFAULT_SCOPE, codeChallengeMethod: 'S256', codeChallenge: __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge') }));
|
|
1568
1724
|
});
|
|
1569
1725
|
}
|
|
1570
1726
|
/**
|
|
@@ -1618,9 +1774,20 @@ class MedplumClient extends EventTarget {
|
|
|
1618
1774
|
* @returns The well-formed FHIR URL.
|
|
1619
1775
|
*/
|
|
1620
1776
|
fhirUrl(...path) {
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1777
|
+
return new URL(__classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'fhir/R4/' + path.join('/'));
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Builds a FHIR search URL from a search query or structured query object.
|
|
1781
|
+
* @param query The FHIR search query or structured query object.
|
|
1782
|
+
* @returns The well-formed FHIR URL.
|
|
1783
|
+
*/
|
|
1784
|
+
fhirSearchUrl(query) {
|
|
1785
|
+
if (typeof query === 'string') {
|
|
1786
|
+
return this.fhirUrl(query);
|
|
1787
|
+
}
|
|
1788
|
+
const url = this.fhirUrl(query.resourceType);
|
|
1789
|
+
url.search = formatSearchQuery(query);
|
|
1790
|
+
return url;
|
|
1624
1791
|
}
|
|
1625
1792
|
/**
|
|
1626
1793
|
* Sends a FHIR search request.
|
|
@@ -1677,7 +1844,7 @@ class MedplumClient extends EventTarget {
|
|
|
1677
1844
|
* @returns Promise to the search result bundle.
|
|
1678
1845
|
*/
|
|
1679
1846
|
search(query, options = {}) {
|
|
1680
|
-
return this.get(
|
|
1847
|
+
return this.get(this.fhirSearchUrl(query), options);
|
|
1681
1848
|
}
|
|
1682
1849
|
/**
|
|
1683
1850
|
* Sends a FHIR search request for a single resource.
|
|
@@ -1699,13 +1866,18 @@ class MedplumClient extends EventTarget {
|
|
|
1699
1866
|
* @returns Promise to the search result bundle.
|
|
1700
1867
|
*/
|
|
1701
1868
|
searchOne(query, options = {}) {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
const
|
|
1707
|
-
|
|
1708
|
-
|
|
1869
|
+
const search = typeof query === 'string' ? parseSearchDefinition(query) : query;
|
|
1870
|
+
search.count = 1;
|
|
1871
|
+
const cacheKey = this.fhirSearchUrl(query).toString() + '-searchOne';
|
|
1872
|
+
if (!(options === null || options === void 0 ? void 0 : options.cache)) {
|
|
1873
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(cacheKey);
|
|
1874
|
+
if (cached) {
|
|
1875
|
+
return cached;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
const promise = new ReadablePromise(this.search(search, 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; }));
|
|
1879
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(cacheKey, promise);
|
|
1880
|
+
return promise;
|
|
1709
1881
|
}
|
|
1710
1882
|
/**
|
|
1711
1883
|
* Sends a FHIR search request for an array of resources.
|
|
@@ -1727,11 +1899,16 @@ class MedplumClient extends EventTarget {
|
|
|
1727
1899
|
* @returns Promise to the search result bundle.
|
|
1728
1900
|
*/
|
|
1729
1901
|
searchResources(query, options = {}) {
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
const
|
|
1733
|
-
|
|
1734
|
-
|
|
1902
|
+
const cacheKey = this.fhirSearchUrl(query).toString() + '-searchResources';
|
|
1903
|
+
if (!(options === null || options === void 0 ? void 0 : options.cache)) {
|
|
1904
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(cacheKey);
|
|
1905
|
+
if (cached) {
|
|
1906
|
+
return cached;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
const promise = new ReadablePromise(this.search(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 : []; }));
|
|
1910
|
+
__classPrivateFieldGet(this, _MedplumClient_requestCache, "f").set(cacheKey, promise);
|
|
1911
|
+
return promise;
|
|
1735
1912
|
}
|
|
1736
1913
|
/**
|
|
1737
1914
|
* Searches a ValueSet resource using the "expand" operation.
|
|
@@ -1741,9 +1918,10 @@ class MedplumClient extends EventTarget {
|
|
|
1741
1918
|
* @returns Promise to expanded ValueSet.
|
|
1742
1919
|
*/
|
|
1743
1920
|
searchValueSet(system, filter, options = {}) {
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1921
|
+
const url = this.fhirUrl('ValueSet', '$expand');
|
|
1922
|
+
url.searchParams.set('url', system);
|
|
1923
|
+
url.searchParams.set('filter', filter);
|
|
1924
|
+
return this.get(url.toString(), options);
|
|
1747
1925
|
}
|
|
1748
1926
|
/**
|
|
1749
1927
|
* Returns a cached resource if it is available.
|
|
@@ -1752,7 +1930,7 @@ class MedplumClient extends EventTarget {
|
|
|
1752
1930
|
* @returns The resource if it is available in the cache; undefined otherwise.
|
|
1753
1931
|
*/
|
|
1754
1932
|
getCached(resourceType, id) {
|
|
1755
|
-
const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id));
|
|
1933
|
+
const cached = __classPrivateFieldGet(this, _MedplumClient_requestCache, "f").get(this.fhirUrl(resourceType, id).toString());
|
|
1756
1934
|
return cached && !cached.isPending() ? cached.read() : undefined;
|
|
1757
1935
|
}
|
|
1758
1936
|
/**
|
|
@@ -1785,27 +1963,6 @@ class MedplumClient extends EventTarget {
|
|
|
1785
1963
|
readResource(resourceType, id) {
|
|
1786
1964
|
return this.get(this.fhirUrl(resourceType, id));
|
|
1787
1965
|
}
|
|
1788
|
-
/**
|
|
1789
|
-
* Reads a resource by resource type and ID using the in-memory resource cache.
|
|
1790
|
-
*
|
|
1791
|
-
* If the resource is not available in the cache, it will be read from the server.
|
|
1792
|
-
*
|
|
1793
|
-
* Example:
|
|
1794
|
-
*
|
|
1795
|
-
* ```typescript
|
|
1796
|
-
* const patient = await medplum.readCached('Patient', '123');
|
|
1797
|
-
* console.log(patient);
|
|
1798
|
-
* ```
|
|
1799
|
-
*
|
|
1800
|
-
* See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
|
|
1801
|
-
*
|
|
1802
|
-
* @param resourceType The FHIR resource type.
|
|
1803
|
-
* @param id The resource ID.
|
|
1804
|
-
* @returns The resource if available; undefined otherwise.
|
|
1805
|
-
*/
|
|
1806
|
-
readCached(resourceType, id) {
|
|
1807
|
-
return this.get(this.fhirUrl(resourceType, id));
|
|
1808
|
-
}
|
|
1809
1966
|
/**
|
|
1810
1967
|
* Reads a resource by `Reference`.
|
|
1811
1968
|
*
|
|
@@ -1827,39 +1984,11 @@ class MedplumClient extends EventTarget {
|
|
|
1827
1984
|
readReference(reference) {
|
|
1828
1985
|
const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
|
|
1829
1986
|
if (!refString) {
|
|
1830
|
-
return new ReadablePromise(Promise.reject('Missing reference'));
|
|
1987
|
+
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
1831
1988
|
}
|
|
1832
1989
|
const [resourceType, id] = refString.split('/');
|
|
1833
1990
|
return this.readResource(resourceType, id);
|
|
1834
1991
|
}
|
|
1835
|
-
/**
|
|
1836
|
-
* Reads a resource by `Reference` using the in-memory resource cache.
|
|
1837
|
-
*
|
|
1838
|
-
* This is a convenience method for `readResource()` that accepts a `Reference` object.
|
|
1839
|
-
*
|
|
1840
|
-
* If the resource is not available in the cache, it will be read from the server.
|
|
1841
|
-
*
|
|
1842
|
-
* Example:
|
|
1843
|
-
*
|
|
1844
|
-
* ```typescript
|
|
1845
|
-
* const serviceRequest = await medplum.readResource('ServiceRequest', '123');
|
|
1846
|
-
* const patient = await medplum.readCachedReference(serviceRequest.subject);
|
|
1847
|
-
* console.log(patient);
|
|
1848
|
-
* ```
|
|
1849
|
-
*
|
|
1850
|
-
* See the FHIR "read" operation for full details: https://www.hl7.org/fhir/http.html#read
|
|
1851
|
-
*
|
|
1852
|
-
* @param reference The FHIR reference object.
|
|
1853
|
-
* @returns The resource if available; undefined otherwise.
|
|
1854
|
-
*/
|
|
1855
|
-
readCachedReference(reference) {
|
|
1856
|
-
const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
|
|
1857
|
-
if (!refString) {
|
|
1858
|
-
return new ReadablePromise(Promise.reject('Missing reference'));
|
|
1859
|
-
}
|
|
1860
|
-
const [resourceType, id] = refString.split('/');
|
|
1861
|
-
return this.readCached(resourceType, id);
|
|
1862
|
-
}
|
|
1863
1992
|
/**
|
|
1864
1993
|
* Returns a cached schema for a resource type.
|
|
1865
1994
|
* If the schema is not cached, returns undefined.
|
|
@@ -1882,7 +2011,7 @@ class MedplumClient extends EventTarget {
|
|
|
1882
2011
|
return Promise.resolve(__classPrivateFieldGet(this, _MedplumClient_schema, "f"));
|
|
1883
2012
|
}
|
|
1884
2013
|
const query = `{
|
|
1885
|
-
StructureDefinitionList(name: "${
|
|
2014
|
+
StructureDefinitionList(name: "${resourceType}") {
|
|
1886
2015
|
name,
|
|
1887
2016
|
description,
|
|
1888
2017
|
snapshot {
|
|
@@ -1902,7 +2031,7 @@ class MedplumClient extends EventTarget {
|
|
|
1902
2031
|
}
|
|
1903
2032
|
}
|
|
1904
2033
|
}
|
|
1905
|
-
SearchParameterList(base: "${
|
|
2034
|
+
SearchParameterList(base: "${resourceType}", _count: 100) {
|
|
1906
2035
|
base,
|
|
1907
2036
|
code,
|
|
1908
2037
|
type,
|
|
@@ -1936,7 +2065,7 @@ class MedplumClient extends EventTarget {
|
|
|
1936
2065
|
*
|
|
1937
2066
|
* @param resourceType The FHIR resource type.
|
|
1938
2067
|
* @param id The resource ID.
|
|
1939
|
-
* @returns
|
|
2068
|
+
* @returns Promise to the resource history.
|
|
1940
2069
|
*/
|
|
1941
2070
|
readHistory(resourceType, id) {
|
|
1942
2071
|
return this.get(this.fhirUrl(resourceType, id, '_history'));
|
|
@@ -1988,8 +2117,9 @@ class MedplumClient extends EventTarget {
|
|
|
1988
2117
|
*/
|
|
1989
2118
|
createResource(resource) {
|
|
1990
2119
|
if (!resource.resourceType) {
|
|
1991
|
-
|
|
2120
|
+
throw new Error('Missing resourceType');
|
|
1992
2121
|
}
|
|
2122
|
+
this.invalidateSearches(resource.resourceType);
|
|
1993
2123
|
return this.post(this.fhirUrl(resource.resourceType), resource);
|
|
1994
2124
|
}
|
|
1995
2125
|
/**
|
|
@@ -2060,9 +2190,9 @@ class MedplumClient extends EventTarget {
|
|
|
2060
2190
|
* @returns The result of the create operation.
|
|
2061
2191
|
*/
|
|
2062
2192
|
createBinary(data, filename, contentType) {
|
|
2063
|
-
|
|
2193
|
+
const url = this.fhirUrl('Binary');
|
|
2064
2194
|
if (filename) {
|
|
2065
|
-
url
|
|
2195
|
+
url.searchParams.set('_filename', filename);
|
|
2066
2196
|
}
|
|
2067
2197
|
return this.post(url, data, contentType);
|
|
2068
2198
|
}
|
|
@@ -2084,15 +2214,48 @@ class MedplumClient extends EventTarget {
|
|
|
2084
2214
|
*
|
|
2085
2215
|
* See the pdfmake document definition for full details: https://pdfmake.github.io/docs/0.1/document-definition-object/
|
|
2086
2216
|
*
|
|
2087
|
-
* @param docDefinition The
|
|
2217
|
+
* @param docDefinition The PDF document definition.
|
|
2088
2218
|
* @returns The result of the create operation.
|
|
2089
2219
|
*/
|
|
2090
|
-
createPdf(docDefinition, filename) {
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2220
|
+
createPdf(docDefinition, filename, tableLayouts, fonts) {
|
|
2221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2222
|
+
const blob = yield generatePdf(docDefinition, tableLayouts, fonts);
|
|
2223
|
+
return this.createBinary(blob, filename, 'application/pdf');
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* Creates a FHIR `Communication` resource with the provided data content.
|
|
2228
|
+
*
|
|
2229
|
+
* This is a convenience method to handle commmon cases where a `Communication` resource is created with a `payload`.
|
|
2230
|
+
*
|
|
2231
|
+
* @param resource The FHIR resource to comment on.
|
|
2232
|
+
* @param text The text of the comment.
|
|
2233
|
+
* @returns The result of the create operation.
|
|
2234
|
+
*/
|
|
2235
|
+
createComment(resource, text) {
|
|
2236
|
+
const profile = this.getProfile();
|
|
2237
|
+
let encounter = undefined;
|
|
2238
|
+
let subject = undefined;
|
|
2239
|
+
if (resource.resourceType === 'Encounter') {
|
|
2240
|
+
encounter = createReference(resource);
|
|
2241
|
+
subject = resource.subject;
|
|
2242
|
+
}
|
|
2243
|
+
if (resource.resourceType === 'ServiceRequest') {
|
|
2244
|
+
encounter = resource.encounter;
|
|
2245
|
+
subject = resource.subject;
|
|
2094
2246
|
}
|
|
2095
|
-
|
|
2247
|
+
if (resource.resourceType === 'Patient') {
|
|
2248
|
+
subject = createReference(resource);
|
|
2249
|
+
}
|
|
2250
|
+
return this.createResource({
|
|
2251
|
+
resourceType: 'Communication',
|
|
2252
|
+
basedOn: [createReference(resource)],
|
|
2253
|
+
encounter,
|
|
2254
|
+
subject,
|
|
2255
|
+
sender: profile ? createReference(profile) : undefined,
|
|
2256
|
+
sent: new Date().toISOString(),
|
|
2257
|
+
payload: [{ contentString: text }],
|
|
2258
|
+
});
|
|
2096
2259
|
}
|
|
2097
2260
|
/**
|
|
2098
2261
|
* Updates a FHIR resource.
|
|
@@ -2120,11 +2283,12 @@ class MedplumClient extends EventTarget {
|
|
|
2120
2283
|
*/
|
|
2121
2284
|
updateResource(resource) {
|
|
2122
2285
|
if (!resource.resourceType) {
|
|
2123
|
-
|
|
2286
|
+
throw new Error('Missing resourceType');
|
|
2124
2287
|
}
|
|
2125
2288
|
if (!resource.id) {
|
|
2126
|
-
|
|
2289
|
+
throw new Error('Missing id');
|
|
2127
2290
|
}
|
|
2291
|
+
this.invalidateSearches(resource.resourceType);
|
|
2128
2292
|
return this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
|
|
2129
2293
|
}
|
|
2130
2294
|
/**
|
|
@@ -2151,6 +2315,7 @@ class MedplumClient extends EventTarget {
|
|
|
2151
2315
|
* @returns The result of the patch operations.
|
|
2152
2316
|
*/
|
|
2153
2317
|
patchResource(resourceType, id, operations) {
|
|
2318
|
+
this.invalidateSearches(resourceType);
|
|
2154
2319
|
return this.patch(this.fhirUrl(resourceType, id), operations);
|
|
2155
2320
|
}
|
|
2156
2321
|
/**
|
|
@@ -2169,8 +2334,49 @@ class MedplumClient extends EventTarget {
|
|
|
2169
2334
|
* @returns The result of the delete operation.
|
|
2170
2335
|
*/
|
|
2171
2336
|
deleteResource(resourceType, id) {
|
|
2337
|
+
this.invalidateSearches(resourceType);
|
|
2172
2338
|
return this.delete(this.fhirUrl(resourceType, id));
|
|
2173
2339
|
}
|
|
2340
|
+
/**
|
|
2341
|
+
* Sends an email using the Medplum Email API.
|
|
2342
|
+
*
|
|
2343
|
+
* Builds the email using nodemailer MailComposer.
|
|
2344
|
+
*
|
|
2345
|
+
* Examples:
|
|
2346
|
+
*
|
|
2347
|
+
* Send a simple text email:
|
|
2348
|
+
*
|
|
2349
|
+
* ```typescript
|
|
2350
|
+
* await medplum.sendEmail({
|
|
2351
|
+
* to: 'alice@example.com',
|
|
2352
|
+
* cc: 'bob@example.com',
|
|
2353
|
+
* subject: 'Hello',
|
|
2354
|
+
* text: 'Hello Alice',
|
|
2355
|
+
* });
|
|
2356
|
+
* ```
|
|
2357
|
+
*
|
|
2358
|
+
* Send an email with a `Binary` attachment:
|
|
2359
|
+
*
|
|
2360
|
+
* ```typescript
|
|
2361
|
+
* await medplum.sendEmail({
|
|
2362
|
+
* to: 'alice@example.com',
|
|
2363
|
+
* subject: 'Email with attachment',
|
|
2364
|
+
* text: 'See the attached report',
|
|
2365
|
+
* attachments: [{
|
|
2366
|
+
* filename: 'report.pdf',
|
|
2367
|
+
* path: "Binary/" + binary.id
|
|
2368
|
+
* }]
|
|
2369
|
+
* });
|
|
2370
|
+
* ```
|
|
2371
|
+
*
|
|
2372
|
+
* See options here: https://nodemailer.com/extras/mailcomposer/
|
|
2373
|
+
*
|
|
2374
|
+
* @param options The MailComposer options.
|
|
2375
|
+
* @returns Promise to the operation outcome.
|
|
2376
|
+
*/
|
|
2377
|
+
sendEmail(email) {
|
|
2378
|
+
return this.post('email/v1/send', email, 'application/json');
|
|
2379
|
+
}
|
|
2174
2380
|
graphql(query, options) {
|
|
2175
2381
|
return this.post(this.fhirUrl('$graphql'), { query }, JSON_CONTENT_TYPE, options);
|
|
2176
2382
|
}
|
|
@@ -2190,6 +2396,9 @@ class MedplumClient extends EventTarget {
|
|
|
2190
2396
|
yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
|
|
2191
2397
|
});
|
|
2192
2398
|
}
|
|
2399
|
+
getAccessToken() {
|
|
2400
|
+
return __classPrivateFieldGet(this, _MedplumClient_accessToken, "f");
|
|
2401
|
+
}
|
|
2193
2402
|
setAccessToken(accessToken) {
|
|
2194
2403
|
__classPrivateFieldSet(this, _MedplumClient_accessToken, accessToken, "f");
|
|
2195
2404
|
__classPrivateFieldSet(this, _MedplumClient_refreshToken, undefined, "f");
|
|
@@ -2228,7 +2437,7 @@ class MedplumClient extends EventTarget {
|
|
|
2228
2437
|
yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
2229
2438
|
}
|
|
2230
2439
|
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addFetchOptionsDefaults).call(this, options);
|
|
2231
|
-
const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
|
|
2440
|
+
const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url.toString(), options);
|
|
2232
2441
|
return response.blob();
|
|
2233
2442
|
});
|
|
2234
2443
|
}
|
|
@@ -2241,29 +2450,35 @@ class MedplumClient extends EventTarget {
|
|
|
2241
2450
|
const pkceState = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState');
|
|
2242
2451
|
if (!pkceState) {
|
|
2243
2452
|
this.clear();
|
|
2244
|
-
|
|
2453
|
+
throw new Error('Invalid PCKE state');
|
|
2245
2454
|
}
|
|
2246
2455
|
const codeVerifier = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeVerifier');
|
|
2247
2456
|
if (!codeVerifier) {
|
|
2248
2457
|
this.clear();
|
|
2249
|
-
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2458
|
+
throw new Error('Invalid PCKE code verifier');
|
|
2459
|
+
}
|
|
2460
|
+
const formBody = new URLSearchParams();
|
|
2461
|
+
formBody.set('grant_type', 'authorization_code');
|
|
2462
|
+
formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
2463
|
+
formBody.set('code_verifier', codeVerifier);
|
|
2464
|
+
formBody.set('code', code);
|
|
2465
|
+
formBody.set('redirect_uri', getBaseUrl());
|
|
2466
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Starts a new OAuth2 client credentials flow.
|
|
2470
|
+
* See: https://datatracker.ietf.org/doc/html/rfc6749#section-4.4
|
|
2471
|
+
* @param clientId The client ID.
|
|
2472
|
+
* @param clientSecret The client secret.
|
|
2473
|
+
* @returns Promise that resolves to the client profile.
|
|
2474
|
+
*/
|
|
2475
|
+
startClientLogin(clientId, clientSecret) {
|
|
2261
2476
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2477
|
+
const formBody = new URLSearchParams();
|
|
2478
|
+
formBody.set('grant_type', 'client_credentials');
|
|
2479
|
+
formBody.set('client_id', clientId);
|
|
2480
|
+
formBody.set('client_secret', clientSecret);
|
|
2481
|
+
return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody);
|
|
2267
2482
|
});
|
|
2268
2483
|
}
|
|
2269
2484
|
}
|
|
@@ -2335,11 +2550,14 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
2335
2550
|
const headers = options.headers;
|
|
2336
2551
|
headers['Content-Type'] = contentType;
|
|
2337
2552
|
}, _MedplumClient_setRequestBody = function _MedplumClient_setRequestBody(options, data) {
|
|
2338
|
-
if (typeof data === 'string' ||
|
|
2553
|
+
if (typeof data === 'string' ||
|
|
2554
|
+
(typeof Blob !== 'undefined' && data instanceof Blob) ||
|
|
2555
|
+
(typeof Buffer !== 'undefined' && data instanceof Buffer) ||
|
|
2556
|
+
(typeof File !== 'undefined' && data instanceof File)) {
|
|
2339
2557
|
options.body = data;
|
|
2340
2558
|
}
|
|
2341
2559
|
else if (data) {
|
|
2342
|
-
options.body = stringify(data);
|
|
2560
|
+
options.body = JSON.stringify(data);
|
|
2343
2561
|
}
|
|
2344
2562
|
}, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, options) {
|
|
2345
2563
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2364,25 +2582,16 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
2364
2582
|
__classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeChallenge', codeChallenge);
|
|
2365
2583
|
});
|
|
2366
2584
|
}, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_clientId, "f")) +
|
|
2378
|
-
'&redirect_uri=' +
|
|
2379
|
-
encodeURIComponent(getBaseUrl()) +
|
|
2380
|
-
'&scope=' +
|
|
2381
|
-
encodeURIComponent(DEFAULT_SCOPE) +
|
|
2382
|
-
'&code_challenge_method=S256' +
|
|
2383
|
-
'&code_challenge=' +
|
|
2384
|
-
encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge')));
|
|
2385
|
-
});
|
|
2585
|
+
__classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
|
|
2586
|
+
const url = new URL(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f"));
|
|
2587
|
+
url.searchParams.set('response_type', 'code');
|
|
2588
|
+
url.searchParams.set('state', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState'));
|
|
2589
|
+
url.searchParams.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
2590
|
+
url.searchParams.set('redirect_uri', getBaseUrl());
|
|
2591
|
+
url.searchParams.set('scope', DEFAULT_SCOPE);
|
|
2592
|
+
url.searchParams.set('code_challenge_method', 'S256');
|
|
2593
|
+
url.searchParams.set('code_challenge', __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'));
|
|
2594
|
+
window.location.assign(url.toString());
|
|
2386
2595
|
}, _MedplumClient_refresh = function _MedplumClient_refresh() {
|
|
2387
2596
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2388
2597
|
if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
|
|
@@ -2390,20 +2599,17 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
2390
2599
|
}
|
|
2391
2600
|
if (!__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
|
|
2392
2601
|
this.clear();
|
|
2393
|
-
|
|
2602
|
+
throw new Error('Invalid refresh token');
|
|
2394
2603
|
}
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2604
|
+
const formBody = new URLSearchParams();
|
|
2605
|
+
formBody.set('grant_type', 'refresh_token');
|
|
2606
|
+
formBody.set('client_id', __classPrivateFieldGet(this, _MedplumClient_clientId, "f"));
|
|
2607
|
+
formBody.set('refresh_token', __classPrivateFieldGet(this, _MedplumClient_refreshToken, "f"));
|
|
2608
|
+
__classPrivateFieldSet(this, _MedplumClient_refreshPromise, __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, formBody), "f");
|
|
2400
2609
|
yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
|
|
2401
2610
|
});
|
|
2402
2611
|
}, _MedplumClient_fetchTokens = function _MedplumClient_fetchTokens(formBody) {
|
|
2403
2612
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2404
|
-
if (!__classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f")) {
|
|
2405
|
-
return Promise.reject('Missing token URL');
|
|
2406
|
-
}
|
|
2407
2613
|
return __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
|
|
2408
2614
|
method: 'POST',
|
|
2409
2615
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
@@ -2411,7 +2617,7 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
2411
2617
|
})
|
|
2412
2618
|
.then((response) => {
|
|
2413
2619
|
if (!response.ok) {
|
|
2414
|
-
|
|
2620
|
+
throw new Error('Failed to fetch tokens');
|
|
2415
2621
|
}
|
|
2416
2622
|
return response.json();
|
|
2417
2623
|
})
|
|
@@ -2425,12 +2631,12 @@ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _M
|
|
|
2425
2631
|
const tokenPayload = parseJWTPayload(token);
|
|
2426
2632
|
if (Date.now() >= tokenPayload.exp * 1000) {
|
|
2427
2633
|
this.clear();
|
|
2428
|
-
|
|
2634
|
+
throw new Error('Token expired');
|
|
2429
2635
|
}
|
|
2430
2636
|
// Verify app_client_id
|
|
2431
2637
|
if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
|
|
2432
2638
|
this.clear();
|
|
2433
|
-
|
|
2639
|
+
throw new Error('Token was not issued for this audience');
|
|
2434
2640
|
}
|
|
2435
2641
|
yield this.setActiveLogin({
|
|
2436
2642
|
accessToken: token,
|
|
@@ -2461,101 +2667,2638 @@ function getBaseUrl() {
|
|
|
2461
2667
|
return window.location.protocol + '//' + window.location.host + '/';
|
|
2462
2668
|
}
|
|
2463
2669
|
|
|
2464
|
-
const SEGMENT_SEPARATOR = '\r';
|
|
2465
|
-
const FIELD_SEPARATOR = '|';
|
|
2466
|
-
const COMPONENT_SEPARATOR = '^';
|
|
2467
2670
|
/**
|
|
2468
|
-
*
|
|
2469
|
-
*
|
|
2470
|
-
*
|
|
2671
|
+
* Returns a single element array with a typed boolean value.
|
|
2672
|
+
* @param value The primitive boolean value.
|
|
2673
|
+
* @returns Single element array with a typed boolean value.
|
|
2471
2674
|
*/
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2675
|
+
function booleanToTypedValue(value) {
|
|
2676
|
+
return [{ type: PropertyType.boolean, value }];
|
|
2677
|
+
}
|
|
2678
|
+
/**
|
|
2679
|
+
* Returns a "best guess" TypedValue for a given value.
|
|
2680
|
+
* @param value The unknown value to check.
|
|
2681
|
+
* @returns A "best guess" TypedValue for the given value.
|
|
2682
|
+
*/
|
|
2683
|
+
function toTypedValue(value) {
|
|
2684
|
+
if (Number.isSafeInteger(value)) {
|
|
2685
|
+
return { type: PropertyType.integer, value };
|
|
2475
2686
|
}
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
return this.segments[index];
|
|
2479
|
-
}
|
|
2480
|
-
return this.segments.find((s) => s.name === index);
|
|
2687
|
+
else if (typeof value === 'number') {
|
|
2688
|
+
return { type: PropertyType.decimal, value };
|
|
2481
2689
|
}
|
|
2482
|
-
|
|
2483
|
-
return
|
|
2690
|
+
else if (typeof value === 'boolean') {
|
|
2691
|
+
return { type: PropertyType.boolean, value };
|
|
2484
2692
|
}
|
|
2485
|
-
|
|
2486
|
-
return
|
|
2693
|
+
else if (typeof value === 'string') {
|
|
2694
|
+
return { type: PropertyType.string, value };
|
|
2487
2695
|
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
const now = new Date();
|
|
2491
|
-
const msh = this.get('MSH');
|
|
2492
|
-
const sendingApp = ((_a = msh === null || msh === void 0 ? void 0 : msh.get(2)) === null || _a === void 0 ? void 0 : _a.toString()) || '';
|
|
2493
|
-
const sendingFacility = ((_b = msh === null || msh === void 0 ? void 0 : msh.get(3)) === null || _b === void 0 ? void 0 : _b.toString()) || '';
|
|
2494
|
-
const receivingApp = ((_c = msh === null || msh === void 0 ? void 0 : msh.get(4)) === null || _c === void 0 ? void 0 : _c.toString()) || '';
|
|
2495
|
-
const receivingFacility = ((_d = msh === null || msh === void 0 ? void 0 : msh.get(5)) === null || _d === void 0 ? void 0 : _d.toString()) || '';
|
|
2496
|
-
const controlId = ((_e = msh === null || msh === void 0 ? void 0 : msh.get(9)) === null || _e === void 0 ? void 0 : _e.toString()) || '';
|
|
2497
|
-
const versionId = ((_f = msh === null || msh === void 0 ? void 0 : msh.get(12)) === null || _f === void 0 ? void 0 : _f.toString()) || '2.5.1';
|
|
2498
|
-
return new Hl7Message([
|
|
2499
|
-
new Hl7Segment([
|
|
2500
|
-
'MSH',
|
|
2501
|
-
'^~\\&',
|
|
2502
|
-
receivingApp,
|
|
2503
|
-
receivingFacility,
|
|
2504
|
-
sendingApp,
|
|
2505
|
-
sendingFacility,
|
|
2506
|
-
now.toISOString(),
|
|
2507
|
-
'',
|
|
2508
|
-
'ACK',
|
|
2509
|
-
now.getTime().toString(),
|
|
2510
|
-
'P',
|
|
2511
|
-
versionId,
|
|
2512
|
-
]),
|
|
2513
|
-
new Hl7Segment(['MSA', 'AA', controlId, 'OK']),
|
|
2514
|
-
]);
|
|
2696
|
+
else if (isQuantity(value)) {
|
|
2697
|
+
return { type: PropertyType.Quantity, value };
|
|
2515
2698
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
const err = new Error('Invalid HL7 message');
|
|
2519
|
-
err.type = 'entity.parse.failed';
|
|
2520
|
-
throw err;
|
|
2521
|
-
}
|
|
2522
|
-
return new Hl7Message(text.split(/[\r\n]+/).map((line) => Hl7Segment.parse(line)));
|
|
2699
|
+
else {
|
|
2700
|
+
return { type: PropertyType.BackboneElement, value };
|
|
2523
2701
|
}
|
|
2524
2702
|
}
|
|
2525
2703
|
/**
|
|
2526
|
-
*
|
|
2527
|
-
*
|
|
2528
|
-
*
|
|
2529
|
-
*
|
|
2704
|
+
* Converts unknown object into a JavaScript boolean.
|
|
2705
|
+
* Note that this is different than the FHIRPath "toBoolean",
|
|
2706
|
+
* which has particular semantics around arrays, empty arrays, and type conversions.
|
|
2707
|
+
* @param obj Any value or array of values.
|
|
2708
|
+
* @returns The converted boolean value according to FHIRPath rules.
|
|
2530
2709
|
*/
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2710
|
+
function toJsBoolean(obj) {
|
|
2711
|
+
return obj.length === 0 ? false : !!obj[0].value;
|
|
2712
|
+
}
|
|
2713
|
+
/**
|
|
2714
|
+
* Removes duplicates in array using FHIRPath equality rules.
|
|
2715
|
+
* @param arr The input array.
|
|
2716
|
+
* @returns The result array with duplicates removed.
|
|
2717
|
+
*/
|
|
2718
|
+
function removeDuplicates(arr) {
|
|
2719
|
+
const result = [];
|
|
2720
|
+
for (const i of arr) {
|
|
2721
|
+
let found = false;
|
|
2722
|
+
for (const j of result) {
|
|
2723
|
+
if (toJsBoolean(fhirPathEquals(i, j))) {
|
|
2724
|
+
found = true;
|
|
2725
|
+
break;
|
|
2726
|
+
}
|
|
2535
2727
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2728
|
+
if (!found) {
|
|
2729
|
+
result.push(i);
|
|
2538
2730
|
}
|
|
2539
|
-
this.name = this.fields[0].components[0];
|
|
2540
2731
|
}
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2732
|
+
return result;
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* Returns a negated FHIRPath boolean expression.
|
|
2736
|
+
* @param input The input array.
|
|
2737
|
+
* @returns The negated type value array.
|
|
2738
|
+
*/
|
|
2739
|
+
function fhirPathNot(input) {
|
|
2740
|
+
return booleanToTypedValue(!toJsBoolean(input));
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* Determines if two arrays are equal according to FHIRPath equality rules.
|
|
2744
|
+
* @param x The first array.
|
|
2745
|
+
* @param y The second array.
|
|
2746
|
+
* @returns FHIRPath true if the arrays are equal.
|
|
2747
|
+
*/
|
|
2748
|
+
function fhirPathArrayEquals(x, y) {
|
|
2749
|
+
if (x.length === 0 || y.length === 0) {
|
|
2750
|
+
return [];
|
|
2546
2751
|
}
|
|
2547
|
-
|
|
2548
|
-
return
|
|
2752
|
+
if (x.length !== y.length) {
|
|
2753
|
+
return booleanToTypedValue(false);
|
|
2549
2754
|
}
|
|
2755
|
+
return booleanToTypedValue(x.every((val, index) => toJsBoolean(fhirPathEquals(val, y[index]))));
|
|
2550
2756
|
}
|
|
2551
2757
|
/**
|
|
2552
|
-
*
|
|
2553
|
-
*
|
|
2554
|
-
*
|
|
2758
|
+
* Determines if two values are equal according to FHIRPath equality rules.
|
|
2759
|
+
* @param x The first value.
|
|
2760
|
+
* @param y The second value.
|
|
2761
|
+
* @returns True if equal.
|
|
2555
2762
|
*/
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2763
|
+
function fhirPathEquals(x, y) {
|
|
2764
|
+
const xValue = x.value;
|
|
2765
|
+
const yValue = y.value;
|
|
2766
|
+
if (typeof xValue === 'number' && typeof yValue === 'number') {
|
|
2767
|
+
return booleanToTypedValue(Math.abs(xValue - yValue) < 1e-8);
|
|
2768
|
+
}
|
|
2769
|
+
if (isQuantity(xValue) && isQuantity(yValue)) {
|
|
2770
|
+
return booleanToTypedValue(isQuantityEquivalent(xValue, yValue));
|
|
2771
|
+
}
|
|
2772
|
+
if (typeof xValue === 'object' && typeof yValue === 'object') {
|
|
2773
|
+
return booleanToTypedValue(deepEquals(x, y));
|
|
2774
|
+
}
|
|
2775
|
+
return booleanToTypedValue(xValue === yValue);
|
|
2776
|
+
}
|
|
2777
|
+
/**
|
|
2778
|
+
* Determines if two arrays are equivalent according to FHIRPath equality rules.
|
|
2779
|
+
* @param x The first array.
|
|
2780
|
+
* @param y The second array.
|
|
2781
|
+
* @returns FHIRPath true if the arrays are equivalent.
|
|
2782
|
+
*/
|
|
2783
|
+
function fhirPathArrayEquivalent(x, y) {
|
|
2784
|
+
if (x.length === 0 && y.length === 0) {
|
|
2785
|
+
return booleanToTypedValue(true);
|
|
2786
|
+
}
|
|
2787
|
+
if (x.length !== y.length) {
|
|
2788
|
+
return booleanToTypedValue(false);
|
|
2789
|
+
}
|
|
2790
|
+
x.sort(fhirPathEquivalentCompare);
|
|
2791
|
+
y.sort(fhirPathEquivalentCompare);
|
|
2792
|
+
return booleanToTypedValue(x.every((val, index) => toJsBoolean(fhirPathEquivalent(val, y[index]))));
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
* Determines if two values are equivalent according to FHIRPath equality rules.
|
|
2796
|
+
* @param x The first value.
|
|
2797
|
+
* @param y The second value.
|
|
2798
|
+
* @returns True if equivalent.
|
|
2799
|
+
*/
|
|
2800
|
+
function fhirPathEquivalent(x, y) {
|
|
2801
|
+
const xValue = x.value;
|
|
2802
|
+
const yValue = y.value;
|
|
2803
|
+
if (typeof xValue === 'number' && typeof yValue === 'number') {
|
|
2804
|
+
// Use more generous threshold than equality
|
|
2805
|
+
// Decimal: values must be equal, comparison is done on values rounded to the precision of the least precise operand.
|
|
2806
|
+
// Trailing zeroes after the decimal are ignored in determining precision.
|
|
2807
|
+
return booleanToTypedValue(Math.abs(xValue - yValue) < 0.01);
|
|
2808
|
+
}
|
|
2809
|
+
if (isQuantity(xValue) && isQuantity(yValue)) {
|
|
2810
|
+
return booleanToTypedValue(isQuantityEquivalent(xValue, yValue));
|
|
2811
|
+
}
|
|
2812
|
+
if (typeof xValue === 'object' && typeof yValue === 'object') {
|
|
2813
|
+
return booleanToTypedValue(deepEquals(xValue, yValue));
|
|
2814
|
+
}
|
|
2815
|
+
if (typeof xValue === 'string' && typeof yValue === 'string') {
|
|
2816
|
+
// String: the strings must be the same, ignoring case and locale, and normalizing whitespace
|
|
2817
|
+
// (see String Equivalence for more details).
|
|
2818
|
+
return booleanToTypedValue(xValue.toLowerCase() === yValue.toLowerCase());
|
|
2819
|
+
}
|
|
2820
|
+
return booleanToTypedValue(xValue === yValue);
|
|
2821
|
+
}
|
|
2822
|
+
/**
|
|
2823
|
+
* Returns the sort order of two values for FHIRPath array equivalence.
|
|
2824
|
+
* @param x The first value.
|
|
2825
|
+
* @param y The second value.
|
|
2826
|
+
* @returns The sort order of the values.
|
|
2827
|
+
*/
|
|
2828
|
+
function fhirPathEquivalentCompare(x, y) {
|
|
2829
|
+
const xValue = x.value;
|
|
2830
|
+
const yValue = y.value;
|
|
2831
|
+
if (typeof xValue === 'number' && typeof yValue === 'number') {
|
|
2832
|
+
return xValue - yValue;
|
|
2833
|
+
}
|
|
2834
|
+
if (typeof xValue === 'string' && typeof yValue === 'string') {
|
|
2835
|
+
return xValue.localeCompare(yValue);
|
|
2836
|
+
}
|
|
2837
|
+
return 0;
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Determines if the typed value is the desired type.
|
|
2841
|
+
* @param typedValue The typed value to check.
|
|
2842
|
+
* @param desiredType The desired type name.
|
|
2843
|
+
* @returns True if the typed value is of the desired type.
|
|
2844
|
+
*/
|
|
2845
|
+
function fhirPathIs(typedValue, desiredType) {
|
|
2846
|
+
const { value } = typedValue;
|
|
2847
|
+
if (value === undefined || value === null) {
|
|
2848
|
+
return false;
|
|
2849
|
+
}
|
|
2850
|
+
switch (desiredType) {
|
|
2851
|
+
case 'Boolean':
|
|
2852
|
+
return typeof value === 'boolean';
|
|
2853
|
+
case 'Decimal':
|
|
2854
|
+
case 'Integer':
|
|
2855
|
+
return typeof value === 'number';
|
|
2856
|
+
case 'Date':
|
|
2857
|
+
return typeof value === 'string' && !!value.match(/^\d{4}(-\d{2}(-\d{2})?)?/);
|
|
2858
|
+
case 'DateTime':
|
|
2859
|
+
return typeof value === 'string' && !!value.match(/^\d{4}(-\d{2}(-\d{2})?)?T/);
|
|
2860
|
+
case 'Time':
|
|
2861
|
+
return typeof value === 'string' && !!value.match(/^T\d/);
|
|
2862
|
+
case 'Period':
|
|
2863
|
+
return isPeriod(value);
|
|
2864
|
+
case 'Quantity':
|
|
2865
|
+
return isQuantity(value);
|
|
2866
|
+
default:
|
|
2867
|
+
return typeof value === 'object' && (value === null || value === void 0 ? void 0 : value.resourceType) === desiredType;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
/**
|
|
2871
|
+
* Determines if the input is a Period object.
|
|
2872
|
+
* This is heuristic based, as we do not have strong typing at runtime.
|
|
2873
|
+
* @param input The input value.
|
|
2874
|
+
* @returns True if the input is a period.
|
|
2875
|
+
*/
|
|
2876
|
+
function isPeriod(input) {
|
|
2877
|
+
return !!(input && typeof input === 'object' && 'start' in input);
|
|
2878
|
+
}
|
|
2879
|
+
/**
|
|
2880
|
+
* Determines if the input is a Quantity object.
|
|
2881
|
+
* This is heuristic based, as we do not have strong typing at runtime.
|
|
2882
|
+
* @param input The input value.
|
|
2883
|
+
* @returns True if the input is a quantity.
|
|
2884
|
+
*/
|
|
2885
|
+
function isQuantity(input) {
|
|
2886
|
+
return !!(input && typeof input === 'object' && 'value' in input && typeof input.value === 'number');
|
|
2887
|
+
}
|
|
2888
|
+
function isQuantityEquivalent(x, y) {
|
|
2889
|
+
return (Math.abs(x.value - y.value) < 0.01 &&
|
|
2890
|
+
(x.unit === y.unit || x.code === y.code || x.unit === y.code || x.code === y.unit));
|
|
2891
|
+
}
|
|
2892
|
+
/**
|
|
2893
|
+
* Resource equality.
|
|
2894
|
+
* Ignores meta.versionId and meta.lastUpdated.
|
|
2895
|
+
* See: https://dmitripavlutin.com/how-to-compare-objects-in-javascript/#4-deep-equality
|
|
2896
|
+
* @param object1 The first object.
|
|
2897
|
+
* @param object2 The second object.
|
|
2898
|
+
* @returns True if the objects are equal.
|
|
2899
|
+
*/
|
|
2900
|
+
function deepEquals(object1, object2) {
|
|
2901
|
+
const keys1 = Object.keys(object1);
|
|
2902
|
+
const keys2 = Object.keys(object2);
|
|
2903
|
+
if (keys1.length !== keys2.length) {
|
|
2904
|
+
return false;
|
|
2905
|
+
}
|
|
2906
|
+
for (const key of keys1) {
|
|
2907
|
+
const val1 = object1[key];
|
|
2908
|
+
const val2 = object2[key];
|
|
2909
|
+
if (isObject(val1) && isObject(val2)) {
|
|
2910
|
+
if (!deepEquals(val1, val2)) {
|
|
2911
|
+
return false;
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
else {
|
|
2915
|
+
if (val1 !== val2) {
|
|
2916
|
+
return false;
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
return true;
|
|
2921
|
+
}
|
|
2922
|
+
function isObject(object) {
|
|
2923
|
+
return object !== null && typeof object === 'object';
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
var _SymbolAtom_instances, _SymbolAtom_evalValue;
|
|
2927
|
+
class FhirPathAtom {
|
|
2928
|
+
constructor(original, child) {
|
|
2929
|
+
this.original = original;
|
|
2930
|
+
this.child = child;
|
|
2931
|
+
}
|
|
2932
|
+
eval(context) {
|
|
2933
|
+
try {
|
|
2934
|
+
if (context.length > 0) {
|
|
2935
|
+
return context.map((e) => this.child.eval([e])).flat();
|
|
2936
|
+
}
|
|
2937
|
+
else {
|
|
2938
|
+
return this.child.eval(context);
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
catch (error) {
|
|
2942
|
+
throw new Error(`FhirPathError on "${this.original}": ${error}`);
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
class LiteralAtom {
|
|
2947
|
+
constructor(value) {
|
|
2948
|
+
this.value = value;
|
|
2949
|
+
}
|
|
2950
|
+
eval() {
|
|
2951
|
+
return [this.value];
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
class SymbolAtom {
|
|
2955
|
+
constructor(name) {
|
|
2956
|
+
this.name = name;
|
|
2957
|
+
_SymbolAtom_instances.add(this);
|
|
2958
|
+
}
|
|
2959
|
+
eval(context) {
|
|
2960
|
+
if (this.name === '$this') {
|
|
2961
|
+
return context;
|
|
2962
|
+
}
|
|
2963
|
+
return context
|
|
2964
|
+
.map((e) => __classPrivateFieldGet(this, _SymbolAtom_instances, "m", _SymbolAtom_evalValue).call(this, e))
|
|
2965
|
+
.flat()
|
|
2966
|
+
.filter((e) => (e === null || e === void 0 ? void 0 : e.value) !== undefined);
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
_SymbolAtom_instances = new WeakSet(), _SymbolAtom_evalValue = function _SymbolAtom_evalValue(typedValue) {
|
|
2970
|
+
const input = typedValue.value;
|
|
2971
|
+
if (!input || typeof input !== 'object') {
|
|
2972
|
+
return undefined;
|
|
2973
|
+
}
|
|
2974
|
+
if ('resourceType' in input && input.resourceType === this.name) {
|
|
2975
|
+
return typedValue;
|
|
2976
|
+
}
|
|
2977
|
+
let result = undefined;
|
|
2978
|
+
if (this.name in input) {
|
|
2979
|
+
result = input[this.name];
|
|
2980
|
+
}
|
|
2981
|
+
else {
|
|
2982
|
+
const propertyName = Object.keys(input).find((k) => k.startsWith(this.name));
|
|
2983
|
+
if (propertyName) {
|
|
2984
|
+
result = input[propertyName];
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
if (result === undefined) {
|
|
2988
|
+
return undefined;
|
|
2989
|
+
}
|
|
2990
|
+
// TODO: Get the PropertyType from the choice of type
|
|
2991
|
+
if (Array.isArray(result)) {
|
|
2992
|
+
return result.map(toTypedValue);
|
|
2993
|
+
}
|
|
2994
|
+
else {
|
|
2995
|
+
return [toTypedValue(result)];
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2998
|
+
class EmptySetAtom {
|
|
2999
|
+
eval() {
|
|
3000
|
+
return [];
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
class UnaryOperatorAtom {
|
|
3004
|
+
constructor(child, impl) {
|
|
3005
|
+
this.child = child;
|
|
3006
|
+
this.impl = impl;
|
|
3007
|
+
}
|
|
3008
|
+
eval(context) {
|
|
3009
|
+
return this.impl(this.child.eval(context));
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
class AsAtom {
|
|
3013
|
+
constructor(left, right) {
|
|
3014
|
+
this.left = left;
|
|
3015
|
+
this.right = right;
|
|
3016
|
+
}
|
|
3017
|
+
eval(context) {
|
|
3018
|
+
return this.left.eval(context);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
class ArithemticOperatorAtom {
|
|
3022
|
+
constructor(left, right, impl) {
|
|
3023
|
+
this.left = left;
|
|
3024
|
+
this.right = right;
|
|
3025
|
+
this.impl = impl;
|
|
3026
|
+
}
|
|
3027
|
+
eval(context) {
|
|
3028
|
+
const leftEvalResult = this.left.eval(context);
|
|
3029
|
+
if (leftEvalResult.length !== 1) {
|
|
3030
|
+
return [];
|
|
3031
|
+
}
|
|
3032
|
+
const rightEvalResult = this.right.eval(context);
|
|
3033
|
+
if (rightEvalResult.length !== 1) {
|
|
3034
|
+
return [];
|
|
3035
|
+
}
|
|
3036
|
+
const leftValue = leftEvalResult[0].value;
|
|
3037
|
+
const rightValue = rightEvalResult[0].value;
|
|
3038
|
+
const leftNumber = isQuantity(leftValue) ? leftValue.value : leftValue;
|
|
3039
|
+
const rightNumber = isQuantity(rightValue) ? rightValue.value : rightValue;
|
|
3040
|
+
const result = this.impl(leftNumber, rightNumber);
|
|
3041
|
+
if (typeof result === 'boolean') {
|
|
3042
|
+
return booleanToTypedValue(result);
|
|
3043
|
+
}
|
|
3044
|
+
else if (isQuantity(leftValue)) {
|
|
3045
|
+
return [{ type: PropertyType.Quantity, value: Object.assign(Object.assign({}, leftValue), { value: result }) }];
|
|
3046
|
+
}
|
|
3047
|
+
else {
|
|
3048
|
+
return [toTypedValue(result)];
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
class ConcatAtom {
|
|
3053
|
+
constructor(left, right) {
|
|
3054
|
+
this.left = left;
|
|
3055
|
+
this.right = right;
|
|
3056
|
+
}
|
|
3057
|
+
eval(context) {
|
|
3058
|
+
const leftValue = this.left.eval(context);
|
|
3059
|
+
const rightValue = this.right.eval(context);
|
|
3060
|
+
const result = [...leftValue, ...rightValue];
|
|
3061
|
+
if (result.length > 0 && result.every((e) => typeof e.value === 'string')) {
|
|
3062
|
+
return [{ type: PropertyType.string, value: result.map((e) => e.value).join('') }];
|
|
3063
|
+
}
|
|
3064
|
+
return result;
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
class ContainsAtom {
|
|
3068
|
+
constructor(left, right) {
|
|
3069
|
+
this.left = left;
|
|
3070
|
+
this.right = right;
|
|
3071
|
+
}
|
|
3072
|
+
eval(context) {
|
|
3073
|
+
const leftValue = this.left.eval(context);
|
|
3074
|
+
const rightValue = this.right.eval(context);
|
|
3075
|
+
return booleanToTypedValue(leftValue.some((e) => e.value === rightValue[0].value));
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
class InAtom {
|
|
3079
|
+
constructor(left, right) {
|
|
3080
|
+
this.left = left;
|
|
3081
|
+
this.right = right;
|
|
3082
|
+
}
|
|
3083
|
+
eval(context) {
|
|
3084
|
+
const leftValue = this.left.eval(context);
|
|
3085
|
+
const rightValue = this.right.eval(context);
|
|
3086
|
+
return booleanToTypedValue(rightValue.some((e) => e.value === leftValue[0].value));
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
class DotAtom {
|
|
3090
|
+
constructor(left, right) {
|
|
3091
|
+
this.left = left;
|
|
3092
|
+
this.right = right;
|
|
3093
|
+
}
|
|
3094
|
+
eval(context) {
|
|
3095
|
+
return this.right.eval(this.left.eval(context));
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
class UnionAtom {
|
|
3099
|
+
constructor(left, right) {
|
|
3100
|
+
this.left = left;
|
|
3101
|
+
this.right = right;
|
|
3102
|
+
}
|
|
3103
|
+
eval(context) {
|
|
3104
|
+
const leftResult = this.left.eval(context);
|
|
3105
|
+
const rightResult = this.right.eval(context);
|
|
3106
|
+
return removeDuplicates([...leftResult, ...rightResult]);
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
class EqualsAtom {
|
|
3110
|
+
constructor(left, right) {
|
|
3111
|
+
this.left = left;
|
|
3112
|
+
this.right = right;
|
|
3113
|
+
}
|
|
3114
|
+
eval(context) {
|
|
3115
|
+
const leftValue = this.left.eval(context);
|
|
3116
|
+
const rightValue = this.right.eval(context);
|
|
3117
|
+
return fhirPathArrayEquals(leftValue, rightValue);
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
class NotEqualsAtom {
|
|
3121
|
+
constructor(left, right) {
|
|
3122
|
+
this.left = left;
|
|
3123
|
+
this.right = right;
|
|
3124
|
+
}
|
|
3125
|
+
eval(context) {
|
|
3126
|
+
const leftValue = this.left.eval(context);
|
|
3127
|
+
const rightValue = this.right.eval(context);
|
|
3128
|
+
return fhirPathNot(fhirPathArrayEquals(leftValue, rightValue));
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
class EquivalentAtom {
|
|
3132
|
+
constructor(left, right) {
|
|
3133
|
+
this.left = left;
|
|
3134
|
+
this.right = right;
|
|
3135
|
+
}
|
|
3136
|
+
eval(context) {
|
|
3137
|
+
const leftValue = this.left.eval(context);
|
|
3138
|
+
const rightValue = this.right.eval(context);
|
|
3139
|
+
return fhirPathArrayEquivalent(leftValue, rightValue);
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
class NotEquivalentAtom {
|
|
3143
|
+
constructor(left, right) {
|
|
3144
|
+
this.left = left;
|
|
3145
|
+
this.right = right;
|
|
3146
|
+
}
|
|
3147
|
+
eval(context) {
|
|
3148
|
+
const leftValue = this.left.eval(context);
|
|
3149
|
+
const rightValue = this.right.eval(context);
|
|
3150
|
+
return fhirPathNot(fhirPathArrayEquivalent(leftValue, rightValue));
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
class IsAtom {
|
|
3154
|
+
constructor(left, right) {
|
|
3155
|
+
this.left = left;
|
|
3156
|
+
this.right = right;
|
|
3157
|
+
}
|
|
3158
|
+
eval(context) {
|
|
3159
|
+
const leftValue = this.left.eval(context);
|
|
3160
|
+
if (leftValue.length !== 1) {
|
|
3161
|
+
return [];
|
|
3162
|
+
}
|
|
3163
|
+
const typeName = this.right.name;
|
|
3164
|
+
return booleanToTypedValue(fhirPathIs(leftValue[0], typeName));
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
/**
|
|
3168
|
+
* 6.5.1. and
|
|
3169
|
+
* Returns true if both operands evaluate to true, false if either operand evaluates to false, and the empty collection ({ }) otherwise.
|
|
3170
|
+
*/
|
|
3171
|
+
class AndAtom {
|
|
3172
|
+
constructor(left, right) {
|
|
3173
|
+
this.left = left;
|
|
3174
|
+
this.right = right;
|
|
3175
|
+
}
|
|
3176
|
+
eval(context) {
|
|
3177
|
+
var _a, _b, _c, _d;
|
|
3178
|
+
const leftValue = this.left.eval(context);
|
|
3179
|
+
const rightValue = this.right.eval(context);
|
|
3180
|
+
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) {
|
|
3181
|
+
return booleanToTypedValue(true);
|
|
3182
|
+
}
|
|
3183
|
+
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) {
|
|
3184
|
+
return booleanToTypedValue(false);
|
|
3185
|
+
}
|
|
3186
|
+
return [];
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
class OrAtom {
|
|
3190
|
+
constructor(left, right) {
|
|
3191
|
+
this.left = left;
|
|
3192
|
+
this.right = right;
|
|
3193
|
+
}
|
|
3194
|
+
eval(context) {
|
|
3195
|
+
const leftValue = this.left.eval(context);
|
|
3196
|
+
if (toJsBoolean(leftValue)) {
|
|
3197
|
+
return leftValue;
|
|
3198
|
+
}
|
|
3199
|
+
const rightValue = this.right.eval(context);
|
|
3200
|
+
if (toJsBoolean(rightValue)) {
|
|
3201
|
+
return rightValue;
|
|
3202
|
+
}
|
|
3203
|
+
return [];
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
/**
|
|
3207
|
+
* 6.5.4. xor
|
|
3208
|
+
* Returns true if exactly one of the operands evaluates to true,
|
|
3209
|
+
* false if either both operands evaluate to true or both operands evaluate to false,
|
|
3210
|
+
* and the empty collection ({ }) otherwise:
|
|
3211
|
+
*/
|
|
3212
|
+
class XorAtom {
|
|
3213
|
+
constructor(left, right) {
|
|
3214
|
+
this.left = left;
|
|
3215
|
+
this.right = right;
|
|
3216
|
+
}
|
|
3217
|
+
eval(context) {
|
|
3218
|
+
const leftResult = this.left.eval(context);
|
|
3219
|
+
const rightResult = this.right.eval(context);
|
|
3220
|
+
if (leftResult.length === 0 && rightResult.length === 0) {
|
|
3221
|
+
return [];
|
|
3222
|
+
}
|
|
3223
|
+
const leftValue = leftResult.length === 0 ? null : leftResult[0].value;
|
|
3224
|
+
const rightValue = rightResult.length === 0 ? null : rightResult[0].value;
|
|
3225
|
+
if ((leftValue === true && rightValue !== true) || (leftValue !== true && rightValue === true)) {
|
|
3226
|
+
return booleanToTypedValue(true);
|
|
3227
|
+
}
|
|
3228
|
+
if ((leftValue === true && rightValue === true) || (leftValue === false && rightValue === false)) {
|
|
3229
|
+
return booleanToTypedValue(false);
|
|
3230
|
+
}
|
|
3231
|
+
return [];
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
class FunctionAtom {
|
|
3235
|
+
constructor(name, args, impl) {
|
|
3236
|
+
this.name = name;
|
|
3237
|
+
this.args = args;
|
|
3238
|
+
this.impl = impl;
|
|
3239
|
+
}
|
|
3240
|
+
eval(context) {
|
|
3241
|
+
return this.impl(context, ...this.args);
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
class IndexerAtom {
|
|
3245
|
+
constructor(left, expr) {
|
|
3246
|
+
this.left = left;
|
|
3247
|
+
this.expr = expr;
|
|
3248
|
+
}
|
|
3249
|
+
eval(context) {
|
|
3250
|
+
const evalResult = this.expr.eval(context);
|
|
3251
|
+
if (evalResult.length !== 1) {
|
|
3252
|
+
return [];
|
|
3253
|
+
}
|
|
3254
|
+
const index = evalResult[0].value;
|
|
3255
|
+
if (typeof index !== 'number') {
|
|
3256
|
+
throw new Error(`Invalid indexer expression: should return integer}`);
|
|
3257
|
+
}
|
|
3258
|
+
const leftResult = this.left.eval(context);
|
|
3259
|
+
if (!(index in leftResult)) {
|
|
3260
|
+
return [];
|
|
3261
|
+
}
|
|
3262
|
+
return [leftResult[index]];
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
function parseDateString(str) {
|
|
3267
|
+
if (str.startsWith('T')) {
|
|
3268
|
+
// If a time string,
|
|
3269
|
+
// then normalize to full length.
|
|
3270
|
+
return str + 'T00:00:00.000Z'.substring(str.length);
|
|
3271
|
+
}
|
|
3272
|
+
if (str.length <= 10) {
|
|
3273
|
+
// If a local date (i.e., "2021-01-01"),
|
|
3274
|
+
// then return as-is.
|
|
3275
|
+
return str;
|
|
3276
|
+
}
|
|
3277
|
+
try {
|
|
3278
|
+
// Try to normalize to UTC
|
|
3279
|
+
return new Date(str).toISOString();
|
|
3280
|
+
}
|
|
3281
|
+
catch (e) {
|
|
3282
|
+
// Fallback to original input
|
|
3283
|
+
// This happens on unsupported time formats such as "2021-01-01T12"
|
|
3284
|
+
return str;
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
/**
|
|
3289
|
+
* Temporary placholder for unimplemented methods.
|
|
3290
|
+
*/
|
|
3291
|
+
const stub = () => [];
|
|
3292
|
+
const functions = {
|
|
3293
|
+
/*
|
|
3294
|
+
* 5.1 Existence
|
|
3295
|
+
* See: https://hl7.org/fhirpath/#existence
|
|
3296
|
+
*/
|
|
3297
|
+
/**
|
|
3298
|
+
* Returns true if the input collection is empty ({ }) and false otherwise.
|
|
3299
|
+
*
|
|
3300
|
+
* See: https://hl7.org/fhirpath/#empty-boolean
|
|
3301
|
+
*
|
|
3302
|
+
* @param input The input collection.
|
|
3303
|
+
* @returns True if the input collection is empty ({ }) and false otherwise.
|
|
3304
|
+
*/
|
|
3305
|
+
empty: (input) => {
|
|
3306
|
+
return booleanToTypedValue(input.length === 0);
|
|
3307
|
+
},
|
|
3308
|
+
/**
|
|
3309
|
+
* Returns true if the collection has unknown elements, and false otherwise.
|
|
3310
|
+
* This is the opposite of empty(), and as such is a shorthand for empty().not().
|
|
3311
|
+
* If the input collection is empty ({ }), the result is false.
|
|
3312
|
+
*
|
|
3313
|
+
* The function can also take an optional criteria to be applied to the collection
|
|
3314
|
+
* prior to the determination of the exists. In this case, the function is shorthand
|
|
3315
|
+
* for where(criteria).exists().
|
|
3316
|
+
*
|
|
3317
|
+
* See: https://hl7.org/fhirpath/#existscriteria-expression-boolean
|
|
3318
|
+
*
|
|
3319
|
+
* @param input
|
|
3320
|
+
* @param criteria
|
|
3321
|
+
* @returns True if the collection has unknown elements, and false otherwise.
|
|
3322
|
+
*/
|
|
3323
|
+
exists: (input, criteria) => {
|
|
3324
|
+
if (criteria) {
|
|
3325
|
+
return booleanToTypedValue(input.filter((e) => toJsBoolean(criteria.eval([e]))).length > 0);
|
|
3326
|
+
}
|
|
3327
|
+
else {
|
|
3328
|
+
return booleanToTypedValue(input.length > 0);
|
|
3329
|
+
}
|
|
3330
|
+
},
|
|
3331
|
+
/**
|
|
3332
|
+
* Returns true if for every element in the input collection, criteria evaluates to true.
|
|
3333
|
+
* Otherwise, the result is false.
|
|
3334
|
+
*
|
|
3335
|
+
* If the input collection is empty ({ }), the result is true.
|
|
3336
|
+
*
|
|
3337
|
+
* See: https://hl7.org/fhirpath/#allcriteria-expression-boolean
|
|
3338
|
+
*
|
|
3339
|
+
* @param input The input collection.
|
|
3340
|
+
* @param criteria The evaluation criteria.
|
|
3341
|
+
* @returns True if for every element in the input collection, criteria evaluates to true.
|
|
3342
|
+
*/
|
|
3343
|
+
all: (input, criteria) => {
|
|
3344
|
+
return booleanToTypedValue(input.every((e) => toJsBoolean(criteria.eval([e]))));
|
|
3345
|
+
},
|
|
3346
|
+
/**
|
|
3347
|
+
* Takes a collection of Boolean values and returns true if all the items are true.
|
|
3348
|
+
* If unknown items are false, the result is false.
|
|
3349
|
+
* If the input is empty ({ }), the result is true.
|
|
3350
|
+
*
|
|
3351
|
+
* See: https://hl7.org/fhirpath/#alltrue-boolean
|
|
3352
|
+
*
|
|
3353
|
+
* @param input The input collection.
|
|
3354
|
+
* @param criteria The evaluation criteria.
|
|
3355
|
+
* @returns True if all the items are true.
|
|
3356
|
+
*/
|
|
3357
|
+
allTrue: (input) => {
|
|
3358
|
+
for (const value of input) {
|
|
3359
|
+
if (!value.value) {
|
|
3360
|
+
return booleanToTypedValue(false);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
return booleanToTypedValue(true);
|
|
3364
|
+
},
|
|
3365
|
+
/**
|
|
3366
|
+
* Takes a collection of Boolean values and returns true if unknown of the items are true.
|
|
3367
|
+
* If all the items are false, or if the input is empty ({ }), the result is false.
|
|
3368
|
+
*
|
|
3369
|
+
* See: https://hl7.org/fhirpath/#anytrue-boolean
|
|
3370
|
+
*
|
|
3371
|
+
* @param input The input collection.
|
|
3372
|
+
* @param criteria The evaluation criteria.
|
|
3373
|
+
* @returns True if unknown of the items are true.
|
|
3374
|
+
*/
|
|
3375
|
+
anyTrue: (input) => {
|
|
3376
|
+
for (const value of input) {
|
|
3377
|
+
if (value.value) {
|
|
3378
|
+
return booleanToTypedValue(true);
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
return booleanToTypedValue(false);
|
|
3382
|
+
},
|
|
3383
|
+
/**
|
|
3384
|
+
* Takes a collection of Boolean values and returns true if all the items are false.
|
|
3385
|
+
* If unknown items are true, the result is false.
|
|
3386
|
+
* If the input is empty ({ }), the result is true.
|
|
3387
|
+
*
|
|
3388
|
+
* See: https://hl7.org/fhirpath/#allfalse-boolean
|
|
3389
|
+
*
|
|
3390
|
+
* @param input The input collection.
|
|
3391
|
+
* @param criteria The evaluation criteria.
|
|
3392
|
+
* @returns True if all the items are false.
|
|
3393
|
+
*/
|
|
3394
|
+
allFalse: (input) => {
|
|
3395
|
+
for (const value of input) {
|
|
3396
|
+
if (value.value) {
|
|
3397
|
+
return booleanToTypedValue(false);
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
return booleanToTypedValue(true);
|
|
3401
|
+
},
|
|
3402
|
+
/**
|
|
3403
|
+
* Takes a collection of Boolean values and returns true if unknown of the items are false.
|
|
3404
|
+
* If all the items are true, or if the input is empty ({ }), the result is false.
|
|
3405
|
+
*
|
|
3406
|
+
* See: https://hl7.org/fhirpath/#anyfalse-boolean
|
|
3407
|
+
*
|
|
3408
|
+
* @param input The input collection.
|
|
3409
|
+
* @param criteria The evaluation criteria.
|
|
3410
|
+
* @returns True if for every element in the input collection, criteria evaluates to true.
|
|
3411
|
+
*/
|
|
3412
|
+
anyFalse: (input) => {
|
|
3413
|
+
for (const value of input) {
|
|
3414
|
+
if (!value.value) {
|
|
3415
|
+
return booleanToTypedValue(true);
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
return booleanToTypedValue(false);
|
|
3419
|
+
},
|
|
3420
|
+
/**
|
|
3421
|
+
* Returns true if all items in the input collection are members of the collection passed
|
|
3422
|
+
* as the other argument. Membership is determined using the = (Equals) (=) operation.
|
|
3423
|
+
*
|
|
3424
|
+
* Conceptually, this function is evaluated by testing each element in the input collection
|
|
3425
|
+
* for membership in the other collection, with a default of true. This means that if the
|
|
3426
|
+
* input collection is empty ({ }), the result is true, otherwise if the other collection
|
|
3427
|
+
* is empty ({ }), the result is false.
|
|
3428
|
+
*
|
|
3429
|
+
* See: http://hl7.org/fhirpath/#subsetofother-collection-boolean
|
|
3430
|
+
*/
|
|
3431
|
+
subsetOf: stub,
|
|
3432
|
+
/**
|
|
3433
|
+
* Returns true if all items in the collection passed as the other argument are members of
|
|
3434
|
+
* the input collection. Membership is determined using the = (Equals) (=) operation.
|
|
3435
|
+
*
|
|
3436
|
+
* Conceptually, this function is evaluated by testing each element in the other collection
|
|
3437
|
+
* for membership in the input collection, with a default of true. This means that if the
|
|
3438
|
+
* other collection is empty ({ }), the result is true, otherwise if the input collection
|
|
3439
|
+
* is empty ({ }), the result is false.
|
|
3440
|
+
*
|
|
3441
|
+
* See: http://hl7.org/fhirpath/#supersetofother-collection-boolean
|
|
3442
|
+
*/
|
|
3443
|
+
supersetOf: stub,
|
|
3444
|
+
/**
|
|
3445
|
+
* Returns the integer count of the number of items in the input collection.
|
|
3446
|
+
* Returns 0 when the input collection is empty.
|
|
3447
|
+
*
|
|
3448
|
+
* See: https://hl7.org/fhirpath/#count-integer
|
|
3449
|
+
*
|
|
3450
|
+
* @param input The input collection.
|
|
3451
|
+
* @returns The integer count of the number of items in the input collection.
|
|
3452
|
+
*/
|
|
3453
|
+
count: (input) => {
|
|
3454
|
+
return [{ type: PropertyType.integer, value: input.length }];
|
|
3455
|
+
},
|
|
3456
|
+
/**
|
|
3457
|
+
* Returns a collection containing only the unique items in the input collection.
|
|
3458
|
+
* To determine whether two items are the same, the = (Equals) (=) operator is used,
|
|
3459
|
+
* as defined below.
|
|
3460
|
+
*
|
|
3461
|
+
* If the input collection is empty ({ }), the result is empty.
|
|
3462
|
+
*
|
|
3463
|
+
* Note that the order of elements in the input collection is not guaranteed to be
|
|
3464
|
+
* preserved in the result.
|
|
3465
|
+
*
|
|
3466
|
+
* See: https://hl7.org/fhirpath/#distinct-collection
|
|
3467
|
+
*
|
|
3468
|
+
* @param input The input collection.
|
|
3469
|
+
* @returns The integer count of the number of items in the input collection.
|
|
3470
|
+
*/
|
|
3471
|
+
distinct: (input) => {
|
|
3472
|
+
const result = [];
|
|
3473
|
+
for (const value of input) {
|
|
3474
|
+
if (!result.some((e) => e.value === value.value)) {
|
|
3475
|
+
result.push(value);
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
return result;
|
|
3479
|
+
},
|
|
3480
|
+
/**
|
|
3481
|
+
* Returns true if all the items in the input collection are distinct.
|
|
3482
|
+
* To determine whether two items are distinct, the = (Equals) (=) operator is used,
|
|
3483
|
+
* as defined below.
|
|
3484
|
+
*
|
|
3485
|
+
* See: https://hl7.org/fhirpath/#isdistinct-boolean
|
|
3486
|
+
*
|
|
3487
|
+
* @param input The input collection.
|
|
3488
|
+
* @returns The integer count of the number of items in the input collection.
|
|
3489
|
+
*/
|
|
3490
|
+
isDistinct: (input) => {
|
|
3491
|
+
return booleanToTypedValue(input.length === functions.distinct(input).length);
|
|
3492
|
+
},
|
|
3493
|
+
/*
|
|
3494
|
+
* 5.2 Filtering and projection
|
|
3495
|
+
*/
|
|
3496
|
+
/**
|
|
3497
|
+
* Returns a collection containing only those elements in the input collection
|
|
3498
|
+
* for which the stated criteria expression evaluates to true.
|
|
3499
|
+
* Elements for which the expression evaluates to false or empty ({ }) are not
|
|
3500
|
+
* included in the result.
|
|
3501
|
+
*
|
|
3502
|
+
* If the input collection is empty ({ }), the result is empty.
|
|
3503
|
+
*
|
|
3504
|
+
* If the result of evaluating the condition is other than a single boolean value,
|
|
3505
|
+
* the evaluation will end and signal an error to the calling environment,
|
|
3506
|
+
* consistent with singleton evaluation of collections behavior.
|
|
3507
|
+
*
|
|
3508
|
+
* See: https://hl7.org/fhirpath/#wherecriteria-expression-collection
|
|
3509
|
+
*
|
|
3510
|
+
* @param input The input collection.
|
|
3511
|
+
* @param condition The condition atom.
|
|
3512
|
+
* @returns A collection containing only those elements in the input collection for which the stated criteria expression evaluates to true.
|
|
3513
|
+
*/
|
|
3514
|
+
where: (input, criteria) => {
|
|
3515
|
+
return input.filter((e) => toJsBoolean(criteria.eval([e])));
|
|
3516
|
+
},
|
|
3517
|
+
/**
|
|
3518
|
+
* Evaluates the projection expression for each item in the input collection.
|
|
3519
|
+
* The result of each evaluation is added to the output collection. If the
|
|
3520
|
+
* evaluation results in a collection with multiple items, all items are added
|
|
3521
|
+
* to the output collection (collections resulting from evaluation of projection
|
|
3522
|
+
* are flattened). This means that if the evaluation for an element results in
|
|
3523
|
+
* the empty collection ({ }), no element is added to the result, and that if
|
|
3524
|
+
* the input collection is empty ({ }), the result is empty as well.
|
|
3525
|
+
*
|
|
3526
|
+
* See: http://hl7.org/fhirpath/#selectprojection-expression-collection
|
|
3527
|
+
*/
|
|
3528
|
+
select: (input, criteria) => {
|
|
3529
|
+
return input.map((e) => criteria.eval([e])).flat();
|
|
3530
|
+
},
|
|
3531
|
+
/**
|
|
3532
|
+
* A version of select that will repeat the projection and add it to the output
|
|
3533
|
+
* collection, as long as the projection yields new items (as determined by
|
|
3534
|
+
* the = (Equals) (=) operator).
|
|
3535
|
+
*
|
|
3536
|
+
* See: http://hl7.org/fhirpath/#repeatprojection-expression-collection
|
|
3537
|
+
*/
|
|
3538
|
+
repeat: stub,
|
|
3539
|
+
/**
|
|
3540
|
+
* Returns a collection that contains all items in the input collection that
|
|
3541
|
+
* are of the given type or a subclass thereof. If the input collection is
|
|
3542
|
+
* empty ({ }), the result is empty. The type argument is an identifier that
|
|
3543
|
+
* must resolve to the name of a type in a model
|
|
3544
|
+
*
|
|
3545
|
+
* See: http://hl7.org/fhirpath/#oftypetype-type-specifier-collection
|
|
3546
|
+
*/
|
|
3547
|
+
ofType: stub,
|
|
3548
|
+
/*
|
|
3549
|
+
* 5.3 Subsetting
|
|
3550
|
+
*/
|
|
3551
|
+
/**
|
|
3552
|
+
* Will return the single item in the input if there is just one item.
|
|
3553
|
+
* If the input collection is empty ({ }), the result is empty.
|
|
3554
|
+
* If there are multiple items, an error is signaled to the evaluation environment.
|
|
3555
|
+
* This function is useful for ensuring that an error is returned if an assumption
|
|
3556
|
+
* about cardinality is violated at run-time.
|
|
3557
|
+
*
|
|
3558
|
+
* See: https://hl7.org/fhirpath/#single-collection
|
|
3559
|
+
*
|
|
3560
|
+
* @param input The input collection.
|
|
3561
|
+
* @returns The single item in the input if there is just one item.
|
|
3562
|
+
*/
|
|
3563
|
+
single: (input) => {
|
|
3564
|
+
if (input.length > 1) {
|
|
3565
|
+
throw new Error('Expected input length one for single()');
|
|
3566
|
+
}
|
|
3567
|
+
return input.length === 0 ? [] : input.slice(0, 1);
|
|
3568
|
+
},
|
|
3569
|
+
/**
|
|
3570
|
+
* Returns a collection containing only the first item in the input collection.
|
|
3571
|
+
* This function is equivalent to item[0], so it will return an empty collection if the input collection has no items.
|
|
3572
|
+
*
|
|
3573
|
+
* See: https://hl7.org/fhirpath/#first-collection
|
|
3574
|
+
*
|
|
3575
|
+
* @param input The input collection.
|
|
3576
|
+
* @returns A collection containing only the first item in the input collection.
|
|
3577
|
+
*/
|
|
3578
|
+
first: (input) => {
|
|
3579
|
+
return input.length === 0 ? [] : input.slice(0, 1);
|
|
3580
|
+
},
|
|
3581
|
+
/**
|
|
3582
|
+
* Returns a collection containing only the last item in the input collection.
|
|
3583
|
+
* Will return an empty collection if the input collection has no items.
|
|
3584
|
+
*
|
|
3585
|
+
* See: https://hl7.org/fhirpath/#last-collection
|
|
3586
|
+
*
|
|
3587
|
+
* @param input The input collection.
|
|
3588
|
+
* @returns A collection containing only the last item in the input collection.
|
|
3589
|
+
*/
|
|
3590
|
+
last: (input) => {
|
|
3591
|
+
return input.length === 0 ? [] : input.slice(input.length - 1, input.length);
|
|
3592
|
+
},
|
|
3593
|
+
/**
|
|
3594
|
+
* Returns a collection containing all but the first item in the input collection.
|
|
3595
|
+
* Will return an empty collection if the input collection has no items, or only one item.
|
|
3596
|
+
*
|
|
3597
|
+
* See: https://hl7.org/fhirpath/#tail-collection
|
|
3598
|
+
*
|
|
3599
|
+
* @param input The input collection.
|
|
3600
|
+
* @returns A collection containing all but the first item in the input collection.
|
|
3601
|
+
*/
|
|
3602
|
+
tail: (input) => {
|
|
3603
|
+
return input.length === 0 ? [] : input.slice(1, input.length);
|
|
3604
|
+
},
|
|
3605
|
+
/**
|
|
3606
|
+
* Returns a collection containing all but the first num items in the input collection.
|
|
3607
|
+
* Will return an empty collection if there are no items remaining after the
|
|
3608
|
+
* indicated number of items have been skipped, or if the input collection is empty.
|
|
3609
|
+
* If num is less than or equal to zero, the input collection is simply returned.
|
|
3610
|
+
*
|
|
3611
|
+
* See: https://hl7.org/fhirpath/#skipnum-integer-collection
|
|
3612
|
+
*
|
|
3613
|
+
* @param input The input collection.
|
|
3614
|
+
* @returns A collection containing all but the first item in the input collection.
|
|
3615
|
+
*/
|
|
3616
|
+
skip: (input, num) => {
|
|
3617
|
+
var _a;
|
|
3618
|
+
const numValue = (_a = num.eval([])[0]) === null || _a === void 0 ? void 0 : _a.value;
|
|
3619
|
+
if (typeof numValue !== 'number') {
|
|
3620
|
+
throw new Error('Expected a number for skip(num)');
|
|
3621
|
+
}
|
|
3622
|
+
if (numValue >= input.length) {
|
|
3623
|
+
return [];
|
|
3624
|
+
}
|
|
3625
|
+
if (numValue <= 0) {
|
|
3626
|
+
return input;
|
|
3627
|
+
}
|
|
3628
|
+
return input.slice(numValue, input.length);
|
|
3629
|
+
},
|
|
3630
|
+
/**
|
|
3631
|
+
* Returns a collection containing the first num items in the input collection,
|
|
3632
|
+
* or less if there are less than num items.
|
|
3633
|
+
* If num is less than or equal to 0, or if the input collection is empty ({ }),
|
|
3634
|
+
* take returns an empty collection.
|
|
3635
|
+
*
|
|
3636
|
+
* See: https://hl7.org/fhirpath/#takenum-integer-collection
|
|
3637
|
+
*
|
|
3638
|
+
* @param input The input collection.
|
|
3639
|
+
* @returns A collection containing the first num items in the input collection.
|
|
3640
|
+
*/
|
|
3641
|
+
take: (input, num) => {
|
|
3642
|
+
var _a;
|
|
3643
|
+
const numValue = (_a = num.eval([])[0]) === null || _a === void 0 ? void 0 : _a.value;
|
|
3644
|
+
if (typeof numValue !== 'number') {
|
|
3645
|
+
throw new Error('Expected a number for take(num)');
|
|
3646
|
+
}
|
|
3647
|
+
if (numValue >= input.length) {
|
|
3648
|
+
return input;
|
|
3649
|
+
}
|
|
3650
|
+
if (numValue <= 0) {
|
|
3651
|
+
return [];
|
|
3652
|
+
}
|
|
3653
|
+
return input.slice(0, numValue);
|
|
3654
|
+
},
|
|
3655
|
+
/**
|
|
3656
|
+
* Returns the set of elements that are in both collections.
|
|
3657
|
+
* Duplicate items will be eliminated by this function.
|
|
3658
|
+
* Order of items is not guaranteed to be preserved in the result of this function.
|
|
3659
|
+
*
|
|
3660
|
+
* See: http://hl7.org/fhirpath/#intersectother-collection-collection
|
|
3661
|
+
*/
|
|
3662
|
+
intersect: (input, other) => {
|
|
3663
|
+
if (!other) {
|
|
3664
|
+
return input;
|
|
3665
|
+
}
|
|
3666
|
+
const otherArray = other.eval([]);
|
|
3667
|
+
const result = [];
|
|
3668
|
+
for (const value of input) {
|
|
3669
|
+
if (!result.some((e) => e.value === value.value) && otherArray.some((e) => e.value === value.value)) {
|
|
3670
|
+
result.push(value);
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
return result;
|
|
3674
|
+
},
|
|
3675
|
+
/**
|
|
3676
|
+
* Returns the set of elements that are not in the other collection.
|
|
3677
|
+
* Duplicate items will not be eliminated by this function, and order will be preserved.
|
|
3678
|
+
*
|
|
3679
|
+
* e.g. (1 | 2 | 3).exclude(2) returns (1 | 3).
|
|
3680
|
+
*
|
|
3681
|
+
* See: http://hl7.org/fhirpath/#excludeother-collection-collection
|
|
3682
|
+
*/
|
|
3683
|
+
exclude: (input, other) => {
|
|
3684
|
+
if (!other) {
|
|
3685
|
+
return input;
|
|
3686
|
+
}
|
|
3687
|
+
const otherArray = other.eval([]);
|
|
3688
|
+
const result = [];
|
|
3689
|
+
for (const value of input) {
|
|
3690
|
+
if (!otherArray.some((e) => e.value === value.value)) {
|
|
3691
|
+
result.push(value);
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
return result;
|
|
3695
|
+
},
|
|
3696
|
+
/*
|
|
3697
|
+
* 5.4. Combining
|
|
3698
|
+
*
|
|
3699
|
+
* See: https://hl7.org/fhirpath/#combining
|
|
3700
|
+
*/
|
|
3701
|
+
/**
|
|
3702
|
+
* Merge the two collections into a single collection,
|
|
3703
|
+
* eliminating unknown duplicate values (using = (Equals) (=) to determine equality).
|
|
3704
|
+
* There is no expectation of order in the resulting collection.
|
|
3705
|
+
*
|
|
3706
|
+
* In other words, this function returns the distinct list of elements from both inputs.
|
|
3707
|
+
*
|
|
3708
|
+
* See: http://hl7.org/fhirpath/#unionother-collection
|
|
3709
|
+
*/
|
|
3710
|
+
union: (input, other) => {
|
|
3711
|
+
if (!other) {
|
|
3712
|
+
return input;
|
|
3713
|
+
}
|
|
3714
|
+
const otherArray = other.eval([]);
|
|
3715
|
+
return removeDuplicates([...input, ...otherArray]);
|
|
3716
|
+
},
|
|
3717
|
+
/**
|
|
3718
|
+
* Merge the input and other collections into a single collection
|
|
3719
|
+
* without eliminating duplicate values. Combining an empty collection
|
|
3720
|
+
* with a non-empty collection will return the non-empty collection.
|
|
3721
|
+
*
|
|
3722
|
+
* There is no expectation of order in the resulting collection.
|
|
3723
|
+
*
|
|
3724
|
+
* See: http://hl7.org/fhirpath/#combineother-collection-collection
|
|
3725
|
+
*/
|
|
3726
|
+
combine: (input, other) => {
|
|
3727
|
+
if (!other) {
|
|
3728
|
+
return input;
|
|
3729
|
+
}
|
|
3730
|
+
const otherArray = other.eval([]);
|
|
3731
|
+
return [...input, ...otherArray];
|
|
3732
|
+
},
|
|
3733
|
+
/*
|
|
3734
|
+
* 5.5. Conversion
|
|
3735
|
+
*
|
|
3736
|
+
* See: https://hl7.org/fhirpath/#conversion
|
|
3737
|
+
*/
|
|
3738
|
+
/**
|
|
3739
|
+
* The iif function in FHIRPath is an immediate if,
|
|
3740
|
+
* also known as a conditional operator (such as C’s ? : operator).
|
|
3741
|
+
*
|
|
3742
|
+
* The criterion expression is expected to evaluate to a Boolean.
|
|
3743
|
+
*
|
|
3744
|
+
* If criterion is true, the function returns the value of the true-result argument.
|
|
3745
|
+
*
|
|
3746
|
+
* If criterion is false or an empty collection, the function returns otherwise-result,
|
|
3747
|
+
* unless the optional otherwise-result is not given, in which case the function returns an empty collection.
|
|
3748
|
+
*
|
|
3749
|
+
* Note that short-circuit behavior is expected in this function. In other words,
|
|
3750
|
+
* true-result should only be evaluated if the criterion evaluates to true,
|
|
3751
|
+
* and otherwise-result should only be evaluated otherwise. For implementations,
|
|
3752
|
+
* this means delaying evaluation of the arguments.
|
|
3753
|
+
*
|
|
3754
|
+
* @param input
|
|
3755
|
+
* @param criterion
|
|
3756
|
+
* @param trueResult
|
|
3757
|
+
* @param otherwiseResult
|
|
3758
|
+
* @returns
|
|
3759
|
+
*/
|
|
3760
|
+
iif: (input, criterion, trueResult, otherwiseResult) => {
|
|
3761
|
+
const evalResult = criterion.eval(input);
|
|
3762
|
+
if (evalResult.length > 1 || (evalResult.length === 1 && typeof evalResult[0].value !== 'boolean')) {
|
|
3763
|
+
throw new Error('Expected criterion to evaluate to a Boolean');
|
|
3764
|
+
}
|
|
3765
|
+
if (toJsBoolean(evalResult)) {
|
|
3766
|
+
return trueResult.eval(input);
|
|
3767
|
+
}
|
|
3768
|
+
if (otherwiseResult) {
|
|
3769
|
+
return otherwiseResult.eval(input);
|
|
3770
|
+
}
|
|
3771
|
+
return [];
|
|
3772
|
+
},
|
|
3773
|
+
/**
|
|
3774
|
+
* Converts an input collection to a boolean.
|
|
3775
|
+
*
|
|
3776
|
+
* If the input collection contains a single item, this function will return a single boolean if:
|
|
3777
|
+
* 1) the item is a Boolean
|
|
3778
|
+
* 2) the item is an Integer and is equal to one of the possible integer representations of Boolean values
|
|
3779
|
+
* 3) the item is a Decimal that is equal to one of the possible decimal representations of Boolean values
|
|
3780
|
+
* 4) the item is a String that is equal to one of the possible string representations of Boolean values
|
|
3781
|
+
*
|
|
3782
|
+
* If the item is not one the above types, or the item is a String, Integer, or Decimal, but is not equal to one of the possible values convertible to a Boolean, the result is empty.
|
|
3783
|
+
*
|
|
3784
|
+
* See: https://hl7.org/fhirpath/#toboolean-boolean
|
|
3785
|
+
*
|
|
3786
|
+
* @param input
|
|
3787
|
+
* @returns
|
|
3788
|
+
*/
|
|
3789
|
+
toBoolean: (input) => {
|
|
3790
|
+
if (input.length === 0) {
|
|
3791
|
+
return [];
|
|
3792
|
+
}
|
|
3793
|
+
const [{ value }] = validateInput(input, 1);
|
|
3794
|
+
if (typeof value === 'boolean') {
|
|
3795
|
+
return [{ type: PropertyType.boolean, value }];
|
|
3796
|
+
}
|
|
3797
|
+
if (typeof value === 'number') {
|
|
3798
|
+
if (value === 0 || value === 1) {
|
|
3799
|
+
return booleanToTypedValue(!!value);
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
if (typeof value === 'string') {
|
|
3803
|
+
const lowerStr = value.toLowerCase();
|
|
3804
|
+
if (['true', 't', 'yes', 'y', '1', '1.0'].includes(lowerStr)) {
|
|
3805
|
+
return booleanToTypedValue(true);
|
|
3806
|
+
}
|
|
3807
|
+
if (['false', 'f', 'no', 'n', '0', '0.0'].includes(lowerStr)) {
|
|
3808
|
+
return booleanToTypedValue(false);
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
return [];
|
|
3812
|
+
},
|
|
3813
|
+
/**
|
|
3814
|
+
* If the input collection contains a single item, this function will return true if:
|
|
3815
|
+
* 1) the item is a Boolean
|
|
3816
|
+
* 2) the item is an Integer that is equal to one of the possible integer representations of Boolean values
|
|
3817
|
+
* 3) the item is a Decimal that is equal to one of the possible decimal representations of Boolean values
|
|
3818
|
+
* 4) the item is a String that is equal to one of the possible string representations of Boolean values
|
|
3819
|
+
*
|
|
3820
|
+
* If the item is not one of the above types, or the item is a String, Integer, or Decimal, but is not equal to one of the possible values convertible to a Boolean, the result is false.
|
|
3821
|
+
*
|
|
3822
|
+
* Possible values for Integer, Decimal, and String are described in the toBoolean() function.
|
|
3823
|
+
*
|
|
3824
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
3825
|
+
*
|
|
3826
|
+
* If the input collection is empty, the result is empty.
|
|
3827
|
+
*
|
|
3828
|
+
* See: http://hl7.org/fhirpath/#convertstoboolean-boolean
|
|
3829
|
+
*
|
|
3830
|
+
* @param input
|
|
3831
|
+
* @returns
|
|
3832
|
+
*/
|
|
3833
|
+
convertsToBoolean: (input) => {
|
|
3834
|
+
if (input.length === 0) {
|
|
3835
|
+
return [];
|
|
3836
|
+
}
|
|
3837
|
+
return booleanToTypedValue(functions.toBoolean(input).length === 1);
|
|
3838
|
+
},
|
|
3839
|
+
/**
|
|
3840
|
+
* Returns the integer representation of the input.
|
|
3841
|
+
*
|
|
3842
|
+
* If the input collection contains a single item, this function will return a single integer if:
|
|
3843
|
+
* 1) the item is an Integer
|
|
3844
|
+
* 2) the item is a String and is convertible to an integer
|
|
3845
|
+
* 3) the item is a Boolean, where true results in a 1 and false results in a 0.
|
|
3846
|
+
*
|
|
3847
|
+
* If the item is not one the above types, the result is empty.
|
|
3848
|
+
*
|
|
3849
|
+
* If the item is a String, but the string is not convertible to an integer (using the regex format (\\+|-)?\d+), the result is empty.
|
|
3850
|
+
*
|
|
3851
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
3852
|
+
*
|
|
3853
|
+
* If the input collection is empty, the result is empty.
|
|
3854
|
+
*
|
|
3855
|
+
* See: https://hl7.org/fhirpath/#tointeger-integer
|
|
3856
|
+
*
|
|
3857
|
+
* @param input The input collection.
|
|
3858
|
+
* @returns The string representation of the input.
|
|
3859
|
+
*/
|
|
3860
|
+
toInteger: (input) => {
|
|
3861
|
+
if (input.length === 0) {
|
|
3862
|
+
return [];
|
|
3863
|
+
}
|
|
3864
|
+
const [{ value }] = validateInput(input, 1);
|
|
3865
|
+
if (typeof value === 'number') {
|
|
3866
|
+
return [{ type: PropertyType.integer, value }];
|
|
3867
|
+
}
|
|
3868
|
+
if (typeof value === 'string' && value.match(/^[+-]?\d+$/)) {
|
|
3869
|
+
return [{ type: PropertyType.integer, value: parseInt(value, 10) }];
|
|
3870
|
+
}
|
|
3871
|
+
if (typeof value === 'boolean') {
|
|
3872
|
+
return [{ type: PropertyType.integer, value: value ? 1 : 0 }];
|
|
3873
|
+
}
|
|
3874
|
+
return [];
|
|
3875
|
+
},
|
|
3876
|
+
/**
|
|
3877
|
+
* Returns true if the input can be converted to string.
|
|
3878
|
+
*
|
|
3879
|
+
* If the input collection contains a single item, this function will return true if:
|
|
3880
|
+
* 1) the item is an Integer
|
|
3881
|
+
* 2) the item is a String and is convertible to an Integer
|
|
3882
|
+
* 3) the item is a Boolean
|
|
3883
|
+
* 4) If the item is not one of the above types, or the item is a String, but is not convertible to an Integer (using the regex format (\\+|-)?\d+), the result is false.
|
|
3884
|
+
*
|
|
3885
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
3886
|
+
*
|
|
3887
|
+
* If the input collection is empty, the result is empty.
|
|
3888
|
+
*
|
|
3889
|
+
* See: https://hl7.org/fhirpath/#convertstointeger-boolean
|
|
3890
|
+
*
|
|
3891
|
+
* @param input The input collection.
|
|
3892
|
+
* @returns
|
|
3893
|
+
*/
|
|
3894
|
+
convertsToInteger: (input) => {
|
|
3895
|
+
if (input.length === 0) {
|
|
3896
|
+
return [];
|
|
3897
|
+
}
|
|
3898
|
+
return booleanToTypedValue(functions.toInteger(input).length === 1);
|
|
3899
|
+
},
|
|
3900
|
+
/**
|
|
3901
|
+
* If the input collection contains a single item, this function will return a single date if:
|
|
3902
|
+
* 1) the item is a Date
|
|
3903
|
+
* 2) the item is a DateTime
|
|
3904
|
+
* 3) the item is a String and is convertible to a Date
|
|
3905
|
+
*
|
|
3906
|
+
* If the item is not one of the above types, the result is empty.
|
|
3907
|
+
*
|
|
3908
|
+
* If the item is a String, but the string is not convertible to a Date (using the format YYYY-MM-DD), the result is empty.
|
|
3909
|
+
*
|
|
3910
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
3911
|
+
*
|
|
3912
|
+
* If the input collection is empty, the result is empty.
|
|
3913
|
+
*
|
|
3914
|
+
* See: https://hl7.org/fhirpath/#todate-date
|
|
3915
|
+
*/
|
|
3916
|
+
toDate: (input) => {
|
|
3917
|
+
if (input.length === 0) {
|
|
3918
|
+
return [];
|
|
3919
|
+
}
|
|
3920
|
+
const [{ value }] = validateInput(input, 1);
|
|
3921
|
+
if (typeof value === 'string' && value.match(/^\d{4}(-\d{2}(-\d{2})?)?/)) {
|
|
3922
|
+
return [{ type: PropertyType.date, value: parseDateString(value) }];
|
|
3923
|
+
}
|
|
3924
|
+
return [];
|
|
3925
|
+
},
|
|
3926
|
+
/**
|
|
3927
|
+
* If the input collection contains a single item, this function will return true if:
|
|
3928
|
+
* 1) the item is a Date
|
|
3929
|
+
* 2) the item is a DateTime
|
|
3930
|
+
* 3) the item is a String and is convertible to a Date
|
|
3931
|
+
*
|
|
3932
|
+
* If the item is not one of the above types, or is not convertible to a Date (using the format YYYY-MM-DD), the result is false.
|
|
3933
|
+
*
|
|
3934
|
+
* If the item contains a partial date (e.g. '2012-01'), the result is a partial date.
|
|
3935
|
+
*
|
|
3936
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
3937
|
+
*
|
|
3938
|
+
* If the input collection is empty, the result is empty.
|
|
3939
|
+
*
|
|
3940
|
+
* See: https://hl7.org/fhirpath/#convertstodate-boolean
|
|
3941
|
+
*/
|
|
3942
|
+
convertsToDate: (input) => {
|
|
3943
|
+
if (input.length === 0) {
|
|
3944
|
+
return [];
|
|
3945
|
+
}
|
|
3946
|
+
return booleanToTypedValue(functions.toDate(input).length === 1);
|
|
3947
|
+
},
|
|
3948
|
+
/**
|
|
3949
|
+
* If the input collection contains a single item, this function will return a single datetime if:
|
|
3950
|
+
* 1) the item is a DateTime
|
|
3951
|
+
* 2) the item is a Date, in which case the result is a DateTime with the year, month, and day of the Date, and the time components empty (not set to zero)
|
|
3952
|
+
* 3) the item is a String and is convertible to a DateTime
|
|
3953
|
+
*
|
|
3954
|
+
* If the item is not one of the above types, the result is empty.
|
|
3955
|
+
*
|
|
3956
|
+
* If the item is a String, but the string is not convertible to a DateTime (using the format YYYY-MM-DDThh:mm:ss.fff(+|-)hh:mm), the result is empty.
|
|
3957
|
+
*
|
|
3958
|
+
* If the item contains a partial datetime (e.g. '2012-01-01T10:00'), the result is a partial datetime.
|
|
3959
|
+
*
|
|
3960
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
3961
|
+
*
|
|
3962
|
+
* If the input collection is empty, the result is empty.
|
|
3963
|
+
|
|
3964
|
+
* See: https://hl7.org/fhirpath/#todatetime-datetime
|
|
3965
|
+
*
|
|
3966
|
+
* @param input
|
|
3967
|
+
* @returns
|
|
3968
|
+
*/
|
|
3969
|
+
toDateTime: (input) => {
|
|
3970
|
+
if (input.length === 0) {
|
|
3971
|
+
return [];
|
|
3972
|
+
}
|
|
3973
|
+
const [{ value }] = validateInput(input, 1);
|
|
3974
|
+
if (typeof value === 'string' && value.match(/^\d{4}(-\d{2}(-\d{2})?)?/)) {
|
|
3975
|
+
return [{ type: PropertyType.dateTime, value: parseDateString(value) }];
|
|
3976
|
+
}
|
|
3977
|
+
return [];
|
|
3978
|
+
},
|
|
3979
|
+
/**
|
|
3980
|
+
* If the input collection contains a single item, this function will return true if:
|
|
3981
|
+
* 1) the item is a DateTime
|
|
3982
|
+
* 2) the item is a Date
|
|
3983
|
+
* 3) the item is a String and is convertible to a DateTime
|
|
3984
|
+
*
|
|
3985
|
+
* If the item is not one of the above types, or is not convertible to a DateTime (using the format YYYY-MM-DDThh:mm:ss.fff(+|-)hh:mm), the result is false.
|
|
3986
|
+
*
|
|
3987
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
3988
|
+
*
|
|
3989
|
+
* If the input collection is empty, the result is empty.
|
|
3990
|
+
*
|
|
3991
|
+
* See: https://hl7.org/fhirpath/#convertstodatetime-boolean
|
|
3992
|
+
*
|
|
3993
|
+
* @param input
|
|
3994
|
+
* @returns
|
|
3995
|
+
*/
|
|
3996
|
+
convertsToDateTime: (input) => {
|
|
3997
|
+
if (input.length === 0) {
|
|
3998
|
+
return [];
|
|
3999
|
+
}
|
|
4000
|
+
return booleanToTypedValue(functions.toDateTime(input).length === 1);
|
|
4001
|
+
},
|
|
4002
|
+
/**
|
|
4003
|
+
* If the input collection contains a single item, this function will return a single decimal if:
|
|
4004
|
+
* 1) the item is an Integer or Decimal
|
|
4005
|
+
* 2) the item is a String and is convertible to a Decimal
|
|
4006
|
+
* 3) the item is a Boolean, where true results in a 1.0 and false results in a 0.0.
|
|
4007
|
+
* 4) If the item is not one of the above types, the result is empty.
|
|
4008
|
+
*
|
|
4009
|
+
* If the item is a String, but the string is not convertible to a Decimal (using the regex format (\\+|-)?\d+(\.\d+)?), the result is empty.
|
|
4010
|
+
*
|
|
4011
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4012
|
+
*
|
|
4013
|
+
* If the input collection is empty, the result is empty.
|
|
4014
|
+
*
|
|
4015
|
+
* See: https://hl7.org/fhirpath/#decimal-conversion-functions
|
|
4016
|
+
*
|
|
4017
|
+
* @param input The input collection.
|
|
4018
|
+
* @returns
|
|
4019
|
+
*/
|
|
4020
|
+
toDecimal: (input) => {
|
|
4021
|
+
if (input.length === 0) {
|
|
4022
|
+
return [];
|
|
4023
|
+
}
|
|
4024
|
+
const [{ value }] = validateInput(input, 1);
|
|
4025
|
+
if (typeof value === 'number') {
|
|
4026
|
+
return [{ type: PropertyType.decimal, value }];
|
|
4027
|
+
}
|
|
4028
|
+
if (typeof value === 'string' && value.match(/^-?\d{1,9}(\.\d{1,9})?$/)) {
|
|
4029
|
+
return [{ type: PropertyType.decimal, value: parseFloat(value) }];
|
|
4030
|
+
}
|
|
4031
|
+
if (typeof value === 'boolean') {
|
|
4032
|
+
return [{ type: PropertyType.decimal, value: value ? 1 : 0 }];
|
|
4033
|
+
}
|
|
4034
|
+
return [];
|
|
4035
|
+
},
|
|
4036
|
+
/**
|
|
4037
|
+
* If the input collection contains a single item, this function will true if:
|
|
4038
|
+
* 1) the item is an Integer or Decimal
|
|
4039
|
+
* 2) the item is a String and is convertible to a Decimal
|
|
4040
|
+
* 3) the item is a Boolean
|
|
4041
|
+
*
|
|
4042
|
+
* If the item is not one of the above types, or is not convertible to a Decimal (using the regex format (\\+|-)?\d+(\.\d+)?), the result is false.
|
|
4043
|
+
*
|
|
4044
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4045
|
+
*
|
|
4046
|
+
* If the input collection is empty, the result is empty.
|
|
4047
|
+
|
|
4048
|
+
* See: https://hl7.org/fhirpath/#convertstodecimal-boolean
|
|
4049
|
+
*
|
|
4050
|
+
* @param input The input collection.
|
|
4051
|
+
* @returns
|
|
4052
|
+
*/
|
|
4053
|
+
convertsToDecimal: (input) => {
|
|
4054
|
+
if (input.length === 0) {
|
|
4055
|
+
return [];
|
|
4056
|
+
}
|
|
4057
|
+
return booleanToTypedValue(functions.toDecimal(input).length === 1);
|
|
4058
|
+
},
|
|
4059
|
+
/**
|
|
4060
|
+
* If the input collection contains a single item, this function will return a single quantity if:
|
|
4061
|
+
* 1) the item is an Integer, or Decimal, where the resulting quantity will have the default unit ('1')
|
|
4062
|
+
* 2) the item is a Quantity
|
|
4063
|
+
* 3) the item is a String and is convertible to a Quantity
|
|
4064
|
+
* 4) the item is a Boolean, where true results in the quantity 1.0 '1', and false results in the quantity 0.0 '1'
|
|
4065
|
+
*
|
|
4066
|
+
* If the item is not one of the above types, the result is empty.
|
|
4067
|
+
*
|
|
4068
|
+
* See: https://hl7.org/fhirpath/#quantity-conversion-functions
|
|
4069
|
+
*
|
|
4070
|
+
* @param input The input collection.
|
|
4071
|
+
* @returns
|
|
4072
|
+
*/
|
|
4073
|
+
toQuantity: (input) => {
|
|
4074
|
+
if (input.length === 0) {
|
|
4075
|
+
return [];
|
|
4076
|
+
}
|
|
4077
|
+
const [{ value }] = validateInput(input, 1);
|
|
4078
|
+
if (isQuantity(value)) {
|
|
4079
|
+
return [{ type: PropertyType.Quantity, value }];
|
|
4080
|
+
}
|
|
4081
|
+
if (typeof value === 'number') {
|
|
4082
|
+
return [{ type: PropertyType.Quantity, value: { value, unit: '1' } }];
|
|
4083
|
+
}
|
|
4084
|
+
if (typeof value === 'string' && value.match(/^-?\d{1,9}(\.\d{1,9})?/)) {
|
|
4085
|
+
return [{ type: PropertyType.Quantity, value: { value: parseFloat(value), unit: '1' } }];
|
|
4086
|
+
}
|
|
4087
|
+
if (typeof value === 'boolean') {
|
|
4088
|
+
return [{ type: PropertyType.Quantity, value: { value: value ? 1 : 0, unit: '1' } }];
|
|
4089
|
+
}
|
|
4090
|
+
return [];
|
|
4091
|
+
},
|
|
4092
|
+
/**
|
|
4093
|
+
* If the input collection contains a single item, this function will return true if:
|
|
4094
|
+
* 1) the item is an Integer, Decimal, or Quantity
|
|
4095
|
+
* 2) the item is a String that is convertible to a Quantity
|
|
4096
|
+
* 3) the item is a Boolean
|
|
4097
|
+
*
|
|
4098
|
+
* If the item is not one of the above types, or is not convertible to a Quantity using the following regex format:
|
|
4099
|
+
*
|
|
4100
|
+
* (?'value'(\+|-)?\d+(\.\d+)?)\s*('(?'unit'[^']+)'|(?'time'[a-zA-Z]+))?
|
|
4101
|
+
*
|
|
4102
|
+
* then the result is false.
|
|
4103
|
+
*
|
|
4104
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4105
|
+
*
|
|
4106
|
+
* If the input collection is empty, the result is empty.
|
|
4107
|
+
*
|
|
4108
|
+
* If the unit argument is provided, it must be the string representation of a UCUM code (or a FHIRPath calendar duration keyword), and is used to determine whether the input quantity can be converted to the given unit, according to the unit conversion rules specified by UCUM. If the input quantity can be converted, the result is true, otherwise, the result is false.
|
|
4109
|
+
*
|
|
4110
|
+
* See: https://hl7.org/fhirpath/#convertstoquantityunit-string-boolean
|
|
4111
|
+
*
|
|
4112
|
+
* @param input The input collection.
|
|
4113
|
+
* @returns
|
|
4114
|
+
*/
|
|
4115
|
+
convertsToQuantity: (input) => {
|
|
4116
|
+
if (input.length === 0) {
|
|
4117
|
+
return [];
|
|
4118
|
+
}
|
|
4119
|
+
return booleanToTypedValue(functions.toQuantity(input).length === 1);
|
|
4120
|
+
},
|
|
4121
|
+
/**
|
|
4122
|
+
* Returns the string representation of the input.
|
|
4123
|
+
*
|
|
4124
|
+
* If the input collection contains a single item, this function will return a single String if:
|
|
4125
|
+
*
|
|
4126
|
+
* 1) the item in the input collection is a String
|
|
4127
|
+
* 2) the item in the input collection is an Integer, Decimal, Date, Time, DateTime, or Quantity the output will contain its String representation
|
|
4128
|
+
* 3) the item is a Boolean, where true results in 'true' and false in 'false'.
|
|
4129
|
+
*
|
|
4130
|
+
* If the item is not one of the above types, the result is false.
|
|
4131
|
+
*
|
|
4132
|
+
* See: https://hl7.org/fhirpath/#tostring-string
|
|
4133
|
+
*
|
|
4134
|
+
* @param input The input collection.
|
|
4135
|
+
* @returns The string representation of the input.
|
|
4136
|
+
*/
|
|
4137
|
+
toString: (input) => {
|
|
4138
|
+
if (input.length === 0) {
|
|
4139
|
+
return [];
|
|
4140
|
+
}
|
|
4141
|
+
const [{ value }] = validateInput(input, 1);
|
|
4142
|
+
if (value === null || value === undefined) {
|
|
4143
|
+
return [];
|
|
4144
|
+
}
|
|
4145
|
+
if (isQuantity(value)) {
|
|
4146
|
+
return [{ type: PropertyType.string, value: `${value.value} '${value.unit}'` }];
|
|
4147
|
+
}
|
|
4148
|
+
return [{ type: PropertyType.string, value: value.toString() }];
|
|
4149
|
+
},
|
|
4150
|
+
/**
|
|
4151
|
+
* Returns true if the input can be converted to string.
|
|
4152
|
+
*
|
|
4153
|
+
* If the input collection contains a single item, this function will return true if:
|
|
4154
|
+
* 1) the item is a String
|
|
4155
|
+
* 2) the item is an Integer, Decimal, Date, Time, or DateTime
|
|
4156
|
+
* 3) the item is a Boolean
|
|
4157
|
+
* 4) the item is a Quantity
|
|
4158
|
+
*
|
|
4159
|
+
* If the item is not one of the above types, the result is false.
|
|
4160
|
+
*
|
|
4161
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4162
|
+
*
|
|
4163
|
+
* If the input collection is empty, the result is empty.
|
|
4164
|
+
*
|
|
4165
|
+
* See: https://hl7.org/fhirpath/#tostring-string
|
|
4166
|
+
*
|
|
4167
|
+
* @param input The input collection.
|
|
4168
|
+
* @returns
|
|
4169
|
+
*/
|
|
4170
|
+
convertsToString: (input) => {
|
|
4171
|
+
if (input.length === 0) {
|
|
4172
|
+
return [];
|
|
4173
|
+
}
|
|
4174
|
+
return booleanToTypedValue(functions.toString(input).length === 1);
|
|
4175
|
+
},
|
|
4176
|
+
/**
|
|
4177
|
+
* If the input collection contains a single item, this function will return a single time if:
|
|
4178
|
+
* 1) the item is a Time
|
|
4179
|
+
* 2) the item is a String and is convertible to a Time
|
|
4180
|
+
*
|
|
4181
|
+
* If the item is not one of the above types, the result is empty.
|
|
4182
|
+
*
|
|
4183
|
+
* If the item is a String, but the string is not convertible to a Time (using the format hh:mm:ss.fff(+|-)hh:mm), the result is empty.
|
|
4184
|
+
*
|
|
4185
|
+
* If the item contains a partial time (e.g. '10:00'), the result is a partial time.
|
|
4186
|
+
*
|
|
4187
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4188
|
+
*
|
|
4189
|
+
* If the input collection is empty, the result is empty.
|
|
4190
|
+
*
|
|
4191
|
+
* See: https://hl7.org/fhirpath/#totime-time
|
|
4192
|
+
*
|
|
4193
|
+
* @param input
|
|
4194
|
+
* @returns
|
|
4195
|
+
*/
|
|
4196
|
+
toTime: (input) => {
|
|
4197
|
+
if (input.length === 0) {
|
|
4198
|
+
return [];
|
|
4199
|
+
}
|
|
4200
|
+
const [{ value }] = validateInput(input, 1);
|
|
4201
|
+
if (typeof value === 'string') {
|
|
4202
|
+
const match = value.match(/^T?(\d{2}(:\d{2}(:\d{2})?)?)/);
|
|
4203
|
+
if (match) {
|
|
4204
|
+
return [{ type: PropertyType.time, value: parseDateString('T' + match[1]) }];
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
return [];
|
|
4208
|
+
},
|
|
4209
|
+
/**
|
|
4210
|
+
* If the input collection contains a single item, this function will return true if:
|
|
4211
|
+
* 1) the item is a Time
|
|
4212
|
+
* 2) the item is a String and is convertible to a Time
|
|
4213
|
+
*
|
|
4214
|
+
* If the item is not one of the above types, or is not convertible to a Time (using the format hh:mm:ss.fff(+|-)hh:mm), the result is false.
|
|
4215
|
+
*
|
|
4216
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4217
|
+
*
|
|
4218
|
+
* If the input collection is empty, the result is empty.
|
|
4219
|
+
*
|
|
4220
|
+
* See: https://hl7.org/fhirpath/#convertstotime-boolean
|
|
4221
|
+
*
|
|
4222
|
+
* @param input
|
|
4223
|
+
* @returns
|
|
4224
|
+
*/
|
|
4225
|
+
convertsToTime: (input) => {
|
|
4226
|
+
if (input.length === 0) {
|
|
4227
|
+
return [];
|
|
4228
|
+
}
|
|
4229
|
+
return booleanToTypedValue(functions.toTime(input).length === 1);
|
|
4230
|
+
},
|
|
4231
|
+
/*
|
|
4232
|
+
* 5.6. String Manipulation.
|
|
4233
|
+
*
|
|
4234
|
+
* See: https://hl7.org/fhirpath/#string-manipulation
|
|
4235
|
+
*/
|
|
4236
|
+
/**
|
|
4237
|
+
* Returns the 0-based index of the first position substring is found in the input string, or -1 if it is not found.
|
|
4238
|
+
*
|
|
4239
|
+
* If substring is an empty string (''), the function returns 0.
|
|
4240
|
+
*
|
|
4241
|
+
* If the input or substring is empty ({ }), the result is empty ({ }).
|
|
4242
|
+
*
|
|
4243
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4244
|
+
*
|
|
4245
|
+
* See: https://hl7.org/fhirpath/#indexofsubstring-string-integer
|
|
4246
|
+
*
|
|
4247
|
+
* @param input The input collection.
|
|
4248
|
+
* @returns The index of the substring.
|
|
4249
|
+
*/
|
|
4250
|
+
indexOf: (input, substringAtom) => {
|
|
4251
|
+
return applyStringFunc((str, substring) => str.indexOf(substring), input, substringAtom);
|
|
4252
|
+
},
|
|
4253
|
+
/**
|
|
4254
|
+
* Returns the part of the string starting at position start (zero-based). If length is given, will return at most length number of characters from the input string.
|
|
4255
|
+
*
|
|
4256
|
+
* If start lies outside the length of the string, the function returns empty ({ }). If there are less remaining characters in the string than indicated by length, the function returns just the remaining characters.
|
|
4257
|
+
*
|
|
4258
|
+
* If the input or start is empty, the result is empty.
|
|
4259
|
+
*
|
|
4260
|
+
* If an empty length is provided, the behavior is the same as if length had not been provided.
|
|
4261
|
+
*
|
|
4262
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4263
|
+
*
|
|
4264
|
+
* @param input The input collection.
|
|
4265
|
+
* @returns The index of the substring.
|
|
4266
|
+
*/
|
|
4267
|
+
substring: (input, startAtom, lengthAtom) => {
|
|
4268
|
+
return applyStringFunc((str, start, length) => {
|
|
4269
|
+
const startIndex = start;
|
|
4270
|
+
const endIndex = length ? startIndex + length : str.length;
|
|
4271
|
+
return startIndex < 0 || startIndex >= str.length ? undefined : str.substring(startIndex, endIndex);
|
|
4272
|
+
}, input, startAtom, lengthAtom);
|
|
4273
|
+
},
|
|
4274
|
+
/**
|
|
4275
|
+
*
|
|
4276
|
+
* @param input The input collection.
|
|
4277
|
+
* @returns The index of the substring.
|
|
4278
|
+
*/
|
|
4279
|
+
startsWith: (input, prefixAtom) => {
|
|
4280
|
+
return applyStringFunc((str, prefix) => str.startsWith(prefix), input, prefixAtom);
|
|
4281
|
+
},
|
|
4282
|
+
/**
|
|
4283
|
+
*
|
|
4284
|
+
* @param input The input collection.
|
|
4285
|
+
* @returns The index of the substring.
|
|
4286
|
+
*/
|
|
4287
|
+
endsWith: (input, suffixAtom) => {
|
|
4288
|
+
return applyStringFunc((str, suffix) => str.endsWith(suffix), input, suffixAtom);
|
|
4289
|
+
},
|
|
4290
|
+
/**
|
|
4291
|
+
*
|
|
4292
|
+
* @param input The input collection.
|
|
4293
|
+
* @returns The index of the substring.
|
|
4294
|
+
*/
|
|
4295
|
+
contains: (input, substringAtom) => {
|
|
4296
|
+
return applyStringFunc((str, substring) => str.includes(substring), input, substringAtom);
|
|
4297
|
+
},
|
|
4298
|
+
/**
|
|
4299
|
+
*
|
|
4300
|
+
* @param input The input collection.
|
|
4301
|
+
* @returns The index of the substring.
|
|
4302
|
+
*/
|
|
4303
|
+
upper: (input) => {
|
|
4304
|
+
return applyStringFunc((str) => str.toUpperCase(), input);
|
|
4305
|
+
},
|
|
4306
|
+
/**
|
|
4307
|
+
*
|
|
4308
|
+
* @param input The input collection.
|
|
4309
|
+
* @returns The index of the substring.
|
|
4310
|
+
*/
|
|
4311
|
+
lower: (input) => {
|
|
4312
|
+
return applyStringFunc((str) => str.toLowerCase(), input);
|
|
4313
|
+
},
|
|
4314
|
+
/**
|
|
4315
|
+
*
|
|
4316
|
+
* @param input The input collection.
|
|
4317
|
+
* @returns The index of the substring.
|
|
4318
|
+
*/
|
|
4319
|
+
replace: (input, patternAtom, substitionAtom) => {
|
|
4320
|
+
return applyStringFunc((str, pattern, substition) => str.replaceAll(pattern, substition), input, patternAtom, substitionAtom);
|
|
4321
|
+
},
|
|
4322
|
+
/**
|
|
4323
|
+
*
|
|
4324
|
+
* @param input The input collection.
|
|
4325
|
+
* @returns The index of the substring.
|
|
4326
|
+
*/
|
|
4327
|
+
matches: (input, regexAtom) => {
|
|
4328
|
+
return applyStringFunc((str, regex) => !!str.match(regex), input, regexAtom);
|
|
4329
|
+
},
|
|
4330
|
+
/**
|
|
4331
|
+
*
|
|
4332
|
+
* @param input The input collection.
|
|
4333
|
+
* @returns The index of the substring.
|
|
4334
|
+
*/
|
|
4335
|
+
replaceMatches: (input, regexAtom, substitionAtom) => {
|
|
4336
|
+
return applyStringFunc((str, pattern, substition) => str.replaceAll(pattern, substition), input, regexAtom, substitionAtom);
|
|
4337
|
+
},
|
|
4338
|
+
/**
|
|
4339
|
+
*
|
|
4340
|
+
* @param input The input collection.
|
|
4341
|
+
* @returns The index of the substring.
|
|
4342
|
+
*/
|
|
4343
|
+
length: (input) => {
|
|
4344
|
+
return applyStringFunc((str) => str.length, input);
|
|
4345
|
+
},
|
|
4346
|
+
/**
|
|
4347
|
+
* Returns the list of characters in the input string. If the input collection is empty ({ }), the result is empty.
|
|
4348
|
+
*
|
|
4349
|
+
* See: https://hl7.org/fhirpath/#tochars-collection
|
|
4350
|
+
*
|
|
4351
|
+
* @param input The input collection.
|
|
4352
|
+
*/
|
|
4353
|
+
toChars: (input) => {
|
|
4354
|
+
return applyStringFunc((str) => (str ? str.split('') : undefined), input);
|
|
4355
|
+
},
|
|
4356
|
+
/*
|
|
4357
|
+
* 5.7. Math
|
|
4358
|
+
*/
|
|
4359
|
+
/**
|
|
4360
|
+
* Returns the absolute value of the input. When taking the absolute value of a quantity, the unit is unchanged.
|
|
4361
|
+
*
|
|
4362
|
+
* If the input collection is empty, the result is empty.
|
|
4363
|
+
*
|
|
4364
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4365
|
+
*
|
|
4366
|
+
* See: https://hl7.org/fhirpath/#abs-integer-decimal-quantity
|
|
4367
|
+
*
|
|
4368
|
+
* @param input The input collection.
|
|
4369
|
+
* @returns A collection containing the result.
|
|
4370
|
+
*/
|
|
4371
|
+
abs: (input) => {
|
|
4372
|
+
return applyMathFunc(Math.abs, input);
|
|
4373
|
+
},
|
|
4374
|
+
/**
|
|
4375
|
+
* Returns the first integer greater than or equal to the input.
|
|
4376
|
+
*
|
|
4377
|
+
* If the input collection is empty, the result is empty.
|
|
4378
|
+
*
|
|
4379
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4380
|
+
*
|
|
4381
|
+
* See: https://hl7.org/fhirpath/#ceiling-integer
|
|
4382
|
+
*
|
|
4383
|
+
* @param input The input collection.
|
|
4384
|
+
* @returns A collection containing the result.
|
|
4385
|
+
*/
|
|
4386
|
+
ceiling: (input) => {
|
|
4387
|
+
return applyMathFunc(Math.ceil, input);
|
|
4388
|
+
},
|
|
4389
|
+
/**
|
|
4390
|
+
* Returns e raised to the power of the input.
|
|
4391
|
+
*
|
|
4392
|
+
* If the input collection contains an Integer, it will be implicitly converted to a Decimal and the result will be a Decimal.
|
|
4393
|
+
*
|
|
4394
|
+
* If the input collection is empty, the result is empty.
|
|
4395
|
+
*
|
|
4396
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4397
|
+
*
|
|
4398
|
+
* See: https://hl7.org/fhirpath/#exp-decimal
|
|
4399
|
+
*
|
|
4400
|
+
* @param input The input collection.
|
|
4401
|
+
* @returns A collection containing the result.
|
|
4402
|
+
*/
|
|
4403
|
+
exp: (input) => {
|
|
4404
|
+
return applyMathFunc(Math.exp, input);
|
|
4405
|
+
},
|
|
4406
|
+
/**
|
|
4407
|
+
* Returns the first integer less than or equal to the input.
|
|
4408
|
+
*
|
|
4409
|
+
* If the input collection is empty, the result is empty.
|
|
4410
|
+
*
|
|
4411
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4412
|
+
*
|
|
4413
|
+
* See: https://hl7.org/fhirpath/#floor-integer
|
|
4414
|
+
*
|
|
4415
|
+
* @param input The input collection.
|
|
4416
|
+
* @returns A collection containing the result.
|
|
4417
|
+
*/
|
|
4418
|
+
floor: (input) => {
|
|
4419
|
+
return applyMathFunc(Math.floor, input);
|
|
4420
|
+
},
|
|
4421
|
+
/**
|
|
4422
|
+
* Returns the natural logarithm of the input (i.e. the logarithm base e).
|
|
4423
|
+
*
|
|
4424
|
+
* When used with an Integer, it will be implicitly converted to a Decimal.
|
|
4425
|
+
*
|
|
4426
|
+
* If the input collection is empty, the result is empty.
|
|
4427
|
+
*
|
|
4428
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4429
|
+
*
|
|
4430
|
+
* See: https://hl7.org/fhirpath/#ln-decimal
|
|
4431
|
+
*
|
|
4432
|
+
* @param input The input collection.
|
|
4433
|
+
* @returns A collection containing the result.
|
|
4434
|
+
*/
|
|
4435
|
+
ln: (input) => {
|
|
4436
|
+
return applyMathFunc(Math.log, input);
|
|
4437
|
+
},
|
|
4438
|
+
/**
|
|
4439
|
+
* Returns the logarithm base base of the input number.
|
|
4440
|
+
*
|
|
4441
|
+
* When used with Integers, the arguments will be implicitly converted to Decimal.
|
|
4442
|
+
*
|
|
4443
|
+
* If base is empty, the result is empty.
|
|
4444
|
+
*
|
|
4445
|
+
* If the input collection is empty, the result is empty.
|
|
4446
|
+
*
|
|
4447
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4448
|
+
*
|
|
4449
|
+
* See: https://hl7.org/fhirpath/#logbase-decimal-decimal
|
|
4450
|
+
*
|
|
4451
|
+
* @param input The input collection.
|
|
4452
|
+
* @returns A collection containing the result.
|
|
4453
|
+
*/
|
|
4454
|
+
log: (input, baseAtom) => {
|
|
4455
|
+
return applyMathFunc((value, base) => Math.log(value) / Math.log(base), input, baseAtom);
|
|
4456
|
+
},
|
|
4457
|
+
/**
|
|
4458
|
+
* Raises a number to the exponent power. If this function is used with Integers, the result is an Integer. If the function is used with Decimals, the result is a Decimal. If the function is used with a mixture of Integer and Decimal, the Integer is implicitly converted to a Decimal and the result is a Decimal.
|
|
4459
|
+
*
|
|
4460
|
+
* If the power cannot be represented (such as the -1 raised to the 0.5), the result is empty.
|
|
4461
|
+
*
|
|
4462
|
+
* If the input is empty, or exponent is empty, the result is empty.
|
|
4463
|
+
*
|
|
4464
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4465
|
+
*
|
|
4466
|
+
* See: https://hl7.org/fhirpath/#powerexponent-integer-decimal-integer-decimal
|
|
4467
|
+
*
|
|
4468
|
+
* @param input The input collection.
|
|
4469
|
+
* @returns A collection containing the result.
|
|
4470
|
+
*/
|
|
4471
|
+
power: (input, expAtom) => {
|
|
4472
|
+
return applyMathFunc(Math.pow, input, expAtom);
|
|
4473
|
+
},
|
|
4474
|
+
/**
|
|
4475
|
+
* Rounds the decimal to the nearest whole number using a traditional round (i.e. 0.5 or higher will round to 1). If specified, the precision argument determines the decimal place at which the rounding will occur. If not specified, the rounding will default to 0 decimal places.
|
|
4476
|
+
*
|
|
4477
|
+
* If specified, the number of digits of precision must be >= 0 or the evaluation will end and signal an error to the calling environment.
|
|
4478
|
+
*
|
|
4479
|
+
* If the input collection contains a single item of type Integer, it will be implicitly converted to a Decimal.
|
|
4480
|
+
*
|
|
4481
|
+
* If the input collection is empty, the result is empty.
|
|
4482
|
+
*
|
|
4483
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4484
|
+
*
|
|
4485
|
+
* See: https://hl7.org/fhirpath/#roundprecision-integer-decimal
|
|
4486
|
+
*
|
|
4487
|
+
* @param input The input collection.
|
|
4488
|
+
* @returns A collection containing the result.
|
|
4489
|
+
*/
|
|
4490
|
+
round: (input) => {
|
|
4491
|
+
return applyMathFunc(Math.round, input);
|
|
4492
|
+
},
|
|
4493
|
+
/**
|
|
4494
|
+
* Returns the square root of the input number as a Decimal.
|
|
4495
|
+
*
|
|
4496
|
+
* If the square root cannot be represented (such as the square root of -1), the result is empty.
|
|
4497
|
+
*
|
|
4498
|
+
* If the input collection is empty, the result is empty.
|
|
4499
|
+
*
|
|
4500
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4501
|
+
*
|
|
4502
|
+
* Note that this function is equivalent to raising a number of the power of 0.5 using the power() function.
|
|
4503
|
+
*
|
|
4504
|
+
* See: https://hl7.org/fhirpath/#sqrt-decimal
|
|
4505
|
+
*
|
|
4506
|
+
* @param input The input collection.
|
|
4507
|
+
* @returns A collection containing the result.
|
|
4508
|
+
*/
|
|
4509
|
+
sqrt: (input) => {
|
|
4510
|
+
return applyMathFunc(Math.sqrt, input);
|
|
4511
|
+
},
|
|
4512
|
+
/**
|
|
4513
|
+
* Returns the integer portion of the input.
|
|
4514
|
+
*
|
|
4515
|
+
* If the input collection is empty, the result is empty.
|
|
4516
|
+
*
|
|
4517
|
+
* If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment.
|
|
4518
|
+
*
|
|
4519
|
+
* See: https://hl7.org/fhirpath/#truncate-integer
|
|
4520
|
+
*
|
|
4521
|
+
* @param input The input collection.
|
|
4522
|
+
* @returns A collection containing the result.
|
|
4523
|
+
*/
|
|
4524
|
+
truncate: (input) => {
|
|
4525
|
+
return applyMathFunc((x) => x | 0, input);
|
|
4526
|
+
},
|
|
4527
|
+
/*
|
|
4528
|
+
* 5.8. Tree navigation
|
|
4529
|
+
*/
|
|
4530
|
+
children: stub,
|
|
4531
|
+
descendants: stub,
|
|
4532
|
+
/*
|
|
4533
|
+
* 5.9. Utility functions
|
|
4534
|
+
*/
|
|
4535
|
+
/**
|
|
4536
|
+
* Adds a String representation of the input collection to the diagnostic log,
|
|
4537
|
+
* using the name argument as the name in the log. This log should be made available
|
|
4538
|
+
* to the user in some appropriate fashion. Does not change the input, so returns
|
|
4539
|
+
* the input collection as output.
|
|
4540
|
+
*
|
|
4541
|
+
* If the projection argument is used, the trace would log the result of evaluating
|
|
4542
|
+
* the project expression on the input, but still return the input to the trace
|
|
4543
|
+
* function unchanged.
|
|
4544
|
+
*
|
|
4545
|
+
* See: https://hl7.org/fhirpath/#tracename-string-projection-expression-collection
|
|
4546
|
+
*
|
|
4547
|
+
* @param input The input collection.
|
|
4548
|
+
* @param nameAtom The log name.
|
|
4549
|
+
*/
|
|
4550
|
+
trace: (input, nameAtom) => {
|
|
4551
|
+
console.log('trace', input, nameAtom);
|
|
4552
|
+
return input;
|
|
4553
|
+
},
|
|
4554
|
+
/**
|
|
4555
|
+
* Returns the current date and time, including timezone offset.
|
|
4556
|
+
*
|
|
4557
|
+
* See: https://hl7.org/fhirpath/#now-datetime
|
|
4558
|
+
*/
|
|
4559
|
+
now: () => {
|
|
4560
|
+
return [{ type: PropertyType.dateTime, value: new Date().toISOString() }];
|
|
4561
|
+
},
|
|
4562
|
+
/**
|
|
4563
|
+
* Returns the current time.
|
|
4564
|
+
*
|
|
4565
|
+
* See: https://hl7.org/fhirpath/#timeofday-time
|
|
4566
|
+
*/
|
|
4567
|
+
timeOfDay: () => {
|
|
4568
|
+
return [{ type: PropertyType.time, value: new Date().toISOString().substring(11) }];
|
|
4569
|
+
},
|
|
4570
|
+
/**
|
|
4571
|
+
* Returns the current date.
|
|
4572
|
+
*
|
|
4573
|
+
* See: https://hl7.org/fhirpath/#today-date
|
|
4574
|
+
*/
|
|
4575
|
+
today: () => {
|
|
4576
|
+
return [{ type: PropertyType.date, value: new Date().toISOString().substring(0, 10) }];
|
|
4577
|
+
},
|
|
4578
|
+
/**
|
|
4579
|
+
* Calculates the difference between two dates or date/times.
|
|
4580
|
+
*
|
|
4581
|
+
* This is not part of the official FHIRPath spec.
|
|
4582
|
+
*
|
|
4583
|
+
* IBM FHIR issue: https://github.com/IBM/FHIR/issues/1014
|
|
4584
|
+
* IBM FHIR PR: https://github.com/IBM/FHIR/pull/1023
|
|
4585
|
+
*/
|
|
4586
|
+
between: (context, startAtom, endAtom, unitsAtom) => {
|
|
4587
|
+
const startDate = functions.toDateTime(startAtom.eval(context));
|
|
4588
|
+
if (startDate.length === 0) {
|
|
4589
|
+
throw new Error('Invalid start date');
|
|
4590
|
+
}
|
|
4591
|
+
const endDate = functions.toDateTime(endAtom.eval(context));
|
|
4592
|
+
if (endDate.length === 0) {
|
|
4593
|
+
throw new Error('Invalid end date');
|
|
4594
|
+
}
|
|
4595
|
+
const unit = unitsAtom.eval(context)[0].value;
|
|
4596
|
+
if (unit !== 'years' && unit !== 'months' && unit !== 'days') {
|
|
4597
|
+
throw new Error('Invalid units');
|
|
4598
|
+
}
|
|
4599
|
+
const age = calculateAge(startDate[0].value, endDate[0].value);
|
|
4600
|
+
return [{ type: PropertyType.Quantity, value: { value: age[unit], unit } }];
|
|
4601
|
+
},
|
|
4602
|
+
/*
|
|
4603
|
+
* 6.3 Types
|
|
4604
|
+
*/
|
|
4605
|
+
/**
|
|
4606
|
+
* The is() function is supported for backwards compatibility with previous
|
|
4607
|
+
* implementations of FHIRPath. Just as with the is keyword, the type argument
|
|
4608
|
+
* is an identifier that must resolve to the name of a type in a model.
|
|
4609
|
+
*
|
|
4610
|
+
* For implementations with compile-time typing, this requires special-case
|
|
4611
|
+
* handling when processing the argument to treat it as a type specifier rather
|
|
4612
|
+
* than an identifier expression:
|
|
4613
|
+
*
|
|
4614
|
+
* @param input
|
|
4615
|
+
* @param typeAtom
|
|
4616
|
+
* @returns
|
|
4617
|
+
*/
|
|
4618
|
+
is: (input, typeAtom) => {
|
|
4619
|
+
let typeName = '';
|
|
4620
|
+
if (typeAtom instanceof SymbolAtom) {
|
|
4621
|
+
typeName = typeAtom.name;
|
|
4622
|
+
}
|
|
4623
|
+
else if (typeAtom instanceof DotAtom) {
|
|
4624
|
+
typeName = typeAtom.left.name + '.' + typeAtom.right.name;
|
|
4625
|
+
}
|
|
4626
|
+
if (!typeName) {
|
|
4627
|
+
return [];
|
|
4628
|
+
}
|
|
4629
|
+
return input.map((value) => ({ type: PropertyType.boolean, value: fhirPathIs(value, typeName) }));
|
|
4630
|
+
},
|
|
4631
|
+
/*
|
|
4632
|
+
* 6.5 Boolean logic
|
|
4633
|
+
*/
|
|
4634
|
+
/**
|
|
4635
|
+
* 6.5.3. not() : Boolean
|
|
4636
|
+
*
|
|
4637
|
+
* Returns true if the input collection evaluates to false, and false if it evaluates to true. Otherwise, the result is empty ({ }):
|
|
4638
|
+
*
|
|
4639
|
+
* @param input
|
|
4640
|
+
* @returns
|
|
4641
|
+
*/
|
|
4642
|
+
not: (input) => {
|
|
4643
|
+
return functions.toBoolean(input).map((value) => ({ type: PropertyType.boolean, value: !value.value }));
|
|
4644
|
+
},
|
|
4645
|
+
/*
|
|
4646
|
+
* Additional functions
|
|
4647
|
+
* See: https://hl7.org/fhir/fhirpath.html#functions
|
|
4648
|
+
*/
|
|
4649
|
+
/**
|
|
4650
|
+
* For each item in the collection, if it is a string that is a uri (or canonical or url), locate the target of the reference, and add it to the resulting collection. If the item does not resolve to a resource, the item is ignored and nothing is added to the output collection.
|
|
4651
|
+
* The items in the collection may also represent a Reference, in which case the Reference.reference is resolved.
|
|
4652
|
+
* @param input The input collection.
|
|
4653
|
+
* @returns
|
|
4654
|
+
*/
|
|
4655
|
+
resolve: (input) => {
|
|
4656
|
+
return input
|
|
4657
|
+
.map((e) => {
|
|
4658
|
+
const value = e.value;
|
|
4659
|
+
let refStr;
|
|
4660
|
+
if (typeof value === 'string') {
|
|
4661
|
+
refStr = value;
|
|
4662
|
+
}
|
|
4663
|
+
else if (typeof value === 'object') {
|
|
4664
|
+
const ref = value;
|
|
4665
|
+
if (ref.resource) {
|
|
4666
|
+
return { type: PropertyType.BackboneElement, value: ref.resource };
|
|
4667
|
+
}
|
|
4668
|
+
refStr = ref.reference;
|
|
4669
|
+
}
|
|
4670
|
+
if (!refStr) {
|
|
4671
|
+
return { type: PropertyType.BackboneElement, value: null };
|
|
4672
|
+
}
|
|
4673
|
+
const [resourceType, id] = refStr.split('/');
|
|
4674
|
+
return { type: PropertyType.BackboneElement, value: { resourceType, id } };
|
|
4675
|
+
})
|
|
4676
|
+
.filter((e) => !!e.value);
|
|
4677
|
+
},
|
|
4678
|
+
/**
|
|
4679
|
+
* The as operator can be used to treat a value as a specific type.
|
|
4680
|
+
* @param context The context value.
|
|
4681
|
+
* @returns The value as the specific type.
|
|
4682
|
+
*/
|
|
4683
|
+
as: (context) => {
|
|
4684
|
+
return context;
|
|
4685
|
+
},
|
|
4686
|
+
/*
|
|
4687
|
+
* 12. Formal Specifications
|
|
4688
|
+
*/
|
|
4689
|
+
/**
|
|
4690
|
+
* Returns the type of the input.
|
|
4691
|
+
*
|
|
4692
|
+
* 12.2. Model Information
|
|
4693
|
+
*
|
|
4694
|
+
* The model information returned by the reflection function type() is specified as an
|
|
4695
|
+
* XML Schema document (xsd) and included in this specification at the following link:
|
|
4696
|
+
* https://hl7.org/fhirpath/modelinfo.xsd
|
|
4697
|
+
*
|
|
4698
|
+
* See: https://hl7.org/fhirpath/#model-information
|
|
4699
|
+
*
|
|
4700
|
+
* @param input The input collection.
|
|
4701
|
+
* @returns
|
|
4702
|
+
*/
|
|
4703
|
+
type: (input) => {
|
|
4704
|
+
return input.map(({ value }) => {
|
|
4705
|
+
if (typeof value === 'boolean') {
|
|
4706
|
+
return { type: PropertyType.BackboneElement, value: { namespace: 'System', name: 'Boolean' } };
|
|
4707
|
+
}
|
|
4708
|
+
if (typeof value === 'number') {
|
|
4709
|
+
return { type: PropertyType.BackboneElement, value: { namespace: 'System', name: 'Integer' } };
|
|
4710
|
+
}
|
|
4711
|
+
if (value && typeof value === 'object' && 'resourceType' in value) {
|
|
4712
|
+
return {
|
|
4713
|
+
type: PropertyType.BackboneElement,
|
|
4714
|
+
value: { namespace: 'FHIR', name: value.resourceType },
|
|
4715
|
+
};
|
|
4716
|
+
}
|
|
4717
|
+
return { type: PropertyType.BackboneElement, value: null };
|
|
4718
|
+
});
|
|
4719
|
+
},
|
|
4720
|
+
conformsTo: (input, systemAtom) => {
|
|
4721
|
+
const system = systemAtom.eval([])[0].value;
|
|
4722
|
+
if (!system.startsWith('http://hl7.org/fhir/StructureDefinition/')) {
|
|
4723
|
+
throw new Error('Expected a StructureDefinition URL');
|
|
4724
|
+
}
|
|
4725
|
+
const expectedResourceType = system.replace('http://hl7.org/fhir/StructureDefinition/', '');
|
|
4726
|
+
return input.map((value) => {
|
|
4727
|
+
var _a;
|
|
4728
|
+
return ({
|
|
4729
|
+
type: PropertyType.boolean,
|
|
4730
|
+
value: ((_a = value.value) === null || _a === void 0 ? void 0 : _a.resourceType) === expectedResourceType,
|
|
4731
|
+
});
|
|
4732
|
+
});
|
|
4733
|
+
},
|
|
4734
|
+
};
|
|
4735
|
+
/*
|
|
4736
|
+
* Helper utilities
|
|
4737
|
+
*/
|
|
4738
|
+
function applyStringFunc(func, input, ...argsAtoms) {
|
|
4739
|
+
if (input.length === 0) {
|
|
4740
|
+
return [];
|
|
4741
|
+
}
|
|
4742
|
+
const [{ value }] = validateInput(input, 1);
|
|
4743
|
+
if (typeof value !== 'string') {
|
|
4744
|
+
throw new Error('String function cannot be called with non-string');
|
|
4745
|
+
}
|
|
4746
|
+
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); }));
|
|
4747
|
+
if (result === undefined) {
|
|
4748
|
+
return [];
|
|
4749
|
+
}
|
|
4750
|
+
if (Array.isArray(result)) {
|
|
4751
|
+
return result.map(toTypedValue);
|
|
4752
|
+
}
|
|
4753
|
+
return [toTypedValue(result)];
|
|
4754
|
+
}
|
|
4755
|
+
function applyMathFunc(func, input, ...argsAtoms) {
|
|
4756
|
+
if (input.length === 0) {
|
|
4757
|
+
return [];
|
|
4758
|
+
}
|
|
4759
|
+
const [{ value }] = validateInput(input, 1);
|
|
4760
|
+
const quantity = isQuantity(value);
|
|
4761
|
+
const numberInput = quantity ? value.value : value;
|
|
4762
|
+
if (typeof numberInput !== 'number') {
|
|
4763
|
+
throw new Error('Math function cannot be called with non-number');
|
|
4764
|
+
}
|
|
4765
|
+
const result = func(numberInput, ...argsAtoms.map((atom) => { var _a, _b; return (_b = (_a = atom.eval([])) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value; }));
|
|
4766
|
+
const type = quantity ? PropertyType.Quantity : input[0].type;
|
|
4767
|
+
const returnValue = quantity ? Object.assign(Object.assign({}, value), { value: result }) : result;
|
|
4768
|
+
return [{ type, value: returnValue }];
|
|
4769
|
+
}
|
|
4770
|
+
function validateInput(input, count) {
|
|
4771
|
+
if (input.length !== count) {
|
|
4772
|
+
throw new Error(`Expected ${count} arguments`);
|
|
4773
|
+
}
|
|
4774
|
+
for (const element of input) {
|
|
4775
|
+
if (element === null || element === undefined) {
|
|
4776
|
+
throw new Error('Expected non-null argument');
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
return input;
|
|
4780
|
+
}
|
|
4781
|
+
|
|
4782
|
+
var _Tokenizer_instances, _Tokenizer_str, _Tokenizer_pos, _Tokenizer_peekToken, _Tokenizer_consumeToken, _Tokenizer_consumeWhitespace, _Tokenizer_consumeMultiLineComment, _Tokenizer_consumeSingleLineComment, _Tokenizer_consumeString, _Tokenizer_consumeBacktickSymbol, _Tokenizer_consumeDateTime, _Tokenizer_consumeNumber, _Tokenizer_consumeSymbol, _Tokenizer_consumeOperator, _Tokenizer_consumeWhile, _Tokenizer_curr, _Tokenizer_prev, _Tokenizer_peek;
|
|
4783
|
+
function tokenize(str) {
|
|
4784
|
+
return new Tokenizer(str).tokenize();
|
|
4785
|
+
}
|
|
4786
|
+
const STANDARD_UNITS = [
|
|
4787
|
+
'year',
|
|
4788
|
+
'years',
|
|
4789
|
+
'month',
|
|
4790
|
+
'months',
|
|
4791
|
+
'week',
|
|
4792
|
+
'weeks',
|
|
4793
|
+
'day',
|
|
4794
|
+
'days',
|
|
4795
|
+
'hour',
|
|
4796
|
+
'hours',
|
|
4797
|
+
'minute',
|
|
4798
|
+
'minutes',
|
|
4799
|
+
'second',
|
|
4800
|
+
'seconds',
|
|
4801
|
+
'millisecond',
|
|
4802
|
+
'milliseconds',
|
|
4803
|
+
];
|
|
4804
|
+
const TWO_CHAR_OPERATORS = ['!=', '!~', '<=', '>=', '{}'];
|
|
4805
|
+
class Tokenizer {
|
|
4806
|
+
constructor(str) {
|
|
4807
|
+
_Tokenizer_instances.add(this);
|
|
4808
|
+
_Tokenizer_str.set(this, void 0);
|
|
4809
|
+
_Tokenizer_pos.set(this, void 0);
|
|
4810
|
+
__classPrivateFieldSet(this, _Tokenizer_str, str, "f");
|
|
4811
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, 0, "f");
|
|
4812
|
+
}
|
|
4813
|
+
tokenize() {
|
|
4814
|
+
const result = [];
|
|
4815
|
+
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f") < __classPrivateFieldGet(this, _Tokenizer_str, "f").length) {
|
|
4816
|
+
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
4817
|
+
if (token) {
|
|
4818
|
+
result.push(token);
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
return result;
|
|
4822
|
+
}
|
|
4823
|
+
}
|
|
4824
|
+
_Tokenizer_str = new WeakMap(), _Tokenizer_pos = new WeakMap(), _Tokenizer_instances = new WeakSet(), _Tokenizer_peekToken = function _Tokenizer_peekToken() {
|
|
4825
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
4826
|
+
const token = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
4827
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, start, "f");
|
|
4828
|
+
return token;
|
|
4829
|
+
}, _Tokenizer_consumeToken = function _Tokenizer_consumeToken() {
|
|
4830
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhitespace).call(this);
|
|
4831
|
+
const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
|
|
4832
|
+
if (!c) {
|
|
4833
|
+
return undefined;
|
|
4834
|
+
}
|
|
4835
|
+
const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
|
|
4836
|
+
if (c === '/' && next === '*') {
|
|
4837
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeMultiLineComment).call(this);
|
|
4838
|
+
}
|
|
4839
|
+
if (c === '/' && next === '/') {
|
|
4840
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSingleLineComment).call(this);
|
|
4841
|
+
}
|
|
4842
|
+
if (c === "'") {
|
|
4843
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeString).call(this);
|
|
4844
|
+
}
|
|
4845
|
+
if (c === '`') {
|
|
4846
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeBacktickSymbol).call(this);
|
|
4847
|
+
}
|
|
4848
|
+
if (c === '@') {
|
|
4849
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeDateTime).call(this);
|
|
4850
|
+
}
|
|
4851
|
+
if (c.match(/\d/)) {
|
|
4852
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeNumber).call(this);
|
|
4853
|
+
}
|
|
4854
|
+
if (c.match(/\w/)) {
|
|
4855
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
|
|
4856
|
+
}
|
|
4857
|
+
if (c === '$' && next.match(/\w/)) {
|
|
4858
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeSymbol).call(this);
|
|
4859
|
+
}
|
|
4860
|
+
return __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeOperator).call(this);
|
|
4861
|
+
}, _Tokenizer_consumeWhitespace = function _Tokenizer_consumeWhitespace() {
|
|
4862
|
+
return buildToken('Whitespace', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\s/)));
|
|
4863
|
+
}, _Tokenizer_consumeMultiLineComment = function _Tokenizer_consumeMultiLineComment() {
|
|
4864
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
4865
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '*' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this) !== '/');
|
|
4866
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, __classPrivateFieldGet(this, _Tokenizer_pos, "f") + 2, "f");
|
|
4867
|
+
return buildToken('Comment', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
|
|
4868
|
+
}, _Tokenizer_consumeSingleLineComment = function _Tokenizer_consumeSingleLineComment() {
|
|
4869
|
+
return buildToken('Comment', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '\n'));
|
|
4870
|
+
}, _Tokenizer_consumeString = function _Tokenizer_consumeString() {
|
|
4871
|
+
var _a, _b;
|
|
4872
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
4873
|
+
const result = buildToken('String', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_prev).call(this) === '\\' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== "'"));
|
|
4874
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_b = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _b++, _b), "f");
|
|
4875
|
+
return result;
|
|
4876
|
+
}, _Tokenizer_consumeBacktickSymbol = function _Tokenizer_consumeBacktickSymbol() {
|
|
4877
|
+
var _a, _b;
|
|
4878
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
4879
|
+
const result = buildToken('Symbol', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) !== '`'));
|
|
4880
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_b = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _b++, _b), "f");
|
|
4881
|
+
return result;
|
|
4882
|
+
}, _Tokenizer_consumeDateTime = function _Tokenizer_consumeDateTime() {
|
|
4883
|
+
var _a, _b, _c, _d, _e;
|
|
4884
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
4885
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
4886
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d-]/));
|
|
4887
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'T') {
|
|
4888
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_b = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _b++, _b), "f");
|
|
4889
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
4890
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
4891
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_c = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _c++, _c), "f");
|
|
4892
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d]/));
|
|
4893
|
+
}
|
|
4894
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === 'Z') {
|
|
4895
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_d = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _d++, _d), "f");
|
|
4896
|
+
}
|
|
4897
|
+
else if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '+' || __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '-') {
|
|
4898
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_e = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _e++, _e), "f");
|
|
4899
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[\d:]/));
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4902
|
+
return buildToken('DateTime', __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start + 1, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
|
|
4903
|
+
}, _Tokenizer_consumeNumber = function _Tokenizer_consumeNumber() {
|
|
4904
|
+
var _a;
|
|
4905
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
4906
|
+
let id = 'Number';
|
|
4907
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
4908
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === '.' && __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this).match(/\d/)) {
|
|
4909
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
4910
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/\d/));
|
|
4911
|
+
}
|
|
4912
|
+
if (__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this) === ' ') {
|
|
4913
|
+
if (isUnitToken(__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peekToken).call(this))) {
|
|
4914
|
+
id = 'Quantity';
|
|
4915
|
+
__classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeToken).call(this);
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
return buildToken(id, __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f")));
|
|
4919
|
+
}, _Tokenizer_consumeSymbol = function _Tokenizer_consumeSymbol() {
|
|
4920
|
+
return buildToken('Symbol', __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_consumeWhile).call(this, () => __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this).match(/[$\w]/)));
|
|
4921
|
+
}, _Tokenizer_consumeOperator = function _Tokenizer_consumeOperator() {
|
|
4922
|
+
var _a;
|
|
4923
|
+
const c = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_curr).call(this);
|
|
4924
|
+
const next = __classPrivateFieldGet(this, _Tokenizer_instances, "m", _Tokenizer_peek).call(this);
|
|
4925
|
+
const twoCharOp = c + next;
|
|
4926
|
+
if (TWO_CHAR_OPERATORS.includes(twoCharOp)) {
|
|
4927
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, __classPrivateFieldGet(this, _Tokenizer_pos, "f") + 2, "f");
|
|
4928
|
+
return buildToken(twoCharOp, twoCharOp);
|
|
4929
|
+
}
|
|
4930
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
4931
|
+
return buildToken(c, c);
|
|
4932
|
+
}, _Tokenizer_consumeWhile = function _Tokenizer_consumeWhile(condition) {
|
|
4933
|
+
var _a;
|
|
4934
|
+
const start = __classPrivateFieldGet(this, _Tokenizer_pos, "f");
|
|
4935
|
+
while (__classPrivateFieldGet(this, _Tokenizer_pos, "f") < __classPrivateFieldGet(this, _Tokenizer_str, "f").length && condition()) {
|
|
4936
|
+
__classPrivateFieldSet(this, _Tokenizer_pos, (_a = __classPrivateFieldGet(this, _Tokenizer_pos, "f"), _a++, _a), "f");
|
|
4937
|
+
}
|
|
4938
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f").substring(start, __classPrivateFieldGet(this, _Tokenizer_pos, "f"));
|
|
4939
|
+
}, _Tokenizer_curr = function _Tokenizer_curr() {
|
|
4940
|
+
return __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f")];
|
|
4941
|
+
}, _Tokenizer_prev = function _Tokenizer_prev() {
|
|
4942
|
+
var _a;
|
|
4943
|
+
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f") - 1]) !== null && _a !== void 0 ? _a : '';
|
|
4944
|
+
}, _Tokenizer_peek = function _Tokenizer_peek() {
|
|
4945
|
+
var _a;
|
|
4946
|
+
return (_a = __classPrivateFieldGet(this, _Tokenizer_str, "f")[__classPrivateFieldGet(this, _Tokenizer_pos, "f") + 1]) !== null && _a !== void 0 ? _a : '';
|
|
4947
|
+
};
|
|
4948
|
+
function buildToken(id, value) {
|
|
4949
|
+
return { id, value };
|
|
4950
|
+
}
|
|
4951
|
+
function isUnitToken(token) {
|
|
4952
|
+
if (token) {
|
|
4953
|
+
if (token.id === 'String') {
|
|
4954
|
+
return true;
|
|
4955
|
+
}
|
|
4956
|
+
if (token.id === 'Symbol' && STANDARD_UNITS.includes(token.value)) {
|
|
4957
|
+
return true;
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
return false;
|
|
4961
|
+
}
|
|
4962
|
+
|
|
4963
|
+
var _ParserBuilder_prefixParselets, _ParserBuilder_infixParselets, _Parser_instances, _Parser_tokens, _Parser_prefixParselets, _Parser_infixParselets, _Parser_getPrecedence, _Parser_consume, _Parser_look;
|
|
4964
|
+
class ParserBuilder {
|
|
4965
|
+
constructor() {
|
|
4966
|
+
_ParserBuilder_prefixParselets.set(this, {});
|
|
4967
|
+
_ParserBuilder_infixParselets.set(this, {});
|
|
4968
|
+
}
|
|
4969
|
+
registerInfix(tokenType, parselet) {
|
|
4970
|
+
__classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f")[tokenType] = parselet;
|
|
4971
|
+
return this;
|
|
4972
|
+
}
|
|
4973
|
+
registerPrefix(tokenType, parselet) {
|
|
4974
|
+
__classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f")[tokenType] = parselet;
|
|
4975
|
+
return this;
|
|
4976
|
+
}
|
|
4977
|
+
prefix(tokenType, precedence, builder) {
|
|
4978
|
+
return this.registerPrefix(tokenType, {
|
|
4979
|
+
parse(parser, token) {
|
|
4980
|
+
const right = parser.consumeAndParse(precedence);
|
|
4981
|
+
return builder(token, right);
|
|
4982
|
+
},
|
|
4983
|
+
});
|
|
4984
|
+
}
|
|
4985
|
+
infixLeft(tokenType, precedence, builder) {
|
|
4986
|
+
return this.registerInfix(tokenType, {
|
|
4987
|
+
parse(parser, left, token) {
|
|
4988
|
+
const right = parser.consumeAndParse(precedence);
|
|
4989
|
+
return builder(left, token, right);
|
|
4990
|
+
},
|
|
4991
|
+
precedence,
|
|
4992
|
+
});
|
|
4993
|
+
}
|
|
4994
|
+
construct(input) {
|
|
4995
|
+
return new Parser(tokenize(input), __classPrivateFieldGet(this, _ParserBuilder_prefixParselets, "f"), __classPrivateFieldGet(this, _ParserBuilder_infixParselets, "f"));
|
|
4996
|
+
}
|
|
4997
|
+
}
|
|
4998
|
+
_ParserBuilder_prefixParselets = new WeakMap(), _ParserBuilder_infixParselets = new WeakMap();
|
|
4999
|
+
class Parser {
|
|
5000
|
+
constructor(tokens, prefixParselets, infixParselets) {
|
|
5001
|
+
_Parser_instances.add(this);
|
|
5002
|
+
_Parser_tokens.set(this, void 0);
|
|
5003
|
+
_Parser_prefixParselets.set(this, void 0);
|
|
5004
|
+
_Parser_infixParselets.set(this, void 0);
|
|
5005
|
+
__classPrivateFieldSet(this, _Parser_tokens, tokens, "f");
|
|
5006
|
+
__classPrivateFieldSet(this, _Parser_prefixParselets, prefixParselets, "f");
|
|
5007
|
+
__classPrivateFieldSet(this, _Parser_infixParselets, infixParselets, "f");
|
|
5008
|
+
}
|
|
5009
|
+
match(expected) {
|
|
5010
|
+
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_look).call(this);
|
|
5011
|
+
if ((token === null || token === void 0 ? void 0 : token.id) !== expected) {
|
|
5012
|
+
return false;
|
|
5013
|
+
}
|
|
5014
|
+
__classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
5015
|
+
return true;
|
|
5016
|
+
}
|
|
5017
|
+
consumeAndParse(precedence = 100 /* Precedence.MaximumPrecedence */) {
|
|
5018
|
+
const token = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
5019
|
+
const prefix = __classPrivateFieldGet(this, _Parser_prefixParselets, "f")[token.id];
|
|
5020
|
+
if (!prefix) {
|
|
5021
|
+
throw Error(`Parse error at ${token.value}. No matching prefix parselet.`);
|
|
5022
|
+
}
|
|
5023
|
+
let left = prefix.parse(this, token);
|
|
5024
|
+
while (precedence > __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_getPrecedence).call(this)) {
|
|
5025
|
+
const next = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_consume).call(this);
|
|
5026
|
+
const infix = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[next.id];
|
|
5027
|
+
left = infix.parse(this, left, next);
|
|
5028
|
+
}
|
|
5029
|
+
return left;
|
|
5030
|
+
}
|
|
5031
|
+
}
|
|
5032
|
+
_Parser_tokens = new WeakMap(), _Parser_prefixParselets = new WeakMap(), _Parser_infixParselets = new WeakMap(), _Parser_instances = new WeakSet(), _Parser_getPrecedence = function _Parser_getPrecedence() {
|
|
5033
|
+
const nextToken = __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_look).call(this);
|
|
5034
|
+
if (!nextToken) {
|
|
5035
|
+
return 100 /* Precedence.MaximumPrecedence */;
|
|
5036
|
+
}
|
|
5037
|
+
const parser = __classPrivateFieldGet(this, _Parser_infixParselets, "f")[nextToken.id];
|
|
5038
|
+
if (parser) {
|
|
5039
|
+
return parser.precedence;
|
|
5040
|
+
}
|
|
5041
|
+
return 100 /* Precedence.MaximumPrecedence */;
|
|
5042
|
+
}, _Parser_consume = function _Parser_consume() {
|
|
5043
|
+
if (!__classPrivateFieldGet(this, _Parser_tokens, "f").length) {
|
|
5044
|
+
throw Error('Cant consume unknown more tokens.');
|
|
5045
|
+
}
|
|
5046
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").shift();
|
|
5047
|
+
}, _Parser_look = function _Parser_look() {
|
|
5048
|
+
return __classPrivateFieldGet(this, _Parser_tokens, "f").length > 0 ? __classPrivateFieldGet(this, _Parser_tokens, "f")[0] : undefined;
|
|
5049
|
+
};
|
|
5050
|
+
const PARENTHESES_PARSELET = {
|
|
5051
|
+
parse(parser) {
|
|
5052
|
+
const expr = parser.consumeAndParse();
|
|
5053
|
+
if (!parser.match(')')) {
|
|
5054
|
+
throw new Error('Parse error: expected `)`');
|
|
5055
|
+
}
|
|
5056
|
+
return expr;
|
|
5057
|
+
},
|
|
5058
|
+
};
|
|
5059
|
+
const INDEXER_PARSELET = {
|
|
5060
|
+
parse(parser, left) {
|
|
5061
|
+
const expr = parser.consumeAndParse();
|
|
5062
|
+
if (!parser.match(']')) {
|
|
5063
|
+
throw new Error('Parse error: expected `]`');
|
|
5064
|
+
}
|
|
5065
|
+
return new IndexerAtom(left, expr);
|
|
5066
|
+
},
|
|
5067
|
+
precedence: 2 /* Precedence.Indexer */,
|
|
5068
|
+
};
|
|
5069
|
+
const FUNCTION_CALL_PARSELET = {
|
|
5070
|
+
parse(parser, left) {
|
|
5071
|
+
if (!(left instanceof SymbolAtom)) {
|
|
5072
|
+
throw new Error('Unexpected parentheses');
|
|
5073
|
+
}
|
|
5074
|
+
if (!(left.name in functions)) {
|
|
5075
|
+
throw new Error('Unrecognized function: ' + left.name);
|
|
5076
|
+
}
|
|
5077
|
+
const args = [];
|
|
5078
|
+
while (!parser.match(')')) {
|
|
5079
|
+
args.push(parser.consumeAndParse());
|
|
5080
|
+
parser.match(',');
|
|
5081
|
+
}
|
|
5082
|
+
return new FunctionAtom(left.name, args, functions[left.name]);
|
|
5083
|
+
},
|
|
5084
|
+
precedence: 0 /* Precedence.FunctionCall */,
|
|
5085
|
+
};
|
|
5086
|
+
function parseQuantity(str) {
|
|
5087
|
+
const parts = str.split(' ');
|
|
5088
|
+
const value = parseFloat(parts[0]);
|
|
5089
|
+
let unit = parts[1];
|
|
5090
|
+
if (unit && unit.startsWith("'") && unit.endsWith("'")) {
|
|
5091
|
+
unit = unit.substring(1, unit.length - 1);
|
|
5092
|
+
}
|
|
5093
|
+
else {
|
|
5094
|
+
unit = '{' + unit + '}';
|
|
5095
|
+
}
|
|
5096
|
+
return { value, unit };
|
|
5097
|
+
}
|
|
5098
|
+
const parserBuilder = new ParserBuilder()
|
|
5099
|
+
.registerPrefix('String', {
|
|
5100
|
+
parse: (_, token) => new LiteralAtom({ type: PropertyType.string, value: token.value }),
|
|
5101
|
+
})
|
|
5102
|
+
.registerPrefix('DateTime', {
|
|
5103
|
+
parse: (_, token) => new LiteralAtom({ type: PropertyType.dateTime, value: parseDateString(token.value) }),
|
|
5104
|
+
})
|
|
5105
|
+
.registerPrefix('Quantity', {
|
|
5106
|
+
parse: (_, token) => new LiteralAtom({ type: PropertyType.Quantity, value: parseQuantity(token.value) }),
|
|
5107
|
+
})
|
|
5108
|
+
.registerPrefix('Number', {
|
|
5109
|
+
parse: (_, token) => new LiteralAtom({ type: PropertyType.decimal, value: parseFloat(token.value) }),
|
|
5110
|
+
})
|
|
5111
|
+
.registerPrefix('Symbol', {
|
|
5112
|
+
parse: (_, token) => {
|
|
5113
|
+
if (token.value === 'false') {
|
|
5114
|
+
return new LiteralAtom({ type: PropertyType.boolean, value: false });
|
|
5115
|
+
}
|
|
5116
|
+
if (token.value === 'true') {
|
|
5117
|
+
return new LiteralAtom({ type: PropertyType.boolean, value: true });
|
|
5118
|
+
}
|
|
5119
|
+
return new SymbolAtom(token.value);
|
|
5120
|
+
},
|
|
5121
|
+
})
|
|
5122
|
+
.registerPrefix('{}', { parse: () => new EmptySetAtom() })
|
|
5123
|
+
.registerPrefix('(', PARENTHESES_PARSELET)
|
|
5124
|
+
.registerInfix('[', INDEXER_PARSELET)
|
|
5125
|
+
.registerInfix('(', FUNCTION_CALL_PARSELET)
|
|
5126
|
+
.prefix('+', 3 /* Precedence.UnaryAdd */, (_, right) => new UnaryOperatorAtom(right, (x) => x))
|
|
5127
|
+
.prefix('-', 3 /* Precedence.UnarySubtract */, (_, right) => new ArithemticOperatorAtom(right, right, (_, y) => -y))
|
|
5128
|
+
.infixLeft('.', 1 /* Precedence.Dot */, (left, _, right) => new DotAtom(left, right))
|
|
5129
|
+
.infixLeft('/', 4 /* Precedence.Divide */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x / y))
|
|
5130
|
+
.infixLeft('*', 4 /* Precedence.Multiply */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x * y))
|
|
5131
|
+
.infixLeft('+', 5 /* Precedence.Add */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x + y))
|
|
5132
|
+
.infixLeft('-', 5 /* Precedence.Subtract */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x - y))
|
|
5133
|
+
.infixLeft('|', 7 /* Precedence.Union */, (left, _, right) => new UnionAtom(left, right))
|
|
5134
|
+
.infixLeft('=', 9 /* Precedence.Equals */, (left, _, right) => new EqualsAtom(left, right))
|
|
5135
|
+
.infixLeft('!=', 9 /* Precedence.Equals */, (left, _, right) => new NotEqualsAtom(left, right))
|
|
5136
|
+
.infixLeft('~', 9 /* Precedence.Equivalent */, (left, _, right) => new EquivalentAtom(left, right))
|
|
5137
|
+
.infixLeft('!~', 9 /* Precedence.NotEquivalent */, (left, _, right) => new NotEquivalentAtom(left, right))
|
|
5138
|
+
.infixLeft('<', 8 /* Precedence.LessThan */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x < y))
|
|
5139
|
+
.infixLeft('<=', 8 /* Precedence.LessThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x <= y))
|
|
5140
|
+
.infixLeft('>', 8 /* Precedence.GreaterThan */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x > y))
|
|
5141
|
+
.infixLeft('>=', 8 /* Precedence.GreaterThanOrEquals */, (left, _, right) => new ArithemticOperatorAtom(left, right, (x, y) => x >= y))
|
|
5142
|
+
.infixLeft('&', 5 /* Precedence.Ampersand */, (left, _, right) => new ConcatAtom(left, right))
|
|
5143
|
+
.infixLeft('Symbol', 6 /* Precedence.Is */, (left, symbol, right) => {
|
|
5144
|
+
switch (symbol.value) {
|
|
5145
|
+
case 'and':
|
|
5146
|
+
return new AndAtom(left, right);
|
|
5147
|
+
case 'as':
|
|
5148
|
+
return new AsAtom(left, right);
|
|
5149
|
+
case 'contains':
|
|
5150
|
+
return new ContainsAtom(left, right);
|
|
5151
|
+
case 'div':
|
|
5152
|
+
return new ArithemticOperatorAtom(left, right, (x, y) => (x / y) | 0);
|
|
5153
|
+
case 'in':
|
|
5154
|
+
return new InAtom(left, right);
|
|
5155
|
+
case 'is':
|
|
5156
|
+
return new IsAtom(left, right);
|
|
5157
|
+
case 'mod':
|
|
5158
|
+
return new ArithemticOperatorAtom(left, right, (x, y) => x % y);
|
|
5159
|
+
case 'or':
|
|
5160
|
+
return new OrAtom(left, right);
|
|
5161
|
+
case 'xor':
|
|
5162
|
+
return new XorAtom(left, right);
|
|
5163
|
+
default:
|
|
5164
|
+
throw new Error('Cannot use ' + symbol.value + ' as infix operator');
|
|
5165
|
+
}
|
|
5166
|
+
});
|
|
5167
|
+
/**
|
|
5168
|
+
* Parses a FHIRPath expression into an AST.
|
|
5169
|
+
* The result can be used to evaluate the expression against a resource or other object.
|
|
5170
|
+
* This method is useful if you know that you will evaluate the same expression many times
|
|
5171
|
+
* against different resources.
|
|
5172
|
+
* @param input The FHIRPath expression to parse.
|
|
5173
|
+
* @returns The AST representing the expression.
|
|
5174
|
+
*/
|
|
5175
|
+
function parseFhirPath(input) {
|
|
5176
|
+
try {
|
|
5177
|
+
return new FhirPathAtom(input, parserBuilder.construct(input).consumeAndParse());
|
|
5178
|
+
}
|
|
5179
|
+
catch (error) {
|
|
5180
|
+
throw new Error(`FhirPathError on "${input}": ${error}`);
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
/**
|
|
5184
|
+
* Evaluates a FHIRPath expression against a resource or other object.
|
|
5185
|
+
* @param input The FHIRPath expression to parse.
|
|
5186
|
+
* @param context The resource or object to evaluate the expression against.
|
|
5187
|
+
* @returns The result of the FHIRPath expression against the resource or object.
|
|
5188
|
+
*/
|
|
5189
|
+
function evalFhirPath(input, context) {
|
|
5190
|
+
// eval requires a TypedValue array
|
|
5191
|
+
// As a convenience, we can accept array or non-array, and TypedValue or unknown value
|
|
5192
|
+
if (!Array.isArray(context)) {
|
|
5193
|
+
context = [context];
|
|
5194
|
+
}
|
|
5195
|
+
const array = Array.isArray(context) ? context : [context];
|
|
5196
|
+
for (let i = 0; i < array.length; i++) {
|
|
5197
|
+
const el = array[i];
|
|
5198
|
+
if (!(typeof el === 'object' && 'type' in el && 'value' in el)) {
|
|
5199
|
+
array[i] = { type: PropertyType.BackboneElement, value: el };
|
|
5200
|
+
}
|
|
5201
|
+
}
|
|
5202
|
+
return parseFhirPath(input)
|
|
5203
|
+
.eval(array)
|
|
5204
|
+
.map((e) => e.value);
|
|
5205
|
+
}
|
|
5206
|
+
|
|
5207
|
+
const SEGMENT_SEPARATOR = '\r';
|
|
5208
|
+
const FIELD_SEPARATOR = '|';
|
|
5209
|
+
const COMPONENT_SEPARATOR = '^';
|
|
5210
|
+
/**
|
|
5211
|
+
* The Hl7Message class represents one HL7 message.
|
|
5212
|
+
* A message is a collection of segments.
|
|
5213
|
+
* Note that we do not strictly parse messages, and only use default delimeters.
|
|
5214
|
+
*/
|
|
5215
|
+
class Hl7Message {
|
|
5216
|
+
constructor(segments) {
|
|
5217
|
+
this.segments = segments;
|
|
5218
|
+
}
|
|
5219
|
+
get(index) {
|
|
5220
|
+
if (typeof index === 'number') {
|
|
5221
|
+
return this.segments[index];
|
|
5222
|
+
}
|
|
5223
|
+
return this.segments.find((s) => s.name === index);
|
|
5224
|
+
}
|
|
5225
|
+
getAll(name) {
|
|
5226
|
+
return this.segments.filter((s) => s.name === name);
|
|
5227
|
+
}
|
|
5228
|
+
toString() {
|
|
5229
|
+
return this.segments.map((s) => s.toString()).join(SEGMENT_SEPARATOR);
|
|
5230
|
+
}
|
|
5231
|
+
buildAck() {
|
|
5232
|
+
var _a, _b, _c, _d, _e, _f;
|
|
5233
|
+
const now = new Date();
|
|
5234
|
+
const msh = this.get('MSH');
|
|
5235
|
+
const sendingApp = ((_a = msh === null || msh === void 0 ? void 0 : msh.get(2)) === null || _a === void 0 ? void 0 : _a.toString()) || '';
|
|
5236
|
+
const sendingFacility = ((_b = msh === null || msh === void 0 ? void 0 : msh.get(3)) === null || _b === void 0 ? void 0 : _b.toString()) || '';
|
|
5237
|
+
const receivingApp = ((_c = msh === null || msh === void 0 ? void 0 : msh.get(4)) === null || _c === void 0 ? void 0 : _c.toString()) || '';
|
|
5238
|
+
const receivingFacility = ((_d = msh === null || msh === void 0 ? void 0 : msh.get(5)) === null || _d === void 0 ? void 0 : _d.toString()) || '';
|
|
5239
|
+
const controlId = ((_e = msh === null || msh === void 0 ? void 0 : msh.get(9)) === null || _e === void 0 ? void 0 : _e.toString()) || '';
|
|
5240
|
+
const versionId = ((_f = msh === null || msh === void 0 ? void 0 : msh.get(12)) === null || _f === void 0 ? void 0 : _f.toString()) || '2.5.1';
|
|
5241
|
+
return new Hl7Message([
|
|
5242
|
+
new Hl7Segment([
|
|
5243
|
+
'MSH',
|
|
5244
|
+
'^~\\&',
|
|
5245
|
+
receivingApp,
|
|
5246
|
+
receivingFacility,
|
|
5247
|
+
sendingApp,
|
|
5248
|
+
sendingFacility,
|
|
5249
|
+
now.toISOString(),
|
|
5250
|
+
'',
|
|
5251
|
+
'ACK',
|
|
5252
|
+
now.getTime().toString(),
|
|
5253
|
+
'P',
|
|
5254
|
+
versionId,
|
|
5255
|
+
]),
|
|
5256
|
+
new Hl7Segment(['MSA', 'AA', controlId, 'OK']),
|
|
5257
|
+
]);
|
|
5258
|
+
}
|
|
5259
|
+
static parse(text) {
|
|
5260
|
+
if (!text.startsWith('MSH|^~\\&')) {
|
|
5261
|
+
const err = new Error('Invalid HL7 message');
|
|
5262
|
+
err.type = 'entity.parse.failed';
|
|
5263
|
+
throw err;
|
|
5264
|
+
}
|
|
5265
|
+
return new Hl7Message(text.split(/[\r\n]+/).map((line) => Hl7Segment.parse(line)));
|
|
5266
|
+
}
|
|
5267
|
+
}
|
|
5268
|
+
/**
|
|
5269
|
+
* The Hl7Segment class represents one HL7 segment.
|
|
5270
|
+
* A segment is a collection of fields.
|
|
5271
|
+
* The name field is the first field.
|
|
5272
|
+
* Note that we do not strictly parse messages, and only use default delimeters.
|
|
5273
|
+
*/
|
|
5274
|
+
class Hl7Segment {
|
|
5275
|
+
constructor(fields) {
|
|
5276
|
+
if (isStringArray(fields)) {
|
|
5277
|
+
this.fields = fields.map((f) => Hl7Field.parse(f));
|
|
5278
|
+
}
|
|
5279
|
+
else {
|
|
5280
|
+
this.fields = fields;
|
|
5281
|
+
}
|
|
5282
|
+
this.name = this.fields[0].components[0];
|
|
5283
|
+
}
|
|
5284
|
+
get(index) {
|
|
5285
|
+
return this.fields[index];
|
|
5286
|
+
}
|
|
5287
|
+
toString() {
|
|
5288
|
+
return this.fields.map((f) => f.toString()).join(FIELD_SEPARATOR);
|
|
5289
|
+
}
|
|
5290
|
+
static parse(text) {
|
|
5291
|
+
return new Hl7Segment(text.split(FIELD_SEPARATOR).map((f) => Hl7Field.parse(f)));
|
|
5292
|
+
}
|
|
5293
|
+
}
|
|
5294
|
+
/**
|
|
5295
|
+
* The Hl7Field class represents one HL7 field.
|
|
5296
|
+
* A field is a collection of components.
|
|
5297
|
+
* Note that we do not strictly parse messages, and only use default delimeters.
|
|
5298
|
+
*/
|
|
5299
|
+
class Hl7Field {
|
|
5300
|
+
constructor(components) {
|
|
5301
|
+
this.components = components;
|
|
2559
5302
|
}
|
|
2560
5303
|
get(index) {
|
|
2561
5304
|
return this.components[index];
|
|
@@ -2651,7 +5394,12 @@ function getSearchParameterType(searchParam, propertyType) {
|
|
|
2651
5394
|
let type = SearchParameterType.TEXT;
|
|
2652
5395
|
switch (searchParam.type) {
|
|
2653
5396
|
case 'date':
|
|
2654
|
-
|
|
5397
|
+
if (propertyType === PropertyType.dateTime || propertyType === PropertyType.instant) {
|
|
5398
|
+
type = SearchParameterType.DATETIME;
|
|
5399
|
+
}
|
|
5400
|
+
else {
|
|
5401
|
+
type = SearchParameterType.DATE;
|
|
5402
|
+
}
|
|
2655
5403
|
break;
|
|
2656
5404
|
case 'number':
|
|
2657
5405
|
type = SearchParameterType.NUMBER;
|
|
@@ -2694,5 +5442,5 @@ function simplifyExpression(input) {
|
|
|
2694
5442
|
return result;
|
|
2695
5443
|
}
|
|
2696
5444
|
|
|
2697
|
-
export { COMPONENT_SEPARATOR, DEFAULT_SEARCH_COUNT, FIELD_SEPARATOR, Hl7Field, Hl7Message, Hl7Segment, LRUCache, MedplumClient, OperationOutcomeError, Operator, PropertyType, ReadablePromise, SEGMENT_SEPARATOR, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, calculateAge, calculateAgeString, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getExtensionValue, getImageSrc, getPropertyDisplayName, getQuestionnaireAnswers, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isObject, isOk, isProfileResource, isStringArray, isUUID, notFound, notModified, parseSearchDefinition, resolveId, stringify };
|
|
5445
|
+
export { COMPONENT_SEPARATOR, DEFAULT_SEARCH_COUNT, FIELD_SEPARATOR, Hl7Field, Hl7Message, Hl7Segment, LRUCache, MedplumClient, OperationOutcomeError, Operator, PropertyType, ReadablePromise, SEGMENT_SEPARATOR, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, calculateAge, calculateAgeString, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals$1 as deepEquals, evalFhirPath, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getExtensionValue, getIdentifier, getImageSrc, getPropertyDisplayName, getQuestionnaireAnswers, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isObject$1 as isObject, isOk, isProfileResource, isStringArray, isUUID, notFound, notModified, parseFhirPath, parseSearchDefinition, resolveId, stringify, tokenize };
|
|
2698
5446
|
//# sourceMappingURL=index.js.map
|