99 lines
4.5 KiB
JavaScript
99 lines
4.5 KiB
JavaScript
/*
|
|
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/>.
|
|
*/
|
|
|
|
// Import bilirubin_lib.js
|
|
const fs = require('fs');
|
|
eval(fs.readFileSync('src/bilirubin_lib.js').toString());
|
|
|
|
const assert = require('node:assert');
|
|
const { suite, test } = require('node:test');
|
|
|
|
suite('Describe bilirubin result', () => {
|
|
const dateBirth = new Date(2024, 11, 24, 4, 20, 31, 415);
|
|
const dateMeasurement = new Date(2024, 11, 25, 4, 20, 31, 415);
|
|
const gestation = 38;
|
|
|
|
test('Well below phototherapy threshold', () => {
|
|
const bilirubin = 20;
|
|
const expectedText = 'Bilirubin of 20 at 1 day, 0 hours is <span class="font-bold">180 below</span> the phototherapy threshold.';
|
|
const expectedColour = 'sky';
|
|
|
|
let d = chronoAgeInDays(dateBirth, dateMeasurement);
|
|
let phototherapy_thresh_value = nice_phototherapy_thresh(d, gestation);
|
|
let exchange_thresh_value = nice_exchange_thresh(d, gestation);
|
|
let [result_text, text_colour, background_colour, accent_colour] = describeBilirubin(d, bilirubin, phototherapy_thresh_value, exchange_thresh_value);
|
|
|
|
assert.equal(d, 1);
|
|
assert.equal(result_text, expectedText);
|
|
assert.equal(text_colour, 'text-' + expectedColour + '-800');
|
|
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
|
|
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
|
|
});
|
|
|
|
test('Within 50 of phototherapy threshold', () => {
|
|
const bilirubin = 160;
|
|
const expectedText = 'Bilirubin of 160 at 1 day, 0 hours is <span class="font-bold">40 below</span> the phototherapy threshold.';
|
|
const expectedColour = 'yellow';
|
|
|
|
let d = chronoAgeInDays(dateBirth, dateMeasurement);
|
|
let phototherapy_thresh_value = nice_phototherapy_thresh(d, gestation);
|
|
let exchange_thresh_value = nice_exchange_thresh(d, gestation);
|
|
let [result_text, text_colour, background_colour, accent_colour] = describeBilirubin(d, bilirubin, phototherapy_thresh_value, exchange_thresh_value);
|
|
|
|
assert.equal(d, 1);
|
|
assert.equal(result_text, expectedText);
|
|
assert.equal(text_colour, 'text-' + expectedColour + '-800');
|
|
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
|
|
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
|
|
});
|
|
|
|
test('Above phototherapy threshold', () => {
|
|
const bilirubin = 220;
|
|
const expectedText = 'Bilirubin of 220 at 1 day, 0 hours is <span class="font-bold">20 above</span> the phototherapy threshold, 80 below the exchange transfusion threshold.';
|
|
const expectedColour = 'orange';
|
|
|
|
let d = chronoAgeInDays(dateBirth, dateMeasurement);
|
|
let phototherapy_thresh_value = nice_phototherapy_thresh(d, gestation);
|
|
let exchange_thresh_value = nice_exchange_thresh(d, gestation);
|
|
let [result_text, text_colour, background_colour, accent_colour] = describeBilirubin(d, bilirubin, phototherapy_thresh_value, exchange_thresh_value);
|
|
|
|
assert.equal(d, 1);
|
|
assert.equal(result_text, expectedText);
|
|
assert.equal(text_colour, 'text-' + expectedColour + '-800');
|
|
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
|
|
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
|
|
});
|
|
|
|
test('Above exchange transfusion threshold', () => {
|
|
const bilirubin = 350;
|
|
const expectedText = 'Bilirubin of 350 at 1 day, 0 hours is 50 above the <span class="font-bold">exchange transfusion</span> threshold.';
|
|
const expectedColour = 'red';
|
|
|
|
let d = chronoAgeInDays(dateBirth, dateMeasurement);
|
|
let phototherapy_thresh_value = nice_phototherapy_thresh(d, gestation);
|
|
let exchange_thresh_value = nice_exchange_thresh(d, gestation);
|
|
let [result_text, text_colour, background_colour, accent_colour] = describeBilirubin(d, bilirubin, phototherapy_thresh_value, exchange_thresh_value);
|
|
|
|
assert.equal(d, 1);
|
|
assert.equal(result_text, expectedText);
|
|
assert.equal(text_colour, 'text-' + expectedColour + '-800');
|
|
assert.equal(background_colour, 'bg-' + expectedColour + '-50');
|
|
assert.equal(accent_colour, 'border-' + expectedColour + '-400');
|
|
});
|
|
});
|