Skip to content

Commit

Permalink
Merge pull request #288 from tidepool-org/gniezen/tandem-2008-fix
Browse files Browse the repository at this point in the history
Tandem bug fix: Handling events around a pump shutdown
  • Loading branch information
gniezen committed Jun 3, 2016
2 parents 1e21a3e + 881f7bd commit 74cb415
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
18 changes: 16 additions & 2 deletions lib/drivers/tandemDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1666,8 +1666,14 @@ module.exports = function (config) {
.with_expectedExtended(bolus.bolex_insulin_requested);
}
record = record.set('index', bolus.index);
cfg.tzoUtil.fillInUTCInfo(record, bolus.jsDate);
records.push(record.done());

if(record.subType === 'normal' && bolus.insulin_delivered === undefined) {
debug('Only part of a bolus received, dropping:', bolus);
}
else{
cfg.tzoUtil.fillInUTCInfo(record, bolus.jsDate);
records.push(record.done());
}

// wizard records
if (_.includes(['standard', 'extended'], bolus.bolus_option) &&
Expand Down Expand Up @@ -1828,6 +1834,14 @@ module.exports = function (config) {

for (var b = 0; b < newDayRecords.length; ++b) {
var event = newDayRecords[b];

var nextEvent = data.log_records[data.log_records.indexOf(event) + 1 ];
if( nextEvent.header_id === PUMP_LOG_RECORDS.LID_TIME_CHANGED.value ||
nextEvent.header_id === PUMP_LOG_RECORDS.LID_DATE_CHANGED.value) {
debug('Dropping new-day event (',event.deviceTime,') followed by date/time change (', nextEvent.deviceTime,')');
continue;
};

var rate = event.commanded_basal_rate;
if ((rate !== null) && (rate > 0)) {
// new day event; breaks up flat-rate basals
Expand Down
16 changes: 11 additions & 5 deletions lib/tandem/tandemSimulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,17 @@ exports.make = function(config){

if (currBasal.deliveryType === 'temp') {
if(!currBasal.isAssigned('duration')) {
if(currTempBasal && currTempBasal.time_left) {
// temp basal was cancelled
currBasal.duration = currTempBasal.duration - currTempBasal.time_left;
}else{
currBasal.duration = currTempBasal.duration;
if(currTempBasal != null) {
if (currTempBasal.time_left) {
// temp basal was cancelled
currBasal.duration = currTempBasal.duration - currTempBasal.time_left;
}else{
currBasal.duration = currTempBasal.duration;
}
}
else {
currBasal.duration = 0;
annotate.annotateEvent(currBasal, 'basal/unknown-duration');
}
}
currBasal = currBasal.done();
Expand Down

0 comments on commit 74cb415

Please sign in to comment.