Do not display result if invalid inputs

This commit is contained in:
RunasSudo 2024-08-26 18:45:07 +10:00
parent c1f2b0c908
commit c9f5fd1082
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
1 changed files with 26 additions and 11 deletions

View File

@ -58,7 +58,7 @@
</div> </div>
</div> </div>
</div> </div>
<div id="result" class="d-none"> <div id="result" class="hidden">
<p></p> <p></p>
</div> </div>
</div> </div>
@ -103,7 +103,7 @@
return phototherapy_38wks(d); return phototherapy_38wks(d);
} }
if (gestation < 22) { if (gestation < 22) {
throw new Exception('Invalid gestation'); throw new Error('Invalid gestation');
} }
if (d <= 0) { if (d <= 0) {
return 40; return 40;
@ -120,7 +120,7 @@
return exchange_38wks(d); return exchange_38wks(d);
} }
if (gestation < 22) { if (gestation < 22) {
throw new Exception('Invalid gestation'); throw new Error('Invalid gestation');
} }
if (d <= 0) { if (d <= 0) {
return 80; return 80;
@ -137,8 +137,15 @@
function plotGraphData() { function plotGraphData() {
let gestation = document.getElementById('gestation').valueAsNumber; 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(); chart.update();
} }
@ -264,30 +271,38 @@
} }
function updateBilirubin() { 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) { if (document.getElementById('time_birth').valueAsDate === null) {
resultDiv.className = 'hidden';
return; return;
} }
if (document.getElementById('time_measurement').valueAsDate === null) { if (document.getElementById('time_measurement').valueAsDate === null) {
resultDiv.className = 'hidden';
return; return;
} }
if (document.getElementById('bilirubin').value === '') { if (isNaN(bilirubin)) {
resultDiv.className = 'hidden';
return;
}
if (isNaN(gestation) || gestation < 22) {
resultDiv.className = 'hidden';
return; return;
} }
// Chronological age in days // Chronological age in days
let d = (document.getElementById('time_measurement').valueAsDate.getTime() - document.getElementById('time_birth').valueAsDate.getTime()) / 1000 / 60 / 60 / 24; 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 phototherapy_thresh_value = phototherapy_thresh(d, gestation);
let exchange_thresh_value = exchange_thresh(d, gestation); let exchange_thresh_value = exchange_thresh(d, gestation);
chart.data.datasets[2].data = [{x: d, y: bilirubin}]; chart.data.datasets[2].data = [{x: d, y: bilirubin}];
chart.update(); chart.update();
let resultDiv = document.getElementById('result');
let resultP = resultDiv.querySelector('p');
if (bilirubin < phototherapy_thresh_value) { if (bilirubin < phototherapy_thresh_value) {
if (bilirubin < phototherapy_thresh_value - 50) { if (bilirubin < phototherapy_thresh_value - 50) {
resultDiv.className = 'border-l-4 border-sky-400 bg-sky-50 py-2 px-4'; resultDiv.className = 'border-l-4 border-sky-400 bg-sky-50 py-2 px-4';