Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Small bug fixes in librelinkup and futher improvements to carelink #17

Merged
merged 6 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/sources/librelinkup.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function linkUpSource (opts, axios) {
},
sessionFromAuth (auth) {
function isPatient (elem) {
return elem.patientId == opts.patientId;
return elem.patientId == opts.linkUpPatientId;
}
var token = auth.data.authTicket.token;
var headers = {
Expand Down Expand Up @@ -161,7 +161,7 @@ function linkUpSource (opts, axios) {
}
};
function tracker_for ( ) {
var AxiosTracer = require('../../trace-axios');
var AxiosTracer = require('../trace-axios');
var tracker = AxiosTracer(http);
return tracker;
}
Expand Down
38 changes: 27 additions & 11 deletions lib/sources/minimedcarelink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var tough = require('tough-cookie');

var ACS = require('axios-cookiejar-support');
var software = require('../../../package.json');
var user_agent_string = [software.name, `${software.name}@${software.version}`, 'M2M@V6', software.homepage].join(', ');
//var user_agent_string = [software.name, `${software.name}@${software.version}`, 'M2M@V6', software.homepage].join(', ');
var user_agent_string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46";

// https://github.com/NightscoutFoundation/xDrip/blob/990df119a8404cff56cb68b92a7e0bb640da95ef/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java#L559
// https://github.com/nightscout/minimed-connect-to-nightscout/blob/master/carelink.js
Expand Down Expand Up @@ -552,28 +553,38 @@ function carelinkSource (opts, axios) {
return elem;
}

function reassign_zone ( ) {
function reassign_zone(item) {
if (lastConduitDateTime) {
var zoneOffsetMatch = lastConduitDateTime.match(/[+-]\d{2}:\d{2}$/);
var zoneOffset = zoneOffsetMatch ? zoneOffsetMatch[0] : '00:00';
return adjust_conduit_timezone.bind(null, zoneOffset);
var zoneOffsetMatch = lastConduitDateTime.match(/[+-]\d{2}:\d{2}$/);
var zoneOffset = zoneOffsetMatch ? zoneOffsetMatch[0] : '00:00';
return adjust_conduit_timezone(zoneOffset, item);
}
return id;
return id(item);
}

function id(x) { return x; }

function id (x) { return x; }
function adjust_conduit_timezone (zoneOffset, item) {
item.datetime = item.datetime.replace('Z', `${zoneOffset}`);
function adjust_conduit_timezone(zoneOffset, item) {
// Handle item.datetime
if (item.datetime && item.datetime.endsWith('Z')) {
item.datetime = item.datetime.replace('Z', `${zoneOffset}`);
}

// Handle item.pump.clock
if (item.pump && item.pump.clock) {
// Replace the current zone offset at the end of the string with the new one
item.pump.clock = item.pump.clock.replace(/[+-]\d{2}:\d{2}$/, `${zoneOffset}`);
}

return item;
}

var entries = data.sgs
.filter(has_datetime)
.map(reassign_zone( ))
.map(reassign_zone)
.map(sgs_to_sgv)
.filter(is_missing)
.map(assign_device);
// var devicestatus = [{ }];

// only the last item has its trend described.
var lastItem = entries.pop( )
Expand All @@ -587,6 +598,11 @@ function carelinkSource (opts, axios) {

var deviceStatus = deviceStatusEntry(data, deviceName);
var devicestatus = [ deviceStatus ];
if (lastConduitDateTime) {
var zoneOffsetMatch = lastConduitDateTime.match(/[+-]\d{2}:\d{2}$/);
var zoneOffset = zoneOffsetMatch ? zoneOffsetMatch[0] : '00:00';
deviceStatus = adjust_conduit_timezone(zoneOffset, deviceStatus);
}
var treatments = [ ];
console.log("INCOMING TALLY", data.sgs.length, 'reduced', entries.length);
console.log("INCOMING DEVICESTATUS", deviceStatus);
Expand Down