@medplum/mock 0.9.5 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +53 -0
- 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/esm/index.js +53 -0
- 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/package.json +6 -6
package/dist/cjs/index.js
CHANGED
|
@@ -6772,6 +6772,34 @@
|
|
|
6772
6772
|
function isObject(object) {
|
|
6773
6773
|
return object !== null && typeof object === 'object';
|
|
6774
6774
|
}
|
|
6775
|
+
/**
|
|
6776
|
+
* Calculates the age in years from the birth date.
|
|
6777
|
+
* @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
|
|
6778
|
+
* @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
|
|
6779
|
+
* @returns The age in years, months, and days.
|
|
6780
|
+
*/
|
|
6781
|
+
function calculateAge(birthDateStr, endDateStr) {
|
|
6782
|
+
const startDate = new Date(birthDateStr);
|
|
6783
|
+
startDate.setUTCHours(0, 0, 0, 0);
|
|
6784
|
+
const endDate = endDateStr ? new Date(endDateStr) : new Date();
|
|
6785
|
+
endDate.setUTCHours(0, 0, 0, 0);
|
|
6786
|
+
const startYear = startDate.getUTCFullYear();
|
|
6787
|
+
const startMonth = startDate.getUTCMonth();
|
|
6788
|
+
const startDay = startDate.getUTCDate();
|
|
6789
|
+
const endYear = endDate.getUTCFullYear();
|
|
6790
|
+
const endMonth = endDate.getUTCMonth();
|
|
6791
|
+
const endDay = endDate.getUTCDate();
|
|
6792
|
+
let years = endYear - startYear;
|
|
6793
|
+
if (endMonth < startMonth || (endMonth === startMonth && endDay < startDay)) {
|
|
6794
|
+
years--;
|
|
6795
|
+
}
|
|
6796
|
+
let months = endYear * 12 + endMonth - (startYear * 12 + startMonth);
|
|
6797
|
+
if (endDay < startDay) {
|
|
6798
|
+
months--;
|
|
6799
|
+
}
|
|
6800
|
+
const days = Math.floor((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
|
|
6801
|
+
return { years, months, days };
|
|
6802
|
+
}
|
|
6775
6803
|
|
|
6776
6804
|
class FhirPathAtom {
|
|
6777
6805
|
constructor(original, child) {
|
|
@@ -8424,6 +8452,30 @@
|
|
|
8424
8452
|
function today() {
|
|
8425
8453
|
return [new Date().toISOString().substring(0, 10)];
|
|
8426
8454
|
}
|
|
8455
|
+
/**
|
|
8456
|
+
* Calculates the difference between two dates or date/times.
|
|
8457
|
+
*
|
|
8458
|
+
* This is not part of the official FHIRPath spec.
|
|
8459
|
+
*
|
|
8460
|
+
* IBM FHIR issue: https://github.com/IBM/FHIR/issues/1014
|
|
8461
|
+
* IBM FHIR PR: https://github.com/IBM/FHIR/pull/1023
|
|
8462
|
+
*/
|
|
8463
|
+
function between(context, startAtom, endAtom, unitsAtom) {
|
|
8464
|
+
const startDate = toDateTime(ensureArray(startAtom.eval(context)));
|
|
8465
|
+
if (startDate.length === 0) {
|
|
8466
|
+
throw new Error('Invalid start date');
|
|
8467
|
+
}
|
|
8468
|
+
const endDate = toDateTime(ensureArray(endAtom.eval(context)));
|
|
8469
|
+
if (endDate.length === 0) {
|
|
8470
|
+
throw new Error('Invalid end date');
|
|
8471
|
+
}
|
|
8472
|
+
const unit = unitsAtom.eval(context);
|
|
8473
|
+
if (unit !== 'years' && unit !== 'months' && unit !== 'days') {
|
|
8474
|
+
throw new Error('Invalid units');
|
|
8475
|
+
}
|
|
8476
|
+
const age = calculateAge(startDate[0], endDate[0]);
|
|
8477
|
+
return [{ value: age[unit], unit }];
|
|
8478
|
+
}
|
|
8427
8479
|
/*
|
|
8428
8480
|
* 6.3 Types
|
|
8429
8481
|
*/
|
|
@@ -8644,6 +8696,7 @@
|
|
|
8644
8696
|
now: now,
|
|
8645
8697
|
timeOfDay: timeOfDay,
|
|
8646
8698
|
today: today,
|
|
8699
|
+
between: between,
|
|
8647
8700
|
is: is,
|
|
8648
8701
|
not: not,
|
|
8649
8702
|
resolve: resolve,
|