Refactor bilirubin vs threshold calculation
This commit is contained in:
parent
f669061d65
commit
030609b45e
@ -150,35 +150,13 @@ function updateBilirubin() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Chronological age in days
|
||||
let d = (document.getElementById('time_measurement').valueAsDate.getTime() - document.getElementById('time_birth').valueAsDate.getTime()) / 1000 / 60 / 60 / 24;
|
||||
|
||||
let phototherapy_thresh_value = phototherapy_thresh(d, gestation);
|
||||
let exchange_thresh_value = exchange_thresh(d, gestation);
|
||||
let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, document.getElementById('time_birth').valueAsDate, document.getElementById('time_measurement').valueAsDate, bilirubin);
|
||||
|
||||
chart.data.datasets[2].data = [{x: d, y: bilirubin}];
|
||||
chart.update();
|
||||
|
||||
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';
|
||||
resultP.className = 'text-sm text-sky-800';
|
||||
} else {
|
||||
resultDiv.className = 'border-l-4 border-yellow-400 bg-yellow-50 py-2 px-4';
|
||||
resultP.className = 'text-sm text-yellow-800';
|
||||
}
|
||||
|
||||
resultP.innerHTML = 'Bilirubin of ' + bilirubin + ' at ' + prettyPrintDays(d) + ' is <span class="font-bold">' + prettyPrintBilirubin(phototherapy_thresh_value - bilirubin) + ' below</span> the phototherapy threshold.';
|
||||
} else if (bilirubin < exchange_thresh_value) {
|
||||
resultDiv.className = 'border-l-4 border-orange-400 bg-orange-50 py-2 px-4';
|
||||
resultP.className = 'text-sm text-orange-800';
|
||||
|
||||
resultP.innerHTML = 'Bilirubin of ' + bilirubin + ' at ' + prettyPrintDays(d) + ' is <span class="font-bold">' + prettyPrintBilirubin(bilirubin - phototherapy_thresh_value) + ' above</span> the phototherapy threshold, ' + prettyPrintBilirubin(exchange_thresh_value - bilirubin) + ' below the exchange transfusion threshold.';
|
||||
} else {
|
||||
resultDiv.className = 'border-l-4 border-red-400 bg-red-50 py-2 px-4';
|
||||
resultP.className = 'text-sm text-red-800';
|
||||
|
||||
resultP.innerHTML = 'Bilirubin of ' + bilirubin + ' at ' + prettyPrintDays(d) + ' is ' + prettyPrintBilirubin(bilirubin - exchange_thresh_value) + ' above the <span class="font-bold">exchange transfusion</span> threshold.';
|
||||
}
|
||||
resultDiv.className = 'border-l-4 ' + accent_colour + ' ' + background_colour + ' py-2 px-4';
|
||||
resultP.className = 'text-sm ' + text_colour;
|
||||
resultP.innerHTML = result_text;
|
||||
}
|
||||
updateBilirubin();
|
||||
|
@ -76,6 +76,48 @@ function exchange_thresh(d, gestation) {
|
||||
return thresh_at_3days;
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// Bilirubin vs threshold calculation
|
||||
|
||||
function describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin) {
|
||||
// Chronological age in days
|
||||
let d = (dateMeasurement.getTime() - dateBirth.getTime()) / 1000 / 60 / 60 / 24;
|
||||
|
||||
let phototherapy_thresh_value = phototherapy_thresh(d, gestation);
|
||||
let exchange_thresh_value = exchange_thresh(d, gestation);
|
||||
|
||||
// Restate colours separately so Tailwind can detect them
|
||||
let result_text, text_colour, background_colour, accent_colour;
|
||||
|
||||
if (bilirubin < phototherapy_thresh_value) {
|
||||
if (bilirubin < phototherapy_thresh_value - 50) {
|
||||
text_colour = 'text-sky-800';
|
||||
background_colour = 'bg-sky-50';
|
||||
accent_colour = 'border-sky-400';
|
||||
} else {
|
||||
text_colour = 'text-yellow-800';
|
||||
background_colour = 'bg-yellow-50';
|
||||
accent_colour = 'border-yellow-400';
|
||||
}
|
||||
|
||||
result_text = 'Bilirubin of ' + bilirubin + ' at ' + prettyPrintDays(d) + ' is <span class="font-bold">' + prettyPrintBilirubin(phototherapy_thresh_value - bilirubin) + ' below</span> the phototherapy threshold.';
|
||||
} else if (bilirubin < exchange_thresh_value) {
|
||||
text_colour = 'text-orange-800';
|
||||
background_colour = 'bg-orange-50';
|
||||
accent_colour = 'border-orange-400';
|
||||
|
||||
result_text = 'Bilirubin of ' + bilirubin + ' at ' + prettyPrintDays(d) + ' is <span class="font-bold">' + prettyPrintBilirubin(bilirubin - phototherapy_thresh_value) + ' above</span> the phototherapy threshold, ' + prettyPrintBilirubin(exchange_thresh_value - bilirubin) + ' below the exchange transfusion threshold.';
|
||||
} else {
|
||||
text_colour = 'text-red-800';
|
||||
background_colour = 'bg-red-50';
|
||||
accent_colour = 'border-red-400';
|
||||
|
||||
result_text = 'Bilirubin of ' + bilirubin + ' at ' + prettyPrintDays(d) + ' is ' + prettyPrintBilirubin(bilirubin - exchange_thresh_value) + ' above the <span class="font-bold">exchange transfusion</span> threshold.';
|
||||
}
|
||||
|
||||
return [d, result_text, text_colour, background_colour, accent_colour];
|
||||
}
|
||||
|
||||
// --------------
|
||||
// Utility functions
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user