Only cancel TBR if needed
This commit is contained in:
parent
f0a2307517
commit
356feb5be0
1 changed files with 66 additions and 24 deletions
|
@ -596,25 +596,40 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
if (activeBasalRate == null) return result;
|
if (activeBasalRate == null) return result;
|
||||||
double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate;
|
double percent = 100D / activeBasalRate.getActiveBasalRate() * absoluteRate;
|
||||||
try {
|
if (isFakingTempsByExtendedBoluses()) {
|
||||||
if (isFakingTempsByExtendedBoluses()) {
|
PumpEnactResult cancelEBResult = cancelExtendedBolusOnly();
|
||||||
PumpEnactResult cancelResult = cancelTempBasal(true);
|
if (cancelEBResult.success) {
|
||||||
if (cancelResult.success) {
|
if (percent > 250) {
|
||||||
if (percent > 250) {
|
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
||||||
PumpEnactResult ebResult = setExtendedBolus((absoluteRate - getBaseBasalRate()) / 60D * ((double) durationInMinutes), durationInMinutes);
|
if (cancelTBRResult.success) {
|
||||||
|
PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D
|
||||||
|
* ((double) durationInMinutes),durationInMinutes);
|
||||||
if (ebResult.success) {
|
if (ebResult.success) {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.isPercent = false;
|
result.isPercent = false;
|
||||||
result.absolute = absoluteRate;
|
result.absolute = absoluteRate;
|
||||||
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
||||||
} else result.comment = ebResult.comment;
|
} else {
|
||||||
} else return setTempBasalPercent((int) percent, durationInMinutes, profile, enforceNew);
|
result.comment = ebResult.comment;
|
||||||
} else result.comment = cancelResult.comment;
|
}
|
||||||
} else return setTempBasalPercent((int) percent, durationInMinutes, profile, enforceNew);
|
} else {
|
||||||
|
result.comment = cancelTBRResult.comment;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.comment = cancelEBResult.comment;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = setTempBasalPercent((int) Math.round(percent), durationInMinutes, profile, enforceNew);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
fetchStatus();
|
||||||
|
readHistory();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("Error while setting TBR: " + e.getClass().getCanonicalName());
|
log.info("Error after setting TBR: " + e.getClass().getCanonicalName());
|
||||||
result.comment = ExceptionTranslator.getString(e);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -653,6 +668,17 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
|
PumpEnactResult result = cancelExtendedBolusOnly();
|
||||||
|
try {
|
||||||
|
fetchStatus();
|
||||||
|
readHistory();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("Exception after delivering extended bolus: " + e.getClass().getCanonicalName());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult setExtendedBolusOnly(Double insulin, Integer durationInMinutes) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
try {
|
try {
|
||||||
DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
|
DeliverBolusMessage bolusMessage = new DeliverBolusMessage();
|
||||||
|
@ -676,8 +702,6 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
||||||
readHistory();
|
|
||||||
fetchStatus();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName());
|
log.info("Exception while delivering extended bolus: " + e.getClass().getCanonicalName());
|
||||||
result.comment = ExceptionTranslator.getString(e);
|
result.comment = ExceptionTranslator.getString(e);
|
||||||
|
@ -687,22 +711,31 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
PumpEnactResult cancelEBResult = null;
|
||||||
|
if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolusOnly();
|
||||||
|
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
||||||
|
result.success = (cancelEBResult != null && cancelEBResult.success) && cancelTBRResult.success;
|
||||||
|
result.enacted = (cancelEBResult != null && cancelEBResult.enacted) || cancelTBRResult.enacted;
|
||||||
|
result.comment = cancelEBResult != null ? cancelEBResult.comment : cancelTBRResult.comment;
|
||||||
|
try {
|
||||||
|
fetchStatus();
|
||||||
|
readHistory();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("Exception after canceling TBR: " + e.getClass().getCanonicalName());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PumpEnactResult cancelTempBasalOnly() {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
try {
|
try {
|
||||||
PumpEnactResult cancelEBResult = null;
|
|
||||||
if (isFakingTempsByExtendedBoluses()) cancelEBResult = cancelExtendedBolus();
|
|
||||||
connectionService.requestMessage(new CancelTBRMessage()).await();
|
connectionService.requestMessage(new CancelTBRMessage()).await();
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.isTempCancel = true;
|
result.isTempCancel = true;
|
||||||
confirmAlert(AlertType.WARNING_36);
|
confirmAlert(AlertType.WARNING_36);
|
||||||
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
||||||
if (isFakingTempsByExtendedBoluses() && !cancelEBResult.success) {
|
|
||||||
result.success = false;
|
|
||||||
result.enacted = false;
|
|
||||||
}
|
|
||||||
readHistory();
|
|
||||||
fetchStatus();
|
|
||||||
} catch (NoActiveTBRToCanceLException e) {
|
} catch (NoActiveTBRToCanceLException e) {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
||||||
|
@ -715,6 +748,17 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelExtendedBolus() {
|
public PumpEnactResult cancelExtendedBolus() {
|
||||||
|
PumpEnactResult result = cancelExtendedBolusOnly();
|
||||||
|
try {
|
||||||
|
fetchStatus();
|
||||||
|
readHistory();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("Exception after canceling bolus: " + e.getClass().getCanonicalName());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PumpEnactResult cancelExtendedBolusOnly() {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
try {
|
try {
|
||||||
for (ActiveBolus activeBolus : activeBoluses) {
|
for (ActiveBolus activeBolus : activeBoluses) {
|
||||||
|
@ -744,8 +788,6 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
}
|
}
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
||||||
readHistory();
|
|
||||||
fetchStatus();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
|
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
|
||||||
result.comment = ExceptionTranslator.getString(e);
|
result.comment = ExceptionTranslator.getString(e);
|
||||||
|
|
Loading…
Reference in a new issue