upload extended bolus to NS
This commit is contained in:
parent
fdf09b9daf
commit
ea43a033d7
2 changed files with 38 additions and 2 deletions
|
@ -310,8 +310,13 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
public Result setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
// TODO: constraints here
|
Double rateAfterConstraints = applyBasalConstraints(insulin);
|
||||||
return activePump.setExtendedBolus(insulin, durationInMinutes);
|
Result result = activePump.setExtendedBolus(rateAfterConstraints, durationInMinutes);
|
||||||
|
if (result.enacted) {
|
||||||
|
uploadExtendedBolus(result.bolusDelivered, result.duration);
|
||||||
|
MainApp.bus().post(new EventTreatmentChange());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,12 +309,15 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
||||||
extendedBolus.isAbsolute = true;
|
extendedBolus.isAbsolute = true;
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
result.bolusDelivered = insulin;
|
||||||
|
result.duration = durationInMinutes;
|
||||||
result.comment = getString(R.string.virtualpump_resultok);
|
result.comment = getString(R.string.virtualpump_resultok);
|
||||||
try {
|
try {
|
||||||
MainApp.instance().getDbHelper().getDaoTempBasals().create(extendedBolus);
|
MainApp.instance().getDbHelper().getDaoTempBasals().create(extendedBolus);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
result.success = false;
|
result.success = false;
|
||||||
|
result.enacted = false;
|
||||||
result.comment = getString(R.string.virtualpump_sqlerror);
|
result.comment = getString(R.string.virtualpump_sqlerror);
|
||||||
}
|
}
|
||||||
if (Config.logPumpComm)
|
if (Config.logPumpComm)
|
||||||
|
|
Loading…
Reference in a new issue