Skip to content

Commit

Permalink
Merge branch 'dev' into wip/devicestatus
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Dec 6, 2015
2 parents 1421898 + fd43cb4 commit df69728
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 64 deletions.
6 changes: 5 additions & 1 deletion lib/client/boluscalc.js
Expand Up @@ -325,7 +325,11 @@ function init(client, $, plugins) {

// Show basal rate
var basal = client.sbx.data.profile.getTempBasal(record.eventTime);
$('#bc_basal').text((basal.treatment ? 'T: ' : '') + basal.tempbasal.toFixed(3));
var tempMark = '';
tempMark += basal.treatment ? 'T' : '';
tempMark += basal.combobolustreatment ? 'C' : '';
tempMark += tempMark ? ': ' : '';
$('#bc_basal').text(tempMark + basal.totalbasal.toFixed(3));
};

boluscalc.gatherBoluscalcData = function gatherBoluscalcData() {
Expand Down
108 changes: 73 additions & 35 deletions lib/client/careportal.js
Expand Up @@ -18,6 +18,7 @@ function init (client, $) {
, { val: 'Meal Bolus', name: 'Meal Bolus' }
, { val: 'Correction Bolus', name: 'Correction Bolus' }
, { val: 'Carb Correction', name: 'Carb Correction' }
, { val: 'Combo Bolus', name: 'Combo Bolus' }
, { val: 'Announcement', name: 'Announcement' }
, { val: 'Note', name: 'Note' }
, { val: 'Question', name: 'Question' }
Expand Down Expand Up @@ -57,24 +58,25 @@ function init (client, $) {
}

var inputMatrix = {
'<none>': { bg: true, insulin: true, carbs: true, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'BG Check': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Snack Bolus': { bg: true, insulin: true, carbs: true, prebolus: true, duration: false, percent: false, absolute: false, profile: false }
, 'Meal Bolus': { bg: true, insulin: true, carbs: true, prebolus: true, duration: false, percent: false, absolute: false, profile: false }
, 'Correction Bolus': { bg: true, insulin: true, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Carb Correction': { bg: true, insulin: false, carbs: true, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Announcement': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Note': { bg: true, insulin: false, carbs: false, prebolus: false, duration: true, percent: false, absolute: false, profile: false }
, 'Question': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Exercise': { bg: false, insulin: false, carbs: false, prebolus: false, duration: true, percent: false, absolute: false, profile: false }
, 'Site Change': { bg: true, insulin: true, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Sensor Start': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Sensor Change': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Insulin Change': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Temp Basal Start': { bg: true, insulin: false, carbs: false, prebolus: false, duration: true, percent: true, absolute: true, profile: false }
, 'Temp Basal End': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
, 'Profile Switch': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: true }
, 'D.A.D. Alert': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false }
'<none>': { bg: true, insulin: true, carbs: true, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'BG Check': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Snack Bolus': { bg: true, insulin: true, carbs: true, prebolus: true, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Meal Bolus': { bg: true, insulin: true, carbs: true, prebolus: true, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Correction Bolus': { bg: true, insulin: true, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Carb Correction': { bg: true, insulin: false, carbs: true, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Combo Bolus': { bg: true, insulin: true, carbs: true, prebolus: true, duration: true, percent: false, absolute: false, profile: false, split: true }
, 'Announcement': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Note': { bg: true, insulin: false, carbs: false, prebolus: false, duration: true, percent: false, absolute: false, profile: false, split: false }
, 'Question': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Exercise': { bg: false, insulin: false, carbs: false, prebolus: false, duration: true, percent: false, absolute: false, profile: false, split: false }
, 'Site Change': { bg: true, insulin: true, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Sensor Start': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Sensor Change': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Insulin Change': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Temp Basal Start': { bg: true, insulin: false, carbs: false, prebolus: false, duration: true, percent: true, absolute: true, profile: false, split: false }
, 'Temp Basal End': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
, 'Profile Switch': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: true, split: false }
, 'D.A.D. Alert': { bg: true, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false }
};

careportal.filterInputs = function filterInputs ( event ) {
Expand Down Expand Up @@ -102,13 +104,16 @@ function init (client, $) {
$('#absoluteLabel').css('display',displayType(inputMatrix[eventType]['absolute'] && $('#percent').val() === ''));
$('#profileLabel').css('display',displayType(inputMatrix[eventType]['profile']));
$('#preBolusLabel').css('display',displayType(inputMatrix[eventType]['prebolus']));
$('#insulinSplitLabel').css('display',displayType(inputMatrix[eventType]['split']));

resetIfHidden(inputMatrix[eventType]['insulin'], '#insulinGiven');
resetIfHidden(inputMatrix[eventType]['carbs'], '#carbsGiven');
resetIfHidden(inputMatrix[eventType]['duration'], '#duration');
resetIfHidden(inputMatrix[eventType]['absolute'], '#absolute');
resetIfHidden(inputMatrix[eventType]['percent'], '#percent');
resetIfHidden(inputMatrix[eventType]['prebolus'], '#preBolus');
resetIfHidden(inputMatrix[eventType]['split'], '#insulinSplitNow');
resetIfHidden(inputMatrix[eventType]['split'], '#insulinSplitExt');

maybePrevent(event);
};
Expand All @@ -121,9 +126,26 @@ function init (client, $) {
$('#eventType').change(careportal.filterInputs);
$('#percent').on('input', careportal.filterInputs);
$('#absolute').on('input', careportal.filterInputs);
$('#insulinSplitNow').on('input', careportal.adjustSplit);
$('#insulinSplitExt').on('input', careportal.adjustSplit);
careportal.filterInputs();
careportal.adjustSplit();
};

careportal.adjustSplit = function adjustSplit(event) {
if ($(this).attr('id') === 'insulinSplitNow') {
var nowval = parseInt($('#insulinSplitNow').val()) || 0;
$('#insulinSplitExt').val(100 - nowval);
$('#insulinSplitNow').val(nowval);
} else {
var extval = parseInt($('#insulinSplitExt').val()) || 0;
$('#insulinSplitNow').val(100 - extval);
$('#insulinSplitExt').val(extval);
}

maybePrevent(event);
};

careportal.resolveEventName = function resolveEventName(value) {
_.each(careportal.events, function eachEvent(e) {
if (e.val === value) {
Expand Down Expand Up @@ -189,6 +211,11 @@ function init (client, $) {
data.eventType = 'Temp Basal';
}

if (data.eventType.indexOf('Combo Bolus') > -1) {
data.splitNow = parseInt($('#insulinSplitNow').val()) || 0;
data.splitExt = parseInt($('#insulinSplitExt').val()) || 0;
}

return data;
}

Expand All @@ -215,7 +242,8 @@ function init (client, $) {

pushIf(data.carbs, translate('Carbs Given') + ': ' + data.carbs);
pushIf(data.insulin, translate('Insulin Given') + ': ' + data.insulin);
pushIf(data.duration, translate('Duration') + ': ' + data.duration);
pushIf(data.eventType === 'Combo Bolus', translate('Combo Bolus') + ': ' + data.splitNow + '% : ' + data.splitExt + '%');
pushIf(data.duration, translate('Duration') + ': ' + data.duration + ' ' + translate('mins'));
pushIf(data.percent, translate('Percent') + ': ' + data.percent);
pushIf('absolute' in data, translate('Basal value') + ': ' + data.absolute);
pushIf(data.profile, translate('Profile') + ': ' + data.profile);
Expand All @@ -229,26 +257,36 @@ function init (client, $) {

function confirmPost(data) {
if (window.confirm(buildConfirmText(data))) {
$.ajax({
method: 'POST',
url: '/api/v1/treatments/'
, headers: {
'api-secret': client.hashauth.hash()
}
, data: data
}).done(function treatmentSaved (response) {
console.info('treatment saved', response);
}).fail(function treatmentSaveFail (response) {
console.info('treatment saved', response);
alert(translate('Entering record failed') + '. ' + translate('Status') + ': ' + response.status);
});
postTreatment(data);
}
}

storage.set('enteredBy', data.enteredBy);
function postTreatment(data) {
if (data.eventType === 'Combo Bolus') {
data.enteredinsulin = data.insulin;
data.insulin = data.enteredinsulin * data.splitNow / 100;
data.relative = data.enteredinsulin * data.splitExt / 100 / data.duration * 60;
}

client.browserUtils.closeDrawer('#treatmentDrawer');
$.ajax({
method: 'POST',
url: '/api/v1/treatments/'
, headers: {
'api-secret': client.hashauth.hash()
}
}
, data: data
}).done(function treatmentSaved (response) {
console.info('treatment saved', response);
}).fail(function treatmentSaveFail (response) {
console.info('treatment saved', response);
alert(translate('Entering record failed') + '. ' + translate('Status') + ': ' + response.status);
});

storage.set('enteredBy', data.enteredBy);

client.browserUtils.closeDrawer('#treatmentDrawer');
}

careportal.dateTimeFocus = function dateTimeFocus (event) {
$('#othertime').prop('checked', true);
updateTime($(this), mergeDateAndTime());
Expand Down
18 changes: 18 additions & 0 deletions lib/client/chart.js
Expand Up @@ -14,6 +14,24 @@ function init (client, d3, $) {
var utils = client.utils;
var renderer = client.renderer;

// add defs for combo boluses
var dashWidth = 5;
d3.select('body').append('svg')
.append('defs')
.append('pattern')
.attr('id', 'hash')
.attr('patternUnits', 'userSpaceOnUse')
.attr('width', 6)
.attr('height', 6)
.attr('x', 0)
.attr('y', 0)
.append('g')
.style('fill', 'none')
.style('stroke', '#0099ff')
.style('stroke-width', 2)
.append('path').attr('d', 'M0,0 l' + dashWidth + ',' + dashWidth)
.append('path').attr('d', 'M' + dashWidth + ',0 l-' + dashWidth + ',' + dashWidth);

var localeFormatter = d3.locale(d3locales.locale(client.settings.language));

function brushStarted ( ) {
Expand Down
8 changes: 7 additions & 1 deletion lib/client/index.js
Expand Up @@ -310,6 +310,7 @@ client.init = function init(serverSettings, plugins) {
, sitechangeTreatments: client.sitechangeTreatments
, insulinchangeTreatments: client.insulinchangeTreatments
, sensorTreatments: client.sensorTreatments
, combobolusTreatments: client.combobolusTreatments
, profile: profile
, devicestatus: devicestatusData
, inRetroMode: inRetroMode()
Expand Down Expand Up @@ -846,6 +847,11 @@ client.init = function init(serverSettings, plugins) {
return t.eventType === 'Profile Switch';
}).sort(function (a,b) { return a.mills > b.mills; });

// filter & prepare 'Combo Bolus' events
client.combobolusTreatments = client.treatments.filter( function filterComboBoluses(t) {
return t.eventType === 'Combo Bolus';
}).sort(function (a,b) { return a.mills > b.mills; });

// filter & prepare temp basals
var tempbasalTreatments = client.treatments.filter( function filterBasals(t) {
return t.eventType && t.eventType.indexOf('Temp Basal') > -1;
Expand Down Expand Up @@ -882,7 +888,7 @@ client.init = function init(serverSettings, plugins) {
});

// Resend new treatments to profile
client.profilefunctions.updateTreatments(client.profileTreatments, client.tempbasalTreatments);
client.profilefunctions.updateTreatments(client.profileTreatments, client.tempbasalTreatments, client.combobolusTreatments);


// Do some reporting on the console
Expand Down
31 changes: 24 additions & 7 deletions lib/client/renderer.js
Expand Up @@ -446,6 +446,7 @@ function init (client, d3) {
client.tooltip.html('<strong>' + translate('Time') + ':</strong> ' + client.formatTime(new Date(treatment.mills)) + '<br/>' + '<strong>' + translate('Treatment type') + ':</strong> ' + translate(client.careportal.resolveEventName(treatment.eventType)) + '<br/>' +
(treatment.carbs ? '<strong>' + translate('Carbs') + ':</strong> ' + treatment.carbs + '<br/>' : '') +
(treatment.insulin ? '<strong>' + translate('Insulin') + ':</strong> ' + treatment.insulin + '<br/>' : '') +
(treatment.enteredinsulin ? '<strong>' + translate('Combo Bolus') + ':</strong> ' + treatment.enteredinsulin + 'U, ' + treatment.splitNow + '% : ' + treatment.splitExt + '%, ' + translate('Duration') + ': ' + treatment.duration + '<br/>' : '') +
(treatment.glucose ? '<strong>' + translate('BG') + ':</strong> ' + treatment.glucose + (treatment.glucoseType ? ' (' + translate(treatment.glucoseType) + ')' : '') + '<br/>' : '') +
(treatment.enteredBy ? '<strong>' + translate('Entered By') + ':</strong> ' + treatment.enteredBy + '<br/>' : '') +
(treatment.notes ? '<strong>' + translate('Notes') + ':</strong> ' + treatment.notes : '') +
Expand Down Expand Up @@ -537,6 +538,7 @@ function init (client, d3) {
var notemplinedata = [];
var basalareadata = [];
var tempbasalareadata = [];
var comboareadata = [];
var from = chart().brush.extent()[0].getTime();
var to = Math.max(chart().brush.extent()[1].getTime(), client.sbx.time) + client.forecastTime;

Expand All @@ -546,14 +548,20 @@ function init (client, d3) {
while (date <= to) {
var basalvalue = profile.getTempBasal(date);
if (!_.isEqual(lastbasal, basalvalue)) {
linedata.push( { d: date, b: basalvalue.tempbasal } );
linedata.push( { d: date, b: basalvalue.totalbasal } );
notemplinedata.push( { d: date, b: basalvalue.basal } );
if (basalvalue.treatment) {
if (basalvalue.combobolustreatment && basalvalue.combobolustreatment.relative) {
tempbasalareadata.push( { d: date, b: basalvalue.tempbasal } );
basalareadata.push( { d: date, b: 0 } );
comboareadata.push( { d: date, b: basalvalue.totalbasal } );
} else if (basalvalue.treatment) {
tempbasalareadata.push( { d: date, b: basalvalue.totalbasal } );
basalareadata.push( { d: date, b: 0 } );
comboareadata.push( { d: date, b: 0 } );
} else {
basalareadata.push( { d: date, b: basalvalue.tempbasal } );
tempbasalareadata.push( { d: date, b: 0 } );
basalareadata.push( { d: date, b: basalvalue.totalbasal } );
comboareadata.push( { d: date, b: 0 } );
}
}
lastbasal = basalvalue;
Expand All @@ -562,10 +570,11 @@ function init (client, d3) {

var toTempBasal = profile.getTempBasal(to);

linedata.push( { d: to, b: toTempBasal.tempbasal } );
linedata.push( { d: to, b: toTempBasal.totalbasal } );
notemplinedata.push( { d: to, b: toTempBasal.basal } );
basalareadata.push( { d: to, b: toTempBasal.basal } );
tempbasalareadata.push( { d: to, b: toTempBasal.tempbasal } );
tempbasalareadata.push( { d: to, b: toTempBasal.totalbasal } );
comboareadata.push( { d: to, b: toTempBasal.totalbasal } );

var max = d3.max(linedata, function (d) { return d.b; });
chart().maxBasalValue = max;
Expand All @@ -576,6 +585,7 @@ function init (client, d3) {
chart().basals.selectAll('.notempline').remove().data(notemplinedata);
chart().basals.selectAll('.basalarea').remove().data(basalareadata);
chart().basals.selectAll('.tempbasalarea').remove().data(tempbasalareadata);
chart().basals.selectAll('.comboarea').remove().data(comboareadata);

var valueline = d3.svg.line()
.interpolate('step-after')
Expand Down Expand Up @@ -622,7 +632,14 @@ function init (client, d3) {
.attr('fill-opacity', .2)
.attr('stroke-width', 1)
.attr('d', area);
//console.log(tempbasals);

g.append('path')
.attr('class', 'area comboarea')
.datum(comboareadata)
.attr('fill', 'url(#hash)')
.attr('fill-opacity', .2)
.attr('stroke-width', 1)
.attr('d', area);

client.tempbasalTreatments.forEach(function (t) {
// only if basal and focus interval overlap and there is a chance to fit
Expand All @@ -635,7 +652,7 @@ function init (client, d3) {
.attr('dy', '.35em')
.attr('x', chart().xScaleBasals((Math.max(t.mills, from) + Math.min(t.mills + times.mins(t.duration).msecs, to))/2))
.attr('y', 10)
.text((t.percent ? (t.percent > 0 ? '+' : '') + t.percent + '%' : '') + (isNaN(t.absolute) ? '' : t.absolute + 'U'));
.text((t.percent ? (t.percent > 0 ? '+' : '') + t.percent + '%' : '') + (isNaN(t.absolute) ? '' : t.absolute + 'U') + (t.relative ? 'C: +' + t.relative + 'U' : ''));
// better hide if not fit
if (text.node().getBBox().width > chart().xScaleBasals(t.mills + times.mins(t.duration).msecs) - chart().xScaleBasals(t.mills)) {
text.attr('display', 'none');
Expand Down
3 changes: 3 additions & 0 deletions lib/language.js
Expand Up @@ -5214,6 +5214,9 @@ function init() {
,fi: 'ISF'
,bg: 'ISF'
}
,'Combo Bolus' : {
cs: 'Kombinovaný bolus'
}

};

Expand Down

0 comments on commit df69728

Please sign in to comment.