Skip to content

Commit

Permalink
Send 'pump_status' entry type instead, with more data
Browse files Browse the repository at this point in the history
  • Loading branch information
mddub committed Oct 7, 2015
1 parent 9a2f542 commit 4791fb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 14 additions & 11 deletions scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
);
}

Expand All @@ -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');
Expand Down

0 comments on commit 4791fb0

Please sign in to comment.