@hedia/recommendation-screen 2.1.15 → 2.1.16
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/coverage/clover.xml +586 -588
- package/coverage/coverage-final.json +27 -27
- package/coverage/lcov-report/index.html +7 -7
- package/coverage/lcov-report/src/RecommendationScreen.tsx.html +979 -10
- package/coverage/lcov-report/src/__tests__/index.html +1 -1
- package/coverage/lcov-report/src/__tests__/utils.tsx.html +29 -8
- package/coverage/lcov-report/src/components/Header.tsx.html +13 -4
- package/coverage/lcov-report/src/components/InfoBars.tsx.html +86 -2
- package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +196 -4
- package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +20 -2
- package/coverage/lcov-report/src/components/LineSeparator.tsx.html +12 -3
- package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +30 -3
- package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +184 -4
- package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +205 -7
- package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +187 -19
- package/coverage/lcov-report/src/components/Remeasure.tsx.html +114 -3
- package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +67 -4
- package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +34 -10
- package/coverage/lcov-report/src/components/activity/Activity.tsx.html +58 -7
- package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +42 -3
- package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +30 -6
- package/coverage/lcov-report/src/components/activity/index.html +1 -1
- package/coverage/lcov-report/src/components/index.html +10 -10
- package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +78 -3
- package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +80 -5
- package/coverage/lcov-report/src/components/mood/index.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/locale/i18nUtils.ts.html +41 -2
- package/coverage/lcov-report/src/locale/index.html +1 -1
- package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +231 -3
- package/coverage/lcov-report/src/utils/Constants.ts.html +71 -2
- package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +89 -2
- package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +306 -9
- package/coverage/lcov-report/src/utils/Translations.ts.html +27 -3
- package/coverage/lcov-report/src/utils/Utils.ts.html +278 -2
- package/coverage/lcov-report/src/utils/Validations.ts.html +716 -14
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/coverage/lcov.info +1158 -1164
- package/ignore-git.sh +1 -0
- package/ignore-publish.sh +1 -0
- package/package.json +5 -3
- package/src/RecommendationScreen.d.ts +323 -6
- package/src/RecommendationScreen.js +234 -1
- package/src/__tests__/RecommendationScreen.test.js +1 -1
- package/src/__tests__/utils.d.ts +5 -5
- package/src/__tests__/utils.js +1 -1
- package/src/components/Header.d.ts +4 -43
- package/src/components/Header.js +3 -1
- package/src/components/Icon.d.ts +9 -2
- package/src/components/Icon.js +6 -1
- package/src/components/InfoBars.d.ts +28 -0
- package/src/components/InfoBars.js +23 -0
- package/src/components/InvisibleNumberInput.d.ts +66 -3
- package/src/components/InvisibleNumberInput.js +53 -0
- package/src/components/LimitationMessage.d.ts +6 -0
- package/src/components/LimitationMessage.js +4 -0
- package/src/components/LineSeparator.d.ts +4 -2
- package/src/components/LineSeparator.js +2 -0
- package/src/components/RecentInsulin.d.ts +10 -2
- package/src/components/RecentInsulin.js +7 -0
- package/src/components/RecommendationModal.d.ts +61 -3
- package/src/components/RecommendationModal.js +45 -0
- package/src/components/RecommendedCarbs.d.ts +71 -4
- package/src/components/RecommendedCarbs.js +56 -0
- package/src/components/RecommendedInsulin.d.ts +66 -4
- package/src/components/RecommendedInsulin.js +51 -5
- package/src/components/Remeasure.d.ts +38 -2
- package/src/components/Remeasure.js +31 -0
- package/src/components/TransferToLogbook.d.ts +23 -3
- package/src/components/TransferToLogbook.js +18 -0
- package/src/components/TwoOptionModal.d.ts +12 -1
- package/src/components/TwoOptionModal.js +3 -3
- package/src/components/activity/Activity.d.ts +21 -5
- package/src/components/activity/Activity.js +14 -0
- package/src/components/activity/ActivityIcon.d.ts +15 -0
- package/src/components/activity/ActivityIcon.js +14 -1
- package/src/components/activity/ActivityIntensity.d.ts +11 -4
- package/src/components/activity/ActivityIntensity.js +7 -0
- package/src/components/mood/Emotion.d.ts +26 -1
- package/src/components/mood/Emotion.js +20 -0
- package/src/components/mood/MoodIcon.d.ts +28 -2
- package/src/components/mood/MoodIcon.js +20 -2
- package/src/locale/i18nUtils.d.ts +13 -0
- package/src/locale/i18nUtils.js +13 -0
- package/src/types/enum.d.ts +10 -0
- package/src/types/enum.js +9 -0
- package/src/types/types.d.ts +9 -7
- package/src/utils/AttentionMessages.d.ts +65 -0
- package/src/utils/AttentionMessages.js +65 -1
- package/src/utils/Constants.d.ts +23 -0
- package/src/utils/Constants.js +23 -0
- package/src/utils/RecommendationError.d.ts +29 -0
- package/src/utils/RecommendationError.js +29 -0
- package/src/utils/RecommendationUtils.d.ts +98 -6
- package/src/utils/RecommendationUtils.js +92 -0
- package/src/utils/Translations.d.ts +7 -0
- package/src/utils/Translations.js +7 -0
- package/src/utils/Utils.d.ts +92 -0
- package/src/utils/Utils.js +92 -0
- package/src/utils/Validations.d.ts +232 -9
- package/src/utils/Validations.js +225 -2
- package/typedoc.json +13 -0
package/src/utils/Validations.js
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The validations module contains functions for checking the integrity of every single value that is being passed in to the recommendation screen from the outside.
|
|
3
|
+
* If any of the individual integrity checks fails, then an exception will be thrown to indicate that the data that was passed in is untrustworthy
|
|
4
|
+
* and prevent a recommendation to be shown to the user based on the corrupted data.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { Activity, BloodGlucoseUnit, BloodKetonesUnit, Languages, UserSettings, } from "@hedia/types";
|
|
2
8
|
import moment from "moment";
|
|
3
9
|
import { ACTIVITY_BUFFER_MINUTES, ACTIVITY_DURATION_MINUTES_LIMITS, ACTIVITY_SETTINGS_INTERVAL_LIMITS, ACTIVITY_TARGET_BGL_MMOL_LIMITS, BOLUS_SECONDS_PASSED_LIMITS, CARBOHYDRATES_LIMTS, CURRENT_BGL_MMOL_LIMITS, CURRENT_BKL_MMOL_LIMITS, INSULIN_DOSE_LIMITS, INSULIN_SENSITIVITY_MMOL_LIMITS, INSULIN_TO_CARBS_RATIO_LIMITS, ONE_HOUR_MINUTES, REMINDER_HOURS_LIMITS, TARGET_BGL_MMOL_LIMITS, } from "./Constants";
|
|
4
10
|
import { ActivityDateError, ActivityDurationError, ActivityIntensityError, ActivitySettingsError, ActivityTargetBGLError, ActivityTypeError, BloodGlucoseUnitError, BloodKetonePropsError, BloodKetoneUnitError, BolusInsulinDoseError, BolusInsulinSecondsPassedError, CarbohydrateLimitError, CurrentBGLError, CurrentBKLError, InjectionMethodError, InsulinSensitivityError, InsulinToCarbsRatioError, LanguageError, LatestLogbook6HoursBGLError, RecentBolusError, TargetBGLError, UserReminderError, } from "./RecommendationError";
|
|
5
11
|
import { Utils } from "./Utils";
|
|
6
12
|
const { hard } = Activity.Enums.ActivityIntensity;
|
|
7
13
|
const { fromFortysix } = Activity.Enums.ActivityReductionIntervals;
|
|
14
|
+
/**
|
|
15
|
+
* Main function for validating all input properties for the insulin recommendation screen component.
|
|
16
|
+
* Throws an exception if any of the individual checks fail.
|
|
17
|
+
*
|
|
18
|
+
* Steps:
|
|
19
|
+
* 1. Call checkCalculatorParams() with the calculatorParams property of the props as argument.
|
|
20
|
+
* 2. Call checkBGLUnit() with the bloodGlucoseUnit property of the props as argument.
|
|
21
|
+
* 3. Call checkBKProps() with the bloodKetoneUnit and currentBKL properties of the props as arguments.
|
|
22
|
+
* 4. Call checkBKLUnit() with the bloodKetoneUnit property of the props as argument.
|
|
23
|
+
* 5. Call checkBloodKetoneLevel() with the currentBKL property of the props as argument.
|
|
24
|
+
* 6. Call checkInjectionMethod() with the injectionMethod property of the props as argument.
|
|
25
|
+
* 7. Call checkUserReminder() with the userReminder property of the props as argument.
|
|
26
|
+
* 8. Call checkLanguage() with the language property of the props as argument.
|
|
27
|
+
* 9. Call checkLatestLogbook6Hours() with the latestLogbookFrom6Hours property of the props as argument.
|
|
28
|
+
* 10. If the activity property of the calculatorParams prop is truthy, and the activityDisplayProps prop is truthy:
|
|
29
|
+
* call the checkActivityType method with the activityType property of the activityDisplayProps prop as the argument.
|
|
30
|
+
* @param props All the props that were passed in to the RecommendationScreen component.
|
|
31
|
+
*/
|
|
8
32
|
export function validateParams(props) {
|
|
9
33
|
checkCalculatorParams(props.calculatorParams);
|
|
10
34
|
checkBGLUnit(props.bloodGlucoseUnit);
|
|
@@ -19,16 +43,42 @@ export function validateParams(props) {
|
|
|
19
43
|
checkActivityType(props.activityDisplayProps.activityType);
|
|
20
44
|
}
|
|
21
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* In case the users is providing a blood ketone current level, check if the blood ketone unit is defined.
|
|
48
|
+
*
|
|
49
|
+
* Steps:
|
|
50
|
+
* 1. If the currentBKL is not null and the bloodKetoneUnit is null throw an BloodKetonePropsError
|
|
51
|
+
* @param bloodKetoneUnit The user’s blood ketone unit.
|
|
52
|
+
* @param currentBKL The users’s current blood ketone level.
|
|
53
|
+
*/
|
|
22
54
|
export function checkBKProps(bloodKetoneUnit, currentBKL) {
|
|
23
55
|
if (currentBKL !== null && bloodKetoneUnit === null) {
|
|
24
56
|
throw BloodKetonePropsError();
|
|
25
57
|
}
|
|
26
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The user’s preferred language for using the app.
|
|
61
|
+
*
|
|
62
|
+
* Steps:
|
|
63
|
+
* 1. Search in the Languages enum values the language provided as an argument.
|
|
64
|
+
* If language is not present in the Languages enum values array, throw a LanguageError.
|
|
65
|
+
* @param language The user’s preferred language for using the app.
|
|
66
|
+
*/
|
|
27
67
|
export function checkLanguage(language) {
|
|
28
68
|
if (!Object.values(Languages).includes(language)) {
|
|
29
69
|
throw LanguageError();
|
|
30
70
|
}
|
|
31
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if the latest logbook from the last 6 hours is valid.
|
|
74
|
+
*
|
|
75
|
+
* Steps:
|
|
76
|
+
* 1. If logbook is undefined, throw an LatestLogbook6HoursBGLError.
|
|
77
|
+
* 2. If logbook is not null and if the blood_glucose_millimolar property of the logbook object is not null,
|
|
78
|
+
* check if the blood_glucose_millimolar is inside the allowed range for blood glucose level.
|
|
79
|
+
* If it is not, throw LatestLogbook6HoursBGLError.
|
|
80
|
+
* @param logbook The user’s latest logbook from the last 6 hours
|
|
81
|
+
*/
|
|
32
82
|
export function checkLatestLogbook6Hours(logbook) {
|
|
33
83
|
if (logbook === undefined) {
|
|
34
84
|
throw LatestLogbook6HoursBGLError();
|
|
@@ -39,18 +89,42 @@ export function checkLatestLogbook6Hours(logbook) {
|
|
|
39
89
|
}
|
|
40
90
|
}
|
|
41
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if the injectionMethod parameter is valid.
|
|
94
|
+
*
|
|
95
|
+
* Steps:
|
|
96
|
+
* 1. Search in the InjectionMethod enum values the injectionMethod provided as an argument.
|
|
97
|
+
* If injectionMethod is not present in the InjectionMethod enum values array, throw a InjectionMethodError.
|
|
98
|
+
* @param injectionMethod The user’s insulin injection method.
|
|
99
|
+
*/
|
|
42
100
|
export function checkInjectionMethod(injectionMethod) {
|
|
43
101
|
const check = Object.values(UserSettings.Enums.InjectionMethod).some((method) => method === injectionMethod);
|
|
44
102
|
if (!check) {
|
|
45
103
|
throw InjectionMethodError();
|
|
46
104
|
}
|
|
47
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Check if the blood glucose unit parameter is valid.
|
|
108
|
+
* Steps:
|
|
109
|
+
* 1. Search in the BloodGlucoseUnit enum values the unit provided as an argument.
|
|
110
|
+
* If unit is not present in the BloodGlucoseUnit enum values array, throw a BloodGlucoseUnitError.
|
|
111
|
+
* @param unit The user’s preferred blood glucose unit for using the app.
|
|
112
|
+
*/
|
|
48
113
|
export function checkBGLUnit(unit) {
|
|
49
114
|
const check = Object.values(BloodGlucoseUnit).some((enumUnit) => enumUnit === unit);
|
|
50
115
|
if (!check) {
|
|
51
116
|
throw BloodGlucoseUnitError();
|
|
52
117
|
}
|
|
53
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if the blood ketones unit parameter is valid.
|
|
121
|
+
*
|
|
122
|
+
* Steps:
|
|
123
|
+
* 1. If the unit is not null, search in the BloodKetonesUnit enum values the unit provided as an argument.
|
|
124
|
+
* If unit is not present in the BloodKetonesUnit enum values array, throw a BloodKetoneUnitError.
|
|
125
|
+
* @param unit The user’s preferred blood ketones unit for using the app.
|
|
126
|
+
* It can be null if the user did not choose a measurement unit at the moment of this validation.
|
|
127
|
+
*/
|
|
54
128
|
export function checkBKLUnit(unit) {
|
|
55
129
|
if (unit !== null) {
|
|
56
130
|
const check = Object.values(BloodKetonesUnit).some((enumUnit) => enumUnit === unit);
|
|
@@ -59,12 +133,34 @@ export function checkBKLUnit(unit) {
|
|
|
59
133
|
}
|
|
60
134
|
}
|
|
61
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Check if the users preferred default reminder duration is valid by verifying that it is within the allowed range.
|
|
138
|
+
*
|
|
139
|
+
* Steps:
|
|
140
|
+
* 1. Use isInRange() {@link Utils} to check if userReminder is in the interval [0; 6]. If it isn’t then throw an UserReminderError().
|
|
141
|
+
* @param userReminder The default reminder time in hours from the user’s settings
|
|
142
|
+
*/
|
|
62
143
|
export function checkUserReminder(userReminder) {
|
|
63
144
|
if (!Utils.isInRange(userReminder, REMINDER_HOURS_LIMITS)) {
|
|
64
145
|
throw UserReminderError();
|
|
65
146
|
}
|
|
66
147
|
}
|
|
67
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Check validity of the values that are used as input for the actual insulin recommendation calculation.
|
|
150
|
+
*
|
|
151
|
+
* Steps:
|
|
152
|
+
* 1. Call checkActivity() with the activity property of the calculatorParams as argument.
|
|
153
|
+
* 2. Call checkCarbohydrates() with the carbohydrates property of the calculatorParams as argument.
|
|
154
|
+
* 3. Call checkCurrentBGL() with the currentBGL property of the calculatorParams as argument.
|
|
155
|
+
* 4. Call checkTargetBGL() with the targetBGL property of the calculatorParams as argument.
|
|
156
|
+
* 5. Call checkInsulinToCarbRatio() with the carbohydrateRatio property of the calculatorParams as argument.
|
|
157
|
+
* 6. Call checkInsulinSensitivity() with the insulinSensitivity property of the calculatorParams as argument.
|
|
158
|
+
* 7. Call checkRecentBolus() with the recentBoluses property of the calculatorParams as argument.
|
|
159
|
+
* 8. Call checkRecentBolusesInsulinDose() with the recentBoluses property of the calculatorParams as argument.
|
|
160
|
+
* 9. Call checkRecentBolusesSecondsPassed() with the recentBoluses property of the calculatorParams as argument.
|
|
161
|
+
* @param calculatorParams The inputs for calculation to be checked
|
|
162
|
+
*/
|
|
163
|
+
export function checkCalculatorParams(calculatorParams) {
|
|
68
164
|
checkActivity(calculatorParams.activity);
|
|
69
165
|
checkCarbohydrates(calculatorParams.carbohydrates);
|
|
70
166
|
checkCurrentBGL(calculatorParams.currentBGL);
|
|
@@ -75,6 +171,18 @@ function checkCalculatorParams(calculatorParams) {
|
|
|
75
171
|
checkRecentBolusesInsulinDose(calculatorParams.recentBoluses);
|
|
76
172
|
checkRecentBolusesSecondsPassed(calculatorParams.recentBoluses);
|
|
77
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Check the validity of the values inputted for physical activity
|
|
176
|
+
*
|
|
177
|
+
* Steps:
|
|
178
|
+
* 1. If the activity argument is truthy do the following:
|
|
179
|
+
* - Call checkActivityDate() with the activity as argument
|
|
180
|
+
* - Call checkActivityDuration() with the activityDuration property of the activity as argument
|
|
181
|
+
* - Call checkActivityIntensity() with the activityIntensity property of the activity as argument
|
|
182
|
+
* - Call checkActivitySettings() with the activitySettings property of the activity as argument
|
|
183
|
+
* - Call checkActivityTargetBGL() with the activitySettings.target property of the activity as argument
|
|
184
|
+
* @param activity The activity that is associated with the calculation, or null if no activity was entered
|
|
185
|
+
*/
|
|
78
186
|
export function checkActivity(activity) {
|
|
79
187
|
if (activity) {
|
|
80
188
|
checkActivityDate(activity);
|
|
@@ -84,11 +192,27 @@ export function checkActivity(activity) {
|
|
|
84
192
|
checkActivityTargetBGL(activity.activitySettings.target);
|
|
85
193
|
}
|
|
86
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Check if the recentBoluses is in the right format.
|
|
197
|
+
*
|
|
198
|
+
* Steps:
|
|
199
|
+
* 1. If recentBoluses is null or undefined throw a RecentBolusError.
|
|
200
|
+
* @param recentBoluses List of all known bolus injections from the past 4 hours including insulin amount and how many seconds has passed since the injection.
|
|
201
|
+
*/
|
|
87
202
|
export function checkRecentBolus(recentBoluses) {
|
|
88
203
|
if (recentBoluses === null || recentBoluses === undefined) {
|
|
89
204
|
throw RecentBolusError();
|
|
90
205
|
}
|
|
91
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if the insulin dose in each of the given recent insulin injections is valid by verifying that they are within the allowed range.
|
|
209
|
+
*
|
|
210
|
+
* Steps
|
|
211
|
+
* 1. If recentBoluses isn’t null, for each bolus element in recentBoluses
|
|
212
|
+
* use isInRange() to check if the insulinDose parameter of the bolus element is in the interval [0; 50].
|
|
213
|
+
* If it isn’t then throw an BolusInsulinDoseError().
|
|
214
|
+
* @param recentBoluses List of all known bolus injections from the past 4 hours including insulin amount and how many seconds has passed since the injection.
|
|
215
|
+
*/
|
|
92
216
|
export function checkRecentBolusesInsulinDose(recentBoluses) {
|
|
93
217
|
recentBoluses.forEach((bolus) => {
|
|
94
218
|
if (!Utils.isInRange(bolus.insulinDose, INSULIN_DOSE_LIMITS)) {
|
|
@@ -96,6 +220,15 @@ export function checkRecentBolusesInsulinDose(recentBoluses) {
|
|
|
96
220
|
}
|
|
97
221
|
});
|
|
98
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Check if the amount of time since each recent insulin injection is valid by verifying that they are within the allowed range.
|
|
225
|
+
*
|
|
226
|
+
* Steps:
|
|
227
|
+
* 1. If recentBoluses isn’t null, for each bolus element in recentBoluses
|
|
228
|
+
* use isInRange() to check if the secondsPassed parameter of the bolus element is in the interval [0; 1440].
|
|
229
|
+
* If it isn’t then throw an BolusInsulinSecondsPassedError().
|
|
230
|
+
* @param recentBoluses List of all known bolus injections from the past 4 hours including insulin amount and how many seconds has passed since the injection.
|
|
231
|
+
*/
|
|
99
232
|
export function checkRecentBolusesSecondsPassed(recentBoluses) {
|
|
100
233
|
recentBoluses.forEach((bolus) => {
|
|
101
234
|
if (!Utils.isInRange(bolus.secondsPassed, BOLUS_SECONDS_PASSED_LIMITS)) {
|
|
@@ -103,23 +236,55 @@ export function checkRecentBolusesSecondsPassed(recentBoluses) {
|
|
|
103
236
|
}
|
|
104
237
|
});
|
|
105
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Check if the duration of an entered activity is valid by verifying that it is within the allowed range.
|
|
241
|
+
*
|
|
242
|
+
* Steps:
|
|
243
|
+
* 1. Use isInRange() to check if activityDuration is in the interval [0; 60]. If it isn’t then throw an ActivityDurationError().
|
|
244
|
+
* @param activityDuration The duration of an entered physical activity in minutes.
|
|
245
|
+
*/
|
|
106
246
|
export function checkActivityDuration(activityDuration) {
|
|
107
247
|
if (!Utils.isInRange(activityDuration, ACTIVITY_DURATION_MINUTES_LIMITS)) {
|
|
108
248
|
throw ActivityDurationError();
|
|
109
249
|
}
|
|
110
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Check if the activity intensity parameter is valid.
|
|
253
|
+
*
|
|
254
|
+
* Steps:
|
|
255
|
+
* 1. Search in the {@link ActivityIntensity} enum values the activityIntensity provided as an argument.
|
|
256
|
+
* If activityIntensity is not present in the ActivityIntensity enum values array, throw an ActivityIntensityError.
|
|
257
|
+
* @param activityIntensity The intensity of the entered activity.
|
|
258
|
+
*/
|
|
111
259
|
export function checkActivityIntensity(activityIntensity) {
|
|
112
260
|
const check = Object.values(Activity.Enums.ActivityIntensity).some((method) => method === activityIntensity?.toLowerCase());
|
|
113
261
|
if (!check) {
|
|
114
262
|
throw ActivityIntensityError();
|
|
115
263
|
}
|
|
116
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Check if the activity type parameter is valid.
|
|
267
|
+
*
|
|
268
|
+
* Steps:
|
|
269
|
+
* 1. Search in the {@link ActivityEnum} enum values the activityType provided as an argument.
|
|
270
|
+
* If activityType is not present in the ActivityEnum enum values array, throw an ActivityTypeError.
|
|
271
|
+
* @param activityType The type of the entered activity.
|
|
272
|
+
*/
|
|
117
273
|
export function checkActivityType(activityType) {
|
|
118
274
|
const check = Object.values(Activity.Enums.ActivityEnum).some((method) => method === activityType);
|
|
119
275
|
if (!check) {
|
|
120
276
|
throw ActivityTypeError();
|
|
121
277
|
}
|
|
122
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Verify that the ending time of the given activity has not been passed by more than 4 hours and 10 minutes.
|
|
281
|
+
*
|
|
282
|
+
* Steps:
|
|
283
|
+
* 1. Use the moment library to create an object that represents the start time of the activity by loading from the activityDate property of the activity argument.
|
|
284
|
+
* Add to the object the duration of the activity plus 4 hours and 10 minutes and save the resulting date as maximumDate.
|
|
285
|
+
* 2. Check if the current time is after maximumDate throw an ActivityDateError().
|
|
286
|
+
* @param activity The activity for which we want to check the date
|
|
287
|
+
*/
|
|
123
288
|
export function checkActivityDate(activity) {
|
|
124
289
|
const maximumDate = moment
|
|
125
290
|
.utc(activity.activityDate)
|
|
@@ -128,6 +293,15 @@ export function checkActivityDate(activity) {
|
|
|
128
293
|
throw ActivityDateError();
|
|
129
294
|
}
|
|
130
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Steps:
|
|
298
|
+
* 1. Iterate over all combinations of activity intensities and activity duration intervals and for each one:
|
|
299
|
+
* - If the current intensity is hard and the duration is long (fromFortysix) then check that the value from activitySettings
|
|
300
|
+
* for the current combination of activity intensity is either null or in the interval [0; 1]
|
|
301
|
+
* - If the current intensity isn’t hard or the duration isn’t long then use isInRange() to check that the value from activitySettings
|
|
302
|
+
* for the current combination of activity intensity is in the interval [0; 1].
|
|
303
|
+
* @param activitySettings The user’s settings for doing physical activity
|
|
304
|
+
*/
|
|
131
305
|
export function checkActivitySettings(activitySettings) {
|
|
132
306
|
for (const intensity of Object.keys(activitySettings)) {
|
|
133
307
|
const reductionIntervals = activitySettings[intensity];
|
|
@@ -145,11 +319,25 @@ export function checkActivitySettings(activitySettings) {
|
|
|
145
319
|
}
|
|
146
320
|
}
|
|
147
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Check if the target blood glucose level for doing exercise is valid by verifying that it is within the allowed range.
|
|
324
|
+
*
|
|
325
|
+
* Steps:
|
|
326
|
+
* 1. Use isInRange() to check if activitySettingsTargetBGL is in the interval [5.0; 13.9]. If it isn’t then throw an ActivityTargetBGLError().
|
|
327
|
+
* @param activitySettingsTargetBGL The target blood glucose level for doing exercise in mmol/L from the user’s settings.
|
|
328
|
+
*/
|
|
148
329
|
export function checkActivityTargetBGL(activitySettingsTargetBGL) {
|
|
149
330
|
if (!Utils.isInRange(activitySettingsTargetBGL, ACTIVITY_TARGET_BGL_MMOL_LIMITS)) {
|
|
150
331
|
throw ActivityTargetBGLError();
|
|
151
332
|
}
|
|
152
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Check if the current blood glucose level is valid by verifying that it is either null or within the allowed range.
|
|
336
|
+
* Steps:
|
|
337
|
+
* 1. If currentBGL is not null then use isInRange() to check if currentBGL is in the interval [1.1; 33.3].
|
|
338
|
+
* If it isn’t then throw a CurrentBGLError().
|
|
339
|
+
* @param currentBGL The current blood glucose level in mmol/L entered by the user, or null to indicate that the value is unknown because it wasn’t given.
|
|
340
|
+
*/
|
|
153
341
|
export function checkCurrentBGL(currentBGL) {
|
|
154
342
|
if (currentBGL !== null) {
|
|
155
343
|
if (!Utils.isInRange(currentBGL, CURRENT_BGL_MMOL_LIMITS)) {
|
|
@@ -157,11 +345,25 @@ export function checkCurrentBGL(currentBGL) {
|
|
|
157
345
|
}
|
|
158
346
|
}
|
|
159
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Check if the target blood glucose level is valid by verifying that it is within the allowed range.
|
|
350
|
+
*
|
|
351
|
+
* Steps:
|
|
352
|
+
* 1. Use isInRange() to check if targetBGL is in the interval [5.0; 13.9]. If it isn’t then throw a TargetBGLError().
|
|
353
|
+
* @param targetBGL The target blood glucose level in mmol/L extracted from the user’s settings depending on the time of day.
|
|
354
|
+
*/
|
|
160
355
|
export function checkTargetBGL(targetBGL) {
|
|
161
356
|
if (!Utils.isInRange(targetBGL, TARGET_BGL_MMOL_LIMITS)) {
|
|
162
357
|
throw TargetBGLError();
|
|
163
358
|
}
|
|
164
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Check if the current blood ketones concentration is valid by verifying that it is either null or within the allowed range.
|
|
362
|
+
*
|
|
363
|
+
* Steps:
|
|
364
|
+
* 1. If currentBKL is not null then use isInRange() to check if currentBGL is in the interval [0.0; 8.0]. If it isn’t then throw a CurrentBKLError().
|
|
365
|
+
* @param currentBKL The current blood ketones concentration in mmol/L entered by the user, or null to indicate that the value is unknown because it wasn’t given.
|
|
366
|
+
*/
|
|
165
367
|
export function checkBloodKetoneLevel(currentBKL) {
|
|
166
368
|
if (currentBKL !== null) {
|
|
167
369
|
if (!Utils.isInRange(currentBKL, CURRENT_BKL_MMOL_LIMITS)) {
|
|
@@ -169,16 +371,37 @@ export function checkBloodKetoneLevel(currentBKL) {
|
|
|
169
371
|
}
|
|
170
372
|
}
|
|
171
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Check if the insulin sensitivity is valid by verifying that it is within the allowed range.
|
|
376
|
+
*
|
|
377
|
+
* Steps:
|
|
378
|
+
* 1. Use isInRange() to check if insulinSensitivity is in the interval [0.3; 10]. If it isn’t then throw an InsulinSensitivityError().
|
|
379
|
+
* @param insulinSensitivity The insulin sensitivity in (mmol/L)/IU extracted from the user’s settings depending on the time of day.
|
|
380
|
+
*/
|
|
172
381
|
export function checkInsulinSensitivity(insulinSensitivity) {
|
|
173
382
|
if (!Utils.isInRange(insulinSensitivity, INSULIN_SENSITIVITY_MMOL_LIMITS)) {
|
|
174
383
|
throw InsulinSensitivityError();
|
|
175
384
|
}
|
|
176
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Check if the insulin-to-carbs ratio is valid by verifying that it is within the allowed range.
|
|
388
|
+
*
|
|
389
|
+
* Steps:
|
|
390
|
+
* 1. Use isInRange() to check if insulinToCarbRatio is in the interval [1; 50]. If it isn’t then throw an InsulinToCarbsRatioError().
|
|
391
|
+
* @param insulinToCarbRatio The insulin-to-carbs ratio in g/IU extracted from the user’s settings depending on the time of day.
|
|
392
|
+
*/
|
|
177
393
|
export function checkInsulinToCarbRatio(insulinToCarbRatio) {
|
|
178
394
|
if (!Utils.isInRange(insulinToCarbRatio, INSULIN_TO_CARBS_RATIO_LIMITS)) {
|
|
179
395
|
throw InsulinToCarbsRatioError();
|
|
180
396
|
}
|
|
181
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Check if the entered amount of carbohydrates is valid by verifying that it is within the allowed range.
|
|
400
|
+
*
|
|
401
|
+
* Steps:
|
|
402
|
+
* 1. Use isInRange() to check if carbohydrates is in the interval [0; 300]. If it isn’t then throw a CarbohydrateLimitError().
|
|
403
|
+
* @param carbohydrates The amount of carbohydrates that the user is eating in grams.
|
|
404
|
+
*/
|
|
182
405
|
export function checkCarbohydrates(carbohydrates) {
|
|
183
406
|
if (!Utils.isInRange(carbohydrates, CARBOHYDRATES_LIMTS)) {
|
|
184
407
|
throw CarbohydrateLimitError();
|
package/typedoc.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"entryPoints": [
|
|
3
|
+
"./src/RecommendationScreen.tsx",
|
|
4
|
+
"./src/components/",
|
|
5
|
+
"./src/locale/i18nUtils.ts",
|
|
6
|
+
"./src/utils/",
|
|
7
|
+
"./src/types/",
|
|
8
|
+
"./node_modules/@hedia/types/dist/index.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"includes": "./node_modules/@hedia/types/dist/",
|
|
11
|
+
"excludeInternal": true,
|
|
12
|
+
"includeVersion": true
|
|
13
|
+
}
|