From e9f0fa3c04a3a2978209316a67a0322badeef085 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 5 Feb 2018 23:58:19 +0100 Subject: [PATCH] Warn when finding multiple boluses in the same minute with same amount. Not much can be done if the user manages to bolus multiple boluses within the same minute, with the same amount. This should almost never happen, but if it does, at least warn the user one of those boluses isn't accounted for wrt to IOB. --- .../plugins/PumpCombo/ComboPlugin.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 372049fedf..176fcba67f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashSet; import java.util.List; import info.nightscout.androidaps.BuildConfig; @@ -1219,6 +1220,23 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return historyResult; } + // Check edge of multiple boluses with the same amount in the same minute being imported. + // This is about as edgy-casey as it can get. I'd be surprised of this one actually ever + // triggers. It might, so at least give a warning, since a delivered bolus isn't accounted + // for. + HashSet bolusSet = new HashSet<>(historyResult.history.bolusHistory); + if (bolusSet.size() != historyResult.history.bolusHistory.size()) { + log.debug("Bolus with same amount within the same minute imported. Only one will make it to the DB."); + Answers.getInstance().logCustom(new CustomEvent("ComboBolusToDbError") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION) + .putCustomAttribute("bolus", "") + .putCustomAttribute("issue", "multiple pump history records with the same time and amount")); + Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string. + combo_error_multiple_boluses_with_idential_timestamp), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } + pumpHistoryChanged = updateDbFromPumpHistory(historyResult.history); if (pumpHistoryChanged) { log.debug("Setting 'pumpHistoryChanged' true");