From 33bdaa1768d618945bf13c893da21e38c2df9fd3 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Wed, 18 Mar 2020 22:39:06 +0000 Subject: [PATCH] - upload site change event to Nightscout, when Pod is initialized --- .../wizard/pages/InitPodRefreshAction.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java index 66d4ea1056..ab4e8d030a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java @@ -3,17 +3,31 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages; import com.atech.android.library.wizardpager.defs.action.AbstractCancelAction; import com.atech.android.library.wizardpager.defs.action.FinishActionInterface; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.db.CareportalEvent; +import info.nightscout.androidaps.db.Source; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; +import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity; import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; +import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.SP; /** * Created by andy on 12/11/2019 */ public class InitPodRefreshAction extends AbstractCancelAction implements FinishActionInterface { + private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); private PodManagementActivity podManagementActivity; private PodActionType actionType; @@ -42,6 +56,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodInitializing); } else { OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAttached); + uploadCareportalEvent(System.currentTimeMillis(), CareportalEvent.SITECHANGE); } } else { OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod); @@ -50,6 +65,28 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish podManagementActivity.refreshButtons(); } + private void uploadCareportalEvent(long date, String event) { + if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != 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); + CareportalEvent careportalEvent = new CareportalEvent(); + careportalEvent.date = date; + careportalEvent.source = Source.USER; + careportalEvent.eventType = event; + careportalEvent.json = data.toString(); + MainApp.getDbHelper().createOrUpdate(careportalEvent); + NSUpload.uploadCareportalEntryToNS(data); + } catch (JSONException e) { + LOG.error("Unhandled exception when uploading SiteChange event.", e); + } + } + + @Override public String getFinishActionText() { return "Finish_OK";