From 8315155f2fbf1d105cabdda0c5e30b99b959efbd Mon Sep 17 00:00:00 2001 From: benceszasz Date: Fri, 26 May 2023 16:07:46 +0200 Subject: [PATCH 1/2] Use LastAlarm as alternative source for timezone identification --- .../cgm/carelinkfollow/CareLinkDataProcessor.java | 4 ++-- .../cgm/carelinkfollow/client/CareLinkClient.java | 9 ++++++++- .../dexdrip/cgm/carelinkfollow/message/Alarm.java | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java index e9db22b..40d7268 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java @@ -278,8 +278,8 @@ static synchronized void processRecentData(final RecentData recentData, final bo // Only Guardian Connect, NGP has all in notifications if (recentData.isGM() && recentData.lastAlarm != null) { //Add notification from alarm - if (recentData.lastAlarm.datetime != null && recentData.lastAlarm.kind != null) - addNotification(recentData.lastAlarm.datetime, recentData.getDeviceFamily(), recentData.lastAlarm); + if (recentData.lastAlarm.datetimeAsDate != null && recentData.lastAlarm.kind != null) + addNotification(recentData.lastAlarm.datetimeAsDate, recentData.getDeviceFamily(), recentData.lastAlarm); } } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java index 118b154..6a7b5f0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java @@ -609,8 +609,15 @@ protected void correctTimeInRecentData(RecentData recentData){ timezoneMissing = true; //offset = this.getZonedDate(recentData.lastSG.datetime).getOffset(); - offsetString = this.getZoneOffset(recentData.lastSG.datetime); + //Try get TZ offset string: lastSG or lastAlarm + if(recentData.lastSG != null && recentData.lastSG.datetime != null) + offsetString = this.getZoneOffset(recentData.lastSG.datetime); + else + offsetString = this.getZoneOffset(recentData.lastAlarm.datetime); + + if(recentData.lastAlarm != null && recentData.lastAlarm.datetime != null) + recentData.lastAlarm.datetimeAsDate = parseDateString(recentData.lastAlarm.datetime); //Build correct dates with timezone recentData.sMedicalDeviceTime = recentData.sMedicalDeviceTime + offsetString; recentData.medicalDeviceTimeAsString = recentData.medicalDeviceTimeAsString + offsetString; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java index 905ef58..8eb712b 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java @@ -9,7 +9,8 @@ public String getMessageAlarmCode(){ } public int code; - public Date datetime; + public String datetime; + public Date datetimeAsDate; public String type; public boolean flash; public String kind; From 99537673ea434fe57d04c854ecedf083ca0b0bd7 Mon Sep 17 00:00:00 2001 From: benceszasz Date: Fri, 26 May 2023 16:09:47 +0200 Subject: [PATCH 2/2] Get device type for patient account using last uploads, because device type can be wrong after changing from standalone CGM to pump --- .../carelinkfollow/client/CareLinkClient.java | 55 ++++++++++++++++++- .../carelinkfollow/message/DataUpload.java | 1 + 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java index 6a7b5f0..350d230 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java @@ -53,6 +53,14 @@ public Profile getSessionProfile() { public CountrySettings getSessionCountrySettings() { return sessionCountrySettings; } + protected RecentUploads sessionRecentUploads; + public RecentUploads getSessionRecentUploads() { + return sessionRecentUploads; + } + protected Boolean sessionDeviceIsBle; + public Boolean getSessionDeviceIsBle() { + return sessionDeviceIsBle; + } protected Boolean sessionM2MEnabled; public boolean getSessionM2MEnabled(){ return sessionM2MEnabled; @@ -157,11 +165,25 @@ else if (this.sessionProfile.username != null) public boolean isBleDevice(String patientUsername){ + Boolean recentUploadBle; + + // Session device already determined + if(sessionDeviceIsBle != null) + return sessionDeviceIsBle; // Force login to get basic info if(getAuthorizationToken() == null) return false; + // Determine session device by recent uploads + if(!this.sessionUser.isCarePartner()){ + recentUploadBle = this.isRecentUploadBle(); + if(recentUploadBle != null){ + this.sessionDeviceIsBle = recentUploadBle; + return sessionDeviceIsBle; + } + } + if(this.sessionM2MEnabled && this.sessionUser.isCarePartner()) if(patientUsername == null || this.sessionPatients == null) return false; @@ -177,6 +199,20 @@ public boolean isBleDevice(String patientUsername){ } + public Boolean isRecentUploadBle(){ + + if(this.sessionRecentUploads == null) + return null; + + for(DataUpload upload : this.sessionRecentUploads.recentUploads){ + if(upload.device.toUpperCase().contains("MINIMED")) + return true; + else if(upload.device.toUpperCase().contains("GUARDIAN")) + return false; + } + return null; + } + // Get CareLink server address protected String careLinkServer() { if (CountryUtils.isUS(carelinkCountry)) @@ -215,10 +251,16 @@ protected boolean executeLoginProcedure() { this.lastResponseCode = consentResponse.code(); consentResponse.close(); - // Get basic infos + // Get required sessions infos + // User this.sessionUser = this.getMyUser(); + // Profile this.sessionProfile = this.getMyProfile(); + // Country settings this.sessionCountrySettings = this.getMyCountrySettings(); + // Recent uploads (only for patients) + if(!this.sessionUser.isCarePartner()) + this.sessionRecentUploads = this.getRecentUploads(30); this.sessionM2MEnabled = this.getM2MEnabled().value; // Multi follow + Care Partner => patients if(this.sessionM2MEnabled && this.sessionUser.isCarePartner()) @@ -370,6 +412,17 @@ public Profile getMyProfile() { return this.getData(this.careLinkServer(), "patient/users/me/profile", null, null, Profile.class); } + // Recent uploads + public RecentUploads getRecentUploads(int numOfUploads) { + + Map queryParams = null; + + queryParams = new HashMap(); + queryParams.put("numUploads", String.valueOf(numOfUploads)); + + return this.getData(this.careLinkServer(), "patient/dataUpload/recentUploads", queryParams, null, RecentUploads.class); + } + // Monitoring data public MonitorData getMonitorData() { return this.getData(this.careLinkServer(), "patient/monitor/data", null, null, MonitorData.class); diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/DataUpload.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/DataUpload.java index 4787681..258c9a2 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/DataUpload.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/DataUpload.java @@ -4,6 +4,7 @@ public class DataUpload { public long date; public boolean mobileUploaded; + public String status; public String device; public String serialNumber;