// ============================================================
// bedside/respiratory.js
// RESPIRATORY MANAGEMENT (Asthma, PRAM, Croup, Bronchiolitis).
// Keeps its own local dose/doseStr/drugRow/drugTable helpers —
// the layout differs from S.drugTable (no 'Notes' column alignment).
// ============================================================
import { S } from './shared.js';
function dose(wt, mgPerKg, maxMg) { var d = Math.round(wt * mgPerKg * 10) / 10; return maxMg ? Math.min(d, maxMg) : d; }
// Delegates to the shared S.dStr so the per-kg math is visible to the prescriber.
function doseStr(wt, mgPerKg, maxMg, unit) {
return S.dStr(wt, mgPerKg, maxMg, unit);
}
function drugRow(name, doseText, route, notes) {
return '
| ' + name + ' | ' + doseText + ' | ' + route + ' | ' + (notes || '') + ' |
';
}
function drugTable(rows) {
return '| Drug | Dose | Route | Notes |
' + rows + '
';
}
function severityBadge(label, color) { return '' + label + ''; }
function asthmaManagement(severity) {
var wt = parseFloat(document.getElementById('resp-weight').value);
var resultDiv = document.getElementById('asthma-result');
if (!wt) { resultDiv.innerHTML = 'Enter weight (kg).
'; return; }
var html = '';
if (severity === 'mild') {
html += severityBadge('Mild Exacerbation', '#10b981');
html += 'Speaks in sentences, no accessory muscle use, SpO2 ≥94%
';
html += drugTable(
drugRow('Albuterol (MDI)', '4-8 puffs via spacer', 'Inhaled', 'q20min x 3 doses, then q1-4h') +
drugRow('Albuterol (neb)', doseStr(wt, 0.15, 5, ' mg') + ' (min 2.5 mg)', 'Nebulized', 'q20min x 3 doses') +
drugRow('Dexamethasone', doseStr(wt, 0.6, 16), 'PO/IV', 'Single dose, or 2 days') +
drugRow('Prednisolone', doseStr(wt, 1, 60) + '/day', 'PO', 'Alternative: 3-5 day course')
);
html += 'Reassess after 1 hour. If improving → discharge with albuterol MDI + spacer + oral steroid course. If not improving → escalate to moderate.
';
} else if (severity === 'moderate') {
html += severityBadge('Moderate Exacerbation', '#f59e0b');
html += 'Speaks in phrases, some accessory muscle use, SpO2 90-93%
';
html += drugTable(
drugRow('Albuterol (neb)', doseStr(wt, 0.15, 5, ' mg') + ' (min 2.5 mg)', 'Nebulized', 'q20min x 3 doses, then continuous if needed') +
drugRow('Ipratropium', wt < 20 ? '250 mcg' : '500 mcg', 'Nebulized', 'q20min x 3 doses with albuterol') +
drugRow('Dexamethasone', doseStr(wt, 0.6, 16), 'PO/IV/IM', 'Single dose') +
drugRow('O2 supplemental', 'Target SpO2 ≥94%', 'Nasal cannula/mask', 'Titrate to effect')
);
html += 'Reassess after 1-2 hours. If improving → step down to mild protocol. If worsening or no improvement → escalate to severe.
';
} else {
html += severityBadge('Severe / Life-Threatening', '#ef4444');
html += 'Speaks in words only, significant accessory muscle use, SpO2 <90%. Consider ICU.
';
html += drugTable(
drugRow('Albuterol continuous', doseStr(wt, 0.5, 20, ' mg') + '/hr', 'Continuous neb', 'Or 0.15-0.3 mg/kg q20min') +
drugRow('Ipratropium', wt < 20 ? '250 mcg' : '500 mcg', 'Nebulized', 'q20min x 3 doses with albuterol') +
drugRow('Dexamethasone', doseStr(wt, 0.6, 16), 'IV', 'Or methylprednisolone 2 mg/kg IV (max 60 mg)') +
drugRow('Magnesium sulfate', doseStr(wt, 50, 2000) + ' IV over 20 min', 'IV', 'Single dose, monitor BP') +
drugRow('Epinephrine (IM)', doseStr(wt, 0.01, 0.5) + ' (1:1000)', 'IM', 'If impending arrest / no IV access') +
drugRow('Terbutaline', doseStr(wt, 0.01, 0.4) + ' SC/IV', 'SC or IV bolus', 'Then 0.1-10 mcg/kg/min infusion') +
drugRow('O2 supplemental', 'Target SpO2 ≥94%', 'High flow / NIPPV', 'Consider BiPAP/CPAP')
);
html += 'Continuous monitoring. Consider ICU admission. If no response to magnesium → terbutaline infusion. If impending respiratory failure → intubation (ketamine preferred induction agent).
';
// Clinical decision points specific to severe asthma
html += '';
// ABG
html += '
' +
'
When to obtain a blood gas
' +
'• Severe exacerbation
not responding after 1-2 h aggressive therapy
' +
'• Impending respiratory failure — altered mentation, fatigue, silent chest
' +
'• SpO2 <92% despite supplemental O2
' +
'• Suspected CO2 retention (rising PCO2 in a previously tachypneic patient)
' +
'
Interpretation: asthmatics hyperventilate → expect
low PCO2. A
"normal" or rising PCO2 = impending failure. Don\'t delay treatment for the gas.' +
'
';
// Intubation
html += '
' +
'
When to intubate (mostly clinical)
' +
'•
Absolute: apnea, cardiac arrest, coma, inability to protect airway
' +
'• Progressive fatigue despite maximal therapy (NIV, mag, terbutaline, heliox)
' +
'• Refractory hypoxemia / hypercapnia with acidosis
' +
'• Silent chest + deteriorating consciousness
' +
'
RSI choice: ketamine 1-2 mg/kg (bronchodilator, preserves BP) +
rocuronium. Avoid succs if hyperkalemic. Permissive hypercapnia after tube; allow expiration (low rate, I:E 1:3-4).' +
'
';
// Heliox
html += '
' +
'
Heliox (He/O2)
' +
'• Lower gas density → less turbulence → reduced work of breathing through narrowed airways.
' +
'•
Consider in: severe asthma not responding to max therapy (bridge), upper airway obstruction (croup, post-extubation stridor, FB partial).
' +
'• Typical mix:
70:30 He:O2 (or 80:20). Delivered via tight non-rebreather or in-line with neb.
' +
'•
Limitation: requires FiO2 ≤ 30-40%. If patient needs higher FiO2, heliox can\'t help.
' +
'• Evidence in asthma is mixed — use as adjunct, not substitute.' +
'
';
html += '
';
}
html += 'NAEPP/GINA guidelines. Always use clinical judgment. Verify doses against institutional protocols.
';
resultDiv.innerHTML = html;
}
function calcPRAM() {
var total = ['pram-spo2','pram-retractions','pram-scalene','pram-air','pram-wheeze'].reduce(function(s, id) {
return s + parseInt(document.getElementById(id).value);
}, 0);
var severity = total <= 3 ? 'Mild' : total <= 7 ? 'Moderate' : 'Severe';
var color = total <= 3 ? '#10b981' : total <= 7 ? '#f59e0b' : '#ef4444';
document.getElementById('pram-result').innerHTML = 'PRAM Score: ' + total + '/12 — ' + severity + 'Mild (0-3): outpatient management. Moderate (4-7): consider oral steroids + frequent bronchodilators. Severe (8-12): aggressive treatment, consider ICU.
';
}
function calcCroup() {
var wt = parseFloat(document.getElementById('resp-weight').value) || 10;
var total = ['croup-conscious','croup-cyanosis','croup-stridor','croup-air','croup-retractions'].reduce(function(s, id) {
return s + parseInt(document.getElementById(id).value);
}, 0);
var severity, color, treatment;
if (total <= 2) { severity = 'Mild'; color = '#10b981'; treatment = drugTable(drugRow('Dexamethasone', doseStr(wt, 0.6, 16), 'PO (single dose)', 'Preferred corticosteroid') + drugRow('Supportive care', 'Cool mist, comfort measures', '', 'Discharge if tolerating PO')); }
else if (total <= 5) { severity = 'Moderate'; color = '#f59e0b'; treatment = drugTable(drugRow('Dexamethasone', doseStr(wt, 0.6, 16), 'PO/IM', 'Single dose') + drugRow('Racemic epinephrine', '0.5 mL of 2.25% solution', 'Nebulized', 'Observe 2-4 hrs after for rebound') + drugRow('Nebulized epinephrine', '0.5 mL/kg of 1:1000 (max 5 mL)', 'Nebulized', 'Alternative to racemic')); }
else if (total <= 11) { severity = 'Severe'; color = '#ef4444'; treatment = drugTable(drugRow('Dexamethasone', doseStr(wt, 0.6, 16), 'IV/IM', 'Immediate') + drugRow('Racemic epinephrine', '0.5 mL of 2.25% solution', 'Nebulized', 'May repeat q15-20min, observe 2-4 hrs') + drugRow('Nebulized epinephrine', '0.5 mL/kg of 1:1000 (max 5 mL)', 'Nebulized', 'Alternative') + drugRow('Heliox', '70:30 or 80:20', 'Face mask', 'Consider if not responding') + drugRow('O2 supplemental', 'Target SpO2 ≥94%', 'Blow-by preferred', 'Minimize agitation')); }
else { severity = 'Impending Respiratory Failure'; color = '#dc2626'; treatment = 'Immediate airway management. Prepare for intubation (use ETT 0.5-1 size smaller than predicted). Call anesthesia/ENT. Continue nebulized epinephrine and dexamethasone IV.
'; }
document.getElementById('croup-result').innerHTML = 'Westley Score: ' + total + '/17 — ' + severity + '
' + treatment + 'Westley WJ et al. Nebulized racemic epinephrine by IPPB for the treatment of croup. Am J Dis Child 1978. Mild ≤2, Moderate 3-5, Severe 6-11, Impending failure ≥12.
';
}
function calcBronchiolitis() {
var wt = parseFloat(document.getElementById('resp-weight').value) || 5;
var age = document.getElementById('bronch-age').value;
var spo2 = document.getElementById('bronch-spo2').value;
var hydration = document.getElementById('bronch-hydration').value;
var distress = document.getElementById('bronch-distress').value;
var html = 'Bronchiolitis Management
';
var admit = distress === 'severe' || spo2 === 'low' || hydration === 'poor' || age === '<12w';
if (admit) {
html += severityBadge('Admit / Observe', '#ef4444');
html += '';
if (age === '<12w') html += '
⚠ Age <12 weeks — high risk for apnea. Monitor closely.
';
html += '
';
} else {
html += severityBadge('Likely Safe for Discharge', '#10b981');
}
html += 'Supportive Care (evidence-based):
';
html += drugTable(
drugRow('Nasal suctioning', 'Bulb suction or NasalClear', 'Nasal', 'Before feeds and as needed') +
drugRow('O2 supplemental', 'Target SpO2 ≥90%', 'NC / high flow', spo2 === 'low' ? 'Required' : 'If needed') +
drugRow('Hypertonic saline 3%', '4 mL nebulized', 'Nebulized', 'Consider in inpatients (AAP weak recommendation)') +
(hydration === 'poor' ? drugRow('IV fluids', 'NS/LR bolus ' + doseStr(wt, 20, null, ' mL'), 'IV', 'Then maintenance D5 0.45NS') + drugRow('NG feeds', 'If unable to feed orally', 'NG tube', 'Preferred over IV if gut functional') : '')
);
html += 'NOT recommended (AAP 2014/2023): Albuterol/salbutamol (no benefit in bronchiolitis), epinephrine (no evidence of benefit), systemic corticosteroids (no benefit), antibiotics (unless secondary bacterial infection), chest physiotherapy.
';
html += 'AAP Clinical Practice Guideline: Management of Bronchiolitis in Infants and Children (2014, reaffirmed 2023). RSV is the most common cause (50-80%).
';
document.getElementById('bronch-result').innerHTML = html;
}
export function init() {
// Sub-pill navigation
document.addEventListener('click', function(e) {
var pill = e.target.closest('[data-resp]');
if (pill) {
document.querySelectorAll('[data-resp]').forEach(function(p) { p.classList.remove('active'); });
pill.classList.add('active');
['asthma','croup','bronchiolitis'].forEach(function(s) {
var el = document.getElementById('resp-' + s);
if (el) el.style.display = pill.dataset.resp === s ? '' : 'none';
});
}
if (e.target.closest('[data-asthma-severity]')) asthmaManagement(e.target.closest('[data-asthma-severity]').dataset.asthmaSeverity);
if (e.target.id === 'btn-pram-calc' || e.target.closest('#btn-pram-calc')) calcPRAM();
if (e.target.id === 'btn-croup-calc' || e.target.closest('#btn-croup-calc')) calcCroup();
if (e.target.id === 'btn-bronch-calc' || e.target.closest('#btn-bronch-calc')) calcBronchiolitis();
});
}