Do not display result if invalid inputs
This commit is contained in:
parent
c1f2b0c908
commit
c9f5fd1082
37
index.html
37
index.html
@ -58,7 +58,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="result" class="d-none">
|
||||
<div id="result" class="hidden">
|
||||
<p></p>
|
||||
</div>
|
||||
</div>
|
||||
@ -103,7 +103,7 @@
|
||||
return phototherapy_38wks(d);
|
||||
}
|
||||
if (gestation < 22) {
|
||||
throw new Exception('Invalid gestation');
|
||||
throw new Error('Invalid gestation');
|
||||
}
|
||||
if (d <= 0) {
|
||||
return 40;
|
||||
@ -120,7 +120,7 @@
|
||||
return exchange_38wks(d);
|
||||
}
|
||||
if (gestation < 22) {
|
||||
throw new Exception('Invalid gestation');
|
||||
throw new Error('Invalid gestation');
|
||||
}
|
||||
if (d <= 0) {
|
||||
return 80;
|
||||
@ -137,8 +137,15 @@
|
||||
|
||||
function plotGraphData() {
|
||||
let gestation = document.getElementById('gestation').valueAsNumber;
|
||||
chart.data.datasets[0].data = [...Array(14*24).keys()].map((i) => i / 24).map((d) => ({x: d, y: phototherapy_thresh(d, gestation)}));
|
||||
chart.data.datasets[1].data = [...Array(14*24).keys()].map((i) => i / 24).map((d) => ({x: d, y: exchange_thresh(d, gestation)}));
|
||||
|
||||
if (isNaN(gestation) || gestation < 22) {
|
||||
chart.data.datasets[0].data = [];
|
||||
chart.data.datasets[1].data = [];
|
||||
} else {
|
||||
chart.data.datasets[0].data = [...Array(14*24).keys()].map((i) => i / 24).map((d) => ({x: d, y: phototherapy_thresh(d, gestation)}));
|
||||
chart.data.datasets[1].data = [...Array(14*24).keys()].map((i) => i / 24).map((d) => ({x: d, y: exchange_thresh(d, gestation)}));
|
||||
}
|
||||
|
||||
chart.update();
|
||||
}
|
||||
|
||||
@ -264,30 +271,38 @@
|
||||
}
|
||||
|
||||
function updateBilirubin() {
|
||||
let resultDiv = document.getElementById('result');
|
||||
let resultP = resultDiv.querySelector('p');
|
||||
|
||||
let bilirubin = document.getElementById('bilirubin').valueAsNumber;
|
||||
let gestation = document.getElementById('gestation').valueAsNumber;
|
||||
|
||||
if (document.getElementById('time_birth').valueAsDate === null) {
|
||||
resultDiv.className = 'hidden';
|
||||
return;
|
||||
}
|
||||
if (document.getElementById('time_measurement').valueAsDate === null) {
|
||||
resultDiv.className = 'hidden';
|
||||
return;
|
||||
}
|
||||
if (document.getElementById('bilirubin').value === '') {
|
||||
if (isNaN(bilirubin)) {
|
||||
resultDiv.className = 'hidden';
|
||||
return;
|
||||
}
|
||||
if (isNaN(gestation) || gestation < 22) {
|
||||
resultDiv.className = 'hidden';
|
||||
return;
|
||||
}
|
||||
|
||||
// Chronological age in days
|
||||
let d = (document.getElementById('time_measurement').valueAsDate.getTime() - document.getElementById('time_birth').valueAsDate.getTime()) / 1000 / 60 / 60 / 24;
|
||||
|
||||
let bilirubin = document.getElementById('bilirubin').valueAsNumber;
|
||||
let gestation = document.getElementById('gestation').valueAsNumber;
|
||||
let phototherapy_thresh_value = phototherapy_thresh(d, gestation);
|
||||
let exchange_thresh_value = exchange_thresh(d, gestation);
|
||||
|
||||
chart.data.datasets[2].data = [{x: d, y: bilirubin}];
|
||||
chart.update();
|
||||
|
||||
let resultDiv = document.getElementById('result');
|
||||
let resultP = resultDiv.querySelector('p');
|
||||
|
||||
if (bilirubin < phototherapy_thresh_value) {
|
||||
if (bilirubin < phototherapy_thresh_value - 50) {
|
||||
resultDiv.className = 'border-l-4 border-sky-400 bg-sky-50 py-2 px-4';
|
||||
|
Loading…
Reference in New Issue
Block a user