Skip to content

Commit

Permalink
Fix shortcut bolus safety guards
Browse files Browse the repository at this point in the history
- Block (with an alert) boluses that exceed the user-configured max (whether this is max pump max bolus or recommended amount)
- Addresses this request #177 (comment)
  • Loading branch information
aug0211 committed Jul 7, 2024
1 parent f5915f5 commit 6ce9fbe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4436,6 +4436,12 @@
}
}
}
},
"The bolus cannot be larger than the pump setting max bolus" : {

},
"The bolus cannot be larger than the suggested insulin" : {

},
"the bolus is not allowed with shortcuts" : {
"localizations" : {
Expand Down
33 changes: 24 additions & 9 deletions FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,37 @@ import Foundation
func bolus(_ bolusAmount: Double) throws -> LocalizedStringResource {
var bolusQuantity: Decimal = 0
switch settingsManager.settings.bolusShortcut {

//Block boluses if they are disabled
case .notAllowed:
return LocalizedStringResource(
"the bolus is not allowed with shortcuts",
"Bolusing is not allowed with shortcuts.",
table: "ShortcutsDetail"
)

//Block any bolus attempted if it is larger than the max bolus in settings
case .limitBolusMax:
bolusQuantity = apsManager
.roundBolus(amount: min(settingsManager.pumpSettings.maxBolus, Decimal(bolusAmount)))
if Decimal(bolusAmount) > settingsManager.pumpSettings.maxBolus {
return LocalizedStringResource(
"The bolus cannot be larger than the pump setting max bolus.",
table: "ShortcutsDetail"
)
} else {
bolusQuantity = apsManager.roundBolus(amount: Decimal(bolusAmount))
}

//Block any bolus attempted if it is larger than the max bolus in settings
case .limitInsulinSuggestion:
let insulinSuggestion = suggestion?.insulinForManualBolus ?? 0

bolusQuantity = apsManager
.roundBolus(amount: min(
insulinSuggestion * (settingsManager.settings.insulinReqPercentage / 100),
Decimal(bolusAmount)
))
if Decimal(bolusAmount) > insulinSuggestion {
return LocalizedStringResource(
"The bolus cannot be larger than the suggested insulin.",
table: "ShortcutsDetail"
)
} else {
bolusQuantity = apsManager
.roundBolus(amount: Decimal(bolusAmount))
}
}

apsManager.enactBolus(amount: Double(bolusQuantity), isSMB: false)
Expand Down

0 comments on commit 6ce9fbe

Please sign in to comment.