distinguish between meal and correction bulus
This commit is contained in:
parent
8614469a35
commit
861c24fc45
8 changed files with 45 additions and 11 deletions
|
@ -377,7 +377,6 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
Treatment stored = null;
|
Treatment stored = null;
|
||||||
trJson = new JSONObject(trstring);
|
|
||||||
String _id = trJson.getString("_id");
|
String _id = trJson.getString("_id");
|
||||||
|
|
||||||
if (trJson.has("timeIndex")) {
|
if (trJson.has("timeIndex")) {
|
||||||
|
@ -405,6 +404,11 @@ public class DataService extends IntentService {
|
||||||
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
|
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
|
||||||
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
|
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
|
||||||
treatment.created_at = new Date(trJson.getLong("mills"));
|
treatment.created_at = new Date(trJson.getLong("mills"));
|
||||||
|
if (trJson.has("eventType")) {
|
||||||
|
treatment.mealBolus = true;
|
||||||
|
if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false;
|
||||||
|
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false;
|
||||||
|
}
|
||||||
treatment.setTimeIndex(treatment.getTimeIndex());
|
treatment.setTimeIndex(treatment.getTimeIndex());
|
||||||
try {
|
try {
|
||||||
MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
|
MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
|
||||||
|
@ -450,6 +454,11 @@ public class DataService extends IntentService {
|
||||||
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
|
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
|
||||||
//treatment.created_at = DateUtil.fromISODateString(trJson.getString("created_at"));
|
//treatment.created_at = DateUtil.fromISODateString(trJson.getString("created_at"));
|
||||||
treatment.created_at = new Date(trJson.getLong("mills"));
|
treatment.created_at = new Date(trJson.getLong("mills"));
|
||||||
|
if (trJson.has("eventType")) {
|
||||||
|
treatment.mealBolus = true;
|
||||||
|
if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false;
|
||||||
|
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false;
|
||||||
|
}
|
||||||
treatment.setTimeIndex(treatment.getTimeIndex());
|
treatment.setTimeIndex(treatment.getTimeIndex());
|
||||||
try {
|
try {
|
||||||
Dao.CreateOrUpdateStatus status = MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
|
Dao.CreateOrUpdateStatus status = MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public static final String DATABASE_TREATMENTS = "Treatments";
|
public static final String DATABASE_TREATMENTS = "Treatments";
|
||||||
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
|
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 3;
|
private static final int DATABASE_VERSION = 4;
|
||||||
|
|
||||||
public DatabaseHelper(Context context) {
|
public DatabaseHelper(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
|
|
@ -47,11 +47,15 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public Double carbs = 0d;
|
public Double carbs = 0d;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public boolean mealBolus = true; // true for meal bolus , false for correction bolus
|
||||||
|
|
||||||
public void copyFrom(Treatment t) {
|
public void copyFrom(Treatment t) {
|
||||||
this._id = t._id;
|
this._id = t._id;
|
||||||
this.created_at = t.created_at;
|
this.created_at = t.created_at;
|
||||||
this.insulin = t.insulin;
|
this.insulin = t.insulin;
|
||||||
this.carbs = t.carbs;
|
this.carbs = t.carbs;
|
||||||
|
this.mealBolus = t.mealBolus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iob iobCalc(Date time, Double dia) {
|
public Iob iobCalc(Date time, Double dia) {
|
||||||
|
@ -90,6 +94,7 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
", _id: " + _id +
|
", _id: " + _id +
|
||||||
", insulin: " + insulin +
|
", insulin: " + insulin +
|
||||||
", carbs: " + carbs +
|
", carbs: " + carbs +
|
||||||
|
", mealBolus: " + mealBolus +
|
||||||
", created_at: " +
|
", created_at: " +
|
||||||
"}";
|
"}";
|
||||||
}
|
}
|
||||||
|
@ -112,7 +117,8 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
String label = "";
|
String label = "";
|
||||||
if (insulin > 0) label += DecimalFormatter.to2Decimal(insulin) + "U";
|
if (insulin > 0) label += DecimalFormatter.to2Decimal(insulin) + "U";
|
||||||
if (carbs > 0) label += (label.equals("") ? "" : " ") + DecimalFormatter.to0Decimal(carbs) + "g";
|
if (carbs > 0)
|
||||||
|
label += (label.equals("") ? "" : " ") + DecimalFormatter.to0Decimal(carbs) + "g";
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +136,10 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
public void sendToNSClient() {
|
public void sendToNSClient() {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
data.put("eventType", "Meal Bolus");
|
if (mealBolus)
|
||||||
|
data.put("eventType", "Meal Bolus");
|
||||||
|
else
|
||||||
|
data.put("eventType", "Correction Bolus");
|
||||||
if (insulin != 0d) data.put("insulin", insulin);
|
if (insulin != 0d) data.put("insulin", insulin);
|
||||||
if (carbs != 0d) data.put("carbs", carbs.intValue());
|
if (carbs != 0d) data.put("carbs", carbs.intValue());
|
||||||
data.put("created_at", DateUtil.toISOString(created_at));
|
data.put("created_at", DateUtil.toISOString(created_at));
|
||||||
|
@ -141,4 +150,4 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,6 +372,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
if (carbTime == 0)
|
if (carbTime == 0)
|
||||||
t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout
|
t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout
|
||||||
t.created_at = new Date();
|
t.created_at = new Date();
|
||||||
|
t.mealBolus = result.carbsDelivered > 0;
|
||||||
try {
|
try {
|
||||||
MainApp.getDbHelper().getDaoTreatments().create(t);
|
MainApp.getDbHelper().getDaoTreatments().create(t);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -419,6 +420,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
t.insulin = result.bolusDelivered;
|
t.insulin = result.bolusDelivered;
|
||||||
t.carbs = (double) result.carbsDelivered;
|
t.carbs = (double) result.carbsDelivered;
|
||||||
t.created_at = new Date();
|
t.created_at = new Date();
|
||||||
|
t.mealBolus = t.carbs > 0;
|
||||||
try {
|
try {
|
||||||
MainApp.getDbHelper().getDaoTreatments().create(t);
|
MainApp.getDbHelper().getDaoTreatments().create(t);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
||||||
Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia());
|
Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia());
|
||||||
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U");
|
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U");
|
||||||
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
|
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
|
||||||
|
holder.mealOrCorrection.setText(treatments.get(position).mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous));
|
||||||
if (iob.iobContrib != 0)
|
if (iob.iobContrib != 0)
|
||||||
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorAffectingIOB));
|
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorAffectingIOB));
|
||||||
else
|
else
|
||||||
|
@ -103,6 +104,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
||||||
TextView carbs;
|
TextView carbs;
|
||||||
TextView iob;
|
TextView iob;
|
||||||
TextView activity;
|
TextView activity;
|
||||||
|
TextView mealOrCorrection;
|
||||||
LinearLayout dateLinearLayout;
|
LinearLayout dateLinearLayout;
|
||||||
|
|
||||||
TreatmentsViewHolder(View itemView) {
|
TreatmentsViewHolder(View itemView) {
|
||||||
|
@ -113,6 +115,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
||||||
carbs = (TextView) itemView.findViewById(R.id.treatments_carbs);
|
carbs = (TextView) itemView.findViewById(R.id.treatments_carbs);
|
||||||
iob = (TextView) itemView.findViewById(R.id.treatments_iob);
|
iob = (TextView) itemView.findViewById(R.id.treatments_iob);
|
||||||
activity = (TextView) itemView.findViewById(R.id.treatments_activity);
|
activity = (TextView) itemView.findViewById(R.id.treatments_activity);
|
||||||
|
mealOrCorrection = (TextView) itemView.findViewById(R.id.treatments_mealorcorrection);
|
||||||
dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout);
|
dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,6 +187,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
||||||
|
|
||||||
public void updateGUI() {
|
public void updateGUI() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||||
|
if (profile == null)
|
||||||
|
return;
|
||||||
if (activity != null && recyclerView != null)
|
if (activity != null && recyclerView != null)
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -158,7 +158,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
if (treatment.carbs >= 1) {
|
if (treatment.carbs >= 1) {
|
||||||
result.carbs += treatment.carbs;
|
result.carbs += treatment.carbs;
|
||||||
}
|
}
|
||||||
if (treatment.insulin >= 0.1) {
|
if (treatment.insulin >= 0.1 && treatment.mealBolus) {
|
||||||
result.boluses += treatment.insulin;
|
result.boluses += treatment.insulin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,21 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="5dp"
|
android:paddingLeft="5dp"
|
||||||
android:text="1.1.2000 18:00"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:textColor="@color/cardItemLabel"
|
android:textColor="@color/cardItemLabel"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:text="Meal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/treatments_mealorcorrection"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textAppearance="@android:style/TextAppearance.Material.Medium"
|
||||||
|
android:textAlignment="textEnd"
|
||||||
|
android:textColor="@color/mdtp_red"
|
||||||
|
android:layout_marginRight="5dp" />
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -65,7 +75,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginRight="30dp"
|
android:layout_marginRight="30dp"
|
||||||
android:text="1.1 U"
|
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -83,7 +92,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginRight="30dp"
|
android:layout_marginRight="30dp"
|
||||||
android:text="48 g"
|
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -107,7 +115,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginRight="30dp"
|
android:layout_marginRight="30dp"
|
||||||
android:text="0.12 U"
|
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -125,7 +132,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginRight="30dp"
|
android:layout_marginRight="30dp"
|
||||||
android:text="0.002 U"
|
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -328,5 +328,7 @@
|
||||||
<string name="overview_editquickwizardlistactivity_add">Add</string>
|
<string name="overview_editquickwizardlistactivity_add">Add</string>
|
||||||
<string name="overview_quickwizard_item_edit_button">Edit</string>
|
<string name="overview_quickwizard_item_edit_button">Edit</string>
|
||||||
<string name="overview_quickwizard_item_remove_button">Remove</string>
|
<string name="overview_quickwizard_item_remove_button">Remove</string>
|
||||||
|
<string name="mealbolus">Meal</string>
|
||||||
|
<string name="correctionbous">Corr</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue