Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

determineBolusEventType #1

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 [] }
Expand Down Expand Up @@ -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,
Expand Down