diff --git a/public/js/calculators.js b/public/js/calculators.js index 0d2815a..b14c735 100644 --- a/public/js/calculators.js +++ b/public/js/calculators.js @@ -4,6 +4,7 @@ import { calculateBMIAssessment, loadBmiLmsData } from './calculators/bmi.js'; import { calculateBPAssessment, computeBPPercentile, loadBpReferenceData } from './calculators/bp.js'; import { calculateBsa, calculateWeightBasedDose } from './calculators/dosing.js'; import { loadEquipmentData, renderEquipmentResult } from './calculators/equipment.js'; +import { calculateGcs } from './calculators/gcs.js'; import { loadGrowthLmsData } from './calculators/growth.js'; import { initImageLightbox } from './calculators/lightbox.js'; import { loadResusMedsData, renderResusMeds } from './calculators/resus.js'; @@ -1111,19 +1112,14 @@ initImageLightbox(); var eye = parseInt(document.getElementById(prefix + '-eye').value) || 0; var verbal = parseInt(document.getElementById(prefix + '-verbal').value) || 0; var motor = parseInt(document.getElementById(prefix + '-motor').value) || 0; - var total = eye + verbal + motor; - - var severity, color, bg; - if (total <= 8) { severity = 'Severe (Coma)'; color = '#ef4444'; bg = '#fee2e2'; } - else if (total <= 12) { severity = 'Moderate'; color = '#f59e0b'; bg = '#fef3c7'; } - else { severity = 'Mild'; color = '#10b981'; bg = '#d1fae5'; } + var score = calculateGcs(eye, verbal, motor); var resultDiv = document.getElementById('gcs-result'); if (resultDiv) { resultDiv.innerHTML = - '
' + - '
GCS: ' + total + '/15
' + - '
' + severity + '
' + + '
' + + '
GCS: ' + score.total + '/15
' + + '
' + score.severity + '
' + '
' + '
' + '
Eye (E)
' + eye + '
' + diff --git a/public/js/calculators/gcs.js b/public/js/calculators/gcs.js new file mode 100644 index 0000000..566afe6 --- /dev/null +++ b/public/js/calculators/gcs.js @@ -0,0 +1,18 @@ +export function calculateGcs(eye, verbal, motor) { + var total = eye + verbal + motor; + var severity, color, bg; + if (total <= 8) { + severity = 'Severe (Coma)'; + color = '#ef4444'; + bg = '#fee2e2'; + } else if (total <= 12) { + severity = 'Moderate'; + color = '#f59e0b'; + bg = '#fef3c7'; + } else { + severity = 'Mild'; + color = '#10b981'; + bg = '#d1fae5'; + } + return { total: total, severity: severity, color: color, bg: bg }; +} diff --git a/test/calculators-data.test.js b/test/calculators-data.test.js index f1ddf39..6182f15 100644 --- a/test/calculators-data.test.js +++ b/test/calculators-data.test.js @@ -419,3 +419,10 @@ test('dosing helpers preserve BSA and weight-based dose outputs', async () => { assert.equal(capped.volumeMl, 10); assert.equal(capped.capped, true); }); + +test('GCS helper preserves severity thresholds', async () => { + const gcs = await import('../public/js/calculators/gcs.js'); + assert.deepEqual(gcs.calculateGcs(1, 1, 1), { total: 3, severity: 'Severe (Coma)', color: '#ef4444', bg: '#fee2e2' }); + assert.equal(gcs.calculateGcs(2, 3, 4).severity, 'Moderate'); + assert.equal(gcs.calculateGcs(4, 5, 6).severity, 'Mild'); +});