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:
parent
e5a68608a0
commit
f09464e5d6
4 changed files with 26 additions and 44 deletions
|
@ -471,46 +471,21 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
|
detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter));
|
||||||
bolusInProgress = false;
|
bolusInProgress = false;
|
||||||
|
|
||||||
if (!cancelBolus && bolusCmdResult.success) {
|
if (bolusCmdResult.delivered > 0) {
|
||||||
detailedBolusInfo.date = bolusCmdResult.state.timestamp;
|
detailedBolusInfo.insulin = bolusCmdResult.delivered;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.source = Source.USER;
|
||||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||||
return new PumpEnactResult().success(true).enacted(true)
|
|
||||||
.bolusDelivered(detailedBolusInfo.insulin)
|
|
||||||
.carbsDelivered(detailedBolusInfo.carbs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the remainder of this method checks what was actually delivered based on pump history
|
return new PumpEnactResult()
|
||||||
// in case of error or cancellation
|
.success(bolusCmdResult.success)
|
||||||
|
.enacted(bolusCmdResult.delivered > 0)
|
||||||
CommandResult historyResult = runCommand(null, 1,
|
.bolusDelivered(bolusCmdResult.delivered)
|
||||||
() -> ruffyScripter.readHistory(new PumpHistoryRequest().bolusHistory(PumpHistoryRequest.LAST)));
|
.carbsDelivered(detailedBolusInfo.carbs);
|
||||||
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 {
|
} finally {
|
||||||
// BolusCommand.execute() intentionally doesn't close the progress dialog if an error
|
// BolusCommand.execute() intentionally doesn't close the progress dialog (indirectly
|
||||||
// occurred so it stays open while the connection was re-established if needed and/or
|
// by reporting 100% progress) if an error occurred so it stays open while the connection
|
||||||
// this method did recovery
|
// was re-established if needed and/or this method did recovery
|
||||||
bolusProgressReporter.report(FINISHED, 100, 0);
|
bolusProgressReporter.report(FINISHED, 100, 0);
|
||||||
pump.activity = null;
|
pump.activity = null;
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||||
|
|
|
@ -811,7 +811,7 @@
|
||||||
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
|
<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_never_connected">Never</string>
|
||||||
<string name="combo_pump_unsupported_operation">Requested operation not supported by pump</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="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="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>
|
<string name="combo_pump_connected_now">Now</string>
|
||||||
|
|
|
@ -13,13 +13,13 @@ public class CommandResult {
|
||||||
public boolean success;
|
public boolean success;
|
||||||
/** State of the pump *after* command execution. */
|
/** State of the pump *after* command execution. */
|
||||||
public PumpState state;
|
public PumpState state;
|
||||||
|
/** Bolus actually delivered if request was a bolus command. */
|
||||||
|
public Double delivered;
|
||||||
/** History if requested by the command. */
|
/** History if requested by the command. */
|
||||||
@Nullable
|
@Nullable
|
||||||
public PumpHistory history;
|
public PumpHistory history;
|
||||||
/** Basal rate profile if requested. */
|
/** Basal rate profile if requested. */
|
||||||
public BasalProfile basalProfile;
|
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
|
/** Warnings raised on the pump that are forwarded to AAPS to be turned into AAPS
|
||||||
* notifications. */
|
* notifications. */
|
||||||
|
@ -28,6 +28,7 @@ public class CommandResult {
|
||||||
public int reservoirLevel = -1;
|
public int reservoirLevel = -1;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@Deprecated
|
||||||
public Bolus lastBolus;
|
public Bolus lastBolus;
|
||||||
|
|
||||||
public CommandResult success(boolean success) {
|
public CommandResult success(boolean success) {
|
||||||
|
@ -35,11 +36,6 @@ public class CommandResult {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandResult duration(String duration) {
|
|
||||||
this.duration = duration;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandResult state(PumpState state) {
|
public CommandResult state(PumpState state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
return this;
|
return this;
|
||||||
|
@ -62,7 +58,6 @@ public class CommandResult {
|
||||||
", state=" + state +
|
", state=" + state +
|
||||||
", history=" + history +
|
", history=" + history +
|
||||||
", basalProfile=" + basalProfile +
|
", basalProfile=" + basalProfile +
|
||||||
", duration='" + duration + '\'' +
|
|
||||||
", forwardedWarnings='" + forwardedWarnings + '\'' +
|
", forwardedWarnings='" + forwardedWarnings + '\'' +
|
||||||
", lastBolus=" + lastBolus +
|
", lastBolus=" + lastBolus +
|
||||||
'}';
|
'}';
|
||||||
|
|
|
@ -152,6 +152,18 @@ public class BolusCommand extends BaseCommand {
|
||||||
// ignore
|
// 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);
|
bolusProgressReporter.report(DELIVERED, 100, bolus);
|
||||||
result.success = true;
|
result.success = true;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in a new issue