Skip to content

Commit

Permalink
BWP pill/tooltip improvements
Browse files Browse the repository at this point in the history
don't remove the pill when we don't have enough info
show reasons why there is no value
show < 0U when BWP is < 0, show the - value in the tooltip with comment that it might be covered by carbs
  • Loading branch information
jasoncalabrese committed Jul 10, 2015
1 parent 1a05647 commit 18e8d10
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 deletions lib/plugins/boluswizardpreview.js
@@ -1,6 +1,7 @@
'use strict';

var TEN_MINS = 10 * 60 * 1000;
var TIME_10_MINS = 10 * 60 * 1000;
var TIME_15_MINS = 15 * 60 * 1000;

function init() {

Expand All @@ -11,39 +12,28 @@ function init() {
bwp.label = 'Bolus Wizard Preview';
bwp.pluginType = 'pill-minor';

function hasRequiredInfo (sbx) {

var warnings = [];
function checkMissingInfo (sbx) {
var errors = [];
if (!sbx.data.profile || !sbx.data.profile.hasData()) {
warnings.push('Missing need a treatment profile');
}

if (!sbx.data.profile.getSensitivity(sbx.time) || !sbx.data.profile.getHighBGTarget(sbx.time) || !sbx.data.profile.getLowBGTarget(sbx.time)) {
warnings.push('Missing sens, target_high, or target_low treatment profile fields');
errors.push('Missing need a treatment profile');
} else if (!sbx.data.profile.getSensitivity(sbx.time) || !sbx.data.profile.getHighBGTarget(sbx.time) || !sbx.data.profile.getLowBGTarget(sbx.time)) {
errors.push('Missing sens, target_high, or target_low treatment profile fields');
}

if (!sbx.properties.iob) {
warnings.push('Missing IOB property');
}

if (sbx.lastSGV() < 40 || sbx.time - sbx.lastSGVMills() > TEN_MINS) {
warnings.push('Data isn\'t current');
errors.push('Missing IOB property');
}

if (warnings.length > 0) {
console.warn('BWP plugin doesn\'t have required info: ' + warnings.join('; '));
return false;
if (sbx.lastSGV() < 39 || sbx.time - sbx.lastSGVMills() > TIME_15_MINS) {
errors.push('Data isn\'t current');
}

return true;

return errors;
}

bwp.setProperties = function setProperties(sbx) {
sbx.offerProperty('bwp', function setBWP ( ) {
if (hasRequiredInfo(sbx)) {
return bwp.calc(sbx);
}
return bwp.calc(sbx);
});
};

Expand Down Expand Up @@ -91,17 +81,31 @@ function init() {
bwp.updateVisualisation = function updateVisualisation (sbx) {

var prop = sbx.properties.bwp;
if (prop === undefined) { return; }

// display text
var info = [
{label: 'Insulin on Board', value: prop.displayIOB + 'U'}
, {label: 'Sensitivity', value: '-' + sbx.data.profile.getSensitivity(sbx.time) + ' ' + sbx.units + '/U'}
, {label: 'Expected effect', value: prop.displayIOB + ' x -' + sbx.data.profile.getSensitivity(sbx.time) + ' = -' + prop.effectDisplay + ' ' + sbx.units}
, {label: 'Expected outcome', value: sbx.lastScaledSGV() + '-' + prop.effectDisplay + ' = ' + prop.outcomeDisplay + ' ' + sbx.units}
];

if (prop.tempBasalAdjustment) {
var info;

if (prop && prop.errors) {
info = [{label: 'Notice', value: 'required info missing'}];
_.forEach(prop.errors, function pushError (error) {
info.push({label: ' • ', value: error})
});
} else if (prop) {
info = [
{label: 'Insulin on Board', value: prop.displayIOB + 'U'}
, {label: 'Sensitivity', value: '-' + sbx.data.profile.getSensitivity(sbx.time) + ' ' + sbx.units + '/U'}
, {label: 'Expected effect', value: prop.displayIOB + ' x -' + sbx.data.profile.getSensitivity(sbx.time) + ' = -' + prop.effectDisplay + ' ' + sbx.units}
, {label: 'Expected outcome', value: sbx.lastScaledSGV() + '-' + prop.effectDisplay + ' = ' + prop.outcomeDisplay + ' ' + sbx.units}
];
} else {
info = [{label: 'Notice', value: 'required info missing'}];
}

if (prop && prop.tempBasalAdjustment) {

if (prop.bolusEstimateDisplay < 0) {
info.unshift({label: '-BWP', value: prop.bolusEstimateDisplay + 'U, maybe covered by carbs?'})
}

var carbsOrBolusMessage = 'too large adjustment needed, give carbs?';
var sign = '';
Expand All @@ -123,8 +127,15 @@ function init() {
}
}

var value;
if (prop && prop.bolusEstimateDisplay >= 0) {
value = prop.bolusEstimateDisplay + 'U';
} else if (prop && prop.bolusEstimateDisplay < 0) {
value = '< 0U'
}

sbx.pluginBase.updatePillText(bwp, {
value: prop.bolusEstimateDisplay + 'U'
value: value
, label: 'BWP'
, info: info
});
Expand All @@ -142,7 +153,10 @@ function init() {

results.lastSGV = sgv;

if (!hasRequiredInfo(sbx)) {
var errors = checkMissingInfo(sbx);

if (errors && errors.length > 0) {
results.errors = errors;
return results;
}

Expand Down Expand Up @@ -194,7 +208,7 @@ function init() {
snoozeBWP: Number(sbx.extendedSettings.snooze) || 0.10
, warnBWP: Number(sbx.extendedSettings.warn) || 0.50
, urgentBWP: Number(sbx.extendedSettings.urgent) || 1.00
, snoozeLength: (sbx.extendedSettings.snoozeMins && Number(sbx.extendedSettings.snoozeMins) * 60 * 1000) || TEN_MINS
, snoozeLength: (sbx.extendedSettings.snoozeMins && Number(sbx.extendedSettings.snoozeMins) * 60 * 1000) || TIME_10_MINS
};
}

Expand Down

0 comments on commit 18e8d10

Please sign in to comment.