Best effort to handle multiple boluses within the same minute.

(cherry picked from commit cc9094f)
This commit is contained in:
Johannes Mockenhaupt 2018-01-28 18:58:06 +01:00
parent 3a95c3c4d9
commit bd87a893c2
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 14 additions and 10 deletions

View file

@ -490,10 +490,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@NonNull
private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
// guard against boluses issued multiple times within a minute
// Guard against boluses issued multiple times within two minutes.
// Two minutes, so that the resulting timestamp and bolus are different with the Combo
// history records which only store with minute-precision
if (lastRequestedBolus != null
&& Math.abs(lastRequestedBolus.amount - detailedBolusInfo.insulin) < 0.01
&& lastRequestedBolus.timestamp + 60 * 1000 > System.currentTimeMillis()) {
&& lastRequestedBolus.timestamp + 120 * 1000 > System.currentTimeMillis()) {
log.error("Bolus delivery failure at stage 0", new Exception());
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.gs(R.string.bolus_frequency_exceeded));
@ -557,9 +559,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
.comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered));
}
// seems we actually made it ...
detailedBolusInfo.date = lastBolus.timestamp;
detailedBolusInfo.pumpId = lastBolus.timestamp + ((int) lastBolus.amount * 10);
// seems we actually made it this far, let's add a treatment record
detailedBolusInfo.date = lastBolus.timestamp + (Math.min((int) lastBolus.amount * 10 * 1000, 59 * 1000));
detailedBolusInfo.pumpId = lastBolus.timestamp + (Math.min((int) lastBolus.amount * 10 * 1000, 59 * 1000));
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.insulin = lastBolus.amount;
boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
@ -955,8 +957,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// Bolus
for (Bolus pumpBolus : history.bolusHistory) {
DetailedBolusInfo dbi = new DetailedBolusInfo();
dbi.date = pumpBolus.timestamp;
dbi.pumpId = pumpBolus.timestamp + ((int) pumpBolus.amount * 10);
dbi.date = pumpBolus.timestamp + (Math.min((int) pumpBolus.amount * 10 * 1000, 59 * 1000));
dbi.pumpId = pumpBolus.timestamp + (Math.min((int) pumpBolus.amount * 10 * 1000, 59 * 1000));
dbi.source = Source.PUMP;
dbi.insulin = pumpBolus.amount;
dbi.eventType = CareportalEvent.CORRECTIONBOLUS;

View file

@ -780,4 +780,6 @@
<string name="openapsama_link_to_preferncejson_doc_txt">Achtung! Normalerweise musst Du diese Werte nicht ändern. Bitte KLICKE HIER und LESE den Text. Verändere Werte erst, wenn Du den Inhalt des Textes verstanden hast.</string>
<string name="pump_basebasalrate">%.2f IE/h</string>
<string name="combo_actvity_reading_basal_profile">Basalratenprofil wird gelesen</string>
<string name="pump_basebasalrate">%.2f IE/h</string>
<string name="urgent_alarm">Dringender Alarm</string>
</resources>

View file

@ -866,7 +866,7 @@
<string name="extendedbolusdeliveryerror">Extended bolus delivery error</string>
<string name="pump_basebasalrate">%.2f U/h</string>
<string name="combo_actvity_reading_basal_profile">Reading basal profile</string>
<string name="combo_bolus_rejected_due_to_pump_history_change">The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested within the same minute for saftery (regardless of whether they were administered or not).</string>
<string name="combo_error_updating_treatment_record">Bolus successfully delivered, but adding the treatment entry failed. This can happen if two small boluses of the same size are administered within the same minute. Please check the pump history and treatment entries and use the Careportal to add missing entries. Make sure not to add any entries for the exact same minute.</string>
<string name="combo_bolus_rejected_due_to_pump_history_change">The pump history has changed after the bolus calculation was performed. The bolus was not delivered. Please recalculate if a bolus is still needed. If the same bolus amount is required, please wait a minute since boluses with the same amount are blocked when requested with less than tow minutes between them for safety (regardless of whether they were administered or not).</string>
<string name="combo_error_updating_treatment_record">Bolus successfully delivered, but adding the treatment entry failed. This can happen if two small boluses of the same size are administered within the last two minutes. Please check the pump history and treatment entries and use the Careportal to add missing entries. Make sure not to add any entries for the exact same minute and same amount.</string>
</resources>