Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Show bg values in warning messages in bolus ui
  • Loading branch information
ps2 committed Feb 24, 2017
commit 27017e61961040a524c0753bf6439b1ecab843c9
4 changes: 2 additions & 2 deletions Loop/Managers/DoseMath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct DoseMath {
let eventualGlucoseTargets = glucoseTargetRange.value(at: eventualGlucose.startDate)

guard minGlucose.quantity >= minimumBGGuard.quantity else {
return BolusRecommendation(amount: 0, pendingInsulin: pendingInsulin, notice: .glucoseBelowMinimumGuard)
return BolusRecommendation(amount: 0, pendingInsulin: pendingInsulin, notice: .glucoseBelowMinimumGuard(minGlucose: minGlucose, unit: glucoseTargetRange.unit))
}

let targetGlucose = eventualGlucoseTargets.maxValue
Expand All @@ -180,7 +180,7 @@ struct DoseMath {
let notice: BolusRecommendationNotice?
if cappedAmount > 0 && minGlucose.quantity.doubleValue(for: glucoseTargetRange.unit) < eventualGlucoseTargets.minValue {
if minGlucose.startDate == glucose[0].startDate {
notice = .currentGlucoseBelowTarget
notice = .currentGlucoseBelowTarget(glucose: minGlucose, unit: glucoseTargetRange.unit)
} else {
notice = .predictedGlucoseBelowTarget(minGlucose: minGlucose, unit: glucoseTargetRange.unit)
}
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ final class LoopDataManager {
completionHandler(nil, LoopError.missingDataError("Glucose data not available"))
return
}

if let carbStore = deviceDataManager.carbStore {
carbStore.getGlucoseEffects(startDate: effectStartDate) { (effects, error) -> Void in
if let error = error {
Expand Down
23 changes: 13 additions & 10 deletions Loop/Models/BolusRecommendation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@ import LoopKit
import HealthKit

enum BolusRecommendationNotice: CustomStringConvertible, Equatable {
case glucoseBelowMinimumGuard
case currentGlucoseBelowTarget
case glucoseBelowMinimumGuard(minGlucose: GlucoseValue, unit: HKUnit)
case currentGlucoseBelowTarget(glucose: GlucoseValue, unit: HKUnit)
case predictedGlucoseBelowTarget(minGlucose: GlucoseValue, unit: HKUnit)

public var description: String {

switch self {
case .glucoseBelowMinimumGuard:
return NSLocalizedString("Predicted glucose is below your minimum BG Guard setting.", comment: "Notice message when recommending bolus when BG is below minimum BG guard.")
case .currentGlucoseBelowTarget:
return NSLocalizedString("Glucose is below target range.", comment: "Message when offering bolus prediction even though bg is below range.")
case .glucoseBelowMinimumGuard(let minGlucose, let unit):
let glucoseFormatter = NumberFormatter.glucoseFormatter(for: unit)
let bgStr = glucoseFormatter.describingGlucose(minGlucose.quantity, for: unit)!
return String(format: NSLocalizedString("Predicted glucose of %1$@ is below your minimum BG Guard setting.", comment: "Notice message when recommending bolus when BG is below minimum BG guard. (1: glucose value)"), bgStr)
case .currentGlucoseBelowTarget(let glucose, let unit):
let glucoseFormatter = NumberFormatter.glucoseFormatter(for: unit)
let bgStr = glucoseFormatter.describingGlucose(glucose.quantity, for: unit)!
return String(format: NSLocalizedString("Current glucose of %1$@ is below target range.", comment: "Message when offering bolus prediction even though bg is below range. (1: glucose value)"), bgStr)
case .predictedGlucoseBelowTarget(let minGlucose, let unit):
let timeFormatter = DateFormatter()
timeFormatter.dateStyle = .none
timeFormatter.timeStyle = .short
let time = timeFormatter.string(from: minGlucose.startDate)

let numberFormatter = NumberFormatter.glucoseFormatter(for: unit)

let minBGStr = numberFormatter.describingGlucose(minGlucose.quantity, for: unit)!

let glucoseFormatter = NumberFormatter.glucoseFormatter(for: unit)
let minBGStr = glucoseFormatter.describingGlucose(minGlucose.quantity, for: unit)!
return String(format: NSLocalizedString("Predicted glucose at %1$@ is %2$@.", comment: "Message when offering bolus prediction even though bg is below range and minBG is in future. (1: glucose time)(2: glucose number)"), time, minBGStr)

}
Expand Down