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..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); @@ -665,15 +661,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) { @@ -1149,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) { @@ -1158,8 +1147,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; } }