diff --git a/lib/drivers/tandemDriver.js b/lib/drivers/tandemDriver.js index c971af7803..c7687c3de0 100644 --- a/lib/drivers/tandemDriver.js +++ b/lib/drivers/tandemDriver.js @@ -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) && @@ -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 diff --git a/lib/tandem/tandemSimulator.js b/lib/tandem/tandemSimulator.js index ec54b67b4a..3915d75e93 100644 --- a/lib/tandem/tandemSimulator.js +++ b/lib/tandem/tandemSimulator.js @@ -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();