distinguish between meal and correction bulus

This commit is contained in:
Milos Kozak 2016-10-25 23:33:02 +02:00
parent 8614469a35
commit 861c24fc45
8 changed files with 45 additions and 11 deletions

View file

@ -377,7 +377,6 @@ public class DataService extends IntentService {
}
Treatment stored = null;
trJson = new JSONObject(trstring);
String _id = trJson.getString("_id");
if (trJson.has("timeIndex")) {
@ -405,6 +404,11 @@ public class DataService extends IntentService {
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
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());
try {
MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);
@ -450,6 +454,11 @@ public class DataService extends IntentService {
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
//treatment.created_at = DateUtil.fromISODateString(trJson.getString("created_at"));
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());
try {
Dao.CreateOrUpdateStatus status = MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment);

View file

@ -40,7 +40,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public static final String DATABASE_TREATMENTS = "Treatments";
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) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);

View file

@ -47,11 +47,15 @@ public class Treatment implements DataPointWithLabelInterface {
@DatabaseField
public Double carbs = 0d;
@DatabaseField
public boolean mealBolus = true; // true for meal bolus , false for correction bolus
public void copyFrom(Treatment t) {
this._id = t._id;
this.created_at = t.created_at;
this.insulin = t.insulin;
this.carbs = t.carbs;
this.mealBolus = t.mealBolus;
}
public Iob iobCalc(Date time, Double dia) {
@ -90,6 +94,7 @@ public class Treatment implements DataPointWithLabelInterface {
", _id: " + _id +
", insulin: " + insulin +
", carbs: " + carbs +
", mealBolus: " + mealBolus +
", created_at: " +
"}";
}
@ -112,7 +117,8 @@ public class Treatment implements DataPointWithLabelInterface {
public String getLabel() {
String label = "";
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;
}
@ -130,7 +136,10 @@ public class Treatment implements DataPointWithLabelInterface {
public void sendToNSClient() {
JSONObject data = new JSONObject();
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 (carbs != 0d) data.put("carbs", carbs.intValue());
data.put("created_at", DateUtil.toISOString(created_at));
@ -141,4 +150,4 @@ public class Treatment implements DataPointWithLabelInterface {
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
}
}
}

View file

@ -372,6 +372,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
if (carbTime == 0)
t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout
t.created_at = new Date();
t.mealBolus = result.carbsDelivered > 0;
try {
MainApp.getDbHelper().getDaoTreatments().create(t);
} catch (SQLException e) {
@ -419,6 +420,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
t.insulin = result.bolusDelivered;
t.carbs = (double) result.carbsDelivered;
t.created_at = new Date();
t.mealBolus = t.carbs > 0;
try {
MainApp.getDbHelper().getDaoTreatments().create(t);
} catch (SQLException e) {

View file

@ -80,6 +80,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia());
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " 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)
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorAffectingIOB));
else
@ -103,6 +104,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
TextView carbs;
TextView iob;
TextView activity;
TextView mealOrCorrection;
LinearLayout dateLinearLayout;
TreatmentsViewHolder(View itemView) {
@ -113,6 +115,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
carbs = (TextView) itemView.findViewById(R.id.treatments_carbs);
iob = (TextView) itemView.findViewById(R.id.treatments_iob);
activity = (TextView) itemView.findViewById(R.id.treatments_activity);
mealOrCorrection = (TextView) itemView.findViewById(R.id.treatments_mealorcorrection);
dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout);
}
}
@ -184,6 +187,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
public void updateGUI() {
Activity activity = getActivity();
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return;
if (activity != null && recyclerView != null)
activity.runOnUiThread(new Runnable() {
@Override

View file

@ -158,7 +158,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
if (treatment.carbs >= 1) {
result.carbs += treatment.carbs;
}
if (treatment.insulin >= 0.1) {
if (treatment.insulin >= 0.1 && treatment.mealBolus) {
result.boluses += treatment.insulin;
}
}

View file

@ -37,11 +37,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="1.1.2000 18:00"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/cardItemLabel"
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>
@ -65,7 +75,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="30dp"
android:text="1.1 U"
android:textStyle="bold" />
<TextView
@ -83,7 +92,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="30dp"
android:text="48 g"
android:textStyle="bold" />
</LinearLayout>
@ -107,7 +115,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="30dp"
android:text="0.12 U"
android:textStyle="bold" />
<TextView
@ -125,7 +132,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="30dp"
android:text="0.002 U"
android:textStyle="bold" />

View file

@ -328,5 +328,7 @@
<string name="overview_editquickwizardlistactivity_add">Add</string>
<string name="overview_quickwizard_item_edit_button">Edit</string>
<string name="overview_quickwizard_item_remove_button">Remove</string>
<string name="mealbolus">Meal</string>
<string name="correctionbous">Corr</string>
</resources>