upload extended bolus to NS

This commit is contained in:
Milos Kozak 2016-06-20 23:44:00 +02:00
parent fdf09b9daf
commit ea43a033d7
2 changed files with 38 additions and 2 deletions

View file

@ -310,8 +310,13 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override
public Result setExtendedBolus(Double insulin, Integer durationInMinutes) {
// TODO: constraints here
return activePump.setExtendedBolus(insulin, durationInMinutes);
Double rateAfterConstraints = applyBasalConstraints(insulin);
Result result = activePump.setExtendedBolus(rateAfterConstraints, durationInMinutes);
if (result.enacted) {
uploadExtendedBolus(result.bolusDelivered, result.duration);
MainApp.bus().post(new EventTreatmentChange());
}
return result;
}
@Override
@ -803,4 +808,32 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
}
public static void uploadExtendedBolus(Double insulin, double durationInMinutes) {
try {
Context context = MainApp.instance().getApplicationContext();
JSONObject data = new JSONObject();
data.put("eventType", "Combo Bolus");
data.put("duration", durationInMinutes);
data.put("splitNow", 0);
data.put("splitExt", 100);
data.put("enteredinsulin", insulin);
data.put("relative", insulin);
data.put("created_at", DateUtil.toISOString(new Date()));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
if (q.size() < 1) {
log.error("DBADD No receivers");
} else log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
} catch (JSONException e) {
}
}
}

View file

@ -309,12 +309,15 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
extendedBolus.isAbsolute = true;
result.success = true;
result.enacted = true;
result.bolusDelivered = insulin;
result.duration = durationInMinutes;
result.comment = getString(R.string.virtualpump_resultok);
try {
MainApp.instance().getDbHelper().getDaoTempBasals().create(extendedBolus);
} catch (SQLException e) {
e.printStackTrace();
result.success = false;
result.enacted = false;
result.comment = getString(R.string.virtualpump_sqlerror);
}
if (Config.logPumpComm)