@hedia/recommendation-screen 1.2.1 → 1.3.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.
Files changed (37) hide show
  1. package/.idea/workspace.xml +30 -30
  2. package/package.json +1 -1
  3. package/src/RecommendationScreen.d.ts +3 -0
  4. package/src/RecommendationScreen.jsx +50 -41
  5. package/src/RecommendationScreen.tsx +80 -56
  6. package/src/components/InvisibleNumberInput.d.ts +1 -0
  7. package/src/components/InvisibleNumberInput.jsx +1 -1
  8. package/src/components/InvisibleNumberInput.tsx +3 -0
  9. package/src/components/RecommendedCarbs.d.ts +0 -2
  10. package/src/components/RecommendedCarbs.jsx +8 -3
  11. package/src/components/RecommendedCarbs.tsx +10 -5
  12. package/src/components/RecommendedInsulin.d.ts +3 -3
  13. package/src/components/RecommendedInsulin.jsx +18 -6
  14. package/src/components/RecommendedInsulin.tsx +24 -10
  15. package/src/components/activity/ActivityIcon.jsx +1 -1
  16. package/src/components/activity/ActivityIcon.tsx +1 -1
  17. package/src/types/enum.d.ts +9 -10
  18. package/src/types/enum.js +9 -10
  19. package/src/types/enum.ts +0 -1
  20. package/src/types/types.ts +1 -0
  21. package/src/utils/AttentionMessages.d.ts +1 -1
  22. package/src/utils/AttentionMessages.jsx +1 -1
  23. package/src/utils/AttentionMessages.tsx +1 -1
  24. package/src/utils/Constants.d.ts +3 -0
  25. package/src/utils/Constants.js +4 -1
  26. package/src/utils/Constants.ts +5 -0
  27. package/src/utils/RecommendationError.d.ts +0 -1
  28. package/src/utils/RecommendationError.jsx +1 -3
  29. package/src/utils/RecommendationError.tsx +0 -7
  30. package/src/utils/RecommendationUtils.d.ts +2 -3
  31. package/src/utils/RecommendationUtils.js +3 -4
  32. package/src/utils/RecommendationUtils.ts +2 -4
  33. package/src/utils/Utils.d.ts +1 -0
  34. package/src/utils/Utils.js +4 -0
  35. package/src/utils/Utils.ts +4 -0
  36. package/src/utils/Validations.js +15 -11
  37. package/src/utils/Validations.ts +16 -11
@@ -1,9 +1,9 @@
1
1
  import { t } from "@lingui/macro";
2
2
  import React from "react";
3
- import { Dimensions, StyleSheet, Text, TouchableOpacity, View } from "react-native";
3
+ import { Alert, Dimensions, StyleSheet, Text, TouchableOpacity, View } from "react-native";
4
4
  import { i18n } from "../locale/i18nUtils";
5
5
  import { BORDER_COLOUR_TEAL } from "../utils/Constants";
6
- import { CarbohydrateLimitError, RecommendationError } from "../utils/RecommendationError";
6
+ import { CarbohydrateLimitError } from "../utils/RecommendationError";
7
7
  import Icon from "./Icon";
8
8
  import { infoStyles } from "./InfoBars";
9
9
  import InvisibleNumberInput from "./InvisibleNumberInput";
@@ -23,7 +23,6 @@ interface IProps {
23
23
  // Callbacks
24
24
  removeRecommendedCarbs(): void;
25
25
  changedRecommendedCarbs(value: number): void;
26
- onError(error: RecommendationError): void;
27
26
  }
28
27
 
29
28
  interface IState {
@@ -50,7 +49,12 @@ export default class RecommendedCarbs extends React.Component<IProps, IState> {
50
49
  public handleChangedCarbs = (carbs: number): void => {
51
50
  if (carbs >= 0) {
52
51
  if (carbs > 300) {
53
- return this.props.onError(CarbohydrateLimitError());
52
+ this.setState({ partialInput: this.props.recommendedCarbs });
53
+ return Alert.alert(i18n._(`Attention`), CarbohydrateLimitError().message, [
54
+ {
55
+ text: i18n._(`OK`),
56
+ },
57
+ ]);
54
58
  }
55
59
  this.props.changedRecommendedCarbs(carbs);
56
60
  }
@@ -58,7 +62,7 @@ export default class RecommendedCarbs extends React.Component<IProps, IState> {
58
62
 
59
63
  public renderRecommendedCarbs = (): JSX.Element => {
60
64
  const shownCarbs = this.state.partialInput ?? Math.round(Number(this.props.recommendedCarbs));
61
- const totalCarbs = Math.round(parseFloat(this.props.enteredCarbs) + parseFloat(this.props.recommendedCarbs));
65
+ const totalCarbs = Math.round(parseFloat(this.props.enteredCarbs) + Number(shownCarbs));
62
66
  return (
63
67
  <React.Fragment>
64
68
  <View style={calculationStyles.borderContainer}>
@@ -114,6 +118,7 @@ export default class RecommendedCarbs extends React.Component<IProps, IState> {
114
118
  partialInput={this.handlePartialInput}
115
119
  onEnd={this.handleChangedCarbs}
116
120
  startValue={this.props.recommendedCarbs}
121
+ maxLength={3}
117
122
  />
118
123
  </React.Fragment>
119
124
  );
@@ -1,19 +1,19 @@
1
1
  import React from "react";
2
2
  import { InjectionMethod } from "../types/enum";
3
- import { RecommendationError } from "../utils/RecommendationError";
4
3
  interface IProps {
5
4
  insulinRecommendation?: number;
5
+ enteredInsulin?: number;
6
6
  activityReduction?: number;
7
7
  injectionMethod: InjectionMethod;
8
8
  updateRecommendedInsulin(value: number): void;
9
- onError(error: RecommendationError): void;
10
9
  }
11
10
  interface IState {
12
- insulin: string;
11
+ partialInput: string;
13
12
  }
14
13
  export default class RecommendedInsulin extends React.Component<IProps, IState> {
15
14
  callbackInput: () => void;
16
15
  constructor(props: IProps);
16
+ componentDidUpdate(prevProps: IProps): void;
17
17
  handleOnPress: () => void;
18
18
  updatePartially: (insulin: string) => string;
19
19
  handleUpdatedInsulin: (value: number) => void;
@@ -9,7 +9,7 @@ const react_1 = __importDefault(require("react"));
9
9
  const react_native_1 = require("react-native");
10
10
  const react_native_linear_gradient_1 = __importDefault(require("react-native-linear-gradient"));
11
11
  const i18nUtils_1 = require("../locale/i18nUtils");
12
- const RecommendationError_1 = require("../utils/RecommendationError");
12
+ const AttentionMessages_1 = require("../utils/AttentionMessages");
13
13
  const Utils_1 = require("../utils/Utils");
14
14
  const Icon_1 = __importDefault(require("./Icon"));
15
15
  const InfoBars_1 = require("./InfoBars");
@@ -23,7 +23,7 @@ class RecommendedInsulin extends react_1.default.Component {
23
23
  this.updatePartially = (insulin) => {
24
24
  const replacedZero = insulin.length > 1 && insulin.startsWith(`0`) && !insulin.startsWith(`0.`) ? insulin.substring(1) : insulin;
25
25
  this.setState({
26
- insulin: replacedZero,
26
+ partialInput: replacedZero,
27
27
  });
28
28
  return replacedZero;
29
29
  };
@@ -33,13 +33,18 @@ class RecommendedInsulin extends react_1.default.Component {
33
33
  const limited = (1 - this.props.activityReduction) * recommendation_calculator_1.SAFETY_INSULIN_LIMIT;
34
34
  if (rounded > limited) {
35
35
  this.updatePartially(`${limited}`);
36
- return this.props.onError(RecommendationError_1.InsulinLimitError(this.props.activityReduction));
36
+ return react_native_1.Alert.alert(i18nUtils_1.i18n._(`Attention`), AttentionMessages_1.Messages.InsulinInputWasLimited(this.props.activityReduction), [
37
+ {
38
+ text: i18nUtils_1.i18n._(`OK`),
39
+ },
40
+ ]);
37
41
  }
38
42
  this.updatePartially(`${rounded}`);
39
43
  this.props.updateRecommendedInsulin(rounded);
40
44
  };
41
45
  this.render = () => {
42
46
  const paddingBottom = react_native_1.Platform.OS === `ios` ? `3%` : `1%`;
47
+ const shownInsulin = this.state.partialInput ?? this.props.insulinRecommendation ?? `0`;
43
48
  return (<react_1.default.Fragment>
44
49
  <react_native_1.TouchableOpacity accessibilityLabel="editRecommendedInsulin" onPress={this.handleOnPress}>
45
50
  <react_native_linear_gradient_1.default style={recommendedInsulinStyles.container} colors={[`#a200ff`, `#578aff`]} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }}>
@@ -50,20 +55,26 @@ class RecommendedInsulin extends react_1.default.Component {
50
55
  </react_native_1.View>
51
56
  <react_native_1.View style={[recommendedInsulinStyles.recommendedContainer, { paddingBottom }]}>
52
57
  <react_native_1.View style={recommendedInsulinStyles.valueContainer}>
53
- <react_native_1.Text style={recommendedInsulinStyles.value}>{this.state.insulin}</react_native_1.Text>
58
+ <react_native_1.Text style={recommendedInsulinStyles.value}>{shownInsulin}</react_native_1.Text>
54
59
  <react_native_1.Text style={recommendedInsulinStyles.units}>{i18nUtils_1.i18n._(macro_1.t `Units`)}</react_native_1.Text>
55
60
  </react_native_1.View>
56
61
  <Icon_1.default style={recommendedInsulinStyles.editIcon} iconIdentifier={`Feather/edit`}/>
57
62
  </react_native_1.View>
58
63
  </react_native_linear_gradient_1.default>
59
64
  </react_native_1.TouchableOpacity>
60
- <InvisibleNumberInput_1.default decimalPlaces={3} negativeAllowed={false} cleanPartialInput={false} partialInput={this.updatePartially} onEnd={this.handleUpdatedInsulin} visible={(visible) => (this.callbackInput = visible)} startValue={`${this.state.insulin}`}/>
65
+ <InvisibleNumberInput_1.default decimalPlaces={3} negativeAllowed={false} cleanPartialInput={false} partialInput={this.updatePartially} onEnd={this.handleUpdatedInsulin} visible={(visible) => (this.callbackInput = visible)} startValue={`${shownInsulin}`}/>
61
66
  </react_1.default.Fragment>);
62
67
  };
63
68
  this.state = {
64
- insulin: `${props.insulinRecommendation ?? 0}`,
69
+ partialInput: null,
65
70
  };
66
71
  }
72
+ componentDidUpdate(prevProps) {
73
+ const { enteredInsulin } = this.props;
74
+ if (prevProps.enteredInsulin !== enteredInsulin) {
75
+ this.setState({ partialInput: enteredInsulin?.toString() });
76
+ }
77
+ }
67
78
  }
68
79
  exports.default = RecommendedInsulin;
69
80
  const recommendedInsulinStyles = react_native_1.StyleSheet.create({
@@ -90,6 +101,7 @@ const recommendedInsulinStyles = react_native_1.StyleSheet.create({
90
101
  flex: 1,
91
102
  flexDirection: `row`,
92
103
  justifyContent: `center`,
104
+ minHeight: react_native_1.Dimensions.get(`screen`).width / 4,
93
105
  },
94
106
  value: {
95
107
  color: `white`,
@@ -1,28 +1,29 @@
1
1
  import { SAFETY_INSULIN_LIMIT } from "@hedia/recommendation-calculator";
2
2
  import { t } from "@lingui/macro";
3
3
  import React from "react";
4
- import { Dimensions, Platform, StyleSheet, Text, TouchableOpacity, View } from "react-native";
4
+ import { Alert, Dimensions, Platform, StyleSheet, Text, TouchableOpacity, View } from "react-native";
5
5
  import LinearGradient from "react-native-linear-gradient";
6
6
  import { i18n } from "../locale/i18nUtils";
7
7
  import { InjectionMethod } from "../types/enum";
8
- import { InsulinLimitError, RecommendationError } from "../utils/RecommendationError";
8
+ import { Messages } from "../utils/AttentionMessages";
9
9
  import { Utils } from "../utils/Utils";
10
10
  import Icon from "./Icon";
11
11
  import { infoStyles } from "./InfoBars";
12
12
  import InvisibleNumberInput from "./InvisibleNumberInput";
13
13
 
14
14
  interface IProps {
15
+ // Values
15
16
  insulinRecommendation?: number;
17
+ enteredInsulin?: number;
16
18
  activityReduction?: number;
17
-
18
19
  injectionMethod: InjectionMethod;
19
20
 
21
+ // Callbacks
20
22
  updateRecommendedInsulin(value: number): void;
21
- onError(error: RecommendationError): void;
22
23
  }
23
24
 
24
25
  interface IState {
25
- insulin: string;
26
+ partialInput: string;
26
27
  }
27
28
 
28
29
  export default class RecommendedInsulin extends React.Component<IProps, IState> {
@@ -32,10 +33,17 @@ export default class RecommendedInsulin extends React.Component<IProps, IState>
32
33
  super(props);
33
34
 
34
35
  this.state = {
35
- insulin: `${props.insulinRecommendation ?? 0}`,
36
+ partialInput: null,
36
37
  };
37
38
  }
38
39
 
40
+ public componentDidUpdate(prevProps: IProps): void {
41
+ const { enteredInsulin } = this.props;
42
+ if (prevProps.enteredInsulin !== enteredInsulin) {
43
+ this.setState({ partialInput: enteredInsulin?.toString() });
44
+ }
45
+ }
46
+
39
47
  public handleOnPress = (): void => {
40
48
  this.callbackInput?.();
41
49
  };
@@ -44,7 +52,7 @@ export default class RecommendedInsulin extends React.Component<IProps, IState>
44
52
  const replacedZero =
45
53
  insulin.length > 1 && insulin.startsWith(`0`) && !insulin.startsWith(`0.`) ? insulin.substring(1) : insulin;
46
54
  this.setState({
47
- insulin: replacedZero,
55
+ partialInput: replacedZero,
48
56
  });
49
57
  return replacedZero;
50
58
  };
@@ -57,7 +65,11 @@ export default class RecommendedInsulin extends React.Component<IProps, IState>
57
65
 
58
66
  if (rounded > limited) {
59
67
  this.updatePartially(`${limited}`);
60
- return this.props.onError(InsulinLimitError(this.props.activityReduction));
68
+ return Alert.alert(i18n._(`Attention`), Messages.InsulinInputWasLimited(this.props.activityReduction), [
69
+ {
70
+ text: i18n._(`OK`),
71
+ },
72
+ ]);
61
73
  }
62
74
 
63
75
  this.updatePartially(`${rounded}`);
@@ -66,6 +78,7 @@ export default class RecommendedInsulin extends React.Component<IProps, IState>
66
78
 
67
79
  public render = (): JSX.Element => {
68
80
  const paddingBottom = Platform.OS === `ios` ? `3%` : `1%`;
81
+ const shownInsulin = this.state.partialInput ?? this.props.insulinRecommendation ?? `0`;
69
82
  return (
70
83
  <React.Fragment>
71
84
  <TouchableOpacity accessibilityLabel="editRecommendedInsulin" onPress={this.handleOnPress}>
@@ -82,7 +95,7 @@ export default class RecommendedInsulin extends React.Component<IProps, IState>
82
95
  </View>
83
96
  <View style={[recommendedInsulinStyles.recommendedContainer, { paddingBottom }]}>
84
97
  <View style={recommendedInsulinStyles.valueContainer}>
85
- <Text style={recommendedInsulinStyles.value}>{this.state.insulin}</Text>
98
+ <Text style={recommendedInsulinStyles.value}>{shownInsulin}</Text>
86
99
  <Text style={recommendedInsulinStyles.units}>{i18n._(t`Units`)}</Text>
87
100
  </View>
88
101
  <Icon style={recommendedInsulinStyles.editIcon} iconIdentifier={`Feather/edit`} />
@@ -96,7 +109,7 @@ export default class RecommendedInsulin extends React.Component<IProps, IState>
96
109
  partialInput={this.updatePartially}
97
110
  onEnd={this.handleUpdatedInsulin}
98
111
  visible={(visible): (() => void) => (this.callbackInput = visible)}
99
- startValue={`${this.state.insulin}`}
112
+ startValue={`${shownInsulin}`}
100
113
  />
101
114
  </React.Fragment>
102
115
  );
@@ -127,6 +140,7 @@ const recommendedInsulinStyles = StyleSheet.create({
127
140
  flex: 1,
128
141
  flexDirection: `row`,
129
142
  justifyContent: `center`,
143
+ minHeight: Dimensions.get(`screen`).width / 4,
130
144
  },
131
145
  value: {
132
146
  color: `white`,
@@ -27,7 +27,7 @@ class ActivityIcon extends react_1.default.Component {
27
27
  const label = `${enum_1.ActivityEnum[activityType]}_activity`;
28
28
  return (<react_native_1.View style={activityIconStyles.container}>
29
29
  <react_native_1.Image style={activityIconStyles.activityIcon} source={this.getActivityIcon()} accessibilityLabel={label}/>
30
- <react_native_1.Text style={activityIconStyles.activityTitle}>{activityTitle ?? i18nUtils_1.i18n._(macro_1.t `Untitled Activity`)}</react_native_1.Text>
30
+ <react_native_1.Text style={activityIconStyles.activityTitle}>{activityTitle || i18nUtils_1.i18n._(macro_1.t `Untitled Activity`)}</react_native_1.Text>
31
31
  </react_native_1.View>);
32
32
  }
33
33
  }
@@ -28,7 +28,7 @@ export default class ActivityIcon extends React.Component<IActivityType & IActiv
28
28
  source={this.getActivityIcon()}
29
29
  accessibilityLabel={label}
30
30
  />
31
- <Text style={activityIconStyles.activityTitle}>{activityTitle ?? i18n._(t`Untitled Activity`)}</Text>
31
+ <Text style={activityIconStyles.activityTitle}>{activityTitle || i18n._(t`Untitled Activity`)}</Text>
32
32
  </View>
33
33
  );
34
34
  }
@@ -39,16 +39,15 @@ export declare enum RecommendationErrorEnum {
39
39
  BolusInsulinDosis = 5,
40
40
  BolusInsulinSecondsPassed = 6,
41
41
  CarbohydrateLimit = 7,
42
- InsulinLimit = 8,
43
- InsulinSensitivity = 9,
44
- InsulinToCarbsRatio = 10,
45
- CurrentBGL = 11,
46
- TargetBGL = 12,
47
- UserReminder = 13,
48
- Language = 14,
49
- InjectionMethod = 15,
50
- Unit = 16,
51
- TimeoutLimit = 17
42
+ InsulinSensitivity = 8,
43
+ InsulinToCarbsRatio = 9,
44
+ CurrentBGL = 10,
45
+ TargetBGL = 11,
46
+ UserReminder = 12,
47
+ Language = 13,
48
+ InjectionMethod = 14,
49
+ Unit = 15,
50
+ TimeoutLimit = 16
52
51
  }
53
52
  export declare enum Milliseconds {
54
53
  Second = 1000,
package/src/types/enum.js CHANGED
@@ -49,16 +49,15 @@ var RecommendationErrorEnum;
49
49
  RecommendationErrorEnum[RecommendationErrorEnum["BolusInsulinDosis"] = 5] = "BolusInsulinDosis";
50
50
  RecommendationErrorEnum[RecommendationErrorEnum["BolusInsulinSecondsPassed"] = 6] = "BolusInsulinSecondsPassed";
51
51
  RecommendationErrorEnum[RecommendationErrorEnum["CarbohydrateLimit"] = 7] = "CarbohydrateLimit";
52
- RecommendationErrorEnum[RecommendationErrorEnum["InsulinLimit"] = 8] = "InsulinLimit";
53
- RecommendationErrorEnum[RecommendationErrorEnum["InsulinSensitivity"] = 9] = "InsulinSensitivity";
54
- RecommendationErrorEnum[RecommendationErrorEnum["InsulinToCarbsRatio"] = 10] = "InsulinToCarbsRatio";
55
- RecommendationErrorEnum[RecommendationErrorEnum["CurrentBGL"] = 11] = "CurrentBGL";
56
- RecommendationErrorEnum[RecommendationErrorEnum["TargetBGL"] = 12] = "TargetBGL";
57
- RecommendationErrorEnum[RecommendationErrorEnum["UserReminder"] = 13] = "UserReminder";
58
- RecommendationErrorEnum[RecommendationErrorEnum["Language"] = 14] = "Language";
59
- RecommendationErrorEnum[RecommendationErrorEnum["InjectionMethod"] = 15] = "InjectionMethod";
60
- RecommendationErrorEnum[RecommendationErrorEnum["Unit"] = 16] = "Unit";
61
- RecommendationErrorEnum[RecommendationErrorEnum["TimeoutLimit"] = 17] = "TimeoutLimit";
52
+ RecommendationErrorEnum[RecommendationErrorEnum["InsulinSensitivity"] = 8] = "InsulinSensitivity";
53
+ RecommendationErrorEnum[RecommendationErrorEnum["InsulinToCarbsRatio"] = 9] = "InsulinToCarbsRatio";
54
+ RecommendationErrorEnum[RecommendationErrorEnum["CurrentBGL"] = 10] = "CurrentBGL";
55
+ RecommendationErrorEnum[RecommendationErrorEnum["TargetBGL"] = 11] = "TargetBGL";
56
+ RecommendationErrorEnum[RecommendationErrorEnum["UserReminder"] = 12] = "UserReminder";
57
+ RecommendationErrorEnum[RecommendationErrorEnum["Language"] = 13] = "Language";
58
+ RecommendationErrorEnum[RecommendationErrorEnum["InjectionMethod"] = 14] = "InjectionMethod";
59
+ RecommendationErrorEnum[RecommendationErrorEnum["Unit"] = 15] = "Unit";
60
+ RecommendationErrorEnum[RecommendationErrorEnum["TimeoutLimit"] = 16] = "TimeoutLimit";
62
61
  })(RecommendationErrorEnum = exports.RecommendationErrorEnum || (exports.RecommendationErrorEnum = {}));
63
62
  var Milliseconds;
64
63
  (function (Milliseconds) {
package/src/types/enum.ts CHANGED
@@ -44,7 +44,6 @@ export enum RecommendationErrorEnum {
44
44
  BolusInsulinDosis,
45
45
  BolusInsulinSecondsPassed,
46
46
  CarbohydrateLimit,
47
- InsulinLimit,
48
47
  InsulinSensitivity,
49
48
  InsulinToCarbsRatio,
50
49
  CurrentBGL,
@@ -22,6 +22,7 @@ export interface logbookEntry {
22
22
  is_deleted: Date | null;
23
23
  utc_timezone_offset?: string | null;
24
24
  }
25
+
25
26
  export interface IInterval {
26
27
  min: number;
27
28
  max: number;
@@ -17,5 +17,5 @@ export declare class Messages {
17
17
  static InsulinKetones: () => string;
18
18
  static RecommendationWasLimited: () => string;
19
19
  static RecommendationWasLimitedActivity: (activityReduction: number) => string;
20
- static InsulinWasLimited: (activityReduction?: number) => string;
20
+ static InsulinInputWasLimited: (activityReduction?: number) => string;
21
21
  }
@@ -57,7 +57,7 @@ Messages.RecommendationWasLimitedActivity = (activityReduction) => i18nUtils_1.i
57
57
  units of insulin per calculation, but because of the physical activity
58
58
  you entered it has been further reduced by ${(activityReduction * 100).toFixed(0)}% to
59
59
  ${getLimitedValue(activityReduction)}.`);
60
- Messages.InsulinWasLimited = (activityReduction) => activityReduction
60
+ Messages.InsulinInputWasLimited = (activityReduction) => activityReduction
61
61
  ? i18nUtils_1.i18n._(macro_1.t `Hedia doesn't support more than ${Calculator.SAFETY_INSULIN_LIMIT} units of insulin per calculation, but because of the physical activity you entered it has been further reduced by
62
62
  ${(activityReduction * 100).toFixed(0)}% to ${getLimitedValue(activityReduction)} units for this calculation.`)
63
63
  : i18nUtils_1.i18n._(macro_1.t `Hedia does not support more than ${Calculator.SAFETY_INSULIN_LIMIT} units of insulin per calculation.`);
@@ -46,7 +46,7 @@ export class Messages {
46
46
  you entered it has been further reduced by ${(activityReduction * 100).toFixed(0)}% to
47
47
  ${getLimitedValue(activityReduction)}.`,
48
48
  );
49
- public static InsulinWasLimited = (activityReduction?: number): string =>
49
+ public static InsulinInputWasLimited = (activityReduction?: number): string =>
50
50
  activityReduction
51
51
  ? i18n._(
52
52
  t`Hedia doesn't support more than ${
@@ -5,6 +5,7 @@ export declare const BORDER_COLOUR_TEAL = "rgba(1, 255, 252, 0.8)";
5
5
  export declare const SEVERE_HYPERGLYCEMIA_START_MMOL = 15;
6
6
  export declare const FOUR_HOURS_SECONDS = 14400;
7
7
  export declare const ONE_HOUR_MINUTES = 60;
8
+ export declare const ACTIVITY_BUFFER_MINUTES = 10;
8
9
  export declare const CARBOHYDRATES_LIMTS: IInterval;
9
10
  export declare const INSULIN_DOSIS_LIMITS: IInterval;
10
11
  export declare const BOLUS_SECONDS_PASSED_LIMITS: IInterval;
@@ -12,6 +13,8 @@ export declare const ACTIVITY_DURATION_MINUTES_LIMITS: IInterval;
12
13
  export declare const INSULIN_SENSITIVITY_MMOL_LIMITS: IInterval;
13
14
  export declare const INSULIN_TO_CARBS_RATIO_LIMITS: IInterval;
14
15
  export declare const CURRENT_BGL_MMOL_LIMITS: IInterval;
16
+ export declare const MMOLL_PER_MGDL: number;
17
+ export declare const MGDL_PER_MMOLL: number;
15
18
  export declare const TARGET_BGL_MMOL_LIMITS: IInterval;
16
19
  export declare const ACTIVITY_TARGET_BGL_MMOL_LIMITS: IInterval;
17
20
  export declare const REMINDER_HOURS_LIMITS: IInterval;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACTIVITY_SETTINGS_INTERVAL_LIMITS = exports.REMINDER_HOURS_LIMITS = exports.ACTIVITY_TARGET_BGL_MMOL_LIMITS = exports.TARGET_BGL_MMOL_LIMITS = exports.CURRENT_BGL_MMOL_LIMITS = exports.INSULIN_TO_CARBS_RATIO_LIMITS = exports.INSULIN_SENSITIVITY_MMOL_LIMITS = exports.ACTIVITY_DURATION_MINUTES_LIMITS = exports.BOLUS_SECONDS_PASSED_LIMITS = exports.INSULIN_DOSIS_LIMITS = exports.CARBOHYDRATES_LIMTS = exports.ONE_HOUR_MINUTES = exports.FOUR_HOURS_SECONDS = exports.SEVERE_HYPERGLYCEMIA_START_MMOL = exports.BORDER_COLOUR_TEAL = exports.BORDER_COLOUR_GREY = exports.BACKGROUND_COLOUR_PURPLE = void 0;
3
+ exports.ACTIVITY_SETTINGS_INTERVAL_LIMITS = exports.REMINDER_HOURS_LIMITS = exports.ACTIVITY_TARGET_BGL_MMOL_LIMITS = exports.TARGET_BGL_MMOL_LIMITS = exports.MGDL_PER_MMOLL = exports.MMOLL_PER_MGDL = exports.CURRENT_BGL_MMOL_LIMITS = exports.INSULIN_TO_CARBS_RATIO_LIMITS = exports.INSULIN_SENSITIVITY_MMOL_LIMITS = exports.ACTIVITY_DURATION_MINUTES_LIMITS = exports.BOLUS_SECONDS_PASSED_LIMITS = exports.INSULIN_DOSIS_LIMITS = exports.CARBOHYDRATES_LIMTS = exports.ACTIVITY_BUFFER_MINUTES = exports.ONE_HOUR_MINUTES = exports.FOUR_HOURS_SECONDS = exports.SEVERE_HYPERGLYCEMIA_START_MMOL = exports.BORDER_COLOUR_TEAL = exports.BORDER_COLOUR_GREY = exports.BACKGROUND_COLOUR_PURPLE = void 0;
4
4
  exports.BACKGROUND_COLOUR_PURPLE = `rgba(27, 31, 72, 1)`;
5
5
  exports.BORDER_COLOUR_GREY = `rgba(74, 91, 134, 1)`;
6
6
  exports.BORDER_COLOUR_TEAL = `rgba(1, 255, 252, 0.8)`;
7
7
  exports.SEVERE_HYPERGLYCEMIA_START_MMOL = 15;
8
8
  exports.FOUR_HOURS_SECONDS = 14400;
9
9
  exports.ONE_HOUR_MINUTES = 60;
10
+ exports.ACTIVITY_BUFFER_MINUTES = 10;
10
11
  exports.CARBOHYDRATES_LIMTS = { min: 0, max: 300 };
11
12
  exports.INSULIN_DOSIS_LIMITS = { min: 0, max: 50 };
12
13
  exports.BOLUS_SECONDS_PASSED_LIMITS = { min: 0, max: exports.FOUR_HOURS_SECONDS };
@@ -14,6 +15,8 @@ exports.ACTIVITY_DURATION_MINUTES_LIMITS = { min: 1, max: exports.ONE_HOUR_MINUT
14
15
  exports.INSULIN_SENSITIVITY_MMOL_LIMITS = { min: 0.3, max: 10 };
15
16
  exports.INSULIN_TO_CARBS_RATIO_LIMITS = { min: 1, max: 50 };
16
17
  exports.CURRENT_BGL_MMOL_LIMITS = { min: 1.1, max: 33.3 };
18
+ exports.MMOLL_PER_MGDL = 0.0555;
19
+ exports.MGDL_PER_MMOLL = 1 / exports.MMOLL_PER_MGDL;
17
20
  exports.TARGET_BGL_MMOL_LIMITS = { min: 5, max: 13.9 };
18
21
  exports.ACTIVITY_TARGET_BGL_MMOL_LIMITS = { min: 5, max: 13.9 };
19
22
  exports.REMINDER_HOURS_LIMITS = { min: 0, max: 6 };
@@ -8,6 +8,8 @@ export const SEVERE_HYPERGLYCEMIA_START_MMOL = 15;
8
8
 
9
9
  export const FOUR_HOURS_SECONDS = 14400;
10
10
  export const ONE_HOUR_MINUTES = 60;
11
+ export const ACTIVITY_BUFFER_MINUTES = 10;
12
+
11
13
  export const CARBOHYDRATES_LIMTS: IInterval = { min: 0, max: 300 };
12
14
  export const INSULIN_DOSIS_LIMITS: IInterval = { min: 0, max: 50 };
13
15
  export const BOLUS_SECONDS_PASSED_LIMITS: IInterval = { min: 0, max: FOUR_HOURS_SECONDS };
@@ -17,6 +19,9 @@ export const INSULIN_SENSITIVITY_MMOL_LIMITS: IInterval = { min: 0.3, max: 10 };
17
19
  export const INSULIN_TO_CARBS_RATIO_LIMITS: IInterval = { min: 1, max: 50 };
18
20
 
19
21
  export const CURRENT_BGL_MMOL_LIMITS: IInterval = { min: 1.1, max: 33.3 };
22
+ export const MMOLL_PER_MGDL: number = 0.0555;
23
+ export const MGDL_PER_MMOLL: number = 1 / MMOLL_PER_MGDL;
24
+
20
25
  export const TARGET_BGL_MMOL_LIMITS: IInterval = { min: 5, max: 13.9 };
21
26
  export const ACTIVITY_TARGET_BGL_MMOL_LIMITS: IInterval = { min: 5, max: 13.9 };
22
27
  export const REMINDER_HOURS_LIMITS: IInterval = { min: 0, max: 6 };
@@ -9,7 +9,6 @@ export declare const ActivityDateError: () => RecommendationError;
9
9
  export declare const ActivityIntensityError: () => RecommendationError;
10
10
  export declare const ActivityTargetBGLError: () => RecommendationError;
11
11
  export declare const CarbohydrateLimitError: () => RecommendationError;
12
- export declare const InsulinLimitError: (activityReduction?: number) => RecommendationError;
13
12
  export declare const InsulinSensitivityError: () => RecommendationError;
14
13
  export declare const InsulinToCarbsRatioError: () => RecommendationError;
15
14
  export declare const CurrentBGLError: () => RecommendationError;
@@ -19,12 +19,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.TimeoutLimitError = exports.UnitError = exports.LanguageError = exports.InjectionMethodError = exports.UserReminderError = exports.BolusInsulinSecondsPassedError = exports.BolusInsulinDosisError = exports.TargetBGLError = exports.CurrentBGLError = exports.InsulinToCarbsRatioError = exports.InsulinSensitivityError = exports.InsulinLimitError = exports.CarbohydrateLimitError = exports.ActivityTargetBGLError = exports.ActivityIntensityError = exports.ActivityDateError = exports.ActivityDurationError = exports.ActivitySettingsError = exports.RecommendationError = void 0;
22
+ exports.TimeoutLimitError = exports.UnitError = exports.LanguageError = exports.InjectionMethodError = exports.UserReminderError = exports.BolusInsulinSecondsPassedError = exports.BolusInsulinDosisError = exports.TargetBGLError = exports.CurrentBGLError = exports.InsulinToCarbsRatioError = exports.InsulinSensitivityError = exports.CarbohydrateLimitError = exports.ActivityTargetBGLError = exports.ActivityIntensityError = exports.ActivityDateError = exports.ActivityDurationError = exports.ActivitySettingsError = exports.RecommendationError = void 0;
23
23
  const Calculator = __importStar(require("@hedia/recommendation-calculator"));
24
24
  const macro_1 = require("@lingui/macro");
25
25
  const i18nUtils_1 = require("../locale/i18nUtils");
26
26
  const enum_1 = require("../types/enum");
27
- const AttentionMessages_1 = require("./AttentionMessages");
28
27
  class RecommendationError extends Error {
29
28
  constructor(message, type) {
30
29
  super(message);
@@ -38,7 +37,6 @@ exports.ActivityDateError = () => new RecommendationError(i18nUtils_1.i18n._(mac
38
37
  exports.ActivityIntensityError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Hedia Calculator does not support your activity intensity value`), enum_1.RecommendationErrorEnum.ActivityIntensity);
39
38
  exports.ActivityTargetBGLError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Please verify that your activity target blood glucose value is correct.`), enum_1.RecommendationErrorEnum.ActivityTargetBGL);
40
39
  exports.CarbohydrateLimitError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Hedia Calculator does not support insulin recommendations with more than 300 grams of carbohydrates present.`), enum_1.RecommendationErrorEnum.CarbohydrateLimit);
41
- exports.InsulinLimitError = (activityReduction) => new RecommendationError(activityReduction ? AttentionMessages_1.Messages.InsulinWasLimited(activityReduction) : AttentionMessages_1.Messages.InsulinWasLimited(), enum_1.RecommendationErrorEnum.InsulinLimit);
42
40
  exports.InsulinSensitivityError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Please verify that your insulin sensitivity value is correct.`), enum_1.RecommendationErrorEnum.InsulinSensitivity);
43
41
  exports.InsulinToCarbsRatioError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Please verify that your insulin to carb ratio value is correct.`), enum_1.RecommendationErrorEnum.InsulinToCarbsRatio);
44
42
  exports.CurrentBGLError = () => new RecommendationError(i18nUtils_1.i18n._(macro_1.t `Error. Hedia Calculator does not support your current blood glucose level.`), enum_1.RecommendationErrorEnum.CurrentBGL);
@@ -2,7 +2,6 @@ import * as Calculator from "@hedia/recommendation-calculator";
2
2
  import { t } from "@lingui/macro";
3
3
  import { i18n } from "../locale/i18nUtils";
4
4
  import { RecommendationErrorEnum } from "../types/enum";
5
- import { Messages } from "./AttentionMessages";
6
5
 
7
6
  export class RecommendationError extends Error {
8
7
  public readonly type: RecommendationErrorEnum;
@@ -51,12 +50,6 @@ export const CarbohydrateLimitError = (): RecommendationError =>
51
50
  RecommendationErrorEnum.CarbohydrateLimit,
52
51
  );
53
52
 
54
- export const InsulinLimitError = (activityReduction?: number): RecommendationError =>
55
- new RecommendationError(
56
- activityReduction ? Messages.InsulinWasLimited(activityReduction) : Messages.InsulinWasLimited(),
57
- RecommendationErrorEnum.InsulinLimit,
58
- );
59
-
60
53
  export const InsulinSensitivityError = (): RecommendationError =>
61
54
  new RecommendationError(
62
55
  i18n._(t`Error. Please verify that your insulin sensitivity value is correct.`),
@@ -1,7 +1,6 @@
1
1
  import { IRecommendationParams } from "@hedia/recommendation-calculator";
2
- import { IRecommendationProps } from "../RecommendationScreen";
3
2
  import { BgLevel } from "../types/enum";
4
- import { IActivity, logbookEntry } from "../types/types";
3
+ import { logbookEntry } from "../types/types";
5
4
  import { AttentionMessage, Messages } from "./AttentionMessages";
6
5
  export declare function getBGLevel(currentBGL: number, latestLogbookFrom6Hours: logbookEntry): BgLevel;
7
6
  export declare function getReminder(bgLevel: BgLevel, carbohydrates: number, userReminder: number, activity: IRecommendationParams["activity"]): number;
@@ -9,4 +8,4 @@ export declare function getAttentionMessage(bgLevel: BgLevel, activity: IRecomme
9
8
  export declare function isSevereHyperglycemia(latestLogbookFrom6Hours: logbookEntry): boolean;
10
9
  export declare function isActivityWithin15Minutes(activity: IRecommendationParams["activity"]): boolean;
11
10
  export declare function getLimitationMessage(wasLimited: boolean, activityReduction: number): Messages;
12
- export declare function getParams(props: IRecommendationProps): IRecommendationParams & IActivity;
11
+ export declare function assignTargetBGL(calculatorParams: IRecommendationParams): IRecommendationParams;
@@ -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.getParams = exports.getLimitationMessage = exports.isActivityWithin15Minutes = exports.isSevereHyperglycemia = exports.getAttentionMessage = exports.getReminder = exports.getBGLevel = void 0;
6
+ exports.assignTargetBGL = exports.getLimitationMessage = exports.isActivityWithin15Minutes = exports.isSevereHyperglycemia = exports.getAttentionMessage = exports.getReminder = exports.getBGLevel = void 0;
7
7
  const moment_1 = __importDefault(require("moment"));
8
8
  const enum_1 = require("../types/enum");
9
9
  const AttentionMessages_1 = require("./AttentionMessages");
@@ -106,8 +106,7 @@ function getLimitationMessage(wasLimited, activityReduction) {
106
106
  return wasLimited ? message : undefined;
107
107
  }
108
108
  exports.getLimitationMessage = getLimitationMessage;
109
- function getParams(props) {
110
- const { calculatorParams } = props;
109
+ function assignTargetBGL(calculatorParams) {
111
110
  const activityTarget = calculatorParams.activity?.activitySettings?.target;
112
111
  const paramsWithAssignedCurrentBGL = {
113
112
  ...calculatorParams,
@@ -115,4 +114,4 @@ function getParams(props) {
115
114
  };
116
115
  return calculatorParams.currentBGL === null ? paramsWithAssignedCurrentBGL : calculatorParams;
117
116
  }
118
- exports.getParams = getParams;
117
+ exports.assignTargetBGL = assignTargetBGL;
@@ -1,8 +1,7 @@
1
1
  import { IRecommendationParams } from "@hedia/recommendation-calculator";
2
2
  import moment from "moment";
3
- import { IRecommendationProps } from "../RecommendationScreen";
4
3
  import { BgLevel, RecommendationReminders } from "../types/enum";
5
- import { IActivity, logbookEntry } from "../types/types";
4
+ import { logbookEntry } from "../types/types";
6
5
  import { addPostponeActivityMessage, AttentionMessage, Messages } from "./AttentionMessages";
7
6
  import { SEVERE_HYPERGLYCEMIA_START_MMOL } from "./Constants";
8
7
  import { CurrentBGLError } from "./RecommendationError";
@@ -117,8 +116,7 @@ export function getLimitationMessage(wasLimited: boolean, activityReduction: num
117
116
  return wasLimited ? message : undefined;
118
117
  }
119
118
 
120
- export function getParams(props: IRecommendationProps): IRecommendationParams & IActivity {
121
- const { calculatorParams } = props;
119
+ export function assignTargetBGL(calculatorParams: IRecommendationParams): IRecommendationParams {
122
120
  const activityTarget = calculatorParams.activity?.activitySettings?.target;
123
121
  const paramsWithAssignedCurrentBGL = {
124
122
  ...calculatorParams,
@@ -4,4 +4,5 @@ export declare class Utils {
4
4
  static getRounding(method: InjectionMethod): number;
5
5
  static roundValue(value: number, injectMethod: InjectionMethod): number;
6
6
  static isInClosedInterval(value: number, interval: IInterval): boolean;
7
+ static convertToMGDL(bglValueMMOL: number): number;
7
8
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Utils = void 0;
4
4
  const enum_1 = require("../types/enum");
5
+ const Constants_1 = require("./Constants");
5
6
  class Utils {
6
7
  static getRounding(method) {
7
8
  switch (method) {
@@ -26,5 +27,8 @@ class Utils {
26
27
  }
27
28
  return value >= interval.min && value <= interval.max;
28
29
  }
30
+ static convertToMGDL(bglValueMMOL) {
31
+ return Math.round(bglValueMMOL * Constants_1.MGDL_PER_MMOLL);
32
+ }
29
33
  }
30
34
  exports.Utils = Utils;
@@ -1,5 +1,6 @@
1
1
  import { InjectionMethod } from "../types/enum";
2
2
  import { IInterval } from "../types/types";
3
+ import { MGDL_PER_MMOLL } from "./Constants";
3
4
 
4
5
  export class Utils {
5
6
  public static getRounding(method: InjectionMethod): number {
@@ -31,4 +32,7 @@ export class Utils {
31
32
 
32
33
  return value >= interval.min && value <= interval.max;
33
34
  }
35
+ public static convertToMGDL(bglValueMMOL: number): number {
36
+ return Math.round(bglValueMMOL * MGDL_PER_MMOLL);
37
+ }
34
38
  }