Revert "fix addToHistoryTreatment"

This reverts commit d707ea7fb0.
This commit is contained in:
AdrianLxM 2018-09-26 13:37:05 +02:00
parent 23a91b3838
commit 95ea377d71
2 changed files with 18 additions and 44 deletions

View file

@ -506,26 +506,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
return null; return null;
} }
public static class UpdateReturn { public class UpdateReturn {
boolean newRecord;
boolean success;
public UpdateReturn() {
success = false;
newRecord = false;
}
public UpdateReturn(boolean success, boolean newRecord) { public UpdateReturn(boolean success, boolean newRecord) {
this.success = success; this.success = success;
this.newRecord = newRecord; this.newRecord = newRecord;
} }
public void or(UpdateReturn ur) { boolean newRecord;
success = success || ur.success; boolean success;
newRecord = newRecord || ur.newRecord;
}
} }
} }

View file

@ -43,7 +43,6 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
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.NSClientInternal.NSUpload;
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; 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;
@ -51,6 +50,7 @@ import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.Sensitivity.SensitivityWeightedAveragePlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.T; import info.nightscout.utils.T;
@ -495,12 +495,6 @@ 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, boolean allowUpdate) { public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate) {
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
log.error("Not valid record");
return false;
}
Treatment treatment = new Treatment(); Treatment treatment = new Treatment();
treatment.date = detailedBolusInfo.date; treatment.date = detailedBolusInfo.date;
treatment.source = detailedBolusInfo.source; treatment.source = detailedBolusInfo.source;
@ -513,27 +507,19 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
treatment.source = detailedBolusInfo.source; treatment.source = detailedBolusInfo.source;
treatment.mealBolus = treatment.carbs > 0; treatment.mealBolus = treatment.carbs > 0;
treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null; treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null;
TreatmentService.UpdateReturn creatOrUpdateResult = new TreatmentService.UpdateReturn(); TreatmentService.UpdateReturn creatOrUpdateResult = getService().createOrUpdate(treatment);
TreatmentService.UpdateReturn creatOrUpdateResultCarbs = new TreatmentService.UpdateReturn(); boolean newRecordCreated = creatOrUpdateResult.newRecord;
if (treatment.insulin > 0) {
creatOrUpdateResult = getService().createOrUpdate(treatment);
//log.debug("Adding new Treatment record" + treatment.toString()); //log.debug("Adding new Treatment record" + treatment.toString());
} if (detailedBolusInfo.carbTime != 0) {
if (detailedBolusInfo.carbTime != 0 && detailedBolusInfo.carbs > 0) {
Treatment carbsTreatment = new Treatment(); Treatment carbsTreatment = new Treatment();
carbsTreatment.source = detailedBolusInfo.source; carbsTreatment.source = detailedBolusInfo.source;
carbsTreatment.pumpId = detailedBolusInfo.pumpId; // but this should never happen carbsTreatment.pumpId = detailedBolusInfo.pumpId; // but this should never happen
carbsTreatment.date = detailedBolusInfo.date + T.mins(detailedBolusInfo.carbTime).msecs() + T.secs(1).msecs(); // add 1 sec to make them different records carbsTreatment.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L + 1000L; // add 1 sec to make them different records
carbsTreatment.carbs = detailedBolusInfo.carbs; carbsTreatment.carbs = detailedBolusInfo.carbs;
carbsTreatment.source = detailedBolusInfo.source; carbsTreatment.source = detailedBolusInfo.source;
creatOrUpdateResultCarbs = getService().createOrUpdate(carbsTreatment); getService().createOrUpdate(carbsTreatment);
//log.debug("Adding new Treatment record" + carbsTreatment); //log.debug("Adding new Treatment record" + carbsTreatment);
} }
creatOrUpdateResult.or(creatOrUpdateResultCarbs);
boolean newRecordCreated = creatOrUpdateResult.newRecord;
if (newRecordCreated && detailedBolusInfo.isValid) if (newRecordCreated && detailedBolusInfo.isValid)
NSUpload.uploadTreatmentRecord(detailedBolusInfo); NSUpload.uploadTreatmentRecord(detailedBolusInfo);