Skip to content

Commit

Permalink
Merge branch 'dev' into new_cache_location
Browse files Browse the repository at this point in the history
  • Loading branch information
sulkaharo authored Aug 30, 2022
2 parents 6978a90 + df85fd2 commit 2e4551e
Show file tree
Hide file tree
Showing 16 changed files with 817 additions and 1,356 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [12.x, 14.x, 16.x]
mongodb-version: [4.2, 4.4]

steps:
Expand Down
14 changes: 7 additions & 7 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function configure (app, wares, ctx, env) {
res.entries_err = err;
return next();
});
}, format_entries);
}, wares.obscure_device, format_entries);

/**
* @module get#/entries/:spec
Expand Down Expand Up @@ -389,7 +389,7 @@ function configure (app, wares, ctx, env) {
prepReqModel(req, req.params.model);
query_models(req, res, next);
}
}, format_entries);
}, wares.obscure_device, format_entries);

/**
* @module get#/entries
Expand All @@ -400,7 +400,7 @@ function configure (app, wares, ctx, env) {
* `find[date]`.
*
*/
api.get('/entries', ifModifiedSinceCTX, query_models, format_entries);
api.get('/entries', ifModifiedSinceCTX, query_models, wares.obscure_device, format_entries);

/**
* @function echo_query
Expand Down Expand Up @@ -738,7 +738,7 @@ function configure (app, wares, ctx, env) {
* @routed
* @response 200 /definitions/Entries
*/
api.get('/times/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, query_models, format_entries);
api.get('/times/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, query_models, wares.obscure_device, format_entries);

api.get('/count/:storage/where', prep_storage, count_records, format_results);

Expand All @@ -753,7 +753,7 @@ function configure (app, wares, ctx, env) {
/api/v1/slice/entries/dateString/mbg/2015.json
```
*/
api.get('/slice/:storage/:field/:type?/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, query_models, format_entries);
api.get('/slice/:storage/:field/:type?/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, query_models, wares.obscure_device, format_entries);

/**
* @module post#/entries/preview
Expand All @@ -765,7 +765,7 @@ function configure (app, wares, ctx, env) {
// setting this flag tells insert_entries to not actually store the results
req.persist_entries = false;
next();
}, insert_entries, format_entries);
}, insert_entries, wares.obscure_device, format_entries);

// Protect endpoints with authenticated api.
if (app.enabled('api')) {
Expand All @@ -780,7 +780,7 @@ function configure (app, wares, ctx, env) {
// setting this flag tells insert_entries to store the results
req.persist_entries = true;
next();
}, insert_entries, format_entries);
}, insert_entries, wares.obscure_device, format_entries);

/**
* @module delete#/entries/:spec
Expand Down
5 changes: 3 additions & 2 deletions lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ function loadEntries(ddata, ctx, callback) {
}
};

var obscureDeviceProvenance = ctx.settings.obscureDeviceProvenance;
ctx.entries.list(q, function(err, results) {

if (err) {
Expand All @@ -213,15 +214,15 @@ function loadEntries(ddata, ctx, callback) {
_id: element._id,
mgdl: Number(element.mbg),
mills: element.date,
device: element.device,
device: obscureDeviceProvenance || element.device,
type: 'mbg'
});
} else if (element.sgv) {
sgvs.push({
_id: element._id,
mgdl: Number(element.sgv),
mills: element.date,
device: element.device,
device: obscureDeviceProvenance || element.device,
direction: element.direction,
filtered: element.filtered,
unfiltered: element.unfiltered,
Expand Down
6 changes: 5 additions & 1 deletion lib/data/ddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ function init () {
ddata.tempbasalTreatments = ddata.processDurations(tempbasalTreatments, false);

// filter temp target
var tempTargetTreatments = ddata.treatments.filter(function filterTargets (t) {
var tempTargetTreatments = ddata.treatments.filter(function filterTargets (tt) {

// Clone the treatment before modifying it
let t = _.cloneDeep(tt);

//check for a units being sent
if (t.units) {
if (t.units == 'mmol') {
Expand Down
3 changes: 2 additions & 1 deletion lib/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function init (fs) {
language.lang = 'en';

language.languages = [
{ code: 'bg', file: 'bg_BG', language: 'Български', speechCode: 'bg-BG' }
{ code: 'ar', file: 'ar_SA', language: 'اللغة العربية', speechCode: 'ar-SA' }
, { code: 'bg', file: 'bg_BG', language: 'Български', speechCode: 'bg-BG' }
, { code: 'cs', file: 'cs_CZ', language: 'Čeština', speechCode: 'cs-CZ' }
, { code: 'de', file: 'de_DE', language: 'Deutsch', speechCode: 'de-DE' }
, { code: 'dk', file: 'da_DK', language: 'Dansk', speechCode: 'dk-DK' }
Expand Down
6 changes: 4 additions & 2 deletions lib/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var wares = {
sendJSONStatus : require('./send-json-status'),
bodyParser : require('body-parser'),
compression : require('compression')
compression : require('compression'),
obscureDeviceProvenance: require('./obscure-provenance')
};

function extensions (list) {
Expand All @@ -26,7 +27,8 @@ function configure (env) {
limit: '1Mb'
}),
compression: wares.compression,
extensions: extensions
extensions: extensions,
obscure_device: wares.obscureDeviceProvenance(env)
};
}

Expand Down
15 changes: 15 additions & 0 deletions lib/middleware/obscure-provenance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var _ = require('lodash');

module.exports = function create_device_obscurity (env) {
function obscure_device (req, res, next) {
if (res.entries && env.settings.obscureDeviceProvenance) {
var entries = _.cloneDeep(res.entries);
for (var i = 0; i < entries.length; i++) {
entries[i].device = env.settings.obscureDeviceProvenance;
}
res.entries = entries;
}
next( );
}
return obscure_device;
}
34 changes: 21 additions & 13 deletions lib/plugins/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function init (ctx) {
, split: false
, targets: false
, reasons: reasonconf
, otp: true
, otp: true
, submitHook: postLoopNotification
},
{
Expand All @@ -252,24 +252,24 @@ function init (ctx) {
{
val: 'Remote Carbs Entry'
, name: 'Remote Carbs Entry'
, remoteCarbs: true
, remoteAbsorption: true
, otp: true
, remoteCarbs: true
, remoteAbsorption: true
, otp: true
, submitHook: postLoopNotification
},
{
val: 'Remote Bolus Entry'
, name: 'Remote Bolus Entry'
, remoteBolus: true
, otp: true
, remoteBolus: true
, otp: true
, submitHook: postLoopNotification
}
];
};

// TODO: Add event listener to customize labels


loop.updateVisualisation = function updateVisualisation (sbx) {
var prop = sbx.properties.loop;

Expand Down Expand Up @@ -356,13 +356,21 @@ function init (ctx) {

function addLastEnacted () {
if (prop.lastEnacted) {
var canceled = prop.lastEnacted.rate === 0 && prop.lastEnacted.duration === 0;
var valueParts = []

var valueParts = [
'<b>Temp Basal' + (canceled ? ' Canceled' : ' Started') + '</b>'
, canceled ? '' : ' ' + prop.lastEnacted.rate.toFixed(2) + 'U/hour for ' + prop.lastEnacted.duration + 'm'
, valueString(', ', prop.lastEnacted.reason)
];
if (prop.lastEnacted.bolusVolume) {
valueParts.push('<b>Automatic Bolus</b>')
valueParts.push(' ' + prop.lastEnacted.bolusVolume + 'U')
if (prop.lastEnacted.rate === 0 && prop.lastEnacted.duration === 0) {
valueParts.push(' (Temp Basal Canceled)')
}
} else if (prop.lastEnacted.rate === 0 && prop.lastEnacted.duration === 0) {
valueParts.push('<b>Temp Basal Canceled</b>')
} else if (prop.lastEnacted.rate != null) {
valueParts.push('<b>Temp Basal Started</b>')
valueParts.push(' ' + prop.lastEnacted.rate.toFixed(2) + 'U/hour for ' + prop.lastEnacted.duration + 'm')
}
valueParts.push(valueString(', ', prop.lastEnacted.reason))

valueParts = concatIOB(valueParts);
valueParts = concatCOB(valueParts);
Expand Down
19 changes: 11 additions & 8 deletions lib/plugins/pump.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function init (ctx) {
var prefs = pump.getPrefs(sbx);

if (!prefs.enableAlerts) { return; }

pump.warnOnSuspend = prefs.warnOnSuspend;

var data = prepareData(sbx.properties.pump, prefs, sbx);
Expand Down Expand Up @@ -130,7 +130,7 @@ function init (ctx) {
}
}
});

if (result.extended) {
info.push({label: '------------', value: ''});
_.forOwn(result.extended, function(value, key) {
Expand Down Expand Up @@ -236,11 +236,7 @@ function init (ctx) {
function updateReservoir (prefs, result) {
if (result.reservoir) {
result.reservoir.label = 'Reservoir';
if (result.reservoir_display_override) {
result.reservoir.display = result.reservoir_display_override;
} else {
result.reservoir.display = result.reservoir.value.toPrecision(3) + 'U';
}
result.reservoir.display = result.reservoir.value.toPrecision(3) + 'U';
if (result.reservoir.value < prefs.urgentRes) {
result.reservoir.level = levels.URGENT;
result.reservoir.message = 'URGENT: Pump Reservoir Low';
Expand All @@ -250,11 +246,17 @@ function init (ctx) {
} else {
result.reservoir.level = levels.NONE;
}
} else if (result.manufacturer === 'Insulet' && result.model === 'Eros') {
} else if (result.manufacturer === 'Insulet') {
result.reservoir = {
label: 'Reservoir', display: '50+ U'
}
}
if (result.reservoir_display_override) {
result.reservoir.display = result.reservoir_display_override;
}
if (result.reservoir_level_override) {
result.reservoir.level = result.reservoir_level_override;
}
}

function updateBattery (type, prefs, result, batteryWarn) {
Expand Down Expand Up @@ -319,6 +321,7 @@ function init (ctx) {
, clock: pump.clock ? { value: moment(pump.clock) } : null
, reservoir: pump.reservoir || pump.reservoir === 0 ? { value: pump.reservoir } : null
, reservoir_display_override: pump.reservoir_display_override || null
, reservoir_level_override: pump.reservoir_level_override || null
, manufacturer: pump.manufacturer
, model: pump.model
, extended: pump.extended || null
Expand Down
5 changes: 2 additions & 3 deletions lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,9 @@ function init () {
};

sbx.displayBg = function displayBg (entry) {
var isDex = entry && (!entry.device || entry.device === 'dexcom' || entry.device === 'share2');
if (isDex && Number(entry.mgdl) === 39) {
if (Number(entry.mgdl) === 39) {
return 'LOW';
} else if (isDex && Number(entry.mgdl) === 401) {
} else if (Number(entry.mgdl) === 401) {
return 'HIGH';
} else {
return sbx.scaleEntry(entry);
Expand Down
2 changes: 1 addition & 1 deletion lib/server/bootevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function boot (env, language) {

const isLTS = process.release.lts ? true : false;

if (isLTS && (semver.satisfies(nodeVersion, '^14.0.0') || semver.satisfies(nodeVersion, '^12.0.0') || semver.satisfies(nodeVersion, '^10.0.0'))) {
if (isLTS && (semver.satisfies(nodeVersion, '^16.0.0') || semver.satisfies(nodeVersion, '^14.0.0') || semver.satisfies(nodeVersion, '^12.0.0') || semver.satisfies(nodeVersion, '^10.0.0'))) {
//Latest Node 10 LTS and Node 12 LTS are recommended and supported.
//Require at least Node 8 LTS and Node 10 LTS without known security issues
console.debug('Node LTS version ' + nodeVersion + ' is supported');
Expand Down
26 changes: 18 additions & 8 deletions lib/server/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,34 @@ function init (env, ctx) {
payload["override-duration-minutes"] = parseInt(data.duration);
}
alert = data.reasonDisplay + " Temporary Override";
} else if (data.eventType === 'Remote Carbs Entry') {
} else if (data.eventType === 'Remote Carbs Entry') {
payload["carbs-entry"] = parseFloat(data.remoteCarbs);
if(payload["carbs-entry"] > 0.0 ) {
if(payload["carbs-entry"] > 0.0 ) {
payload["absorption-time"] = 3.0;
if (data.remoteAbsorption !== undefined && parseFloat(data.remoteAbsorption) > 0.0) {
payload["absorption-time"] = parseFloat(data.remoteAbsorption);
}
if (data.otp !== undefined && data.otp.length > 0) {
payload["otp"] = ""+data.otp
}
if (data.created_at !== undefined) {
payload['start-time'] = data.created_at;
}
alert = "Remote Carbs Entry: "+payload["carbs-entry"]+" grams\n";
alert += "Absorption Time: "+payload["absorption-time"]+" hours";
} else {
} else {
completion("Loop remote carbs failed. Incorrect carbs entry: ", data.remoteCarbs);
return;
}
} else if (data.eventType === 'Remote Bolus Entry') {

} else if (data.eventType === 'Remote Bolus Entry') {
payload["bolus-entry"] = parseFloat(data.remoteBolus);
if(payload["bolus-entry"] > 0.0 ) {
if(payload["bolus-entry"] > 0.0 ) {
alert = "Remote Bolus Entry: "+payload["bolus-entry"]+" U\n";
if (data.otp !== undefined && data.otp.length > 0) {
payload["otp"] = ""+data.otp
}
} else {
} else {
completion("Loop remote bolus failed. Incorrect bolus entry: ", data.remoteBolus);
return;
}
Expand All @@ -112,11 +115,18 @@ function init (env, ctx) {
alert += " - " + data.enteredBy
}

// Track time notification was sent
let now = new Date()
payload['sent-at'] = now.toISOString();

// Expire after 5 minutes.
let expiration = new Date(now.getTime() + 5 * 60 * 1000)
payload['expiration'] = expiration.toISOString();

let notification = new apn.Notification();
notification.alert = alert;
notification.topic = loopSettings.bundleIdentifier;
notification.contentAvailable = 1;
notification.expiry = Math.round((Date.now() / 1000)) + 60 * 5; // Allow this to enact within 5 minutes.
notification.payload = payload;

provider.send(notification, [loopSettings.deviceToken]).then( (response) => {
Expand Down
6 changes: 3 additions & 3 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function init (env, ctx, server) {
ctx.store.collection(collection).findOne({ '_id': id }
, function(err, results) {
console.log('Got results', results);
if (!err) {
if (!err && results !== null) {
ctx.bus.emit('data-update', {
type: data.collection
, op: 'update'
Expand Down Expand Up @@ -266,7 +266,7 @@ function init (env, ctx, server) {
ctx.store.collection(collection).findOne({ '_id': objId }
, function(err, results) {
console.log('Got results', results);
if (!err) {
if (!err && results !== null) {
ctx.bus.emit('data-update', {
type: data.collection
, op: 'update'
Expand Down Expand Up @@ -294,7 +294,7 @@ function init (env, ctx, server) {
socket.on('dbAdd', function dbAdd (data, callback) {
console.log(LOG_WS + 'dbAdd client ID: ', socket.client.id, ' data: ', data);
var collection = supportedCollections[data.collection];
var maxtimediff = times.mins(1).msecs;
var maxtimediff = times.secs(2).msecs;

var check = checkConditions('dbAdd', data);
if (check) {
Expand Down
Loading

0 comments on commit 2e4551e

Please sign in to comment.