From e8c86aa7774e5d2c49bf0e7b125de8bb75b640fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Fri, 29 Sep 2023 14:00:51 +0200 Subject: [PATCH] determineBolusEventType --- .../Sources/APS/Storage/PumpHistoryStorage.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift b/FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift index 05adf9fef6..b3b034f0de 100644 --- a/FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift +++ b/FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift @@ -211,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 [] } @@ -251,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 : (event.isNonPumpInsulin ?? false) ? .nonPumpInsulin : .bolus, + eventType: eventType, createdAt: event.timestamp, enteredBy: NigtscoutTreatment.local, bolus: event,