diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 93fef87342..75e830e654 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -346,7 +346,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoBgReadings().update(bgReading); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1201,6 +1201,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } + public CareportalEvent getCareportalEventFromTimestamp(long timestamp) { + try { + return getDaoCareportalEvents().queryForId(timestamp); + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return null; + } + @Nullable public CareportalEvent getLastCareportalEvent(String event) { try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java index 23f5e5ac3c..1ddc4fd4b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryIntentAdapter.java @@ -1,22 +1,25 @@ package info.nightscout.androidaps.plugins.PumpInsight.history; 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 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; /** * Created by jamorham on 27/01/2018. - * + *
* Parse inbound logbook intents
- *
*/
class HistoryIntentAdapter {
@@ -121,4 +124,80 @@ class HistoryIntentAdapter {
TDD tdd = new TDD(date.getTime(), bolus, basal, bolus + basal);
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;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java
index 0523eddc6e..0e254e3341 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryReceiver.java
@@ -43,6 +43,10 @@ public class HistoryReceiver {
filter.addAction(ACTION_SYNC_STARTED);
filter.addAction(ACTION_STILL_SYNCING);
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);
}
@@ -74,7 +78,6 @@ public class HistoryReceiver {
}
switch (action) {
-
case ACTION_SYNC_STARTED:
status = SYNCING;
break;
@@ -93,6 +96,18 @@ public class HistoryReceiver {
case ACTION_DAILY_TOTAL:
intentAdapter.processDailyTotalIntent(intent);
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;
}
}
};
diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java
index 96d24af4d4..9b9b940ef9 100644
--- a/app/src/main/java/info/nightscout/utils/NSUpload.java
+++ b/app/src/main/java/info/nightscout/utils/NSUpload.java
@@ -406,6 +406,10 @@ public class NSUpload {
}
public static void uploadError(String error) {
+ uploadError(error, new Date());
+ }
+
+ public static void uploadError(String error, Date date) {
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
@@ -413,7 +417,7 @@ public class NSUpload {
JSONObject data = new JSONObject();
try {
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("notes", error);
data.put("isAnnouncement", true);
diff --git a/app/src/main/res/values-de/insight_alerts.xml b/app/src/main/res/values-de/insight_alerts.xml
new file mode 100644
index 0000000000..886122994d
--- /dev/null
+++ b/app/src/main/res/values-de/insight_alerts.xml
@@ -0,0 +1,27 @@
+
+