Просмотр исходного кода

Set current entered carbs to 0 when backdating carbs to avoid doubled recommendation

Marvin Polscheit 1 год назад
Родитель
Сommit
a7c98ce47a
1 измененных файлов с 4 добавлено и 0 удалено
  1. 4 0
      Trio/Sources/Modules/Treatments/TreatmentsStateModel.swift

+ 4 - 0
Trio/Sources/Modules/Treatments/TreatmentsStateModel.swift

@@ -388,6 +388,10 @@ extension Treatments {
             // Use the cob value of the simulation if carbs are backdated, otherwise set `simulatedCOB` to nil so that the cob value of the most recent determination gets used in the Bolus Calc Manager
             let simulatedCOB: Int16? = isBackdated ?
                 Int16(truncating: NSNumber(value: (simulatedDetermination?.cob as NSDecimalNumber?)?.doubleValue ?? 0)) : nil
+            // If the user backdates carbs the current carb value must be set to 0
+            // otherwise the calc would recommend insulin for carbs + backdated carbs
+            // e.g. you enter 50g carbs and backdate them 1h -> calc would recommend insulin for 50g + ~45g (where ~45g is the partially absorbed cob)
+            let carbs: Decimal = isBackdated ? 0 : self.carbs
 
             let result = await bolusCalculationManager.handleBolusCalculation(
                 carbs: carbs,