From f110ab2ba370346e8c23c08b852a2ad74fc4b719 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Mon, 30 Dec 2019 17:30:54 +0100 Subject: [PATCH] - database bolus + treatments AAPS - database TBR + treatments AAPS - refactoring bolus a little --- .../pump/common/utils/DateTimeUtil.java | 17 +++++++ .../pump/omnipod/OmnipodPumpPlugin.java | 46 ++----------------- .../omnipod/comm/data/PodCommResponse.java | 19 -------- .../OmnipodCommunicationManagerInterface.java | 5 +- .../omnipod/driver/OmnipodPumpStatus.java | 1 + .../driver/comm/AapsOmnipodManager.java | 40 +++++++++++++--- .../driver/db/PodHistoryEntryType.java | 1 + .../pump/omnipod/driver/ui/OmnipodUITask.java | 8 ++-- .../comm/OmnipodDashCommunicationManager.java | 6 +++ app/src/main/res/values/strings.xml | 1 + 10 files changed, 71 insertions(+), 73 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java index 76e8697666..7c3e3eb767 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/DateTimeUtil.java @@ -283,4 +283,21 @@ public class DateTimeUtil { } + public static long getTimeInFutureFromMinutes(long startTime, int minutes) { + return startTime + getTimeInMs(minutes); + } + + public static long getTimeInFutureFromMinutes(int minutes) { + return System.currentTimeMillis() + getTimeInMs(minutes); + } + + + public static long getTimeInMs(int minutes) { + return getTimeInS(minutes) * 1000L; + } + + public static int getTimeInS(int minutes) { + return minutes * 60; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 6145693620..5b8f8667df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -51,6 +51,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor; +import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; @@ -561,7 +562,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump if (currentProfile != null) { int hour = (new GregorianCalendar()).get(Calendar.HOUR_OF_DAY); - return currentProfile.getBasalTimeFromMidnight(getTimeInS(hour * 60)); + return currentProfile.getBasalTimeFromMidnight(DateTimeUtil.getTimeInS(hour * 60)); } else { return 0.0d; } @@ -618,7 +619,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump try { OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBolus, - detailedBolusInfo.insulin, detailedBolusInfo.isSMB); + detailedBolusInfo); PumpEnactResult result = responseTask.getResult(); @@ -626,8 +627,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump if (result.success) { - TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); - // we subtract insulin, exact amount will be visible with next remainingInsulin update. // if (getPodPumpStatusObject().reservoirRemainingUnits != 0 && // getPodPumpStatusObject().reservoirRemainingUnits != 75 ) { @@ -637,14 +636,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses : OmnipodConst.Statistics.StandardBoluses); - // calculate time for bolus and set driver to busy for that time - - // TODO fix this -// int bolusTime = 1; //omnipodCommunicationManager.get; -// long time = System.currentTimeMillis() + (bolusTime * 1000); -// -// this.busyTimestamps.add(time); - result.bolusDelivered(detailedBolusInfo.insulin).carbsDelivered(detailedBolusInfo.carbs); + result.carbsDelivered(detailedBolusInfo.carbs); } return result; @@ -667,12 +659,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump LOG.info(getLogPrefix() + "stopBolusDelivering - wasSuccess={}", result.success); - if (result.success) { - // TODO fix bolus record with cancel - - //TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); - } - finishAction("Bolus"); } @@ -748,19 +734,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + result.success); if (result.success) { - pumpStatusLocal.tempBasalStart = System.currentTimeMillis(); - pumpStatusLocal.tempBasalAmount = absoluteRate; - pumpStatusLocal.tempBasalLength = durationInMinutes; - pumpStatusLocal.tempBasalEnd = getTimeInFutureFromMinutes(durationInMinutes); - - TemporaryBasal tempStart = new TemporaryBasal() // - .date(System.currentTimeMillis()) // - .duration(durationInMinutes) // - .absolute(absoluteRate) // - .source(Source.USER); - - TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart); - incrementStatistics(OmnipodConst.Statistics.TBRsSet); } @@ -791,19 +764,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump } - protected long getTimeInFutureFromMinutes(int minutes) { - return System.currentTimeMillis() + getTimeInMs(minutes); - } - protected long getTimeInMs(int minutes) { - return getTimeInS(minutes) * 1000L; - } - - protected int getTimeInS(int minutes) { - return minutes * 60; - } - @Override public PumpEnactResult cancelTempBasal(boolean enforceNew) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java deleted file mode 100644 index 625168bac0..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/data/PodCommResponse.java +++ /dev/null @@ -1,19 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.comm.data; - -import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodResponseType; - -public class PodCommResponse { - - PodResponseType podResponseType; - - Boolean acknowledged; - Object customData; - Object errorResponse; - - public boolean isAcknowledged() { - return (acknowledged != null && acknowledged); - } - - // some status data if it can be returned (battery, reservoir, etc) - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java index 01d25c8763..3999cd2923 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodCommunicationManagerInterface.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs; +import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; @@ -39,9 +40,9 @@ public interface OmnipodCommunicationManagerInterface { /** * Set Bolus * - * @param amount amount of bolus in U + * @param detailedBolusInfo DetailedBolusInfo instance with amount and all other required data */ - PumpEnactResult setBolus(Double amount, boolean isSmb); + PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo); /** * Cancel Bolus (if bolus is already stopped, return acknowledgment) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java index 2fb6bd10c2..8996795fa9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java @@ -41,6 +41,7 @@ public class OmnipodPumpStatus extends PumpStatus { public long tempBasalEnd; public Double tempBasalAmount = 0.0d; public Integer tempBasalLength; + public long tempBasalPumpId; public PodSessionState podSessionState; private boolean rileyLinkAddressChanged = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java index d6b4638e0c..a9c8fad873 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java @@ -16,6 +16,7 @@ import java.util.Objects; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.Source; @@ -31,6 +32,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; +import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult; @@ -270,17 +272,17 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface } @Override - public PumpEnactResult setBolus(Double units, boolean isSmb) { + public PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo) { OmnipodManager.BolusCommandResult bolusCommandResult; - boolean beepsEnabled = isSmb ? isSmbBeepsEnabled() : isBolusBeepsEnabled(); + boolean beepsEnabled = detailedBolusInfo.isSMB ? isSmbBeepsEnabled() : isBolusBeepsEnabled(); Date bolusStarted; try { - bolusCommandResult = delegate.bolus(units, beepsEnabled, beepsEnabled, isSmb ? null : + bolusCommandResult = delegate.bolus(detailedBolusInfo.insulin, beepsEnabled, beepsEnabled, detailedBolusInfo.isSMB ? null : (estimatedUnitsDelivered, percentage) -> { EventOverviewBolusProgress progressUpdateEvent = EventOverviewBolusProgress.INSTANCE; - progressUpdateEvent.setStatus(getStringResource(R.string.bolusdelivering, units)); + progressUpdateEvent.setStatus(getStringResource(R.string.bolusdelivering, detailedBolusInfo.insulin)); progressUpdateEvent.setPercent(percentage); sendEvent(progressUpdateEvent); }); @@ -303,11 +305,20 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface double unitsDelivered = bolusDeliveryResult.getUnitsDelivered(); - if (pumpStatus != null && !isSmb) { + if (pumpStatus != null && !detailedBolusInfo.isSMB) { lastBolusTime = pumpStatus.lastBolusTime = bolusStarted; lastBolusUnits = pumpStatus.lastBolusAmount = unitsDelivered; } + long pumpId = addSuccessToHistory(bolusStarted.getTime(), PodHistoryEntryType.SetBolus, unitsDelivered); + + detailedBolusInfo.date = bolusStarted.getTime(); + detailedBolusInfo.insulin = unitsDelivered; + detailedBolusInfo.pumpId = pumpId; + detailedBolusInfo.source = Source.PUMP; + + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); + return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered); } @@ -334,13 +345,30 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface long time = System.currentTimeMillis(); try { delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled); - addSuccessToHistory(time, PodHistoryEntryType.SetTemporaryBasal, tempBasalPair); + time = System.currentTimeMillis(); } catch (Exception ex) { String comment = handleAndTranslateException(ex); addFailureToHistory(time, PodHistoryEntryType.SetTemporaryBasal, comment); return new PumpEnactResult().success(false).enacted(false).comment(comment); } + long pumpId = addSuccessToHistory(time, PodHistoryEntryType.SetTemporaryBasal, tempBasalPair); + + pumpStatus.tempBasalStart = time; + pumpStatus.tempBasalAmount = tempBasalPair.getInsulinRate(); + pumpStatus.tempBasalLength = tempBasalPair.getDurationMinutes(); + pumpStatus.tempBasalEnd = DateTimeUtil.getTimeInFutureFromMinutes(time, tempBasalPair.getDurationMinutes()); + pumpStatus.tempBasalPumpId = pumpId; + + TemporaryBasal tempStart = new TemporaryBasal() // + .date(time) // + .duration(tempBasalPair.getDurationMinutes()) // + .absolute(tempBasalPair.getInsulinRate()) // + .pumpId(pumpId) + .source(Source.PUMP); + + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart); + return new PumpEnactResult().success(true).enacted(true); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java index b75453c8e5..0e7c3a9dc2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java @@ -20,6 +20,7 @@ public enum PodHistoryEntryType { SetTemporaryBasal(10, R.string.omnipod_cmd_set_tbr), CancelTemporaryBasal(11, R.string.omnipod_cmd_cancel_tbr), + CancelTemporaryBasalForce(12, R.string.omnipod_cmd_cancel_tbr_forced), SetBasalSchedule(20, R.string.omnipod_cmd_set_basal_schedule), diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java index aafd5e960c..e7dce48a5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; @@ -73,11 +74,10 @@ public class OmnipodUITask { break; case SetBolus: { - Double amount = getDoubleFromParameters(0); - boolean isSmb = getBooleanFromParameters(1); + DetailedBolusInfo detailedBolusInfo = (DetailedBolusInfo)parameters[0]; - if (amount != null) - returnData = communicationManager.setBolus(amount, isSmb); + if (detailedBolusInfo != null) + returnData = communicationManager.setBolus(detailedBolusInfo); } break; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java index ee8d9212c4..40105b1126 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod_dash/comm/OmnipodDashCommunicationManager.java @@ -5,6 +5,7 @@ import android.content.Context; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; @@ -86,6 +87,11 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana return null; } + @Override + public PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo) { + return null; + } + public PumpEnactResult setBolus(Double parameter, boolean isSmb) { return null; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 258a164297..916b9c7212 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1704,6 +1704,7 @@ Cancel Bolus Set Temporary Basal Cancel Temporary Basal + Cancel Temporary Basal (Forced) Set Basal Schedule Get Pod Status Get Pod Info