From a06d7ccea39457ce918b450c8c5a2f1a59e12e47 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 23 Mar 2015 23:06:57 -0700 Subject: [PATCH] fix a bug that caused a treatment's glucose value to be ignored and the avg. bg at the treatment time used instead --- static/js/client.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/static/js/client.js b/static/js/client.js index 33cd3f8b5..c12a46344 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -1198,17 +1198,26 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; var treatmentGlucose = null; - if (isNaN(treatment.glucose)) { - if (treatment.glucose && treatment.units) { - if (treatment.units != browserSettings.units && treatment.units != 'mmol') { - //BG is in mg/dl and display in mmol - treatmentGlucose = scaleBg(treatment.glucose); - } else if (treatment.units != browserSettings.units && treatment.units == 'mmol') { - //BG is in mmol and display in mg/dl - treatmentGlucose = Math.round(treatment.glucose * 18) + if (treatment.glucose && isNaN(treatment.glucose)) { + console.warn('found an invalid glucose value', treatment); + } else { + if (treatment.glucose && treatment.units && browserSettings.units) { + if (treatment.units != browserSettings.units) { + console.info('found mismatched glucose units, converting ' + treatment.units + ' into ' + browserSettings.units, treatment); + if (treatment.units == 'mmol') { + //BG is in mmol and display in mg/dl + treatmentGlucose = Math.round(treatment.glucose * 18) + } else { + //BG is in mg/dl and display in mmol + treatmentGlucose = scaleBg(treatment.glucose); + } + } else { + console.warn('found an VALID glucose value', treatment); + treatmentGlucose = treatment.glucose; } - } else { + } else if (treatment.glucose) { //no units, assume everything is the same + console.warn('found an glucose value with any units, maybe from an old version?', treatment); treatmentGlucose = treatment.glucose; } }