@hedia/recommendation-screen 2.0.1 → 2.0.2
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/App.jsx +3 -20
- package/App.tsx +3 -20
- package/package.json +1 -1
- package/src/__tests__/RecommendationUtils.test.js +6 -29
- package/src/__tests__/RecommendationUtils.test.ts +6 -30
- package/src/__tests__/Utils.test.js +1 -1
- package/src/__tests__/Utils.test.ts +1 -1
- package/src/__tests__/Validations.test.js +19 -7
- package/src/__tests__/Validations.test.ts +31 -8
- package/src/__tests__/utils.d.ts +3 -1
- package/src/__tests__/utils.jsx +38 -9
- package/src/__tests__/utils.tsx +37 -9
- package/src/locale/da/messages.js +1 -1
- package/src/locale/da/messages.po +14 -10
- package/src/locale/de/messages.js +1 -1
- package/src/locale/de/messages.po +14 -10
- package/src/locale/en/messages.js +1 -1
- package/src/locale/en/messages.po +14 -10
- package/src/locale/es/messages.js +1 -1
- package/src/locale/es/messages.po +14 -10
- package/src/locale/fr/messages.js +1 -1
- package/src/locale/fr/messages.po +14 -10
- package/src/locale/it/messages.js +1 -1
- package/src/locale/it/messages.po +14 -10
- package/src/types/enum.d.ts +9 -8
- package/src/types/enum.js +9 -8
- package/src/types/enum.ts +1 -0
- package/src/utils/RecommendationError.d.ts +1 -0
- package/src/utils/RecommendationError.jsx +3 -1
- package/src/utils/RecommendationError.tsx +7 -0
- package/src/utils/Utils.d.ts +1 -1
- package/src/utils/Utils.js +1 -1
- package/src/utils/Utils.ts +1 -1
- package/src/utils/Validations.d.ts +2 -1
- package/src/utils/Validations.js +25 -13
- package/src/utils/Validations.ts +25 -13
|
@@ -60,18 +60,22 @@ msgstr "Ricorda di non iniziare l'attività fisica prima che il livello di gluco
|
|
|
60
60
|
msgid "Entered"
|
|
61
61
|
msgstr "Inserito"
|
|
62
62
|
|
|
63
|
-
#: src/utils/RecommendationError.tsx:
|
|
63
|
+
#: src/utils/RecommendationError.tsx:27
|
|
64
64
|
msgid "Error. Hedia Calculator could not find your recent boluses"
|
|
65
65
|
msgstr ""
|
|
66
66
|
|
|
67
|
-
#: src/utils/RecommendationError.tsx:
|
|
67
|
+
#: src/utils/RecommendationError.tsx:25
|
|
68
68
|
msgid "Error. Hedia Calculator does not support an insulin dose greater than {SAFETY_INSULIN_LIMIT} units"
|
|
69
69
|
msgstr "Errore. Hedia Calculator non supporta una dose di insulina superiore a {SAFETY_INSULIN_LIMIT} unità"
|
|
70
70
|
|
|
71
|
-
#: src/utils/RecommendationError.tsx:
|
|
71
|
+
#: src/utils/RecommendationError.tsx:26
|
|
72
72
|
msgid "Error. Hedia Calculator does not support insulin recommendations with boluses older than 4 hours"
|
|
73
73
|
msgstr "Errore. Hedia Calculator non supporta le raccomandazioni di insulina con boli più vecchi di 4 ore"
|
|
74
74
|
|
|
75
|
+
#: src/utils/RecommendationError.tsx:22
|
|
76
|
+
msgid "Error. Hedia Calculator does not support the blood glucose level of your latest logbook entry from the last 6 hours."
|
|
77
|
+
msgstr ""
|
|
78
|
+
|
|
75
79
|
#: src/utils/RecommendationError.tsx:15
|
|
76
80
|
msgid "Error. Hedia Calculator does not support your activity intensity value"
|
|
77
81
|
msgstr "Errore. Hedia Calculator non supporta il valore dell'intensità dell'attività"
|
|
@@ -84,23 +88,23 @@ msgstr "Errore. Hedia Calculator non supporta il valore del tipo di attività"
|
|
|
84
88
|
msgid "Error. Hedia Calculator does not support your current blood glucose level."
|
|
85
89
|
msgstr "Errore. Hedia Calculator non supporta il livello attuale di glucosio nel sangue."
|
|
86
90
|
|
|
87
|
-
#: src/utils/RecommendationError.tsx:
|
|
91
|
+
#: src/utils/RecommendationError.tsx:32
|
|
88
92
|
msgid "Error. Hedia Calculator does not support your current blood glucose unit."
|
|
89
93
|
msgstr "Errore. Hedia Calculator non supporta l'attuale unità misura di glucosio nel sangue."
|
|
90
94
|
|
|
91
|
-
#: src/utils/RecommendationError.tsx:
|
|
95
|
+
#: src/utils/RecommendationError.tsx:23
|
|
92
96
|
msgid "Error. Hedia Calculator does not support your current blood ketone level."
|
|
93
97
|
msgstr "Errore. Hedia Calculator non supporta l'attuale livello di chetoni nel sangue."
|
|
94
98
|
|
|
95
|
-
#: src/utils/RecommendationError.tsx:
|
|
99
|
+
#: src/utils/RecommendationError.tsx:31
|
|
96
100
|
msgid "Error. Hedia Calculator does not support your current blood ketone unit."
|
|
97
101
|
msgstr "Errore. Hedia Calculator non supporta l'attuale unità di misura di chetoni del sangue."
|
|
98
102
|
|
|
99
|
-
#: src/utils/RecommendationError.tsx:
|
|
103
|
+
#: src/utils/RecommendationError.tsx:30
|
|
100
104
|
msgid "Error. Hedia Calculator does not support your current language."
|
|
101
105
|
msgstr "Errore. Hedia Calculator non supporta la lingua corrente."
|
|
102
106
|
|
|
103
|
-
#: src/utils/RecommendationError.tsx:
|
|
107
|
+
#: src/utils/RecommendationError.tsx:29
|
|
104
108
|
msgid "Error. Hedia Calculator does not support your injection method."
|
|
105
109
|
msgstr "Errore. Hedia Calculator non supporta il metodo di iniezione."
|
|
106
110
|
|
|
@@ -124,11 +128,11 @@ msgstr "Errore. Verificare che il valore della sensibilità all'insulina sia cor
|
|
|
124
128
|
msgid "Error. Please verify that your insulin to carb ratio value is correct."
|
|
125
129
|
msgstr "Errore. Verificare che il valore del rapporto insulina/carboidrati sia corretto."
|
|
126
130
|
|
|
127
|
-
#: src/utils/RecommendationError.tsx:
|
|
131
|
+
#: src/utils/RecommendationError.tsx:24
|
|
128
132
|
msgid "Error. Please verify that your target blood glucose value is correct."
|
|
129
133
|
msgstr "Errore. Verificare che il valore obiettivo della glicemia sia corretto."
|
|
130
134
|
|
|
131
|
-
#: src/utils/RecommendationError.tsx:
|
|
135
|
+
#: src/utils/RecommendationError.tsx:28
|
|
132
136
|
msgid "Error. Please verify your notifications settings."
|
|
133
137
|
msgstr "Errore. Verificare le impostazioni di notifica."
|
|
134
138
|
|
package/src/types/enum.d.ts
CHANGED
|
@@ -55,14 +55,15 @@ export declare enum RecommendationErrorEnum {
|
|
|
55
55
|
CarbohydrateLimit = 9,
|
|
56
56
|
InsulinSensitivity = 10,
|
|
57
57
|
InsulinToCarbsRatio = 11,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
LatestLogbook6HoursBGL = 12,
|
|
59
|
+
CurrentBGL = 13,
|
|
60
|
+
CurrentBKL = 14,
|
|
61
|
+
TargetBGL = 15,
|
|
62
|
+
UserReminder = 16,
|
|
63
|
+
Language = 17,
|
|
64
|
+
InjectionMethod = 18,
|
|
65
|
+
BloodKetoneUnit = 19,
|
|
66
|
+
BloodGlucoseUnit = 20
|
|
66
67
|
}
|
|
67
68
|
export declare enum BgLevel {
|
|
68
69
|
SevereHypoglycemia = 0,
|
package/src/types/enum.js
CHANGED
|
@@ -68,14 +68,15 @@ var RecommendationErrorEnum;
|
|
|
68
68
|
RecommendationErrorEnum[RecommendationErrorEnum["CarbohydrateLimit"] = 9] = "CarbohydrateLimit";
|
|
69
69
|
RecommendationErrorEnum[RecommendationErrorEnum["InsulinSensitivity"] = 10] = "InsulinSensitivity";
|
|
70
70
|
RecommendationErrorEnum[RecommendationErrorEnum["InsulinToCarbsRatio"] = 11] = "InsulinToCarbsRatio";
|
|
71
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
72
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
73
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
74
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
75
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
76
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
77
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
78
|
-
RecommendationErrorEnum[RecommendationErrorEnum["
|
|
71
|
+
RecommendationErrorEnum[RecommendationErrorEnum["LatestLogbook6HoursBGL"] = 12] = "LatestLogbook6HoursBGL";
|
|
72
|
+
RecommendationErrorEnum[RecommendationErrorEnum["CurrentBGL"] = 13] = "CurrentBGL";
|
|
73
|
+
RecommendationErrorEnum[RecommendationErrorEnum["CurrentBKL"] = 14] = "CurrentBKL";
|
|
74
|
+
RecommendationErrorEnum[RecommendationErrorEnum["TargetBGL"] = 15] = "TargetBGL";
|
|
75
|
+
RecommendationErrorEnum[RecommendationErrorEnum["UserReminder"] = 16] = "UserReminder";
|
|
76
|
+
RecommendationErrorEnum[RecommendationErrorEnum["Language"] = 17] = "Language";
|
|
77
|
+
RecommendationErrorEnum[RecommendationErrorEnum["InjectionMethod"] = 18] = "InjectionMethod";
|
|
78
|
+
RecommendationErrorEnum[RecommendationErrorEnum["BloodKetoneUnit"] = 19] = "BloodKetoneUnit";
|
|
79
|
+
RecommendationErrorEnum[RecommendationErrorEnum["BloodGlucoseUnit"] = 20] = "BloodGlucoseUnit";
|
|
79
80
|
})(RecommendationErrorEnum = exports.RecommendationErrorEnum || (exports.RecommendationErrorEnum = {}));
|
|
80
81
|
var BgLevel;
|
|
81
82
|
(function (BgLevel) {
|
package/src/types/enum.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const CarbohydrateLimitError: () => RecommendationError;
|
|
|
13
13
|
export declare const InsulinSensitivityError: () => RecommendationError;
|
|
14
14
|
export declare const InsulinToCarbsRatioError: () => RecommendationError;
|
|
15
15
|
export declare const CurrentBGLError: () => RecommendationError;
|
|
16
|
+
export declare const LatestLogbook6HoursBGLError: () => RecommendationError;
|
|
16
17
|
export declare const CurrentBKLError: () => RecommendationError;
|
|
17
18
|
export declare const TargetBGLError: () => RecommendationError;
|
|
18
19
|
export declare const BolusInsulinDoseError: () => RecommendationError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BloodGlucoseUnitError = exports.BloodKetoneUnitError = exports.LanguageError = exports.InjectionMethodError = exports.UserReminderError = exports.RecentBolusError = exports.BolusInsulinSecondsPassedError = exports.BolusInsulinDoseError = exports.TargetBGLError = exports.CurrentBKLError = exports.CurrentBGLError = exports.InsulinToCarbsRatioError = exports.InsulinSensitivityError = exports.CarbohydrateLimitError = exports.ActivityTargetBGLError = exports.ActivityTypeError = exports.ActivityIntensityError = exports.ActivityDateError = exports.ActivityDurationError = exports.ActivitySettingsError = exports.RecommendationError = void 0;
|
|
3
|
+
exports.BloodGlucoseUnitError = exports.BloodKetoneUnitError = exports.LanguageError = exports.InjectionMethodError = exports.UserReminderError = exports.RecentBolusError = exports.BolusInsulinSecondsPassedError = exports.BolusInsulinDoseError = exports.TargetBGLError = exports.CurrentBKLError = exports.LatestLogbook6HoursBGLError = exports.CurrentBGLError = exports.InsulinToCarbsRatioError = exports.InsulinSensitivityError = exports.CarbohydrateLimitError = exports.ActivityTargetBGLError = exports.ActivityTypeError = exports.ActivityIntensityError = exports.ActivityDateError = exports.ActivityDurationError = exports.ActivitySettingsError = exports.RecommendationError = void 0;
|
|
4
4
|
const types_1 = require("@hedia/types");
|
|
5
5
|
const macro_1 = require("@lingui/macro");
|
|
6
6
|
const i18nUtils_1 = require("../locale/i18nUtils");
|
|
@@ -33,6 +33,8 @@ const InsulinToCarbsRatioError = () => new RecommendationError(i18nUtils_1.i18n.
|
|
|
33
33
|
exports.InsulinToCarbsRatioError = InsulinToCarbsRatioError;
|
|
34
34
|
const CurrentBGLError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Hedia Calculator does not support your current blood glucose level.`), enum_1.RecommendationErrorEnum.CurrentBGL);
|
|
35
35
|
exports.CurrentBGLError = CurrentBGLError;
|
|
36
|
+
const LatestLogbook6HoursBGLError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Hedia Calculator does not support the blood glucose level of your latest logbook entry from the last 6 hours.`), enum_1.RecommendationErrorEnum.LatestLogbook6HoursBGL);
|
|
37
|
+
exports.LatestLogbook6HoursBGLError = LatestLogbook6HoursBGLError;
|
|
36
38
|
const CurrentBKLError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Hedia Calculator does not support your current blood ketone level.`), enum_1.RecommendationErrorEnum.CurrentBKL);
|
|
37
39
|
exports.CurrentBKLError = CurrentBKLError;
|
|
38
40
|
const TargetBGLError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Please verify that your target blood glucose value is correct.`), enum_1.RecommendationErrorEnum.TargetBGL);
|
|
@@ -74,6 +74,13 @@ export const CurrentBGLError = (): RecommendationError =>
|
|
|
74
74
|
i18n._(t`Error. Hedia Calculator does not support your current blood glucose level.`),
|
|
75
75
|
RecommendationErrorEnum.CurrentBGL,
|
|
76
76
|
);
|
|
77
|
+
export const LatestLogbook6HoursBGLError = (): RecommendationError =>
|
|
78
|
+
new RecommendationError(
|
|
79
|
+
i18n._(
|
|
80
|
+
t`Error. Hedia Calculator does not support the blood glucose level of your latest logbook entry from the last 6 hours.`,
|
|
81
|
+
),
|
|
82
|
+
RecommendationErrorEnum.LatestLogbook6HoursBGL,
|
|
83
|
+
);
|
|
77
84
|
export const CurrentBKLError = (): RecommendationError =>
|
|
78
85
|
new RecommendationError(
|
|
79
86
|
i18n._(t`Error. Hedia Calculator does not support your current blood ketone level.`),
|
package/src/utils/Utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { IInterval } from "../types/types";
|
|
|
3
3
|
export declare class Utils {
|
|
4
4
|
static getRounding(method: UserSettings.Enums.InjectionMethod): number;
|
|
5
5
|
static roundValue(value: number, injectMethod: UserSettings.Enums.InjectionMethod): number;
|
|
6
|
-
static
|
|
6
|
+
static isInRange(value: number | null, interval: IInterval): boolean;
|
|
7
7
|
static convertBGLToMGDL(value: number): number;
|
|
8
8
|
static displayedBGLValue(value: number, unit: BloodGlucoseUnit): number;
|
|
9
9
|
static convertBKLToMGDL(value: number): number;
|
package/src/utils/Utils.js
CHANGED
package/src/utils/Utils.ts
CHANGED
|
@@ -27,7 +27,7 @@ export class Utils {
|
|
|
27
27
|
return Math.round(value * rounding) / rounding;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public static
|
|
30
|
+
public static isInRange(value: number | null, interval: IInterval): boolean {
|
|
31
31
|
if (value === null) {
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Activity, BloodGlucoseUnit, BloodKetonesUnit, Languages, UserSettings } from "@hedia/types";
|
|
2
2
|
import { IRecommendationProps } from "../RecommendationScreen";
|
|
3
|
-
import { ActivitySettings, IActivityParams, IRecentBolus } from "../types/types";
|
|
3
|
+
import { ActivitySettings, IActivityParams, IRecentBolus, logbookEntry } from "../types/types";
|
|
4
4
|
export declare function validateParams(props: IRecommendationProps): void;
|
|
5
5
|
export declare function checkLanguage(language: Languages): void;
|
|
6
|
+
export declare function checkLatestLogbook6Hours(logbook: logbookEntry | null): void;
|
|
6
7
|
export declare function checkInjectionMethod(injectionMethod: UserSettings.Enums.InjectionMethod): void;
|
|
7
8
|
export declare function checkBGLUnit(unit: BloodGlucoseUnit): void;
|
|
8
9
|
export declare function checkBKLUnit(unit: BloodKetonesUnit): void;
|
package/src/utils/Validations.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.checkCarbohydrates = exports.checkInsulinToCarbRatio = exports.checkInsulinSensitivity = exports.checkBloodKetoneLevel = exports.checkTargetBGL = exports.checkCurrentBGL = exports.checkActivityTargetBGL = exports.checkActivitySettings = exports.checkActivityDate = exports.checkActivityType = exports.checkActivityIntensity = exports.checkActivityDuration = exports.checkRecentBolusesSecondsPassed = exports.checkRecentBolusesInsulinDose = exports.checkRecentBolus = exports.checkActivity = exports.checkUserReminder = exports.checkBKLUnit = exports.checkBGLUnit = exports.checkInjectionMethod = exports.checkLanguage = exports.validateParams = void 0;
|
|
6
|
+
exports.checkCarbohydrates = exports.checkInsulinToCarbRatio = exports.checkInsulinSensitivity = exports.checkBloodKetoneLevel = exports.checkTargetBGL = exports.checkCurrentBGL = exports.checkActivityTargetBGL = exports.checkActivitySettings = exports.checkActivityDate = exports.checkActivityType = exports.checkActivityIntensity = exports.checkActivityDuration = exports.checkRecentBolusesSecondsPassed = exports.checkRecentBolusesInsulinDose = exports.checkRecentBolus = exports.checkActivity = exports.checkUserReminder = exports.checkBKLUnit = exports.checkBGLUnit = exports.checkInjectionMethod = exports.checkLatestLogbook6Hours = exports.checkLanguage = exports.validateParams = void 0;
|
|
7
7
|
const types_1 = require("@hedia/types");
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
9
|
const Constants_1 = require("./Constants");
|
|
@@ -19,6 +19,7 @@ function validateParams(props) {
|
|
|
19
19
|
checkInjectionMethod(props.injectionMethod);
|
|
20
20
|
checkUserReminder(props.userReminder);
|
|
21
21
|
checkLanguage(props.language);
|
|
22
|
+
checkLatestLogbook6Hours(props.latestLogbookFrom6Hours);
|
|
22
23
|
if (props?.calculatorParams?.activity && props?.activityDisplayProps) {
|
|
23
24
|
checkActivityType(props.activityDisplayProps.activityType);
|
|
24
25
|
}
|
|
@@ -30,6 +31,17 @@ function checkLanguage(language) {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
exports.checkLanguage = checkLanguage;
|
|
34
|
+
function checkLatestLogbook6Hours(logbook) {
|
|
35
|
+
if (logbook === undefined) {
|
|
36
|
+
throw RecommendationError_1.LatestLogbook6HoursBGLError();
|
|
37
|
+
}
|
|
38
|
+
if (logbook !== null) {
|
|
39
|
+
if (!Utils_1.Utils.isInRange(logbook.blood_glucose_millimolar, Constants_1.CURRENT_BGL_MMOL_LIMITS)) {
|
|
40
|
+
throw RecommendationError_1.LatestLogbook6HoursBGLError();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.checkLatestLogbook6Hours = checkLatestLogbook6Hours;
|
|
33
45
|
function checkInjectionMethod(injectionMethod) {
|
|
34
46
|
const check = Object.values(types_1.UserSettings.Enums.InjectionMethod).some((method) => method === injectionMethod);
|
|
35
47
|
if (!check) {
|
|
@@ -52,7 +64,7 @@ function checkBKLUnit(unit) {
|
|
|
52
64
|
}
|
|
53
65
|
exports.checkBKLUnit = checkBKLUnit;
|
|
54
66
|
function checkUserReminder(userReminder) {
|
|
55
|
-
if (!Utils_1.Utils.
|
|
67
|
+
if (!Utils_1.Utils.isInRange(userReminder, Constants_1.REMINDER_HOURS_LIMITS)) {
|
|
56
68
|
throw RecommendationError_1.UserReminderError();
|
|
57
69
|
}
|
|
58
70
|
}
|
|
@@ -86,7 +98,7 @@ function checkRecentBolus(recentBoluses) {
|
|
|
86
98
|
exports.checkRecentBolus = checkRecentBolus;
|
|
87
99
|
function checkRecentBolusesInsulinDose(recentBoluses) {
|
|
88
100
|
recentBoluses.forEach((bolus) => {
|
|
89
|
-
if (!Utils_1.Utils.
|
|
101
|
+
if (!Utils_1.Utils.isInRange(bolus.insulinDose, Constants_1.INSULIN_DOSE_LIMITS)) {
|
|
90
102
|
throw RecommendationError_1.BolusInsulinDoseError();
|
|
91
103
|
}
|
|
92
104
|
});
|
|
@@ -94,14 +106,14 @@ function checkRecentBolusesInsulinDose(recentBoluses) {
|
|
|
94
106
|
exports.checkRecentBolusesInsulinDose = checkRecentBolusesInsulinDose;
|
|
95
107
|
function checkRecentBolusesSecondsPassed(recentBoluses) {
|
|
96
108
|
recentBoluses.forEach((bolus) => {
|
|
97
|
-
if (!Utils_1.Utils.
|
|
109
|
+
if (!Utils_1.Utils.isInRange(bolus.secondsPassed, Constants_1.BOLUS_SECONDS_PASSED_LIMITS)) {
|
|
98
110
|
throw RecommendationError_1.BolusInsulinSecondsPassedError();
|
|
99
111
|
}
|
|
100
112
|
});
|
|
101
113
|
}
|
|
102
114
|
exports.checkRecentBolusesSecondsPassed = checkRecentBolusesSecondsPassed;
|
|
103
115
|
function checkActivityDuration(activityDuration) {
|
|
104
|
-
if (!Utils_1.Utils.
|
|
116
|
+
if (!Utils_1.Utils.isInRange(activityDuration, Constants_1.ACTIVITY_DURATION_MINUTES_LIMITS)) {
|
|
105
117
|
throw RecommendationError_1.ActivityDurationError();
|
|
106
118
|
}
|
|
107
119
|
}
|
|
@@ -134,7 +146,7 @@ function checkActivitySettings(activitySettings) {
|
|
|
134
146
|
const reductionIntervals = activitySettings[intensity];
|
|
135
147
|
for (const interval of Object.keys(reductionIntervals)) {
|
|
136
148
|
const value = activitySettings[intensity][interval];
|
|
137
|
-
const isInInterval = Utils_1.Utils.
|
|
149
|
+
const isInInterval = Utils_1.Utils.isInRange(value, Constants_1.ACTIVITY_SETTINGS_INTERVAL_LIMITS);
|
|
138
150
|
if (intensity === hard && interval === fromFortysix) {
|
|
139
151
|
if (!isInInterval && value !== null) {
|
|
140
152
|
throw RecommendationError_1.ActivitySettingsError();
|
|
@@ -148,47 +160,47 @@ function checkActivitySettings(activitySettings) {
|
|
|
148
160
|
}
|
|
149
161
|
exports.checkActivitySettings = checkActivitySettings;
|
|
150
162
|
function checkActivityTargetBGL(activitySettingsTargetBGL) {
|
|
151
|
-
if (!Utils_1.Utils.
|
|
163
|
+
if (!Utils_1.Utils.isInRange(activitySettingsTargetBGL, Constants_1.ACTIVITY_TARGET_BGL_MMOL_LIMITS)) {
|
|
152
164
|
throw RecommendationError_1.ActivityTargetBGLError();
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
167
|
exports.checkActivityTargetBGL = checkActivityTargetBGL;
|
|
156
168
|
function checkCurrentBGL(currentBGL) {
|
|
157
169
|
if (currentBGL !== null) {
|
|
158
|
-
if (!Utils_1.Utils.
|
|
170
|
+
if (!Utils_1.Utils.isInRange(currentBGL, Constants_1.CURRENT_BGL_MMOL_LIMITS)) {
|
|
159
171
|
throw RecommendationError_1.CurrentBGLError();
|
|
160
172
|
}
|
|
161
173
|
}
|
|
162
174
|
}
|
|
163
175
|
exports.checkCurrentBGL = checkCurrentBGL;
|
|
164
176
|
function checkTargetBGL(targetBGL) {
|
|
165
|
-
if (!Utils_1.Utils.
|
|
177
|
+
if (!Utils_1.Utils.isInRange(targetBGL, Constants_1.TARGET_BGL_MMOL_LIMITS)) {
|
|
166
178
|
throw RecommendationError_1.TargetBGLError();
|
|
167
179
|
}
|
|
168
180
|
}
|
|
169
181
|
exports.checkTargetBGL = checkTargetBGL;
|
|
170
182
|
function checkBloodKetoneLevel(currentBKL) {
|
|
171
183
|
if (currentBKL !== null) {
|
|
172
|
-
if (!Utils_1.Utils.
|
|
184
|
+
if (!Utils_1.Utils.isInRange(currentBKL, Constants_1.CURRENT_BKL_MMOL_LIMITS)) {
|
|
173
185
|
throw RecommendationError_1.CurrentBKLError();
|
|
174
186
|
}
|
|
175
187
|
}
|
|
176
188
|
}
|
|
177
189
|
exports.checkBloodKetoneLevel = checkBloodKetoneLevel;
|
|
178
190
|
function checkInsulinSensitivity(insulinSensitivity) {
|
|
179
|
-
if (!Utils_1.Utils.
|
|
191
|
+
if (!Utils_1.Utils.isInRange(insulinSensitivity, Constants_1.INSULIN_SENSITIVITY_MMOL_LIMITS)) {
|
|
180
192
|
throw RecommendationError_1.InsulinSensitivityError();
|
|
181
193
|
}
|
|
182
194
|
}
|
|
183
195
|
exports.checkInsulinSensitivity = checkInsulinSensitivity;
|
|
184
196
|
function checkInsulinToCarbRatio(insulinToCarbRatio) {
|
|
185
|
-
if (!Utils_1.Utils.
|
|
197
|
+
if (!Utils_1.Utils.isInRange(insulinToCarbRatio, Constants_1.INSULIN_TO_CARBS_RATIO_LIMITS)) {
|
|
186
198
|
throw RecommendationError_1.InsulinToCarbsRatioError();
|
|
187
199
|
}
|
|
188
200
|
}
|
|
189
201
|
exports.checkInsulinToCarbRatio = checkInsulinToCarbRatio;
|
|
190
202
|
function checkCarbohydrates(carbohydrates) {
|
|
191
|
-
if (!Utils_1.Utils.
|
|
203
|
+
if (!Utils_1.Utils.isInRange(carbohydrates, Constants_1.CARBOHYDRATES_LIMTS)) {
|
|
192
204
|
throw RecommendationError_1.CarbohydrateLimitError();
|
|
193
205
|
}
|
|
194
206
|
}
|
package/src/utils/Validations.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Activity, BloodGlucoseUnit, BloodKetonesUnit, Languages, UserSettings } from "@hedia/types";
|
|
2
2
|
import moment from "moment";
|
|
3
3
|
import { IRecommendationProps } from "../RecommendationScreen";
|
|
4
|
-
import { ActivitySettings, IActivityParams, IRecentBolus, IRecommendationParams } from "../types/types";
|
|
4
|
+
import { ActivitySettings, IActivityParams, IRecentBolus, IRecommendationParams, logbookEntry } from "../types/types";
|
|
5
5
|
import {
|
|
6
6
|
ACTIVITY_BUFFER_MINUTES,
|
|
7
7
|
ACTIVITY_DURATION_MINUTES_LIMITS,
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
InsulinSensitivityError,
|
|
37
37
|
InsulinToCarbsRatioError,
|
|
38
38
|
LanguageError,
|
|
39
|
+
LatestLogbook6HoursBGLError,
|
|
39
40
|
RecentBolusError,
|
|
40
41
|
TargetBGLError,
|
|
41
42
|
UserReminderError,
|
|
@@ -55,6 +56,7 @@ export function validateParams(props: IRecommendationProps): void {
|
|
|
55
56
|
checkInjectionMethod(props.injectionMethod);
|
|
56
57
|
checkUserReminder(props.userReminder);
|
|
57
58
|
checkLanguage(props.language);
|
|
59
|
+
checkLatestLogbook6Hours(props.latestLogbookFrom6Hours);
|
|
58
60
|
if (props?.calculatorParams?.activity && props?.activityDisplayProps) {
|
|
59
61
|
checkActivityType(props.activityDisplayProps.activityType);
|
|
60
62
|
}
|
|
@@ -65,6 +67,16 @@ export function checkLanguage(language: Languages): void {
|
|
|
65
67
|
throw LanguageError();
|
|
66
68
|
}
|
|
67
69
|
}
|
|
70
|
+
export function checkLatestLogbook6Hours(logbook: logbookEntry | null): void {
|
|
71
|
+
if (logbook === undefined) {
|
|
72
|
+
throw LatestLogbook6HoursBGLError();
|
|
73
|
+
}
|
|
74
|
+
if (logbook !== null) {
|
|
75
|
+
if (!Utils.isInRange(logbook.blood_glucose_millimolar, CURRENT_BGL_MMOL_LIMITS)) {
|
|
76
|
+
throw LatestLogbook6HoursBGLError();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
68
80
|
|
|
69
81
|
export function checkInjectionMethod(injectionMethod: UserSettings.Enums.InjectionMethod): void {
|
|
70
82
|
const check = Object.values(UserSettings.Enums.InjectionMethod).some(
|
|
@@ -89,7 +101,7 @@ export function checkBKLUnit(unit: BloodKetonesUnit): void {
|
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
export function checkUserReminder(userReminder: number): void {
|
|
92
|
-
if (!Utils.
|
|
104
|
+
if (!Utils.isInRange(userReminder, REMINDER_HOURS_LIMITS)) {
|
|
93
105
|
throw UserReminderError();
|
|
94
106
|
}
|
|
95
107
|
}
|
|
@@ -124,7 +136,7 @@ export function checkRecentBolus(recentBoluses: Array<IRecentBolus>): void {
|
|
|
124
136
|
|
|
125
137
|
export function checkRecentBolusesInsulinDose(recentBoluses: Array<IRecentBolus>): void {
|
|
126
138
|
recentBoluses.forEach((bolus: IRecentBolus): void => {
|
|
127
|
-
if (!Utils.
|
|
139
|
+
if (!Utils.isInRange(bolus.insulinDose, INSULIN_DOSE_LIMITS)) {
|
|
128
140
|
throw BolusInsulinDoseError();
|
|
129
141
|
}
|
|
130
142
|
});
|
|
@@ -132,14 +144,14 @@ export function checkRecentBolusesInsulinDose(recentBoluses: Array<IRecentBolus>
|
|
|
132
144
|
|
|
133
145
|
export function checkRecentBolusesSecondsPassed(recentBoluses: Array<IRecentBolus>): void {
|
|
134
146
|
recentBoluses.forEach((bolus: IRecentBolus): void => {
|
|
135
|
-
if (!Utils.
|
|
147
|
+
if (!Utils.isInRange(bolus.secondsPassed, BOLUS_SECONDS_PASSED_LIMITS)) {
|
|
136
148
|
throw BolusInsulinSecondsPassedError();
|
|
137
149
|
}
|
|
138
150
|
});
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
export function checkActivityDuration(activityDuration: number): void {
|
|
142
|
-
if (!Utils.
|
|
154
|
+
if (!Utils.isInRange(activityDuration, ACTIVITY_DURATION_MINUTES_LIMITS)) {
|
|
143
155
|
throw ActivityDurationError();
|
|
144
156
|
}
|
|
145
157
|
}
|
|
@@ -174,7 +186,7 @@ export function checkActivitySettings(activitySettings: ActivitySettings): void
|
|
|
174
186
|
const reductionIntervals = activitySettings[intensity];
|
|
175
187
|
for (const interval of Object.keys(reductionIntervals) as Array<keyof typeof reductionIntervals>) {
|
|
176
188
|
const value = activitySettings[intensity][interval];
|
|
177
|
-
const isInInterval: boolean = Utils.
|
|
189
|
+
const isInInterval: boolean = Utils.isInRange(value, ACTIVITY_SETTINGS_INTERVAL_LIMITS);
|
|
178
190
|
if (intensity === hard && interval === fromFortysix) {
|
|
179
191
|
if (!isInInterval && value !== null) {
|
|
180
192
|
throw ActivitySettingsError();
|
|
@@ -187,47 +199,47 @@ export function checkActivitySettings(activitySettings: ActivitySettings): void
|
|
|
187
199
|
}
|
|
188
200
|
|
|
189
201
|
export function checkActivityTargetBGL(activitySettingsTargetBGL: number): void {
|
|
190
|
-
if (!Utils.
|
|
202
|
+
if (!Utils.isInRange(activitySettingsTargetBGL, ACTIVITY_TARGET_BGL_MMOL_LIMITS)) {
|
|
191
203
|
throw ActivityTargetBGLError();
|
|
192
204
|
}
|
|
193
205
|
}
|
|
194
206
|
|
|
195
207
|
export function checkCurrentBGL(currentBGL: number): void {
|
|
196
208
|
if (currentBGL !== null) {
|
|
197
|
-
if (!Utils.
|
|
209
|
+
if (!Utils.isInRange(currentBGL, CURRENT_BGL_MMOL_LIMITS)) {
|
|
198
210
|
throw CurrentBGLError();
|
|
199
211
|
}
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
214
|
|
|
203
215
|
export function checkTargetBGL(targetBGL: number): void {
|
|
204
|
-
if (!Utils.
|
|
216
|
+
if (!Utils.isInRange(targetBGL, TARGET_BGL_MMOL_LIMITS)) {
|
|
205
217
|
throw TargetBGLError();
|
|
206
218
|
}
|
|
207
219
|
}
|
|
208
220
|
|
|
209
221
|
export function checkBloodKetoneLevel(currentBKL: number): void {
|
|
210
222
|
if (currentBKL !== null) {
|
|
211
|
-
if (!Utils.
|
|
223
|
+
if (!Utils.isInRange(currentBKL, CURRENT_BKL_MMOL_LIMITS)) {
|
|
212
224
|
throw CurrentBKLError();
|
|
213
225
|
}
|
|
214
226
|
}
|
|
215
227
|
}
|
|
216
228
|
|
|
217
229
|
export function checkInsulinSensitivity(insulinSensitivity: number): void {
|
|
218
|
-
if (!Utils.
|
|
230
|
+
if (!Utils.isInRange(insulinSensitivity, INSULIN_SENSITIVITY_MMOL_LIMITS)) {
|
|
219
231
|
throw InsulinSensitivityError();
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
234
|
|
|
223
235
|
export function checkInsulinToCarbRatio(insulinToCarbRatio: number): void {
|
|
224
|
-
if (!Utils.
|
|
236
|
+
if (!Utils.isInRange(insulinToCarbRatio, INSULIN_TO_CARBS_RATIO_LIMITS)) {
|
|
225
237
|
throw InsulinToCarbsRatioError();
|
|
226
238
|
}
|
|
227
239
|
}
|
|
228
240
|
|
|
229
241
|
export function checkCarbohydrates(carbohydrates: number): void {
|
|
230
|
-
if (!Utils.
|
|
242
|
+
if (!Utils.isInRange(carbohydrates, CARBOHYDRATES_LIMTS)) {
|
|
231
243
|
throw CarbohydrateLimitError();
|
|
232
244
|
}
|
|
233
245
|
}
|