@hedia/recommendation-screen 2.0.1 → 2.1.0
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.d.ts +2 -2
- package/App.jsx +3 -20
- package/coverage/clover.xml +700 -0
- package/coverage/coverage-final.json +28 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +201 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/src/RecommendationScreen.tsx.html +1460 -0
- package/coverage/lcov-report/src/__tests__/index.html +111 -0
- package/coverage/lcov-report/src/__tests__/utils.tsx.html +512 -0
- package/coverage/lcov-report/src/components/Header.tsx.html +347 -0
- package/coverage/lcov-report/src/components/InfoBars.tsx.html +404 -0
- package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +374 -0
- package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +191 -0
- package/coverage/lcov-report/src/components/LineSeparator.tsx.html +152 -0
- package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +383 -0
- package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +737 -0
- package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +857 -0
- package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +605 -0
- package/coverage/lcov-report/src/components/Remeasure.tsx.html +440 -0
- package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +380 -0
- package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +635 -0
- package/coverage/lcov-report/src/components/activity/Activity.tsx.html +311 -0
- package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +242 -0
- package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +257 -0
- package/coverage/lcov-report/src/components/activity/index.html +141 -0
- package/coverage/lcov-report/src/components/index.html +276 -0
- package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +278 -0
- package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +260 -0
- package/coverage/lcov-report/src/components/mood/index.html +126 -0
- package/coverage/lcov-report/src/index.html +111 -0
- package/coverage/lcov-report/src/locale/i18nUtils.ts.html +161 -0
- package/coverage/lcov-report/src/locale/index.html +111 -0
- package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +326 -0
- package/coverage/lcov-report/src/utils/Constants.ts.html +176 -0
- package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +500 -0
- package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +467 -0
- package/coverage/lcov-report/src/utils/Translations.ts.html +107 -0
- package/coverage/lcov-report/src/utils/Utils.ts.html +263 -0
- package/coverage/lcov-report/src/utils/Validations.ts.html +815 -0
- package/coverage/lcov-report/src/utils/index.html +201 -0
- package/coverage/lcov.info +1581 -0
- package/jest.config.js +2 -1
- package/package.json +2 -2
- package/src/RecommendationScreen.d.ts +2 -3
- package/src/__tests__/RecommendationUtils.test.js +6 -29
- package/src/__tests__/Utils.test.js +1 -1
- package/src/__tests__/Validations.test.js +19 -7
- package/src/__tests__/components/Emotion.test.jsx +7 -8
- package/src/__tests__/utils.d.ts +3 -1
- package/src/__tests__/utils.jsx +38 -9
- package/src/components/Icon.d.ts +13 -0
- package/src/components/Icon.jsx +42 -0
- package/src/components/LimitationMessage.d.ts +1 -2
- package/src/components/RecommendationModal.d.ts +2 -3
- package/src/components/RecommendationModal.jsx +2 -1
- package/src/components/activity/ActivityIntensity.jsx +4 -3
- 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/utils/AttentionMessages.d.ts +16 -10
- package/src/utils/AttentionMessages.jsx +15 -10
- package/src/utils/RecommendationError.d.ts +1 -0
- package/src/utils/RecommendationError.jsx +3 -1
- package/src/utils/RecommendationUtils.d.ts +2 -3
- package/src/utils/RecommendationUtils.js +10 -6
- package/src/utils/Utils.d.ts +2 -1
- package/src/utils/Utils.js +5 -1
- package/src/utils/Validations.d.ts +2 -1
- package/src/utils/Validations.js +25 -13
- package/tsconfig.json +7 -5
- package/App.tsx +0 -157
- package/index.ts +0 -6
- package/src/RecommendationScreen.tsx +0 -461
- package/src/__tests__/RecommendationScreen.test.tsx +0 -1231
- package/src/__tests__/RecommendationUtils.test.ts +0 -356
- package/src/__tests__/Translate.test.tsx +0 -31
- package/src/__tests__/Utils.test.ts +0 -91
- package/src/__tests__/Validations.test.ts +0 -625
- package/src/__tests__/components/Activity.test.tsx +0 -163
- package/src/__tests__/components/Emotion.test.tsx +0 -110
- package/src/__tests__/components/Header.test.tsx +0 -44
- package/src/__tests__/components/InfoBars.test.tsx +0 -152
- package/src/__tests__/components/InvisibleNumberInput.test.tsx +0 -294
- package/src/__tests__/components/LimitationMessage.test.tsx +0 -58
- package/src/__tests__/components/MoodIcon.test.tsx +0 -45
- package/src/__tests__/components/RecommendationModal.test.tsx +0 -169
- package/src/__tests__/components/RecommendedCarbs.test.tsx +0 -234
- package/src/__tests__/components/RecommendedInsulin.test.tsx +0 -241
- package/src/__tests__/components/Remeasure.test.tsx +0 -97
- package/src/__tests__/components/TransferToLogbook.test.tsx +0 -38
- package/src/__tests__/components/TwoOptionModal.test.tsx +0 -72
- package/src/__tests__/utils.tsx +0 -116
- package/src/components/Header.tsx +0 -89
- package/src/components/Icon.js +0 -41
- package/src/components/InfoBars.tsx +0 -108
- package/src/components/InvisibleNumberInput.tsx +0 -98
- package/src/components/LimitationMessage.tsx +0 -38
- package/src/components/LineSeparator.tsx +0 -24
- package/src/components/RecentInsulin.tsx +0 -101
- package/src/components/RecommendationModal.tsx +0 -224
- package/src/components/RecommendedCarbs.tsx +0 -259
- package/src/components/RecommendedInsulin.tsx +0 -175
- package/src/components/Remeasure.tsx +0 -120
- package/src/components/TransferToLogbook.tsx +0 -100
- package/src/components/TwoOptionModal.tsx +0 -185
- package/src/components/activity/Activity.tsx +0 -77
- package/src/components/activity/ActivityIcon.tsx +0 -54
- package/src/components/activity/ActivityIntensity.tsx +0 -58
- package/src/components/mood/Emotion.tsx +0 -66
- package/src/components/mood/MoodIcon.tsx +0 -60
- package/src/locale/CleanLanguage.ts +0 -13
- package/src/locale/i18nUtils.ts +0 -27
- package/src/types/enum.ts +0 -107
- package/src/types/types.ts +0 -16
- package/src/utils/AttentionMessages.tsx +0 -75
- package/src/utils/Constants.ts +0 -32
- package/src/utils/RecommendationError.tsx +0 -133
- package/src/utils/RecommendationUtils.ts +0 -125
- package/src/utils/Translations.ts +0 -9
- package/src/utils/Utils.ts +0 -57
- package/src/utils/Validations.ts +0 -233
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export declare const AttentionMessage: {
|
|
2
|
+
SevereHypoglycemia: () => string;
|
|
3
|
+
Hypoglycemia: () => string;
|
|
4
|
+
MildHypoglycemia: () => string;
|
|
5
|
+
NormoglycemiaActivityUnder5MMOL: () => string;
|
|
6
|
+
HyperglycemiaActivity: () => string;
|
|
7
|
+
SevereHyperglycemia: () => string;
|
|
8
|
+
SevereHyperglycemiaActivity: () => string;
|
|
9
|
+
BGLevelNotProvided: null;
|
|
10
|
+
Hyperglycemia: null;
|
|
11
|
+
MildHyperglycemia: null;
|
|
12
|
+
Normoglycemia: null;
|
|
13
|
+
NormoglycemiaUnder5MMOL: null;
|
|
14
|
+
UnsupportedBGLevel: null;
|
|
15
|
+
};
|
|
16
|
+
export declare function addPostponeActivityMessageUnder5MMOL(message: string): string;
|
|
11
17
|
export declare class Messages {
|
|
12
18
|
static VeryLowBGL: () => string;
|
|
13
19
|
static LowBGL: () => string;
|
|
@@ -8,16 +8,21 @@ const types_1 = require("@hedia/types");
|
|
|
8
8
|
const macro_1 = require("@lingui/macro");
|
|
9
9
|
const moment_1 = __importDefault(require("moment"));
|
|
10
10
|
const i18nUtils_1 = require("../locale/i18nUtils");
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
exports.AttentionMessage = {
|
|
12
|
+
SevereHypoglycemia: () => `${Messages.VeryLowBGL()}${`\n`}${Messages.Reminder15Minutes()}`,
|
|
13
|
+
Hypoglycemia: () => `${Messages.LowBGL()}${`\n`}${Messages.Reminder15Minutes()}`,
|
|
14
|
+
MildHypoglycemia: () => Messages.Reminder15Minutes(),
|
|
15
|
+
NormoglycemiaActivityUnder5MMOL: () => Messages.PostponePhysicalActivityUnder5MMOL(),
|
|
16
|
+
HyperglycemiaActivity: () => `${Messages.HighBGL()}${`\n`}${Messages.InsulinKetones()}${`\n`}${Messages.Reminder15Minutes()}${`\n`}${Messages.PostponePhysicalActivity()}`,
|
|
17
|
+
SevereHyperglycemia: () => `${Messages.HighBGL()}${`\n`}${Messages.InsulinKetones()}${`\n`}`,
|
|
18
|
+
SevereHyperglycemiaActivity: () => `${Messages.HighBGL()}${`\n`}${Messages.InsulinKetones()}${`\n`}${Messages.Reminder15Minutes()}${`\n`}${Messages.PostponePhysicalActivity()}`,
|
|
19
|
+
BGLevelNotProvided: null,
|
|
20
|
+
Hyperglycemia: null,
|
|
21
|
+
MildHyperglycemia: null,
|
|
22
|
+
Normoglycemia: null,
|
|
23
|
+
NormoglycemiaUnder5MMOL: null,
|
|
24
|
+
UnsupportedBGLevel: null,
|
|
25
|
+
};
|
|
21
26
|
function addPostponeActivityMessageUnder5MMOL(message) {
|
|
22
27
|
return `${message}${`\n`}${Messages.PostponePhysicalActivityUnder5MMOL()}`;
|
|
23
28
|
}
|
|
@@ -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);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { BgLevel } from "../types/enum";
|
|
2
2
|
import { IActivityParams, logbookEntry } from "../types/types";
|
|
3
|
-
import { AttentionMessage, Messages } from "./AttentionMessages";
|
|
4
3
|
export declare function getBGLevel(currentBGL: number, latestLogbookFrom6Hours: logbookEntry | null): BgLevel;
|
|
5
4
|
export declare function getReminder(bgLevel: BgLevel, carbohydrates: number, userReminder: number, activity: IActivityParams | null): number;
|
|
6
|
-
export declare function getAttentionMessage(bgLevel: BgLevel, activity: IActivityParams | null):
|
|
5
|
+
export declare function getAttentionMessage(bgLevel: BgLevel, activity: IActivityParams | null): string | null;
|
|
7
6
|
export declare function isSevereHyperglycemia(logbook?: logbookEntry | null): boolean;
|
|
8
7
|
export declare function isActivityWithin15Minutes(activity: IActivityParams | null): boolean;
|
|
9
|
-
export declare function getLimitationMessage(wasLimited: boolean, activityReduction: number | null):
|
|
8
|
+
export declare function getLimitationMessage(wasLimited: boolean, activityReduction: number | null): string | null;
|
|
@@ -9,6 +9,7 @@ const enum_1 = require("../types/enum");
|
|
|
9
9
|
const AttentionMessages_1 = require("./AttentionMessages");
|
|
10
10
|
const Constants_1 = require("./Constants");
|
|
11
11
|
const RecommendationError_1 = require("./RecommendationError");
|
|
12
|
+
const Utils_1 = require("./Utils");
|
|
12
13
|
function getBGLevel(currentBGL, latestLogbookFrom6Hours) {
|
|
13
14
|
if (currentBGL === null) {
|
|
14
15
|
return enum_1.BgLevel.BGLevelNotProvided;
|
|
@@ -65,23 +66,26 @@ function getReminder(bgLevel, carbohydrates, userReminder, activity) {
|
|
|
65
66
|
}
|
|
66
67
|
exports.getReminder = getReminder;
|
|
67
68
|
function getAttentionMessage(bgLevel, activity) {
|
|
69
|
+
const key = Utils_1.Utils.getKeyFromValue(enum_1.BgLevel, bgLevel);
|
|
70
|
+
const isAttentionMessageNull = AttentionMessages_1.AttentionMessage[key] === null;
|
|
71
|
+
const isWithin15Minutes = isActivityWithin15Minutes(activity);
|
|
68
72
|
switch (bgLevel) {
|
|
69
73
|
case enum_1.BgLevel.BGLevelNotProvided:
|
|
70
74
|
case enum_1.BgLevel.Normoglycemia:
|
|
71
75
|
case enum_1.BgLevel.MildHyperglycemia:
|
|
72
76
|
return null;
|
|
73
77
|
case enum_1.BgLevel.NormoglycemiaUnder5MMOL:
|
|
74
|
-
return
|
|
78
|
+
return isWithin15Minutes ? AttentionMessages_1.AttentionMessage.NormoglycemiaActivityUnder5MMOL() : null;
|
|
75
79
|
case enum_1.BgLevel.SevereHypoglycemia:
|
|
76
80
|
case enum_1.BgLevel.Hypoglycemia:
|
|
77
81
|
case enum_1.BgLevel.MildHypoglycemia:
|
|
78
|
-
return
|
|
79
|
-
? AttentionMessages_1.addPostponeActivityMessageUnder5MMOL(AttentionMessages_1.AttentionMessage[
|
|
80
|
-
: AttentionMessages_1.AttentionMessage[
|
|
82
|
+
return isWithin15Minutes && !isAttentionMessageNull
|
|
83
|
+
? AttentionMessages_1.addPostponeActivityMessageUnder5MMOL(AttentionMessages_1.AttentionMessage[key]())
|
|
84
|
+
: AttentionMessages_1.AttentionMessage[key]();
|
|
81
85
|
case enum_1.BgLevel.Hyperglycemia:
|
|
82
|
-
return
|
|
86
|
+
return isWithin15Minutes ? AttentionMessages_1.AttentionMessage.HyperglycemiaActivity() : null;
|
|
83
87
|
case enum_1.BgLevel.SevereHyperglycemia:
|
|
84
|
-
return
|
|
88
|
+
return isWithin15Minutes
|
|
85
89
|
? AttentionMessages_1.AttentionMessage.SevereHyperglycemiaActivity()
|
|
86
90
|
: AttentionMessages_1.AttentionMessage.SevereHyperglycemia();
|
|
87
91
|
default:
|
package/src/utils/Utils.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ 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;
|
|
10
10
|
static displayedBKLValue(value: number, unit: BloodKetonesUnit): number;
|
|
11
11
|
static formatUnit: (unit: BloodGlucoseUnit | BloodKetonesUnit) => string;
|
|
12
|
+
static getKeyFromValue<T>(keys: T, value: T[keyof T]): keyof T;
|
|
12
13
|
}
|
package/src/utils/Utils.js
CHANGED
|
@@ -22,7 +22,7 @@ class Utils {
|
|
|
22
22
|
const rounding = Utils.getRounding(injectMethod);
|
|
23
23
|
return Math.round(value * rounding) / rounding;
|
|
24
24
|
}
|
|
25
|
-
static
|
|
25
|
+
static isInRange(value, interval) {
|
|
26
26
|
if (value === null) {
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
@@ -40,6 +40,10 @@ class Utils {
|
|
|
40
40
|
static displayedBKLValue(value, unit) {
|
|
41
41
|
return unit === types_1.BloodKetonesUnit.MMOL_L ? value : Utils.convertBKLToMGDL(value);
|
|
42
42
|
}
|
|
43
|
+
static getKeyFromValue(keys, value) {
|
|
44
|
+
const values = Object.values(keys);
|
|
45
|
+
return Object.keys(keys)[values.indexOf(value)];
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
exports.Utils = Utils;
|
|
45
49
|
Utils.formatUnit = (unit) => {
|
|
@@ -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/tsconfig.json
CHANGED
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
|
|
29
29
|
/* Strict Type-Checking Options */
|
|
30
30
|
//"strict": true, /* Enable all strict type-checking options. */
|
|
31
|
-
|
|
31
|
+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
32
32
|
"strictNullChecks": true, /* Enable strict null checks. */
|
|
33
|
-
|
|
33
|
+
"strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
34
34
|
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
36
|
+
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
37
|
+
"noStrictGenericChecks": true,
|
|
37
38
|
|
|
38
39
|
/* Additional Checks */
|
|
39
40
|
"noUnusedLocals": true, /* Report errors on unused locals. */
|
|
@@ -61,7 +62,8 @@
|
|
|
61
62
|
/* Experimental Options */
|
|
62
63
|
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
|
|
63
64
|
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
|
|
64
|
-
"skipLibCheck": true
|
|
65
|
+
"skipLibCheck": true,
|
|
66
|
+
"noErrorTruncation": true
|
|
65
67
|
},
|
|
66
68
|
"exclude": [
|
|
67
69
|
"src/locale/CleanLanguage.ts",
|
package/App.tsx
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { Activity, BloodGlucoseUnit, BloodKetonesUnit, Languages, UserSettings } from "@hedia/types";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import RecommendationScreen from "./src/RecommendationScreen";
|
|
4
|
-
import { IActivityDisplayProps, IRecommendationParams, logbookEntry } from "./src/types/types";
|
|
5
|
-
import { RecommendationError } from "./src/utils/RecommendationError";
|
|
6
|
-
|
|
7
|
-
interface IState {
|
|
8
|
-
params: IRecommendationParams & IActivityDisplayProps;
|
|
9
|
-
carbs: number | null;
|
|
10
|
-
injectionMethod: UserSettings.Enums.InjectionMethod;
|
|
11
|
-
activityDisplayProps: IActivityDisplayProps;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const ActivityEnum = Activity.Enums.ActivityEnum;
|
|
15
|
-
|
|
16
|
-
const { Cycling } = ActivityEnum;
|
|
17
|
-
const { Pump } = UserSettings.Enums.InjectionMethod;
|
|
18
|
-
|
|
19
|
-
export default class App extends React.Component<{}, IState> {
|
|
20
|
-
constructor(props) {
|
|
21
|
-
super(props);
|
|
22
|
-
|
|
23
|
-
const params: IState["params"] = {
|
|
24
|
-
carbohydrateRatio: 10,
|
|
25
|
-
currentBGL: 33, // in order to recommend insulin
|
|
26
|
-
carbohydrates: 1, // in order not to have entered carbs = 0
|
|
27
|
-
insulinSensitivity: 4,
|
|
28
|
-
targetBGL: 6,
|
|
29
|
-
recentBoluses: [
|
|
30
|
-
{
|
|
31
|
-
insulinDose: 2,
|
|
32
|
-
secondsPassed: 1000,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
insulinDose: 1.7,
|
|
36
|
-
secondsPassed: 10000,
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
activityTitle: `Moderate Activity Test Title`,
|
|
40
|
-
activityType: Cycling,
|
|
41
|
-
activity: null,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
this.state = {
|
|
45
|
-
params,
|
|
46
|
-
carbs: 25,
|
|
47
|
-
injectionMethod: Pump,
|
|
48
|
-
activityDisplayProps: {
|
|
49
|
-
activityType: params.activityType,
|
|
50
|
-
activityTitle: params.activityTitle,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public exitCallback = () => {
|
|
56
|
-
console.log(`exitcallback...`);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
public closeCalculationCallback = () => {
|
|
60
|
-
console.log(`closeCalculationCallback...`);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
public removeCarbs = () => {
|
|
64
|
-
this.setState({
|
|
65
|
-
carbs: null,
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
public changeCarbs = (carbs: number) => {
|
|
70
|
-
this.setState({
|
|
71
|
-
carbs,
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
public onYes = () => {
|
|
76
|
-
console.log(`Navigate to recent bolus screen`);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
public updatedRecommendedInsulin = (val: number) => {
|
|
80
|
-
console.log(`Updated recommended insulin: `, val);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
public transferToLogbook = (...params) => {
|
|
84
|
-
console.log(`Transfered:`, params);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
public updateRemeasureTime = (remeasureTime: number) => {
|
|
88
|
-
console.log(`updateRemeasureTime:`, remeasureTime);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
public recommendationAnswer = (carbRecommendationAnswer: boolean) => {
|
|
92
|
-
console.log("carbRecommendationAnswer", carbRecommendationAnswer);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
public showBolusBar = (showBolusBar: boolean) => {
|
|
96
|
-
console.log("showBolusBar", showBolusBar);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
public restartCalculation = () => {
|
|
100
|
-
console.log("restart calculation");
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
public handleError = (error: RecommendationError) => {
|
|
104
|
-
console.log(JSON.stringify(error));
|
|
105
|
-
|
|
106
|
-
switch (error.type) {
|
|
107
|
-
default:
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
public render(): JSX.Element {
|
|
113
|
-
const logbook1: logbookEntry = {
|
|
114
|
-
blood_glucose_millimolar: 16,
|
|
115
|
-
carbohydrates_entered_grams: 25,
|
|
116
|
-
carbohydrates_suggested_grams: 25,
|
|
117
|
-
client_timestamp: `25`,
|
|
118
|
-
client_version: `25`,
|
|
119
|
-
entry_timestamp: `25`,
|
|
120
|
-
event_uuid: null,
|
|
121
|
-
insulin_entered_units: 25,
|
|
122
|
-
insulin_suggested_units: 25,
|
|
123
|
-
is_deleted: null,
|
|
124
|
-
mood: 2,
|
|
125
|
-
settings_uuid: `25`,
|
|
126
|
-
uuid: `aaa`,
|
|
127
|
-
device_and_os: `iOS 12.1.2`,
|
|
128
|
-
overwritten_by_id: null,
|
|
129
|
-
server_timestamp: null,
|
|
130
|
-
server_version: null,
|
|
131
|
-
utc_timezone_offset: null,
|
|
132
|
-
blood_ketones_millimolar: null,
|
|
133
|
-
carbohydrates_modified_suggested_grams: null,
|
|
134
|
-
};
|
|
135
|
-
return (
|
|
136
|
-
<RecommendationScreen
|
|
137
|
-
latestLogbookFrom6Hours={logbook1}
|
|
138
|
-
language={Languages.en}
|
|
139
|
-
injectionMethod={this.state.injectionMethod}
|
|
140
|
-
calculatorParams={this.state.params}
|
|
141
|
-
userReminder={5}
|
|
142
|
-
bloodGlucoseUnit={BloodGlucoseUnit.MMOL_L}
|
|
143
|
-
bloodKetoneUnit={BloodKetonesUnit.MG_DL}
|
|
144
|
-
currentBKL={0}
|
|
145
|
-
closeCalculationCallback={this.closeCalculationCallback}
|
|
146
|
-
exitCallback={this.exitCallback}
|
|
147
|
-
showBolusBar={this.showBolusBar}
|
|
148
|
-
onRecentInsulinYes={this.onYes}
|
|
149
|
-
transferToLogbook={this.transferToLogbook}
|
|
150
|
-
onError={this.handleError}
|
|
151
|
-
carbRecommendationAnswer={this.recommendationAnswer}
|
|
152
|
-
restartCalculation={this.restartCalculation}
|
|
153
|
-
activityDisplayProps={this.state.activityDisplayProps}
|
|
154
|
-
/>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
package/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import RecommendationScreen from "./src/RecommendationScreen";
|
|
2
|
-
import { RecommendationErrorEnum } from "./src/types/enum";
|
|
3
|
-
import * as Errors from "./src/utils/RecommendationError";
|
|
4
|
-
|
|
5
|
-
export default RecommendationScreen;
|
|
6
|
-
export { Errors, RecommendationErrorEnum };
|