Skip to content

Commit

Permalink
Remove formatting in calculator output
Browse files Browse the repository at this point in the history
  • Loading branch information
jplomas committed Jan 23, 2021
1 parent 58c397c commit ac5d6b3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 48 deletions.
74 changes: 43 additions & 31 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
/* eslint no-console: 0, max-len: 0, prefer-destructuring: 0 */
/* global $, ClipboardJS, calc, FastClick */

var parseResult = function (advice) {
var output = '';
if (advice.type === 'additional') {
output += '<br><br><strong>Additional advice:</strong><br>';
}
advice.text.forEach(function (element) {
output += element + '<br>';
});
return output;
};

var gocalc = function () {
var result = null;
var current = parseFloat($('#d2').dropdown('get value'));
Expand All @@ -9,10 +20,13 @@ var gocalc = function () {
console.log('rate = ' + rate);
console.log('current = ' + current);
console.log('previous = ' + previous);
result = calc.ongoingRate(current, previous, rate).rate + calc.ongoingRate(current, previous, rate).advice;
result = calc.ongoingRate(current, previous, rate).rate + parseResult(calc.ongoingRate(current, previous, rate).advice);
if (result) {
var hex = calc.ongoingRate(current, previous, rate).hex;
result = result + '<br><br><strong>Calculation reference code (record in casenotes):</strong><br><span id="foo">' + hex + '</span>';
result = result
+ '<br><br><strong>Calculation reference code (record in casenotes):</strong><br><span id="foo">'
+ hex
+ '</span>';
result += '<br><span id="copyAdvice" data-clipboard-target="#foo"><button class="ui mini button"><i class="ui copy icon"></i> Copy code to clipboard</button></span>';
return result;
}
Expand All @@ -24,12 +38,9 @@ $(function () {
});

$(document).ready(function () {
$('.message .close')
.on('click', function () {
$(this)
.closest('.message')
.transition('fade');
});
$('.message .close').on('click', function () {
$(this).closest('.message').transition('fade');
});
var clipboard = new ClipboardJS('#copyAdvice');
clipboard.on('success', function (e) {
console.info('Action:', e.action);
Expand Down Expand Up @@ -74,32 +85,33 @@ $(document).ready(function () {
}
if (gov.last) {
$('#res').html(`
<p>Code <strong>${code}</strong> was generated <strong>${gov.date}</strong></p>
<p>The user entered the following data:</p>
<div class="ui secondary segment">
<p>Current blood glucose [mmol/L]: <strong>${gov.current}</strong></p>
<p>Previous blood glucose [mmol/L]: <strong>${gov.last}</strong></p>
<p>Current Insulin rate [ml/hr of 1 iU/ml]: <strong>${gov.rate}</strong></p>
</div>
<p>For these values, the calculator generated the following output:</p>
<div class="ui secondary segment">
<p><strong>New Insulin rate:</strong><br />
${calc.ongoingRate(gov.current, gov.last, gov.rate).rate + calc.ongoingRate(gov.current, gov.last, gov.rate).advice}</p>
</div><br>`);
<p>Code <strong>${code}</strong> was generated <strong>${gov.date}</strong></p>
<p>The user entered the following data:</p>
<div class="ui secondary segment">
<p>Current blood glucose [mmol/L]: <strong>${gov.current}</strong></p>
<p>Previous blood glucose [mmol/L]: <strong>${gov.last}</strong></p>
<p>Current Insulin rate [ml/hr of 1 iU/ml]: <strong>${gov.rate}</strong></p>
</div>
<p>For these values, the calculator generated the following output:</p>
<div class="ui secondary segment">
<p><strong>New Insulin rate:</strong><br />
${calc.ongoingRate(gov.current, gov.last, gov.rate).rate + parseResult(calc.ongoingRate(gov.current, gov.last, gov.rate).advice)}
</p>
</div><br>`);
return true;
}
if (gov.current) {
$('#res').html(`
<p>Code <strong>${code}</strong> was generated <strong>${gov.date}</strong></p>
<p>The user entered the following data:</p>
<div class="ui secondary segment">
<p>Current blood glucose [mmol/L]: <strong>${gov.current}</strong></p>
</div>
<p>For these values, the calculator generated the following output:</p>
<div class="ui secondary segment">
<p><strong>Advice:</strong><br />
${calc.startingRate(gov.current).advice}</p>
</div><br>`);
<p>Code <strong>${code}</strong> was generated <strong>${gov.date}</strong></p>
<p>The user entered the following data:</p>
<div class="ui secondary segment">
<p>Current blood glucose [mmol/L]: <strong>${gov.current}</strong></p>
</div>
<p>For these values, the calculator generated the following output:</p>
<div class="ui secondary segment">
<p><strong>Advice:</strong><br />
${parseResult(calc.startingRate(gov.current).advice)}</p>
</div><br>`);
return true;
}
$('#res').html('<p>Invalid code entered.<br /><br /></p>');
Expand Down Expand Up @@ -157,7 +169,7 @@ $(document).ready(function () {
console.log('BG = ' + value);
if (value) {
var r = calc.startingRate(value);
var result = r.advice;
var result = parseResult(r.advice);
var hex = r.hex;
result = result + '<br><br><strong>Calculation reference code (record in casenotes):</strong><br><span id="foo">' + hex + '</span>';
result += '<br><span id="copyAdvice" data-clipboard-target="#foo"><button class="ui mini button"><i class="ui copy icon"></i> Copy code to clipboard</button></span>';
Expand Down
34 changes: 17 additions & 17 deletions js/insulin-calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var startingRate = function (value) {
rate = '';
}
var hex = createGovernance({ f: 'a', glucose: value });
return { advice: result, rate: rate, hex: hex };
return { advice: { type: 'normal', text: [result] }, rate: rate, hex: hex };
};

var ongoingRate = function (current, previous, rate) {
Expand Down Expand Up @@ -160,22 +160,22 @@ var ongoingRate = function (current, previous, rate) {
var result = newR + 'ml/hr';
r.rate = result;
r.rateNum = newR;
if (A11 === '1') { r.advice = '<br><br><strong>Additional advice:</strong><br>STOP INSULIN FOR AT LEAST 1 HOUR<br>Follow hypoglycaemia protocol.<br>Give IV dextrose immediately & ensure background nutrition or glucose intake.<br>Recheck blood glucose in 15, 30 and 60 minutes until stable.'; }
if (A11 === '2') { r.advice = '<br><br><strong>Additional advice:</strong><br>STOP INSULIN FOR AT LEAST 1 HOUR<br>Give IV dextrose immediately if blood glucose < 4mmol/L & ensure background nutrition or glucose intake.<br> If blood glucose is greater than 4mmol/l then it is falling rapidly. Recheck blood glucose in 30 and 60 minutes.'; }
if (A11 === '3') { r.advice = '<br><br><strong>Additional advice:</strong><br>STOP INSULIN FOR AT LEAST 1 HOUR<br>Ensure background nutrition or glucose intake. Recheck blood glucose in 1 hour.'; }
if (A11 === '10') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour.<br>If blood glucose has been between 6-10mmol consider 2 hourly blood glucose checks.'; }
if (A11 === '17') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour. '; }
if (A11 === '18') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1-2 hours.<br>(1 hour if drop in blood glucose > 2 mmol/L in last hour)'; }
if (A11 === '29') { r.advice = '<br><br><strong>Additional advice:</strong><br>STOP INSULIN FOR AT LEAST 1 HOUR<br>Restart insulin if blood glucose > 10mmol/L'; }
if (A11 === '32') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 2 hours.'; }
if (A11 === '33') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour.'; }
if (A11 === '34') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour.'; }
if (A11 === '35') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour.'; }
if (A11 === '36') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 2 hours.'; }
if (A11 === '37') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour.'; }
if (A11 === '38') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour.'; }
if (A11 === '53') { r.advice = '<br><br><strong>Additional advice:</strong><br>Recheck blood glucose in 1 hour.<br>Caution as blood glucose is approaching bottom of target range.'; }
if (A11 === '54') { r.advice = '<br><br><strong>Additional advice:</strong><br>If blood glucose and calorie intake have been stable for last 2 hours move to 2 hourly BG checks. '; }
if (A11 === '1') { r.advice = { type: 'additional', text: ['STOP INSULIN FOR AT LEAST 1 HOUR', 'Follow hypoglycaemia protocol.', 'Give IV dextrose immediately & ensure background nutrition or glucose intake.', 'Recheck blood glucose in 15, 30 and 60 minutes until stable.'] }; }
if (A11 === '2') { r.advice = { type: 'additional', text: ['STOP INSULIN FOR AT LEAST 1 HOUR', 'Give IV dextrose immediately if blood glucose < 4mmol/L & ensure background nutrition or glucose intake.', ' If blood glucose is greater than 4mmol/l then it is falling rapidly. Recheck blood glucose in 30 and 60 minutes.'] }; }
if (A11 === '3') { r.advice = { type: 'additional', text: ['STOP INSULIN FOR AT LEAST 1 HOUR', 'Ensure background nutrition or glucose intake. Recheck blood glucose in 1 hour.'] }; }
if (A11 === '10') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour.', 'If blood glucose has been between 6-10mmol consider 2 hourly blood glucose checks.'] }; }
if (A11 === '17') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour. '] }; }
if (A11 === '18') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1-2 hours.', '(1 hour if drop in blood glucose > 2 mmol/L in last hour)'] }; }
if (A11 === '29') { r.advice = { type: 'additional', text: ['STOP INSULIN FOR AT LEAST 1 HOUR', 'Restart insulin if blood glucose > 10mmol/L'] }; }
if (A11 === '32') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 2 hours.'] }; }
if (A11 === '33') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour.'] }; }
if (A11 === '34') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour.'] }; }
if (A11 === '35') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour.'] }; }
if (A11 === '36') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 2 hours.'] }; }
if (A11 === '37') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour.'] }; }
if (A11 === '38') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour.'] }; }
if (A11 === '53') { r.advice = { type: 'additional', text: ['Recheck blood glucose in 1 hour.', 'Caution as blood glucose is approaching bottom of target range.'] }; }
if (A11 === '54') { r.advice = { type: 'additional', text: ['If blood glucose and calorie intake have been stable for last 2 hours move to 2 hourly BG checks. '] }; }
var hex = createGovernance({
f: 'b',
rate: rate,
Expand Down

0 comments on commit ac5d6b3

Please sign in to comment.