storing extended bolus fix for insight

This commit is contained in:
Milos Kozak 2018-08-16 15:02:45 +02:00
parent b46ebf34c4
commit c927b8f061

View file

@ -961,6 +961,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
extendedBolus.durationInMinutes = trJson.getInt("duration"); extendedBolus.durationInMinutes = trJson.getInt("duration");
extendedBolus.insulin = trJson.getDouble("originalExtendedAmount"); extendedBolus.insulin = trJson.getDouble("originalExtendedAmount");
extendedBolus._id = trJson.getString("_id"); extendedBolus._id = trJson.getString("_id");
// if faking found in NS, adapt AAPS to use it too
if (!VirtualPumpPlugin.getFakingStatus()) { if (!VirtualPumpPlugin.getFakingStatus()) {
VirtualPumpPlugin.setFakingStatus(true); VirtualPumpPlugin.setFakingStatus(true);
updateEarliestDataChange(0); updateEarliestDataChange(0);
@ -975,6 +976,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
extendedBolus.durationInMinutes = 0; extendedBolus.durationInMinutes = 0;
extendedBolus.insulin = 0; extendedBolus.insulin = 0;
extendedBolus._id = trJson.getString("_id"); extendedBolus._id = trJson.getString("_id");
// if faking found in NS, adapt AAPS to use it too
if (!VirtualPumpPlugin.getFakingStatus()) { if (!VirtualPumpPlugin.getFakingStatus()) {
VirtualPumpPlugin.setFakingStatus(true); VirtualPumpPlugin.setFakingStatus(true);
updateEarliestDataChange(0); updateEarliestDataChange(0);
@ -1044,17 +1046,24 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
extendedBolus.date = roundDateToSec(extendedBolus.date); extendedBolus.date = roundDateToSec(extendedBolus.date);
if (extendedBolus.source == Source.PUMP) { if (extendedBolus.source == Source.PUMP) {
// check for changed from pump change in NS // if pumpId == 0 do not check for existing pumpId
QueryBuilder<ExtendedBolus, Long> queryBuilder = getDaoExtendedBolus().queryBuilder(); // used with pumps without history
Where where = queryBuilder.where(); // and insight where record as added first without pumpId
where.eq("pumpId", extendedBolus.pumpId); // and then is record updated with pumpId
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare(); if (extendedBolus.pumpId == 0) {
List<ExtendedBolus> trList = getDaoExtendedBolus().query(preparedQuery); getDaoExtendedBolus().createOrUpdate(extendedBolus);
if (trList.size() > 0) { } else {
// do nothing, pump history record cannot be changed QueryBuilder<ExtendedBolus, Long> queryBuilder = getDaoExtendedBolus().queryBuilder();
return false; Where where = queryBuilder.where();
where.eq("pumpId", extendedBolus.pumpId);
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
List<ExtendedBolus> trList = getDaoExtendedBolus().query(preparedQuery);
if (trList.size() > 0) {
log.error("EXTENDEDBOLUS: Multiple records found for pumpId: " + extendedBolus.pumpId);
return false;
}
getDaoExtendedBolus().createOrUpdate(extendedBolus);
} }
getDaoExtendedBolus().create(extendedBolus);
if (L.isEnabled(L.DATABASE)) if (L.isEnabled(L.DATABASE))
log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.toString()); log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.toString());
updateEarliestDataChange(extendedBolus.date); updateEarliestDataChange(extendedBolus.date);