From 34182b81a1131e0ea53e732b070503b2bb9b0188 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 12 Oct 2018 00:46:05 +0200 Subject: [PATCH 1/2] Combo: allow records created by the combo to be merged with existing records. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) 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 3f30071327..a082d6bb25 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 @@ -665,15 +665,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint dbi.source = Source.PUMP; dbi.insulin = lastPumpBolus.amount; try { - boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false); - if (!treatmentCreated) { - log.error("Adding treatment record overrode an existing record: " + dbi); - if (dbi.isSMB) { - Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - } - return false; - } + TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true); } catch (Exception e) { log.error("Adding treatment record failed", e); if (dbi.isSMB) { @@ -1158,8 +1150,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint dbi.source = Source.PUMP; dbi.insulin = pumpBolus.amount; dbi.eventType = CareportalEvent.CORRECTIONBOLUS; - if (TreatmentsPlugin.getPlugin().getService().getPumpRecordById(dbi.pumpId) == null) { - TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, false); + if (TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true)) { updated = true; } } From b0fcbf3013730a915e6a339e0c3e904fd17b51a1 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 14 Oct 2018 14:36:05 +0200 Subject: [PATCH 2/2] Update JavaDoc. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 a082d6bb25..ee7feb5eaf 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 @@ -653,11 +653,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint } } - /** - * Updates a DetailedBolusInfo from a pump bolus and adds it as a Treatment to the DB. - * Handles edge cases when dates aren't unique which are extremely unlikely to occur, - * but if they do, the user should be warned since a bolus will be missing from calculations. - */ + /** Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. */ private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) { DetailedBolusInfo dbi = detailedBolusInfo.copy(); dbi.date = calculateFakeBolusDate(lastPumpBolus); @@ -1141,6 +1137,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint return historyResult.success; } + /** Return value indicates whether a new record was created. */ private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) { boolean updated = false; for (Bolus pumpBolus : history.bolusHistory) {