Add 0%-TBR to history when pump has been started or stopped

This commit is contained in:
TebbeUbben 2018-04-21 23:20:33 +02:00
parent d82a24873f
commit fd776a2a0e
5 changed files with 56 additions and 10 deletions

Binary file not shown.

View file

@ -161,18 +161,54 @@ class HistoryIntentAdapter {
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE);
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null) return;
try {
JSONObject data = new JSONObject();
String enteredBy = SP.getString("careportal_enteredby", "");
if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
data.put("created_at", DateUtil.toISOString(date));
data.put("eventType", CareportalEvent.NOTE);
data.put("notes", MainApp.instance().getString(getAlertText(alertType)));
NSUpload.uploadCareportalEntryToNS(data);
} catch (JSONException e) {
e.printStackTrace();
logNote(date, MainApp.instance().getString(getAlertText(alertType)));
}
}
void processPumpStatusChangedIntent(Intent intent) {
Date newStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
if (SP.getBoolean("insight_automatic_careportal_events", false)) {
String newStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_NEW_STATUS);
switch (newStatus) {
case "STARTED":
logNote(newStatusTime, MainApp.instance().getString(R.string.pump_started));
break;
case "STOPPED":
logNote(newStatusTime, MainApp.instance().getString(R.string.pump_stopped));
break;
case "PAUSED":
logNote(newStatusTime, MainApp.instance().getString(R.string.pump_paused));
break;
}
}
if (intent.hasExtra(HistoryBroadcast.EXTRA_OLD_STATUS_TIME)) {
String oldStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_OLD_STATUS);
if (oldStatus.equals("STOPPED") ||oldStatus.equals("PAUSED")) {
Date oldStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_OLD_STATUS_TIME);
int duration = (int) ((newStatusTime.getTime() - oldStatusTime.getTime()) / 60000);
long serialNumber = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
long recordId = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
long uniqueRecordId = getRecordUniqueID(serialNumber, recordId);
logAdapter.createTBRrecord(oldStatusTime, 0, duration, uniqueRecordId);
}
}
}
private void logNote(Date date, String note) {
try {
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null) return;
JSONObject data = new JSONObject();
String enteredBy = SP.getString("careportal_enteredby", "");
if (!enteredBy.equals("")) data.put("enteredBy", enteredBy);
data.put("created_at", DateUtil.toISOString(date));
data.put("eventType", CareportalEvent.NOTE);
data.put("notes", note);
NSUpload.uploadCareportalEntryToNS(data);
} catch (JSONException e) {
e.printStackTrace();
}
}
private int getAlertText(String type) {

View file

@ -47,6 +47,7 @@ public class HistoryReceiver {
filter.addAction(ACTION_CARTRIDGE_INSERTED);
filter.addAction(ACTION_BATTERY_INSERTED);
filter.addAction(ACTION_OCCURENCE_OF_ALERT);
filter.addAction(ACTION_PUMP_STATUS_CHANGED);
MainApp.instance().registerReceiver(historyReceiver, filter);
}
@ -108,6 +109,9 @@ public class HistoryReceiver {
case ACTION_OCCURENCE_OF_ALERT:
intentAdapter.processOccurenceOfAlertIntent(intent);
break;
case ACTION_PUMP_STATUS_CHANGED:
intentAdapter.processPumpStatusChangedIntent(intent);
break;
}
}
};

View file

@ -735,4 +735,7 @@
<string name="combo_suspious_bolus_time">Zeit/Datum des abgegebenen Boluses auf der Pumpe erscheint falsch, IOB ist wahrscheinlich nicht korrekt. Bitte prüfe Zeit/Datum der Pumpe.</string>
<string name="combo_tbr_count">Anzahl TBRs</string>
<string name="combo_bolus_count">Anzahl Boluse</string>
<string name="pump_stopped">Pumpe gestoppt</string>
<string name="pump_started">Pumpe pausiert</string>
<string name="pump_paused">Pumpe gestartet</string>
</resources>

View file

@ -995,4 +995,7 @@
<string name="key_openapssmb_max_iob" translatable="false">openapsmb_max_iob</string>
<string name="openapssmb_maxiob_title">Maximum total IOB OpenAPS can\'t go over [U]</string>
<string name="openapssmb_maxiob_summary">This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value</string>
<string name="pump_stopped">Pump stopped</string>
<string name="pump_started">Pump paused</string>
<string name="pump_paused">Pump started</string>
</resources>