瀏覽代碼

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

Marvin Polscheit 1 年之前
父節點
當前提交
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
             // 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 ?
             let simulatedCOB: Int16? = isBackdated ?
                 Int16(truncating: NSNumber(value: (simulatedDetermination?.cob as NSDecimalNumber?)?.doubleValue ?? 0)) : nil
                 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(
             let result = await bolusCalculationManager.handleBolusCalculation(
                 carbs: carbs,
                 carbs: carbs,