Merge pull request #855 from TebbeUbben/automatic-careportal-events
Automatic careportal events
This commit is contained in:
commit
0f0d68e46a
8 changed files with 180 additions and 12 deletions
|
@ -346,7 +346,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
try {
|
try {
|
||||||
getDaoBgReadings().update(bgReading);
|
getDaoBgReadings().update(bgReading);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1201,6 +1201,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
scheduleCareportalEventChange();
|
scheduleCareportalEventChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CareportalEvent getCareportalEventFromTimestamp(long timestamp) {
|
||||||
|
try {
|
||||||
|
return getDaoCareportalEvents().queryForId(timestamp);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CareportalEvent getLastCareportalEvent(String event) {
|
public CareportalEvent getLastCareportalEvent(String event) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpInsight.history;
|
package info.nightscout.androidaps.plugins.PumpInsight.history;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
|
import info.nightscout.androidaps.db.TDD;
|
||||||
|
import info.nightscout.utils.DateUtil;
|
||||||
|
import info.nightscout.utils.NSUpload;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import sugar.free.sightparser.handling.HistoryBroadcast;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import android.database.DatabaseUtils;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
|
||||||
import info.nightscout.androidaps.db.TDD;
|
|
||||||
import sugar.free.sightparser.handling.HistoryBroadcast;
|
|
||||||
|
|
||||||
import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.updatePumpSerialNumber;
|
import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache.updatePumpSerialNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by jamorham on 27/01/2018.
|
* Created by jamorham on 27/01/2018.
|
||||||
*
|
* <p>
|
||||||
* Parse inbound logbook intents
|
* Parse inbound logbook intents
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HistoryIntentAdapter {
|
class HistoryIntentAdapter {
|
||||||
|
@ -121,4 +124,80 @@ class HistoryIntentAdapter {
|
||||||
TDD tdd = new TDD(date.getTime(), bolus, basal, bolus + basal);
|
TDD tdd = new TDD(date.getTime(), bolus, basal, bolus + basal);
|
||||||
MainApp.getDbHelper().createOrUpdateTDD(tdd);
|
MainApp.getDbHelper().createOrUpdateTDD(tdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void processCannulaFilledIntent(Intent intent) {
|
||||||
|
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||||
|
uploadCareportalEvent(date, CareportalEvent.SITECHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void processCartridgeInsertedIntent(Intent intent) {
|
||||||
|
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||||
|
uploadCareportalEvent(date, CareportalEvent.INSULINCHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void processBatteryInsertedIntent(Intent intent) {
|
||||||
|
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||||
|
uploadCareportalEvent(date, CareportalEvent.PUMPBATTERYCHANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void uploadCareportalEvent(Date date, String event) {
|
||||||
|
if (SP.getBoolean("insight_automatic_careportal_events", false)) {
|
||||||
|
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", event);
|
||||||
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void processOccurenceOfAlertIntent(Intent intent) {
|
||||||
|
if (SP.getBoolean("insight_automatic_careportal_events", false)) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAlertText(String type) {
|
||||||
|
if (type.equals("Error6MechanicalError")) return R.string.alert_e6;
|
||||||
|
if (type.equals("Error7ElectronicError")) return R.string.alert_e7;
|
||||||
|
if (type.equals("Error10RewindError")) return R.string.alert_e10;
|
||||||
|
if (type.equals("Error13LanguageError")) return R.string.alert_e13;
|
||||||
|
if (type.equals("Maintenance20CartridgeNotInserted")) return R.string.alert_m20;
|
||||||
|
if (type.equals("Maintenance21CartridgeEmpty")) return R.string.alert_m21;
|
||||||
|
if (type.equals("Maintenance22BatteryEmpty")) return R.string.alert_m22;
|
||||||
|
if (type.equals("Maintenance23AutomaticOff")) return R.string.alert_m23;
|
||||||
|
if (type.equals("Maintenance24Occlusion")) return R.string.alert_m24;
|
||||||
|
if (type.equals("Maintenance25LoantimeOver")) return R.string.alert_m25;
|
||||||
|
if (type.equals("Maintenance26CartridgeChangeNotCompleted")) return R.string.alert_m26;
|
||||||
|
if (type.equals("Maintenance27DataDownloadFailed")) return R.string.alert_m27;
|
||||||
|
if (type.equals("Maintenance28PauseModeTimeout")) return R.string.alert_m28;
|
||||||
|
if (type.equals("Maintenance29BatteryTypeNotSet")) return R.string.alert_m29;
|
||||||
|
if (type.equals("Maintenance30CartridgeTypeNotSet")) return R.string.alert_m30;
|
||||||
|
if (type.equals("Warning31CartridgeLow")) return R.string.alert_w31;
|
||||||
|
if (type.equals("Warning32BatteryLow")) return R.string.alert_w32;
|
||||||
|
if (type.equals("Warning33InvalidDateTime")) return R.string.alert_w33;
|
||||||
|
if (type.equals("Warning34EndOfWarranty")) return R.string.alert_w34;
|
||||||
|
if (type.equals("Warning36TBRCancelled")) return R.string.alert_w36;
|
||||||
|
if (type.equals("Warning38BolusCancelled")) return R.string.alert_w38;
|
||||||
|
if (type.equals("Warning39LoantimeWarning")) return R.string.alert_w39;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,10 @@ public class HistoryReceiver {
|
||||||
filter.addAction(ACTION_SYNC_STARTED);
|
filter.addAction(ACTION_SYNC_STARTED);
|
||||||
filter.addAction(ACTION_STILL_SYNCING);
|
filter.addAction(ACTION_STILL_SYNCING);
|
||||||
filter.addAction(ACTION_SYNC_FINISHED);
|
filter.addAction(ACTION_SYNC_FINISHED);
|
||||||
|
filter.addAction(ACTION_CANNULA_FILLED);
|
||||||
|
filter.addAction(ACTION_CARTRIDGE_INSERTED);
|
||||||
|
filter.addAction(ACTION_BATTERY_INSERTED);
|
||||||
|
filter.addAction(ACTION_OCCURENCE_OF_ALERT);
|
||||||
|
|
||||||
MainApp.instance().registerReceiver(historyReceiver, filter);
|
MainApp.instance().registerReceiver(historyReceiver, filter);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +78,6 @@ public class HistoryReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
|
||||||
case ACTION_SYNC_STARTED:
|
case ACTION_SYNC_STARTED:
|
||||||
status = SYNCING;
|
status = SYNCING;
|
||||||
break;
|
break;
|
||||||
|
@ -93,6 +96,18 @@ public class HistoryReceiver {
|
||||||
case ACTION_DAILY_TOTAL:
|
case ACTION_DAILY_TOTAL:
|
||||||
intentAdapter.processDailyTotalIntent(intent);
|
intentAdapter.processDailyTotalIntent(intent);
|
||||||
break;
|
break;
|
||||||
|
case ACTION_CANNULA_FILLED:
|
||||||
|
intentAdapter.processCannulaFilledIntent(intent);
|
||||||
|
break;
|
||||||
|
case ACTION_CARTRIDGE_INSERTED:
|
||||||
|
intentAdapter.processCartridgeInsertedIntent(intent);
|
||||||
|
break;
|
||||||
|
case ACTION_BATTERY_INSERTED:
|
||||||
|
intentAdapter.processBatteryInsertedIntent(intent);
|
||||||
|
break;
|
||||||
|
case ACTION_OCCURENCE_OF_ALERT:
|
||||||
|
intentAdapter.processOccurenceOfAlertIntent(intent);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -406,6 +406,10 @@ public class NSUpload {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void uploadError(String error) {
|
public static void uploadError(String error) {
|
||||||
|
uploadError(error, new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void uploadError(String error, Date date) {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("action", "dbAdd");
|
bundle.putString("action", "dbAdd");
|
||||||
|
@ -413,7 +417,7 @@ public class NSUpload {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
data.put("eventType", "Announcement");
|
data.put("eventType", "Announcement");
|
||||||
data.put("created_at", DateUtil.toISOString(new Date()));
|
data.put("created_at", DateUtil.toISOString(date));
|
||||||
data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name)));
|
data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name)));
|
||||||
data.put("notes", error);
|
data.put("notes", error);
|
||||||
data.put("isAnnouncement", true);
|
data.put("isAnnouncement", true);
|
||||||
|
|
27
app/src/main/res/values-de/insight_alerts.xml
Normal file
27
app/src/main/res/values-de/insight_alerts.xml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="alert_w31">Warnung W31: Ampulle fast leer</string>
|
||||||
|
<string name="alert_w32">Warnung W32: Batterie fast leer</string>
|
||||||
|
<string name="alert_w33">Warnung W33: Zeit/Datum ungültig</string>
|
||||||
|
<string name="alert_w34">Warnung W34: Garantie abgelaufen</string>
|
||||||
|
<string name="alert_w36">Warnung W36: TBR abgebrochen</string>
|
||||||
|
<string name="alert_w38">Warnung W38: Bolus abgebrochen</string>
|
||||||
|
<string name="alert_w39">Warnung W39: Leihdauer-Warnung</string>
|
||||||
|
|
||||||
|
<string name="alert_m20">Wartung M20: Keine Ampulle eingesetzt</string>
|
||||||
|
<string name="alert_m21">Wartung M21: Ampulle leer</string>
|
||||||
|
<string name="alert_m22">Wartung M22: Batterie leer</string>
|
||||||
|
<string name="alert_m23">Wartung M23: Sicherheitsabschaltung</string>
|
||||||
|
<string name="alert_m24">Wartung M24: Verstopfung</string>
|
||||||
|
<string name="alert_m25">Wartung M25: Leihdauer abgelaufen</string>
|
||||||
|
<string name="alert_m26">Wartung M26: Ampullenwechsel nicht abgeschlossen</string>
|
||||||
|
<string name="alert_m27">Wartung M27: Datenübertragung fehlgeschlagen</string>
|
||||||
|
<string name="alert_m28">Wartung M28: Zeitüberschreitung bei Pause</string>
|
||||||
|
<string name="alert_m29">Wartung M29: Batterietyp nicht eingestellt</string>
|
||||||
|
<string name="alert_m30">Wartung M30: Ampullentyp nicht eingestellt</string>
|
||||||
|
|
||||||
|
<string name="alert_e6">Fehler E6: Mechanikfehler</string>
|
||||||
|
<string name="alert_e7">Fehler E7: Elektronikfehler</string>
|
||||||
|
<string name="alert_e10">Fehler E10: Fehler beim Zurückfahren</string>
|
||||||
|
<string name="alert_e13">Fehler E13: Fehler in der Sprachanzeige</string>
|
||||||
|
</resources>
|
27
app/src/main/res/values/insight_alerts.xml
Normal file
27
app/src/main/res/values/insight_alerts.xml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="alert_w31">Warning W31: Cartridge low</string>
|
||||||
|
<string name="alert_w32">Warning W32: Battery low</string>
|
||||||
|
<string name="alert_w33">Warning W33: Invalid time/date</string>
|
||||||
|
<string name="alert_w34">Warning W34: End of warranty</string>
|
||||||
|
<string name="alert_w36">Warning W36: TBR cancelled</string>
|
||||||
|
<string name="alert_w38">Warning W38: Bolus canelled</string>
|
||||||
|
<string name="alert_w39">Warning W39: Loantime warning</string>
|
||||||
|
|
||||||
|
<string name="alert_m20">Maintenance M20: Cartridge not inserted</string>
|
||||||
|
<string name="alert_m21">Maintenance M21: Cartridge empty</string>
|
||||||
|
<string name="alert_m22">Maintenance M22: Battery empty</string>
|
||||||
|
<string name="alert_m23">Maintenance M23: Automatic off</string>
|
||||||
|
<string name="alert_m24">Maintenance M24: Occlusion</string>
|
||||||
|
<string name="alert_m25">Maintenance M25: Loantime over - end of operation</string>
|
||||||
|
<string name="alert_m26">Maintenance M26: Cartridge change not completed</string>
|
||||||
|
<string name="alert_m27">Maintenance M27: Data download failed</string>
|
||||||
|
<string name="alert_m28">Maintenance M28: Pause mode timeout</string>
|
||||||
|
<string name="alert_m29">Maintenance M29: Battery type not set</string>
|
||||||
|
<string name="alert_m30">Maintenance M30: Cartridge type not set</string>
|
||||||
|
|
||||||
|
<string name="alert_e6">Error E6: Mechanical error</string>
|
||||||
|
<string name="alert_e7">Error E7: Electronic error</string>
|
||||||
|
<string name="alert_e10">Error E10: Rewind error</string>
|
||||||
|
<string name="alert_e13">Error E13: Language error</string>
|
||||||
|
</resources>
|
|
@ -989,6 +989,8 @@
|
||||||
<string name="iobcobcalculator" translatable="false">IobCobCalculator</string>
|
<string name="iobcobcalculator" translatable="false">IobCobCalculator</string>
|
||||||
<string name="waitingfortimesynchronization">Waiting for time synchronization (%d sec)</string>
|
<string name="waitingfortimesynchronization">Waiting for time synchronization (%d sec)</string>
|
||||||
<string name="loopdisconnectedfor">Disconnected (%d m)</string>
|
<string name="loopdisconnectedfor">Disconnected (%d m)</string>
|
||||||
|
<string name="automatic_careportal_events">Automatic careportal events</string>
|
||||||
|
<string name="automatically_upload_insulin_cannula_and_battery_changes_to_nightscout">Automatically upload insulin, cannula and battery changes and pump alarms to Nightscout</string>
|
||||||
<string name="key_openapssmb_max_iob" translatable="false">openapsmb_max_iob</string>
|
<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_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="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>
|
||||||
|
|
|
@ -19,4 +19,9 @@
|
||||||
android:key="insight_real_tbr_cancel"
|
android:key="insight_real_tbr_cancel"
|
||||||
android:title="@string/insight_use_real_tbr_cancels"
|
android:title="@string/insight_use_real_tbr_cancels"
|
||||||
android:summary="@string/insight_actually_cancel_tbr_summary"/>
|
android:summary="@string/insight_actually_cancel_tbr_summary"/>
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="insight_automatic_careportal_events"
|
||||||
|
android:title="@string/automatic_careportal_events"
|
||||||
|
android:summary="@string/automatically_upload_insulin_cannula_and_battery_changes_to_nightscout"/>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in a new issue