Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote bolus/carbs + otp entry for loop #5598

Merged
merged 54 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d9e7842
Merge pull request #1 from nightscout/dev
josep1972 Dec 13, 2019
f6f5405
Test for remote carbs entry
Mar 25, 2020
03fa2f3
default 180 mins for duration
Mar 25, 2020
e60cbb1
debug
Mar 25, 2020
0a82ad6
debug
Mar 25, 2020
34b299d
debug
Mar 25, 2020
675c93c
debug
Mar 25, 2020
ef25394
debug
Mar 25, 2020
d731d4b
debug
Mar 25, 2020
c73ad93
debug
Mar 25, 2020
ec582e1
debug
Mar 25, 2020
ba3ef0f
debug
Mar 25, 2020
51f95f1
debug
Mar 25, 2020
7731510
debug
Mar 25, 2020
e475de7
debug
Mar 25, 2020
10a79d4
debug
Mar 25, 2020
25e548d
debug
Mar 25, 2020
d624657
debug
Mar 25, 2020
5b3cbae
debug
Mar 25, 2020
9028adf
debug
Mar 25, 2020
8c1cb40
debug
Mar 25, 2020
c586c55
New Treatement Entries
Mar 25, 2020
a1991c8
Careportal Additions For Remote Loop Control
Mar 25, 2020
033ebd1
Changes for Remote Carbs Entry
Mar 25, 2020
42e76b2
Fixed Typo
Mar 25, 2020
afff5cf
Implemented Remote Bolus
Mar 25, 2020
ad446ca
Implemented Remote Bolus
Mar 25, 2020
12087a7
Added OTP
Mar 25, 2020
686747c
Fix typo
Mar 25, 2020
630ad02
fixed otp input box
Mar 26, 2020
b4150ec
send otp as string
Mar 26, 2020
8dd6a4f
initial branch
Mar 28, 2020
f9dbb5d
Merge branch 'dev' into dev_otp
josep1972 Apr 3, 2020
e288c78
fixed index
Apr 3, 2020
7f595df
fixed index
Apr 3, 2020
18138ff
fixed empty nutrition fieldset
Apr 3, 2020
34e8310
fix nutiriton fieldset'
Apr 3, 2020
47de5bd
fixed empty nutrition fieldset
Apr 3, 2020
2b3e683
fix nutiriton fieldset check'
Apr 3, 2020
0d11827
fix nutiriton fieldset check'
Apr 3, 2020
47070d5
fix nutiriton fieldset check'
Apr 3, 2020
4932e8a
fix nutiriton fieldset check'
Apr 3, 2020
9dd43f8
fix nutiriton fieldset check'
Apr 3, 2020
b7254f0
fix nutiriton fieldset check'
Apr 3, 2020
62b0028
index fix for nutrition
Apr 3, 2020
b8e4cf3
index fix for nutrition
Apr 3, 2020
244cecc
added nutrition container for better control
Apr 3, 2020
02fffe3
added nutrition container for better control
Apr 3, 2020
0524db6
added nutrition container for better control
Apr 3, 2020
83bc353
added nutrition container for better control 2
Apr 3, 2020
21054d6
added nutrition container for better control 2
Apr 3, 2020
fc7b56f
nutrition fix 3
Apr 3, 2020
a75ec50
nutriton fix 4
Apr 3, 2020
53dbf8d
final version
Apr 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -327,6 +349,8 @@ function init (client, $) {
}
}

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

return {
allOk
, messages
Expand All @@ -350,6 +374,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 @@ -327,7 +327,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 @@ -341,6 +358,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