- database bolus + treatments AAPS
- database TBR + treatments AAPS - refactoring bolus a little
This commit is contained in:
parent
0260b68fa8
commit
f110ab2ba3
10 changed files with 71 additions and 73 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1704,6 +1704,7 @@
|
|||
<string name="omnipod_cmd_cancel_bolus">Cancel Bolus</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_forced">Cancel Temporary Basal (Forced)</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_info">Get Pod Info</string>
|
||||
|
|
Loading…
Reference in a new issue