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