diff --git a/src/bilirubin_app.js b/src/bilirubin_app.js index ecd15fc..3f905bd 100644 --- a/src/bilirubin_app.js +++ b/src/bilirubin_app.js @@ -16,18 +16,39 @@ along with this program. If not, see . */ +// -------------------------------------- +// Extra questions by guideline/gestation + +function updateExtraQuestions() { + // Show or hide extra questions according to guideline and gestation +} +updateExtraQuestions(); + // -------------- // Graph plotting +function isGestationValid(guideline, gestation) { + if (isNaN(gestation)) { + return false; + } + if (guideline === 'nice' && gestation < 23) { + return false; + } + return true; +} + function plotGraphData() { + let guideline = document.getElementById('guideline').value; let gestation = document.getElementById('gestation').valueAsNumber; - if (isNaN(gestation) || gestation < 23) { + if (!isGestationValid(guideline, gestation)) { chart.data.datasets[0].data = []; chart.data.datasets[1].data = []; - } else { + } else if (guideline === 'nice') { chart.data.datasets[0].data = [...Array(14*24).keys()].map((i) => i / 24).map((d) => ({x: d, y: nice_phototherapy_thresh(d, gestation)})); chart.data.datasets[1].data = [...Array(14*24).keys()].map((i) => i / 24).map((d) => ({x: d, y: nice_exchange_thresh(d, gestation)})); + } else { + throw new Error('Unexpected guideline'); } chart.update(); @@ -130,6 +151,7 @@ function updateBilirubin() { let resultDiv = document.getElementById('result'); let resultP = resultDiv.querySelector('p'); + let guideline = document.getElementById('guideline').value; let bilirubin = document.getElementById('bilirubin').valueAsNumber; let gestation = document.getElementById('gestation').valueAsNumber; @@ -145,12 +167,18 @@ function updateBilirubin() { resultDiv.className = 'hidden'; return; } - if (isNaN(gestation) || gestation < 23) { + if (!isGestationValid(guideline, gestation)) { resultDiv.className = 'hidden'; return; } - let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, new Date(document.getElementById('time_birth').value), new Date(document.getElementById('time_measurement').value), bilirubin); + let d, result_text, text_colour, background_colour, accent_colour; + + if (guideline === 'nice') { + [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, new Date(document.getElementById('time_birth').value), new Date(document.getElementById('time_measurement').value), bilirubin); + } else { + throw new Error('Unexpected guideline'); + } chart.data.datasets[2].data = [{x: d, y: bilirubin}]; chart.update(); diff --git a/src/index.html b/src/index.html index 43d89fd..24ad3b7 100644 --- a/src/index.html +++ b/src/index.html @@ -29,10 +29,16 @@

Neonatal jaundice treatment thresholds

+
+ + +
- +
completed weeks