- database bolus + treatments AAPS

- database TBR + treatments AAPS
- refactoring bolus a little
This commit is contained in:
Andy Rozman 2019-12-30 17:30:54 +01:00
parent 0260b68fa8
commit f110ab2ba3
10 changed files with 71 additions and 73 deletions

View file

@ -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;
}
} }

View file

@ -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.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask; 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.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.comm.message.response.podinfo.PodInfoRecentPulseLog;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
@ -561,7 +562,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
if (currentProfile != null) { if (currentProfile != null) {
int hour = (new GregorianCalendar()).get(Calendar.HOUR_OF_DAY); int hour = (new GregorianCalendar()).get(Calendar.HOUR_OF_DAY);
return currentProfile.getBasalTimeFromMidnight(getTimeInS(hour * 60)); return currentProfile.getBasalTimeFromMidnight(DateTimeUtil.getTimeInS(hour * 60));
} else { } else {
return 0.0d; return 0.0d;
} }
@ -618,7 +619,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
try { try {
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBolus, OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBolus,
detailedBolusInfo.insulin, detailedBolusInfo.isSMB); detailedBolusInfo);
PumpEnactResult result = responseTask.getResult(); PumpEnactResult result = responseTask.getResult();
@ -626,8 +627,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
if (result.success) { if (result.success) {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
// we subtract insulin, exact amount will be visible with next remainingInsulin update. // we subtract insulin, exact amount will be visible with next remainingInsulin update.
// if (getPodPumpStatusObject().reservoirRemainingUnits != 0 && // if (getPodPumpStatusObject().reservoirRemainingUnits != 0 &&
// getPodPumpStatusObject().reservoirRemainingUnits != 75 ) { // getPodPumpStatusObject().reservoirRemainingUnits != 75 ) {
@ -637,14 +636,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses incrementStatistics(detailedBolusInfo.isSMB ? OmnipodConst.Statistics.SMBBoluses
: OmnipodConst.Statistics.StandardBoluses); : OmnipodConst.Statistics.StandardBoluses);
// calculate time for bolus and set driver to busy for that time result.carbsDelivered(detailedBolusInfo.carbs);
// 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);
} }
return result; return result;
@ -667,12 +659,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
LOG.info(getLogPrefix() + "stopBolusDelivering - wasSuccess={}", result.success); LOG.info(getLogPrefix() + "stopBolusDelivering - wasSuccess={}", result.success);
if (result.success) {
// TODO fix bolus record with cancel
//TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
}
finishAction("Bolus"); finishAction("Bolus");
} }
@ -748,19 +734,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + result.success); LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + result.success);
if (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); 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 @Override
public PumpEnactResult cancelTempBasal(boolean enforceNew) { public PumpEnactResult cancelTempBasal(boolean enforceNew) {

View file

@ -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)
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.defs; 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.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
@ -39,9 +40,9 @@ public interface OmnipodCommunicationManagerInterface {
/** /**
* Set Bolus * 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) * Cancel Bolus (if bolus is already stopped, return acknowledgment)

View file

@ -41,6 +41,7 @@ public class OmnipodPumpStatus extends PumpStatus {
public long tempBasalEnd; public long tempBasalEnd;
public Double tempBasalAmount = 0.0d; public Double tempBasalAmount = 0.0d;
public Integer tempBasalLength; public Integer tempBasalLength;
public long tempBasalPumpId;
public PodSessionState podSessionState; public PodSessionState podSessionState;
private boolean rileyLinkAddressChanged = false; private boolean rileyLinkAddressChanged = false;

View file

@ -16,6 +16,7 @@ import java.util.Objects;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source; 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.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType; 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.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.OmnipodCommunicationService;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult; import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult;
@ -270,17 +272,17 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
} }
@Override @Override
public PumpEnactResult setBolus(Double units, boolean isSmb) { public PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo) {
OmnipodManager.BolusCommandResult bolusCommandResult; OmnipodManager.BolusCommandResult bolusCommandResult;
boolean beepsEnabled = isSmb ? isSmbBeepsEnabled() : isBolusBeepsEnabled(); boolean beepsEnabled = detailedBolusInfo.isSMB ? isSmbBeepsEnabled() : isBolusBeepsEnabled();
Date bolusStarted; Date bolusStarted;
try { try {
bolusCommandResult = delegate.bolus(units, beepsEnabled, beepsEnabled, isSmb ? null : bolusCommandResult = delegate.bolus(detailedBolusInfo.insulin, beepsEnabled, beepsEnabled, detailedBolusInfo.isSMB ? null :
(estimatedUnitsDelivered, percentage) -> { (estimatedUnitsDelivered, percentage) -> {
EventOverviewBolusProgress progressUpdateEvent = EventOverviewBolusProgress.INSTANCE; EventOverviewBolusProgress progressUpdateEvent = EventOverviewBolusProgress.INSTANCE;
progressUpdateEvent.setStatus(getStringResource(R.string.bolusdelivering, units)); progressUpdateEvent.setStatus(getStringResource(R.string.bolusdelivering, detailedBolusInfo.insulin));
progressUpdateEvent.setPercent(percentage); progressUpdateEvent.setPercent(percentage);
sendEvent(progressUpdateEvent); sendEvent(progressUpdateEvent);
}); });
@ -303,11 +305,20 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
double unitsDelivered = bolusDeliveryResult.getUnitsDelivered(); double unitsDelivered = bolusDeliveryResult.getUnitsDelivered();
if (pumpStatus != null && !isSmb) { if (pumpStatus != null && !detailedBolusInfo.isSMB) {
lastBolusTime = pumpStatus.lastBolusTime = bolusStarted; lastBolusTime = pumpStatus.lastBolusTime = bolusStarted;
lastBolusUnits = pumpStatus.lastBolusAmount = unitsDelivered; 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); return new PumpEnactResult().success(true).enacted(true).bolusDelivered(unitsDelivered);
} }
@ -334,13 +345,30 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
try { try {
delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled); delegate.setTemporaryBasal(tempBasalPair, beepsEnabled, beepsEnabled);
addSuccessToHistory(time, PodHistoryEntryType.SetTemporaryBasal, tempBasalPair); time = System.currentTimeMillis();
} catch (Exception ex) { } catch (Exception ex) {
String comment = handleAndTranslateException(ex); String comment = handleAndTranslateException(ex);
addFailureToHistory(time, PodHistoryEntryType.SetTemporaryBasal, comment); addFailureToHistory(time, PodHistoryEntryType.SetTemporaryBasal, comment);
return new PumpEnactResult().success(false).enacted(false).comment(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); return new PumpEnactResult().success(true).enacted(true);
} }

View file

@ -20,6 +20,7 @@ public enum PodHistoryEntryType {
SetTemporaryBasal(10, R.string.omnipod_cmd_set_tbr), SetTemporaryBasal(10, R.string.omnipod_cmd_set_tbr),
CancelTemporaryBasal(11, R.string.omnipod_cmd_cancel_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), SetBasalSchedule(20, R.string.omnipod_cmd_set_basal_schedule),

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
@ -73,11 +74,10 @@ public class OmnipodUITask {
break; break;
case SetBolus: { case SetBolus: {
Double amount = getDoubleFromParameters(0); DetailedBolusInfo detailedBolusInfo = (DetailedBolusInfo)parameters[0];
boolean isSmb = getBooleanFromParameters(1);
if (amount != null) if (detailedBolusInfo != null)
returnData = communicationManager.setBolus(amount, isSmb); returnData = communicationManager.setBolus(detailedBolusInfo);
} }
break; break;

View file

@ -5,6 +5,7 @@ import android.content.Context;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
@ -86,6 +87,11 @@ public class OmnipodDashCommunicationManager implements OmnipodCommunicationMana
return null; return null;
} }
@Override
public PumpEnactResult setBolus(DetailedBolusInfo detailedBolusInfo) {
return null;
}
public PumpEnactResult setBolus(Double parameter, boolean isSmb) { public PumpEnactResult setBolus(Double parameter, boolean isSmb) {
return null; return null;
} }

View file

@ -1704,6 +1704,7 @@
<string name="omnipod_cmd_cancel_bolus">Cancel Bolus</string> <string name="omnipod_cmd_cancel_bolus">Cancel Bolus</string>
<string name="omnipod_cmd_set_tbr">Set Temporary Basal</string> <string name="omnipod_cmd_set_tbr">Set Temporary Basal</string>
<string name="omnipod_cmd_cancel_tbr">Cancel Temporary Basal</string> <string name="omnipod_cmd_cancel_tbr">Cancel Temporary Basal</string>
<string name="omnipod_cmd_cancel_tbr_forced">Cancel Temporary Basal (Forced)</string>
<string name="omnipod_cmd_set_basal_schedule">Set Basal Schedule</string> <string name="omnipod_cmd_set_basal_schedule">Set Basal Schedule</string>
<string name="omnipod_cmd_get_pod_status">Get Pod Status</string> <string name="omnipod_cmd_get_pod_status">Get Pod Status</string>
<string name="omnipod_cmd_get_pod_info">Get Pod Info</string> <string name="omnipod_cmd_get_pod_info">Get Pod Info</string>