ezmedicationinput 0.1.20 → 0.1.21
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/parser.js +29 -17
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/parser.js
CHANGED
|
@@ -1069,13 +1069,10 @@ function reconcileMealTimingSpecificity(internal) {
|
|
|
1069
1069
|
// Optionally replace generic meal tokens with concrete breakfast/lunch/dinner
|
|
1070
1070
|
// EventTiming codes when the cadence makes the intent obvious.
|
|
1071
1071
|
function expandMealTimings(internal, options) {
|
|
1072
|
-
var _a;
|
|
1072
|
+
var _a, _b, _c;
|
|
1073
1073
|
if (!(options === null || options === void 0 ? void 0 : options.smartMealExpansion)) {
|
|
1074
1074
|
return;
|
|
1075
1075
|
}
|
|
1076
|
-
if (!internal.when.length) {
|
|
1077
|
-
return;
|
|
1078
|
-
}
|
|
1079
1076
|
if (internal.when.some((code) => SPECIFIC_MEAL_TIMINGS.has(code))) {
|
|
1080
1077
|
return;
|
|
1081
1078
|
}
|
|
@@ -1083,6 +1080,13 @@ function expandMealTimings(internal, options) {
|
|
|
1083
1080
|
if (!frequency || frequency < 1 || frequency > 4) {
|
|
1084
1081
|
return;
|
|
1085
1082
|
}
|
|
1083
|
+
const hasGeneralMealToken = (0, array_1.arrayIncludes)(internal.when, types_1.EventTiming["Before Meal"]) ||
|
|
1084
|
+
(0, array_1.arrayIncludes)(internal.when, types_1.EventTiming["After Meal"]) ||
|
|
1085
|
+
(0, array_1.arrayIncludes)(internal.when, types_1.EventTiming.Meal);
|
|
1086
|
+
const needsDefaultExpansion = internal.when.length === 0 && frequency >= 2;
|
|
1087
|
+
if (!hasGeneralMealToken && !needsDefaultExpansion) {
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1086
1090
|
if (internal.period !== undefined &&
|
|
1087
1091
|
internal.periodUnit !== undefined &&
|
|
1088
1092
|
(internal.periodUnit !== types_1.FhirPeriodUnit.Day || internal.period !== 1)) {
|
|
@@ -1101,26 +1105,34 @@ function expandMealTimings(internal, options) {
|
|
|
1101
1105
|
}
|
|
1102
1106
|
const pairPreference = (_a = options.twoPerDayPair) !== null && _a !== void 0 ? _a : "breakfast+dinner";
|
|
1103
1107
|
const replacements = [];
|
|
1104
|
-
|
|
1105
|
-
const specifics = computeMealExpansions(
|
|
1108
|
+
const addReplacement = (general, base, removeGeneral) => {
|
|
1109
|
+
const specifics = computeMealExpansions(base, frequency, pairPreference);
|
|
1106
1110
|
if (specifics) {
|
|
1107
|
-
replacements.push({ general
|
|
1111
|
+
replacements.push({ general, specifics, removeGeneral });
|
|
1108
1112
|
}
|
|
1113
|
+
};
|
|
1114
|
+
if ((0, array_1.arrayIncludes)(internal.when, types_1.EventTiming["Before Meal"])) {
|
|
1115
|
+
addReplacement(types_1.EventTiming["Before Meal"], "before", true);
|
|
1109
1116
|
}
|
|
1110
1117
|
if ((0, array_1.arrayIncludes)(internal.when, types_1.EventTiming["After Meal"])) {
|
|
1111
|
-
|
|
1112
|
-
if (specifics) {
|
|
1113
|
-
replacements.push({ general: types_1.EventTiming["After Meal"], specifics });
|
|
1114
|
-
}
|
|
1118
|
+
addReplacement(types_1.EventTiming["After Meal"], "after", true);
|
|
1115
1119
|
}
|
|
1116
1120
|
if ((0, array_1.arrayIncludes)(internal.when, types_1.EventTiming.Meal)) {
|
|
1117
|
-
|
|
1118
|
-
if (specifics) {
|
|
1119
|
-
replacements.push({ general: types_1.EventTiming.Meal, specifics });
|
|
1120
|
-
}
|
|
1121
|
+
addReplacement(types_1.EventTiming.Meal, "with", true);
|
|
1121
1122
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1123
|
+
if (needsDefaultExpansion) {
|
|
1124
|
+
const relation = (_c = (_b = options === null || options === void 0 ? void 0 : options.context) === null || _b === void 0 ? void 0 : _b.mealRelation) !== null && _c !== void 0 ? _c : types_1.EventTiming.Meal;
|
|
1125
|
+
const base = relation === types_1.EventTiming["Before Meal"]
|
|
1126
|
+
? "before"
|
|
1127
|
+
: relation === types_1.EventTiming["After Meal"]
|
|
1128
|
+
? "after"
|
|
1129
|
+
: "with";
|
|
1130
|
+
addReplacement(relation, base, false);
|
|
1131
|
+
}
|
|
1132
|
+
for (const { general, specifics, removeGeneral } of replacements) {
|
|
1133
|
+
if (removeGeneral) {
|
|
1134
|
+
removeWhen(internal.when, general);
|
|
1135
|
+
}
|
|
1124
1136
|
for (const specific of specifics) {
|
|
1125
1137
|
addWhen(internal.when, specific);
|
|
1126
1138
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -285,6 +285,7 @@ export interface MedicationContext {
|
|
|
285
285
|
containerValue?: number;
|
|
286
286
|
containerUnit?: string;
|
|
287
287
|
defaultUnit?: string;
|
|
288
|
+
mealRelation?: (typeof EventTiming)["Before Meal"] | (typeof EventTiming)["After Meal"] | (typeof EventTiming)["Meal"];
|
|
288
289
|
}
|
|
289
290
|
export interface FormatOptions {
|
|
290
291
|
locale?: "en" | "th" | string;
|