Namespace NICE-specific functions

This commit is contained in:
RunasSudo 2025-07-25 17:19:49 +10:00
parent 258dfefe2d
commit bdfe972113
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 37 additions and 39 deletions

View File

@ -1,6 +1,6 @@
/*
Neonatal jaundice treatment threshold calculator
Copyright (C) 2024 Lee Yingtong Li
Copyright (C) 2024-2025 Lee Yingtong Li
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@ -26,8 +26,8 @@ function plotGraphData() {
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.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)}));
}
chart.update();

View File

@ -1,6 +1,6 @@
/*
Neonatal jaundice treatment threshold calculator
Copyright (C) 2024 Lee Yingtong Li
Copyright (C) 2024-2025 Lee Yingtong Li
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@ -16,10 +16,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// ----------------------
// Threshold calculations
// -----------------------------
// Threshold calculations (NICE)
function phototherapy_38wks(d) {
function nice_phototherapy_38wks(d) {
if (d <= 0) {
return 100;
}
@ -32,7 +32,7 @@ function phototherapy_38wks(d) {
return 350;
}
function exchange_38wks(d) {
function nice_exchange_38wks(d) {
if (d <= 0) {
return 100;
}
@ -42,9 +42,9 @@ function exchange_38wks(d) {
return 450;
}
function phototherapy_thresh(d, gestation) {
function nice_phototherapy_thresh(d, gestation) {
if (gestation >= 38) {
return phototherapy_38wks(d);
return nice_phototherapy_38wks(d);
}
if (gestation < 23) {
throw new Error('Invalid gestation');
@ -59,9 +59,9 @@ function phototherapy_thresh(d, gestation) {
return thresh_at_3days;
}
function exchange_thresh(d, gestation) {
function nice_exchange_thresh(d, gestation) {
if (gestation >= 38) {
return exchange_38wks(d);
return nice_exchange_38wks(d);
}
if (gestation < 23) {
throw new Error('Invalid gestation');
@ -83,8 +83,8 @@ 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);
let phototherapy_thresh_value = nice_phototherapy_thresh(d, gestation);
let exchange_thresh_value = nice_exchange_thresh(d, gestation);
// Restate colours separately so Tailwind can detect them
let result_text, text_colour, background_colour, accent_colour;

View File

@ -1,26 +1,24 @@
<!--
Neonatal jaundice treatment threshold calculator
Copyright (C) 2024-2025 Lee Yingtong Li
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--
Neonatal jaundice treatment threshold calculator
Copyright (C) 2024 Lee Yingtong Li
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Neonatal jaundice treatment threshold calculator</title>
<link href="build/main.css" rel="stylesheet">
@ -67,7 +65,7 @@
<div class="border-t border-gray-400 mt-4 pt-4 text-xs text-gray-600 space-y-2">
<p>Treatment thresholds as per: National Institute for Health and Clinical Excellence. Neonatal jaundice treatment threshold graphs. In: Jaundice in newborn babies under 28 days. London: National Institute for Health and Clinical Excellence; 2023. (NICE clinical guidelines; CG98). <a href="https://www.nice.org.uk/guidance/cg98" class="text-blue-500 hover:underline hover:text-blue-600">https://www.nice.org.uk/guidance/cg98</a></p>
<p>This tool is made available in the hope that it will be useful, but <em>WITHOUT ANY WARRANTY</em>; without even the implied warranty of <em>MERCHANTABILITY</em> or <em>FITNESS FOR A PARTICULAR PURPOSE</em>. Information provided in this tool is intended for reference by medical professionals. Nothing in this tool is intended to constitute medical advice.</p>
<p>Lee Yingtong Li, 2024. Source code available at <a href="https://yingtongli.me/git/bilirubin-calculator" class="text-blue-500 hover:underline hover:text-blue-600">https://yingtongli.me/git/bilirubin-calculator</a>.</p>
<p>Lee Yingtong Li, 2024–2025. Source code available at <a href="https://yingtongli.me/git/bilirubin-calculator" class="text-blue-500 hover:underline hover:text-blue-600">https://yingtongli.me/git/bilirubin-calculator</a>.</p>
</div>
</div>
<script src="bilirubin_lib.js"></script>

View File

@ -1,6 +1,6 @@
/*
Neonatal jaundice treatment threshold calculator
Copyright (C) 2024 Lee Yingtong Li
Copyright (C) 2024-2025 Lee Yingtong Li
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@ -51,7 +51,7 @@ suite('Phototherapy thresholds vs NICE', () => {
test('Phototherapy thresholds at >= 38 weeks', () => {
for (let gestation = 42; gestation >= 38; gestation--) {
for (let i = 0, d = 0; d <= 14; i += 1, d += 0.25) {
assert(nearlyEqual(phototherapy_thresh(d, gestation), expected_phototherapy[38][i], 0.5));
assert(nearlyEqual(nice_phototherapy_thresh(d, gestation), expected_phototherapy[38][i], 0.5));
}
}
});
@ -59,7 +59,7 @@ suite('Phototherapy thresholds vs NICE', () => {
for (let gestation = 37; gestation >= 23; gestation--) {
test('Phototherapy thresholds at ' + gestation + ' weeks', () => {
for (let i = 0, d = 0; d <= 14; i += 1, d += 0.25) {
assert(nearlyEqual(phototherapy_thresh(d, gestation), expected_phototherapy[gestation >= 38 ? 38 : gestation][i], 0.5));
assert(nearlyEqual(nice_phototherapy_thresh(d, gestation), expected_phototherapy[gestation >= 38 ? 38 : gestation][i], 0.5));
}
});
}
@ -89,7 +89,7 @@ suite('Exchange therapy thresholds vs NICE', () => {
test('Exchange transfusion thresholds at >= 38 weeks', () => {
for (let gestation = 42; gestation >= 38; gestation--) {
for (let i = 0, d = 0; d <= 14; i += 1, d += 0.25) {
assert(nearlyEqual(exchange_thresh(d, gestation), expected_exchange[38][i], 0.5));
assert(nearlyEqual(nice_exchange_thresh(d, gestation), expected_exchange[38][i], 0.5));
}
}
});
@ -97,7 +97,7 @@ suite('Exchange therapy thresholds vs NICE', () => {
for (let gestation = 37; gestation >= 23; gestation--) {
test('Exchange transfusion thresholds at ' + gestation + ' weeks', () => {
for (let i = 0, d = 0; d <= 14; i += 1, d += 0.25) {
assert(nearlyEqual(exchange_thresh(d, gestation), expected_exchange[gestation >= 38 ? 38 : gestation][i], 0.5));
assert(nearlyEqual(nice_exchange_thresh(d, gestation), expected_exchange[gestation >= 38 ? 38 : gestation][i], 0.5));
}
});
}