Clean up bolus delivery code.
This commit is contained in:
parent
038ea06abc
commit
3adda9bf6e
2 changed files with 14 additions and 17 deletions
|
@ -493,18 +493,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
lastRequestedBolus = new Bolus(System.currentTimeMillis(), detailedBolusInfo.insulin, true);
|
||||
|
||||
// check pump is ready and all pump bolus records are known
|
||||
CommandResult stateResult = runCommand(null, 2, ruffyScripter::readReservoirLevelAndLastBolus);
|
||||
long pumpTimeWhenBolusWasRequested = stateResult .state.pumpTime;
|
||||
if (!stateResult.success || pumpTimeWhenBolusWasRequested == 0) {
|
||||
if (!stateResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
|
||||
.comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered));
|
||||
}
|
||||
|
||||
if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus));
|
||||
}
|
||||
|
||||
// the commands above ensured a connection was made, which updated this field
|
||||
if (pumpHistoryChanged) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
|
@ -529,32 +527,30 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
() -> ruffyScripter.deliverBolus(detailedBolusInfo.insulin, progressReporter));
|
||||
bolusInProgress = false;
|
||||
|
||||
// Note that the result of the issues the bolus command is not checked. If there was
|
||||
// Note that the result of the issued bolus command is not checked. If there was
|
||||
// a connection problem, ruffyscripter tried to recover and we can just check the
|
||||
// history below
|
||||
// history below to see what was actually delivered
|
||||
|
||||
CommandResult postBolusStateResult = runCommand(null, 3, ruffyScripter::readReservoirLevelAndLastBolus);
|
||||
if (!postBolusStateResult.success) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
|
||||
}
|
||||
|
||||
Bolus lastBolus = postBolusStateResult.lastBolus;
|
||||
if (lastBolus == null || lastBolus.equals(previousBolus)) {
|
||||
Bolus lastPumpBolus = postBolusStateResult.lastBolus;
|
||||
if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
|
||||
}
|
||||
|
||||
if (Math.abs(lastBolus.amount - detailedBolusInfo.insulin) > 0.01) {
|
||||
if (Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01) {
|
||||
return new PumpEnactResult().success(false).enacted(true)
|
||||
.comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered));
|
||||
}
|
||||
|
||||
// seems we actually made it this far, let's add a treatment record
|
||||
detailedBolusInfo.date = calculateFakeBolusDate(lastBolus);
|
||||
detailedBolusInfo.pumpId = calculateFakeBolusDate(lastBolus);
|
||||
detailedBolusInfo.date = calculateFakeBolusDate(lastPumpBolus);
|
||||
detailedBolusInfo.pumpId = calculateFakeBolusDate(lastPumpBolus);
|
||||
detailedBolusInfo.source = Source.PUMP;
|
||||
detailedBolusInfo.insulin = lastBolus.amount;
|
||||
detailedBolusInfo.insulin = lastPumpBolus.amount;
|
||||
try {
|
||||
boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||
if (!treatmentCreated) {
|
||||
|
@ -579,8 +575,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
return new PumpEnactResult()
|
||||
.success(true)
|
||||
.enacted(lastBolus.amount > 0)
|
||||
.bolusDelivered(lastBolus.amount)
|
||||
.enacted(lastPumpBolus.amount > 0)
|
||||
.bolusDelivered(lastPumpBolus.amount)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
} finally {
|
||||
pump.activity = null;
|
||||
|
|
|
@ -858,6 +858,7 @@
|
|||
<string name="combo_read_full_history_warning">This will read the full history and state of the pump. Everything in \"My Data\" and the basal rate. Boluses and TBRs will be added to Treatments if they don\'t already exist. This can cause entries to be duplicated because the pump\'s time is imprecise. Using this when normally looping with the pump is highly discouraged and reserved for special circumstances. If you still want to do this, long press this button again.\n\nWARNING: this can trigger a bug which causes the pump to reject all connection attempts and requires pressing a button on the pump to recover and should therefore be avoided.</string>
|
||||
<string name="combo_read_full_history_confirmation">Are you really sure you want to read all pump data and take the consequences of this action?</string>
|
||||
<string name="combo_pump_tbr_cancelled_warrning">TBR CANCELLED warning was confirmed</string>
|
||||
<string name="combo_error_no_connection_no_bolus_delivered">The pump could\'nt be reached. No bolus was given</string>
|
||||
<string name="combo_error_no_bolus_delivered">Bolus delivery failed. It appears no bolus was delivered. To be sure, please check the pump to avoid a double bolus and then bolus again. To guard against bugs, boluses are not automatically retried.</string>
|
||||
<string name="combo_error_partial_bolus_delivered">Only %.2f U of the requested bolus of %.2f U was delivered due to an error. Please check the pump to verify this and take appropriate actions.</string>
|
||||
<string name="combo_error_bolus_verification_failed">Delivering the bolus and verifying the pump\'s history failed, please check the pump and manually create a bolus record using the Careportal tab if a bolus was delivered.</string>
|
||||
|
|
Loading…
Reference in a new issue