From 3adda9bf6e27f5c6a2a9613f2b9b19a362f8b86f Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 13:18:49 +0100 Subject: [PATCH] Clean up bolus delivery code. --- .../plugins/PumpCombo/ComboPlugin.java | 30 ++++++++----------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index baaca002a8..d1173a103f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -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; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ca7dce0430..cb9ca63a59 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -858,6 +858,7 @@ 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. Are you really sure you want to read all pump data and take the consequences of this action? TBR CANCELLED warning was confirmed + The pump could\'nt be reached. No bolus was given 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. 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. 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.