update with data from pump
This commit is contained in:
parent
b39fa514c2
commit
297fe487f7
4 changed files with 49 additions and 11 deletions
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLab
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.JsonHelper;
|
import info.nightscout.utils.JsonHelper;
|
||||||
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
|
||||||
@DatabaseTable(tableName = Treatment.TABLE_TREATMENTS)
|
@DatabaseTable(tableName = Treatment.TABLE_TREATMENTS)
|
||||||
public class Treatment implements DataPointWithLabelInterface {
|
public class Treatment implements DataPointWithLabelInterface {
|
||||||
|
@ -135,16 +136,21 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mealBolus, _id and isSMB cannot be known coming from pump. Only compare rest
|
* mealBolus, _id and isSMB cannot be known coming from pump. Only compare rest
|
||||||
|
* TODO: remove debug toasts
|
||||||
*/
|
*/
|
||||||
public boolean equalsRePumpHistory(Treatment other) {
|
public boolean equalsRePumpHistory(Treatment other) {
|
||||||
if (date != other.date)
|
if (date != other.date) {
|
||||||
|
ToastUtils.showToastInUiThread(MainApp.instance(), "date: " + date + " vs " + other.date);
|
||||||
return false;
|
return false;
|
||||||
if (insulin != other.insulin)
|
}
|
||||||
|
if (insulin != other.insulin) {
|
||||||
|
ToastUtils.showToastInUiThread(MainApp.instance(), "insulin: " + insulin + " vs " + other.insulin);
|
||||||
return false;
|
return false;
|
||||||
if (carbs != other.carbs)
|
}
|
||||||
return false;
|
if (carbs != other.carbs) {
|
||||||
if (pumpId != other.pumpId)
|
ToastUtils.showToastInUiThread(MainApp.instance(), "carbs: " + carbs + " vs " + other.carbs);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +164,13 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
isSMB = t.isSMB;
|
isSMB = t.isSMB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void copyBasics(Treatment t) {
|
||||||
|
date = t.date;
|
||||||
|
insulin = t.insulin;
|
||||||
|
carbs = t.carbs;
|
||||||
|
pumpId = t.pumpId;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------- DataPointInterface --------------------
|
// ----------------- DataPointInterface --------------------
|
||||||
@Override
|
@Override
|
||||||
public double getX() {
|
public double getX() {
|
||||||
|
|
|
@ -250,10 +250,32 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
// check for changed from pump change in NS
|
// check for changed from pump change in NS
|
||||||
Treatment existingTreatment = getPumpRecordById(treatment.pumpId);
|
Treatment existingTreatment = getPumpRecordById(treatment.pumpId);
|
||||||
if (existingTreatment != null) {
|
if (existingTreatment != null) {
|
||||||
// do nothing, pump history record cannot be changed
|
boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment);
|
||||||
log.debug("TREATMENT: Pump record already found in database: " + treatment.toString());
|
if(!equalRePumpHistory) {
|
||||||
//return new UpdateReturn(true, false);
|
// another treatment exists. Update it with the treatment coming from the pump
|
||||||
return new UpdateReturn(existingTreatment.equalsRePumpHistory(treatment), false);
|
log.debug("TREATMENT: Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||||
|
long oldDate = existingTreatment.date;
|
||||||
|
getDao().delete(existingTreatment); // need to delete/create because date may change too
|
||||||
|
existingTreatment.copyBasics(treatment);
|
||||||
|
getDao().create(existingTreatment);
|
||||||
|
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||||
|
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
|
||||||
|
scheduleTreatmentChange(treatment); }
|
||||||
|
return new UpdateReturn(equalRePumpHistory, false);
|
||||||
|
}
|
||||||
|
existingTreatment = getDao().queryForId(treatment.date);
|
||||||
|
if (existingTreatment != null) {
|
||||||
|
// another treatment exists with different pumpID. Update it with the treatment coming from the pump
|
||||||
|
boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment);
|
||||||
|
long oldDate = existingTreatment.date;
|
||||||
|
log.debug("TREATMENT: Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||||
|
getDao().delete(existingTreatment); // need to delete/create because date may change too
|
||||||
|
existingTreatment.copyFrom(treatment);
|
||||||
|
getDao().create(existingTreatment);
|
||||||
|
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||||
|
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
|
||||||
|
scheduleTreatmentChange(treatment);
|
||||||
|
return new UpdateReturn(equalRePumpHistory, false);
|
||||||
}
|
}
|
||||||
getDao().create(treatment);
|
getDao().create(treatment);
|
||||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||||
|
|
|
@ -497,10 +497,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
|
|
||||||
if (!allowUpdate && !creatOrUpdateResult.success) {
|
if (!allowUpdate && !creatOrUpdateResult.success) {
|
||||||
log.error("Treatment could not be added to DB", new Exception());
|
log.error("Treatment could not be added to DB", new Exception());
|
||||||
|
|
||||||
|
String status = String.format(MainApp.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, DateUtil.dateAndTimeString(treatment.date));
|
||||||
|
|
||||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
i.putExtra("soundid", R.raw.error);
|
i.putExtra("soundid", R.raw.error);
|
||||||
i.putExtra("title", MainApp.gs(R.string.error_adding_treatment_title));
|
i.putExtra("title", MainApp.gs(R.string.error_adding_treatment_title));
|
||||||
i.putExtra("status", String.format(MainApp.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs));
|
i.putExtra("status", status);
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
MainApp.instance().startActivity(i);
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1181,7 +1181,7 @@
|
||||||
<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_title">Treatment data incomplete</string>
|
<string name="error_adding_treatment_title">Treatment data incomplete</string>
|
||||||
<!-- TODO convert to proper style -->
|
<!-- TODO convert to proper style -->
|
||||||
<string name="error_adding_treatment_message" formatted="false">A treatment (insulin: %.2f, carbs: %d) could not be added to treatments. Please check and manually add a record as appropriate.</string>
|
<string name="error_adding_treatment_message" formatted="false">A treatment (insulin: %.2f, carbs: %d, at: %s) could 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>
|
||||||
|
|
Loading…
Reference in a new issue