alarm on clashes, not on identical treatments
This commit is contained in:
parent
bf3b4502bf
commit
b39fa514c2
|
@ -132,6 +132,22 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mealBolus, _id and isSMB cannot be known coming from pump. Only compare rest
|
||||
*/
|
||||
public boolean equalsRePumpHistory(Treatment other) {
|
||||
if (date != other.date)
|
||||
return false;
|
||||
if (insulin != other.insulin)
|
||||
return false;
|
||||
if (carbs != other.carbs)
|
||||
return false;
|
||||
if (pumpId != other.pumpId)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void copyFrom(Treatment t) {
|
||||
date = t.date;
|
||||
_id = t._id;
|
||||
|
|
|
@ -241,7 +241,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
}
|
||||
|
||||
// return true if new record is created
|
||||
public boolean createOrUpdate(Treatment treatment) {
|
||||
public UpdateReturn createOrUpdate(Treatment treatment) {
|
||||
try {
|
||||
Treatment old;
|
||||
treatment.date = DatabaseHelper.roundDateToSec(treatment.date);
|
||||
|
@ -252,13 +252,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
if (existingTreatment != null) {
|
||||
// do nothing, pump history record cannot be changed
|
||||
log.debug("TREATMENT: Pump record already found in database: " + treatment.toString());
|
||||
return false;
|
||||
//return new UpdateReturn(true, false);
|
||||
return new UpdateReturn(existingTreatment.equalsRePumpHistory(treatment), false);
|
||||
}
|
||||
getDao().create(treatment);
|
||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment);
|
||||
return true;
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
if (treatment.source == Source.NIGHTSCOUT) {
|
||||
old = getDao().queryForId(treatment.date);
|
||||
|
@ -275,9 +276,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
DatabaseHelper.updateEarliestDataChange(old.date);
|
||||
}
|
||||
scheduleTreatmentChange(treatment);
|
||||
return true;
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
return false;
|
||||
return new UpdateReturn(true, false);
|
||||
}
|
||||
// find by NS _id
|
||||
if (treatment._id != null) {
|
||||
|
@ -295,7 +296,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
DatabaseHelper.updateEarliestDataChange(old.date);
|
||||
}
|
||||
scheduleTreatmentChange(treatment);
|
||||
return true;
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -303,19 +304,19 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment);
|
||||
return true;
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
if (treatment.source == Source.USER) {
|
||||
getDao().create(treatment);
|
||||
log.debug("TREATMENT: New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment);
|
||||
return true;
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
return false;
|
||||
return new UpdateReturn(false, false);
|
||||
}
|
||||
|
||||
/** Returns the record for the given id, null if none, throws RuntimeException
|
||||
|
@ -439,4 +440,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
|||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public class UpdateReturn {
|
||||
public UpdateReturn(boolean success, boolean newRecord){
|
||||
this.success = success;
|
||||
this.newRecord = newRecord;
|
||||
}
|
||||
boolean newRecord;
|
||||
boolean success;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -479,7 +479,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
treatment.carbs = detailedBolusInfo.carbs;
|
||||
treatment.source = detailedBolusInfo.source;
|
||||
treatment.mealBolus = treatment.carbs > 0;
|
||||
boolean newRecordCreated = getService().createOrUpdate(treatment);
|
||||
TreatmentService.UpdateReturn creatOrUpdateResult = getService().createOrUpdate(treatment);
|
||||
boolean newRecordCreated = creatOrUpdateResult.newRecord;
|
||||
//log.debug("Adding new Treatment record" + treatment.toString());
|
||||
if (detailedBolusInfo.carbTime != 0) {
|
||||
Treatment carbsTreatment = new Treatment();
|
||||
|
@ -494,7 +495,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
if (newRecordCreated && detailedBolusInfo.isValid)
|
||||
NSUpload.uploadTreatmentRecord(detailedBolusInfo);
|
||||
|
||||
if (!allowUpdate && !newRecordCreated) {
|
||||
if (!allowUpdate && !creatOrUpdateResult.success) {
|
||||
log.error("Treatment could not be added to DB", new Exception());
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.error);
|
||||
|
|
Loading…
Reference in a new issue