// ============================================================ // bedside/agitation.js // AGITATION — step 1/2/3 pathway, drugs.json-backed. // ============================================================ import { S } from './shared.js'; // Fallback inline data — mirrors drugs.json agitation section, split into // step-2 (PO/IN) and step-3 (IV/IM) subgroups by the route field. // Display-name column intentionally drops the route suffix from the JSON // name so the table still shows "Lorazepam" / "Midazolam" / "Ketamine". var AGIT_FALLBACK = [ // Step 2 — PO / IN { name: 'Lorazepam PO', display: 'Lorazepam', step: 2, dose_mg_per_kg: 0.05, max_mg: 2, unit: 'mg', route: 'PO', notes: '0.05 mg/kg. May repeat in 30 min.' }, { name: 'Midazolam PO', display: 'Midazolam', step: 2, dose_mg_per_kg: 0.5, max_mg: 10, unit: 'mg', route: 'PO', notes: '0.5 mg/kg (max 10 mg)' }, { name: 'Midazolam IN', display: 'Midazolam', step: 2, dose_mg_per_kg: 0.3, max_mg: 10, unit: 'mg', route: 'IN (5 mg/mL)', notes: '0.3 mg/kg split between nares (max 10 mg)' }, { name: 'Olanzapine (ODT)', display: 'Olanzapine (ODT)', step: 2, dose_mg_per_kg: null, max_mg: null, unit: 'mg', route: 'PO / ODT', notes: 'Age ≥6 yr. Avoid IM + benzo combo (risk of resp depression).', dose_display_if_under_30kg: '2.5-5 mg', dose_display_if_30kg_or_more: '5-10 mg' }, { name: 'Diphenhydramine PO', display: 'Diphenhydramine', step: 2, dose_mg_per_kg: 1, max_mg: 50, unit: 'mg', route: 'PO', notes: '1 mg/kg. Adjunct only; sedating.' }, // Step 3 — IV / IM { name: 'Midazolam IV/IM', display: 'Midazolam', step: 3, dose_mg_per_kg: 0.1, max_mg: 5, unit: 'mg', route: 'IV / IM', notes: '0.05-0.1 mg/kg IV, 0.1-0.15 mg/kg IM (max 10 mg)' }, { name: 'Lorazepam IV/IM', display: 'Lorazepam', step: 3, dose_mg_per_kg: 0.1, max_mg: 4, unit: 'mg', route: 'IV / IM', notes: '0.05-0.1 mg/kg (max 4 mg). May cause resp depression.' }, { name: 'Haloperidol', display: 'Haloperidol', step: 3, dose_mg_per_kg: 0.05, max_mg: null, unit: 'mg', route: 'IM / IV', notes: 'Avoid <3 yr. Risk: QT, EPS, NMS. ECG if repeated.', dose_display_if_under_40kg: '0.025-0.075 mg/kg', dose_display_if_40kg_or_more: '2.5-5 mg' }, { name: 'Olanzapine IM', display: 'Olanzapine', step: 3, dose_mg_per_kg: null, max_mg: null, unit: 'mg', route: 'IM', notes: 'Avoid benzo co-administration (resp depression, hypotension)', dose_display_if_under_40kg: '2.5-5 mg', dose_display_if_40kg_or_more: '5-10 mg' }, { name: 'Ketamine IM', display: 'Ketamine', step: 3, dose_mg_per_kg: 4, max_mg: 500, unit: 'mg', route: 'IM', notes: '4-5 mg/kg IM (rescue for severe excited delirium). Monitor airway.' }, { name: 'Droperidol', display: 'Droperidol', step: 3, dose_mg_per_kg: 0.05, max_mg: null, unit: 'mg', route: 'IM / IV', notes: 'Effective but QT concern — get ECG.', dose_display_prefix: '0.03-0.07 mg/kg' } ]; function agitDrugs() { var s = window._DRUGS && window._DRUGS.sections && window._DRUGS.sections.agitation; if (s && s.drugs && s.drugs.length) { // Merge per-drug hints from fallback (display name, step) when the // JSON doesn't carry them — keeps rendering identical. return s.drugs.map(function(dg) { var fb = AGIT_FALLBACK.filter(function(x) { return x.name === dg.name; })[0] || {}; return Object.assign({}, fb, dg); }); } return AGIT_FALLBACK; } // Render one drug row, handling the agitation-specific display quirks: // weight-conditional dose strings (Olanzapine, Haloperidol) and hand- // computed "prefix = value mg" strings (Droperidol, Haloperidol <40 kg). function agitRowFor(wt, dg) { var dose; if (dg.dose_display_if_under_30kg && dg.dose_display_if_30kg_or_more) { dose = wt < 30 ? dg.dose_display_if_under_30kg : dg.dose_display_if_30kg_or_more; } else if (dg.dose_display_if_under_40kg && dg.dose_display_if_40kg_or_more) { dose = wt < 40 ? dg.dose_display_if_under_40kg + ' = ' + S.d(wt, dg.dose_mg_per_kg) + ' mg' : dg.dose_display_if_40kg_or_more; } else if (dg.dose_display_prefix) { dose = dg.dose_display_prefix + ' = ' + S.d(wt, dg.dose_mg_per_kg) + ' mg'; } else if (dg.dose_mg_per_kg != null) { dose = S.dStr(wt, dg.dose_mg_per_kg, dg.max_mg, ' ' + dg.unit); } else { dose = dg.dose_display || ''; } return S.drugRow(dg.display || dg.name, dose, dg.route, dg.notes); } function calcAgit() { var wt = parseFloat(document.getElementById('agit-weight').value); var el = document.getElementById('agit-result'); if (!wt) { el.innerHTML = '
Enter weight (kg).
'; return; } var drugs = agitDrugs(); var step2 = drugs.filter(function(dg) { return dg.step === 2; }); var step3 = drugs.filter(function(dg) { return dg.step === 3; }); var html = '