ソースを参照

AH - correction for insulin deletion

AH - correction for insulin deletion
Pierre L 3 年 前
コミット
8b26721be5

+ 5 - 2
FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift

@@ -52,7 +52,8 @@ enum DataTable {
     }
 
     class Treatment: Identifiable, Hashable, Equatable {
-        var id: UUID
+        let id: UUID
+        let idPumpEvent: String?
         let units: GlucoseUnits
         let type: DataType
         let date: Date
@@ -74,7 +75,8 @@ enum DataTable {
             amount: Decimal? = nil,
             secondAmount: Decimal? = nil,
             duration: Decimal? = nil,
-            id: UUID? = nil
+            id: UUID? = nil,
+            idPumpEvent: String? = nil
         ) {
             self.units = units
             self.type = type
@@ -83,6 +85,7 @@ enum DataTable {
             self.secondAmount = secondAmount
             self.duration = duration
             self.id = id ?? UUID()
+            self.idPumpEvent = idPumpEvent
         }
 
         static func == (lhs: Treatment, rhs: Treatment) -> Bool {

+ 3 - 1
FreeAPS/Sources/Modules/DataTable/DataTableProvider.swift

@@ -28,7 +28,9 @@ extension DataTable {
 
         func deleteInsulin(_ treatement: Treatment) {
             nightscoutManager.deleteInsulin(at: treatement.date)
-            healthkitManager.deleteInsulin(syncID: treatement.id.uuidString)
+            if let id = treatement.idPumpEvent {
+                healthkitManager.deleteInsulin(syncID: id)
+            }
         }
 
         func glucose() -> [BloodGlucose] {

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

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