Move detection of partial bolus delivery to BolusCommand.

Have BolusCommand verify delivered bolus if needed and return the
actually delivered bolus amount. This makes more sense now,
given history is only read if unavoidable.
This commit is contained in:
Johannes Mockenhaupt 2017-12-08 12:10:54 +01:00
parent e5a68608a0
commit f09464e5d6
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 26 additions and 44 deletions

View file

@ -471,46 +471,21 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
bolusInProgress = false;
if (!cancelBolus && bolusCmdResult.success) {
detailedBolusInfo.date = bolusCmdResult.state.timestamp;
if (bolusCmdResult.delivered > 0) {
detailedBolusInfo.insulin = bolusCmdResult.delivered;
detailedBolusInfo.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
return new PumpEnactResult().success(true).enacted(true)
.bolusDelivered(detailedBolusInfo.insulin)
}
return new PumpEnactResult()
.success(bolusCmdResult.success)
.enacted(bolusCmdResult.delivered > 0)
.bolusDelivered(bolusCmdResult.delivered)
.carbsDelivered(detailedBolusInfo.carbs);
}
// the remainder of this method checks what was actually delivered based on pump history
// in case of error or cancellation
CommandResult historyResult = runCommand(null, 1,
() -> ruffyScripter.readHistory(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
if (!historyResult.success || historyResult.history == null || historyResult.history.bolusHistory.isEmpty()) {
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
}
Bolus lastPumpBolus = historyResult.history.bolusHistory.get(0);
if (cancelBolus) {
// if cancellation was requested, the delivered bolus is allowed to differ from requested
} else if (lastPumpBolus == null || Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01
|| System.currentTimeMillis() - lastPumpBolus.timestamp > 5 * 60 * 1000) {
return new PumpEnactResult().success(false).enacted(false).
comment(MainApp.sResources.getString(R.string.combo_bolus_bolus_delivery_failed));
}
if (lastPumpBolus != null && (lastPumpBolus.amount > 0)) {
detailedBolusInfo.insulin = lastPumpBolus.amount;
detailedBolusInfo.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
return new PumpEnactResult().success(true).enacted(true)
.bolusDelivered(lastPumpBolus.amount).carbsDelivered(detailedBolusInfo.carbs);
} else {
return new PumpEnactResult().success(true).enacted(false);
}
} finally {
// BolusCommand.execute() intentionally doesn't close the progress dialog if an error
// occurred so it stays open while the connection was re-established if needed and/or
// this method did recovery
// BolusCommand.execute() intentionally doesn't close the progress dialog (indirectly
// by reporting 100% progress) if an error occurred so it stays open while the connection
// was re-established if needed and/or this method did recovery
bolusProgressReporter.report(FINISHED, 100, 0);
pump.activity = null;
MainApp.bus().post(new EventComboPumpUpdateGUI());

View file

@ -811,7 +811,7 @@
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
<string name="combo_pump_never_connected">Never</string>
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</string>
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Attempting to update history from pump. Please the pump and treatments tabs and bolus again as needed.</string>
<string name="combo_bolus_bolus_delivery_failed">Bolus delivery failed. A (partial) bolus might have been delivered. Please check the pump and the treatments tabs and bolus again as needed.</string>
<string name="combo_force_disabled_notification">Unsafe usage: extended or multiwave boluses have been delivered within the last 6 hours or the selected basal rate is not 1. Loop mode has been set to low-suspend only until 6 hours after the last unsupported bolus or basal rate profile. Only normal boluses are supported in loop mode with basal rate profile 1.</string>
<string name="bolus_frequency_exceeded">A bolus with the same amount was requested within the last minute. For safety reasons this is disallowed.</string>
<string name="combo_pump_connected_now">Now</string>

View file

@ -13,13 +13,13 @@ public class CommandResult {
public boolean success;
/** State of the pump *after* command execution. */
public PumpState state;
/** Bolus actually delivered if request was a bolus command. */
public Double delivered;
/** History if requested by the command. */
@Nullable
public PumpHistory history;
/** Basal rate profile if requested. */
public BasalProfile basalProfile;
/** Total duration the command took. */
public String duration;
/** Warnings raised on the pump that are forwarded to AAPS to be turned into AAPS
* notifications. */
@ -28,6 +28,7 @@ public class CommandResult {
public int reservoirLevel = -1;
@Nullable
@Deprecated
public Bolus lastBolus;
public CommandResult success(boolean success) {
@ -35,11 +36,6 @@ public class CommandResult {
return this;
}
public CommandResult duration(String duration) {
this.duration = duration;
return this;
}
public CommandResult state(PumpState state) {
this.state = state;
return this;
@ -62,7 +58,6 @@ public class CommandResult {
", state=" + state +
", history=" + history +
", basalProfile=" + basalProfile +
", duration='" + duration + '\'' +
", forwardedWarnings='" + forwardedWarnings + '\'' +
", lastBolus=" + lastBolus +
'}';

View file

@ -152,6 +152,18 @@ public class BolusCommand extends BaseCommand {
// ignore
}
}
if (cancelInProgress) {
// delivery was started, but cancellation requested, so there is a bolus we can read
ReadReservoirLevelAndLastBolus readReservoirLevelAndLastBolus = new ReadReservoirLevelAndLastBolus();
readReservoirLevelAndLastBolus.setScripter(scripter);
readReservoirLevelAndLastBolus.execute();
result.delivered = readReservoirLevelAndLastBolus.result.lastBolus.amount;
} else {
// bolus delivery completed successfully and completely
result.delivered = bolus;
}
bolusProgressReporter.report(DELIVERED, 100, bolus);
result.success = true;
} finally {