Procházet zdrojové kódy

Bolus guardrail cleanup

- Removed limitInsulinSuggestion case (limited to required insulin) --> discussed with a group of 10 devs and leaders in Trio community and confirmed we do not want this
- Cleaned up settings for bolus shortcuts per above
- Trimmed some code that is now dead after removing limitInsulinSuggestion case
-Bonus: clean up punctuation (? and .) in some bolus prompts/confirmations
Auggie Fisher před 1 rokem
rodič
revize
72dbd3fe3f

+ 0 - 3
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -4,7 +4,6 @@ enum BolusShortcutLimit: String, JSON, CaseIterable, Identifiable {
     var id: String { rawValue }
     case notAllowed
     case limitBolusMax
-    case limitInsulinSuggestion
 
     var displayName: String {
         switch self {
@@ -12,8 +11,6 @@ enum BolusShortcutLimit: String, JSON, CaseIterable, Identifiable {
             return String(localized: "Not allowed", table: "ShortcutsDetail")
         case .limitBolusMax:
             return String(localized: "Max bolus", table: "ShortcutsDetail")
-        case .limitInsulinSuggestion:
-            return String(localized: "Insulin recommended", table: "ShortcutsDetail")
         }
     }
 }

+ 0 - 11
FreeAPS/Sources/Modules/ShortcutsConfig/View/ShortcutsConfigView.swift

@@ -25,17 +25,6 @@ extension ShortcutsConfig {
                         String(localized: "Allow bolusing with shortcuts", table: "ShortcutsDetail"),
                         isOn: $state.allowBolusByShortcuts
                     )
-
-                    Picker(
-                        selection: $state.maxBolusByShortcuts,
-                        label: Text("Limit bolus from shortcuts to", tableName: "ShortcutsDetail")
-                    ) {
-                        ForEach(BolusShortcutLimit.allCases) { v in
-                            v != .notAllowed ? Text(v.displayName).tag(v) : nil
-                            // Text(v.displayName).tag(v)
-                        }
-                    }
-                    .disabled(!state.allowBolusByShortcuts)
                 }
             }
             .onAppear(perform: configureView)

+ 7 - 4
FreeAPS/Sources/Shortcuts/Bolus/BolusIntent.swift

@@ -20,22 +20,25 @@ import Swinject
         title: LocalizedStringResource("Amount", table: "ShortcutsDetail"),
         description: LocalizedStringResource("Bolus amount in U", table: "ShortcutsDetail"),
         controlStyle: .field,
+        /// The 200 upperBound does nothing here, the true max is set based on pump max
+        /// An upperBound is specificed so that we can usethe lowerBound of 0, which ensures no negatives are allowed
+        /// A preferred approach would be to just block negatives and not specify an upperBound here, since it is implemented elsewhere
         inclusiveRange: (lowerBound: 0, upperBound: 200),
         requestValueDialog: IntentDialog(LocalizedStringResource(
-            "What is the value of the bolus amount in insulin units ?",
+            "What is the value of the bolus amount in insulin units?",
             table: "ShortcutsDetail"
         ))
     ) var bolusQuantity: Double
 
     @Parameter(
         title: LocalizedStringResource("Confirm Before applying", table: "ShortcutsDetail"),
-        description: LocalizedStringResource("If toggled, you will need to confirm before applying", table: "ShortcutsDetail"),
+        description: LocalizedStringResource("If toggled, you will need to confirm before applying.", table: "ShortcutsDetail"),
         default: true
     ) var confirmBeforeApplying: Bool
 
     static var parameterSummary: some ParameterSummary {
         When(\.$confirmBeforeApplying, .equalTo, true, {
-            Summary("Applying \(\.$bolusQuantity) U ", table: "ShortcutsDetail") {
+            Summary("Applying \(\.$bolusQuantity) U", table: "ShortcutsDetail") {
                 \.$confirmBeforeApplying
             }
         }, otherwise: {
@@ -54,7 +57,7 @@ import Swinject
                 try await requestConfirmation(
                     result: .result(
                         dialog: IntentDialog(LocalizedStringResource(
-                            "Are you sure you want to bolus \(bolusFormatted) U of insulin ?",
+                            "Are you sure you want to bolus \(bolusFormatted) U of insulin?",
                             table: "ShortcutsDetail"
                         ))
                     )

+ 5 - 61
FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift

@@ -3,12 +3,6 @@ import CoreData
 import Foundation
 
 @available(iOS 16.0,*) final class BolusIntentRequest: BaseIntentsRequest {
-    private var suggestion: Determination? {
-        // TODO: CRITICAL
-        /// This MUST update to use the latest determination's insulinRequired from Core Data
-        fileStorage.retrieve(OpenAPS.Enact.suggested, as: Determination.self)
-    }
-
     func bolus(_ bolusAmount: Double) async throws -> LocalizedStringResource {
         var bolusQuantity: Decimal = 0
         switch settingsManager.settings.bolusShortcut {
@@ -29,61 +23,11 @@ import Foundation
             } else {
                 bolusQuantity = apsManager.roundBolus(amount: Decimal(bolusAmount))
             }
-
-        // Block any bolus attempted if it is larger than the insulin recommended
-        case .limitInsulinSuggestion:
-            /*
-             case .limitInsulinSuggestion:
-                 let lastDetermination = await CoreDataStack.shared.fetchEntitiesAsync(
-                     ofType: OrefDetermination.self,
-                     onContext: coredataContext,
-                     predicate: NSPredicate.predicateFor30MinAgoForDetermination,
-                     key: "deliveryAt", ascending: false,
-                     fetchLimit: 1
-                 )
-                 guard let latest = lastDetermination.first else {
-                     return LocalizedStringResource(
-                         "Error retrieving suggested insulin amount guardrail.",
-                         table: "ShortcutsDetail"
-                     )
-                 }
-                 let insulinSuggestion = latest.insulinForManualBolus ?? 0
-             */
-            let insulinSuggestion = suggestion?.insulinForManualBolus ?? 0
-            if Decimal(bolusAmount) > insulinSuggestion {
-                return LocalizedStringResource(
-                    "The bolus cannot be larger than the suggested insulin (\(insulinSuggestion.description)).",
-                    table: "ShortcutsDetail"
-                )
-            }
-            // Also make sure that no matter what, the bolus doesn't exceed the max setting in Trio
-            else if Decimal(bolusAmount) > settingsManager.pumpSettings.maxBolus {
-                return LocalizedStringResource(
-                    "The bolus cannot be larger than the pump setting max bolus (\(settingsManager.pumpSettings.maxBolus.description)).",
-                    table: "ShortcutsDetail"
-                )
-            } else {
-                bolusQuantity = apsManager
-                    .roundBolus(amount: Decimal(bolusAmount))
-            }
-        }
-
-        await apsManager.enactBolus(amount: Double(bolusQuantity), isSMB: false)
-        return LocalizedStringResource(
-            "A bolus command of \(bolusQuantity.formatted()) U of insulin was sent",
-            table: "ShortcutsDetail"
-        )
-    }
-
-    private var glucoseFormatter: NumberFormatter {
-        let formatter = NumberFormatter()
-        formatter.numberStyle = .decimal
-        formatter.maximumFractionDigits = 0
-        if settingsManager.settings.units == .mmolL {
-            formatter.minimumFractionDigits = 1
-            formatter.maximumFractionDigits = 1
+            await apsManager.enactBolus(amount: Double(bolusQuantity), isSMB: false)
+            return LocalizedStringResource(
+                "A bolus command of \(bolusQuantity.formatted()) U of insulin was sent.",
+                table: "ShortcutsDetail"
+            )
         }
-        formatter.roundingMode = .halfUp
-        return formatter
     }
 }