Преглед изворни кода

Add "non-pump insulin" as treatment type.

Co-authored-by: dnzxy <d.c.cengiz@googlemail.com>
Brian Wieder пре 2 година
родитељ
комит
c971356bff

+ 11 - 2
FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift

@@ -44,7 +44,8 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         durationMin: nil,
                         rate: nil,
                         temp: nil,
-                        carbInput: nil
+                        carbInput: nil,
+                        isNonPumpInsulin: dose.manuallyEntered
                     )]
                 case .tempBasal:
                     guard let dose = event.dose else { return [] }
@@ -209,6 +210,13 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
         }
     }
 
+    func determineBolusEventType(for event: PumpHistoryEvent) -> EventType {
+        if event.isNonPumpInsulin ?? false {
+            return .nonPumpInsulin
+        }
+        return event.type
+    }
+
     func nightscoutTretmentsNotUploaded() -> [NigtscoutTreatment] {
         let events = recent()
         guard !events.isEmpty else { return [] }
@@ -249,13 +257,14 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
         let bolusesAndCarbs = events.compactMap { event -> NigtscoutTreatment? in
             switch event.type {
             case .bolus:
+                let eventType = determineBolusEventType(for: event)
                 return NigtscoutTreatment(
                     duration: event.duration,
                     rawDuration: nil,
                     rawRate: nil,
                     absolute: nil,
                     rate: nil,
-                    eventType: .bolus,
+                    eventType: eventType,
                     createdAt: event.timestamp,
                     enteredBy: NigtscoutTreatment.local,
                     bolus: event,

+ 2 - 2
FreeAPS/Sources/Localizations/Main/de.lproj/Localizable.strings

@@ -1222,8 +1222,8 @@ Enact a temp Basal or a temp target */
 /* An Automatic delivered bolus (SMB) */
 "SMB" = "SMB";
 
-/* A manually entered dose of external insulin */
-"External Insulin" = "Externes Insulin";
+/* A manually entered dose of non-pump insulin */
+"Non-pump Insulin" = "Externes Insulin";
 
 /* Status highlight when manual temp basal is running. */
 "Manual Basal" = "Manuelle Temporäre Basalrate";

+ 5 - 2
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -614,6 +614,9 @@ Enact a temp Basal or a temp target */
 /* Automatic delivered treatments */
 "Automatic" = "Automatic";
 
+/* Non-pump insulin treatments */
+"Non-Pump" = "Non-Pump";
+
 /* External insulin treatments */
 "External" = "External";
 
@@ -1220,8 +1223,8 @@ Enact a temp Basal or a temp target */
 /* An Automatic delivered bolus (SMB) */
 "SMB" = "SMB";
 
-/* A manually entered dose of external insulin */
-"External Insulin" = "External Insulin";
+/* A manually entered dose of non-pump insulin */
+"Non-pump Insulin" = "Non-pump Insulin";
 
 /* Status highlight when manual temp basal is running. */
 "Manual Basal" = "Manual Basal";

+ 7 - 2
FreeAPS/Sources/Models/PumpHistoryEvent.swift

@@ -11,6 +11,7 @@ struct PumpHistoryEvent: JSON, Equatable {
     let temp: TempType?
     let carbInput: Int?
     let note: String?
+    let isNonPumpInsulin: Bool?
 
     init(
         id: String,
@@ -22,7 +23,8 @@ struct PumpHistoryEvent: JSON, Equatable {
         rate: Decimal? = nil,
         temp: TempType? = nil,
         carbInput: Int? = nil,
-        note: String? = nil
+        note: String? = nil,
+        isNonPumpInsulin: Bool? = nil
     ) {
         self.id = id
         self.type = type
@@ -34,12 +36,14 @@ struct PumpHistoryEvent: JSON, Equatable {
         self.temp = temp
         self.carbInput = carbInput
         self.note = note
+        self.isNonPumpInsulin = isNonPumpInsulin
     }
 }
 
 enum EventType: String, JSON {
     case bolus = "Bolus"
-    case mealBulus = "Meal Bolus"
+    case nonPumpInsulin = "Non-pump Insulin"
+    case mealBolus = "Meal Bolus"
     case correctionBolus = "Correction Bolus"
     case snackBolus = "Snack Bolus"
     case bolusWizard = "BolusWizard"
@@ -80,5 +84,6 @@ extension PumpHistoryEvent {
         case temp
         case carbInput = "carb_input"
         case note
+        case isNonPumpInsulin
     }
 }

+ 2 - 1
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -83,7 +83,8 @@ extension Bolus {
                         durationMin: nil,
                         rate: nil,
                         temp: nil,
-                        carbInput: nil
+                        carbInput: nil,
+                        isNonPumpInsulin: true
                     )
                 ]
             )

+ 18 - 8
FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift

@@ -66,8 +66,9 @@ enum DataTable {
         let isFPU: Bool?
         let fpuID: String?
         let note: String?
+        let isNonPump: Bool?
 
-        private var numberFormater: NumberFormatter {
+        private var numberFormatter: NumberFormatter {
             let formatter = NumberFormatter()
             formatter.numberStyle = .decimal
             formatter.maximumFractionDigits = 2
@@ -92,7 +93,8 @@ enum DataTable {
             idPumpEvent: String? = nil,
             isFPU: Bool? = false,
             fpuID: String? = nil,
-            note: String? = nil
+            note: String? = nil,
+            isNonPump: Bool? = nil
         ) {
             self.units = units
             self.type = type
@@ -105,6 +107,7 @@ enum DataTable {
             self.isFPU = isFPU
             self.fpuID = fpuID
             self.note = note
+            self.isNonPump = isNonPump
         }
 
         static func == (lhs: Treatment, rhs: Treatment) -> Bool {
@@ -126,14 +129,21 @@ enum DataTable {
 
             switch type {
             case .carbs:
-                return numberFormater.string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carbs")
+                return numberFormatter.string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carbs")
             case .fpus:
-                return numberFormater
+                return numberFormatter
                     .string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carb equilvalents")
             case .bolus:
-                return numberFormater.string(from: amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
+                var bolusText = ""
+
+                if isNonPump ?? false {
+                    bolusText += " " + NSLocalizedString("Non-Pump", comment: "Non-pump Insulin")
+                }
+
+                return numberFormatter
+                    .string(from: amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit") + bolusText
             case .tempBasal:
-                return numberFormater
+                return numberFormatter
                     .string(from: amount as NSNumber)! + NSLocalizedString(" U/hr", comment: "Unit insulin per hour")
             case .tempTarget:
                 var converted = amount
@@ -142,7 +152,7 @@ enum DataTable {
                 }
 
                 guard var secondAmount = secondAmount else {
-                    return numberFormater.string(from: converted as NSNumber)! + " \(units.rawValue)"
+                    return numberFormatter.string(from: converted as NSNumber)! + " \(units.rawValue)"
                 }
                 if units == .mmolL {
                     secondAmount = secondAmount.asMmolL
@@ -177,7 +187,7 @@ enum DataTable {
             guard let duration = duration, duration > 0 else {
                 return nil
             }
-            return numberFormater.string(from: duration as NSNumber)! + " min"
+            return numberFormatter.string(from: duration as NSNumber)! + " min"
         }
     }
 

+ 8 - 1
FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift

@@ -66,7 +66,14 @@ extension DataTable {
                 let boluses = self.provider.pumpHistory()
                     .filter { $0.type == .bolus }
                     .map {
-                        Treatment(units: units, type: .bolus, date: $0.timestamp, amount: $0.amount, idPumpEvent: $0.id)
+                        Treatment(
+                            units: units,
+                            type: .bolus,
+                            date: $0.timestamp,
+                            amount: $0.amount,
+                            idPumpEvent: $0.id,
+                            isNonPump: $0.isNonPumpInsulin
+                        )
                     }
 
                 let tempBasals = self.provider.pumpHistory()