Skip to content

Commit

Permalink
add support for canceling a temp target
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Apr 27, 2016
1 parent db819b5 commit 3a293dc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 8 additions & 2 deletions lib/client/careportal.js
Expand Up @@ -219,9 +219,15 @@ function init (client, plugins, $) {
}

if (data.eventType.indexOf('Temp Basal') > -1) {
data.duration = 0;
data.eventType = 'Temp Basal';
}

if (data.eventType.indexOf('Temporary Target Cancel') > -1) {
data.duration = 0;
data.eventType = 'Temporary Target';
}

if (data.eventType.indexOf('Combo Bolus') > -1) {
data.splitNow = parseInt($('#insulinSplitNow').val()) || 0;
data.splitExt = parseInt($('#insulinSplitExt').val()) || 0;
Expand Down Expand Up @@ -280,8 +286,8 @@ function init (client, plugins, $) {
}

$.ajax({
method: 'POST',
url: '/api/v1/treatments/'
method: 'POST'
, url: '/api/v1/treatments/'
, headers: {
'api-secret': client.hashauth.hash()
}
Expand Down
5 changes: 5 additions & 0 deletions lib/plugins/openaps.js
Expand Up @@ -216,6 +216,11 @@ function init() {
, { name: 'Manual' }
]
}
, {
val: 'Temporary Target Cancel'
, name: 'Temporary Target Cancel'
, bg: false, insulin: false, carbs: false, prebolus: false, duration: false, percent: false, absolute: false, profile: false, split: false
}
, {
val: 'OpenAPS Offline'
, name: 'OpenAPS Offline'
Expand Down
14 changes: 9 additions & 5 deletions lib/treatments.js
Expand Up @@ -166,20 +166,24 @@ function prepareData(obj) {
}
}

function deleteIfNaN (field) {
console.info('>>>', field, obj[field], isNaN(obj[field]));
if (isNaN(obj[field])) {
delete obj[field];
}
}

deleteIfEmpty('targetTop');
deleteIfEmpty('targetBottom');
deleteIfEmpty('carbs');
deleteIfEmpty('insulin');
deleteIfEmpty('duration');
deleteIfEmpty('percent');
deleteIfEmpty('relative');
deleteIfEmpty('notes');
deleteIfEmpty('preBolus');

//special handling for absolute to support temp to 0
if (isNaN(obj.absolute)) {
delete obj.absolute;
}
deleteIfNaN('absolute');
deleteIfNaN('duration');

if (obj.glucose === 0 || isNaN(obj.glucose)) {
delete obj.glucose;
Expand Down

0 comments on commit 3a293dc

Please sign in to comment.