redesign uploading treatments to NS
This commit is contained in:
parent
ec76908eca
commit
358de54322
|
@ -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;
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ public class PumpEnactResult extends Object {
|
||||||
public boolean isTempCancel = false; // if true we are caceling temp basal
|
public boolean isTempCancel = false; // if true we are caceling temp basal
|
||||||
// Result of treatment delivery
|
// Result of treatment delivery
|
||||||
public Double bolusDelivered = 0d; // real value of delivered insulin
|
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;
|
public boolean queued = false;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,10 @@ public class CareportalEvent {
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public String json;
|
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 COMBOBOLUS = "Combo Bolus";
|
||||||
public static final String TEMPBASAL = "Temp Basal";
|
public static final String TEMPBASAL = "Temp Basal";
|
||||||
public static final String TEMPORARYTARGET = "Temporary Target";
|
public static final String TEMPORARYTARGET = "Temporary Target";
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ public interface PumpInterface {
|
||||||
|
|
||||||
double getBaseBasalRate(); // base basal rate, not temp basal
|
double getBaseBasalRate(); // base basal rate, not temp basal
|
||||||
|
|
||||||
PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context);
|
PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo);
|
||||||
void stopBolusDelivering();
|
void stopBolusDelivering();
|
||||||
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes);
|
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes);
|
||||||
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.interfaces;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
|
@ -48,7 +49,7 @@ public interface TreatmentsInterface {
|
||||||
void addToHistoryExtendedBolusStop(long time);
|
void addToHistoryExtendedBolusStop(long time);
|
||||||
OverlappingIntervals<ExtendedBolus> getExtendedBolusesFromHistory();
|
OverlappingIntervals<ExtendedBolus> getExtendedBolusesFromHistory();
|
||||||
|
|
||||||
void addTreatmentToHistory(Treatment treatment);
|
void addTreatmentToHistory(DetailedBolusInfo detailedBolusInfo);
|
||||||
|
|
||||||
TempTarget getTempTargetFromHistory(long time);
|
TempTarget getTempTargetFromHistory(long time);
|
||||||
OverlappingIntervals<TempTarget> getTempTargetsFromHistory();
|
OverlappingIntervals<TempTarget> getTempTargetsFromHistory();
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.text.DecimalFormat;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
@ -159,7 +160,11 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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) {
|
if (!result.success) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
@ -402,7 +403,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
else
|
else
|
||||||
return 0d;
|
return 0d;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
|
public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
PumpEnactResult result;
|
PumpEnactResult result;
|
||||||
|
@ -438,7 +439,32 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
return result;
|
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
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
||||||
return deliverTreatment(insulinType, insulin, carbs, context, true);
|
return deliverTreatment(insulinType, insulin, carbs, context, true);
|
||||||
|
@ -487,7 +513,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
activePump.stopBolusDelivering();
|
activePump.stopBolusDelivering();
|
||||||
|
@ -904,8 +930,11 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTreatmentToHistory(Treatment treatment) {
|
public void addTreatmentToHistory(DetailedBolusInfo detailedBolusInfo) {
|
||||||
activeTreatments.addTreatmentToHistory(treatment);
|
if (!detailedBolusInfo.addToTreatments)
|
||||||
|
return;
|
||||||
|
activeTreatments.addTreatmentToHistory(detailedBolusInfo);
|
||||||
|
NSUpload.uploadBolusWizardRecord(detailedBolusInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,9 @@ import java.text.DecimalFormat;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.utils.PlusMinusEditText;
|
import info.nightscout.utils.PlusMinusEditText;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
@ -86,7 +88,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString());
|
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";
|
String confirmMessage = getString(R.string.entertreatmentquestion) + "\n";
|
||||||
|
|
||||||
|
@ -98,8 +100,8 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
if (insulinAfterConstraints - insulin != 0 || carbsAfterConstraints != carbs)
|
if (insulinAfterConstraints - insulin != 0 || carbsAfterConstraints != carbs)
|
||||||
confirmMessage += "\n" + getString(R.string.constraintapllied);
|
confirmMessage += "\n" + getString(R.string.constraintapllied);
|
||||||
|
|
||||||
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
final double finalInsulinAfterConstraints = insulinAfterConstraints;
|
||||||
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
final int finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||||
|
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
@ -113,7 +115,13 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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) {
|
if (!result.success) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
|
|
|
@ -42,8 +42,10 @@ import java.util.Date;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
|
@ -308,16 +310,16 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
MainApp.getConfigBuilder().getActiveInsulin(),
|
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||||
context,
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
finalInsulinAfterConstraints,
|
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||||
finalCarbsAfterConstraints,
|
detailedBolusInfo.context = context;
|
||||||
bg,
|
detailedBolusInfo.glucose = bg;
|
||||||
"Manual",
|
detailedBolusInfo.glucoseType = "Manual";
|
||||||
carbTime,
|
detailedBolusInfo.carbTime = carbTime;
|
||||||
boluscalcJSON
|
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||||
);
|
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.Overview;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.DashPathEffect;
|
import android.graphics.DashPathEffect;
|
||||||
|
@ -62,10 +63,12 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -645,8 +648,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
||||||
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||||
|
final Context context = getContext();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||||
builder.setMessage(confirmMessage);
|
builder.setMessage(confirmMessage);
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
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() {
|
sHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = pump.deliverTreatmentFromBolusWizard(
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
MainApp.getConfigBuilder().getActiveInsulin(),
|
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||||
getContext(),
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
finalInsulinAfterConstraints,
|
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||||
finalCarbsAfterConstraints,
|
detailedBolusInfo.context = context;
|
||||||
actualBg.valueToUnits(profile.getUnits()),
|
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||||
"Manual",
|
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
||||||
0,
|
|
||||||
boluscalcJSON
|
|
||||||
);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -296,26 +297,29 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||||
if (insulin > 0 || carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
Treatment t = new Treatment(insulinType);
|
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
|
||||||
boolean connectionOK = false;
|
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();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = connectionOK;
|
result.success = connectionOK;
|
||||||
result.bolusDelivered = t.insulin;
|
result.bolusDelivered = t.insulin;
|
||||||
result.carbsDelivered = carbs;
|
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
if (Config.logPumpActions)
|
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;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = false;
|
result.success = false;
|
||||||
result.bolusDelivered = 0d;
|
result.bolusDelivered = 0d;
|
||||||
result.carbsDelivered = 0;
|
result.carbsDelivered = 0d;
|
||||||
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
||||||
log.error("deliverTreatment: Invalid input");
|
log.error("deliverTreatment: Invalid input");
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -299,26 +300,29 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||||
if (insulin > 0 || carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
Treatment t = new Treatment(insulinType);
|
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
|
||||||
boolean connectionOK = false;
|
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();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = connectionOK;
|
result.success = connectionOK;
|
||||||
result.bolusDelivered = t.insulin;
|
result.bolusDelivered = t.insulin;
|
||||||
result.carbsDelivered = carbs;
|
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
if (Config.logPumpActions)
|
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;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = false;
|
result.success = false;
|
||||||
result.bolusDelivered = 0d;
|
result.bolusDelivered = 0d;
|
||||||
result.carbsDelivered = 0;
|
result.carbsDelivered = 0d;
|
||||||
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
||||||
log.error("deliverTreatment: Invalid input");
|
log.error("deliverTreatment: Invalid input");
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -282,26 +283,29 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||||
if (insulin > 0 || carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
Treatment t = new Treatment(insulinType);
|
Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
|
||||||
boolean connectionOK = false;
|
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();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = connectionOK;
|
result.success = connectionOK;
|
||||||
result.bolusDelivered = t.insulin;
|
result.bolusDelivered = t.insulin;
|
||||||
result.carbsDelivered = carbs;
|
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
if (Config.logPumpActions)
|
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;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = false;
|
result.success = false;
|
||||||
result.bolusDelivered = 0d;
|
result.bolusDelivered = 0d;
|
||||||
result.carbsDelivered = 0;
|
result.carbsDelivered = 0d;
|
||||||
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
||||||
log.error("deliverTreatment: Invalid input");
|
log.error("deliverTreatment: Invalid input");
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
@ -164,12 +165,13 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.bolusDelivered = insulin;
|
result.bolusDelivered = detailedBolusInfo.insulin;
|
||||||
result.carbsDelivered = carbs;
|
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
|
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -189,23 +190,23 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.bolusDelivered = insulin;
|
result.bolusDelivered = detailedBolusInfo.insulin;
|
||||||
result.carbsDelivered = carbs;
|
result.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
|
|
||||||
Double delivering = 0d;
|
Double delivering = 0d;
|
||||||
|
|
||||||
while (delivering < insulin) {
|
while (delivering < detailedBolusInfo.insulin) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivering);
|
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);
|
MainApp.bus().post(bolusingEvent);
|
||||||
delivering += 0.1d;
|
delivering += 0.1d;
|
||||||
}
|
}
|
||||||
|
@ -214,7 +215,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
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;
|
bolusingEvent.percent = 100;
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
try {
|
try {
|
||||||
|
@ -222,9 +223,10 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
if (Config.logPumpComm)
|
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());
|
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||||
lastDataTime = new Date();
|
lastDataTime = new Date();
|
||||||
|
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.Services.Intents;
|
import info.nightscout.androidaps.Services.Intents;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
@ -465,7 +466,9 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
||||||
if (pumpInterface != null) {
|
if (pumpInterface != null) {
|
||||||
danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
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) {
|
if (result.success) {
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
||||||
if (danaRPlugin != null)
|
if (danaRPlugin != null)
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Iob;
|
import info.nightscout.androidaps.data.Iob;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
@ -403,9 +404,24 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTreatmentToHistory(Treatment treatment) {
|
public void addTreatmentToHistory(DetailedBolusInfo detailedBolusInfo) {
|
||||||
log.debug("Adding new Treatment record" + treatment);
|
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);
|
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
|
@Override
|
||||||
|
|
|
@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
@ -368,7 +369,10 @@ public class ActionStringHandler {
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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) {
|
if (!result.success) {
|
||||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||||
"\n" +
|
"\n" +
|
||||||
|
@ -384,7 +388,10 @@ public class ActionStringHandler {
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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) {
|
if (!result.success) {
|
||||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||||
"\n" +
|
"\n" +
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Date;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.Services.Intents;
|
import info.nightscout.androidaps.Services.Intents;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
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();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
data.put("eventType", "Bolus Wizard");
|
data.put("eventType", detailedBolusInfo.eventType);
|
||||||
if (t.insulin != 0d) data.put("insulin", t.insulin);
|
if (detailedBolusInfo.insulin != 0d) data.put("insulin", detailedBolusInfo.insulin);
|
||||||
if (t.carbs != 0d) data.put("carbs", t.carbs.intValue());
|
if (detailedBolusInfo.carbs != 0d) data.put("carbs", (int) detailedBolusInfo.carbs);
|
||||||
data.put("created_at", DateUtil.toISOString(t.date));
|
data.put("created_at", DateUtil.toISOString(detailedBolusInfo.date));
|
||||||
data.put("date", t.date);
|
data.put("date", detailedBolusInfo.date);
|
||||||
if (glucose != 0d) data.put("glucose", glucose);
|
if (detailedBolusInfo.glucose != 0d)
|
||||||
data.put("glucoseType", glucoseType);
|
data.put("glucose", detailedBolusInfo.glucose);
|
||||||
data.put("boluscalc", boluscalc);
|
if (!detailedBolusInfo.glucoseType.equals(""))
|
||||||
if (carbTime != 0) data.put("preBolus", carbTime);
|
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) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue