@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/esm/index.js
CHANGED
|
@@ -6768,6 +6768,34 @@ function deepEquals(object1, object2) {
|
|
|
6768
6768
|
function isObject(object) {
|
|
6769
6769
|
return object !== null && typeof object === 'object';
|
|
6770
6770
|
}
|
|
6771
|
+
/**
|
|
6772
|
+
* Calculates the age in years from the birth date.
|
|
6773
|
+
* @param birthDateStr The birth date or start date in ISO-8601 format YYYY-MM-DD.
|
|
6774
|
+
* @param endDateStr Optional end date in ISO-8601 format YYYY-MM-DD. Default value is today.
|
|
6775
|
+
* @returns The age in years, months, and days.
|
|
6776
|
+
*/
|
|
6777
|
+
function calculateAge(birthDateStr, endDateStr) {
|
|
6778
|
+
const startDate = new Date(birthDateStr);
|
|
6779
|
+
startDate.setUTCHours(0, 0, 0, 0);
|
|
6780
|
+
const endDate = endDateStr ? new Date(endDateStr) : new Date();
|
|
6781
|
+
endDate.setUTCHours(0, 0, 0, 0);
|
|
6782
|
+
const startYear = startDate.getUTCFullYear();
|
|
6783
|
+
const startMonth = startDate.getUTCMonth();
|
|
6784
|
+
const startDay = startDate.getUTCDate();
|
|
6785
|
+
const endYear = endDate.getUTCFullYear();
|
|
6786
|
+
const endMonth = endDate.getUTCMonth();
|
|
6787
|
+
const endDay = endDate.getUTCDate();
|
|
6788
|
+
let years = endYear - startYear;
|
|
6789
|
+
if (endMonth < startMonth || (endMonth === startMonth && endDay < startDay)) {
|
|
6790
|
+
years--;
|
|
6791
|
+
}
|
|
6792
|
+
let months = endYear * 12 + endMonth - (startYear * 12 + startMonth);
|
|
6793
|
+
if (endDay < startDay) {
|
|
6794
|
+
months--;
|
|
6795
|
+
}
|
|
6796
|
+
const days = Math.floor((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
|
|
6797
|
+
return { years, months, days };
|
|
6798
|
+
}
|
|
6771
6799
|
|
|
6772
6800
|
class FhirPathAtom {
|
|
6773
6801
|
constructor(original, child) {
|
|
@@ -8420,6 +8448,30 @@ function timeOfDay() {
|
|
|
8420
8448
|
function today() {
|
|
8421
8449
|
return [new Date().toISOString().substring(0, 10)];
|
|
8422
8450
|
}
|
|
8451
|
+
/**
|
|
8452
|
+
* Calculates the difference between two dates or date/times.
|
|
8453
|
+
*
|
|
8454
|
+
* This is not part of the official FHIRPath spec.
|
|
8455
|
+
*
|
|
8456
|
+
* IBM FHIR issue: https://github.com/IBM/FHIR/issues/1014
|
|
8457
|
+
* IBM FHIR PR: https://github.com/IBM/FHIR/pull/1023
|
|
8458
|
+
*/
|
|
8459
|
+
function between(context, startAtom, endAtom, unitsAtom) {
|
|
8460
|
+
const startDate = toDateTime(ensureArray(startAtom.eval(context)));
|
|
8461
|
+
if (startDate.length === 0) {
|
|
8462
|
+
throw new Error('Invalid start date');
|
|
8463
|
+
}
|
|
8464
|
+
const endDate = toDateTime(ensureArray(endAtom.eval(context)));
|
|
8465
|
+
if (endDate.length === 0) {
|
|
8466
|
+
throw new Error('Invalid end date');
|
|
8467
|
+
}
|
|
8468
|
+
const unit = unitsAtom.eval(context);
|
|
8469
|
+
if (unit !== 'years' && unit !== 'months' && unit !== 'days') {
|
|
8470
|
+
throw new Error('Invalid units');
|
|
8471
|
+
}
|
|
8472
|
+
const age = calculateAge(startDate[0], endDate[0]);
|
|
8473
|
+
return [{ value: age[unit], unit }];
|
|
8474
|
+
}
|
|
8423
8475
|
/*
|
|
8424
8476
|
* 6.3 Types
|
|
8425
8477
|
*/
|
|
@@ -8640,6 +8692,7 @@ var functions = /*#__PURE__*/Object.freeze({
|
|
|
8640
8692
|
now: now,
|
|
8641
8693
|
timeOfDay: timeOfDay,
|
|
8642
8694
|
today: today,
|
|
8695
|
+
between: between,
|
|
8643
8696
|
is: is,
|
|
8644
8697
|
not: not,
|
|
8645
8698
|
resolve: resolve,
|