Skip to content

Commit

Permalink
Merge pull request #27 from benceszasz/dev
Browse files Browse the repository at this point in the history
Timezone determination, wrong device type correction
  • Loading branch information
benceszasz authored May 26, 2023
2 parents ba4d34e + 9953767 commit 98b7212
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<String, String> queryParams = null;

queryParams = new HashMap<String, String>();
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);
Expand Down Expand Up @@ -609,8 +662,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class DataUpload {

public long date;
public boolean mobileUploaded;
public String status;
public String device;
public String serialNumber;

Expand Down

0 comments on commit 98b7212

Please sign in to comment.