alarm on failure to add treatment to db.

This commit is contained in:
Johannes Mockenhaupt 2018-07-01 17:20:28 +02:00
parent 658af4bcfd
commit 6ebb13d28d
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
17 changed files with 34 additions and 22 deletions

View file

@ -50,7 +50,7 @@ public interface TreatmentsInterface {
boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus); boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus);
boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo); boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate);
TempTarget getTempTargetFromHistory(); TempTarget getTempTargetFromHistory();
TempTarget getTempTargetFromHistory(long time); TempTarget getTempTargetFromHistory(long time);

View file

@ -270,7 +270,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
detailedBolusInfo.notes = notes; detailedBolusInfo.notes = notes;
if (recordOnlyCheckbox.isChecked()) { if (recordOnlyCheckbox.isChecked()) {
detailedBolusInfo.date = time; detailedBolusInfo.date = time;
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
} else { } else {
detailedBolusInfo.date = now(); detailedBolusInfo.date = now();
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {

View file

@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Objects; import java.util.Objects;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -187,7 +186,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
} }
}); });
} else { } else {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
} }
FabricPrivacy.getInstance().logCustom(new CustomEvent("Bolus")); FabricPrivacy.getInstance().logCustom(new CustomEvent("Bolus"));
} }

View file

@ -389,7 +389,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
} }
}); });
} else { } else {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
} }
FabricPrivacy.getInstance().logCustom(new CustomEvent("Wizard")); FabricPrivacy.getInstance().logCustom(new CustomEvent("Wizard"));
} }

View file

@ -878,7 +878,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
}); });
} else { } else {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
} }
FabricPrivacy.getInstance().logCustom(new CustomEvent("QuickWizard")); FabricPrivacy.getInstance().logCustom(new CustomEvent("QuickWizard"));
} }

View file

@ -199,7 +199,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.insulin = t.insulin;
detailedBolusInfo.date = System.currentTimeMillis(); detailedBolusInfo.date = System.currentTimeMillis();
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
return result; return result;
} else { } else {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();

View file

@ -202,7 +202,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.insulin = t.insulin;
detailedBolusInfo.date = System.currentTimeMillis(); detailedBolusInfo.date = System.currentTimeMillis();
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
return result; return result;
} else { } else {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();

View file

@ -133,14 +133,14 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
break; break;
case DanaRPump.BOLUS: case DanaRPump.BOLUS:
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
DetailedBolusInfoStorage.remove(detailedBolusInfo.date); DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
status = "BOLUS " + DateUtil.timeString(datetime); status = "BOLUS " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.DUALBOLUS: case DanaRPump.DUALBOLUS:
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
DetailedBolusInfoStorage.remove(detailedBolusInfo.date); DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
status = "DUALBOLUS " + DateUtil.timeString(datetime); status = "DUALBOLUS " + DateUtil.timeString(datetime);
@ -183,7 +183,7 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
emptyCarbsInfo.date = datetime.getTime(); emptyCarbsInfo.date = datetime.getTime();
emptyCarbsInfo.source = Source.PUMP; emptyCarbsInfo.source = Source.PUMP;
emptyCarbsInfo.pumpId = datetime.getTime(); emptyCarbsInfo.pumpId = datetime.getTime();
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false);
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g"); log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
status = "CARBS " + DateUtil.timeString(datetime); status = "CARBS " + DateUtil.timeString(datetime);
break; break;

View file

@ -107,14 +107,14 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break; break;
case DanaRPump.BOLUS: case DanaRPump.BOLUS:
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
DetailedBolusInfoStorage.remove(detailedBolusInfo.date); DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
status = "BOLUS " + DateUtil.timeString(datetime); status = "BOLUS " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.DUALBOLUS: case DanaRPump.DUALBOLUS:
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
DetailedBolusInfoStorage.remove(detailedBolusInfo.date); DetailedBolusInfoStorage.remove(detailedBolusInfo.date);
status = "DUALBOLUS " + DateUtil.timeString(datetime); status = "DUALBOLUS " + DateUtil.timeString(datetime);
@ -157,7 +157,7 @@ public class MsgHistoryEvents_v2 extends MessageBase {
emptyCarbsInfo.date = datetime.getTime(); emptyCarbsInfo.date = datetime.getTime();
emptyCarbsInfo.source = Source.PUMP; emptyCarbsInfo.source = Source.PUMP;
emptyCarbsInfo.pumpId = datetime.getTime(); emptyCarbsInfo.pumpId = datetime.getTime();
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false);
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g"); log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
status = "CARBS " + DateUtil.timeString(datetime); status = "CARBS " + DateUtil.timeString(datetime);
break; break;

View file

@ -61,7 +61,6 @@ import sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfil
import sugar.free.sightparser.applayer.messages.AppLayerMessage; import sugar.free.sightparser.applayer.messages.AppLayerMessage;
import sugar.free.sightparser.applayer.messages.remote_control.BolusMessage; import sugar.free.sightparser.applayer.messages.remote_control.BolusMessage;
import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage; import sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage;
import sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage;
import sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMessage; import sugar.free.sightparser.applayer.messages.remote_control.ExtendedBolusMessage;
import sugar.free.sightparser.applayer.messages.remote_control.StandardBolusMessage; import sugar.free.sightparser.applayer.messages.remote_control.StandardBolusMessage;
import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage; import sugar.free.sightparser.applayer.messages.status.ActiveBolusesMessage;
@ -456,7 +455,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
bolusingEvent.bolusId = bolusId; bolusingEvent.bolusId = bolusId;
bolusingEvent.percent = 0; bolusingEvent.percent = 0;
MainApp.bus().post(bolusingEvent); MainApp.bus().post(bolusingEvent);
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
} else { } else {
log.debug("Failure to deliver treatment"); log.debug("Failure to deliver treatment");
} }

View file

@ -83,6 +83,6 @@ class HistoryLogAdapter {
detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = record_id; detailedBolusInfo.pumpId = record_id;
detailedBolusInfo.insulin = insulin; detailedBolusInfo.insulin = insulin;
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
} }
} }

View file

@ -136,7 +136,7 @@ public class MDIPlugin extends PluginBase implements PumpInterface {
result.bolusDelivered = detailedBolusInfo.insulin; result.bolusDelivered = detailedBolusInfo.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; result.carbsDelivered = detailedBolusInfo.carbs;
result.comment = MainApp.gs(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
return result; return result;
} }

View file

@ -226,7 +226,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui()); MainApp.bus().post(new EventVirtualPumpUpdateGui());
lastDataTime = new Date(); lastDataTime = new Date();
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
return result; return result;
} }

View file

@ -50,7 +50,7 @@ public class CarbsGenerator {
} }
}); });
} else { } else {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(carbInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(carbInfo, false);
} }
} }
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.Treatments; package info.nightscout.androidaps.plugins.Treatments;
import android.content.Intent;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
@ -38,6 +39,7 @@ import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin;
@ -465,7 +467,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
// return true if new record is created // return true if new record is created
@Override @Override
public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo) { public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate) {
Treatment treatment = new Treatment(); Treatment treatment = new Treatment();
treatment.date = detailedBolusInfo.date; treatment.date = detailedBolusInfo.date;
treatment.source = detailedBolusInfo.source; treatment.source = detailedBolusInfo.source;
@ -491,6 +493,16 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
} }
if (newRecordCreated && detailedBolusInfo.isValid) if (newRecordCreated && detailedBolusInfo.isValid)
NSUpload.uploadTreatmentRecord(detailedBolusInfo); NSUpload.uploadTreatmentRecord(detailedBolusInfo);
if (!allowUpdate && !newRecordCreated) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.error);
i.putExtra("status", MainApp.gs(R.string.error_adding_treatment_message));
i.putExtra("title", MainApp.gs(R.string.error_adding_treatment_title));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
return newRecordCreated; return newRecordCreated;
} }

View file

@ -719,7 +719,7 @@ public class ActionStringHandler {
} }
}); });
} else { } else {
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
} }
} }

View file

@ -1179,6 +1179,8 @@
<string name="careportal_removestartedevents">Clean AndroidAPS started</string> <string name="careportal_removestartedevents">Clean AndroidAPS started</string>
<string name="storedsettingsfound">Stored settings found</string> <string name="storedsettingsfound">Stored settings found</string>
<string name="allow_hardware_pump_text">Attention: If you activate and connect to a hardware pump, AndroidAPS will copy the basal settings from the profile to the pump, overwriting the existing basal rate stored on the pump. Make sure you have the correct basal setting in AndroidAPS. If you are not sure or don\'t want to overwrite the basal settings on your pump, press cancel and repeat switching to the pump at a later time.</string> <string name="allow_hardware_pump_text">Attention: If you activate and connect to a hardware pump, AndroidAPS will copy the basal settings from the profile to the pump, overwriting the existing basal rate stored on the pump. Make sure you have the correct basal setting in AndroidAPS. If you are not sure or don\'t want to overwrite the basal settings on your pump, press cancel and repeat switching to the pump at a later time.</string>
<string name="error_adding_treatment_message">Treatment data incomplete</string>
<string name="error_adding_treatment_title">A treatment (insulin:%0.2f, carbs: %2) couldn\'t not be added to treatments. Please check and manually add a record as appropriate.</string>
<plurals name="objective_days"> <plurals name="objective_days">
<item quantity="one">%d day</item> <item quantity="one">%d day</item>