@hedia/recommendation-screen 2.1.73 → 2.1.74-alpha.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 (408) hide show
  1. package/lib/commonjs/RecommendationScreen.js +768 -0
  2. package/lib/commonjs/RecommendationScreen.js.map +1 -0
  3. package/lib/commonjs/assets/IconsSVG/Close.js +20 -0
  4. package/lib/commonjs/assets/IconsSVG/Close.js.map +1 -0
  5. package/lib/commonjs/assets/IconsSVG/CloseOutlined.js +28 -0
  6. package/lib/commonjs/assets/IconsSVG/CloseOutlined.js.map +1 -0
  7. package/lib/commonjs/assets/IconsSVG/Edit.js +23 -0
  8. package/lib/commonjs/assets/IconsSVG/Edit.js.map +1 -0
  9. package/lib/commonjs/assets/IconsSVG/activity/Cycling.js +43 -0
  10. package/lib/commonjs/assets/IconsSVG/activity/Cycling.js.map +1 -0
  11. package/lib/commonjs/assets/IconsSVG/activity/Running.js +33 -0
  12. package/lib/commonjs/assets/IconsSVG/activity/Running.js.map +1 -0
  13. package/lib/commonjs/assets/IconsSVG/activity/Stretching.js +33 -0
  14. package/lib/commonjs/assets/IconsSVG/activity/Stretching.js.map +1 -0
  15. package/lib/commonjs/assets/IconsSVG/activity/Swimming.js +48 -0
  16. package/lib/commonjs/assets/IconsSVG/activity/Swimming.js.map +1 -0
  17. package/lib/commonjs/assets/IconsSVG/activity/Walking.js +38 -0
  18. package/lib/commonjs/assets/IconsSVG/activity/Walking.js.map +1 -0
  19. package/lib/commonjs/assets/IconsSVG/mood/Happy.js +34 -0
  20. package/lib/commonjs/assets/IconsSVG/mood/Happy.js.map +1 -0
  21. package/lib/commonjs/assets/IconsSVG/mood/Neutral.js +34 -0
  22. package/lib/commonjs/assets/IconsSVG/mood/Neutral.js.map +1 -0
  23. package/lib/commonjs/assets/IconsSVG/mood/Sad.js +34 -0
  24. package/lib/commonjs/assets/IconsSVG/mood/Sad.js.map +1 -0
  25. package/lib/commonjs/assets/IconsSVG/mood/SemiHappy.js +34 -0
  26. package/lib/commonjs/assets/IconsSVG/mood/SemiHappy.js.map +1 -0
  27. package/lib/commonjs/assets/IconsSVG/mood/SemiSad.js +34 -0
  28. package/lib/commonjs/assets/IconsSVG/mood/SemiSad.js.map +1 -0
  29. package/lib/commonjs/components/ExitModal.js +124 -0
  30. package/lib/commonjs/components/ExitModal.js.map +1 -0
  31. package/lib/commonjs/components/InfoBars.js +123 -0
  32. package/lib/commonjs/components/InfoBars.js.map +1 -0
  33. package/lib/commonjs/components/InvisibleNumberInput.js +150 -0
  34. package/lib/commonjs/components/InvisibleNumberInput.js.map +1 -0
  35. package/lib/commonjs/components/LineSeparator.js +27 -0
  36. package/lib/commonjs/components/LineSeparator.js.map +1 -0
  37. package/lib/commonjs/components/RecentInsulin.js +105 -0
  38. package/lib/commonjs/components/RecentInsulin.js.map +1 -0
  39. package/lib/commonjs/components/RecommendationModal.js +302 -0
  40. package/lib/commonjs/components/RecommendationModal.js.map +1 -0
  41. package/lib/commonjs/components/RecommendedCarbs.js +289 -0
  42. package/lib/commonjs/components/RecommendedCarbs.js.map +1 -0
  43. package/lib/commonjs/components/RecommendedInsulin.js +208 -0
  44. package/lib/commonjs/components/RecommendedInsulin.js.map +1 -0
  45. package/lib/commonjs/components/Remeasure.js +131 -0
  46. package/lib/commonjs/components/Remeasure.js.map +1 -0
  47. package/lib/commonjs/components/Text.js +25 -0
  48. package/lib/commonjs/components/Text.js.map +1 -0
  49. package/lib/commonjs/components/TimeoutModal.js +113 -0
  50. package/lib/commonjs/components/TimeoutModal.js.map +1 -0
  51. package/lib/commonjs/components/TransferToLogbook.js +83 -0
  52. package/lib/commonjs/components/TransferToLogbook.js.map +1 -0
  53. package/lib/commonjs/components/activity/Activity.js +112 -0
  54. package/lib/commonjs/components/activity/Activity.js.map +1 -0
  55. package/lib/commonjs/components/activity/ActivityIcon.js +86 -0
  56. package/lib/commonjs/components/activity/ActivityIcon.js.map +1 -0
  57. package/lib/commonjs/components/activity/ActivityIntensity.js +65 -0
  58. package/lib/commonjs/components/activity/ActivityIntensity.js.map +1 -0
  59. package/lib/commonjs/components/mood/Emotion.js +86 -0
  60. package/lib/commonjs/components/mood/Emotion.js.map +1 -0
  61. package/lib/commonjs/components/mood/MoodIcon.js +107 -0
  62. package/lib/commonjs/components/mood/MoodIcon.js.map +1 -0
  63. package/lib/commonjs/components/styles/fonts.js +154 -0
  64. package/lib/commonjs/components/styles/fonts.js.map +1 -0
  65. package/lib/commonjs/index.js +21 -0
  66. package/lib/commonjs/index.js.map +1 -0
  67. package/lib/commonjs/locales/da/translations.json +82 -0
  68. package/lib/commonjs/locales/de/translations.json +81 -0
  69. package/lib/commonjs/locales/en/translations.json +84 -0
  70. package/lib/commonjs/locales/es/translations.json +81 -0
  71. package/lib/commonjs/locales/fr/translations.json +81 -0
  72. package/lib/commonjs/locales/it/translations.json +81 -0
  73. package/lib/commonjs/locales/translate.js +63 -0
  74. package/lib/commonjs/locales/translate.js.map +1 -0
  75. package/lib/commonjs/types/enum.js +179 -0
  76. package/lib/commonjs/types/enum.js.map +1 -0
  77. package/lib/commonjs/types/types.js +6 -0
  78. package/lib/commonjs/types/types.js.map +1 -0
  79. package/lib/commonjs/utils/AttentionMessages.js +141 -0
  80. package/lib/commonjs/utils/AttentionMessages.js.map +1 -0
  81. package/lib/commonjs/utils/Constants.js +138 -0
  82. package/lib/commonjs/utils/Constants.js.map +1 -0
  83. package/lib/commonjs/utils/RecommendationError.js +116 -0
  84. package/lib/commonjs/utils/RecommendationError.js.map +1 -0
  85. package/lib/commonjs/utils/RecommendationUtils.js +212 -0
  86. package/lib/commonjs/utils/RecommendationUtils.js.map +1 -0
  87. package/lib/commonjs/utils/Translations.js +22 -0
  88. package/lib/commonjs/utils/Translations.js.map +1 -0
  89. package/lib/commonjs/utils/Utils.js +162 -0
  90. package/lib/commonjs/utils/Utils.js.map +1 -0
  91. package/lib/commonjs/utils/Validations.js +468 -0
  92. package/lib/commonjs/utils/Validations.js.map +1 -0
  93. package/lib/module/RecommendationScreen.js +758 -0
  94. package/lib/module/RecommendationScreen.js.map +1 -0
  95. package/lib/module/assets/IconsSVG/Close.js +11 -0
  96. package/lib/module/assets/IconsSVG/Close.js.map +1 -0
  97. package/lib/module/assets/IconsSVG/CloseOutlined.js +19 -0
  98. package/lib/module/assets/IconsSVG/CloseOutlined.js.map +1 -0
  99. package/lib/module/assets/IconsSVG/Edit.js +14 -0
  100. package/lib/module/assets/IconsSVG/Edit.js.map +1 -0
  101. package/lib/module/assets/IconsSVG/activity/Cycling.js +34 -0
  102. package/lib/module/assets/IconsSVG/activity/Cycling.js.map +1 -0
  103. package/lib/module/assets/IconsSVG/activity/Running.js +24 -0
  104. package/lib/module/assets/IconsSVG/activity/Running.js.map +1 -0
  105. package/lib/module/assets/IconsSVG/activity/Stretching.js +24 -0
  106. package/lib/module/assets/IconsSVG/activity/Stretching.js.map +1 -0
  107. package/lib/module/assets/IconsSVG/activity/Swimming.js +39 -0
  108. package/lib/module/assets/IconsSVG/activity/Swimming.js.map +1 -0
  109. package/lib/module/assets/IconsSVG/activity/Walking.js +29 -0
  110. package/lib/module/assets/IconsSVG/activity/Walking.js.map +1 -0
  111. package/lib/module/assets/IconsSVG/mood/Happy.js +25 -0
  112. package/lib/module/assets/IconsSVG/mood/Happy.js.map +1 -0
  113. package/lib/module/assets/IconsSVG/mood/Neutral.js +25 -0
  114. package/lib/module/assets/IconsSVG/mood/Neutral.js.map +1 -0
  115. package/lib/module/assets/IconsSVG/mood/Sad.js +25 -0
  116. package/lib/module/assets/IconsSVG/mood/Sad.js.map +1 -0
  117. package/lib/module/assets/IconsSVG/mood/SemiHappy.js +25 -0
  118. package/lib/module/assets/IconsSVG/mood/SemiHappy.js.map +1 -0
  119. package/lib/module/assets/IconsSVG/mood/SemiSad.js +25 -0
  120. package/lib/module/assets/IconsSVG/mood/SemiSad.js.map +1 -0
  121. package/lib/module/components/ExitModal.js +114 -0
  122. package/lib/module/components/ExitModal.js.map +1 -0
  123. package/lib/module/components/InfoBars.js +114 -0
  124. package/lib/module/components/InfoBars.js.map +1 -0
  125. package/lib/module/components/InvisibleNumberInput.js +142 -0
  126. package/lib/module/components/InvisibleNumberInput.js.map +1 -0
  127. package/lib/module/components/LineSeparator.js +19 -0
  128. package/lib/module/components/LineSeparator.js.map +1 -0
  129. package/lib/module/components/RecentInsulin.js +97 -0
  130. package/lib/module/components/RecentInsulin.js.map +1 -0
  131. package/lib/module/components/RecommendationModal.js +291 -0
  132. package/lib/module/components/RecommendationModal.js.map +1 -0
  133. package/lib/module/components/RecommendedCarbs.js +281 -0
  134. package/lib/module/components/RecommendedCarbs.js.map +1 -0
  135. package/lib/module/components/RecommendedInsulin.js +200 -0
  136. package/lib/module/components/RecommendedInsulin.js.map +1 -0
  137. package/lib/module/components/Remeasure.js +123 -0
  138. package/lib/module/components/Remeasure.js.map +1 -0
  139. package/lib/module/components/Text.js +16 -0
  140. package/lib/module/components/Text.js.map +1 -0
  141. package/lib/module/components/TimeoutModal.js +103 -0
  142. package/lib/module/components/TimeoutModal.js.map +1 -0
  143. package/lib/module/components/TransferToLogbook.js +75 -0
  144. package/lib/module/components/TransferToLogbook.js.map +1 -0
  145. package/lib/module/components/activity/Activity.js +104 -0
  146. package/lib/module/components/activity/Activity.js.map +1 -0
  147. package/lib/module/components/activity/ActivityIcon.js +78 -0
  148. package/lib/module/components/activity/ActivityIcon.js.map +1 -0
  149. package/lib/module/components/activity/ActivityIntensity.js +57 -0
  150. package/lib/module/components/activity/ActivityIntensity.js.map +1 -0
  151. package/lib/module/components/mood/Emotion.js +78 -0
  152. package/lib/module/components/mood/Emotion.js.map +1 -0
  153. package/lib/module/components/mood/MoodIcon.js +97 -0
  154. package/lib/module/components/mood/MoodIcon.js.map +1 -0
  155. package/lib/module/components/styles/fonts.js +145 -0
  156. package/lib/module/components/styles/fonts.js.map +1 -0
  157. package/lib/module/index.js +5 -0
  158. package/lib/module/index.js.map +1 -0
  159. package/lib/module/locales/da/translations.json +82 -0
  160. package/lib/module/locales/de/translations.json +81 -0
  161. package/lib/module/locales/en/translations.json +84 -0
  162. package/lib/module/locales/es/translations.json +81 -0
  163. package/lib/module/locales/fr/translations.json +81 -0
  164. package/lib/module/locales/it/translations.json +81 -0
  165. package/lib/module/locales/translate.js +55 -0
  166. package/lib/module/locales/translate.js.map +1 -0
  167. package/lib/module/types/enum.js +170 -0
  168. package/lib/module/types/enum.js.map +1 -0
  169. package/lib/module/types/types.js.map +1 -0
  170. package/lib/module/utils/AttentionMessages.js +131 -0
  171. package/lib/module/utils/AttentionMessages.js.map +1 -0
  172. package/{dist/src → lib/module}/utils/Constants.js +78 -35
  173. package/lib/module/utils/Constants.js.map +1 -0
  174. package/{dist/src → lib/module}/utils/RecommendationError.js +28 -6
  175. package/lib/module/utils/RecommendationError.js.map +1 -0
  176. package/{dist/src → lib/module}/utils/RecommendationUtils.js +89 -90
  177. package/lib/module/utils/RecommendationUtils.js.map +1 -0
  178. package/{dist/src → lib/module}/utils/Translations.js +5 -3
  179. package/lib/module/utils/Translations.js.map +1 -0
  180. package/lib/module/utils/Utils.js +155 -0
  181. package/lib/module/utils/Utils.js.map +1 -0
  182. package/{dist/src → lib/module}/utils/Validations.js +155 -128
  183. package/lib/module/utils/Validations.js.map +1 -0
  184. package/{dist/src → lib/typescript}/RecommendationScreen.d.ts +2 -1
  185. package/lib/typescript/RecommendationScreen.d.ts.map +1 -0
  186. package/{dist/src → lib/typescript}/assets/IconsSVG/Close.d.ts +1 -0
  187. package/lib/typescript/assets/IconsSVG/Close.d.ts.map +1 -0
  188. package/{dist/src → lib/typescript}/assets/IconsSVG/CloseOutlined.d.ts +1 -0
  189. package/lib/typescript/assets/IconsSVG/CloseOutlined.d.ts.map +1 -0
  190. package/{dist/src → lib/typescript}/assets/IconsSVG/Edit.d.ts +1 -0
  191. package/lib/typescript/assets/IconsSVG/Edit.d.ts.map +1 -0
  192. package/{dist/src → lib/typescript}/assets/IconsSVG/activity/Cycling.d.ts +1 -0
  193. package/lib/typescript/assets/IconsSVG/activity/Cycling.d.ts.map +1 -0
  194. package/{dist/src → lib/typescript}/assets/IconsSVG/activity/Running.d.ts +1 -0
  195. package/lib/typescript/assets/IconsSVG/activity/Running.d.ts.map +1 -0
  196. package/{dist/src → lib/typescript}/assets/IconsSVG/activity/Stretching.d.ts +1 -0
  197. package/lib/typescript/assets/IconsSVG/activity/Stretching.d.ts.map +1 -0
  198. package/{dist/src → lib/typescript}/assets/IconsSVG/activity/Swimming.d.ts +1 -0
  199. package/lib/typescript/assets/IconsSVG/activity/Swimming.d.ts.map +1 -0
  200. package/{dist/src → lib/typescript}/assets/IconsSVG/activity/Walking.d.ts +1 -0
  201. package/lib/typescript/assets/IconsSVG/activity/Walking.d.ts.map +1 -0
  202. package/{dist/src → lib/typescript}/assets/IconsSVG/mood/Happy.d.ts +1 -0
  203. package/lib/typescript/assets/IconsSVG/mood/Happy.d.ts.map +1 -0
  204. package/{dist/src → lib/typescript}/assets/IconsSVG/mood/Neutral.d.ts +1 -0
  205. package/lib/typescript/assets/IconsSVG/mood/Neutral.d.ts.map +1 -0
  206. package/{dist/src → lib/typescript}/assets/IconsSVG/mood/Sad.d.ts +1 -0
  207. package/lib/typescript/assets/IconsSVG/mood/Sad.d.ts.map +1 -0
  208. package/{dist/src → lib/typescript}/assets/IconsSVG/mood/SemiHappy.d.ts +1 -0
  209. package/lib/typescript/assets/IconsSVG/mood/SemiHappy.d.ts.map +1 -0
  210. package/{dist/src → lib/typescript}/assets/IconsSVG/mood/SemiSad.d.ts +1 -0
  211. package/lib/typescript/assets/IconsSVG/mood/SemiSad.d.ts.map +1 -0
  212. package/{dist/src → lib/typescript}/components/ExitModal.d.ts +1 -0
  213. package/lib/typescript/components/ExitModal.d.ts.map +1 -0
  214. package/{dist/src → lib/typescript}/components/InfoBars.d.ts +1 -0
  215. package/lib/typescript/components/InfoBars.d.ts.map +1 -0
  216. package/{dist/src → lib/typescript}/components/InvisibleNumberInput.d.ts +1 -0
  217. package/lib/typescript/components/InvisibleNumberInput.d.ts.map +1 -0
  218. package/{dist/src → lib/typescript}/components/LineSeparator.d.ts +1 -0
  219. package/lib/typescript/components/LineSeparator.d.ts.map +1 -0
  220. package/{dist/src → lib/typescript}/components/RecentInsulin.d.ts +1 -0
  221. package/lib/typescript/components/RecentInsulin.d.ts.map +1 -0
  222. package/{dist/src → lib/typescript}/components/RecommendationModal.d.ts +1 -0
  223. package/lib/typescript/components/RecommendationModal.d.ts.map +1 -0
  224. package/{dist/src → lib/typescript}/components/RecommendedCarbs.d.ts +1 -0
  225. package/lib/typescript/components/RecommendedCarbs.d.ts.map +1 -0
  226. package/{dist/src → lib/typescript}/components/RecommendedInsulin.d.ts +1 -0
  227. package/lib/typescript/components/RecommendedInsulin.d.ts.map +1 -0
  228. package/{dist/src → lib/typescript}/components/Remeasure.d.ts +1 -0
  229. package/lib/typescript/components/Remeasure.d.ts.map +1 -0
  230. package/{dist/src → lib/typescript}/components/Text.d.ts +1 -0
  231. package/lib/typescript/components/Text.d.ts.map +1 -0
  232. package/{dist/src → lib/typescript}/components/TimeoutModal.d.ts +1 -0
  233. package/lib/typescript/components/TimeoutModal.d.ts.map +1 -0
  234. package/{dist/src → lib/typescript}/components/TransferToLogbook.d.ts +1 -0
  235. package/lib/typescript/components/TransferToLogbook.d.ts.map +1 -0
  236. package/{dist/src → lib/typescript}/components/activity/Activity.d.ts +1 -0
  237. package/lib/typescript/components/activity/Activity.d.ts.map +1 -0
  238. package/{dist/src → lib/typescript}/components/activity/ActivityIcon.d.ts +1 -0
  239. package/lib/typescript/components/activity/ActivityIcon.d.ts.map +1 -0
  240. package/{dist/src → lib/typescript}/components/activity/ActivityIntensity.d.ts +1 -0
  241. package/lib/typescript/components/activity/ActivityIntensity.d.ts.map +1 -0
  242. package/{dist/src → lib/typescript}/components/mood/Emotion.d.ts +1 -0
  243. package/lib/typescript/components/mood/Emotion.d.ts.map +1 -0
  244. package/{dist/src → lib/typescript}/components/mood/MoodIcon.d.ts +1 -0
  245. package/lib/typescript/components/mood/MoodIcon.d.ts.map +1 -0
  246. package/{dist/src → lib/typescript}/components/styles/fonts.d.ts +1 -0
  247. package/lib/typescript/components/styles/fonts.d.ts.map +1 -0
  248. package/lib/typescript/index.d.ts +5 -0
  249. package/lib/typescript/index.d.ts.map +1 -0
  250. package/{dist/src → lib/typescript}/locales/translate.d.ts +1 -0
  251. package/lib/typescript/locales/translate.d.ts.map +1 -0
  252. package/{dist/src → lib/typescript}/types/enum.d.ts +1 -0
  253. package/lib/typescript/types/enum.d.ts.map +1 -0
  254. package/{dist/src → lib/typescript}/types/types.d.ts +1 -0
  255. package/lib/typescript/types/types.d.ts.map +1 -0
  256. package/{dist/src → lib/typescript}/utils/AttentionMessages.d.ts +1 -0
  257. package/lib/typescript/utils/AttentionMessages.d.ts.map +1 -0
  258. package/{dist/src → lib/typescript}/utils/Constants.d.ts +1 -0
  259. package/lib/typescript/utils/Constants.d.ts.map +1 -0
  260. package/{dist/src → lib/typescript}/utils/RecommendationError.d.ts +1 -0
  261. package/lib/typescript/utils/RecommendationError.d.ts.map +1 -0
  262. package/{dist/src → lib/typescript}/utils/RecommendationUtils.d.ts +1 -0
  263. package/lib/typescript/utils/RecommendationUtils.d.ts.map +1 -0
  264. package/{dist/src → lib/typescript}/utils/Translations.d.ts +1 -0
  265. package/lib/typescript/utils/Translations.d.ts.map +1 -0
  266. package/{dist/src → lib/typescript}/utils/Utils.d.ts +1 -0
  267. package/lib/typescript/utils/Utils.d.ts.map +1 -0
  268. package/{dist/src → lib/typescript}/utils/Validations.d.ts +1 -0
  269. package/lib/typescript/utils/Validations.d.ts.map +1 -0
  270. package/package.json +27 -7
  271. package/src/RecommendationScreen.tsx +854 -0
  272. package/src/assets/IconsSVG/Close.tsx +13 -0
  273. package/src/assets/IconsSVG/CloseOutlined.tsx +23 -0
  274. package/src/assets/IconsSVG/Edit.tsx +16 -0
  275. package/src/assets/IconsSVG/activity/Cycling.tsx +41 -0
  276. package/src/assets/IconsSVG/activity/Running.tsx +29 -0
  277. package/src/assets/IconsSVG/activity/Stretching.tsx +29 -0
  278. package/src/assets/IconsSVG/activity/Swimming.tsx +47 -0
  279. package/src/assets/IconsSVG/activity/Walking.tsx +35 -0
  280. package/src/assets/IconsSVG/mood/Happy.tsx +30 -0
  281. package/src/assets/IconsSVG/mood/Neutral.tsx +30 -0
  282. package/src/assets/IconsSVG/mood/Sad.tsx +30 -0
  283. package/src/assets/IconsSVG/mood/SemiHappy.tsx +30 -0
  284. package/src/assets/IconsSVG/mood/SemiSad.tsx +30 -0
  285. package/src/components/ExitModal.tsx +134 -0
  286. package/src/components/InfoBars.tsx +122 -0
  287. package/src/components/InvisibleNumberInput.tsx +170 -0
  288. package/src/components/LineSeparator.tsx +29 -0
  289. package/src/components/RecentInsulin.tsx +109 -0
  290. package/src/components/RecommendationModal.tsx +319 -0
  291. package/src/components/RecommendedCarbs.tsx +303 -0
  292. package/src/components/RecommendedInsulin.tsx +219 -0
  293. package/src/components/Remeasure.tsx +135 -0
  294. package/src/components/Text.tsx +27 -0
  295. package/src/components/TimeoutModal.tsx +121 -0
  296. package/src/components/TransferToLogbook.tsx +92 -0
  297. package/src/components/activity/Activity.tsx +107 -0
  298. package/src/components/activity/ActivityIcon.tsx +77 -0
  299. package/src/components/activity/ActivityIntensity.tsx +67 -0
  300. package/src/components/mood/Emotion.tsx +97 -0
  301. package/src/components/mood/MoodIcon.tsx +91 -0
  302. package/src/components/styles/fonts.ts +145 -0
  303. package/src/index.ts +5 -0
  304. package/src/locales/da/translations.json +82 -0
  305. package/src/locales/de/translations.json +81 -0
  306. package/src/locales/en/translations.json +84 -0
  307. package/src/locales/es/translations.json +81 -0
  308. package/src/locales/fr/translations.json +81 -0
  309. package/src/locales/it/translations.json +81 -0
  310. package/src/locales/translate.ts +62 -0
  311. package/src/types/enum.ts +164 -0
  312. package/src/types/types.ts +19 -0
  313. package/src/utils/AttentionMessages.ts +167 -0
  314. package/src/utils/Constants.ts +77 -0
  315. package/src/utils/RecommendationError.ts +182 -0
  316. package/src/utils/RecommendationUtils.ts +232 -0
  317. package/src/utils/Translations.ts +17 -0
  318. package/src/utils/Utils.ts +156 -0
  319. package/src/utils/Validations.ts +490 -0
  320. package/dist/index.d.ts +0 -5
  321. package/dist/index.js +0 -6
  322. package/dist/index.js.map +0 -1
  323. package/dist/src/RecommendationScreen.js +0 -537
  324. package/dist/src/RecommendationScreen.js.map +0 -1
  325. package/dist/src/assets/IconsSVG/Close.js +0 -7
  326. package/dist/src/assets/IconsSVG/Close.js.map +0 -1
  327. package/dist/src/assets/IconsSVG/CloseOutlined.js +0 -9
  328. package/dist/src/assets/IconsSVG/CloseOutlined.js.map +0 -1
  329. package/dist/src/assets/IconsSVG/Edit.js +0 -8
  330. package/dist/src/assets/IconsSVG/Edit.js.map +0 -1
  331. package/dist/src/assets/IconsSVG/activity/Cycling.js +0 -12
  332. package/dist/src/assets/IconsSVG/activity/Cycling.js.map +0 -1
  333. package/dist/src/assets/IconsSVG/activity/Running.js +0 -10
  334. package/dist/src/assets/IconsSVG/activity/Running.js.map +0 -1
  335. package/dist/src/assets/IconsSVG/activity/Stretching.js +0 -10
  336. package/dist/src/assets/IconsSVG/activity/Stretching.js.map +0 -1
  337. package/dist/src/assets/IconsSVG/activity/Swimming.js +0 -13
  338. package/dist/src/assets/IconsSVG/activity/Swimming.js.map +0 -1
  339. package/dist/src/assets/IconsSVG/activity/Walking.js +0 -11
  340. package/dist/src/assets/IconsSVG/activity/Walking.js.map +0 -1
  341. package/dist/src/assets/IconsSVG/mood/Happy.js +0 -11
  342. package/dist/src/assets/IconsSVG/mood/Happy.js.map +0 -1
  343. package/dist/src/assets/IconsSVG/mood/Neutral.js +0 -11
  344. package/dist/src/assets/IconsSVG/mood/Neutral.js.map +0 -1
  345. package/dist/src/assets/IconsSVG/mood/Sad.js +0 -11
  346. package/dist/src/assets/IconsSVG/mood/Sad.js.map +0 -1
  347. package/dist/src/assets/IconsSVG/mood/SemiHappy.js +0 -11
  348. package/dist/src/assets/IconsSVG/mood/SemiHappy.js.map +0 -1
  349. package/dist/src/assets/IconsSVG/mood/SemiSad.js +0 -11
  350. package/dist/src/assets/IconsSVG/mood/SemiSad.js.map +0 -1
  351. package/dist/src/components/ExitModal.js +0 -91
  352. package/dist/src/components/ExitModal.js.map +0 -1
  353. package/dist/src/components/InfoBars.js +0 -98
  354. package/dist/src/components/InfoBars.js.map +0 -1
  355. package/dist/src/components/InvisibleNumberInput.js +0 -123
  356. package/dist/src/components/InvisibleNumberInput.js.map +0 -1
  357. package/dist/src/components/LineSeparator.js +0 -17
  358. package/dist/src/components/LineSeparator.js.map +0 -1
  359. package/dist/src/components/RecentInsulin.js +0 -90
  360. package/dist/src/components/RecentInsulin.js.map +0 -1
  361. package/dist/src/components/RecommendationModal.js +0 -241
  362. package/dist/src/components/RecommendationModal.js.map +0 -1
  363. package/dist/src/components/RecommendedCarbs.js +0 -234
  364. package/dist/src/components/RecommendedCarbs.js.map +0 -1
  365. package/dist/src/components/RecommendedInsulin.js +0 -166
  366. package/dist/src/components/RecommendedInsulin.js.map +0 -1
  367. package/dist/src/components/Remeasure.js +0 -103
  368. package/dist/src/components/Remeasure.js.map +0 -1
  369. package/dist/src/components/Text.js +0 -14
  370. package/dist/src/components/Text.js.map +0 -1
  371. package/dist/src/components/TimeoutModal.js +0 -84
  372. package/dist/src/components/TimeoutModal.js.map +0 -1
  373. package/dist/src/components/TransferToLogbook.js +0 -68
  374. package/dist/src/components/TransferToLogbook.js.map +0 -1
  375. package/dist/src/components/activity/Activity.js +0 -93
  376. package/dist/src/components/activity/Activity.js.map +0 -1
  377. package/dist/src/components/activity/ActivityIcon.js +0 -66
  378. package/dist/src/components/activity/ActivityIcon.js.map +0 -1
  379. package/dist/src/components/activity/ActivityIntensity.js +0 -55
  380. package/dist/src/components/activity/ActivityIntensity.js.map +0 -1
  381. package/dist/src/components/mood/Emotion.js +0 -69
  382. package/dist/src/components/mood/Emotion.js.map +0 -1
  383. package/dist/src/components/mood/MoodIcon.js +0 -68
  384. package/dist/src/components/mood/MoodIcon.js.map +0 -1
  385. package/dist/src/components/styles/fonts.js +0 -145
  386. package/dist/src/components/styles/fonts.js.map +0 -1
  387. package/dist/src/locales/da/translations.json +0 -82
  388. package/dist/src/locales/de/translations.json +0 -81
  389. package/dist/src/locales/en/translations.json +0 -84
  390. package/dist/src/locales/es/translations.json +0 -81
  391. package/dist/src/locales/fr/translations.json +0 -81
  392. package/dist/src/locales/it/translations.json +0 -81
  393. package/dist/src/locales/translate.js +0 -53
  394. package/dist/src/locales/translate.js.map +0 -1
  395. package/dist/src/types/enum.js +0 -154
  396. package/dist/src/types/enum.js.map +0 -1
  397. package/dist/src/types/types.js.map +0 -1
  398. package/dist/src/utils/AttentionMessages.js +0 -123
  399. package/dist/src/utils/AttentionMessages.js.map +0 -1
  400. package/dist/src/utils/Constants.js.map +0 -1
  401. package/dist/src/utils/RecommendationError.js.map +0 -1
  402. package/dist/src/utils/RecommendationUtils.js.map +0 -1
  403. package/dist/src/utils/Translations.js.map +0 -1
  404. package/dist/src/utils/Utils.js +0 -142
  405. package/dist/src/utils/Utils.js.map +0 -1
  406. package/dist/src/utils/Validations.js.map +0 -1
  407. package/dist/tsconfig.tsbuildinfo +0 -1
  408. /package/{dist/src → lib/module}/types/types.js +0 -0
@@ -0,0 +1,854 @@
1
+ import React from "react";
2
+ import { AppState, AppStateStatus, LogBox, NativeEventSubscription, StyleSheet, View } from "react-native";
3
+ import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
4
+
5
+ import * as Calculator from "@hedia/recommendation-calculator";
6
+ import {
7
+ BloodGlucoseUnit,
8
+ BloodKetonesUnit,
9
+ BolusCalculator,
10
+ Languages,
11
+ Logbook,
12
+ Milliseconds,
13
+ UserSettings,
14
+ } from "@hedia/types";
15
+
16
+ import Activity from "./components/activity/Activity";
17
+ import ExitModal from "./components/ExitModal";
18
+ import InfoBars from "./components/InfoBars";
19
+ import Emotion from "./components/mood/Emotion";
20
+ import RecentInsulin from "./components/RecentInsulin";
21
+ import RecommendationModal from "./components/RecommendationModal";
22
+ import RecommendedCarbs from "./components/RecommendedCarbs";
23
+ import RecommendedInsulin from "./components/RecommendedInsulin";
24
+ import Remeasure from "./components/Remeasure";
25
+ import { FONTS } from "./components/styles/fonts";
26
+ import Text from "./components/Text";
27
+ import TimeoutModal from "./components/TimeoutModal";
28
+ import TransferToLogbook from "./components/TransferToLogbook";
29
+ import { changeLocale, t } from "./locales/translate";
30
+ import { ExitModalActions, Testing, TimeoutModalActions } from "./types/enum";
31
+ import { IActivityDisplayProps } from "./types/types";
32
+ import { Messages } from "./utils/AttentionMessages";
33
+ import { colors } from "./utils/Constants";
34
+ import { RecommendationError } from "./utils/RecommendationError";
35
+ import { getAttentionMessage, getBGLevel, getLimitationMessage, getReminder } from "./utils/RecommendationUtils";
36
+ import { Utils } from "./utils/Utils";
37
+ import { validateParams } from "./utils/Validations";
38
+
39
+ const { InfoBarTestIds, RecommendationScreenTestIds } = Testing.Id;
40
+
41
+ // Ignoring long timer warnings
42
+ // https://github.com/facebook/react-native/issues/12981#issuecomment-652745831
43
+ LogBox.ignoreLogs([`Setting a timer`]);
44
+
45
+ /** Represents both a suggestion by HDA and an actual amount of either insulin or carbohydrates. */
46
+ export interface IResult {
47
+ /** The suggested amount (of insulin in units or carbohydrates in grams) */
48
+ suggested: number;
49
+ /** The actual amount (of insulin in units or carbohydrates in grams) */
50
+ entered: number | null;
51
+ }
52
+
53
+ export interface IRecommendationProps {
54
+ /** The blood glucose measurement unit that the user prefers. */
55
+ bloodGlucoseUnit: BloodGlucoseUnit;
56
+ /** The user’s preferred language. */
57
+ language: keyof typeof Languages;
58
+ /** The user’s preferred default reminder time in hours when they enter carbohydrates or an activity. */
59
+ userReminder: number;
60
+ /** The values needed to make an insulin recommendation calculation. */
61
+ calculatorParams: BolusCalculator.Types.IRecommendationParams;
62
+ /** Indicates which method the user uses to inject insulin and thus how insulin amounts should be rounded. */
63
+ injectionMethod: UserSettings.Enums.InjectionMethod;
64
+ /** The user’s entered current blood ketones value. Null if no blood ketones value was entered. */
65
+ currentBKL: number | null;
66
+ /** The blood ketones measurement unit that the user prefers. Null if the user hasn’t selected a preferred blood ketones unit. */
67
+ bloodKetoneUnit: BloodKetonesUnit | null;
68
+ /** The latest logbook entry (if any) from the last 6 hours. */
69
+ latestLogbookFrom6Hours: Logbook.Types.ILogbookEntry | null;
70
+ /** The properties of the entered activity that are not used for making the calculation itself, but will be used on the recommendation screen. */
71
+ activityDisplayProps: IActivityDisplayProps | null;
72
+ /** Should the exit modal be displayed or not */
73
+ showExitModal: boolean;
74
+
75
+ /**
76
+ * Callback function taking a single boolean argument and returning nothing.
77
+ * To be called when the user decides on a presented carbohydrate recommendation.
78
+ * @param carbRecommendationAnswer Whether the user chose to accept (true) or reject (false) the carbohydrate recommendation.
79
+ */
80
+ carbRecommendationAnswer(carbRecommendationAnswer: boolean): void;
81
+ /**
82
+ * Callback function without arguments or return values.
83
+ * To be called if the user decides to exit the recommendation screen without transferring any of the data to the logbook.
84
+ * The unsaved logbook data shall be cleared.
85
+ */
86
+ closeCalculationCallback(): void;
87
+ /**
88
+ * Callback function without arguments or return values.
89
+ * To be called if the user closes the recommendation screen by tapping the cancel button in the header.
90
+ */
91
+ exitCallback(): void;
92
+ /**
93
+ * Callback function without arguments or return values.
94
+ * To be called if the user taps “Yes” when asked if they have taken insulin recently.
95
+ * Should allow the user to enter when they injected insulin and how much.
96
+ */
97
+ onRecentInsulinYes(): void;
98
+ /**
99
+ * Callback function without arguments or return values.
100
+ * To be called if the user taps “No” when asked if they have taken insulin recently.
101
+ * Should allow the user to enter when they injected insulin and how much.
102
+ */
103
+ onRecentInsulinNo(): void;
104
+ /**
105
+ * Callback function without arguments or return values.
106
+ * To be called if the user taps “No” when asked if they have taken insulin recently, making the recommendation visible.
107
+ * Should display insulin recommendation.
108
+ */
109
+ onRecommendationDisplayed(): void;
110
+ /**
111
+ * To be called when the “Transfer to Logbook” button is pressed.
112
+ * @param carbs The suggested and entered amount of carbohydrates.
113
+ * @param insulin The suggested and entered amount of insulin.
114
+ * @param reminder The amount of time in hours until the user should get a reminder to measure their BGL again.
115
+ * @param recommendationDate The date and time when the recommendation calculation was made.
116
+ * @param mood The mood the user has selected
117
+ */
118
+ transferToLogbook(
119
+ carbs: IResult,
120
+ insulin: IResult,
121
+ reminder: number,
122
+ recommendationDate: Date,
123
+ mood: Logbook.Enums.MoodEnum | null,
124
+ ): void;
125
+ /**
126
+ * Callback function taking a single argument of type RecommendationError.
127
+ * To be called in case a serious issue with the validity of input data is detected.
128
+ * @param error The detected error.
129
+ */
130
+ onError(error: RecommendationError | Error): void;
131
+ /**
132
+ * Callback function taking no arguments.
133
+ * To be called if the user chooses to restart the calculation.
134
+ */
135
+ restartCalculation(): void;
136
+ /**
137
+ * Callback function without arguments or return values.
138
+ */
139
+ hideExitModal(): void;
140
+ /**
141
+ * Callback function without arguments or return values.
142
+ * To be called if the user taps "No, return to dahsboard" when asked after 15 mins of inactivity.
143
+ */
144
+ onReturnToDashboard(): void;
145
+ /**
146
+ * Callback function without arguments or return values.
147
+ * To be called if the user taps “Yes, save to logbook” when asked after 15 mins of inactivity.
148
+ */
149
+ onSaveToLogbook(): void;
150
+ }
151
+
152
+ interface IState {
153
+ /** The time in hours in hours until a reminder notification will be sent to the user. If 0 then no notification will be sent. */
154
+ remeasureTime: number;
155
+ /**
156
+ * If true then the user will see the insulin input field with their recommendation.
157
+ * Otherwise, the user will be presented with a card that asks them whether they have taken bolus insulin within the last 4 hours
158
+ */
159
+ isRecommendationDisplayed: boolean;
160
+ /** The suggested amount of insulin. */
161
+ insulinRecommendation: number;
162
+ /** The fraction by which the recommendation was multiplied to get the reduced amount */
163
+ activityReduction: number | null;
164
+ /** Indicates whether or not the insulin recommendation was limited by the maximum threshold. */
165
+ wasLimited: boolean;
166
+ /** The suggested amount of additional carbs. */
167
+ carbRecommendation: number | null;
168
+ /** The amount of IOB that was estimated during the recommendation calculation. */
169
+ activeInsulin: number;
170
+ /** The mood that is currently selected or null if no mood is selected. */
171
+ selectedMood: Logbook.Enums.MoodEnum | null;
172
+ /** The amount of carbs that are being shown in the additional carbs input field. */
173
+ enteredCarbs: number | null;
174
+ /** The current insulin value in the insulin recommendation/input field. */
175
+ enteredInsulin: number | null;
176
+ /** Indicates whether or not the modal for displaying warnings and other special messages should be visible. */
177
+ recommendationModal: boolean;
178
+ /**
179
+ * Keeps track of whether or not the exit modal should be displayed.
180
+ * The exit modal prompts the user to consider saving the calculation to a logbook entry before closing the recommendation screen.
181
+ */
182
+ showExitModal: boolean;
183
+ /** Keeps track of action taken in the exit modal. */
184
+ exitModalAction: ExitModalActions | null;
185
+ /** Keeps track of whether or not only the limitation page of the recommendation modal should be visible. */
186
+ onlyShowLimitationMessage: boolean;
187
+ /** Keeps track of whether or not a message about the recommendation being too old should be displayed. */
188
+ showTimeoutModal: boolean;
189
+ /** Keeps track of action taken in the timout modal. */
190
+ timeoutModalAction: TimeoutModalActions | null;
191
+ }
192
+
193
+ /**
194
+ * The RecommendationScreen is the React component that passes relevant inputs to the recommendation calculation module and presents
195
+ * the resulting recommendation along with related messages or warnings to the user.
196
+ * The RecommendationScreen component accepts properties with the user’s settings/preferences and other inputs needed for calculating a recommendation.
197
+ * @noInheritDoc
198
+ */
199
+ export class RecommendationScreen extends React.Component<IRecommendationProps, IState> {
200
+ /** Reference to the timer that prompts the user to make a new calculation after 15 minutes. */
201
+ private readonly timer!: ReturnType<typeof setTimeout>;
202
+ /**
203
+ * The carbohydrate recommendation for the user.
204
+ * This value is saved in a member variable because we want to store it unmodified if the logbook entry
205
+ * gets saved regardless of what other changes were made on the recommendation screen.
206
+ */
207
+ private readonly suggestedCarbs!: number;
208
+ /**
209
+ * A guard against displaying wrong or dangerous information to the user.
210
+ * If an error has occurred, this variable will be set to true and an empty placeholder will be rendered instead of the normal recommendation screen.
211
+ */
212
+ private readonly hasError: boolean = false;
213
+ /** The timestamp when the current recommendation was made. For determining if the recommendation is too old and should be hidden from the user. */
214
+ private readonly recommendationDate!: Date;
215
+ /**
216
+ * A reference to the screens scrollview allowing us to programmatically scroll the screen in the handleNoRecentInsulin() method.
217
+ * The member is initiated without a value but will be set as soon as the component is being rendered.
218
+ */
219
+ private scrollView?: KeyboardAwareScrollView;
220
+
221
+ /**
222
+ * A reference to the eventSubscription that'll be returned by AppState.addEventListener().
223
+ * It'll allow us to later remove the subscription.
224
+ */
225
+ private appStateSubscription?: NativeEventSubscription;
226
+
227
+ /**
228
+ * Steps:
229
+ * 1. Call the super() method with the props.
230
+ * 2. Execute the following steps and if an exception is thrown, catch it, set the hasError member variable to true and call the onError callback prop with the caught exception as argument:
231
+ * - Call the validateParams() method with the props as argument
232
+ * - Set the recommendationDate member to the current date and time
233
+ * - Set the language by using the language prop as argument for calling changeLanguage()
234
+ * - Unpack recentBoluses from the calculatorParams prop.
235
+ * - Use the calculatorParams prop as argument for calling calculateRecommendation() and unpack all of the resulting values.
236
+ * - Call the onRecommendationDisplayed() callback prop if the recommendation is visible
237
+ * - Copy the carbRecommendation to the suggestedCarbs member variable.
238
+ * - Set the following state variables:
239
+ * - Set remeasureTime to the return value from calling the getBGLevelRemeasurementReminder() method.
240
+ * - Set isRecommendationDisplayed to be false if the length of recentBoluses is 0 or false otherwise.
241
+ * - Set insulinRecommendation to be the bolus insulin recommendation rounded using roundValue().
242
+ * - Set wasLimited to the wasLimited return value from calling calculateRecommendation() above.
243
+ * - Set activityReduction to the reduction returned from the calculation result.
244
+ * - Set carbRecommendation to the recommendation returned from the calculation result.
245
+ * - Set activeInsulin to the estimation returned from the calculation result.
246
+ * - Set enteredCarbs, enteredInsulin, selectedMood to null.
247
+ * - Set recommendationModal to be true if wasLimited is true or if carbRecommendation after being rounded is truthy or if the return value from calling the getBGLevelAttentionMessage() method is truthy.
248
+ * - Set onlyShowLimitationMessage, showTimeoutModal to be false.
249
+ * - Set showExitModal with the value of the showExitModal prop.
250
+ * 3. Start a 15 minute timer assigned to the timer member variable using the setTimeout() function. When the timer expires, call the showTimeoutModal() method.
251
+ * @param props The data required to initialise the Recommendation Screen
252
+ */
253
+ constructor(props: IRecommendationProps) {
254
+ super(props);
255
+ try {
256
+ validateParams(props);
257
+ changeLocale(props.language);
258
+ this.recommendationDate = new Date();
259
+
260
+ const { recentBoluses } = props.calculatorParams;
261
+ const { bolus, carbRecommendation, activityReduction, wasLimited, activeInsulin } =
262
+ Calculator.calculateRecommendation(props.calculatorParams);
263
+
264
+ this.suggestedCarbs = carbRecommendation;
265
+
266
+ const isRecommendationDisplayed = recentBoluses?.length !== 0;
267
+ if (isRecommendationDisplayed) {
268
+ this.props.onRecommendationDisplayed();
269
+ }
270
+
271
+ this.state = {
272
+ remeasureTime: this.getBGLevelRemeasurementReminder(),
273
+ isRecommendationDisplayed,
274
+ insulinRecommendation: Utils.roundValue(bolus, props.injectionMethod),
275
+ wasLimited,
276
+ activityReduction,
277
+ carbRecommendation,
278
+ activeInsulin,
279
+ enteredCarbs: null,
280
+ enteredInsulin: null,
281
+ selectedMood: null,
282
+ recommendationModal:
283
+ wasLimited || !!Math.round(carbRecommendation) || !!this.getBGLevelAttentionMessage(),
284
+ onlyShowLimitationMessage: false,
285
+ showExitModal: props.showExitModal,
286
+ showTimeoutModal: false,
287
+ timeoutModalAction: null,
288
+ exitModalAction: null,
289
+ };
290
+
291
+ this.timer = setTimeout(this.showTimeoutModal, Milliseconds.Minute * 15);
292
+ } catch (error) {
293
+ this.hasError = true;
294
+ props.onError(error);
295
+ }
296
+ }
297
+
298
+ /**
299
+ * Called immediately after a component is mounted. Setting state here will trigger re-rendering.
300
+ *
301
+ * Steps:
302
+ * 1. If there is no error, create a listener to call the handleAppStateChange() method when the app state changes.
303
+ */
304
+ public componentDidMount(): void {
305
+ if (!this.hasError) {
306
+ this.appStateSubscription = AppState.addEventListener(`change`, this.handleAppStateChange);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Called immediately before a component is destroyed.
312
+ * Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.
313
+ *
314
+ * Clear the 15 minute timer that was set in the constructor during initialisation so it doesn't keep running and gets triggered after the recommendation screen was closed.
315
+ *
316
+ * Steps:
317
+ * 1. Call clearTimeout on the timer member variable.
318
+ * 2. Remove the listener for app state changes that was set by the componentDidMount() method.
319
+ */
320
+ public componentWillUnmount(): void {
321
+ if (this.timer !== undefined) {
322
+ clearTimeout(this.timer);
323
+ }
324
+ this.appStateSubscription?.remove();
325
+ }
326
+
327
+ /**
328
+ * Called immediately after updating occurs. This method is not called for the initial render.
329
+ * Use this as an opportunity to operate on the DOM when the component has been updated.
330
+ * Steps:
331
+ * 1. If the showExitModal prop is true and it was false before, call the onExit() method.
332
+ * @param showExitModal The previous showExitModal props of the component.
333
+ */
334
+ public componentDidUpdate({ showExitModal }: IRecommendationProps): void {
335
+ if (this.props.showExitModal && showExitModal !== this.props.showExitModal) {
336
+ this.onExit();
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Steps:
342
+ * 1. Evaluate a boolean called isOlderThan15Minutes to indicate whether the recommendationDate member variable represents a time more than 15 minutes ago.
343
+ * 2. If nextAppState is ‘active’ and isOlderThan15Minutes is true then call the showTimeoutModal() method.
344
+ * @param nextAppState The new state of the app.
345
+ */
346
+ public handleAppStateChange = (nextAppState: AppStateStatus): void => {
347
+ const time = this.recommendationDate.getTime();
348
+ const isOlderThan15Minutes = new Date().getTime() - time > Milliseconds.Minute * 15;
349
+ if (nextAppState === `active` && isOlderThan15Minutes) {
350
+ this.showTimeoutModal();
351
+ }
352
+ };
353
+
354
+ /**
355
+ * Steps:
356
+ * 1. Set the showTimeoutModal state variable to be true.
357
+ * */
358
+ public showTimeoutModal = (): void => {
359
+ this.setState({ showTimeoutModal: true });
360
+ };
361
+
362
+ /**
363
+ * Make a new insulin calculation and set the result to be displayed to the user.
364
+ *
365
+ * Steps:
366
+ * 1. Use calculatorParams as an argument for calling calculateRecommendation(). Unpack bolus, wasLimited, and activityReduction from the result.
367
+ * 2. Set the following state variables:
368
+ * - Set insulinRecommendation to the bolus rounded using the roundValue() function.
369
+ * - Set enteredInsulin to be undefined.
370
+ * - Set wasLimited to be the value returned from the insulin calculator.
371
+ * - Set activityReduction to be the value returned from the insulin calculator.
372
+ * - Set showLimitationMessage to be the wasLimited value returned from the insulin calculator.
373
+ * @param calculatorParams The input values for the bolus calculator itself.
374
+ */
375
+ public recalculateInsulin = (calculatorParams: BolusCalculator.Types.IRecommendationParams): void => {
376
+ const { bolus, wasLimited, activityReduction } = Calculator.calculateRecommendation(calculatorParams);
377
+ this.setState({
378
+ insulinRecommendation: Utils.roundValue(bolus, this.props.injectionMethod),
379
+ enteredInsulin: null,
380
+ wasLimited,
381
+ activityReduction,
382
+ onlyShowLimitationMessage: wasLimited,
383
+ });
384
+ };
385
+
386
+ /**
387
+ * Handle presses on the exit button in the header bar.
388
+ *
389
+ * Steps:
390
+ * 1. If the insulin recommendation is being displayed (the isRecommendationDisplayed state variable is true):
391
+ * - Set the showExitModal state variable to true.
392
+ * 2. Else:
393
+ * - Call the exitCallback prop callback function.
394
+ */
395
+ public onExit = (): void => {
396
+ if (this.state?.isRecommendationDisplayed) {
397
+ this.setState({ showExitModal: true });
398
+ } else {
399
+ this.props.exitCallback();
400
+ }
401
+ };
402
+
403
+ /**
404
+ * Hide the modal that shows attention messages.
405
+ *
406
+ * Steps:
407
+ * 1. Set the recommendationModal state variable to false.
408
+ */
409
+ public hideAttentionModal = (): void => {
410
+ this.setState({ recommendationModal: false, onlyShowLimitationMessage: false });
411
+ };
412
+
413
+ /**
414
+ * Handle presses on the transfer button in the exit modal.
415
+ */
416
+ public onPressTransferExitModal = (): void => {
417
+ this.setState({ showExitModal: false, exitModalAction: ExitModalActions.Transfer });
418
+ };
419
+
420
+ /**
421
+ * Handle presses on the close calculation button in the exit modal.
422
+ */
423
+ public onPressCloseExitModal = (): void => {
424
+ this.setState({ showExitModal: false, exitModalAction: ExitModalActions.CloseCalculation });
425
+ };
426
+
427
+ /**
428
+ * Handle presses on the hide button in the exit modal.
429
+ */
430
+ public onPressHideExitModal = (): void => {
431
+ this.setState({ showExitModal: false, exitModalAction: ExitModalActions.Hide });
432
+ };
433
+
434
+ /**
435
+ * Call the chosen modal action on the didHide modal callback .
436
+ */
437
+ public onExitModalDidHide = () => {
438
+ switch (this.state.exitModalAction) {
439
+ case ExitModalActions.Transfer:
440
+ this.handleTransfer();
441
+ break;
442
+ case ExitModalActions.CloseCalculation:
443
+ this.props.closeCalculationCallback();
444
+ break;
445
+ case ExitModalActions.Hide:
446
+ this.props.hideExitModal();
447
+ break;
448
+ }
449
+ };
450
+
451
+ /**
452
+ * Handle presses on the close calculation button in the timeout modal.
453
+ */
454
+ public onPressCloseCalculationTimeoutModal = (): void => {
455
+ this.setState({ showTimeoutModal: false, timeoutModalAction: TimeoutModalActions.CloseCalculation });
456
+ };
457
+
458
+ /**
459
+ * Handle presses on the restart calculation button in the timeout modal.
460
+ */
461
+ public onPressRestartCalculationTimeoutModal = (): void => {
462
+ this.setState({ showTimeoutModal: false, timeoutModalAction: TimeoutModalActions.RestartCalculation });
463
+ };
464
+
465
+ /**
466
+ * Handle presses on the transfer button in the timeout modal.
467
+ */
468
+ public onPressTransferTimeoutModal = (): void => {
469
+ this.setState({ showTimeoutModal: false, timeoutModalAction: TimeoutModalActions.Transfer });
470
+ };
471
+
472
+ /**
473
+ * Call the chosen modal action on the didHide modal callback .
474
+ */
475
+ public onTimeoutModalDidHide = () => {
476
+ switch (this.state.timeoutModalAction) {
477
+ case TimeoutModalActions.RestartCalculation:
478
+ this.props.restartCalculation();
479
+ break;
480
+ case TimeoutModalActions.Transfer:
481
+ this.props.onSaveToLogbook();
482
+ this.handleTransfer();
483
+ break;
484
+ case TimeoutModalActions.CloseCalculation:
485
+ this.props.onReturnToDashboard();
486
+ this.props.closeCalculationCallback();
487
+ break;
488
+ }
489
+ };
490
+
491
+ /**
492
+ * Used as a callback function for the Remeasure component to update the state when the remeasure time slider’s value changes.
493
+ *
494
+ * Steps:
495
+ * 1. Set the remeasureTime state variable to the value of the remeasureTime argument.
496
+ * @param remeasureTime The number of hours for which to wait before reminding the user to measure their BGL again. 0 indicates that the user should not be reminded.
497
+ */
498
+ public updateRemeasureTime = (remeasureTime: number): void => {
499
+ this.setState({ remeasureTime });
500
+ };
501
+
502
+ /**
503
+ * Handle what happens if the user taps “No” to the question about injecting insulin within the last 4 hours.
504
+ * The card that prompts the user to answer if they have injected insulin within the last 4 hours shall be hidden and
505
+ * the screen shall automatically be scrolled to the bottom so the user can see the now visible “Transfer to logbook” button.
506
+ *
507
+ * Steps:
508
+ * 1. Set the isRecommendationDisplayed state variable to be true.
509
+ * 2. Call the onRecommendationDisplayed prop callback function.
510
+ * 3. As a callback to the setState() method, define a new anonymous function that calls setTimeout() with a duration of 0 milliseconds.
511
+ * When the time expires, call the scrollToEnd() method of the scrollView member, with the animated argument set to true.
512
+ * This ensures that the scroll event happens after all other events that get queued to happen at the same time,
513
+ * so all relevant elements are visible on the screen and the scroll happens reliably.
514
+ */
515
+ public handleNoRecentInsulin = (): void => {
516
+ this.props.onRecentInsulinNo();
517
+ this.setState({ isRecommendationDisplayed: true }, (): void => {
518
+ this.props.onRecommendationDisplayed();
519
+ setTimeout((): void => {
520
+ this.scrollView?.scrollToEnd(true);
521
+ }, 0);
522
+ });
523
+ };
524
+
525
+ /**
526
+ * Handle what happens when the user changes the content of the additional carbohydrates input field.
527
+ *
528
+ * Steps:
529
+ * 1. Set the enteredCarbs state variable to the value of the enteredCarbs argument.
530
+ * 2. As a callback to the setState() method, define a new anonymous function that calls the recalculateInsulin() function using
531
+ * a copy of the calculatorParams prop where the carbohydrates property has been overwritten to be
532
+ * the sum of the carbohydrates property of the calculatorParams prop and the enteredCarbs argument.
533
+ * @param enteredCarbs The amount of carbohydrates in grams that has been entered in the additional carbohydrates input field.
534
+ */
535
+ public updateCarbRecommendation = (enteredCarbs: number): void => {
536
+ const providedCarbs = this.props.calculatorParams.carbohydrates;
537
+ this.setState({ enteredCarbs }, (): void => {
538
+ this.recalculateInsulin({ ...this.props.calculatorParams, carbohydrates: providedCarbs + enteredCarbs });
539
+ });
540
+ };
541
+
542
+ /**
543
+ * Handle what happens when the cross button by the additional carbohydrates button is tapped.
544
+ *
545
+ * Steps:
546
+ * 1. Set both the enteredCarbs and the carbRecommendation state variables to null.
547
+ * 2. As a callback to the setState() method, define a new anonymous function that calls the recalculateInsulin() function using a copy of the calculatorParams prop.
548
+ */
549
+ public removeCarbRecommendation = (): void => {
550
+ this.setState({ enteredCarbs: null, carbRecommendation: null }, (): void =>
551
+ this.recalculateInsulin({ ...this.props.calculatorParams }),
552
+ );
553
+ };
554
+
555
+ /**
556
+ * Handle what happens when the user is recommended to eat additional carbohydrates but taps the decline button.
557
+ *
558
+ * Steps:
559
+ * 1. Call the hideAttentionModal() method.
560
+ * 2. Call the removeCarbRecommendation() method.
561
+ * 3. Call the carbRecommendationAnswer() prop callback function with false as argument.
562
+ */
563
+ public declineCarbRecommendation = (): void => {
564
+ this.hideAttentionModal();
565
+ this.removeCarbRecommendation();
566
+ this.props.carbRecommendationAnswer(false);
567
+ };
568
+
569
+ /**
570
+ * Handle what happens when the user is recommended to eat additional carbohydrates and they tap the accept button.
571
+ *
572
+ * Steps:
573
+ * 1. Call the hideAttentionModal() method.
574
+ * 2. Call the carbRecommendationAnswer() prop callback function with true as argument.
575
+ */
576
+ public acceptCarbRecommendation = (): void => {
577
+ this.hideAttentionModal();
578
+ this.props.carbRecommendationAnswer(true);
579
+ };
580
+
581
+ /**
582
+ * Used as a callback function for the Emotion component to update the state when a mood icon is tapped.
583
+ *
584
+ * Steps:
585
+ * 1. Set the selectedMood state variable to the value of the selectedMood argument.
586
+ * @param selectedMood he mood that should be selected going forward or null if no mood should be selected.
587
+ */
588
+ public handleMoodSelected = (selectedMood: IState["selectedMood"]): void => {
589
+ this.setState({ selectedMood });
590
+ };
591
+
592
+ /**
593
+ * Handle what happens when the user changes the content of the insulin input field.
594
+ *
595
+ * Steps:
596
+ * 1. Set the enteredInsulin state variable to the value of the enteredInsulin argument.
597
+ * @param enteredInsulin The amount of insulin (in units) that has been entered in the insulin input field.
598
+ */
599
+ public updateInsulinRecommendation = (enteredInsulin: number): void => {
600
+ this.setState({ enteredInsulin });
601
+ };
602
+
603
+ /**
604
+ * Handle what happens when the “Transfer to Logbook” button is pressed.
605
+ * Namely, the entered data should be saved in a logbook entry and the recommendation screen should be closed.
606
+ *
607
+ * Steps:
608
+ * 1. Unpack the enteredCarbs, enteredInsulin, insulinRecommendation, remeasureTime, and showExitModal state variables
609
+ * 2. Create an IResult object called carbs consisting of suggestedCarbs and enteredCarbs.
610
+ * 3. Create an IResult object called Insulin consisting of insulinRecommendation and enteredInsulin.
611
+ * 4. Call the transferToLogbook prop callback function with the following arguments:
612
+ * - Set the carbs argument to the carbs IResult object.
613
+ * - Set the insulin argument to the insulin IResult object.
614
+ * - Set the reminder argument to the remeasureTime state variable.
615
+ * - Set the recommendationDate argument to the recommendationDate member variable.
616
+ */
617
+ public handleTransfer = (): void => {
618
+ const { enteredCarbs, enteredInsulin, insulinRecommendation, remeasureTime, selectedMood } = this.state;
619
+ const carbs: IResult = { suggested: this.suggestedCarbs, entered: enteredCarbs };
620
+ const insulin: IResult = { suggested: insulinRecommendation, entered: enteredInsulin };
621
+
622
+ this.props.transferToLogbook(carbs, insulin, remeasureTime, this.recommendationDate, selectedMood);
623
+ };
624
+
625
+ /**
626
+ * Get the attention message that should be displayed for the user to draw their attention to noteworthy circumstances regarding their current blood glucose level.
627
+ *
628
+ * Steps:
629
+ * 1. Unpack calculatorParams and latestLogbookFrom6Hours from the props.
630
+ * 2. Unpack currentBGL and activity from calculatorparams.
631
+ * 3. Get bgLevel, the categorisation of the blood glucose level, by calling the getBGLevel() function with the currentBGL and latestLogbookFrom6Hours as arguments.
632
+ * 4. Return the attention message that is returned when calling getAttentionMessage() using bgLevel and activity as arguments.
633
+ * @returns A string describing what the user needs to be aware of regarding their current blood glucose level.
634
+ * If there is nothing noteworthy, null will be returned instead.
635
+ */
636
+ public getBGLevelAttentionMessage = (): string | null => {
637
+ const { calculatorParams, latestLogbookFrom6Hours } = this.props;
638
+ const { currentBGL, activity } = calculatorParams;
639
+ const bgLevel = getBGLevel(currentBGL, latestLogbookFrom6Hours);
640
+ return getAttentionMessage(bgLevel, activity);
641
+ };
642
+
643
+ /**
644
+ * Get the initial value for the remeasurement reminder time slider depending on the user’s entered information.
645
+ *
646
+ * Steps:
647
+ * 1. Unpack calculatorParams, userReminder, and latestLogbookFrom6Hours from the props.
648
+ * 2. Unpack currentBGL, activity, and carbohydrates from calculatorParams.
649
+ * 3. Get bgLevel, the categorisation of the blood glucose level, by calling the getBGLevel() function with the currentBGL and latestLogbookFrom6Hours as arguments.
650
+ * 4. Return the attention message that is returned when calling getReminder() using bgLevel, carbohydrates, userReminder, and activity as arguments.
651
+ * @returns The time interval in hours that should be used as the initial value for the remeasurement reminder time slider.
652
+ */
653
+ public getBGLevelRemeasurementReminder = (): number => {
654
+ const { calculatorParams, userReminder, latestLogbookFrom6Hours } = this.props;
655
+ const { currentBGL, activity, carbohydrates } = calculatorParams;
656
+ const bgLevel = getBGLevel(currentBGL, latestLogbookFrom6Hours);
657
+
658
+ return getReminder(bgLevel, carbohydrates, userReminder, activity);
659
+ };
660
+
661
+ /**
662
+ * Get the attention message that should be displayed to the user to let them know that the insulin recommendation that
663
+ * is being displayed to them was limited by the maximum insulin threshold.
664
+ *
665
+ * Steps:
666
+ * 1. Unpack the wasLimited and activityReduction state variables.
667
+ * 2. Return the result from calling getLimitationMessage() with wasLimited and activityReduction as arguments.
668
+ * @returns A message to inform the user how the insulin recommendation was limited. If there is no limitation attention message, null will be returned instead.
669
+ */
670
+ public getLimitationAttentionMessage = (): string | null => {
671
+ const { wasLimited, activityReduction } = this.state;
672
+
673
+ return getLimitationMessage(wasLimited, activityReduction);
674
+ };
675
+
676
+ /** Render a JSX element for displaying the insulin recommendation screen. */
677
+ public render(): JSX.Element {
678
+ if (this.hasError) {
679
+ return <View style={styles.container} />;
680
+ }
681
+
682
+ const {
683
+ activeInsulin,
684
+ recommendationModal,
685
+ carbRecommendation: carbRecommendationProp,
686
+ enteredCarbs,
687
+ enteredInsulin,
688
+ insulinRecommendation,
689
+ activityReduction,
690
+ isRecommendationDisplayed,
691
+ } = this.state;
692
+
693
+ const {
694
+ BloodGlucose: BGValueTestID,
695
+ BloodKetone: BKValueTestID,
696
+ ActiveInsulin: ActiveInsulinValueTestID,
697
+ } = InfoBarTestIds.Value;
698
+ const {
699
+ ActiveInsulin: ActiveInsulinUnitTestID,
700
+ BloodGlucose: BGUnitTestID,
701
+ BloodKetone: BKUnitTestID,
702
+ } = InfoBarTestIds.Unit;
703
+
704
+ const carbRecommendation = carbRecommendationProp !== null ? Math.round(carbRecommendationProp) : null;
705
+ const recommendedCarbs = enteredCarbs ?? carbRecommendation;
706
+ const foodBorderColor = recommendedCarbs !== null && recommendedCarbs > 0 ? colors.teal : colors.dustyDarkBlue;
707
+
708
+ const { calculatorParams, bloodGlucoseUnit, currentBKL, bloodKetoneUnit } = this.props;
709
+ const { currentBGL, carbohydrates: providedCarbs } = calculatorParams;
710
+ const displayedBGL = currentBGL ? Utils.displayedBGLValue(currentBGL, bloodGlucoseUnit) : null;
711
+ const displayedBKL =
712
+ currentBKL !== null && bloodKetoneUnit ? Utils.displayedBKLValue(currentBKL, bloodKetoneUnit) : null;
713
+ return (
714
+ <>
715
+ <KeyboardAwareScrollView
716
+ testID={RecommendationScreenTestIds.RecommendationScrollView}
717
+ enableResetScrollToCoords={false}
718
+ style={styles.container}
719
+ ref={(view): void => {
720
+ if (view !== null) {
721
+ this.scrollView = view;
722
+ }
723
+ }}
724
+ >
725
+ <Text style={styles.header}>{t(`Insulin recommendation`)}</Text>
726
+ <InfoBars
727
+ label={t(`Active Insulin`)}
728
+ value={activeInsulin ? `${activeInsulin.toFixed(1)}` : null}
729
+ unit={t(`units`)}
730
+ showNullAsDash={false}
731
+ testID={{ unitID: ActiveInsulinUnitTestID, valueID: ActiveInsulinValueTestID }}
732
+ />
733
+ <InfoBars
734
+ label={t(`Blood Glucose Level`)}
735
+ value={displayedBGL}
736
+ unit={this.props.bloodGlucoseUnit}
737
+ showNullAsDash={true}
738
+ testID={{ unitID: BGUnitTestID, valueID: BGValueTestID }}
739
+ />
740
+ <InfoBars
741
+ label={t(`Blood Ketone Level`)}
742
+ value={displayedBKL}
743
+ unit={this.props.bloodKetoneUnit}
744
+ showNullAsDash={true}
745
+ testID={{ unitID: BKUnitTestID, valueID: BKValueTestID }}
746
+ />
747
+ <View style={[styles.carbsBorder, { borderColor: foodBorderColor }]}>
748
+ <RecommendedCarbs
749
+ enteredCarbs={`${providedCarbs}`}
750
+ changedRecommendedCarbs={this.updateCarbRecommendation}
751
+ recommendedCarbs={`${recommendedCarbs}`}
752
+ removeRecommendedCarbs={this.removeCarbRecommendation}
753
+ />
754
+ </View>
755
+ {this.props.calculatorParams.activity && this.props.activityDisplayProps && (
756
+ <Activity
757
+ activity={this.props.calculatorParams.activity}
758
+ activityType={this.props.activityDisplayProps.activityType}
759
+ activityTitle={this.props.activityDisplayProps.activityTitle}
760
+ activityReduction={activityReduction}
761
+ />
762
+ )}
763
+ <Remeasure onSliderChange={this.updateRemeasureTime} remeasureTime={this.state.remeasureTime} />
764
+ {!isRecommendationDisplayed ? (
765
+ <RecentInsulin
766
+ onRecentInsulinYes={this.props.onRecentInsulinYes}
767
+ onRecentInsulinNo={this.handleNoRecentInsulin}
768
+ />
769
+ ) : (
770
+ <RecommendedInsulin
771
+ injectionMethod={this.props.injectionMethod}
772
+ insulinRecommendation={insulinRecommendation}
773
+ enteredInsulin={enteredInsulin}
774
+ activityReduction={activityReduction}
775
+ updateRecommendedInsulin={this.updateInsulinRecommendation}
776
+ />
777
+ )}
778
+ <TransferToLogbook visible={isRecommendationDisplayed} transfer={this.handleTransfer} />
779
+ <Emotion moodSelected={this.handleMoodSelected} currentMood={this.state.selectedMood} />
780
+ <RecommendationModal
781
+ isVisible={recommendationModal || this.state.onlyShowLimitationMessage}
782
+ onlyShowLimitationMessage={this.state.onlyShowLimitationMessage}
783
+ suggestedCarbohydrates={carbRecommendationProp}
784
+ attentionMessage={this.getBGLevelAttentionMessage()}
785
+ limitationMessage={this.getLimitationAttentionMessage()}
786
+ onClickOkButton={this.hideAttentionModal}
787
+ onAcceptCarbohydrates={this.acceptCarbRecommendation}
788
+ onDeclineCarbohydrates={this.declineCarbRecommendation}
789
+ />
790
+ </KeyboardAwareScrollView>
791
+
792
+ <ExitModal
793
+ isVisible={this.state.showExitModal}
794
+ title={t(`Save data before closing?`)}
795
+ message={t(`Your saved data will be used for future calculations.`)}
796
+ textFirstOption={t(`Save to logbook`)}
797
+ textSecondOption={t(`Close calculation`)}
798
+ firstOption={this.onPressTransferExitModal}
799
+ secondOption={this.onPressCloseExitModal}
800
+ onClose={this.onPressHideExitModal}
801
+ onModalHide={this.onExitModalDidHide}
802
+ />
803
+
804
+ {isRecommendationDisplayed ? (
805
+ <TimeoutModal
806
+ isVisible={this.state.showTimeoutModal}
807
+ title={Messages.TimeoutPrompTitle()}
808
+ message={Messages.TimeoutRecommendationVisible(this.recommendationDate)}
809
+ textFirstOption={t(`Yes, save to logbook`)}
810
+ textSecondOption={t(`No, return to dashboard`)}
811
+ firstOption={this.onPressTransferTimeoutModal}
812
+ secondOption={this.onPressCloseCalculationTimeoutModal}
813
+ onModalHide={this.onTimeoutModalDidHide}
814
+ />
815
+ ) : (
816
+ <TimeoutModal
817
+ isVisible={this.state.showTimeoutModal}
818
+ title={Messages.TimeoutPrompTitle()}
819
+ message={Messages.TimeoutRecommendationNotVisible()}
820
+ textFirstOption={t(`Start new calculation`)}
821
+ textSecondOption={t(`Return to dashboard`)}
822
+ firstOption={this.onPressRestartCalculationTimeoutModal}
823
+ secondOption={this.onPressCloseCalculationTimeoutModal}
824
+ onModalHide={this.onTimeoutModalDidHide}
825
+ />
826
+ )}
827
+ </>
828
+ );
829
+ }
830
+ }
831
+
832
+ const styles = StyleSheet.create({
833
+ container: {
834
+ flex: 1,
835
+ paddingHorizontal: 18,
836
+ backgroundColor: colors.darkBlue,
837
+ },
838
+ limitationModalContainer: {
839
+ ...StyleSheet.absoluteFillObject,
840
+ justifyContent: `center`,
841
+ backgroundColor: colors.transparentBlack,
842
+ },
843
+ carbsBorder: {
844
+ borderWidth: 1,
845
+ borderRadius: 5,
846
+ padding: 16,
847
+ },
848
+ header: {
849
+ ...FONTS.Poppins.medium_Base,
850
+ color: colors.dustyBlue,
851
+ marginBottom: 22,
852
+ textAlign: `center`,
853
+ },
854
+ });