extract calculator GCS helper
This commit is contained in:
parent
ae0ca83ccb
commit
9b5f01a19b
3 changed files with 30 additions and 9 deletions
|
|
@ -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 =
|
||||
'<div class="calc-result-header" style="background:' + bg + ';border-color:' + color + ';">' +
|
||||
'<div style="font-size:24px;font-weight:700;color:' + color + ';">GCS: ' + total + '/15</div>' +
|
||||
'<div style="font-size:14px;color:var(--g600);margin-top:4px;">' + severity + '</div>' +
|
||||
'<div class="calc-result-header" style="background:' + score.bg + ';border-color:' + score.color + ';">' +
|
||||
'<div style="font-size:24px;font-weight:700;color:' + score.color + ';">GCS: ' + score.total + '/15</div>' +
|
||||
'<div style="font-size:14px;color:var(--g600);margin-top:4px;">' + score.severity + '</div>' +
|
||||
'</div>' +
|
||||
'<div class="calc-result-grid" style="margin-top:12px;">' +
|
||||
'<div class="calc-result-item"><div class="calc-result-label">Eye (E)</div><div class="calc-result-value">' + eye + '</div></div>' +
|
||||
|
|
|
|||
18
public/js/calculators/gcs.js
Normal file
18
public/js/calculators/gcs.js
Normal file
|
|
@ -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 };
|
||||
}
|
||||
|
|
@ -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');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue