tempbasal & extendedbolus 3way sync

This commit is contained in:
Milos Kozak 2017-06-08 18:15:17 +02:00
parent 4d30ba9cdb
commit 1153c33200
31 changed files with 581 additions and 325 deletions

View file

@ -463,24 +463,18 @@ public class DataService extends IntentService {
public void handleAddChangeTempTargetRecord(JSONObject trJson) throws JSONException {
if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.TEMPORARYTARGET)) {
if (Config.logIncommingData)
log.debug("Processing TempTarget record: " + trJson.toString());
MainApp.getDbHelper().createTemptargetFromJsonIfNotExists(trJson);
}
}
public void handleAddChangeTempBasalRecord(JSONObject trJson) throws JSONException {
if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.TEMPBASAL)) {
if (Config.logIncommingData)
log.debug("Processing TempBasal record: " + trJson.toString());
MainApp.getDbHelper().createTempBasalFromJsonIfNotExists(trJson);
}
}
public void handleAddChangeExtendedBolusRecord(JSONObject trJson) throws JSONException {
if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.COMBOBOLUS)) {
if (Config.logIncommingData)
log.debug("Processing Extended Bolus record: " + trJson.toString());
MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(trJson);
}
}

View file

@ -28,6 +28,5 @@ public class DetailedBolusInfo {
public JSONObject boluscalc = null; // additional bolus wizard info
public Context context = null; // context for progress dialog
public boolean addToTreatments = true;
public boolean recordFromHistory = false; // true if record is comming from pump history (not a newly created treatment)
public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment)
}

View file

@ -87,6 +87,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
onCreate(getWritableDatabase(), getConnectionSource());
//onUpgrade(getWritableDatabase(), getConnectionSource(), 1,1);
}
@Override
@ -673,7 +674,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void createTreatmentFromJsonIfNotExists(JSONObject trJson) {
try {
Treatment treatment = new Treatment();
;
treatment.source = Source.NIGHTSCOUT;
treatment.date = roundDateToSec(trJson.getLong("mills"));
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
@ -881,15 +881,85 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
// ------------ TemporaryBasal handling ---------------
public void createOrUpdate(TemporaryBasal tempBasal) {
tempBasal.date = tempBasal.date - tempBasal.date % 1000;
//return true if new record was created
public boolean createOrUpdate(TemporaryBasal tempBasal) {
try {
getDaoTemporaryBasal().createOrUpdate(tempBasal);
updateEarliestDataChange(tempBasal.date);
TemporaryBasal old;
tempBasal.date = roundDateToSec(tempBasal.date);
if (tempBasal.source == Source.PUMP) {
// check for changed from pump change in NS
QueryBuilder<TemporaryBasal, Long> queryBuilder = getDaoTemporaryBasal().queryBuilder();
Where where = queryBuilder.where();
where.eq("pumpId", tempBasal.pumpId);
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
List<TemporaryBasal> trList = getDaoTemporaryBasal().query(preparedQuery);
if (trList.size() > 0) {
// do nothing, pump history record cannot be changed
log.debug("TEMPBASAL: Already exists from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
return false;
}
getDaoTemporaryBasal().create(tempBasal);
log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
updateEarliestDataChange(tempBasal.date);
scheduleTemporaryBasalChange();
return true;
}
if (tempBasal.source == Source.NIGHTSCOUT) {
old = getDaoTemporaryBasal().queryForId(tempBasal.date);
if (old != null) {
if (!old.isEqual(tempBasal)) {
long oldDate = old.date;
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
old.copyFrom(tempBasal);
getDaoTemporaryBasal().create(old);
log.debug("TEMPBASAL: Updating record by date from: " + Source.getString(tempBasal.source) + " " + old.toString());
updateEarliestDataChange(oldDate);
updateEarliestDataChange(old.date);
scheduleTemporaryBasalChange();
return true;
}
return false;
}
// find by NS _id
if (tempBasal._id != null) {
QueryBuilder<TemporaryBasal, Long> queryBuilder = getDaoTemporaryBasal().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", tempBasal._id);
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
List<TemporaryBasal> trList = getDaoTemporaryBasal().query(preparedQuery);
if (trList.size() > 0) {
old = trList.get(0);
if (!old.isEqual(tempBasal)) {
long oldDate = old.date;
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
old.copyFrom(tempBasal);
getDaoTemporaryBasal().create(old);
log.debug("TEMPBASAL: Updating record by _id from: " + Source.getString(tempBasal.source) + " " + old.toString());
updateEarliestDataChange(oldDate);
updateEarliestDataChange(old.date);
scheduleTemporaryBasalChange();
return true;
}
}
}
getDaoTemporaryBasal().create(tempBasal);
log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
updateEarliestDataChange(tempBasal.date);
scheduleTemporaryBasalChange();
return true;
}
if (tempBasal.source == Source.USER) {
getDaoTemporaryBasal().create(tempBasal);
log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
updateEarliestDataChange(tempBasal.date);
scheduleTemporaryBasalChange();
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
scheduleTemporaryBasalChange();
return false;
}
public void delete(TemporaryBasal tempBasal) {
@ -919,23 +989,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
@Nullable
public TemporaryBasal findTempBasalByTime(Long timeIndex) {
public TemporaryBasal findTempBasalByTime(long date) {
try {
QueryBuilder<TemporaryBasal, String> qb = null;
Dao<TemporaryBasal, Long> daoTemporaryBasal = getDaoTemporaryBasal();
QueryBuilder<TemporaryBasal, Long> queryBuilder = daoTemporaryBasal.queryBuilder();
Where where = queryBuilder.where();
where.eq("date", timeIndex);
queryBuilder.limit(10L);
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
List<TemporaryBasal> trList = daoTemporaryBasal.query(preparedQuery);
if (trList.size() != 1) {
//log.debug("TemporaryBasal findTempBasalByTime query size: " + trList.size());
return null;
} else {
//log.debug("TemporaryBasal findTempBasalByTime found: " + trList.get(0).log());
return trList.get(0);
}
return getDaoTemporaryBasal().queryForId(date);
} catch (SQLException e) {
e.printStackTrace();
}
@ -983,82 +1039,28 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void createTempBasalFromJsonIfNotExists(JSONObject trJson) {
try {
if (trJson.has("originalExtendedAmount")) { // extended bolus uploaded as temp basal
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
queryBuilder = getDaoExtendedBolus().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
List<ExtendedBolus> list = getDaoExtendedBolus().query(preparedQuery);
ExtendedBolus extendedBolus;
if (list.size() == 0) {
extendedBolus = new ExtendedBolus();
extendedBolus.source = Source.NIGHTSCOUT;
if (Config.logIncommingData)
log.debug("Adding ExtendedBolus record to database: " + trJson.toString());
// Record does not exists. add
} else if (list.size() == 1) {
extendedBolus = list.get(0);
if (Config.logIncommingData)
log.debug("Updating ExtendedBolus record in database: " + trJson.toString());
} else {
log.error("Something went wrong");
return;
}
ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.source = Source.NIGHTSCOUT;
extendedBolus.date = trJson.getLong("mills");
extendedBolus.pumpId = trJson.has("pumpId") ? trJson.getLong("pumpId") : 0;
extendedBolus.durationInMinutes = trJson.getInt("duration");
extendedBolus.insulin = trJson.getDouble("originalExtendedAmount");
extendedBolus._id = trJson.getString("_id");
createOrUpdate(extendedBolus);
} else if (trJson.has("isFakedTempBasal")) { // extended bolus end uploaded as temp basal end
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
queryBuilder = getDaoExtendedBolus().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
List<ExtendedBolus> list = getDaoExtendedBolus().query(preparedQuery);
ExtendedBolus extendedBolus;
if (list.size() == 0) {
extendedBolus = new ExtendedBolus();
extendedBolus.source = Source.NIGHTSCOUT;
if (Config.logIncommingData)
log.debug("Adding ExtendedBolus record to database: " + trJson.toString());
// Record does not exists. add
} else if (list.size() == 1) {
extendedBolus = list.get(0);
if (Config.logIncommingData)
log.debug("Updating ExtendedBolus record in database: " + trJson.toString());
} else {
log.error("Something went wrong");
return;
}
ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.source = Source.NIGHTSCOUT;
extendedBolus.date = trJson.getLong("mills");
extendedBolus.pumpId = trJson.has("pumpId") ? trJson.getLong("pumpId") : 0;
extendedBolus.durationInMinutes = 0;
extendedBolus.insulin = 0;
extendedBolus._id = trJson.getString("_id");
createOrUpdate(extendedBolus);
} else {
QueryBuilder<TemporaryBasal, Long> queryBuilder = null;
queryBuilder = getDaoTemporaryBasal().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
List<TemporaryBasal> list = getDaoTemporaryBasal().query(preparedQuery);
TemporaryBasal tempBasal;
if (list.size() == 0) {
tempBasal = new TemporaryBasal();
tempBasal.source = Source.NIGHTSCOUT;
if (Config.logIncommingData)
log.debug("Adding TemporaryBasal record to database: " + trJson.toString());
// Record does not exists. add
} else if (list.size() == 1) {
tempBasal = list.get(0);
if (Config.logIncommingData)
log.debug("Updating TemporaryBasal record in database: " + trJson.toString());
} else {
log.error("Something went wrong");
return;
}
TemporaryBasal tempBasal = new TemporaryBasal();
tempBasal.date = trJson.getLong("mills");
tempBasal.source = Source.NIGHTSCOUT;
tempBasal.pumpId = trJson.has("pumpId") ? trJson.getLong("pumpId") : 0;
if (trJson.has("duration")) {
tempBasal.durationInMinutes = trJson.getInt("duration");
}
@ -1073,12 +1075,22 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
tempBasal._id = trJson.getString("_id");
createOrUpdate(tempBasal);
}
} catch (SQLException | JSONException e) {
} catch (JSONException e) {
e.printStackTrace();
}
}
public void deleteTempBasalById(String _id) {
TemporaryBasal stored = findTempBasalById(_id);
if (stored != null) {
log.debug("TEMPBASAL: Removing TempBasal record from database: " + stored.toString());
delete(stored);
updateEarliestDataChange(stored.date);
scheduleTemporaryBasalChange();
}
}
public TemporaryBasal findTempBasalById(String _id) {
try {
QueryBuilder<TemporaryBasal, Long> queryBuilder = null;
queryBuilder = getDaoTemporaryBasal().queryBuilder();
@ -1087,31 +1099,96 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
List<TemporaryBasal> list = getDaoTemporaryBasal().query(preparedQuery);
if (list.size() == 1) {
TemporaryBasal record = list.get(0);
if (Config.logIncommingData)
log.debug("Removing TempBasal record from database: " + record.log());
delete(record);
if (list.size() != 1) {
return null;
} else {
if (Config.logIncommingData)
log.debug("TempBasal not found database: " + _id);
return list.get(0);
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
// ------------ ExtendedBolus handling ---------------
public void createOrUpdate(ExtendedBolus extendedBolus) {
extendedBolus.date = extendedBolus.date - extendedBolus.date % 1000;
public boolean createOrUpdate(ExtendedBolus extendedBolus) {
try {
getDaoExtendedBolus().createOrUpdate(extendedBolus);
updateEarliestDataChange(extendedBolus.date);
ExtendedBolus old;
extendedBolus.date = roundDateToSec(extendedBolus.date);
if (extendedBolus.source == Source.PUMP) {
// check for changed from pump change in NS
QueryBuilder<ExtendedBolus, Long> queryBuilder = getDaoExtendedBolus().queryBuilder();
Where where = queryBuilder.where();
where.eq("pumpId", extendedBolus.pumpId);
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
List<ExtendedBolus> trList = getDaoExtendedBolus().query(preparedQuery);
if (trList.size() > 0) {
// do nothing, pump history record cannot be changed
return false;
}
getDaoExtendedBolus().create(extendedBolus);
log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.toString());
updateEarliestDataChange(extendedBolus.date);
scheduleTreatmentChange();
return true;
}
if (extendedBolus.source == Source.NIGHTSCOUT) {
old = getDaoExtendedBolus().queryForId(extendedBolus.date);
if (old != null) {
if (!old.isEqual(extendedBolus)) {
long oldDate = old.date;
getDaoExtendedBolus().delete(old); // need to delete/create because date may change too
old.copyFrom(extendedBolus);
getDaoExtendedBolus().create(old);
log.debug("EXTENDEDBOLUS: Updating record by date from: " + Source.getString(extendedBolus.source) + " " + old.toString());
updateEarliestDataChange(oldDate);
updateEarliestDataChange(old.date);
scheduleTreatmentChange();
return true;
}
return false;
}
// find by NS _id
if (extendedBolus._id != null) {
QueryBuilder<ExtendedBolus, Long> queryBuilder = getDaoExtendedBolus().queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", extendedBolus._id);
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
List<ExtendedBolus> trList = getDaoExtendedBolus().query(preparedQuery);
if (trList.size() > 0) {
old = trList.get(0);
if (!old.isEqual(extendedBolus)) {
long oldDate = old.date;
getDaoExtendedBolus().delete(old); // need to delete/create because date may change too
old.copyFrom(extendedBolus);
getDaoExtendedBolus().create(old);
log.debug("EXTENDEDBOLUS: Updating record by _id from: " + Source.getString(extendedBolus.source) + " " + old.toString());
updateEarliestDataChange(oldDate);
updateEarliestDataChange(old.date);
scheduleTreatmentChange();
return true;
}
}
}
getDaoExtendedBolus().create(extendedBolus);
log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.toString());
updateEarliestDataChange(extendedBolus.date);
scheduleTreatmentChange();
return true;
}
if (extendedBolus.source == Source.USER) {
getDaoExtendedBolus().create(extendedBolus);
log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.toString());
updateEarliestDataChange(extendedBolus.date);
scheduleTreatmentChange();
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
scheduleExtendedBolusChange();
return false;
}
public void delete(ExtendedBolus extendedBolus) {

View file

@ -13,15 +13,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.Objects;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
import info.nightscout.utils.DateUtil;
@ -42,6 +43,9 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
@DatabaseField
public boolean isValid = true;
@DatabaseField(index = true)
public long pumpId = 0;
@DatabaseField
public int source = Source.NONE;
@DatabaseField
@ -57,6 +61,35 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
@DatabaseField
public double dia = Constants.defaultDIA;
public ExtendedBolus() {
}
public ExtendedBolus(long date) {
this.date = date;
}
public boolean isEqual(ExtendedBolus other) {
if (date != other.date) {
return false;
}
if (durationInMinutes != other.durationInMinutes)
return false;
if (insulin != other.insulin)
return false;
if (pumpId != other.pumpId)
return false;
if (!Objects.equals(_id, other._id))
return false;
return true;
}
public void copyFrom(ExtendedBolus t) {
date = t.date;
_id = t._id;
durationInMinutes = t.durationInMinutes;
insulin = t.insulin;
pumpId = t.pumpId;
}
// -------- Interval interface ---------
@ -122,6 +155,7 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
", date= " + DateUtil.dateAndTimeString(date) +
", isValid=" + isValid +
", _id= " + _id +
", pumpId= " + pumpId +
", insulin= " + insulin +
", durationInMinutes= " + durationInMinutes +
"}";

View file

@ -7,14 +7,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.Objects;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -32,6 +33,9 @@ public class TemporaryBasal implements Interval {
@DatabaseField
public boolean isValid = true;
@DatabaseField(index = true)
public long pumpId = 0;
@DatabaseField
public int source = Source.NONE;
@DatabaseField
@ -49,6 +53,10 @@ public class TemporaryBasal implements Interval {
public TemporaryBasal() {
}
public TemporaryBasal(long date) {
this.date = date;
}
public TemporaryBasal(ExtendedBolus extendedBolus) {
double basal = MainApp.getConfigBuilder().getProfile(extendedBolus.date).getBasal(extendedBolus.date);
this.date = extendedBolus.date;
@ -66,6 +74,7 @@ public class TemporaryBasal implements Interval {
t.isValid = isValid;
t.source = source;
t._id = _id;
t.pumpId = pumpId;
t.durationInMinutes = durationInMinutes;
t.isAbsolute = isAbsolute;
t.percentRate = percentRate;
@ -73,6 +82,35 @@ public class TemporaryBasal implements Interval {
return t;
}
public boolean isEqual(TemporaryBasal other) {
if (date != other.date) {
return false;
}
if (durationInMinutes != other.durationInMinutes)
return false;
if (isAbsolute != other.isAbsolute)
return false;
if (percentRate != other.percentRate)
return false;
if (absoluteRate != other.absoluteRate)
return false;
if (pumpId != other.pumpId)
return false;
if (!Objects.equals(_id, other._id))
return false;
return true;
}
public void copyFrom(TemporaryBasal t) {
date = t.date;
_id = t._id;
durationInMinutes = t.durationInMinutes;
isAbsolute = t.isAbsolute;
percentRate = t.percentRate;
absoluteRate = t.absoluteRate;
pumpId = t.pumpId;
}
// -------- Interval interface ---------
Long cuttedEnd = null;
@ -205,11 +243,12 @@ public class TemporaryBasal implements Interval {
}
}
public String log() {
public String toString() {
return "TemporaryBasal{" +
"date=" + date +
", date=" + DateUtil.dateAndTimeString(date) +
", isValid=" + isValid +
", pumpId=" + pumpId +
", _id=" + _id +
", percentRate=" + percentRate +
", absoluteRate=" + absoluteRate +
@ -218,7 +257,7 @@ public class TemporaryBasal implements Interval {
'}';
}
public String toString() {
public String toStringFull() {
if (isAbsolute) {
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h @" +
DateUtil.timeString(date) +

View file

@ -56,6 +56,10 @@ public class Treatment implements DataPointWithLabelInterface {
public Treatment() {
}
public Treatment(long date) {
this.date = date;
}
public Treatment(InsulinInterface insulin) {
insulinInterfaceID = insulin.getId();
dia = insulin.getDia();

View file

@ -35,8 +35,7 @@ public interface TreatmentsInterface {
boolean isInHistoryRealTempBasalInProgress();
TemporaryBasal getRealTempBasalFromHistory(long time);
void addToHistoryTempBasalStart(TemporaryBasal tempBasal);
void addToHistoryTempBasalStop(long time);
boolean addToHistoryTempBasal(TemporaryBasal tempBasal);
// basal that can be faked by extended boluses
boolean isTempBasalInProgress();
@ -47,10 +46,10 @@ public interface TreatmentsInterface {
boolean isInHistoryExtendedBoluslInProgress();
ExtendedBolus getExtendedBolusFromHistory(long time);
void addToHistoryExtendedBolusStart(ExtendedBolus extendedBolus);
void addToHistoryExtendedBolusStop(long time);
OverlappingIntervals<ExtendedBolus> getExtendedBolusesFromHistory();
boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus);
boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo);
TempTarget getTempTargetFromHistory(long time);

View file

@ -57,22 +57,22 @@ import info.nightscout.utils.NSUpload;
public class ConfigBuilderPlugin implements PluginBase, PumpInterface, ConstraintsInterface, TreatmentsInterface {
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
static BgSourceInterface activeBgSource;
static PumpInterface activePump;
static ProfileInterface activeProfile;
static TreatmentsInterface activeTreatments;
static APSInterface activeAPS;
static LoopPlugin activeLoop;
static InsulinInterface activeInsulin;
private static BgSourceInterface activeBgSource;
private static PumpInterface activePump;
private static ProfileInterface activeProfile;
private static TreatmentsInterface activeTreatments;
private static APSInterface activeAPS;
private static LoopPlugin activeLoop;
private static InsulinInterface activeInsulin;
static public String nightscoutVersionName = "";
static public Integer nightscoutVersionCode = 0;
static public String nsClientVersionName = "";
static public Integer nsClientVersionCode = 0;
static ArrayList<PluginBase> pluginList;
private static ArrayList<PluginBase> pluginList;
PowerManager.WakeLock mWakeLock;
private PowerManager.WakeLock mWakeLock;
public ConfigBuilderPlugin() {
MainApp.bus().register(this);
@ -109,12 +109,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
@Override
public boolean isEnabled(int type) {
return type == GENERAL && true;
return type == GENERAL;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL && true;
return type == GENERAL;
}
@Override
@ -208,7 +208,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
return activeLoop;
}
public void logPluginStatus() {
void logPluginStatus() {
for (PluginBase p : pluginList) {
log.debug(p.getName() + ":" +
(p.isEnabled(1) ? " GENERAL" : "") +
@ -405,43 +405,44 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
else
return 0d;
}
/*
public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
mWakeLock.acquire();
PumpEnactResult result;
insulin = applyBolusConstraints(insulin);
carbs = applyCarbsConstraints(carbs);
BolusProgressDialog bolusProgressDialog = null;
if (context != null) {
bolusProgressDialog = new BolusProgressDialog();
bolusProgressDialog.setInsulin(insulin);
bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress");
/*
public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
mWakeLock.acquire();
PumpEnactResult result;
insulin = applyBolusConstraints(insulin);
carbs = applyCarbsConstraints(carbs);
BolusProgressDialog bolusProgressDialog = null;
if (context != null) {
bolusProgressDialog = new BolusProgressDialog();
bolusProgressDialog.setInsulin(insulin);
bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress");
}
MainApp.bus().post(new EventBolusRequested(insulin));
result = activePump.deliverTreatment(insulinType, insulin, carbs, context);
BolusProgressDialog.bolusEnded = true;
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
if (result.success) {
Treatment t = new Treatment(insulinType);
t.insulin = result.bolusDelivered;
if (carbTime == 0)
t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout
t.date = new Date().getTime();
t.mealBolus = result.carbsDelivered > 0;
addToHistoryTreatment(t);
t.carbs = (double) result.carbsDelivered;
NSUpload.uploadBolusWizardRecord(t, glucose, glucoseType, carbTime, boluscalc);
}
mWakeLock.release();
return result;
}
MainApp.bus().post(new EventBolusRequested(insulin));
result = activePump.deliverTreatment(insulinType, insulin, carbs, context);
BolusProgressDialog.bolusEnded = true;
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
if (result.success) {
Treatment t = new Treatment(insulinType);
t.insulin = result.bolusDelivered;
if (carbTime == 0)
t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout
t.date = new Date().getTime();
t.mealBolus = result.carbsDelivered > 0;
addToHistoryTreatment(t);
t.carbs = (double) result.carbsDelivered;
NSUpload.uploadBolusWizardRecord(t, glucose, glucoseType, carbTime, boluscalc);
}
mWakeLock.release();
return result;
}
*/
*/
@Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
mWakeLock.acquire();
@ -466,56 +467,57 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
mWakeLock.release();
return result;
}
/*
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
return deliverTreatment(insulinType, insulin, carbs, context, true);
}
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context, boolean createTreatment) {
mWakeLock.acquire();
PumpEnactResult result;
insulin = applyBolusConstraints(insulin);
carbs = applyCarbsConstraints(carbs);
BolusProgressDialog bolusProgressDialog = null;
if (context != null) {
bolusProgressDialog = new BolusProgressDialog();
bolusProgressDialog.setInsulin(insulin);
bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress");
} else {
Intent i = new Intent();
i.putExtra("insulin", insulin.doubleValue());
i.setClass(MainApp.instance(), BolusProgressHelperActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
/*
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
return deliverTreatment(insulinType, insulin, carbs, context, true);
}
MainApp.bus().post(new EventBolusRequested(insulin));
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context, boolean createTreatment) {
mWakeLock.acquire();
PumpEnactResult result;
insulin = applyBolusConstraints(insulin);
carbs = applyCarbsConstraints(carbs);
result = activePump.deliverTreatment(insulinType, insulin, carbs, context);
BolusProgressDialog bolusProgressDialog = null;
if (context != null) {
bolusProgressDialog = new BolusProgressDialog();
bolusProgressDialog.setInsulin(insulin);
bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress");
} else {
Intent i = new Intent();
i.putExtra("insulin", insulin.doubleValue());
i.setClass(MainApp.instance(), BolusProgressHelperActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
BolusProgressDialog.bolusEnded = true;
MainApp.bus().post(new EventBolusRequested(insulin));
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
result = activePump.deliverTreatment(insulinType, insulin, carbs, context);
if (Config.logCongigBuilderActions)
log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
BolusProgressDialog.bolusEnded = true;
if (result.success && createTreatment) {
Treatment t = new Treatment(insulinType);
t.insulin = result.bolusDelivered;
t.carbs = (double) result.carbsDelivered;
t.date = new Date().getTime();
t.mealBolus = t.carbs > 0;
addToHistoryTreatment(t);
NSUpload.uploadTreatment(t);
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
if (Config.logCongigBuilderActions)
log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
if (result.success && createTreatment) {
Treatment t = new Treatment(insulinType);
t.insulin = result.bolusDelivered;
t.carbs = (double) result.carbsDelivered;
t.date = new Date().getTime();
t.mealBolus = t.carbs > 0;
addToHistoryTreatment(t);
NSUpload.uploadTreatment(t);
}
mWakeLock.release();
return result;
}
mWakeLock.release();
return result;
}
*/
*/
@Override
public void stopBolusDelivering() {
activePump.stopBolusDelivering();
@ -887,19 +889,17 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public void addToHistoryTempBasalStart(TemporaryBasal tempBasal) {
activeTreatments.addToHistoryTempBasalStart(tempBasal);
if (tempBasal.isAbsolute)
NSUpload.uploadTempBasalStartAbsolute(tempBasal, null);
else
NSUpload.uploadTempBasalStartPercent(tempBasal);
}
@Override
public void addToHistoryTempBasalStop(long time) {
activeTreatments.addToHistoryTempBasalStop(time);
NSUpload.uploadTempBasalEnd(time, false);
public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) {
boolean newRecordCreated = activeTreatments.addToHistoryTempBasal(tempBasal);
if (newRecordCreated) {
if (tempBasal.durationInMinutes == 0)
NSUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId);
else if (tempBasal.isAbsolute)
NSUpload.uploadTempBasalStartAbsolute(tempBasal, null);
else
NSUpload.uploadTempBasalStartPercent(tempBasal);
}
return newRecordCreated;
}
@Override
@ -914,21 +914,20 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public void addToHistoryExtendedBolusStart(ExtendedBolus extendedBolus) {
activeTreatments.addToHistoryExtendedBolusStart(extendedBolus);
if (activePump.isFakingTempsByExtendedBoluses())
NSUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin);
else
NSUpload.uploadExtendedBolus(extendedBolus);
}
@Override
public void addToHistoryExtendedBolusStop(long time) {
activeTreatments.addToHistoryExtendedBolusStop(time);
if (activePump.isFakingTempsByExtendedBoluses())
NSUpload.uploadTempBasalEnd(time, true);
else
NSUpload.uploadExtendedBolusEnd(time);
public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) {
boolean newRecordCreated = activeTreatments.addToHistoryExtendedBolus(extendedBolus);
if (newRecordCreated) {
if (extendedBolus.durationInMinutes == 0) {
if (activePump.isFakingTempsByExtendedBoluses())
NSUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId);
else
NSUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId);
} else if (activePump.isFakingTempsByExtendedBoluses())
NSUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin);
else
NSUpload.uploadExtendedBolus(extendedBolus);
}
return newRecordCreated;
}
@Override
@ -983,6 +982,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
public String getProfileName() {
return getProfileName(new Date().getTime());
}
public String getProfileName(long time) {
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time);
if (profileSwitch != null) {
@ -999,12 +999,13 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
if (defaultProfile != null)
return defaultProfile;
// If default from plugin fails .... create empty
return "Default";
return "Default";
}
public Profile getProfile() {
return getProfile(new Date().getTime());
}
public Profile getProfile(long time) {
//log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time));
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time);

View file

@ -996,7 +996,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
String basalText = "";
if (activeTemp != null) {
basalText = activeTemp.toString() + " ";
basalText = activeTemp.toStringFull() + " ";
}
if (Config.NSCLIENT)
basalText += "( " + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h )";

View file

@ -230,7 +230,7 @@ public class DanaRFragment extends Fragment {
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toString());
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toStringFull());
} else {
tempBasalView.setText("");
}

View file

@ -805,7 +805,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
}
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toString() + "\n";
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toStringFull() + "\n";
}
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolusFromHistory(new Date().getTime()).toString() + "\n";

View file

@ -10,6 +10,7 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -73,17 +74,21 @@ public class MsgStatusBolusExtended extends MessageBase {
if (pump.isExtendedInProgress) {
if (extendedBolus.absoluteRate() != pump.extendedBolusAbsoluteRate) {
// Close current extended
treatmentsInterface.addToHistoryExtendedBolusStop(now - 1000);
ExtendedBolus exStop = new ExtendedBolus(now - 1000);
exStop.source = Source.USER;
treatmentsInterface.addToHistoryExtendedBolus(exStop);
// Create new
ExtendedBolus newExtended = new ExtendedBolus();
newExtended.date = new Date(now).getTime();
newExtended.insulin = pump.extendedBolusAmount;
newExtended.durationInMinutes = pump.extendedBolusMinutes;
treatmentsInterface.addToHistoryExtendedBolusStart(newExtended);
treatmentsInterface.addToHistoryExtendedBolus(newExtended);
}
} else {
// Close curent temp basal
treatmentsInterface.addToHistoryExtendedBolusStop(now);
ExtendedBolus exStop = new ExtendedBolus(now);
exStop.source = Source.USER;
treatmentsInterface.addToHistoryExtendedBolus(exStop);
}
} else {
if (pump.isExtendedInProgress) {
@ -92,7 +97,7 @@ public class MsgStatusBolusExtended extends MessageBase {
newExtended.date = new Date(now).getTime();
newExtended.insulin = pump.extendedBolusAmount;
newExtended.durationInMinutes = pump.extendedBolusMinutes;
treatmentsInterface.addToHistoryExtendedBolusStart(newExtended);
treatmentsInterface.addToHistoryExtendedBolus(newExtended);
}
}
}

View file

@ -9,6 +9,7 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -67,18 +68,23 @@ public class MsgStatusTempBasal extends MessageBase {
if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percentRate != danaRPump.tempBasalPercent) {
// Close current temp basal
treatmentsInterface.addToHistoryTempBasalStop(now - 1000);
TemporaryBasal tempStop = new TemporaryBasal(now - 1000);
tempStop.source = Source.USER;
treatmentsInterface.addToHistoryTempBasal(tempStop);
// Create new
TemporaryBasal newTempBasal = new TemporaryBasal();
newTempBasal.date = new Date(now).getTime();
newTempBasal.percentRate = danaRPump.tempBasalPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = danaRPump.tempBasalTotalSec / 60;
treatmentsInterface.addToHistoryTempBasalStart(newTempBasal);
newTempBasal.source = Source.USER;
treatmentsInterface.addToHistoryTempBasal(newTempBasal);
}
} else {
// Close current temp basal
treatmentsInterface.addToHistoryTempBasalStop(now);
TemporaryBasal tempStop = new TemporaryBasal(now);
tempStop.source = Source.USER;
treatmentsInterface.addToHistoryTempBasal(tempStop);
}
} else {
if (danaRPump.isTempBasalInProgress) {
@ -88,7 +94,8 @@ public class MsgStatusTempBasal extends MessageBase {
newTempBasal.percentRate = danaRPump.tempBasalPercent;
newTempBasal.isAbsolute = false;
newTempBasal.durationInMinutes = danaRPump.tempBasalTotalSec / 60;
treatmentsInterface.addToHistoryTempBasalStart(newTempBasal);
newTempBasal.source = Source.USER;
treatmentsInterface.addToHistoryTempBasal(newTempBasal);
}
}
}

View file

@ -229,7 +229,7 @@ public class DanaRKoreanFragment extends Fragment {
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h");
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toString());
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toStringFull());
} else {
tempBasalView.setText("");
}

View file

@ -809,7 +809,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
}
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toString() + "\n";
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasalFromHistory(new Date().getTime()).toStringFull() + "\n";
}
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolusFromHistory(new Date().getTime()).toString() + "\n";

View file

@ -227,7 +227,7 @@ public class DanaRv2Fragment extends Fragment {
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(new Date().getTime()).toString());
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(new Date().getTime()).toStringFull());
} else {
tempBasalView.setText("");
}

View file

@ -723,7 +723,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
}
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getTempBasalFromHistory(new Date().getTime()).toString() + "\n";
ret += "Temp: " + MainApp.getConfigBuilder().getTempBasalFromHistory(new Date().getTime()).toStringFull() + "\n";
}
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolusFromHistory(new Date().getTime()).toString() + "\n";

View file

@ -11,7 +11,6 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
@ -53,77 +52,61 @@ public class MsgHistoryEvents_v2 extends MessageBase {
int param1 = intFromBuff(bytes, 7, 2);
int param2 = intFromBuff(bytes, 9, 2);
TemporaryBasal temporaryBasal = MainApp.getDbHelper().findTempBasalByTime(datetime.getTime());
if (temporaryBasal != null) {
log.debug("EVENT (" + recordCode + ") " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
log.debug("Existing temporaryBasal found. Skipping ...");
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
return;
}
temporaryBasal = new TemporaryBasal();
TemporaryBasal temporaryBasal = new TemporaryBasal();
temporaryBasal.date = datetime.getTime();
temporaryBasal.source = Source.PUMP;
temporaryBasal.pumpId = datetime.getTime();
ExtendedBolus extendedBolus = MainApp.getDbHelper().findExtendedBolusByTime(datetime.getTime());
if (extendedBolus != null) {
log.debug("EVENT (" + recordCode + ") " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
log.debug("Existing extendedBolus found. Skipping ...");
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
return;
}
extendedBolus = new ExtendedBolus();
ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.date = datetime.getTime();
extendedBolus.source = Source.PUMP;
extendedBolus.pumpId = datetime.getTime();
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.recordFromHistory = true;
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime();
switch (recordCode) {
case DanaRPump.TEMPSTART:
log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " Ratio: " + param1 + "% Duration: " + param2 + "min");
temporaryBasal.date = datetime.getTime();
temporaryBasal.percentRate = param1;
temporaryBasal.durationInMinutes = param2;
MainApp.getConfigBuilder().addToHistoryTempBasalStart(temporaryBasal);
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
break;
case DanaRPump.TEMPSTOP:
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString());
MainApp.getConfigBuilder().addToHistoryTempBasalStop(datetime.getTime());
MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal);
break;
case DanaRPump.EXTENDEDSTART:
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.date = datetime.getTime();
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus);
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
break;
case DanaRPump.EXTENDEDSTOP:
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
MainApp.getConfigBuilder().addToHistoryExtendedBolusStop(datetime.getTime());
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
break;
case DanaRPump.BOLUS:
log.debug("EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.insulin = param1 / 100d;
detailedBolusInfo.source = Source.PUMP;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
break;
case DanaRPump.DUALBOLUS:
log.debug("EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.insulin = param1 / 100d;
detailedBolusInfo.source = Source.PUMP;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
break;
case DanaRPump.DUALEXTENDEDSTART:
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.date = datetime.getTime();
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus);
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
break;
case DanaRPump.DUALEXTENDEDSTOP:
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
MainApp.getConfigBuilder().addToHistoryExtendedBolusStop(datetime.getTime());
MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus);
break;
case DanaRPump.SUSPENDON:
log.debug("EVENT SUSPENDON (" + recordCode + ") " + datetime.toLocaleString());
@ -142,9 +125,7 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break;
case DanaRPump.CARBS:
log.debug("EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.carbs = param1;
detailedBolusInfo.source = Source.PUMP;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
break;
default:
@ -155,6 +136,5 @@ public class MsgHistoryEvents_v2 extends MessageBase {
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
return;
}
}

View file

@ -89,7 +89,7 @@ public class VirtualPumpFragment extends Fragment {
basaBasalRateView.setText(VirtualPumpPlugin.getInstance().getBaseBasalRate() + "U");
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(new Date().getTime()).toString());
tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(new Date().getTime()).toStringFull());
} else {
tempBasalView.setText("");
}

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
@ -242,6 +243,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
tempBasal.isAbsolute = true;
tempBasal.absoluteRate = absoluteRate;
tempBasal.durationInMinutes = durationInMinutes;
tempBasal.source = Source.USER;
PumpEnactResult result = new PumpEnactResult();
result.success = true;
result.enacted = true;
@ -249,7 +251,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
result.absolute = absoluteRate;
result.duration = durationInMinutes;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
treatmentsInterface.addToHistoryTempBasalStart(tempBasal);
treatmentsInterface.addToHistoryTempBasal(tempBasal);
if (Config.logPumpComm)
log.debug("Setting temp basal absolute: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
@ -271,6 +273,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
tempBasal.isAbsolute = false;
tempBasal.percentRate = percent;
tempBasal.durationInMinutes = durationInMinutes;
tempBasal.source = Source.USER;
result.success = true;
result.enacted = true;
result.percent = percent;
@ -278,7 +281,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
result.isTempCancel = false;
result.duration = durationInMinutes;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
treatmentsInterface.addToHistoryTempBasalStart(tempBasal);
treatmentsInterface.addToHistoryTempBasal(tempBasal);
if (Config.logPumpComm)
log.debug("Settings temp basal percent: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
@ -296,13 +299,14 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
extendedBolus.date = new Date().getTime();
extendedBolus.insulin = insulin;
extendedBolus.durationInMinutes = durationInMinutes;
extendedBolus.source = Source.USER;
result.success = true;
result.enacted = true;
result.bolusDelivered = insulin;
result.isTempCancel = false;
result.duration = durationInMinutes;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
treatmentsInterface.addToHistoryExtendedBolusStart(extendedBolus);
treatmentsInterface.addToHistoryExtendedBolus(extendedBolus);
if (Config.logPumpComm)
log.debug("Setting extended bolus: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
@ -319,7 +323,9 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (treatmentsInterface.isTempBasalInProgress()) {
result.enacted = true;
treatmentsInterface.addToHistoryTempBasalStop(new Date().getTime());
TemporaryBasal tempStop = new TemporaryBasal(new Date().getTime());
tempStop.source = Source.USER;
treatmentsInterface.addToHistoryTempBasal(tempStop);
//tempBasal = null;
if (Config.logPumpComm)
log.debug("Canceling temp basal: " + result);
@ -334,7 +340,9 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
PumpEnactResult result = new PumpEnactResult();
if (treatmentsInterface.isInHistoryExtendedBoluslInProgress()) {
treatmentsInterface.addToHistoryExtendedBolusStop(new Date().getTime());
ExtendedBolus exStop = new ExtendedBolus(new Date().getTime());
exStop.source = Source.USER;
treatmentsInterface.addToHistoryExtendedBolus(exStop);
}
result.success = true;
result.enacted = true;

View file

@ -342,18 +342,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
@Override
public void addToHistoryExtendedBolusStart(ExtendedBolus extendedBolus) {
log.debug("Adding new ExtentedBolus record" + extendedBolus.log());
MainApp.getDbHelper().createOrUpdate(extendedBolus);
}
@Override
public void addToHistoryExtendedBolusStop(long time) {
ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.date = time;
extendedBolus.durationInMinutes = 0;
log.debug("Adding new ExtentedBolus stop record" + extendedBolus.log());
MainApp.getDbHelper().createOrUpdate(extendedBolus);
public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) {
//log.debug("Adding new ExtentedBolus record" + extendedBolus.log());
return MainApp.getDbHelper().createOrUpdate(extendedBolus);
}
@Override
@ -391,44 +382,33 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
@Override
public void addToHistoryTempBasalStart(TemporaryBasal tempBasal) {
log.debug("Adding new TemporaryBasal record" + tempBasal.log());
MainApp.getDbHelper().createOrUpdate(tempBasal);
}
@Override
public void addToHistoryTempBasalStop(long time) {
TemporaryBasal temporaryBasal = new TemporaryBasal();
temporaryBasal.date = time;
temporaryBasal.durationInMinutes = 0;
log.debug("Adding new TemporaryBasal stop record" + temporaryBasal.log());
MainApp.getDbHelper().createOrUpdate(temporaryBasal);
public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) {
//log.debug("Adding new TemporaryBasal record" + tempBasal.toString());
return MainApp.getDbHelper().createOrUpdate(tempBasal);
}
@Override
public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo) {
Treatment treatment = new Treatment(detailedBolusInfo.insulinInterface);
treatment.date = detailedBolusInfo.date;
treatment.source = detailedBolusInfo.recordFromHistory ? Source.PUMP : Source.USER;
if (detailedBolusInfo.recordFromHistory)
treatment.pumpId = treatment.date;
treatment.source = detailedBolusInfo.source;
treatment.pumpId = detailedBolusInfo.pumpId;
treatment.insulin = detailedBolusInfo.insulin;
if (detailedBolusInfo.carbTime == 0)
treatment.carbs = detailedBolusInfo.carbs;
treatment.source = detailedBolusInfo.source;
treatment.mealBolus = treatment.carbs > 0;
boolean newRecordCreated = MainApp.getDbHelper().createOrUpdate(treatment);
log.debug("Adding new Treatment record" + treatment.toString());
//log.debug("Adding new Treatment record" + treatment.toString());
if (detailedBolusInfo.carbTime != 0) {
Treatment carbsTreatment = new Treatment(detailedBolusInfo.insulinInterface);
carbsTreatment.source = detailedBolusInfo.recordFromHistory ? Source.PUMP : Source.USER;
if (detailedBolusInfo.recordFromHistory)
carbsTreatment.pumpId = treatment.date;
carbsTreatment.source = detailedBolusInfo.source;
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.carbs = detailedBolusInfo.carbs;
carbsTreatment.source = detailedBolusInfo.source;
MainApp.getDbHelper().createOrUpdate(carbsTreatment);
log.debug("Adding new Treatment record" + carbsTreatment);
//log.debug("Adding new Treatment record" + carbsTreatment);
}
return newRecordCreated;
}
@ -481,7 +461,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override
public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) {
log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
MainApp.getDbHelper().createOrUpdate(profileSwitch);
}

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.utils.DateUtil;
@ -62,6 +63,8 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
@Override
public void onBindViewHolder(ExtendedBolusesViewHolder holder, int position) {
ExtendedBolus extendedBolus = extendedBolusList.getReversed(position);
holder.ph.setVisibility(extendedBolus.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(extendedBolus._id != null ? View.VISIBLE : View.GONE);
if (extendedBolus.isEndingEvent()) {
holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date));
holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
@ -115,6 +118,8 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
TextView insulinSoFar;
TextView iob;
TextView remove;
TextView ph;
TextView ns;
ExtendedBolusesViewHolder(View itemView) {
super(itemView);
@ -126,6 +131,8 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
ratio = (TextView) itemView.findViewById(R.id.extendedboluses_ratio);
insulinSoFar = (TextView) itemView.findViewById(R.id.extendedboluses_netinsulin);
iob = (TextView) itemView.findViewById(R.id.extendedboluses_iob);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.extendedboluses_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

View file

@ -26,6 +26,7 @@ import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileIntervals;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.events.EventTempTargetChange;
@ -67,6 +68,8 @@ public class TreatmentsProfileSwitchFragment extends Fragment implements View.On
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) return;
ProfileSwitch profileSwitch = profileSwitchList.getReversed(position);
holder.ph.setVisibility(profileSwitch.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(profileSwitch._id != null ? View.VISIBLE : View.GONE);
holder.date.setText(DateUtil.dateAndTimeString(profileSwitch.date));
if (!profileSwitch.isEndingEvent()) {
@ -98,6 +101,8 @@ public class TreatmentsProfileSwitchFragment extends Fragment implements View.On
TextView duration;
TextView name;
TextView remove;
TextView ph;
TextView ns;
ProfileSwitchViewHolder(View itemView) {
super(itemView);
@ -105,6 +110,8 @@ public class TreatmentsProfileSwitchFragment extends Fragment implements View.On
date = (TextView) itemView.findViewById(R.id.profileswitch_date);
duration = (TextView) itemView.findViewById(R.id.profileswitch_duration);
name = (TextView) itemView.findViewById(R.id.profileswitch_name);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.profileswitch_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

View file

@ -23,6 +23,7 @@ import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.data.Profile;
@ -64,6 +65,8 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) return;
TempTarget tempTarget = tempTargetList.getReversed(position);
holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(tempTarget._id != null ? View.VISIBLE : View.GONE);
if (!tempTarget.isEndingEvent()) {
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTarget.originalEnd()));
holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min");
@ -106,6 +109,8 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
TextView reasonLabel;
TextView reasonColon;
TextView remove;
TextView ph;
TextView ns;
TempTargetsViewHolder(View itemView) {
super(itemView);
@ -117,6 +122,8 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
reason = (TextView) itemView.findViewById(R.id.temptargetrange_reason);
reasonLabel = (TextView) itemView.findViewById(R.id.temptargetrange_reason_label);
reasonColon = (TextView) itemView.findViewById(R.id.temptargetrange_reason_colon);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.temptargetrange_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

View file

@ -28,6 +28,7 @@ import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange;
@ -64,6 +65,8 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
@Override
public void onBindViewHolder(TempBasalsViewHolder holder, int position) {
TemporaryBasal tempBasal = tempBasalList.getReversed(position);
holder.ph.setVisibility(tempBasal.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(tempBasal._id != null ? View.VISIBLE : View.GONE);
if (tempBasal.isEndingEvent()) {
holder.date.setText(DateUtil.dateAndTimeString(tempBasal.date));
holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
@ -130,6 +133,8 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
TextView iob;
TextView extendedFlag;
TextView remove;
TextView ph;
TextView ns;
TempBasalsViewHolder(View itemView) {
super(itemView);
@ -143,6 +148,8 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
netInsulin = (TextView) itemView.findViewById(R.id.tempbasals_netinsulin);
iob = (TextView) itemView.findViewById(R.id.tempbasals_iob);
extendedFlag = (TextView) itemView.findViewById(R.id.tempbasals_extendedflag);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.tempbasals_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
@ -219,7 +226,7 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
public void updateGUI() {
Activity activity = getActivity();
if (activity != null && recyclerView != null)
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {

View file

@ -44,6 +44,8 @@ public class NSUpload {
data.put("eventType", CareportalEvent.TEMPBASAL);
data.put("duration", temporaryBasal.durationInMinutes);
data.put("absolute", temporaryBasal.absoluteRate);
if (temporaryBasal.pumpId != 0)
data.put("pumpId", temporaryBasal.pumpId);
data.put("created_at", DateUtil.toISOString(temporaryBasal.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.absoluteRate + "u/h " + temporaryBasal.durationInMinutes + " min"); // ECOR
@ -81,6 +83,8 @@ public class NSUpload {
data.put("eventType", CareportalEvent.TEMPBASAL);
data.put("duration", temporaryBasal.durationInMinutes);
data.put("percent", temporaryBasal.percentRate - 100);
if (temporaryBasal.pumpId != 0)
data.put("pumpId", temporaryBasal.pumpId);
data.put("created_at", DateUtil.toISOString(temporaryBasal.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.percentRate + "% " + temporaryBasal.durationInMinutes + " min"); // ECOR
@ -99,7 +103,7 @@ public class NSUpload {
}
}
public static void uploadTempBasalEnd(long time, boolean isFakedTempBasal) {
public static void uploadTempBasalEnd(long time, boolean isFakedTempBasal, long pumpId) {
try {
Context context = MainApp.instance().getApplicationContext();
JSONObject data = new JSONObject();
@ -109,6 +113,8 @@ public class NSUpload {
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalendnote)); // ECOR
if (isFakedTempBasal)
data.put("isFakedTempBasal", isFakedTempBasal);
if (pumpId != 0)
data.put("pumpId", pumpId);
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
@ -133,6 +139,8 @@ public class NSUpload {
data.put("splitExt", 100);
data.put("enteredinsulin", extendedBolus.insulin);
data.put("relative", extendedBolus.insulin);
if (extendedBolus.pumpId != 0)
data.put("pumpId", extendedBolus.pumpId);
data.put("created_at", DateUtil.toISOString(extendedBolus.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
Bundle bundle = new Bundle();
@ -149,7 +157,7 @@ public class NSUpload {
}
}
public static void uploadExtendedBolusEnd(long time) {
public static void uploadExtendedBolusEnd(long time, long pumpId) {
try {
Context context = MainApp.instance().getApplicationContext();
JSONObject data = new JSONObject();
@ -161,6 +169,8 @@ public class NSUpload {
data.put("relative", 0);
data.put("created_at", DateUtil.toISOString(time));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
if (pumpId != 0)
data.put("pumpId", pumpId);
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");

View file

@ -96,7 +96,6 @@
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="PH"
android:textAlignment="viewEnd"
android:textColor="@color/colorSetTempButton" />
<TextView
@ -105,7 +104,6 @@
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="NS"
android:textAlignment="viewEnd"
android:textColor="@color/colorSetTempButton" />
</LinearLayout>

View file

@ -112,6 +112,30 @@
android:paddingRight="10dp"
android:text="0.05 U"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/pump_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="PH"
android:textColor="@color/colorSetTempButton" />
<TextView
android:id="@+id/ns_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="NS"
android:textColor="@color/colorSetTempButton" />
</LinearLayout>
<LinearLayout

View file

@ -48,12 +48,34 @@
android:id="@+id/profileswitch_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="60 min"
android:textAlignment="viewEnd"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/pump_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="PH"
android:textColor="@color/colorSetTempButton" />
<TextView
android:id="@+id/ns_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="NS"
android:textColor="@color/colorSetTempButton" />
<TextView
android:id="@+id/profileswitch_remove"
android:layout_width="wrap_content"

View file

@ -131,6 +131,30 @@
android:paddingRight="10dp"
android:text="0.05 U"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/pump_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="PH"
android:textColor="@color/colorSetTempButton" />
<TextView
android:id="@+id/ns_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="NS"
android:textColor="@color/colorSetTempButton" />
</LinearLayout>
<LinearLayout

View file

@ -67,6 +67,29 @@
android:text="30 min"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/pump_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="PH"
android:textColor="@color/colorSetTempButton" />
<TextView
android:id="@+id/ns_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="NS"
android:textColor="@color/colorSetTempButton" />
</LinearLayout>
<LinearLayout