Skip to content

Commit

Permalink
Merge pull request #26 from benceszasz/dev
Browse files Browse the repository at this point in the history
Multi follow server Care Partner
  • Loading branch information
benceszasz authored May 14, 2023
2 parents d2c3e94 + 5e2ccd7 commit ba4d34e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eveningoutpost.dexdrip.cgm.carelinkfollow.client;

import com.eveningoutpost.dexdrip.Models.JoH;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -119,50 +120,63 @@ public RecentData getRecentData() {
public RecentData getRecentData(String patientUsername) {

// Force login to get basic info
if (getAuthorizationToken() != null) {
// M2M
if (this.sessionM2MEnabled)
// Care Partner
if(this.sessionUser.isCarePartner())
return this.getM2MPatientData(patientUsername);
// Patient
else
// 7xxG
if(sessionMonitorData.isBle())
return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(),
sessionCountrySettings.blePereodicDataEndpoint);
// Standalone CGM
else
return this.getLast24Hours();
// Non M2M (old logic)
else if (sessionMonitorData.isBle())
return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(),
sessionCountrySettings.blePereodicDataEndpoint);
else
return this.getLast24Hours();
} else {
if (getAuthorizationToken() == null)
return null;
}

// 7xxG
if (this.isBleDevice(patientUsername))
return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(), patientUsername,
sessionCountrySettings.blePereodicDataEndpoint);
// Guardian + multi
else if (this.sessionM2MEnabled)
return this.getM2MPatientData(patientUsername);
// Guardian + single
else
return this.getLast24Hours();

}

public String getDefaultPatientUsername() {

// Force login to get basic info
if (getAuthorizationToken() != null) {
if (this.sessionUser != null)
if (this.sessionUser.isCarePartner())
if (this.sessionPatients != null && this.sessionPatients.length > 0)
return this.sessionPatients[0].username;
else
return null;
else
return this.sessionProfile.username;
if (getAuthorizationToken() == null)
return null;

// Care Partner + multi follow => first patient
if (this.sessionUser.isCarePartner() && this.sessionM2MEnabled)
if (this.sessionPatients != null && this.sessionPatients.length > 0)
return this.sessionPatients[0].username;
else
return null;
} else
// Not care partner or no multi follow => username from session profile
else if (this.sessionProfile.username != null)
return this.sessionProfile.username;
else
return null;
}

public boolean isBleDevice(String patientUsername){


// Force login to get basic info
if(getAuthorizationToken() == null)
return false;

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;
}
else
return this.sessionMonitorData.isBle();

}

// Get CareLink server address
protected String careLinkServer() {
if (CountryUtils.isUS(carelinkCountry))
Expand Down Expand Up @@ -206,10 +220,10 @@ protected boolean executeLoginProcedure() {
this.sessionProfile = this.getMyProfile();
this.sessionCountrySettings = this.getMyCountrySettings();
this.sessionM2MEnabled = this.getM2MEnabled().value;
//Care Partner + multi follow => patients
if(this.sessionUser.isCarePartner() && this.sessionM2MEnabled)
// Multi follow + Care Partner => patients
if(this.sessionM2MEnabled && this.sessionUser.isCarePartner())
this.sessionPatients = this.getM2MPatients();
//Patient or Care Partner & not multi follow => monitor data
// Single follow and/or Patient => monitor data
else
this.sessionMonitorData = this.getMonitorData();

Expand All @@ -221,8 +235,9 @@ protected boolean executeLoginProcedure() {
}

// Set login success if everything was ok:
if(this.sessionUser != null && this.sessionProfile != null && this.sessionCountrySettings != null && this.sessionM2MEnabled != null
&& ((this.sessionM2MEnabled && this.sessionUser.isCarePartner() && this.sessionPatients != null) || this.sessionMonitorData != null))
if(this.sessionUser != null && this.sessionProfile != null && this.sessionCountrySettings != null && this.sessionM2MEnabled != null &&
(((!this.sessionM2MEnabled || !this.sessionUser.isCarePartner()) && this.sessionMonitorData != null) ||
(this.sessionM2MEnabled && this.sessionUser.isCarePartner() && this.sessionPatients != null)))
lastLoginSuccess = true;
//Clear cookies, session infos if error occured during login process
else {
Expand Down Expand Up @@ -408,7 +423,7 @@ public RecentData getLast24Hours() {
}

// Periodic data from CareLink Cloud
public RecentData getConnectDisplayMessage(String username, String role, String endpointUrl) {
public RecentData getConnectDisplayMessage(String username, String role, String patientUsername, String endpointUrl) {

RequestBody requestBody = null;
Gson gson = null;
Expand All @@ -419,6 +434,8 @@ public RecentData getConnectDisplayMessage(String username, String role, String
userJson = new JsonObject();
userJson.addProperty("username", username);
userJson.addProperty("role", role);
if(!JoH.emptyString(patientUsername))
userJson.addProperty("patientId", patientUsername);

gson = new GsonBuilder().create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public class Patient {
public String lastDeviceFamily;
public boolean patientUsesConnect;

public boolean isBle() {
return lastDeviceFamily.contains("BLE");
}

}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@
<string name="summary_clfollow_pass">CareLink login password</string>
<string name="title_clfollow_country">CareLink Country</string>
<string name="summary_clfollow_country">CareLink country code</string>
<string name="title_clfollow_patient">CareLink Patient Username</string>
<string name="title_clfollow_patient">CareLink Patient</string>
<string name="summary_clfollow_patient">CareLink patient username</string>
<string name="title_clfollow_lang">CareLink Language</string>
<string name="summary_clfollow_lang">CareLink language code</string>
Expand Down

0 comments on commit ba4d34e

Please sign in to comment.