redesign uploading treatments to NS

This commit is contained in:
Milos Kozak 2017-05-29 21:45:59 +02:00
parent ec76908eca
commit 358de54322
19 changed files with 211 additions and 83 deletions

View file

@ -0,0 +1,31 @@
package info.nightscout.androidaps.data;
import android.content.Context;
import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.interfaces.InsulinInterface;
/**
* Created by mike on 29.05.2017.
*/
public class DetailedBolusInfo {
public long date = new Date().getTime();
public InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
public String eventType = CareportalEvent.MEALBOLUS;
public double insulin = 0;
public double carbs = 0;
public int source = Source.NONE;
public double glucose = 0; // Bg value in current units
public String glucoseType = ""; // NS values: Manual, Finger, Sensor
public int carbTime = 0; // time shift of carbs in minutes
public JSONObject boluscalc = null; // additional bolus wizard info
public Context context = null; // context for progress dialog
public boolean addToTreatments = true;
}

View file

@ -25,7 +25,7 @@ public class PumpEnactResult extends Object {
public boolean isTempCancel = false; // if true we are caceling temp basal
// Result of treatment delivery
public Double bolusDelivered = 0d; // real value of delivered insulin
public Integer carbsDelivered = 0; // real value of delivered carbs
public Double carbsDelivered = 0d; // real value of delivered carbs
public boolean queued = false;

View file

@ -40,6 +40,10 @@ public class CareportalEvent {
@DatabaseField
public String json;
public static final String CARBCORRECTION = "Carb Correction";
public static final String BOLUSWIZARD = "Bolus Wizard";
public static final String CORRECTIONBOLUS = "Correction Bolus";
public static final String MEALBOLUS = "Meal Bolus";
public static final String COMBOBOLUS = "Combo Bolus";
public static final String TEMPBASAL = "Temp Basal";
public static final String TEMPORARYTARGET = "Temporary Target";

View file

@ -6,6 +6,7 @@ import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
@ -30,7 +31,7 @@ public interface PumpInterface {
double getBaseBasalRate(); // base basal rate, not temp basal
PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context);
PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo);
void stopBolusDelivering();
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes);
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.interfaces;
import java.util.List;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.ExtendedBolus;
@ -48,7 +49,7 @@ public interface TreatmentsInterface {
void addToHistoryExtendedBolusStop(long time);
OverlappingIntervals<ExtendedBolus> getExtendedBolusesFromHistory();
void addTreatmentToHistory(Treatment treatment);
void addTreatmentToHistory(DetailedBolusInfo detailedBolusInfo);
TempTarget getTempTargetFromHistory(long time);
OverlappingIntervals<TempTarget> getTempTargetsFromHistory();

View file

@ -26,6 +26,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
@ -159,7 +160,11 @@ public class FillDialog extends DialogFragment implements OnClickListener {
mHandler.post(new Runnable() {
@Override
public void run() {
PumpEnactResult result = pump.deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), finalInsulinAfterConstraints, 0, context, false);
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
detailedBolusInfo.context = context;
detailedBolusInfo.addToTreatments = false;
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));

View file

@ -19,6 +19,7 @@ import java.util.List;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.PumpEnactResult;
@ -402,7 +403,7 @@ 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;
@ -438,7 +439,32 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
mWakeLock.release();
return result;
}
*/
@Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
mWakeLock.acquire();
PumpEnactResult result;
detailedBolusInfo.insulin = applyBolusConstraints(detailedBolusInfo.insulin);
detailedBolusInfo.carbs = applyCarbsConstraints((int) detailedBolusInfo.carbs);
BolusProgressDialog bolusProgressDialog = null;
if (detailedBolusInfo.context != null) {
bolusProgressDialog = new BolusProgressDialog();
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
}
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
result = activePump.deliverTreatment(detailedBolusInfo);
BolusProgressDialog.bolusEnded = true;
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
mWakeLock.release();
return result;
}
/*
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
return deliverTreatment(insulinType, insulin, carbs, context, true);
@ -487,7 +513,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
return result;
}
*/
@Override
public void stopBolusDelivering() {
activePump.stopBolusDelivering();
@ -904,8 +930,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public void addTreatmentToHistory(Treatment treatment) {
activeTreatments.addTreatmentToHistory(treatment);
public void addTreatmentToHistory(DetailedBolusInfo detailedBolusInfo) {
if (!detailedBolusInfo.addToTreatments)
return;
activeTreatments.addTreatmentToHistory(detailedBolusInfo);
NSUpload.uploadBolusWizardRecord(detailedBolusInfo);
}
@Override

View file

@ -24,7 +24,9 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.SafeParse;
@ -86,7 +88,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
try {
Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString());
Integer carbs = SafeParse.stringToInt(this.carbs.getText().toString());
final Integer carbs = SafeParse.stringToInt(this.carbs.getText().toString());
String confirmMessage = getString(R.string.entertreatmentquestion) + "\n";
@ -98,8 +100,8 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
if (insulinAfterConstraints - insulin != 0 || carbsAfterConstraints != carbs)
confirmMessage += "\n" + getString(R.string.constraintapllied);
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
final double finalInsulinAfterConstraints = insulinAfterConstraints;
final int finalCarbsAfterConstraints = carbsAfterConstraints;
final Context context = getContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
@ -113,7 +115,13 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
mHandler.post(new Runnable() {
@Override
public void run() {
PumpEnactResult result = pump.deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), finalInsulinAfterConstraints, finalCarbsAfterConstraints, context);
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
if (finalInsulinAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
if (finalCarbsAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
detailedBolusInfo.context = context;
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));

View file

@ -42,8 +42,10 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventRefreshGui;
@ -308,16 +310,16 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
mHandler.post(new Runnable() {
@Override
public void run() {
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
MainApp.getConfigBuilder().getActiveInsulin(),
context,
finalInsulinAfterConstraints,
finalCarbsAfterConstraints,
bg,
"Manual",
carbTime,
boluscalcJSON
);
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
detailedBolusInfo.context = context;
detailedBolusInfo.glucose = bg;
detailedBolusInfo.glucoseType = "Manual";
detailedBolusInfo.carbTime = carbTime;
detailedBolusInfo.boluscalc = boluscalcJSON;
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.Overview;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.DashPathEffect;
@ -62,10 +63,12 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
@ -645,8 +648,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
final Context context = getContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@ -656,16 +659,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
sHandler.post(new Runnable() {
@Override
public void run() {
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
MainApp.getConfigBuilder().getActiveInsulin(),
getContext(),
finalInsulinAfterConstraints,
finalCarbsAfterConstraints,
actualBg.valueToUnits(profile.getUnits()),
"Manual",
0,
boluscalcJSON
);
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
detailedBolusInfo.context = context;
detailedBolusInfo.boluscalc = boluscalcJSON;
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
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.TemporaryBasal;
@ -296,26 +297,29 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
if (insulin > 0 || carbs > 0) {
Treatment t = new Treatment(insulinType);
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
boolean connectionOK = false;
if (insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t);
PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK;
result.bolusDelivered = t.insulin;
result.carbsDelivered = carbs;
result.carbsDelivered = detailedBolusInfo.carbs;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (Config.logPumpActions)
log.debug("deliverTreatment: OK. Asked: " + insulin + " Delivered: " + result.bolusDelivered);
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
detailedBolusInfo.insulin = t.insulin;
detailedBolusInfo.date = new Date().getTime();
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
return result;
} else {
PumpEnactResult result = new PumpEnactResult();
result.success = false;
result.bolusDelivered = 0d;
result.carbsDelivered = 0;
result.carbsDelivered = 0d;
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
log.error("deliverTreatment: Invalid input");
return result;

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
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.TemporaryBasal;
@ -299,26 +300,29 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
}
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
if (insulin > 0 || carbs > 0) {
Treatment t = new Treatment(insulinType);
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
boolean connectionOK = false;
if (insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t);
PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK;
result.bolusDelivered = t.insulin;
result.carbsDelivered = carbs;
result.carbsDelivered = detailedBolusInfo.carbs;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (Config.logPumpActions)
log.debug("deliverTreatment: OK. Asked: " + insulin + " Delivered: " + result.bolusDelivered);
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
detailedBolusInfo.insulin = t.insulin;
detailedBolusInfo.date = new Date().getTime();
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
return result;
} else {
PumpEnactResult result = new PumpEnactResult();
result.success = false;
result.bolusDelivered = 0d;
result.carbsDelivered = 0;
result.carbsDelivered = 0d;
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
log.error("deliverTreatment: Invalid input");
return result;

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
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.TemporaryBasal;
@ -282,26 +283,29 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
}
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
if (insulin > 0 || carbs > 0) {
Treatment t = new Treatment(insulinType);
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
boolean connectionOK = false;
if (insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t);
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t);
PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK;
result.bolusDelivered = t.insulin;
result.carbsDelivered = carbs;
result.carbsDelivered = detailedBolusInfo.carbs;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (Config.logPumpActions)
log.debug("deliverTreatment: OK. Asked: " + insulin + " Delivered: " + result.bolusDelivered);
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
detailedBolusInfo.insulin = t.insulin;
detailedBolusInfo.date = new Date().getTime();
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
return result;
} else {
PumpEnactResult result = new PumpEnactResult();
result.success = false;
result.bolusDelivered = 0d;
result.carbsDelivered = 0;
result.carbsDelivered = 0d;
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
log.error("deliverTreatment: Invalid input");
return result;

View file

@ -13,6 +13,7 @@ import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
@ -164,12 +165,13 @@ public class MDIPlugin implements PluginBase, PumpInterface {
}
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
PumpEnactResult result = new PumpEnactResult();
result.success = true;
result.bolusDelivered = insulin;
result.carbsDelivered = carbs;
result.bolusDelivered = detailedBolusInfo.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
return result;
}

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
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.TemporaryBasal;
@ -189,23 +190,23 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
}
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
PumpEnactResult result = new PumpEnactResult();
result.success = true;
result.bolusDelivered = insulin;
result.carbsDelivered = carbs;
result.bolusDelivered = detailedBolusInfo.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
Double delivering = 0d;
while (delivering < insulin) {
while (delivering < detailedBolusInfo.insulin) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivering);
bolusingEvent.percent = Math.min((int) (delivering / insulin * 100), 100);
bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100);
MainApp.bus().post(bolusingEvent);
delivering += 0.1d;
}
@ -214,7 +215,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
} catch (InterruptedException e) {
}
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivered), insulin);
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivered), detailedBolusInfo.insulin);
bolusingEvent.percent = 100;
MainApp.bus().post(bolusingEvent);
try {
@ -222,9 +223,10 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
} catch (InterruptedException e) {
}
if (Config.logPumpComm)
log.debug("Delivering treatment insulin: " + insulin + "U carbs: " + carbs + "g " + result);
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
lastDataTime = new Date();
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
return result;
}

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.PumpEnactResult;
@ -465,7 +466,9 @@ public class SmsCommunicatorPlugin implements PluginBase {
PumpInterface pumpInterface = MainApp.getConfigBuilder();
if (pumpInterface != null) {
danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
PumpEnactResult result = pumpInterface.deliverTreatment(ConfigBuilderPlugin.getActiveInsulin(), bolusWaitingForConfirmation.bolusRequested, 0, null);
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested;
PumpEnactResult result = pumpInterface.deliverTreatment(detailedBolusInfo);
if (result.success) {
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
if (danaRPlugin != null)

View file

@ -14,6 +14,7 @@ import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
@ -403,9 +404,24 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
@Override
public void addTreatmentToHistory(Treatment treatment) {
log.debug("Adding new Treatment record" + treatment);
public void addTreatmentToHistory(DetailedBolusInfo detailedBolusInfo) {
Treatment treatment = new Treatment(detailedBolusInfo.insulinInterface);
treatment.date = detailedBolusInfo.date;
treatment.insulin = detailedBolusInfo.insulin;
if (detailedBolusInfo.carbTime == 0)
treatment.carbs = detailedBolusInfo.carbs;
treatment.source = detailedBolusInfo.source;
treatment.mealBolus = treatment.carbs > 0;
MainApp.getDbHelper().createOrUpdate(treatment);
log.debug("Adding new Treatment record" + treatment);
if (detailedBolusInfo.carbTime != 0) {
Treatment carbsTreatment = new Treatment(detailedBolusInfo.insulinInterface);
carbsTreatment.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L;
carbsTreatment.carbs = detailedBolusInfo.carbs;
carbsTreatment.source = detailedBolusInfo.source;
MainApp.getDbHelper().createOrUpdate(carbsTreatment);
log.debug("Adding new Treatment record" + carbsTreatment);
}
}
@Override

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
@ -368,7 +369,10 @@ public class ActionStringHandler {
handler.post(new Runnable() {
@Override
public void run() {
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), amount, 0, null, false);
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.insulin = amount;
detailedBolusInfo.addToTreatments = false;
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(detailedBolusInfo);
if (!result.success) {
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
"\n" +
@ -384,7 +388,10 @@ public class ActionStringHandler {
handler.post(new Runnable() {
@Override
public void run() {
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), amount, carbs, null, true);
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.insulin = amount;
detailedBolusInfo.carbs = carbs;
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(detailedBolusInfo);
if (!result.success) {
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
"\n" +

View file

@ -16,6 +16,7 @@ import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
@ -251,18 +252,22 @@ public class NSUpload {
}
}
public static void uploadBolusWizardRecord(Treatment t, double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
public static void uploadBolusWizardRecord(DetailedBolusInfo detailedBolusInfo) {
JSONObject data = new JSONObject();
try {
data.put("eventType", "Bolus Wizard");
if (t.insulin != 0d) data.put("insulin", t.insulin);
if (t.carbs != 0d) data.put("carbs", t.carbs.intValue());
data.put("created_at", DateUtil.toISOString(t.date));
data.put("date", t.date);
if (glucose != 0d) data.put("glucose", glucose);
data.put("glucoseType", glucoseType);
data.put("boluscalc", boluscalc);
if (carbTime != 0) data.put("preBolus", carbTime);
data.put("eventType", detailedBolusInfo.eventType);
if (detailedBolusInfo.insulin != 0d) data.put("insulin", detailedBolusInfo.insulin);
if (detailedBolusInfo.carbs != 0d) data.put("carbs", (int) detailedBolusInfo.carbs);
data.put("created_at", DateUtil.toISOString(detailedBolusInfo.date));
data.put("date", detailedBolusInfo.date);
if (detailedBolusInfo.glucose != 0d)
data.put("glucose", detailedBolusInfo.glucose);
if (!detailedBolusInfo.glucoseType.equals(""))
data.put("glucoseType", detailedBolusInfo.glucoseType);
if (detailedBolusInfo.boluscalc != null)
data.put("boluscalc", detailedBolusInfo.boluscalc);
if (detailedBolusInfo.carbTime != 0)
data.put("preBolus", detailedBolusInfo.carbTime);
} catch (JSONException e) {
e.printStackTrace();
}