Skip to content

Commit

Permalink
Add remote bolus/carbs + otp entry for loop (#5598)
Browse files Browse the repository at this point in the history
Add a remote bolus entry field for users on Loop, along with support for an OTP field
  • Loading branch information
josep1972 authored Jun 12, 2020
1 parent 3d6f488 commit 5698ae2
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 7 deletions.
31 changes: 30 additions & 1 deletion lib/client/careportal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function init (client, $) {
submitHooks = {};

_.forEach(careportal.allEventTypes, function each (event) {
inputMatrix[event.val] = _.pick(event, ['bg', 'insulin', 'carbs', 'protein', 'fat', 'prebolus', 'duration', 'percent', 'absolute', 'profile', 'split', 'reasons', 'targets']);
inputMatrix[event.val] = _.pick(event, ['otp','remoteCarbs', 'remoteAbsorption', 'remoteBolus', 'bg', 'insulin', 'carbs', 'protein', 'fat', 'prebolus', 'duration', 'percent', 'absolute', 'profile', 'split', 'reasons', 'targets']);
submitHooks[event.val] = event.submitHook;
});
}
Expand Down Expand Up @@ -80,11 +80,18 @@ function init (client, $) {
$('#reasonLabel').css('display', displayType(reasons && reasons.length > 0));
$('#targets').css('display', displayType(inputMatrix[eventType]['targets']));

$('#otpLabel').css('display', displayType(inputMatrix[eventType]['otp']));
$('#remoteCarbsLabel').css('display', displayType(inputMatrix[eventType]['remoteCarbs']));
$('#remoteAbsorptionLabel').css('display', displayType(inputMatrix[eventType]['remoteAbsorption']));
$('#remoteBolusLabel').css('display', displayType(inputMatrix[eventType]['remoteBolus']));

$('#bg').css('display', displayType(inputMatrix[eventType]['bg']));
$('#insulinGivenLabel').css('display', displayType(inputMatrix[eventType]['insulin']));

$('#carbsGivenLabel').css('display', displayType(inputMatrix[eventType]['carbs']));
$('#proteinGivenLabel').css('display', displayType(inputMatrix[eventType]['protein']));
$('#fatGivenLabel').css('display', displayType(inputMatrix[eventType]['fat']));

$('#durationLabel').css('display', displayType(inputMatrix[eventType]['duration']));
$('#percentLabel').css('display', displayType(inputMatrix[eventType]['percent'] && $('#absolute').val() === ''));
$('#absoluteLabel').css('display', displayType(inputMatrix[eventType]['absolute'] && $('#percent').val() === ''));
Expand All @@ -99,6 +106,11 @@ function init (client, $) {

careportal.reasonable();

resetIfHidden(inputMatrix[eventType]['otp'], '#otp');
resetIfHidden(inputMatrix[eventType]['remoteCarbs'], '#remoteCarbs');
resetIfHidden(inputMatrix[eventType]['remoteAbsorption'], '#remoteAbsorption');
resetIfHidden(inputMatrix[eventType]['remoteBolus'], '#remoteBolus');

resetIfHidden(inputMatrix[eventType]['insulin'], '#insulinGiven');
resetIfHidden(inputMatrix[eventType]['carbs'], '#carbsGiven');
resetIfHidden(inputMatrix[eventType]['protein'], '#proteinGiven');
Expand Down Expand Up @@ -192,6 +204,12 @@ function init (client, $) {
$('#eventType').val('<none>');
$('#glucoseValue').val('').attr('placeholder', translate('Value in') + ' ' + client.settings.units);
$('#meter').prop('checked', true);

$('#otp').val('');
$('#remoteCarbs').val('');
$('#remoteAbsorption').val('');
$('#remoteBolus').val('');

$('#carbsGiven').val('');
$('#proteinGiven').val('');
$('#fatGiven').val('');
Expand All @@ -214,6 +232,10 @@ function init (client, $) {
var data = {
enteredBy: $('#enteredBy').val()
, eventType: eventType
, otp: $('#otp').val()
, remoteCarbs: $('#remoteCarbs').val()
, remoteAbsorption: $('#remoteAbsorption').val()
, remoteBolus: $('#remoteBolus').val()
, glucose: $('#glucoseValue').val().replace(',', '.')
, reason: selectedReason
, targetTop: $('#targetTop').val().replace(',', '.')
Expand Down Expand Up @@ -337,6 +359,8 @@ function init (client, $) {
}
}

// TODO: add check for remote (Bolus, Carbs, Absorption)

return {
allOk
, messages
Expand All @@ -360,6 +384,11 @@ function init (client, $) {
text[text.length - 1] += ' ' + translate('Cancel');
}

pushIf(data.remoteCarbs, translate('Remote Carbs') + ': ' + data.remoteCarbs);
pushIf(data.remoteAbsorption, translate('Remote Absorption') + ': ' + data.remoteAbsorption);
pushIf(data.remoteBolus, translate('Remote Bolus') + ': ' + data.remoteBolus);
pushIf(data.otp, translate('One Time Pascode') + ': ' + data.otp);

pushIf(data.glucose, translate('Blood Glucose') + ': ' + data.glucose);
pushIf(data.glucose, translate('Measurement Method') + ': ' + translate(data.glucoseType));

Expand Down
21 changes: 21 additions & 0 deletions lib/plugins/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ function init (ctx) {
});
}

// TODO: add OTP entry

return [
{
val: 'Temporary Override'
Expand All @@ -229,6 +231,7 @@ function init (ctx) {
, split: false
, targets: false
, reasons: reasonconf
, otp: true
, submitHook: postLoopNotification
},
{
Expand All @@ -245,10 +248,28 @@ function init (ctx) {
, split: false
, targets: false
, submitHook: postLoopNotification
},
{
val: 'Remote Carbs Entry'
, name: 'Remote Carbs Entry'
, remoteCarbs: true
, remoteAbsorption: true
, otp: true
, submitHook: postLoopNotification
},
{
val: 'Remote Bolus Entry'
, name: 'Remote Bolus Entry'
, remoteBolus: true
, otp: true
, submitHook: postLoopNotification
}
];
};

// TODO: Add event listener to customize labels


loop.updateVisualisation = function updateVisualisation (sbx) {
var prop = sbx.properties.loop;

Expand Down
41 changes: 36 additions & 5 deletions lib/server/loop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
//'use strict';

const apn = require('apn');

Expand All @@ -9,6 +9,10 @@ function init (env, ctx) {
}

loop.sendNotification = function sendNotification (data, remoteAddress, completion) {

// console.info("JAP");
// console.info(data);

if (env.extendedSettings.loop.apnsKey === undefined || env.extendedSettings.loop.apnsKey.length == 0) {
completion("Loop notification failed: LOOP_APNS_KEY not set.");
return;
Expand Down Expand Up @@ -63,7 +67,38 @@ function init (env, ctx) {
alert = "Cancel Temporary Override";
} else if (data.eventType === 'Temporary Override') {
payload["override-name"] = data.reason;
if (data.duration !== undefined && parseInt(data.duration) > 0) {
payload["override-duration-minutes"] = parseInt(data.duration);
}
alert = data.reasonDisplay + " Temporary Override";
} else if (data.eventType === 'Remote Carbs Entry') {
payload["carbs-entry"] = parseFloat(data.remoteCarbs);
if(payload["carbs-entry"] > 0.0 ) {
payload["absorption-time"] = 3.0;
if (data.remoteAbsorption !== undefined && parseFloat(data.remoteAbsorption) > 0.0) {
payload["absorption-time"] = parseFloat(data.remoteAbsorption);
}
if (data.otp !== undefined && data.otp.length > 0) {
payload["otp"] = ""+data.otp
}
alert = "Remote Carbs Entry: "+payload["carbs-entry"]+" grams\n";
alert += "Absorption Time: "+payload["absorption-time"]+" hours";
} else {
completion("Loop remote carbs failed. Incorrect carbs entry: ", data.remoteCarbs);
return;
}

} else if (data.eventType === 'Remote Bolus Entry') {
payload["bolus-entry"] = parseFloat(data.remoteBolus);
if(payload["bolus-entry"] > 0.0 ) {
alert = "Remote Bolus Entry: "+payload["bolus-entry"]+" U\n";
if (data.otp !== undefined && data.otp.length > 0) {
payload["otp"] = ""+data.otp
}
} else {
completion("Loop remote bolus failed. Incorrect bolus entry: ", data.remoteBolus);
return;
}
} else {
completion("Loop notification failed: Unhandled event type:", data.eventType);
return;
Expand All @@ -84,10 +119,6 @@ function init (env, ctx) {
notification.expiry = Math.round((Date.now() / 1000)) + 60 * 5; // Allow this to enact within 5 minutes.
notification.payload = payload;

if (data.duration && parseInt(data.duration) > 0) {
notification.payload["override-duration-minutes"] = parseInt(data.duration);
}

provider.send(notification, [loopSettings.deviceToken]).then( (response) => {
if (response.sent && response.sent.length > 0) {
completion();
Expand Down
Empty file added test
Empty file.
20 changes: 19 additions & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,24 @@
<span class="translate">Sensor<br></span>
</label>
</fieldset>
<fieldset id="nutrition">
<label id="remoteCarbsLabel" for="remoteCarbs" class="left-column short-label">
<span class="translate">Carbs</span>
<input type="number" step="any" min="0" id="remoteCarbs" placeholder="Amount in grams" class="titletranslate" pattern="[0-9.,]*" />
</label>
<label id="remoteAbsorptionLabel" for="remoteAbsorption" class="left-column short-label">
<span class="translate">Absorption</span>
<input type="number" step="any" min="0" id="remoteAbsorption" placeholder="Time in hours" class="titletranslate" pattern="[0-9.,]*" />
</label>
<label id="remoteBolusLabel" for="remoteBolus" class="left-column short-label">
<span class="translate">Bolus</span>
<input type="number" step="any" min="0" id="remoteBolus" placeholder="Amount in units" class="titletranslate" pattern="[0-9.,]*" />
</label>
<label id="otpLabel" for="otp" class="left-column short-label">
<span class="translate">OTP</span>
<input type="text" id="otp" placeholder="password" class="titletranslate" />
</label>

<fieldset id="nutrition" >
<label id="carbsGivenLabel" for="carbsGiven" class="left-column short-label">
<span class="translate">Carbs Given</span>
<input type="number" step="any" min="0" id="carbsGiven" placeholder="Amount in grams" class="titletranslate" pattern="\d*">
Expand All @@ -354,6 +371,7 @@
<input type="number" step="any" min="0" id="fatGiven" placeholder="Amount in grams" class="titletranslate" pattern="\d*">
</label>
</fieldset>

<label id="insulinGivenLabel" for="insulinGiven" class="left-column short-label">
<span class="translate">Insulin Given</span>
<input type="number" step="any" min="0" id="insulinGiven" placeholder="Amount in units" class="titletranslate" pattern="[0-9.,]*">
Expand Down

0 comments on commit 5698ae2

Please sign in to comment.