fix addToHistoryTreatment
This commit is contained in:
parent
b474e9146f
commit
d707ea7fb0
2 changed files with 44 additions and 18 deletions
|
@ -506,14 +506,26 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpdateReturn {
|
public static 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean newRecord;
|
public void or(UpdateReturn ur) {
|
||||||
boolean success;
|
success = success || ur.success;
|
||||||
|
newRecord = newRecord || ur.newRecord;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ 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;
|
||||||
|
@ -50,7 +51,6 @@ 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;
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
|
|
||||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getPlugin().getActiveInsulin();
|
InsulinInterface insulinInterface = ConfigBuilderPlugin.getPlugin().getActiveInsulin();
|
||||||
if (insulinInterface == null)
|
if (insulinInterface == null)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
double dia = profile.getDia();
|
double dia = profile.getDia();
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
if (t > absorptionTime_ago && t <= now) {
|
if (t > absorptionTime_ago && t <= now) {
|
||||||
if (treatment.carbs >= 1) {
|
if (treatment.carbs >= 1) {
|
||||||
result.carbs += treatment.carbs;
|
result.carbs += treatment.carbs;
|
||||||
if(t > result.lastCarbTime)
|
if (t > result.lastCarbTime)
|
||||||
result.lastCarbTime = t;
|
result.lastCarbTime = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (L.isEnabled(L.DATATREATMENTS))
|
if (L.isEnabled(L.DATATREATMENTS))
|
||||||
log.debug("Last bolus time: " + new Date(last).toLocaleString());
|
log.debug("Last bolus time: " + new Date(last).toLocaleString());
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventReloadTreatmentData ev) {
|
public void onStatusEvent(final EventReloadTreatmentData ev) {
|
||||||
if (L.isEnabled(L.DATATREATMENTS))
|
if (L.isEnabled(L.DATATREATMENTS))
|
||||||
log.debug("EventReloadTreatmentData");
|
log.debug("EventReloadTreatmentData");
|
||||||
initializeTreatmentData();
|
initializeTreatmentData();
|
||||||
initializeExtendedBolusData();
|
initializeExtendedBolusData();
|
||||||
updateTotalIOBTreatments();
|
updateTotalIOBTreatments();
|
||||||
|
@ -352,7 +352,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void onStatusEvent(final EventReloadTempBasalData ev) {
|
public void onStatusEvent(final EventReloadTempBasalData ev) {
|
||||||
if (L.isEnabled(L.DATATREATMENTS))
|
if (L.isEnabled(L.DATATREATMENTS))
|
||||||
log.debug("EventReloadTempBasalData");
|
log.debug("EventReloadTempBasalData");
|
||||||
initializeTempBasalData();
|
initializeTempBasalData();
|
||||||
updateTotalIOBTempBasals();
|
updateTotalIOBTempBasals();
|
||||||
}
|
}
|
||||||
|
@ -372,14 +372,14 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
|
|
||||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getPlugin().getActiveInsulin();
|
InsulinInterface insulinInterface = ConfigBuilderPlugin.getPlugin().getActiveInsulin();
|
||||||
if (insulinInterface == null)
|
if (insulinInterface == null)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
synchronized (tempBasals) {
|
synchronized (tempBasals) {
|
||||||
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
||||||
TemporaryBasal t = tempBasals.get(pos);
|
TemporaryBasal t = tempBasals.get(pos);
|
||||||
if (t.date > time) continue;
|
if (t.date > time) continue;
|
||||||
IobTotal calc;
|
IobTotal calc;
|
||||||
if(truncate && t.end() > truncateTime){
|
if (truncate && t.end() > truncateTime) {
|
||||||
TemporaryBasal dummyTemp = new TemporaryBasal();
|
TemporaryBasal dummyTemp = new TemporaryBasal();
|
||||||
dummyTemp.copyFrom(t);
|
dummyTemp.copyFrom(t);
|
||||||
dummyTemp.cutEndTo(truncateTime);
|
dummyTemp.cutEndTo(truncateTime);
|
||||||
|
@ -398,7 +398,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
ExtendedBolus e = extendedBoluses.get(pos);
|
ExtendedBolus e = extendedBoluses.get(pos);
|
||||||
if (e.date > time) continue;
|
if (e.date > time) continue;
|
||||||
IobTotal calc;
|
IobTotal calc;
|
||||||
if(truncate && e.end() > truncateTime){
|
if (truncate && e.end() > truncateTime) {
|
||||||
ExtendedBolus dummyExt = new ExtendedBolus();
|
ExtendedBolus dummyExt = new ExtendedBolus();
|
||||||
dummyExt.copyFrom(e);
|
dummyExt.copyFrom(e);
|
||||||
dummyExt.cutEndTo(truncateTime);
|
dummyExt.cutEndTo(truncateTime);
|
||||||
|
@ -495,6 +495,12 @@ 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;
|
||||||
|
@ -507,19 +513,27 @@ 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 = getService().createOrUpdate(treatment);
|
TreatmentService.UpdateReturn creatOrUpdateResult = new TreatmentService.UpdateReturn();
|
||||||
boolean newRecordCreated = creatOrUpdateResult.newRecord;
|
TreatmentService.UpdateReturn creatOrUpdateResultCarbs = new TreatmentService.UpdateReturn();
|
||||||
//log.debug("Adding new Treatment record" + treatment.toString());
|
if (treatment.insulin > 0) {
|
||||||
if (detailedBolusInfo.carbTime != 0) {
|
creatOrUpdateResult = getService().createOrUpdate(treatment);
|
||||||
|
//log.debug("Adding new Treatment record" + treatment.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
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 + detailedBolusInfo.carbTime * 60 * 1000L + 1000L; // add 1 sec to make them different records
|
carbsTreatment.date = detailedBolusInfo.date + T.mins(detailedBolusInfo.carbTime).msecs() + T.secs(1).msecs(); // add 1 sec to make them different records
|
||||||
carbsTreatment.carbs = detailedBolusInfo.carbs;
|
carbsTreatment.carbs = detailedBolusInfo.carbs;
|
||||||
carbsTreatment.source = detailedBolusInfo.source;
|
carbsTreatment.source = detailedBolusInfo.source;
|
||||||
getService().createOrUpdate(carbsTreatment);
|
creatOrUpdateResultCarbs = 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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue