From 4791fb03ee35fa76c752cf1feff37ad6762465bf Mon Sep 17 00:00:00 2001 From: Mark Wilson Date: Tue, 6 Oct 2015 20:18:40 -0700 Subject: [PATCH] Send 'pump_status' entry type instead, with more data --- README.md | 3 ++- scraper.js | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 642789c..6debe55 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ ## Currently supported data * Sensor glucose values -* Active insulin (sent to Nightscout as entries of type `reported_active_bolus`) +* Pump: active insulin, reservoir level in units, reservoir level as percentage +* MiniMed Connect: battery level, connection status to phone, connection status to pump * Pump model and serial number (included in all Nightscout entries) **Potential future data**: See [this sensor-disabled gist] and [this sensor-enabled gist] for sample data provided by CareLink Connect. In particular, I'd love to include BG trend (up/down arrows) based on `lastSGTrend`. Please [get in touch] if you use an Enlite sensor and would like to help. diff --git a/scraper.js b/scraper.js index 29e346a..1284527 100644 --- a/scraper.js +++ b/scraper.js @@ -8,7 +8,7 @@ phantom.injectJs('./vendor/casperjs/bin/bootstrap.js'); var Rusha = require('./vendor/rusha.js'); -var ACTIVE_INSULIN_ENTRY_TYPE = 'reported_active_bolus'; +var PUMP_STATUS_ENTRY_TYPE = 'pump_status'; var SENSOR_GLUCOSE_ENTRY_TYPE = 'sgv'; var isNewData = (function() { @@ -31,15 +31,18 @@ function addTimeToEntry(pumpTimeString, entry) { function transformForNightscout(data) { var entries = []; - if(data['activeInsulin'] && data['activeInsulin']['datetime'] && data['activeInsulin']['amount'] >= 0) { + if(data['sMedicalDeviceTime']) { + var entry = {'type': PUMP_STATUS_ENTRY_TYPE}; + ['conduitBatteryLevel', 'conduitInRange', 'conduitMedicalDeviceInRange', 'reservoirLevelPercent', 'reservoirAmount', 'medicalDeviceBatteryLevelPercent'].forEach(function(key) { + if(data[key] !== undefined) { + entry[key] = data[key]; + } + }); + if(data['activeInsulin'] && data['activeInsulin']['datetime'] && data['activeInsulin']['amount'] >= 0) { + entry['activeInsulin'] = data['activeInsulin']['amount']; + } entries.push( - addTimeToEntry( - data['activeInsulin']['datetime'], - { - 'type': ACTIVE_INSULIN_ENTRY_TYPE, - 'insulin': data['activeInsulin']['amount'] - } - ) + addTimeToEntry(data['sMedicalDeviceTime'], entry) ); } @@ -66,8 +69,8 @@ function transformForNightscout(data) { entry['device'] = 'MiniMed Connect ' + data['medicalDeviceFamily'] + ' ' + data['medicalDeviceSerialNumber']; }); - var activeEntry = entries.filter(function(e) { return e['type'] === ACTIVE_INSULIN_ENTRY_TYPE; })[0]; - var activeIns = activeEntry ? activeEntry['insulin'] + ' at ' + activeEntry['dateString'] : 'unknown'; + var statusEntry = entries.filter(function(e) { return e['type'] === PUMP_STATUS_ENTRY_TYPE; })[0]; + var activeIns = statusEntry && statusEntry['activeInsulin'] ? statusEntry['activeInsulin'] + ' at ' + statusEntry['dateString'] : 'unknown'; var sgvEntries = entries.filter(function(e) { return e['type'] === SENSOR_GLUCOSE_ENTRY_TYPE; }); var recentSgv = sgvEntries.length ? sgvEntries[sgvEntries.length - 1]['sgv'] + ' at ' + sgvEntries[sgvEntries.length - 1]['dateString'] : 'unknown'; casper.log('active insulin ' + activeIns, 'info');