From 7c2655f0a8f262d692dc6447bd97d3d4bcc56ffe Mon Sep 17 00:00:00 2001 From: benceszasz Date: Fri, 26 May 2023 13:37:14 +0200 Subject: [PATCH] Wrong device type may occur in CareLink, try to extract actual device type from data uploads for patient accounts. --- .../carelinkfollow/client/CareLinkClient.java | 79 ++++++++++++++++++- .../carelinkfollow/message/DataUpload.java | 1 + .../carelinkfollow/message/RecentUploads.java | 9 +++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentUploads.java 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 f6345d049f..f27ca0b137 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 @@ -3,12 +3,14 @@ import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ActiveNotification; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.ClearedNotification; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.CountrySettings; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.DataUpload; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Marker; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.MonitorData; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Profile; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.Patient; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.M2MEnabled; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentData; +import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.RecentUploads; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.SensorGlucose; import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.User; import com.eveningoutpost.dexdrip.models.JoH; @@ -109,7 +111,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; @@ -171,7 +180,7 @@ public RecentData getRecentData(String patientUsername) { return null; // 7xxG - if (this.sessionMonitorData.isBle()) + if (this.isBleDevice(patientUsername)) return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(), patientUsername, sessionCountrySettings.blePereodicDataEndpoint); // Guardian + multi @@ -203,6 +212,58 @@ else if (this.sessionProfile.username != null) return 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; + + // Patient: device from recent uploads if possible + if(!this.sessionUser.isCarePartner()){ + recentUploadBle = this.isRecentUploadBle(); + if(recentUploadBle != null){ + this.sessionDeviceIsBle = recentUploadBle; + return sessionDeviceIsBle; + } + } + + // Care partner (+M2M): device from patient list + if(this.sessionM2MEnabled && this.sessionUser.isCarePartner()) + if(patientUsername == null || this.sessionPatients == null) + return false; + else { + for (int i = 0; i < this.sessionPatients.length; i++) { + if (sessionPatients[i].username.equals(patientUsername)) + return sessionPatients[i].isBle(); + } + return false; + } + // Other: classic method (session monitor data) + else + return this.sessionMonitorData.isBle(); + + } + + 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; + } + //Authentication methods protected boolean executeLoginProcedure() { @@ -247,6 +308,9 @@ protected boolean executeLoginProcedure() { this.sessionProfile = this.getMyProfile(); // Country settings this.sessionCountrySettings = this.getMyCountrySettings(); + // Recent uploads (only for patients) + if(!this.sessionUser.isCarePartner()) + this.sessionRecentUploads = this.getRecentUploads(30); // Multi follow enabled on server this.sessionM2MEnabled = this.getM2MEnabled().value; // Multi follow + Care Partner => patients @@ -428,6 +492,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 4787681c57..258c9a27da 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; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentUploads.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentUploads.java new file mode 100644 index 0000000000..6c79d8ae6c --- /dev/null +++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentUploads.java @@ -0,0 +1,9 @@ +package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message; + +import java.util.List; + +public class RecentUploads { + + public List recentUploads; + +}