/* 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 . */ // 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 180 below the phototherapy threshold.'; const expectedColour = 'sky'; let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin); 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 40 below the phototherapy threshold.'; const expectedColour = 'yellow'; let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin); 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 20 above the phototherapy threshold, 80 below the exchange transfusion threshold.'; const expectedColour = 'orange'; let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin); 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 exchange transfusion threshold.'; const expectedColour = 'red'; let [d, result_text, text_colour, background_colour, accent_colour] = describeBilirubin(gestation, dateBirth, dateMeasurement, bilirubin); 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'); }); });