Combo: create separate bolus/carb records at driver level.

This commit is contained in:
Johannes Mockenhaupt 2020-03-06 12:33:20 +01:00
parent 4cca305e1b
commit 70053ea61c
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -654,16 +654,29 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
* Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. * Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus.
*/ */
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) { private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
DetailedBolusInfo dbi = detailedBolusInfo.copy(); DetailedBolusInfo bolusInfo = detailedBolusInfo.copy();
dbi.date = calculateFakeBolusDate(lastPumpBolus); bolusInfo.date = calculateFakeBolusDate(lastPumpBolus);
dbi.pumpId = dbi.date; bolusInfo.pumpId = bolusInfo.date;
dbi.source = Source.PUMP; bolusInfo.source = Source.PUMP;
dbi.insulin = lastPumpBolus.amount; bolusInfo.insulin = lastPumpBolus.amount;
try { try {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi, true); if (bolusInfo.carbs > 0 && bolusInfo.carbTime != 0) {
// split out a separate carbs record without a pumpId
DetailedBolusInfo carbInfo = new DetailedBolusInfo();
carbInfo.date = bolusInfo.date + bolusInfo.carbTime * 60L * 1000L;
carbInfo.carbs = bolusInfo.carbs;
carbInfo.source = Source.USER;
TreatmentsPlugin.getPlugin().addToHistoryTreatment(carbInfo, true);
// remove carbs from bolusInfo to not trigger any unwanted code paths in
// TreatmentsPlugin.addToHistoryTreatment() method
bolusInfo.carbTime = 0;
bolusInfo.carbs = 0;
}
TreatmentsPlugin.getPlugin().addToHistoryTreatment(bolusInfo, true);
} catch (Exception e) { } catch (Exception e) {
log.error("Adding treatment record failed", e); log.error("Adding treatment record failed", e);
if (dbi.isSMB) { if (bolusInfo.isSMB) {
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT); Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT);
RxBus.INSTANCE.send(new EventNewNotification(notification)); RxBus.INSTANCE.send(new EventNewNotification(notification));
} }