فهرست منبع

Add "non-pump insulin" as treatment type (#267)

Co-authored-by: Jonas Björkert <bjorkert@me.com>
Deniz Cengiz 2 سال پیش
والد
کامیت
6011575963

+ 1 - 1
FreeAPS.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -30,7 +30,7 @@
       },
       {
         "package": "SwiftCharts",
-        "repositoryURL": "https://github.com/ivanschuetz/SwiftCharts",
+        "repositoryURL": "https://github.com/ivanschuetz/SwiftCharts.git",
         "state": {
           "branch": "master",
           "revision": "c354c1945bb35a1f01b665b22474f6db28cba4a2",

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

@@ -45,7 +45,8 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         rate: nil,
                         temp: nil,
                         carbInput: nil,
-                        isSMB: dose.automatic
+                        isSMB: dose.automatic,
+                        isNonPumpInsulin: dose.manuallyEntered
                     )]
                 case .tempBasal:
                     guard let dose = event.dose else { return [] }
@@ -210,6 +211,16 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
         }
     }
 
+    func determineBolusEventType(for event: PumpHistoryEvent) -> EventType {
+        if event.isSMB ?? false {
+            return .smb
+        }
+        if event.isNonPumpInsulin ?? false {
+            return .nonPumpInsulin
+        }
+        return event.type
+    }
+
     func nightscoutTretmentsNotUploaded() -> [NigtscoutTreatment] {
         let events = recent()
         guard !events.isEmpty else { return [] }
@@ -250,13 +261,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: (event.isSMB ?? false) ? .smb : .bolus,
+                    eventType: eventType,
                     createdAt: event.timestamp,
                     enteredBy: NigtscoutTreatment.local,
                     bolus: event,

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

@@ -1171,6 +1171,9 @@ Enact a temp Basal or a temp target */
 /* An Automatic delivered bolus (SMB) */
 "SMB" = "SMB";
 
+/* 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";
 

+ 6 - 0
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -569,6 +569,9 @@ Enact a temp Basal or a temp target */
 /* Automatic delivered treatments */
 "Automatic" = "Automatic";
 
+/* Non-pump insulin treatments */
+"Non-Pump" = "Non-Pump";
+
 /* */
 "Other" = "Other";
 
@@ -1172,6 +1175,9 @@ Enact a temp Basal or a temp target */
 /* An Automatic delivered bolus (SMB) */
 "SMB" = "SMB";
 
+/* 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

@@ -12,6 +12,7 @@ struct PumpHistoryEvent: JSON, Equatable {
     let carbInput: Int?
     let note: String?
     let isSMB: Bool?
+    let isNonPumpInsulin: Bool?
 
     init(
         id: String,
@@ -24,7 +25,8 @@ struct PumpHistoryEvent: JSON, Equatable {
         temp: TempType? = nil,
         carbInput: Int? = nil,
         note: String? = nil,
-        isSMB: Bool? = nil
+        isSMB: Bool? = nil,
+        isNonPumpInsulin: Bool? = nil
     ) {
         self.id = id
         self.type = type
@@ -37,13 +39,15 @@ struct PumpHistoryEvent: JSON, Equatable {
         self.carbInput = carbInput
         self.note = note
         self.isSMB = isSMB
+        self.isNonPumpInsulin = isNonPumpInsulin
     }
 }
 
 enum EventType: String, JSON {
     case bolus = "Bolus"
     case smb = "SMB"
-    case mealBulus = "Meal Bolus"
+    case nonPumpInsulin = "Non-pump Insulin"
+    case mealBolus = "Meal Bolus"
     case correctionBolus = "Correction Bolus"
     case snackBolus = "Snack Bolus"
     case bolusWizard = "BolusWizard"
@@ -86,5 +90,6 @@ extension PumpHistoryEvent {
         case carbInput = "carb_input"
         case note
         case isSMB
+        case isNonPumpInsulin
     }
 }

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

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

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

@@ -67,6 +67,7 @@ enum DataTable {
         let fpuID: String?
         let note: String?
         let isSMB: Bool?
+        let isNonPump: Bool?
 
         private var numberFormatter: NumberFormatter {
             let formatter = NumberFormatter()
@@ -94,7 +95,8 @@ enum DataTable {
             isFPU: Bool? = nil,
             fpuID: String? = nil,
             note: String? = nil,
-            isSMB: Bool? = nil
+            isSMB: Bool? = nil,
+            isNonPump: Bool? = nil
         ) {
             self.units = units
             self.type = type
@@ -108,6 +110,7 @@ enum DataTable {
             self.fpuID = fpuID
             self.note = note
             self.isSMB = isSMB
+            self.isNonPump = isNonPump
         }
 
         static func == (lhs: Treatment, rhs: Treatment) -> Bool {
@@ -135,12 +138,18 @@ enum DataTable {
                 return numberFormatter
                     .string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carb equilvalents")
             case .bolus:
+                var bolusText = " "
+
+                if isSMB ?? false {
+                    bolusText += NSLocalizedString("Automatic", comment: "Automatic delivered treatments")
+                } else if isNonPump ?? false {
+                    bolusText += NSLocalizedString("Non-Pump", comment: "Non-pump Insulin")
+                } else {
+                    bolusText += NSLocalizedString("Manual", comment: "Manual Bolus")
+                }
+
                 return numberFormatter
-                    .string(from: amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit") +
-                    (
-                        (isSMB ?? false) ? " " + NSLocalizedString("Automatic", comment: "Automatic delivered treatments") : " " +
-                            NSLocalizedString("Manual", comment: "Manual Bolus")
-                    )
+                    .string(from: amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit") + bolusText
             case .tempBasal:
                 return numberFormatter
                     .string(from: amount as NSNumber)! + NSLocalizedString(" U/hr", comment: "Unit insulin per hour")
@@ -172,9 +181,9 @@ enum DataTable {
             case .fpus:
                 return .orange.opacity(0.5)
             case .bolus:
-                return .insulin
+                return Color.insulin
             case .tempBasal:
-                return Color.insulin.opacity(0.5)
+                return Color.insulin.opacity(0.4)
             case .resume,
                  .suspend,
                  .tempTarget:

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

@@ -73,7 +73,8 @@ extension DataTable {
                             date: $0.timestamp,
                             amount: $0.amount,
                             idPumpEvent: $0.id,
-                            isSMB: $0.isSMB
+                            isSMB: $0.isSMB,
+                            isNonPump: $0.isNonPumpInsulin
                         )
                     }