mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Handle mmol to mgdl conversions with a constant reference (#5274)
This commit is contained in:
+11
-10
@@ -4,6 +4,7 @@ var moment = require('moment-timezone');
|
|||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var parse_duration = require('parse-duration'); // https://www.npmjs.com/package/parse-duration
|
var parse_duration = require('parse-duration'); // https://www.npmjs.com/package/parse-duration
|
||||||
var times = require('../times');
|
var times = require('../times');
|
||||||
|
var consts = require('../constants');
|
||||||
var Storages = require('js-storage');
|
var Storages = require('js-storage');
|
||||||
|
|
||||||
function init (client, $) {
|
function init (client, $) {
|
||||||
@@ -240,8 +241,8 @@ function init (client, $) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (units == "mmol") {
|
if (units == "mmol") {
|
||||||
data.targetTop = data.targetTop * 18;
|
data.targetTop = data.targetTop * consts.MMOL_TO_MGDL;
|
||||||
data.targetBottom = data.targetBottom * 18;
|
data.targetBottom = data.targetBottom * consts.MMOL_TO_MGDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//special handling for absolute to support temp to 0
|
//special handling for absolute to support temp to 0
|
||||||
@@ -298,14 +299,14 @@ function init (client, $) {
|
|||||||
let targetTop = parseInt(data.targetTop);
|
let targetTop = parseInt(data.targetTop);
|
||||||
let targetBottom = parseInt(data.targetBottom);
|
let targetBottom = parseInt(data.targetBottom);
|
||||||
|
|
||||||
let minTarget = 4 * 18;
|
let minTarget = 4 * consts.MMOL_TO_MGDL;
|
||||||
let maxTarget = 18 * 18;
|
let maxTarget = 18 * consts.MMOL_TO_MGDL;
|
||||||
|
|
||||||
if (units == "mmol") {
|
if (units == "mmol") {
|
||||||
targetTop = Math.round(targetTop / 18.0 * 10) / 10;
|
targetTop = Math.round(targetTop / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
targetBottom = Math.round(targetBottom / 18.0 * 10) / 10;
|
targetBottom = Math.round(targetBottom / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
minTarget = Math.round(minTarget / 18.0 * 10) / 10;
|
minTarget = Math.round(minTarget / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
maxTarget = Math.round(maxTarget / 18.0 * 10) / 10;
|
maxTarget = Math.round(maxTarget / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetTop > maxTarget) {
|
if (targetTop > maxTarget) {
|
||||||
@@ -358,8 +359,8 @@ function init (client, $) {
|
|||||||
var targetBottom = data.targetBottom;
|
var targetBottom = data.targetBottom;
|
||||||
|
|
||||||
if (units == "mmol") {
|
if (units == "mmol") {
|
||||||
targetTop = Math.round(data.targetTop / 18.0 * 10) / 10;
|
targetTop = Math.round(data.targetTop / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
targetBottom = Math.round(data.targetBottom / 18.0 * 10) / 10;
|
targetBottom = Math.round(data.targetBottom / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
pushIf(data.targetTop, translate('Target Top') + ': ' + targetTop);
|
pushIf(data.targetTop, translate('Target Top') + ': ' + targetTop);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var times = require('../times');
|
var times = require('../times');
|
||||||
|
var consts = require('../constants');
|
||||||
|
|
||||||
var DEFAULT_FOCUS = times.hours(3).msecs
|
var DEFAULT_FOCUS = times.hours(3).msecs
|
||||||
, WIDTH_SMALL_DOTS = 420
|
, WIDTH_SMALL_DOTS = 420
|
||||||
@@ -210,8 +211,8 @@ function init (client, d3) {
|
|||||||
var targetTop = d.targetTop;
|
var targetTop = d.targetTop;
|
||||||
|
|
||||||
if (client.settings.units === 'mmol') {
|
if (client.settings.units === 'mmol') {
|
||||||
targetBottom = Math.round(targetBottom / 18.0 * 10) / 10;
|
targetBottom = Math.round(targetBottom / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
targetTop = Math.round(targetTop / 18.0 * 10) / 10;
|
targetTop = Math.round(targetTop / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
var correctionRangeText;
|
var correctionRangeText;
|
||||||
@@ -632,7 +633,7 @@ function init (client, d3) {
|
|||||||
function treatmentTooltip () {
|
function treatmentTooltip () {
|
||||||
var glucose = treatment.glucose;
|
var glucose = treatment.glucose;
|
||||||
if (client.settings.units != client.ddata.profile.getUnits()) {
|
if (client.settings.units != client.ddata.profile.getUnits()) {
|
||||||
glucose *= (client.settings.units === 'mmol' ? 0.055 : 18);
|
glucose *= (client.settings.units === 'mmol' ? (1 / consts.MMOL_TO_MGDL) : consts.MMOL_TO_MGDL);
|
||||||
var decimals = (client.settings.units === 'mmol' ? 10 : 1);
|
var decimals = (client.settings.units === 'mmol' ? 10 : 1);
|
||||||
|
|
||||||
glucose = Math.round(glucose * decimals) / decimals;
|
glucose = Math.round(glucose * decimals) / decimals;
|
||||||
|
|||||||
+2
-1
@@ -4,5 +4,6 @@
|
|||||||
"HTTP_UNAUTHORIZED" : 401,
|
"HTTP_UNAUTHORIZED" : 401,
|
||||||
"HTTP_VALIDATION_ERROR" : 422,
|
"HTTP_VALIDATION_ERROR" : 422,
|
||||||
"HTTP_INTERNAL_ERROR" : 500,
|
"HTTP_INTERNAL_ERROR" : 500,
|
||||||
"ENTRIES_DEFAULT_COUNT" : 10
|
"ENTRIES_DEFAULT_COUNT" : 10,
|
||||||
|
"MMOL_TO_MGDL": 18
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var times = require('../times');
|
var times = require('../times');
|
||||||
|
var consts = require('../constants');
|
||||||
|
|
||||||
var DEVICE_TYPE_FIELDS = ['uploader', 'pump', 'openaps', 'loop', 'xdripjs'];
|
var DEVICE_TYPE_FIELDS = ['uploader', 'pump', 'openaps', 'loop', 'xdripjs'];
|
||||||
|
|
||||||
@@ -213,18 +214,18 @@ function init () {
|
|||||||
if (t.units) {
|
if (t.units) {
|
||||||
if (t.units == 'mmol') {
|
if (t.units == 'mmol') {
|
||||||
//convert to mgdl
|
//convert to mgdl
|
||||||
t.targetTop = t.targetTop * 18;
|
t.targetTop = t.targetTop * consts.MMOL_TO_MGDL;
|
||||||
t.targetBottom = t.targetBottom * 18;
|
t.targetBottom = t.targetBottom * consts.MMOL_TO_MGDL;
|
||||||
t.units = 'mg/dl';
|
t.units = 'mg/dl';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if we have a temp target thats below 20, assume its mmol and convert to mgdl for safety.
|
//if we have a temp target thats below 20, assume its mmol and convert to mgdl for safety.
|
||||||
if (t.targetTop < 20) {
|
if (t.targetTop < 20) {
|
||||||
t.targetTop = t.targetTop * 18;
|
t.targetTop = t.targetTop * consts.MMOL_TO_MGDL;
|
||||||
t.units = 'mg/dl';
|
t.units = 'mg/dl';
|
||||||
}
|
}
|
||||||
if (t.targetBottom < 20) {
|
if (t.targetBottom < 20) {
|
||||||
t.targetBottom = t.targetBottom * 18;
|
t.targetBottom = t.targetBottom * consts.MMOL_TO_MGDL;
|
||||||
t.units = 'mg/dl';
|
t.units = 'mg/dl';
|
||||||
}
|
}
|
||||||
return t.eventType && t.eventType.indexOf('Temporary Target') > -1;
|
return t.eventType && t.eventType.indexOf('Temporary Target') > -1;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
var consts = require('../constants');
|
||||||
|
|
||||||
const MAX_BG_MMOL = 22;
|
const MAX_BG_MMOL = 22;
|
||||||
const MAX_BG_MGDL = MAX_BG_MMOL * 18;
|
const MAX_BG_MGDL = MAX_BG_MMOL * consts.MMOL_TO_MGDL;
|
||||||
|
|
||||||
module.exports = function fitTreatmentsToBGCurve (ddata, env, ctx) {
|
module.exports = function fitTreatmentsToBGCurve (ddata, env, ctx) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var times = require('../times');
|
var times = require('../times');
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
|
var consts = require('../constants');
|
||||||
|
|
||||||
function init (ctx) {
|
function init (ctx) {
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ function init (ctx) {
|
|||||||
var units = profile.getUnits();
|
var units = profile.getUnits();
|
||||||
|
|
||||||
if (sbx.settings.units != units) {
|
if (sbx.settings.units != units) {
|
||||||
sensitivity *= (sbx.settings.units === 'mmol' ? 0.055 : 18);
|
sensitivity *= (sbx.settings.units === 'mmol' ? (1 / consts.MMOL_TO_MGDL) : consts.MMOL_TO_MGDL);
|
||||||
var decimals = (sbx.settings.units === 'mmol' ? 10 : 1);
|
var decimals = (sbx.settings.units === 'mmol' ? 10 : 1);
|
||||||
|
|
||||||
sensitivity = Math.round(sensitivity * decimals) / decimals;
|
sensitivity = Math.round(sensitivity * decimals) / decimals;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ var _ = require('lodash');
|
|||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
var times = require('../times');
|
var times = require('../times');
|
||||||
var levels = require('../levels');
|
var levels = require('../levels');
|
||||||
|
var consts = require('../constants');
|
||||||
|
|
||||||
// var ALL_STATUS_FIELDS = ['status-symbol', 'status-label', 'iob', 'meal-assist', 'freq', 'rssi']; Unused variable
|
// var ALL_STATUS_FIELDS = ['status-symbol', 'status-label', 'iob', 'meal-assist', 'freq', 'rssi']; Unused variable
|
||||||
|
|
||||||
@@ -352,7 +353,7 @@ function init (ctx) {
|
|||||||
var units = sbx.data.profile.getUnits();
|
var units = sbx.data.profile.getUnits();
|
||||||
|
|
||||||
if (units === 'mmol') {
|
if (units === 'mmol') {
|
||||||
bg = Math.round(bg / 18 * 10) / 10;
|
bg = Math.round(bg / consts.MMOL_TO_MGDL * 10) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
var valueParts = [
|
var valueParts = [
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var consts = require('../constants');
|
||||||
|
|
||||||
var glucosedistribution = {
|
var glucosedistribution = {
|
||||||
name: 'glucosedistribution'
|
name: 'glucosedistribution'
|
||||||
, label: 'Distribution'
|
, label: 'Distribution'
|
||||||
@@ -174,7 +176,7 @@ glucosedistribution.report = function report_glucosedistribution (datastorage, s
|
|||||||
var bg = Math.floor(entry.bgValue + bgDelta * j);
|
var bg = Math.floor(entry.bgValue + bgDelta * j);
|
||||||
var t = new Date(entry.displayTime.getTime() + j * timePatch);
|
var t = new Date(entry.displayTime.getTime() + j * timePatch);
|
||||||
var newEntry = {
|
var newEntry = {
|
||||||
sgv: displayUnits === 'mmol' ? bg / 18 : bg
|
sgv: displayUnits === 'mmol' ? bg / consts.MMOL_TO_MGDL : bg
|
||||||
, bgValue: bg
|
, bgValue: bg
|
||||||
, displayTime: t
|
, displayTime: t
|
||||||
};
|
};
|
||||||
@@ -217,7 +219,7 @@ glucosedistribution.report = function report_glucosedistribution (datastorage, s
|
|||||||
const interpolatedValue = prevEntry.bgValue + d;
|
const interpolatedValue = prevEntry.bgValue + d;
|
||||||
|
|
||||||
let newEntry = {
|
let newEntry = {
|
||||||
sgv: displayUnits === 'mmol' ? interpolatedValue / 18 : interpolatedValue
|
sgv: displayUnits === 'mmol' ? interpolatedValue / consts.MMOL_TO_MGDL : interpolatedValue
|
||||||
, bgValue: interpolatedValue
|
, bgValue: interpolatedValue
|
||||||
, displayTime: entry.displayTime
|
, displayTime: entry.displayTime
|
||||||
};
|
};
|
||||||
@@ -433,11 +435,11 @@ glucosedistribution.report = function report_glucosedistribution (datastorage, s
|
|||||||
|
|
||||||
var unitString = ' mg/dl';
|
var unitString = ' mg/dl';
|
||||||
if (displayUnits == 'mmol') {
|
if (displayUnits == 'mmol') {
|
||||||
TDC = TDC / 18.0;
|
TDC = TDC / consts.MMOL_TO_MGDL;
|
||||||
TDCHourly = TDCHourly / 18.0;
|
TDCHourly = TDCHourly / consts.MMOL_TO_MGDL;
|
||||||
unitString = ' mmol/L';
|
unitString = ' mmol/L';
|
||||||
|
|
||||||
RMS = Math.sqrt(RMSTotal / events) / 18;
|
RMS = Math.sqrt(RMSTotal / events) / consts.MMOL_TO_MGDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TDC = Math.round(TDC * 100) / 100;
|
TDC = Math.round(TDC * 100) / 100;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var consts = require('../constants');
|
||||||
|
|
||||||
var moment = window.moment;
|
var moment = window.moment;
|
||||||
var utils = { };
|
var utils = { };
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ utils.scaledTreatmentBG = function scaledTreatmentBG(treatment,data) {
|
|||||||
console.info('found mismatched glucose units, converting ' + treatment.units + ' into ' + client.settings.units, treatment);
|
console.info('found mismatched glucose units, converting ' + treatment.units + ' into ' + client.settings.units, treatment);
|
||||||
if (treatment.units === 'mmol') {
|
if (treatment.units === 'mmol') {
|
||||||
//BG is in mmol and display in mg/dl
|
//BG is in mmol and display in mg/dl
|
||||||
treatmentGlucose = Math.round(treatment.glucose * 18);
|
treatmentGlucose = Math.round(treatment.glucose * consts.MMOL_TO_MGDL);
|
||||||
} else {
|
} else {
|
||||||
//BG is in mg/dl and display in mmol
|
//BG is in mg/dl and display in mmol
|
||||||
treatmentGlucose = client.utils.scaleMgdl(treatment.glucose);
|
treatmentGlucose = client.utils.scaleMgdl(treatment.glucose);
|
||||||
|
|||||||
+4
-2
@@ -1,11 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var consts = require('./constants');
|
||||||
|
|
||||||
function mgdlToMMOL(mgdl) {
|
function mgdlToMMOL(mgdl) {
|
||||||
return (Math.round((mgdl / 18) * 10) / 10).toFixed(1);
|
return (Math.round((mgdl / consts.MMOL_TO_MGDL) * 10) / 10).toFixed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mmolToMgdl(mgdl) {
|
function mmolToMgdl(mgdl) {
|
||||||
return Math.round(mgdl * 18);
|
return Math.round(mgdl * consts.MMOL_TO_MGDL);
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure() {
|
function configure() {
|
||||||
|
|||||||
Reference in New Issue
Block a user