Management of hypokalemia and hyperkalemia (pharmacology)

Reading File
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Loading Image
Loading Image
I now have comprehensive, detailed pharmacological content from multiple authoritative sources. Let me compile the full answer.

Management of Hypokalemia and Hyperkalemia - Pharmacology


HYPOKALEMIA

Definition & Severity Classification

SeveritySerum K⁺
Mild3.0 - 3.5 mEq/L
Moderate2.5 - 3.0 mEq/L
Severe< 2.5 mEq/L
Hypokalemia is the most common electrolyte abnormality in clinical practice - affecting >20% of hospitalized patients and up to 40% of outpatients on thiazide diuretics.
Key rule: Each 0.3 mEq/L drop in serum K⁺ below normal corresponds to roughly 100 mEq of total body potassium deficit.

ECG Changes in Hypokalemia

Progressive changes with falling K⁺:
ECG changes in hypokalemia showing T-wave flattening, prominent U waves, and ST depression at K⁺ levels of 3.9, 2.7, and 1.3 mEq/L
  • T-wave flattening
  • Prominent U wave (deflection after T wave)
  • ST-segment depression
  • Prolonged QT interval (>500 ms raises risk of torsades de pointes 2-3x)
  • Increased P-wave amplitude, prolonged PR interval

Pharmacological Management of Hypokalemia

Treatment depends on severity and presence of organ dysfunction (especially cardiac).

1. Oral Potassium Replacement (Mild-to-Moderate Hypokalemia)

  • Drug of choice: Potassium chloride (KCl) - preferred because co-existing hypochloremic alkalosis benefits from chloride as well
  • Available in liquid, powder, and tablet form
  • Dose: 40-60 mEq PO every 2-4 hours, well tolerated
  • Maintenance/chronic: 60-80 mEq/day
  • Suitable when no nausea/vomiting is driving the hypokalemia

2. Intravenous Potassium Replacement (Severe or Symptomatic Hypokalemia)

  • Reserved for: significant ECG changes, arrhythmias, severe muscle weakness, K⁺ < 2.0 mEq/L, or QT > 500 ms
  • Goal of IV therapy: Remove from immediate danger - not to correct entire deficit
  • Standard rate: 10-20 mEq/hr via peripheral line
  • Rates > 20 mEq/hr: require central venous access + continuous cardiac monitoring
  • Peripheral IV should not exceed 8 mEq/hr due to venous irritation
  • Maximum daily dose: 240 mEq/day
  • Avoid dextrose-containing solutions - they stimulate insulin release, which drives K⁺ into cells and can worsen hypokalemia transiently

3. Treat Concurrent Hypomagnesemia

  • Hypokalemia is very frequently associated with hypomagnesemia
  • Magnesium deficiency impairs renal K⁺ conservation - potassium replacement fails until Mg²⁺ is corrected
  • Always check and replete magnesium when treating hypokalemia; suspect hypomagnesemia if K⁺ does not respond to replacement

4. Potassium-Sparing Strategies (Prevention/Chronic Management)

For diuretic-induced hypokalemia, the mechanism involves 4 pathways: increased tubular flow, AVP secretion, aldosterone secretion, and metabolic alkalosis. Drugs used to prevent or treat:
Drug ClassAgentsMechanism
Mineralocorticoid receptor antagonistsSpironolactone, eplerenoneBlock aldosterone-driven K⁺ secretion
ENaC blockersAmiloride, triamtereneBlock sodium reabsorption in collecting duct, reduce K⁺ secretion
ACE inhibitors / ARBsEnalapril, losartanSuppress RAAS, reduce aldosterone
Direct renin inhibitorsAliskirenSuppress RAAS upstream

Special Considerations

  • Digoxin toxicity: Hypokalemia sensitizes the heart to digoxin toxicity - aggressive K⁺ repletion is critical in this setting
  • Cardiac patients (heart failure, MI, arrhythmia): Target K⁺ 4.0-5.0 mEq/L; even mild hypokalemia is an independent risk factor for morbidity/mortality
  • Beta-agonists as a cause: Albuterol 1 standard nebulized dose reduces K⁺ by 0.2-0.4 mEq/L; a second dose within 1 hour can reduce it by ~1 mEq/L

HYPERKALEMIA

Definition & Severity Classification

SeveritySerum K⁺
Mild5.5 - 6.0 mEq/L
Moderate6.1 - 6.9 mEq/L
Severe≥ 7.0 mEq/L
K⁺ > 6 mEq/L should always be corrected due to lethal potential.

ECG Changes in Hyperkalemia

Sequential progression with rising K⁺:
ECG changes in hyperkalemia progressing from peaked T waves to widened QRS to sine wave pattern
  1. Peaked (tented) T waves - usually at K⁺ > 5.5-6.5 mEq/L
  2. Widening QRS complex
  3. PR prolongation → P wave disappearance (at K⁺ > 6.5-7.5 mEq/L)
  4. Loss of R-wave amplitude, ST changes
  5. Sine wave pattern → Ventricular fibrillation / asystole (at K⁺ > 7-8 mEq/L)

The 3-Step Framework for Hyperkalemia Treatment

Treatment is organized into three sequential goals:
Step 1: Stabilize the cardiac membrane Step 2: Shift K⁺ into cells (temporizing) Step 3: Remove K⁺ from the body (definitive)

Step 1 - Cardiac Membrane Stabilization

DrugDoseOnsetDurationNotes
Calcium gluconate 10%10 mL (1 g) IV over 2-3 min; repeat after 5 min if needed1-3 min30-60 minFirst-line for ECG changes
Calcium chloride 10%5-10 mL (0.5-1 g) IV1-3 min30-60 minMore elemental Ca²⁺ per mL (3x), can cause tissue necrosis if extravasated - prefer central line
  • Mechanism: Calcium raises the cardiac action potential threshold, directly antagonizing the depolarizing effect of hyperkalemia on myocardial cell membranes. Does NOT lower serum K⁺.
  • Caution with digoxin: Calcium potentiates digoxin toxicity - give slowly and with caution in digoxin patients

Step 2 - Shifting K⁺ into Cells (Temporizing)

These agents lower serum K⁺ quickly but do not remove it from the body.
DrugDoseOnsetPeak EffectK⁺ Reduction
Regular insulin + DextroseInsulin 10 units IV push + Dextrose 50% 50 mL (25 g) IV push< 15 min30-60 min~0.6 mEq/L
Nebulized albuterol10-15 mg by continuous inhalation (high dose)< 15 min30-60 min0.5-1.0 mEq/L
Sodium bicarbonate50-100 mEq IV infusion~15 minVariableModest
Beta-2 agonists (IV/SC)Low-dose epinephrine infusionMinutesRapidUseful in massive transfusion
Notes on each agent:
  • Insulin + Glucose: Activates Na⁺/K⁺-ATPase, driving K⁺ intracellularly. Use 5 units insulin if renal dysfunction (to avoid hypoglycemia). Monitor glucose closely. Dextrose is withheld if patient is already hyperglycemic (serum glucose > ~250 mg/dL).
  • Albuterol: Beta-2 stimulation activates Na⁺/K⁺-ATPase. Additive with insulin - combined effect is greater. Particularly useful as an adjunct. Do NOT use as monotherapy in severe hyperkalemia.
  • Sodium bicarbonate: Corrects acidosis, which drives H⁺ out of cells and K⁺ back in. Most effective when metabolic acidosis is present. Less effective in isolated hyperkalemia without acidosis. Also provides sodium load (beneficial in some scenarios).
  • Normal saline bolus (100-250 mL): Used in conjunction with nephrologist guidance if patient is dialysis-dependent.

Step 3 - Remove K⁺ from the Body (Definitive)

MethodOnsetNotes
HemodialysisImmediate/reliableReduces K⁺ by ~1 mEq/L in first hour, another 1 mEq/L over next 2 hours. Definitive treatment. Required in renal failure.
Furosemide (loop diuretic) + IV fluidsMinutes to hoursEffective with intact renal function (e.g., rhabdomyolysis, tumor lysis). Administer by slow infusion (not bolus) to reduce ototoxicity risk. Not reliable in acute management.
Sodium polystyrene sulfonate (SPS, Kayexalate)4-6+ hoursNOT effective for acute/urgent management. Onset too slow. FDA black box warning: risk of intestinal necrosis, especially with abnormal bowel function.
Patiromer (Veltassa)Hours (chronic use)Non-absorbed cation exchange polymer - binds K⁺ in exchange for Ca²⁺ in GI tract. FDA-approved for chronic hyperkalemia. Not for acute/urgent use.
Sodium zirconium cyclosilicate (Lokelma)HoursHighly selective cation exchanger - traps K⁺ in intestines in exchange for Na⁺ and H⁺. Useful for chronic hyperkalemia in CKD and heart failure.

Specific Drug Causes of Hyperkalemia to Address

When drugs are the cause, discontinuation is the primary step:
  • ACE inhibitors / ARBs
  • NSAIDs
  • Spironolactone, amiloride, triamterene
  • Succinylcholine (especially dangerous in CKD patients already hyperkalemic - rapid K⁺ release from depolarizing blockade)
  • Beta-blockers (impair K⁺ uptake into cells)
  • Digoxin overdose
  • Potassium supplements
For hypoaldosteronism-driven hyperkalemia: mineralocorticoid replacement (fludrocortisone) is the targeted treatment.

Anesthetic Considerations in Hyperkalemia

  • Elective surgery should be postponed in significant hyperkalemia
  • Succinylcholine is absolutely contraindicated - causes K⁺ release from muscle depolarization
  • Avoid potassium-containing IV fluids (e.g., Lactated Ringer's)
  • Prevent acidosis (both metabolic and respiratory) - acidosis drives K⁺ extracellularly
  • Consider mild hyperventilation under general anesthesia
  • Monitor neuromuscular blockade closely - hyperkalemia potentiates non-depolarizing NMBs

Summary Table: Hypokalemia vs. Hyperkalemia Pharmacology

FeatureHypokalemiaHyperkalemia
ECGT-wave flat, U wave, ↑QTPeaked T, wide QRS, P loss, sine wave
Cardiac dangerArrhythmias, digoxin toxicityVF/asystole, cardiac arrest
Acute drug RxKCl IV 10-20 mEq/hrCalcium gluconate → Insulin/glucose → Albuterol
Oral RxKCl 40-60 mEq q2-4hPatiromer, SPS (chronic only)
Associated deficiency to correctMagnesiumN/A
Definitive removalN/AHemodialysis (renal failure), furosemide (intact kidneys)
AvoidDextrose-only IVF, insulin without glucoseSuccinylcholine, K⁺-containing IVF, ACEi/ARBs

Sources:
  • Rosen's Emergency Medicine, 9e - Chapter 114
  • Morgan & Mikhail's Clinical Anesthesiology, 7e - Chapter 49
  • Current Surgical Therapy, 14e
  • Brenner and Rector's The Kidney, 2-Volume Set - Chapter 50

from kd tripathi

Finding Sources
Finding Sources
Unfortunately, KD Tripathi's Essentials of Medical Pharmacology is not available in the medical textbook library. The pharmacology books currently in the library are:
  • Goodman & Gilman's The Pharmacological Basis of Therapeutics
  • Katzung's Basic and Clinical Pharmacology, 16th Edition
  • Lippincott Illustrated Reviews: Pharmacology
  • Stahl's Essential Psychopharmacology
I can cover the hypokalemia and hyperkalemia management from any of these - especially Goodman & Gilman's or Katzung's, which are the most comprehensive pharmacology references available. Alternatively, I can present the topic in the style and format typical of KD Tripathi (concise, classification-based, tabular, exam-oriented) using pharmacological principles from the available texts.
Which would you prefer?
  1. From Goodman & Gilman's (closest authoritative pharmacology reference in the library)
  2. From Katzung's Basic & Clinical Pharmacology
  3. In KD Tripathi style (concise, tabular, classification-focused) synthesized from available sources

Management of hypokalemia and hyperkalemia kd tripathi

Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Finding Sources
Reading File
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
I now have enough solid pharmacological content. I'll now compile everything in KD Tripathi's characteristic style - concise, classification-based, bold drug names, mechanism-dose-side effect format, with a clean layout.

Management of Hypokalemia and Hyperkalemia

(In the style of KD Tripathi's Essentials of Medical Pharmacology)

Note: KD Tripathi's textbook is not available in this library. This response is presented in KD Tripathi's characteristic writing style - concise, tabular, drug-classification-based, with mechanism, dose, and notes - drawing from Katzung's Basic & Clinical Pharmacology (16e), Rosen's Emergency Medicine (9e), Barash's Clinical Anesthesia (9e), and Morgan & Mikhail's Clinical Anesthesiology (7e).

HYPOKALEMIA

Normal serum K⁺: 3.5-5.0 mEq/L Hypokalemia: serum K⁺ < 3.5 mEq/L
SeverityK⁺ level
Mild3.0 - 3.5 mEq/L
Moderate2.5 - 3.0 mEq/L
Severe< 2.5 mEq/L
Rule of thumb: Each 0.3 mEq/L fall below normal ≈ 100 mEq total body K⁺ deficit

ECG Changes in Hypokalemia

ECG progression in hypokalemia - T-wave flattening, prominent U wave at K⁺ 3.9, 2.7, 1.3 mEq/L
  • Flattening of T wave → prominent U wave (after T wave)
  • ST-segment depression
  • Prolonged QT interval → risk of torsades de pointes (if QT > 500 ms)
  • Increased P-wave amplitude, PR prolongation

Treatment of Hypokalemia

Treatment depends on severity and presence of organ dysfunction.

A. ORAL POTASSIUM REPLACEMENT

(For mild to moderate hypokalemia, asymptomatic)
Potassium Chloride (KCl) — Drug of choice
  • Why KCl? Most hypokalemia is accompanied by metabolic alkalosis and hypochloremia; chloride co-repletion corrects both.
  • Dose: 40-60 mEq orally every 2-4 hours; maintenance 60-80 mEq/day
  • Forms: Liquid, powder (sachets), slow-release tablets (Slow-K)
  • SE: GI irritation, nausea, GI ulceration with slow-release forms
  • Avoid: Enteric-coated tablets (erratic absorption, GI ulcers)
Alternatives:
  • Potassium bicarbonate/citrate - preferred if acidosis is also present
  • Dietary sources - bananas, oranges, tomatoes (insufficient alone in deficiency)

B. INTRAVENOUS POTASSIUM REPLACEMENT

(For severe hypokalemia, significant ECG changes, arrhythmias, weakness)
Drug: Potassium Chloride (KCl) IV infusion
RouteMax RateCondition
Peripheral IV10 mEq/hr (max 20 mEq/hr)Standard
Peripheral IVDo NOT exceed 8 mEq/hrAvoids vein irritation
Central venous10-20 mEq/hrRapid replacement with ECG monitoring
Any route> 20 mEq/hrOnly for K⁺ < 2.0 mEq/L or QT > 500 ms; mandatory cardiac monitoring
  • Max daily dose: 240 mEq/day
  • Goal: Remove from immediate danger - NOT correct entire deficit in one go
  • Important: Use normal saline as diluent - NOT dextrose. Dextrose stimulates insulin → drives K⁺ into cells → transiently worsens hypokalemia
  • Digoxin patients: Hypokalemia potentiates digoxin toxicity. Aggressive K⁺ repletion is mandatory; target K⁺ 4.0-5.0 mEq/L

C. TREAT CONCURRENT HYPOMAGNESEMIA

  • Hypokalemia frequently co-exists with hypomagnesemia
  • Mg²⁺ deficiency impairs renal K⁺ conservation - K⁺ replacement will fail unless Mg²⁺ is corrected first
  • Magnesium sulfate (MgSO₄) IV given concurrently

D. DRUGS USED TO PREVENT/TREAT DIURETIC-INDUCED HYPOKALEMIA

(Potassium-sparing agents)
DrugClassMechanismDose
SpironolactoneAldosterone antagonistBlocks mineralocorticoid receptor → reduces K⁺ secretion in collecting duct25-100 mg/day
EplerenoneSelective aldosterone antagonistSame as spironolactone; fewer hormonal SE25-50 mg/day
AmilorideENaC blockerBlocks Na⁺ channel in collecting duct → reduces electrochemical gradient for K⁺ secretion5-10 mg/day
TriamtereneENaC blockerSame as amiloride50-150 mg/day
Also used (RAAS inhibitors that reduce aldosterone):
  • ACE inhibitors (enalapril, ramipril)
  • ARBs (losartan, valsartan)
  • Direct renin inhibitor (aliskiren)
Note from Katzung: Loop diuretics increase K⁺ secretion by 4 mechanisms - ↑tubular flow, ↑AVP, ↑aldosterone, metabolic alkalosis. K⁺-sparing agents counteract these. At least one study showed K⁺ supplementation at initiation of loop diuretics (regardless of serum K⁺) improves survival.

HYPERKALEMIA

Hyperkalemia: serum K⁺ > 5.0 mEq/L
SeverityK⁺ level
Mild5.5 - 6.0 mEq/L
Moderate6.1 - 6.9 mEq/L
Severe≥ 7.0 mEq/L
K⁺ > 6 mEq/L must always be treated due to risk of fatal arrhythmia.

ECG Changes in Hyperkalemia (Sequential)

ECG progression in hyperkalemia - peaked T waves, widening QRS, sine wave pattern
  1. Peaked (tented) T waves - first sign (K⁺ ~5.5-6.5 mEq/L)
  2. Widened QRS
  3. PR prolongation → P wave disappears (K⁺ ~6.5-7.5 mEq/L)
  4. Sine wave pattern (K⁺ > 7-8 mEq/L)
  5. VF / Asystole → death
Hypocalcemia, hyponatremia, and acidosis accentuate the cardiac toxicity of hyperkalemia.

Treatment of Hyperkalemia — The 3-Step Approach

STEP 1 → Stabilize cardiac membrane  (fastest, buys time)
STEP 2 → Shift K⁺ into cells         (temporizing, ~60 min)
STEP 3 → Remove K⁺ from body         (definitive)

STEP 1 — Cardiac Membrane Stabilization

Calcium Salts — antagonize the membrane effects of hyperkalemia directly
DrugDoseOnsetDuration
Calcium gluconate 10%10 mL (1 g) IV over 2-3 min; repeat after 5 min if no response1-3 min30-60 min
Calcium chloride 10%5-10 mL IV1-3 min30-60 min
  • Mechanism: Raises the threshold potential of cardiac myocytes → antagonizes the depolarizing effect of high extracellular K⁺ on the resting membrane potential. Does NOT lower serum K⁺.
  • CaCl₂ vs gluconate: CaCl₂ provides ~3x more elemental calcium per mL but causes tissue necrosis if extravasated → prefer central line; gluconate is safer peripherally
  • Caution: In digoxin toxicity - calcium potentiates digoxin cardiac toxicity; administer slowly and monitor ECG

STEP 2 — Shift K⁺ into Cells (Temporizing)

All agents here lower serum K⁺ within 15-60 min but do not remove K⁺ from body.

1. Insulin + Glucose (Most reliable, first-line)

ParameterDetail
DrugRegular insulin + 50% Dextrose
DoseInsulin 10 units IV bolus + Dextrose 50 mL (25 g) IV
In renal failureInsulin 5 units (to reduce hypoglycemia risk)
In hyperglycemiaInsulin without dextrose if glucose > ~250 mg/dL
Onset< 15 minutes
Duration30-60 minutes
K⁺ reduction~0.6 mEq/L
MechanismActivates Na⁺/K⁺-ATPase → drives K⁺ intracellularly
MonitorBlood glucose (hypoglycemia risk)

2. Beta-2 Agonists

ParameterDetail
DrugSalbutamol (Albuterol) nebulized
Dose10-15 mg by continuous nebulization (high dose)
Onset< 15 minutes
K⁺ reduction0.5-1.0 mEq/L
MechanismStimulates β₂ receptors → activates Na⁺/K⁺-ATPase → intracellular K⁺ shift
NoteAdditive with insulin - combined effect > either alone
CautionDo NOT use as monotherapy in severe hyperkalemia. Tachycardia as SE.
For massive transfusion-related hyperkalemia: low-dose IV epinephrine infusion - rapid K⁺ shift + inotropic support.

3. Sodium Bicarbonate

ParameterDetail
Dose50-100 mEq IV over 5-10 min
Onset~15 minutes
MechanismCorrects acidosis → H⁺ exits cells in exchange for K⁺ (K⁺ shifts intracellularly)
Best usedOnly when metabolic acidosis is concurrently present
Least effectiveHyperkalemia without acidosis

STEP 3 — Remove K⁺ from Body (Definitive)

1. Hemodialysis (Most effective)

  • Reduces K⁺ by ~1 mEq/L in first hour, another ~1 mEq/L over next 2 hours
  • Indication: Renal failure (oliguric AKI, CKD, CRF), life-threatening hyperkalemia, failed medical management
  • Only reliable definitive method in renal failure

2. Loop Diuretics (Intact renal function only)

  • Drug: Furosemide IV
  • Enhances urinary K⁺ excretion; supplement with NaCl + water infusion to maintain euvolemia
  • Administer by slow IV infusion (not bolus) to reduce ototoxicity risk
  • Useful in rhabdomyolysis, tumour lysis syndrome (intact urine output)

3. Cation Exchange Resins

DrugMechanismOnsetUse
Sodium polystyrene sulfonate (SPS, Kayexalate)Exchanges Na⁺ for K⁺ in gut4-6 hoursNOT for acute/emergency management. Risk of intestinal necrosis (FDA black box warning). Oral or rectal.
Patiromer (Veltassa)Non-absorbed polymer; binds K⁺ in exchange for Ca²⁺ in GI tractHoursChronic hyperkalemia (CKD, heart failure). FDA-approved. NOT for acute use.
Sodium Zirconium Cyclosilicate (SZC, Lokelma)Highly selective cation exchanger; traps K⁺ in intestine in exchange for Na⁺/H⁺~4 hours (K⁺ < 5.5 mEq/L in median 4 hrs in trials)Chronic hyperkalemia. Approved in US and EU. NOT for acute/emergency use.
SPS is no longer recommended for emergent management due to lack of efficacy within 4 hours and serious GI complications. Patiromer and SZC are preferred for outpatient chronic hyperkalemia management.

Drugs That CAUSE Hyperkalemia (to identify and stop)

Drug/ClassMechanism
ACE inhibitors, ARBs↓ angiotensin II → ↓ aldosterone → ↓ K⁺ excretion
Spironolactone, amiloride, triamtereneDirect K⁺-sparing action
NSAIDs↓ renin → ↓ aldosterone (type IV RTA pattern)
Beta-blockersImpair K⁺ uptake into cells
SuccinylcholineDepolarization → K⁺ efflux from muscle; absolutely contraindicated in hyperkalemia
Heparin↓ adrenal aldosterone synthesis
Digoxin overdoseInhibits Na⁺/K⁺-ATPase → K⁺ leaks out of cells
For hypoaldosteronism-induced hyperkalemiaFludrocortisone (mineralocorticoid replacement)

Quick Comparison Table

FeatureHypokalemiaHyperkalemia
K⁺ level< 3.5 mEq/L> 5.0 mEq/L
ECG hallmarkFlat T, prominent U wave, ↑QTPeaked T waves → sine wave
First-line acute drugKCl oral/IVCalcium gluconate IV
Temporizing (shift K⁺)N/AInsulin + glucose, Albuterol
Definitive removalN/ADialysis (renal failure), Furosemide (intact kidneys)
Chronic oral drugKCl + K⁺-sparing diureticPatiromer / SZC
AvoidDextrose IVF alone, delay in Mg²⁺ correctionSuccinylcholine, K⁺-containing IVF, SPS in acute setting
Key associated deficiencyHypomagnesemiaN/A
Digoxin interactionPotentiates toxicity (replace K⁺ aggressively)Calcium potentiates digoxin toxicity (give cautiously)

Sources: Katzung's Basic & Clinical Pharmacology 16e, Rosen's Emergency Medicine 9e, Morgan & Mikhail's Clinical Anesthesiology 7e, Barash's Clinical Anesthesia 9e

Create a concise PDF reference card for hypokalemia and hyperkalemia management

Reading File
Running Command

ls -la /home/daytona/workspace/ 2>/dev/null || echo "workspace not found"

Running Command

mkdir -p /home/daytona/workspace/potassium-refcard && python3 -c "import reportl…

Writing File

~/potassium-refcard/build_refcard.py

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.units import mm
from reportlab.platypus import (
    SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer,
    HRFlowable, KeepTogether
)
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_CENTER, TA_LEFT
from reportlab.platypus import BaseDocTemplate, Frame, PageTemplate

# ── Colour palette ─────────────────────────────────────────────────────────────
BLUE_DARK   = colors.HexColor("#1a3a5c")   # header bar
BLUE_MID    = colors.HexColor("#1e6091")   # section title
BLUE_LIGHT  = colors.HexColor("#d6eaf8")   # hypo col header bg
RED_DARK    = colors.HexColor("#7b1a1a")   # hyperK accents
RED_LIGHT   = colors.HexColor("#fde8e8")   # hyperK col header bg
AMBER       = colors.HexColor("#fff3cd")   # warning rows
GREEN_LIGHT = colors.HexColor("#d5f5e3")   # step header bg
GRAY_LIGHT  = colors.HexColor("#f4f6f8")   # alternating rows
WHITE       = colors.white
BLACK       = colors.HexColor("#1a1a1a")

# ── Output path ────────────────────────────────────────────────────────────────
OUTPUT = "/home/daytona/workspace/potassium-refcard/Potassium_Management_Refcard.pdf"

W, H = A4  # 595 x 842 pt

# ── Document ───────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT,
    pagesize=A4,
    leftMargin=12*mm, rightMargin=12*mm,
    topMargin=10*mm, bottomMargin=10*mm,
)

# ── Base styles ────────────────────────────────────────────────────────────────
SS = getSampleStyleSheet()

def sty(name, **kw):
    return ParagraphStyle(name, **kw)

TITLE  = sty("Title",  fontSize=15, textColor=WHITE,      fontName="Helvetica-Bold",
             alignment=TA_CENTER, spaceAfter=0, leading=18)
SUBTITLE = sty("Sub",  fontSize=8,  textColor=colors.HexColor("#cce3f5"),
             fontName="Helvetica",  alignment=TA_CENTER, spaceAfter=0)
SEC    = sty("Sec",    fontSize=9,  textColor=WHITE,       fontName="Helvetica-Bold",
             alignment=TA_CENTER,   spaceAfter=0, leading=11)
BODY   = sty("Body",   fontSize=7.5, textColor=BLACK,      fontName="Helvetica",
             leading=10, spaceAfter=0)
BODY_B = sty("BodyB",  fontSize=7.5, textColor=BLACK,      fontName="Helvetica-Bold",
             leading=10, spaceAfter=0)
SMALL  = sty("Small",  fontSize=6.5, textColor=colors.HexColor("#444444"),
             fontName="Helvetica", leading=9)
WARN   = sty("Warn",   fontSize=7,  textColor=colors.HexColor("#7b4f00"),
             fontName="Helvetica-Bold", leading=9)
FOOT   = sty("Foot",   fontSize=5.5, textColor=colors.HexColor("#888888"),
             fontName="Helvetica", alignment=TA_CENTER)

def p(text, style=BODY):  return Paragraph(text, style)
def pb(text):             return Paragraph(text, BODY_B)
def ps(text):             return Paragraph(text, SMALL)
def sp(h=2):              return Spacer(1, h*mm)

# ── Helper: section header bar ─────────────────────────────────────────────────
def sec_bar(text, bg=BLUE_MID, full_width=True):
    col_w = (W - 24*mm)  # total usable width
    tbl = Table([[p(text, SEC)]], colWidths=[col_w])
    tbl.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), bg),
        ("TOPPADDING",    (0,0), (-1,-1), 3),
        ("BOTTOMPADDING", (0,0), (-1,-1), 3),
        ("LEFTPADDING",   (0,0), (-1,-1), 5),
        ("RIGHTPADDING",  (0,0), (-1,-1), 5),
    ]))
    return tbl

# ── Helper: two-column section bar ─────────────────────────────────────────────
HALF = (W - 24*mm) / 2 - 1*mm

def two_sec_bars(left_text, right_text):
    row = [p(left_text, SEC), p(right_text, SEC)]
    tbl = Table([row], colWidths=[HALF, HALF])
    tbl.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (0,0), BLUE_MID),
        ("BACKGROUND", (1,0), (1,0), RED_DARK),
        ("TOPPADDING",    (0,0), (-1,-1), 3),
        ("BOTTOMPADDING", (0,0), (-1,-1), 3),
        ("LEFTPADDING",   (0,0), (-1,-1), 6),
        ("RIGHTPADDING",  (0,0), (-1,-1), 6),
        ("LINEAFTER",     (0,0), (0,-1), 2, WHITE),
    ]))
    return tbl

# ── Helper: styled data table ──────────────────────────────────────────────────
def make_table(data, col_widths, header_bg=BLUE_LIGHT, alt_bg=GRAY_LIGHT):
    """data[0] = header row (bold), rest = body rows."""
    styled_data = []
    for i, row in enumerate(data):
        styled_row = []
        for cell in row:
            if isinstance(cell, str):
                if i == 0:
                    styled_row.append(pb(cell))
                else:
                    styled_row.append(p(cell))
            else:
                styled_row.append(cell)
        styled_data.append(styled_row)

    tbl = Table(styled_data, colWidths=col_widths, repeatRows=1)
    style_cmds = [
        ("BACKGROUND",    (0,0), (-1,0), header_bg),
        ("LINEBELOW",     (0,0), (-1,0), 0.5, BLUE_MID),
        ("GRID",          (0,0), (-1,-1), 0.3, colors.HexColor("#cccccc")),
        ("TOPPADDING",    (0,0), (-1,-1), 2),
        ("BOTTOMPADDING", (0,0), (-1,-1), 2),
        ("LEFTPADDING",   (0,0), (-1,-1), 3),
        ("RIGHTPADDING",  (0,0), (-1,-1), 3),
        ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ]
    for i in range(1, len(styled_data)):
        if i % 2 == 0:
            style_cmds.append(("BACKGROUND", (0,i), (-1,i), alt_bg))
    tbl.setStyle(TableStyle(style_cmds))
    return tbl

# ══════════════════════════════════════════════════════════════════════════════
# BUILD CONTENT
# ══════════════════════════════════════════════════════════════════════════════
story = []
TW = W - 24*mm   # total usable width

# ── TITLE BLOCK ────────────────────────────────────────────────────────────────
title_tbl = Table(
    [[p("POTASSIUM DISORDERS — MANAGEMENT REFERENCE CARD", TITLE)],
     [p("Hypokalemia  ·  Hyperkalemia  ·  Pharmacology", SUBTITLE)]],
    colWidths=[TW]
)
title_tbl.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), BLUE_DARK),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("ROUNDEDCORNERS", [4]),
]))
story.append(title_tbl)
story.append(sp(2))

# ── NORMAL VALUES + CLASSIFICATION (side-by-side) ─────────────────────────────
story.append(two_sec_bars("HYPOKALEMIA  (K⁺ < 3.5 mEq/L)", "HYPERKALEMIA  (K⁺ > 5.0 mEq/L)"))

class_data = [
    ["Severity", "K⁺ (mEq/L)", "Severity", "K⁺ (mEq/L)"],
    ["Mild",     "3.0 – 3.5",  "Mild",     "5.5 – 6.0"],
    ["Moderate", "2.5 – 3.0",  "Moderate", "6.1 – 6.9"],
    ["Severe",   "< 2.5",      "Severe",   "≥ 7.0"],
]
cw = [TW*0.15, TW*0.10, TW*0.15, TW*0.10]   # only 4 cols; fill remaining
full_cw = [TW*0.175, TW*0.135, TW*0.175, TW*0.135]
class_tbl = make_table(class_data, full_cw, header_bg=BLUE_LIGHT)
# recolour hyperK header cols
class_tbl.setStyle(TableStyle([
    ("BACKGROUND", (2,0), (3,0), RED_LIGHT),
    ("LINEAFTER",  (1,0), (1,-1), 1, BLUE_MID),
]))
story.append(class_tbl)
story.append(sp(1))

# Rule of thumb
rule_tbl = Table(
    [[p("📌  Rule: each 0.3 mEq/L drop below normal ≈ 100 mEq total body K⁺ deficit", WARN)]],
    colWidths=[TW]
)
rule_tbl.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), AMBER),
    ("TOPPADDING", (0,0), (-1,-1), 3), ("BOTTOMPADDING", (0,0), (-1,-1), 3),
    ("LEFTPADDING", (0,0), (-1,-1), 5),
    ("BOX", (0,0), (-1,-1), 0.5, colors.HexColor("#e6a817")),
]))
story.append(rule_tbl)
story.append(sp(2))

# ── ECG CHANGES (side-by-side) ─────────────────────────────────────────────────
story.append(two_sec_bars("ECG CHANGES — HYPOKALEMIA", "ECG CHANGES — HYPERKALEMIA"))
ecg_data = [
    ["Hypokalemia ECG Findings",          "Hyperkalemia ECG Findings (sequential)"],
    ["• Flat / inverted T waves",         "① Peaked (tented) T waves  (K⁺ ~5.5–6.5)"],
    ["• Prominent U waves (after T wave)","② PR prolongation → P wave disappears"],
    ["• ST-segment depression",           "③ Wide QRS complex  (K⁺ ~6.5–7.5)"],
    ["• Prolonged QT interval",           "④ Sine-wave pattern  (K⁺ > 7–8)"],
    ["• QT > 500 ms → Torsades risk 2-3×","⑤ VF / Asystole → DEATH"],
]
ecg_tbl = make_table(ecg_data, [TW*0.5 - 1*mm, TW*0.5 - 1*mm],
                     header_bg=BLUE_LIGHT)
ecg_tbl.setStyle(TableStyle([
    ("BACKGROUND", (1,0), (1,0), RED_LIGHT),
    ("BACKGROUND", (1,5), (1,5), RED_LIGHT),
    ("LINEAFTER",  (0,0), (0,-1), 1, BLUE_MID),
]))
story.append(ecg_tbl)
story.append(sp(1))
note_tbl = Table(
    [[p("⚠  Hypocalcemia, hyponatremia, and acidosis accentuate cardiac toxicity of hyperkalemia", WARN)]],
    colWidths=[TW]
)
note_tbl.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), RED_LIGHT),
    ("TOPPADDING", (0,0), (-1,-1), 2), ("BOTTOMPADDING", (0,0), (-1,-1), 2),
    ("LEFTPADDING", (0,0), (-1,-1), 5),
    ("BOX", (0,0), (-1,-1), 0.5, RED_DARK),
]))
story.append(note_tbl)
story.append(sp(3))

# ══ HYPOKALEMIA TREATMENT ══════════════════════════════════════════════════════
story.append(sec_bar("▶  TREATMENT OF HYPOKALEMIA"))
story.append(sp(1))

# Oral replacement
oral_data = [
    ["Drug",                    "Route", "Dose",                            "Notes"],
    ["Potassium Chloride (KCl)","Oral",  "40–60 mEq q2–4h; maint 60–80 mEq/day",
     "Drug of choice. Corrects co-existing hypochloremic alkalosis"],
    ["KCl",                    "IV",    "10–20 mEq/hr peripheral\n(max 8 mEq/hr to avoid vein irritation)",
     "For severe/symptomatic or ECG changes"],
    ["KCl",                    "IV central","Up to 20 mEq/hr",
     "K⁺ < 2.0 or QT > 500 ms. Continuous ECG monitoring mandatory"],
    ["Potassium bicarbonate/citrate","Oral","As required",
     "Preferred when metabolic acidosis is also present"],
]
oral_tbl = make_table(oral_data, [TW*0.22, TW*0.10, TW*0.30, TW*0.38], header_bg=BLUE_LIGHT)
story.append(oral_tbl)
story.append(sp(1))

iv_warn = Table([[p("⚠  IV diluent: use Normal Saline — NOT dextrose (insulin released by dextrose drives K⁺ into cells, worsening hypokalemia)  |  Max daily dose: 240 mEq/day", WARN)]], colWidths=[TW])
iv_warn.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), AMBER),
    ("TOPPADDING", (0,0), (-1,-1), 2), ("BOTTOMPADDING", (0,0), (-1,-1), 2),
    ("LEFTPADDING", (0,0), (-1,-1), 5),
    ("BOX", (0,0), (-1,-1), 0.5, colors.HexColor("#e6a817")),
]))
story.append(iv_warn)
story.append(sp(2))

# K-sparing drugs
story.append(sec_bar("▶  K⁺-SPARING DRUGS (Prevention / Diuretic-Induced Hypokalemia)", bg=BLUE_MID))
story.append(sp(1))
ksp_data = [
    ["Drug",              "Class",                       "Mechanism",                               "Dose"],
    ["Spironolactone",    "Aldosterone antagonist",      "Blocks mineralocorticoid receptor → ↓ K⁺ secretion in collecting duct", "25–100 mg/day"],
    ["Eplerenone",        "Selective aldo. antagonist",  "Same; fewer hormonal SE (no gynaecomastia)","25–50 mg/day"],
    ["Amiloride",         "ENaC blocker",                "Blocks Na⁺ channel in collecting duct → ↓ electrochemical gradient for K⁺ secretion","5–10 mg/day"],
    ["Triamterene",       "ENaC blocker",                "Same mechanism as amiloride",              "50–150 mg/day"],
    ["ACEi / ARBs",       "RAAS inhibitors",             "↓ Angiotensin II → ↓ aldosterone → ↓ K⁺ excretion","As per indication"],
    ["Fludrocortisone",   "Mineralocorticoid",           "Replacement in hypoaldosteronism-driven hypoK⁺","0.1 mg/day"],
]
ksp_tbl = make_table(ksp_data, [TW*0.18, TW*0.20, TW*0.40, TW*0.22], header_bg=BLUE_LIGHT)
story.append(ksp_tbl)
story.append(sp(1))
mg_box = Table([[p("🔑  Always check and correct hypomagnesemia — Mg²⁺ deficiency impairs renal K⁺ conservation; K⁺ replacement will FAIL until Mg²⁺ is corrected", WARN)]], colWidths=[TW])
mg_box.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), GREEN_LIGHT),
    ("TOPPADDING", (0,0), (-1,-1), 3), ("BOTTOMPADDING", (0,0), (-1,-1), 3),
    ("LEFTPADDING", (0,0), (-1,-1), 5),
    ("BOX", (0,0), (-1,-1), 0.5, colors.HexColor("#1e8449")),
]))
story.append(mg_box)
story.append(sp(3))

# ══ HYPERKALEMIA TREATMENT ════════════════════════════════════════════════════
story.append(sec_bar("▶  TREATMENT OF HYPERKALEMIA — 3-STEP APPROACH", bg=RED_DARK))
story.append(sp(1))

steps_data = [
    ["Step", "Goal",                       "Drug / Intervention",            "Dose",                                "Onset",       "K⁺ Effect"],
    ["1",    "Stabilise cardiac membrane", "Calcium gluconate 10% IV",       "10 mL (1 g) over 2–3 min; repeat ×1 after 5 min","1–3 min","None (cardioprotective only)"],
    ["1",    "Stabilise cardiac membrane", "Calcium chloride 10% IV",        "5–10 mL; prefer central line (tissue necrosis risk)","1–3 min","None"],
    ["2",    "Shift K⁺ into cells",        "Regular Insulin + Dextrose 50%", "Insulin 10 U IV + Dextrose 25 g IV\n(5 U if renal failure)","<15 min","↓ ~0.6 mEq/L"],
    ["2",    "Shift K⁺ into cells",        "Salbutamol (Albuterol) nebulised","10–15 mg continuous nebulisation",    "<15 min",     "↓ 0.5–1.0 mEq/L"],
    ["2",    "Shift K⁺ into cells",        "Sodium Bicarbonate IV",          "50–100 mEq over 5–10 min",            "~15 min",     "Modest (use only if acidosis present)"],
    ["3",    "Remove K⁺ from body",        "Furosemide IV",                  "Slow infusion (rate per clinical need); add NaCl if hypovolaemic","Minutes–hours","Definitive (intact renal fn)"],
    ["3",    "Remove K⁺ from body",        "Patiromer (Veltassa)",           "8.4 g oral daily; titrate",           "Hours",       "Chronic use only — NOT acute"],
    ["3",    "Remove K⁺ from body",        "Sodium Zirconium Cyclosilicate (Lokelma)","10 g oral TDS × 48 h, then 5–10 g/day","~4 h","Chronic — NOT acute emergency"],
    ["3",    "Remove K⁺ from body",        "Haemodialysis",                  "Emergent",                            "Immediate",   "↓ ~1 mEq/L/hr; definitive in renal failure"],
]
hyper_tbl = make_table(steps_data,
    [TW*0.04, TW*0.12, TW*0.22, TW*0.26, TW*0.10, TW*0.26],
    header_bg=RED_LIGHT)
# colour step rows
hyper_tbl.setStyle(TableStyle([
    ("BACKGROUND", (0,1), (0,2), colors.HexColor("#d6eaf8")),   # step 1 blue
    ("BACKGROUND", (0,3), (0,5), GREEN_LIGHT),                  # step 2 green
    ("BACKGROUND", (0,6), (0,9), colors.HexColor("#fde8e8")),   # step 3 red
    ("FONTNAME",   (0,1), (0,-1), "Helvetica-Bold"),
    ("ALIGN",      (0,0), (0,-1), "CENTER"),
]))
story.append(hyper_tbl)
story.append(sp(1))

sps_warn = Table([[p("⚠  Sodium Polystyrene Sulfonate (Kayexalate / SPS): NOT recommended — onset > 4 h (ineffective acutely); FDA black-box warning — risk of intestinal necrosis", WARN)]], colWidths=[TW])
sps_warn.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), RED_LIGHT),
    ("TOPPADDING", (0,0), (-1,-1), 3), ("BOTTOMPADDING", (0,0), (-1,-1), 3),
    ("LEFTPADDING", (0,0), (-1,-1), 5),
    ("BOX", (0,0), (-1,-1), 0.5, RED_DARK),
]))
story.append(sps_warn)
story.append(sp(1))

# Digoxin note
dig_box = Table([[p("⚠  Calcium in digoxin toxicity: potentiates digoxin cardiac toxicity — administer slowly with ECG monitoring. Insulin without dextrose if glucose > 250 mg/dL.", WARN)]], colWidths=[TW])
dig_box.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), AMBER),
    ("TOPPADDING", (0,0), (-1,-1), 2), ("BOTTOMPADDING", (0,0), (-1,-1), 2),
    ("LEFTPADDING", (0,0), (-1,-1), 5),
    ("BOX", (0,0), (-1,-1), 0.5, colors.HexColor("#e6a817")),
]))
story.append(dig_box)
story.append(sp(3))

# ── DRUGS CAUSING HYPERKALEMIA ─────────────────────────────────────────────────
story.append(sec_bar("▶  DRUGS CAUSING HYPERKALEMIA — IDENTIFY & STOP", bg=RED_DARK))
story.append(sp(1))
cause_data = [
    ["Drug / Class",                         "Mechanism"],
    ["ACE inhibitors / ARBs",                "↓ Angiotensin II → ↓ Aldosterone → ↓ K⁺ excretion"],
    ["Spironolactone / Amiloride / Triamterene","K⁺-sparing action in collecting duct"],
    ["NSAIDs",                               "↓ Renin → ↓ Aldosterone (type IV RTA pattern)"],
    ["Beta-blockers",                        "Impair intracellular K⁺ uptake via β₂ blockade"],
    ["Succinylcholine",                      "Depolarising block → K⁺ efflux from muscle. CONTRAINDICATED in hyperkalemia"],
    ["Heparin",                              "↓ Adrenal aldosterone synthesis"],
    ["Digoxin overdose",                     "Inhibits Na⁺/K⁺-ATPase → K⁺ leaks out of cells"],
    ["Potassium supplements / K⁺ penicillin","Exogenous K⁺ load"],
]
cause_tbl = make_table(cause_data, [TW*0.35, TW*0.65], header_bg=RED_LIGHT)
story.append(cause_tbl)
story.append(sp(3))

# ── QUICK COMPARISON TABLE ────────────────────────────────────────────────────
story.append(sec_bar("▶  QUICK COMPARISON SUMMARY", bg=BLUE_DARK))
story.append(sp(1))
comp_data = [
    ["Feature",                "HYPOKALEMIA",                                   "HYPERKALEMIA"],
    ["K⁺ level",               "< 3.5 mEq/L",                                  "> 5.0 mEq/L"],
    ["ECG hallmark",           "Flat T, prominent U wave, ↑QT",               "Peaked T → sine wave → VF"],
    ["Immediate drug",         "KCl oral 40–60 mEq q2–4h",                    "Ca gluconate 10 mL IV"],
    ["Temporising",            "—",                                             "Insulin 10U + Dextrose 25g IV"],
    ["Adjunct shift",          "—",                                             "Albuterol 10–15 mg nebulised"],
    ["Definitive removal",     "—",                                             "Dialysis (renal failure); Furosemide (intact kidneys)"],
    ["Chronic oral drug",      "KCl + K⁺-sparing diuretic",                   "Patiromer / SZC (Lokelma)"],
    ["Key co-deficiency",      "Hypomagnesemia — must correct first",           "—"],
    ["Avoid",                  "Dextrose IVF alone; delay in Mg²⁺ correction", "Succinylcholine; K⁺-containing IVF; SPS acutely"],
    ["Digoxin interaction",    "↓ K⁺ potentiates digoxin toxicity",            "Ca²⁺ potentiates digoxin toxicity"],
    ["Target K⁺ in HF/MI",    "4.0 – 5.0 mEq/L",                             "< 5.0 mEq/L"],
]
comp_tbl = make_table(comp_data, [TW*0.22, TW*0.39, TW*0.39], header_bg=BLUE_LIGHT)
comp_tbl.setStyle(TableStyle([
    ("BACKGROUND", (2,0), (2,0), RED_LIGHT),
    ("LINEAFTER",  (0,0), (0,-1), 0.5, BLUE_MID),
    ("LINEAFTER",  (1,0), (1,-1), 0.5, BLUE_MID),
    ("FONTNAME",   (0,1), (0,-1), "Helvetica-Bold"),
]))
story.append(comp_tbl)
story.append(sp(2))

# ── FOOTER ─────────────────────────────────────────────────────────────────────
story.append(HRFlowable(width=TW, thickness=0.5, color=BLUE_MID))
story.append(sp(1))
story.append(p("Sources: Katzung's Basic & Clinical Pharmacology 16e · Morgan & Mikhail's Clinical Anesthesiology 7e · Rosen's Emergency Medicine 9e · Barash's Clinical Anesthesia 9e  |  For educational use only", FOOT))

# ── BUILD ──────────────────────────────────────────────────────────────────────
doc.build(story)
print(f"PDF created: {OUTPUT}")
Running Command

cd /home/daytona/workspace/potassium-refcard && python3 build_refcard.py 2>&1

Running Command

ls -lh /home/daytona/workspace/potassium-refcard/Potassium_Management_Refcard.pd…

Your reference card is ready. Here's what's included across the single A4 page:
Sections covered:
  1. Classification - Severity grades for both hypokalemia and hyperkalemia side-by-side
  2. ECG Changes - Sequential changes for both disorders in a parallel table
  3. Hypokalemia Treatment - KCl oral and IV dosing table with routes, rates, and cautions
  4. K⁺-Sparing Drugs - Spironolactone, eplerenone, amiloride, triamterene, ACEi/ARBs with mechanisms and doses
  5. Hyperkalemia 3-Step Table - Step 1 (Ca gluconate/chloride), Step 2 (insulin+glucose, albuterol, bicarb), Step 3 (furosemide, patiromer, SZC, dialysis) with onset and K⁺ reduction per agent
  6. Drugs Causing Hyperkalemia - With mechanisms
  7. Quick Comparison Summary - Side-by-side at-a-glance table
Colour coding: Blue = hypokalemia, Red = hyperkalemia, Amber = warnings, Green = key pearls

Potassium Management Refcard

PDF Document · PDF

Generate a quick-reference Word document with case scenarios fvc

Reading File
Running Command

ls /home/daytona/skills/docx/scripts/office/ && node --version && ls /home/dayto…

Running Command

mkdir -p /home/daytona/workspace/potassium-docx && ls /home/daytona/skills/docx/…

Writing File

~/potassium-docx/build.js

"use strict";
const {
  Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
  HeadingLevel, AlignmentType, BorderStyle, WidthType, ShadingType,
  VerticalAlign, PageNumber, Header, Footer, ImageRun, TableOfContents,
  PageBreak, convertInchesToTwip, UnderlineType
} = require("docx");
const fs = require("fs");

// ── Colour palette ─────────────────────────────────────────────────────────
const BLUE_DARK  = "1A3A5C";
const BLUE_MID   = "1E6091";
const BLUE_LIGHT = "D6EAF8";
const RED_DARK   = "7B1A1A";
const RED_LIGHT  = "FDE8E8";
const AMBER      = "FFF3CD";
const GREEN_DARK = "1A5C2A";
const GREEN_LIGHT= "D5F5E3";
const ORANGE     = "F0A500";
const GRAY_LIGHT = "F4F6F8";
const WHITE      = "FFFFFF";
const BLACK      = "1A1A1A";

// ── Helpers ────────────────────────────────────────────────────────────────
const pt = (n) => n * 20; // half-points → twips for spacing

function run(text, opts = {}) {
  return new TextRun({
    text,
    font: "Calibri",
    size: opts.size || 20,
    bold: opts.bold || false,
    italics: opts.italic || false,
    color: opts.color || BLACK,
    highlight: opts.highlight || undefined,
    underline: opts.underline ? { type: UnderlineType.SINGLE } : undefined,
  });
}

function para(children, opts = {}) {
  const runs = children.map((c) =>
    typeof c === "string" ? run(c, opts) : c
  );
  return new Paragraph({
    children: runs,
    alignment: opts.align || AlignmentType.LEFT,
    spacing: { before: opts.before || 40, after: opts.after || 40 },
    indent: opts.indent ? { left: convertInchesToTwip(0.25) } : undefined,
  });
}

function headingPara(text, level, color = WHITE, bg = BLUE_DARK) {
  return new Paragraph({
    children: [new TextRun({ text, font: "Calibri", size: level === 1 ? 28 : level === 2 ? 24 : 22, bold: true, color })],
    heading: level === 1 ? HeadingLevel.HEADING_1 : level === 2 ? HeadingLevel.HEADING_2 : HeadingLevel.HEADING_3,
    alignment: AlignmentType.LEFT,
    spacing: { before: 120, after: 60 },
    shading: { type: ShadingType.CLEAR, fill: bg },
  });
}

function sectionBar(text, bg = BLUE_MID) {
  return new Paragraph({
    children: [new TextRun({ text: "  " + text, font: "Calibri", size: 22, bold: true, color: WHITE })],
    alignment: AlignmentType.LEFT,
    spacing: { before: 160, after: 60 },
    shading: { type: ShadingType.CLEAR, fill: bg },
  });
}

function noteBox(text, fill = AMBER, textColor = "7B4F00") {
  return new Table({
    width: { size: 100, type: WidthType.PERCENTAGE },
    rows: [new TableRow({ children: [
      new TableCell({
        width: { size: 100, type: WidthType.PERCENTAGE },
        shading: { type: ShadingType.CLEAR, fill },
        borders: allBorders("B8860B", 8),
        children: [new Paragraph({
          children: [new TextRun({ text, font: "Calibri", size: 18, bold: true, color: textColor })],
          spacing: { before: 60, after: 60 },
          indent: { left: convertInchesToTwip(0.1) },
        })],
      }),
    ]})]
  });
}

function allBorders(color = "AAAAAA", sz = 4) {
  const b = { style: BorderStyle.SINGLE, size: sz, color };
  return { top: b, bottom: b, left: b, right: b, insideHorizontal: b, insideVertical: b };
}

function headerRow(cells, widths, bg = BLUE_LIGHT) {
  return new TableRow({
    tableHeader: true,
    children: cells.map((text, i) =>
      new TableCell({
        width: { size: widths[i], type: WidthType.PERCENTAGE },
        shading: { type: ShadingType.CLEAR, fill: bg },
        verticalAlign: VerticalAlign.CENTER,
        children: [new Paragraph({
          children: [new TextRun({ text, font: "Calibri", size: 19, bold: true, color: BLACK })],
          spacing: { before: 40, after: 40 },
          indent: { left: convertInchesToTwip(0.05) },
        })],
      })
    ),
  });
}

function dataRow(cells, widths, bg = WHITE, textColor = BLACK, bold = false) {
  return new TableRow({
    children: cells.map((text, i) =>
      new TableCell({
        width: { size: widths[i], type: WidthType.PERCENTAGE },
        shading: { type: ShadingType.CLEAR, fill: bg },
        verticalAlign: VerticalAlign.TOP,
        children: [new Paragraph({
          children: [new TextRun({ text, font: "Calibri", size: 18, color: textColor, bold })],
          spacing: { before: 30, after: 30 },
          indent: { left: convertInchesToTwip(0.05) },
        })],
      })
    ),
  });
}

function makeTable(headers, rows, widths, headerBg = BLUE_LIGHT) {
  const allRows = [headerRow(headers, widths, headerBg)];
  rows.forEach((r, i) => allRows.push(dataRow(r, widths, i % 2 === 0 ? WHITE : GRAY_LIGHT)));
  return new Table({
    width: { size: 100, type: WidthType.PERCENTAGE },
    rows: allRows,
    borders: allBorders("CCCCCC", 4),
  });
}

// ── Case scenario builder ──────────────────────────────────────────────────
function caseScenario(num, title, bg, accentBg, accentColor, fields) {
  // fields: { presentation, labs, ecg, diagnosis, management, keyPearl }
  const items = [];

  // Case title bar
  items.push(new Table({
    width: { size: 100, type: WidthType.PERCENTAGE },
    rows: [new TableRow({ children: [
      new TableCell({
        shading: { type: ShadingType.CLEAR, fill: bg },
        borders: allBorders(bg, 0),
        children: [new Paragraph({
          children: [
            new TextRun({ text: `  CASE ${num}: `, font: "Calibri", size: 24, bold: true, color: WHITE }),
            new TextRun({ text: title, font: "Calibri", size: 24, bold: true, color: WHITE }),
          ],
          spacing: { before: 80, after: 80 },
        })],
      }),
    ]})]
  }));

  // 2-col layout: Presentation | Labs + ECG
  items.push(new Table({
    width: { size: 100, type: WidthType.PERCENTAGE },
    rows: [new TableRow({ children: [
      // Left cell: Presentation
      new TableCell({
        width: { size: 48, type: WidthType.PERCENTAGE },
        shading: { type: ShadingType.CLEAR, fill: WHITE },
        borders: allBorders("DDDDDD", 4),
        children: [
          new Paragraph({ children: [new TextRun({ text: "PRESENTATION", font: "Calibri", size: 19, bold: true, color: bg })], spacing: { before: 50, after: 30 }, indent: { left: convertInchesToTwip(0.05) } }),
          new Paragraph({ children: [new TextRun({ text: fields.presentation, font: "Calibri", size: 18, color: BLACK })], spacing: { before: 20, after: 40 }, indent: { left: convertInchesToTwip(0.05) } }),
        ],
      }),
      // Right cell: Labs + ECG
      new TableCell({
        width: { size: 52, type: WidthType.PERCENTAGE },
        shading: { type: ShadingType.CLEAR, fill: GRAY_LIGHT },
        borders: allBorders("DDDDDD", 4),
        children: [
          new Paragraph({ children: [new TextRun({ text: "LABS & ECG", font: "Calibri", size: 19, bold: true, color: bg })], spacing: { before: 50, after: 30 }, indent: { left: convertInchesToTwip(0.05) } }),
          new Paragraph({ children: [new TextRun({ text: fields.labs, font: "Calibri", size: 18, color: BLACK })], spacing: { before: 20, after: 20 }, indent: { left: convertInchesToTwip(0.05) } }),
          new Paragraph({ children: [new TextRun({ text: "ECG: " + fields.ecg, font: "Calibri", size: 18, bold: false, color: BLACK })], spacing: { before: 10, after: 40 }, indent: { left: convertInchesToTwip(0.05) } }),
        ],
      }),
    ]})]
  }));

  // Diagnosis row
  items.push(new Table({
    width: { size: 100, type: WidthType.PERCENTAGE },
    rows: [new TableRow({ children: [
      new TableCell({
        shading: { type: ShadingType.CLEAR, fill: accentBg },
        borders: allBorders(bg, 6),
        children: [new Paragraph({
          children: [
            new TextRun({ text: "DIAGNOSIS: ", font: "Calibri", size: 20, bold: true, color: bg }),
            new TextRun({ text: fields.diagnosis, font: "Calibri", size: 20, bold: true, color: accentColor }),
          ],
          spacing: { before: 60, after: 60 },
          indent: { left: convertInchesToTwip(0.1) },
        })],
      }),
    ]})]
  }));

  // Management table
  items.push(new Paragraph({
    children: [new TextRun({ text: "  MANAGEMENT STEPS", font: "Calibri", size: 20, bold: true, color: WHITE })],
    shading: { type: ShadingType.CLEAR, fill: bg },
    spacing: { before: 60, after: 40 },
  }));
  items.push(makeTable(
    ["Step", "Action", "Drug / Dose", "Rationale"],
    fields.management,
    [8, 22, 38, 32],
    accentBg
  ));

  // Key Pearl
  items.push(noteBox("💡  KEY PEARL: " + fields.keyPearl, accentBg, accentColor));
  items.push(new Paragraph({ children: [], spacing: { before: 80, after: 20 } }));

  return items;
}

// ══════════════════════════════════════════════════════════════════════════════
// DOCUMENT CONTENT
// ══════════════════════════════════════════════════════════════════════════════
const content = [];

// ── Title Block ────────────────────────────────────────────────────────────
content.push(new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    new TableRow({ children: [new TableCell({
      shading: { type: ShadingType.CLEAR, fill: BLUE_DARK },
      borders: allBorders(BLUE_DARK, 0),
      children: [
        new Paragraph({
          children: [new TextRun({ text: "POTASSIUM DISORDERS", font: "Calibri", size: 40, bold: true, color: WHITE })],
          alignment: AlignmentType.CENTER, spacing: { before: 120, after: 40 },
        }),
        new Paragraph({
          children: [new TextRun({ text: "Quick-Reference Guide with Clinical Case Scenarios", font: "Calibri", size: 24, color: "AAD4F5", italics: true })],
          alignment: AlignmentType.CENTER, spacing: { before: 0, after: 60 },
        }),
        new Paragraph({
          children: [new TextRun({ text: "Hypokalemia  ·  Hyperkalemia  ·  Pharmacology  ·  KD Tripathi Style", font: "Calibri", size: 20, color: "7FB8E8" })],
          alignment: AlignmentType.CENTER, spacing: { before: 0, after: 100 },
        }),
      ],
    })})]
  ]
}));
content.push(new Paragraph({ children: [], spacing: { before: 60, after: 20 } }));

// ══ SECTION 1: Classification ═════════════════════════════════════════════
content.push(sectionBar("1.  CLASSIFICATION & SEVERITY", BLUE_MID));

content.push(makeTable(
  ["Disorder", "Definition", "Mild", "Moderate", "Severe"],
  [
    ["Hypokalemia", "Serum K⁺ < 3.5 mEq/L", "3.0–3.5 mEq/L", "2.5–3.0 mEq/L", "< 2.5 mEq/L"],
    ["Hyperkalemia", "Serum K⁺ > 5.0 mEq/L", "5.5–6.0 mEq/L", "6.1–6.9 mEq/L", "≥ 7.0 mEq/L"],
  ],
  [18, 28, 18, 18, 18],
  BLUE_LIGHT
));
content.push(noteBox("📌  Rule: Each 0.3 mEq/L drop below normal ≈ 100 mEq total body K⁺ deficit  |  Normal K⁺: 3.5–5.0 mEq/L", AMBER, "7B4F00"));

// ══ SECTION 2: ECG Changes ════════════════════════════════════════════════
content.push(sectionBar("2.  ECG CHANGES", BLUE_MID));

content.push(makeTable(
  ["Hypokalemia — ECG Findings", "Hyperkalemia — ECG Sequence"],
  [
    ["Flat / inverted T waves", "① Peaked (tented) T waves  (K⁺ ~5.5–6.5 mEq/L)"],
    ["Prominent U waves (after T wave)", "② Prolonged PR interval"],
    ["ST-segment depression", "③ P wave disappears  (K⁺ ~6.5–7.5 mEq/L)"],
    ["Prolonged QT interval", "④ Wide QRS complex"],
    ["QT > 500 ms → Torsades de Pointes (2–3× risk)", "⑤ Sine-wave pattern → VF / Asystole  (K⁺ > 7–8)"],
  ],
  [50, 50],
  BLUE_LIGHT
));
content.push(noteBox("⚠  Hypocalcaemia, hyponatraemia, and acidosis ACCENTUATE cardiac toxicity of hyperkalemia", RED_LIGHT, RED_DARK));

// ══ SECTION 3: Hypokalemia Treatment ══════════════════════════════════════
content.push(sectionBar("3.  TREATMENT OF HYPOKALEMIA", BLUE_MID));

content.push(makeTable(
  ["Drug", "Route", "Dose", "Notes"],
  [
    ["Potassium Chloride (KCl)", "Oral", "40–60 mEq q2–4h; maintenance 60–80 mEq/day", "Drug of choice. Corrects co-existing hypochloraemic alkalosis"],
    ["KCl", "IV Peripheral", "10 mEq/hr (max 20 mEq/hr); max 8 mEq/hr to avoid vein irritation", "For symptomatic/moderate hypokalemia"],
    ["KCl", "IV Central", "Up to 20 mEq/hr with continuous ECG monitoring", "K⁺ < 2.0 mEq/L or QT > 500 ms. Central access mandatory"],
    ["Potassium bicarbonate / citrate", "Oral", "As required", "Use when metabolic acidosis co-exists"],
    ["Magnesium sulfate (MgSO₄)", "IV", "1–2 g IV over 10–20 min", "Correct hypomagnesaemia first — K⁺ replacement will fail otherwise"],
  ],
  [18, 14, 36, 32],
  BLUE_LIGHT
));
content.push(noteBox("⚠  IV diluent: Normal Saline ONLY — NOT Dextrose (dextrose → insulin release → K⁺ driven intracellularly → worsens hypokalemia)  |  Max daily IV dose: 240 mEq/day", AMBER, "7B4F00"));

// K+ sparing
content.push(new Paragraph({ children: [new TextRun({ text: "Potassium-Sparing Drugs (Prevention / Diuretic-Induced Hypokalemia)", font: "Calibri", size: 20, bold: true, color: BLUE_MID })], spacing: { before: 100, after: 40 } }));
content.push(makeTable(
  ["Drug", "Class", "Mechanism", "Dose"],
  [
    ["Spironolactone", "Aldosterone antagonist", "Blocks mineralocorticoid receptor → ↓ K⁺ secretion in collecting duct", "25–100 mg/day"],
    ["Eplerenone", "Selective aldo. antagonist", "Same; no gynaecomastia (selective for MR)", "25–50 mg/day"],
    ["Amiloride", "ENaC blocker", "Blocks luminal Na⁺ channel → ↓ electrochemical gradient for K⁺ secretion", "5–10 mg/day"],
    ["Triamterene", "ENaC blocker", "Same as amiloride", "50–150 mg/day"],
    ["ACEi / ARBs", "RAAS inhibitors", "↓ Angiotensin II → ↓ aldosterone → ↓ K⁺ excretion", "As per indication"],
    ["Fludrocortisone", "Mineralocorticoid replacement", "Used when hypoaldosteronism drives K⁺ loss", "0.1 mg/day"],
  ],
  [18, 22, 40, 20],
  BLUE_LIGHT
));

// ══ SECTION 4: Hyperkalemia Treatment ═════════════════════════════════════
content.push(sectionBar("4.  TREATMENT OF HYPERKALEMIA — 3-STEP APPROACH", RED_DARK));

content.push(makeTable(
  ["Step", "Goal", "Drug / Intervention", "Dose", "Onset", "K⁺ Effect"],
  [
    ["1", "Stabilise cardiac membrane", "Calcium gluconate 10%", "10 mL (1 g) IV over 2–3 min; repeat after 5 min if no response", "1–3 min", "None (cardioprotective only)"],
    ["1", "Stabilise cardiac membrane", "Calcium chloride 10%", "5–10 mL IV; prefer central line (tissue necrosis if extravasated)", "1–3 min", "None"],
    ["2", "Shift K⁺ into cells", "Regular Insulin + Dextrose 50%", "Insulin 10 U IV bolus + Dextrose 25 g IV  (use 5 U if renal failure)", "<15 min", "↓ ~0.6 mEq/L"],
    ["2", "Shift K⁺ into cells", "Salbutamol (Albuterol) nebulised", "10–15 mg continuous nebulisation", "<15 min", "↓ 0.5–1.0 mEq/L"],
    ["2", "Shift K⁺ into cells", "Sodium Bicarbonate IV", "50–100 mEq over 5–10 min", "~15 min", "Modest; use only if metabolic acidosis present"],
    ["3", "Remove K⁺ from body", "Furosemide IV", "Slow infusion; supplement NaCl + H₂O if hypovolaemic", "Minutes–hours", "Definitive (intact renal function only)"],
    ["3", "Remove K⁺ from body", "Patiromer (Veltassa)", "8.4 g oral daily; titrate up", "Hours", "Chronic use only — NOT for acute emergency"],
    ["3", "Remove K⁺ from body", "Sodium Zirconium Cyclosilicate (Lokelma / SZC)", "10 g oral TDS × 48 h, then 5–10 g/day", "~4 hours", "Chronic — NOT acute emergency"],
    ["3", "Remove K⁺ from body", "Haemodialysis", "Emergent — institute early in renal failure", "Immediate", "↓ ~1 mEq/L/hr; definitive in renal failure"],
  ],
  [5, 16, 20, 26, 10, 23],
  RED_LIGHT
));
content.push(noteBox("⚠  Sodium Polystyrene Sulfonate (Kayexalate/SPS): NOT recommended acutely — onset > 4h; FDA black-box warning for intestinal necrosis", RED_LIGHT, RED_DARK));
content.push(noteBox("⚠  In digoxin toxicity: Calcium potentiates digoxin toxicity — give slowly with ECG monitoring. Give Insulin without Dextrose if blood glucose > 250 mg/dL.", AMBER, "7B4F00"));

// Drugs causing hyperK
content.push(new Paragraph({ children: [new TextRun({ text: "Drugs Causing Hyperkalemia — Identify and Stop", font: "Calibri", size: 20, bold: true, color: RED_DARK })], spacing: { before: 100, after: 40 } }));
content.push(makeTable(
  ["Drug / Class", "Mechanism"],
  [
    ["ACE inhibitors / ARBs", "↓ Angiotensin II → ↓ Aldosterone → ↓ K⁺ excretion"],
    ["Spironolactone / Amiloride / Triamterene", "Direct K⁺-sparing action in collecting duct"],
    ["NSAIDs", "↓ Renin → ↓ Aldosterone (Type IV RTA pattern)"],
    ["Beta-blockers", "Impair intracellular K⁺ uptake via β₂ blockade"],
    ["Succinylcholine", "Depolarising block → K⁺ efflux from muscle. ABSOLUTELY CONTRAINDICATED"],
    ["Heparin", "↓ Adrenal aldosterone synthesis"],
    ["Digoxin overdose", "Inhibits Na⁺/K⁺-ATPase → K⁺ leaks extracellularly"],
    ["Potassium supplements / K⁺ penicillin", "Exogenous K⁺ load"],
  ],
  [38, 62],
  RED_LIGHT
));

// ══ SECTION 5: Comparison Summary ═════════════════════════════════════════
content.push(sectionBar("5.  QUICK COMPARISON SUMMARY", BLUE_DARK));

content.push(makeTable(
  ["Feature", "HYPOKALEMIA", "HYPERKALEMIA"],
  [
    ["K⁺ level", "< 3.5 mEq/L", "> 5.0 mEq/L"],
    ["ECG hallmark", "Flat T wave, prominent U wave, ↑QT", "Peaked T → wide QRS → sine wave → VF"],
    ["Immediate drug", "KCl oral 40–60 mEq q2–4h", "Calcium gluconate 10 mL IV"],
    ["Temporising", "—", "Insulin 10 U + Dextrose 25 g IV"],
    ["Adjunct shift", "—", "Albuterol 10–15 mg nebulised"],
    ["Definitive removal", "—", "Dialysis (renal failure); Furosemide (intact kidneys)"],
    ["Chronic oral drug", "KCl + K⁺-sparing diuretic", "Patiromer / SZC (Lokelma)"],
    ["Key co-deficiency", "Hypomagnesaemia — correct first", "—"],
    ["Avoid", "Dextrose IVF alone; delaying Mg²⁺ correction", "Succinylcholine; K⁺-containing IVF; SPS acutely"],
    ["Digoxin interaction", "↓ K⁺ potentiates digoxin toxicity — replace aggressively", "Ca²⁺ potentiates digoxin toxicity — give cautiously"],
    ["Target K⁺ in HF/MI", "4.0–5.0 mEq/L", "< 5.0 mEq/L"],
  ],
  [22, 39, 39],
  BLUE_LIGHT
));

// ══ SECTION 6: CASE SCENARIOS ═════════════════════════════════════════════
content.push(new Paragraph({ children: [new PageBreak()] }));
content.push(sectionBar("6.  CLINICAL CASE SCENARIOS", BLUE_DARK));
content.push(new Paragraph({ children: [], spacing: { before: 20, after: 20 } }));

// ── CASE 1: Diuretic-induced Hypokalemia ────────────────────────────────────
content.push(...caseScenario(
  1,
  "Diuretic-Induced Hypokalemia",
  BLUE_MID, BLUE_LIGHT, BLUE_DARK,
  {
    presentation: "62-year-old woman with hypertension and heart failure presents with 3 days of generalised weakness, muscle cramps, and palpitations. She has been on furosemide 40 mg/day for the past 2 months.",
    labs: "K⁺: 2.8 mEq/L  |  Mg²⁺: 0.6 mmol/L (low)  |  Na⁺: 138 mEq/L  |  Cl⁻: 94 mEq/L (low)  |  HCO₃⁻: 30 mEq/L  |  pH: 7.48 (metabolic alkalosis)",
    ecg: "Flat T waves, prominent U waves, ST depression, QTc 490 ms",
    diagnosis: "Moderate Hypokalemia (K⁺ 2.8 mEq/L) + Hypomagnesaemia + Hypochloraemic Metabolic Alkalosis secondary to furosemide",
    management: [
      ["1", "IV access + Cardiac monitoring", "Continuous ECG; repeat K⁺ q2h", "QTc 490 ms — arrhythmia risk; Mg²⁺ also low"],
      ["2", "Correct hypomagnesaemia FIRST", "MgSO₄ 2 g IV over 20 min", "K⁺ replacement fails without Mg²⁺ correction"],
      ["3", "K⁺ replacement — IV", "KCl 20 mEq/hr in Normal Saline × 2 h then reassess", "Use NS NOT dextrose; max 20 mEq/hr peripherally"],
      ["4", "Continue oral K⁺", "KCl 40–60 mEq oral q4h", "After IV phase; target K⁺ 4.0–5.0 mEq/L"],
      ["5", "Switch diuretic or add K⁺-sparer", "Spironolactone 25–50 mg/day OR Amiloride 5–10 mg/day", "Prevents recurrence; also beneficial in HF"],
      ["6", "Monitor closely", "K⁺, Mg²⁺, ECG at 2 h, 6 h, 24 h", "Rapid correction can cause rebound hyperkalemia"],
    ],
    keyPearl: "Hypomagnesaemia is the most common reason potassium replacement fails. ALWAYS check Mg²⁺ and correct it first. Furosemide causes 4 mechanisms of K⁺ loss: ↑ tubular flow, ↑ AVP, ↑ aldosterone, and metabolic alkalosis.",
  }
));

// ── CASE 2: Severe Hypokalemia with Arrhythmia ─────────────────────────────
content.push(...caseScenario(
  2,
  "Severe Hypokalemia — QT Prolongation & Arrhythmia Risk",
  BLUE_DARK, BLUE_LIGHT, BLUE_DARK,
  {
    presentation: "28-year-old woman with anorexia nervosa presents with episodic palpitations, muscle weakness, and inability to walk. She admits to excessive vomiting (>10×/day) for 2 weeks.",
    labs: "K⁺: 1.9 mEq/L  |  Mg²⁺: 0.5 mmol/L  |  Cl⁻: 82 mEq/L  |  HCO₃⁻: 34 mEq/L  |  pH: 7.52",
    ecg: "Flat T waves, massive U waves, QTc 560 ms — HIGH risk of Torsades de Pointes",
    diagnosis: "Severe Hypokalemia (K⁺ 1.9 mEq/L) with critical QT prolongation — risk of Torsades de Pointes",
    management: [
      ["1", "URGENT IV access + cardiac monitoring", "ICU/HDU admission; continuous ECG", "QTc 560 ms — Torsades de Pointes imminent"],
      ["2", "Correct Mg²⁺ urgently", "MgSO₄ 2 g IV over 10 min; repeat if needed", "MgSO₄ is also first-line treatment for Torsades"],
      ["3", "Aggressive IV K⁺ via central line", "KCl 20 mEq/hr centrally × 3–4 h; monitor K⁺ hourly", "Severe K⁺ < 2.0 mEq/L — central line mandatory"],
      ["4", "Concurrent oral K⁺ top-up", "KCl 40 mEq oral q2h once tolerating orally", "Oral + IV together shortens repletion time"],
      ["5", "Treat underlying cause", "Antiemetics (ondansetron); nutritional support", "Address vomiting — ongoing losses will outpace replacement"],
      ["6", "Avoid QT-prolonging drugs", "Withhold azithromycin, haloperidol, ondansetron if QTc > 500", "Additive QT prolongation → increases Torsades risk"],
    ],
    keyPearl: "K⁺ < 2.0 mEq/L or QTc > 500 ms = IV replacement via central line with continuous cardiac monitoring is mandatory. A standard dose of nebulised albuterol reduces K⁺ by 0.2–0.4 mEq/L — avoid in hypokalemia as it worsens it.",
  }
));

// ── CASE 3: Hyperkalemia in CKD ────────────────────────────────────────────
content.push(...caseScenario(
  3,
  "Hyperkalemia in Chronic Kidney Disease",
  RED_DARK, RED_LIGHT, RED_DARK,
  {
    presentation: "58-year-old man with CKD stage 4 (eGFR 18) and type 2 diabetes on ramipril, spironolactone, and trimethoprim presents with generalised weakness and fatigue. No acute complaints.",
    labs: "K⁺: 6.4 mEq/L  |  Creatinine: 340 µmol/L  |  HCO₃⁻: 17 mEq/L (metabolic acidosis)  |  Glucose: 8.2 mmol/L",
    ecg: "Peaked T waves in V2–V5; PR 210 ms (borderline); QRS 90 ms (normal)",
    diagnosis: "Moderate Hyperkalemia (K⁺ 6.4 mEq/L) secondary to CKD + RAAS inhibitors + trimethoprim (blocks tubular K⁺ secretion)",
    management: [
      ["1", "Stop offending drugs", "Withhold ramipril, spironolactone, trimethoprim", "Multiple converging causes of hyperkalemia"],
      ["2", "Cardiac membrane stabilisation", "Calcium gluconate 10% 10 mL IV over 3 min", "ECG changes present — membrane stabilisation is priority"],
      ["3", "Shift K⁺ into cells", "Insulin 10 U IV + Dextrose 50 mL (25 g) IV", "Onset <15 min; reduces K⁺ ~0.6 mEq/L"],
      ["4", "Shift K⁺ — adjunct", "Salbutamol 10 mg nebulised", "Additive with insulin; onset <15 min"],
      ["5", "Correct metabolic acidosis", "Sodium bicarbonate 50 mEq IV (HCO₃⁻ is 17)", "Acidosis driving K⁺ extracellularly; correction shifts K⁺ back in"],
      ["6", "Promote K⁺ elimination", "Furosemide 80 mg IV (some renal function remains)", "Enhance urinary K⁺ excretion; monitor response"],
      ["7", "Chronic management", "Patiromer (Veltassa) 8.4 g oral daily; dietary K⁺ restriction", "Long-term hyperkalemia control in CKD to allow continued ACEi use"],
      ["8", "Dialysis planning", "Refer nephrology; plan haemodialysis access if K⁺ not controlled", "GFR 18 — may need dialysis soon; K⁺ control essential"],
    ],
    keyPearl: "In CKD, trimethoprim blocks ENaC in collecting duct similar to amiloride — a commonly missed cause of hyperkalemia. RAAS inhibitor-induced hyperkalemia in CKD can be managed with Patiromer or SZC (Lokelma) without withdrawing the cardioprotective RAAS inhibitor.",
  }
));

// ── CASE 4: Life-Threatening Hyperkalemia (ECG changes) ────────────────────
content.push(...caseScenario(
  4,
  "Life-Threatening Hyperkalemia — Cardiac Emergency",
  RED_DARK, RED_LIGHT, RED_DARK,
  {
    presentation: "45-year-old man with end-stage renal disease (on haemodialysis 3×/week) missed his last two dialysis sessions. Brought in by family — unresponsive, bradycardic.",
    labs: "K⁺: 8.1 mEq/L  |  HCO₃⁻: 12 mEq/L  |  Ca²⁺: 1.9 mmol/L (low)",
    ecg: "Absent P waves, QRS width 180 ms, merging into T wave — SINE WAVE PATTERN",
    diagnosis: "Severe Life-Threatening Hyperkalemia (K⁺ 8.1 mEq/L) with sine wave ECG — imminent cardiac arrest",
    management: [
      ["1", "IMMEDIATE: Cardiac membrane", "Calcium gluconate 10% 20–30 mL IV rapidly (over 2 min)", "Sine wave = imminent VF. Calcium is the FIRST step — do not delay"],
      ["2", "Correct hypocalcaemia", "Repeat calcium if no ECG improvement in 5 min", "Hypocalcaemia accentuates cardiac toxicity — correct both"],
      ["3", "Shift K⁺ — insulin", "Insulin 10 U IV + Dextrose 50 mL IV (withhold glucose if glucose > 250)", "Fastest intracellular shift alongside calcium"],
      ["4", "Shift K⁺ — beta-agonist", "Salbutamol 10–15 mg nebulised (or IV adrenaline if haemodynamically unstable)", "Additive with insulin; adrenaline also provides inotropic support"],
      ["5", "Correct acidosis", "Sodium bicarbonate 100 mEq IV (HCO₃⁻ 12 = severe acidosis)", "Severe metabolic acidosis driving K⁺ extracellularly"],
      ["6", "EMERGENT Haemodialysis", "Institute immediately — call renal team STAT", "ESRD + missed dialysis — only reliable method of K⁺ removal. Target: ↓1 mEq/L per hour"],
      ["7", "Prepare for resuscitation", "Defibrillator at bedside; ACLS team on standby", "Sine wave → VF arrest can occur any moment"],
    ],
    keyPearl: "In ESRD + missed dialysis, haemodialysis is the ONLY definitive treatment. Medical management (calcium, insulin, bicarbonate, albuterol) buys 60–120 minutes — use this time to set up dialysis. Haemodialysis reduces K⁺ by ~1 mEq/L in the first hour.",
  }
));

// ── CASE 5: Drug-induced Hyperkalemia (ACEi + Spironolactone) ───────────────
content.push(...caseScenario(
  5,
  "Drug-Induced Hyperkalemia — ACEi + Spironolactone",
  "8B4513", AMBER, "7B4F00",
  {
    presentation: "70-year-old woman with heart failure (EF 30%), hypertension, and CKD stage 3 on enalapril 10 mg, spironolactone 50 mg, and ibuprofen (for knee pain). Presents with fatigue and mild confusion.",
    labs: "K⁺: 6.1 mEq/L  |  eGFR: 38  |  Na⁺: 136 mEq/L  |  HCO₃⁻: 20 mEq/L",
    ecg: "Peaked T waves in precordial leads; no P wave changes; QRS normal",
    diagnosis: "Mild-Moderate Hyperkalemia (K⁺ 6.1 mEq/L) — drug-induced via triple RAAS blockade (ACEi + MRA + NSAID)",
    management: [
      ["1", "Identify and stop offending drug", "Immediately stop IBUPROFEN", "NSAIDs ↓ renin → ↓ aldosterone = additive hyperkalemia. Remove the modifiable cause first"],
      ["2", "Cardiac membrane stabilisation", "Calcium gluconate 10 mL IV (ECG shows peaked T)", "ECG changes present — membrane stabilisation first"],
      ["3", "Shift K⁺ into cells", "Insulin 10 U IV + Dextrose 25 g IV", "Temporising measure while planning elimination"],
      ["4", "Reduce spironolactone dose", "Reduce to 25 mg/day (do not stop if EF 30% — mortality benefit)", "Spironolactone improves survival in systolic HF — dose-reduce not discontinue"],
      ["5", "Continue enalapril cautiously", "Reduce dose if needed; monitor K⁺ closely", "ACEi is cardioprotective in HF — target K⁺ < 5.5 with monitoring"],
      ["6", "Chronic K⁺ management", "Patiromer 8.4 g/day orally", "FDA-approved for hyperkalemia in CKD + HF; allows continuation of RAAS inhibitor"],
      ["7", "Pain management", "Replace ibuprofen with paracetamol", "Safe analgesic without RAAS or renal interaction"],
    ],
    keyPearl: "NSAIDs + ACEi + MRA = 'triple whammy' for hyperkalemia in CKD. Patiromer and SZC (Lokelma) are approved specifically to manage chronic hyperkalemia in CKD/HF patients so that life-saving RAAS inhibitors do NOT need to be withdrawn.",
  }
));

// ── CASE 6: Hypokalemia from Beta-2 Agonist Overuse ─────────────────────────
content.push(...caseScenario(
  6,
  "Hypokalemia — Beta-2 Agonist Overuse in Acute Asthma",
  "2E7D32", GREEN_LIGHT, GREEN_DARK,
  {
    presentation: "19-year-old asthmatic presents in severe bronchospasm. Treated in ED with 5 back-to-back salbutamol (albuterol) 5 mg nebulisations over 1 hour. Post-treatment: tremors, palpitations, muscle weakness.",
    labs: "Pre-treatment K⁺: 3.7 mEq/L  |  Post-treatment K⁺: 2.5 mEq/L  |  Glucose: 9.1 mmol/L",
    ecg: "Sinus tachycardia (HR 118); flattened T waves; prominent U waves; QTc 465 ms",
    diagnosis: "Iatrogenic Hypokalemia (K⁺ 2.5 mEq/L) secondary to high-dose nebulised salbutamol in acute asthma",
    management: [
      ["1", "Recognise the cause", "Salbutamol stimulates β₂ → activates Na⁺/K⁺-ATPase → K⁺ shifts intracellularly", "Each 5 mg nebulisation ↓ K⁺ by ~0.2–0.4 mEq/L; 5 doses = ~1–2 mEq/L drop"],
      ["2", "Cardiac monitoring", "ECG monitoring; repeat K⁺ in 2 hours", "QTc 465 ms — monitor for further prolongation"],
      ["3", "Oral K⁺ replacement", "KCl 40–60 mEq oral q4h (patient not vomiting)", "Moderate hypokalemia — oral route preferred if tolerated"],
      ["4", "Check and correct Mg²⁺", "Check serum Mg²⁺; give MgSO₄ 2 g IV if low", "MgSO₄ also relieves bronchospasm — dual benefit in asthma"],
      ["5", "Space out salbutamol doses", "Extend nebulisation intervals once bronchospasm controlled", "Ongoing salbutamol counteracts K⁺ replacement"],
      ["6", "Reassess", "K⁺, ECG at 4 h and 8 h", "Hypokalemia typically self-corrects once salbutamol is spaced — redistribution, not total body loss"],
    ],
    keyPearl: "Salbutamol-induced hypokalemia is a REDISTRIBUTION phenomenon (intracellular shift) — total body K⁺ is normal. It does NOT require large K⁺ doses; oral replacement is usually sufficient. It reverses as salbutamol wears off. This is clinically relevant in ICU patients on continuous beta-agonist nebulisation.",
  }
));

// ── CASE 7: Hyperkalaemia in Rhabdomyolysis ─────────────────────────────────
content.push(...caseScenario(
  7,
  "Hyperkalemia in Rhabdomyolysis",
  RED_DARK, RED_LIGHT, RED_DARK,
  {
    presentation: "22-year-old male bodybuilder found collapsed after marathon training in extreme heat. Presents with dark (cola-coloured) urine, severe muscle pain, oliguria, and confusion.",
    labs: "K⁺: 6.8 mEq/L  |  CK: 48,000 U/L  |  Creatinine: 280 µmol/L (AKI)  |  Phosphate: 2.1 mmol/L  |  HCO₃⁻: 16 mEq/L",
    ecg: "Peaked T waves; PR 200 ms; QRS 95 ms",
    diagnosis: "Moderate Hyperkalemia (K⁺ 6.8 mEq/L) secondary to Rhabdomyolysis with Acute Kidney Injury",
    management: [
      ["1", "Cardiac membrane stabilisation", "Calcium gluconate 10 mL IV over 3 min", "ECG changes present — protect myocardium first"],
      ["2", "Shift K⁺ — insulin + glucose", "Insulin 10 U IV + Dextrose 25 g IV", "Temporising; K⁺ release from muscle ongoing"],
      ["3", "Aggressive IV fluids", "Normal saline 1–1.5 L/hr until urine output > 200–300 mL/hr", "Dilutes K⁺; forces urine output; prevents tubular myoglobin precipitation"],
      ["4", "Loop diuretic + saline", "Furosemide IV once euvolaemic; ensure continued NS infusion", "Enhances urinary K⁺ and myoglobin excretion in rhabdomyolysis"],
      ["5", "Urinary alkalinisation (optional)", "Sodium bicarbonate added to IV fluid (target urine pH > 6.5)", "Prevents myoglobin precipitation in acidic urine; also corrects acidosis and shifts K⁺ into cells"],
      ["6", "Monitor K⁺ hourly", "Serial K⁺ + CK + renal function q2–4h", "K⁺ will rise rapidly as muscle continues to lyse — titrate treatment"],
      ["7", "Haemodialysis if refractory", "Institute if K⁺ > 7 despite above, or oliguria persists", "AKI + rhabdomyolysis = high risk of needing dialysis"],
    ],
    keyPearl: "Rhabdomyolysis releases massive intracellular K⁺ from lysed muscle. Unlike redistribution hyperkalemia, this is TRUE total body K⁺ excess — aggressive IV fluids + furosemide are key. Dialysis must be instituted early if urine output fails to respond.",
  }
));

// ── FOOTER NOTE ──────────────────────────────────────────────────────────────
content.push(new Paragraph({ children: [], spacing: { before: 80, after: 20 } }));
content.push(new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [new TableRow({ children: [new TableCell({
    shading: { type: ShadingType.CLEAR, fill: GRAY_LIGHT },
    borders: allBorders("CCCCCC", 4),
    children: [new Paragraph({
      children: [new TextRun({ text: "Sources: Katzung's Basic & Clinical Pharmacology 16e  ·  Morgan & Mikhail's Clinical Anesthesiology 7e  ·  Rosen's Emergency Medicine 9e  ·  Barash's Clinical Anesthesia 9e  |  For educational use only", font: "Calibri", size: 16, color: "888888", italics: true })],
      alignment: AlignmentType.CENTER, spacing: { before: 50, after: 50 },
    })],
  })})]
}));

// ── Build Document ─────────────────────────────────────────────────────────
const doc = new Document({
  creator: "Orris Medical Assistant",
  title: "Potassium Disorders — Quick Reference with Case Scenarios",
  description: "Hypokalemia and Hyperkalemia management pharmacology reference card with clinical cases",
  styles: {
    default: {
      document: { run: { font: "Calibri", size: 20, color: BLACK } },
    },
  },
  sections: [{
    properties: {
      page: {
        margin: { top: 720, right: 720, bottom: 720, left: 720 },  // ~1.27 cm
      },
    },
    headers: {
      default: new Header({
        children: [new Paragraph({
          children: [
            new TextRun({ text: "POTASSIUM DISORDERS — Quick Reference  |  ", font: "Calibri", size: 18, color: "888888" }),
            new TextRun({ text: "Hypokalemia & Hyperkalemia Management", font: "Calibri", size: 18, bold: true, color: BLUE_MID }),
          ],
          alignment: AlignmentType.RIGHT,
          border: { bottom: { style: BorderStyle.SINGLE, size: 4, color: BLUE_MID } },
        })],
      }),
    },
    footers: {
      default: new Footer({
        children: [new Paragraph({
          children: [
            new TextRun({ text: "For educational use only  |  Page ", font: "Calibri", size: 16, color: "888888" }),
            new PageNumber(),
          ],
          alignment: AlignmentType.CENTER,
          border: { top: { style: BorderStyle.SINGLE, size: 4, color: BLUE_MID } },
        })],
      }),
    },
    children: content,
  }],
});

const OUTPUT = "/home/daytona/workspace/potassium-docx/Potassium_Disorders_Reference.docx";
Packer.toBuffer(doc).then((buffer) => {
  fs.writeFileSync(OUTPUT, buffer);
  console.log("DOCX created:", OUTPUT);
}).catch(err => { console.error(err); process.exit(1); });
Running Command

cd /home/daytona/workspace/potassium-docx && node build.js 2>&1

Reading File
Editing File

~/potassium-docx/build.js

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/potassium-docx/build.js'
Running Command

cd /home/daytona/workspace/potassium-docx && node build.js 2>&1

Reading File
Editing File

~/potassium-docx/build.js

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/potassium-docx/build.js'
Running Command

cd /home/daytona/workspace/potassium-docx && node --check build.js 2>&1

Running Command

cd /home/daytona/workspace/potassium-docx && node build.js 2>&1

Running Command

node -e "const d = require('docx'); console.log(Object.keys(d).filter(k => k.toL…

Editing File

~/potassium-docx/build.js

Error: String not found in file: '  Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,
  InternalHyperlink, Bookmark, FootnoteReferenceRun, PositionalTab,
  PositionalTabAlignment, PositionalTabRelativeTo, PositionalTabLeader,
  TabStopType, TabStopPosition, Column, SectionType,
  TableOfContents, HeadingLevel, BorderStyle, WidthType, ShadingType,
  VerticalAlign, PageNumber, Header, Footer, ImageRun, TableOfContents,
  PageBreak, convertInchesToTwip, UnderlineType'
Reading File
Editing File

~/potassium-docx/build.js

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/potassium-docx/build.js'
Editing File

~/potassium-docx/build.js

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/potassium-docx/build.js'
Running Command

cd /home/daytona/workspace/potassium-docx && node build.js 2>&1 && python3 /home…

Running Command

ls -lh /home/daytona/workspace/potassium-docx/Potassium_Disorders_Reference.docx

Your Word document is ready. Here's what's included:

Document structure (colour-coded, fully formatted):
Reference sections (pages 1-2):
  1. Classification & Severity - Grading table for both disorders
  2. ECG Changes - Side-by-side comparison table
  3. Hypokalemia Treatment - KCl oral/IV dosing + K⁺-sparing drugs table
  4. Hyperkalemia 3-Step Approach - Full treatment table with onset/K⁺ effect per agent + drugs causing hyperkalemia
  5. Quick Comparison Summary - At-a-glance side-by-side
7 Clinical Case Scenarios (page 3 onwards):
CaseScenario
1Diuretic-induced hypokalemia (HF patient on furosemide)
2Severe hypokalemia with QT prolongation/Torsades risk (anorexia)
3Hyperkalemia in CKD (ramipril + spironolactone + trimethoprim)
4Life-threatening hyperkalemia in ESRD - sine wave ECG
5Drug-induced hyperkalemia - ACEi + MRA + NSAID "triple whammy"
6Salbutamol-induced hypokalemia in acute asthma
7Hyperkalemia in rhabdomyolysis
Each case includes: presentation, labs, ECG, diagnosis, step-by-step management table, and a key pharmacology pearl.

Potassium Disorders Reference

Word Document · DOCX

Difference between obstructive and restrictive lung disease in table

Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Finding Sources
Finding Sources
Reading File
Finding Sources
Finding Sources
Loading Image
Reading File
Finding Sources
I now have comprehensive data from multiple authoritative textbooks plus the flow-volume loop image. Let me compile the full, detailed comparison.

Obstructive vs. Restrictive Lung Disease

Flow-Volume Loops

Flow-volume curves: A = COPD (obstructive, concave expiratory curve); B = Interstitial lung disease (restrictive, steep/narrow vertically-oriented curve); C = Suboptimal effort; D = Large airway obstruction patterns
(A) Obstructive - expiratory limb is concave upward (scooped), reflecting greater reduction in flow at low lung volumes due to air trapping. (B) Restrictive - loop is steep and vertically oriented (narrow), reflecting reduced lung volume but relatively preserved flow rates.

Main Comparison Table

FeatureObstructive Lung DiseaseRestrictive Lung Disease
DefinitionSmall airway obstruction to expiratory flowProportional reduction in all lung volumes
Primary defectIncreased airway resistance → difficulty expiringReduced lung compliance or chest wall expansion → difficulty inspiring
PathophysiologyAirway narrowing (mucus, bronchoconstriction, wall destruction) → air trappingStiff lungs (↑ elastic recoil) OR reduced thoracic/neuromuscular expansion

Pulmonary Function Tests (Spirometry + Lung Volumes)

ParameterObstructiveRestrictiveNotes
FEV₁↓↓↓↓Both reduced, but by different mechanisms
FVCNormal or slightly ↓↓↓↓Key distinguishing point
FEV₁/FVC ratio↓↓↓ (<0.70)Normal or ↑ (>0.70)Single most important differentiating parameter
FEF₂₅₋₇₅%↓↓↓NormalReflects small airway flow; impaired in obstruction
TLCNormal or ↑ (gas trapping/hyperinflation)↓↓↓Gold standard for confirming restriction
RV↑ (air trapping)RV increases in obstruction due to early airway closure
RV/TLC ratioNormal or ↓Elevated ratio = significant air trapping
FRC↑ (if gas trapping)↓↓
Airway resistance (Raw)↑↑NormalMeasured by body plethysmography
Lung compliance↑ (in emphysema - loss of elastic recoil) (in parenchymal restriction - stiff lungs)Opposite directions
DLCO↓ in emphysema; Normal/↑ in asthma↓ in parenchymal restriction (e.g. IPF, sarcoidosis)Normal in extra-parenchymal restriction
Bronchodilator responsePartial/full reversibility (esp. asthma)No significant response
Gold standard for restriction: TLC < lower limit of normal (LLN) confirmed by plethysmography. Spirometry alone has only ~50% sensitivity for restriction - TLC must be measured to confirm.

Flow-Volume Loop Appearance

FeatureObstructiveRestrictive
ShapeExpiratory limb concave upward ("scooped")Steep, narrow, vertically oriented
Loop widthWide or normal (large TLC)Narrow (small TLC and RV)
Peak expiratory flowReducedNormal or mildly reduced
InspirationUsually normalReduced in proportion to VC
Pattern descriptor"Concave upward""Convex upward" / steep descent

Causes

Obstructive Lung Disease

ConditionSite of ObstructionKey Mechanism
COPD - EmphysemaAcinus/alveoliDestruction of alveolar walls → loss of elastic recoil → airway collapse on expiration
COPD - Chronic bronchitisLarge and small airwaysMucous gland hyperplasia, secretions, fibrosis → airway narrowing
AsthmaBronchiSmooth muscle hyperplasia, mucosal oedema, excess mucus → bronchoconstriction (reversible)
BronchiectasisBronchiAirway dilation and scarring from recurrent infection
Small airways disease / bronchiolitisBronchioles (<2 mm)Inflammatory scarring/obliteration
Upper airway obstructionTrachea/larynxFixed or variable obstruction

Restrictive Lung Disease

CategoryExamples
Parenchymal (intrinsic)Idiopathic pulmonary fibrosis (IPF), sarcoidosis, hypersensitivity pneumonitis, asbestosis, pneumoconiosis, ARDS
PleuralPleural effusion, pleural thickening, fibrothorax
Chest wall / musculoskeletalKyphoscoliosis, ankylosing spondylitis, rib fractures, obesity
NeuromuscularDiaphragm paralysis, Guillain-Barré syndrome, myasthenia gravis, ALS, muscular dystrophy
Space-occupyingMassive ascites, pregnancy, large pleural effusion
In parenchymal restriction: DLCO is reduced and FEV₁/FVC is elevated (high elastic recoil). In extra-parenchymal restriction (neuromuscular, chest wall): DLCO is usually normal.

Clinical Features

FeatureObstructiveRestrictive
Primary symptomExertional dyspnea + chronic cough ± wheezeProgressive dyspnea on exertion (often insidious)
SputumOften present (especially COPD/bronchitis)Usually absent
WheezeCommonAbsent
Breath soundsProlonged expiration, decreased air entry, wheezeFine inspiratory crackles (Velcro crackles) in ILD
Chest shapeBarrel chest (hyperinflation in COPD)Normal or restricted expansion
CyanosisLate (hypoxaemia from V/Q mismatch)Early hypoxaemia in severe ILD
ClubbingAbsent (except bronchiectasis)Present in IPF, asbestosis
Cor pulmonaleLate complication (pulmonary HTN from hypoxia)Can occur in advanced restrictive disease

Severity Grading (by FEV₁ % predicted - GOLD criteria for obstructive; ATS for both)

GradeObstructive (FEV₁ % predicted)Restrictive (FVC % predicted)
Mild≥ 70%70 – 80%
Moderate50 – 69%60 – 69%
Severe30 – 49%51 – 59%
Very severe< 30%≤ 50%

Quick Memory Summary

OBSTRUCTIVE:
  FEV₁ ↓  |  FVC normal  |  FEV₁/FVC ↓  |  TLC ↑  |  RV ↑
  Concave expiratory loop  |  ↑ Raw  |  ↑ Compliance (emphysema)
  Causes: COPD, Asthma, Bronchiectasis

RESTRICTIVE:
  FEV₁ ↓  |  FVC ↓↓  |  FEV₁/FVC normal/↑  |  TLC ↓  |  RV ↓
  Narrow steep loop  |  Normal Raw  |  ↓ Compliance (parenchymal)
  Causes: IPF, Sarcoidosis, Kyphoscoliosis, Neuromuscular disorders

Sources: Murray & Nadel's Respiratory Medicine · Barash's Clinical Anesthesia 9e · Robbins Pathologic Basis of Disease · Miller's Anesthesia 10e

Ossification of bone

Finding Sources
Finding Sources
Reading File
Finding Sources
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Loading Image
Loading Image
Loading Image
Excellent - I have all the diagrams and detailed textbook content needed. Here is the comprehensive answer:

Ossification of Bone

Ossification (osteogenesis) is the process by which bone tissue is formed. There are two distinct mechanisms, differentiated by whether a cartilage model (template) is used or not.

Comparison: Intramembranous vs. Endochondral Ossification

FeatureIntramembranous OssificationEndochondral Ossification
DefinitionBone formed directly from mesenchyme, without a cartilage intermediateBone formed by replacement of a pre-existing hyaline cartilage model
Bones formedFlat bones of skull, mandible, maxilla, clavicleLong bones (femur, tibia, humerus), vertebrae, ribs, bones of base of skull
Precursor tissueMesenchyme (embryonic connective tissue)Hyaline cartilage model
Cartilage modelAbsentPresent - serves as scaffold
First appearance~8th week of embryonic developmentSlightly later; cartilage model forms first
Cell lineageMesenchymal cell → osteoprogenitor → osteoblast → osteocyteMesenchymal cell → chondroblast → chondrocyte → (degeneration) → osteoprogenitor → osteoblast → osteocyte
Key transcription factorCBFA1 (RUNX2)CBFA1 (RUNX2) + SOX9 (for chondrogenesis)
Vascular invasionEarly - mesenchyme is already vascularRequired to initiate ossification center formation
Type of bone first producedWoven (immature) bone → remodelled to lamellarWoven bone on calcified cartilage spicules → lamellar
GrowthAppositional onlyInterstitial (length) + appositional (width)

I. Intramembranous Ossification

Diagram

Intramembranous ossification: (a) ossification center forming in mesenchyme with osteoprogenitor cells secreting osteoid; (b) osteoblasts at periphery, entrapped cells become osteocytes; (c) trabeculae of woven bone with blood vessels; (d) compact bone plate, spongy bone with marrow, periosteum

Steps

1. Mesenchymal cell condensation (ossification centre)
  • Spindle-shaped mesenchymal cells in the embryonic connective tissue migrate and aggregate at specific areas (e.g., future flat bone regions of the skull) around the 8th week of development
  • These ossification centres form in the mesenchyme
2. Differentiation into osteoprogenitor cells → osteoblasts
  • Mesenchymal cells in the centre elongate and express CBFA1 (RUNX2) transcription factor - essential for osteoblast differentiation
  • Cytoplasm shifts from eosinophilic to basophilic; Golgi becomes prominent
  • Cells differentiate into osteoblasts
3. Osteoid secretion and mineralisation
  • Osteoblasts secrete osteoid (unmineralized matrix): type I collagen, bone sialoproteins, osteocalcin
  • Osteoblasts accumulate at periphery and continue secreting toward the centre
  • Osteoid undergoes mineralisation - trapped osteoblasts become osteocytes enclosed within lacunae
4. Formation of woven bone trabeculae
  • Initial bone tissue forms a network of irregular trabeculae (woven bone / primary spongiosa)
  • Blood vessels and mesenchyme fill the spaces between trabeculae → future bone marrow
5. Remodelling to mature bone
  • Outer surface: osteoblasts lay down compact bone plates (outer and inner tables)
  • Interior: remains as spongy bone (diploë) with marrow
  • Surrounding mesenchyme becomes periosteum
  • Woven bone is gradually replaced by lamellar bone via remodelling

II. Endochondral Ossification

Diagram - Stages of Long Bone Development

Schematic diagram of developing long bone (stages 1-10): hyaline cartilage model → bony collar → primary ossification center → bone marrow cavity → secondary ossification centers → epiphyseal growth plates → epiphyseal line at closure

Steps

1. Formation of the hyaline cartilage model
  • Mesenchymal cells at the site of future bone condense and differentiate into chondroblasts under the influence of BMPs and growth factors; they express type II collagen and SOX9
  • Chondroblasts secrete cartilage matrix forming a hyaline cartilage model - a miniature version of the future bone
  • The model grows by interstitial growth (length) and appositional growth (width from perichondrium)
2. Formation of the periosteal bony collar
  • Perichondrial cells in the midregion (diaphysis) stop producing cartilage and become osteoprogenitor cells → convert to periosteum
  • These cells differentiate into osteoblasts by intramembranous ossification and deposit a cuff of bone (bony collar) around the mid-shaft of the cartilage model
  • This is the first bone formed in endochondral ossification
3. Cartilage calcification and chondrocyte hypertrophy
  • Chondrocytes in the centre of the diaphysis become hypertrophic (10-20x enlarged)
  • They secrete VEGF (initiates vascular invasion), RANKL, and type X collagen
  • Surrounding cartilage matrix becomes compressed into thin bands, then undergoes calcification
  • Calcified cartilage inhibits nutrient diffusion → chondrocytes degenerate/die (or transdifferentiate into osteoblasts)
4. Vascular invasion and primary ossification centre
  • Blood vessels penetrate the thin bony collar into the degenerating cartilage
  • Mesenchymal stem cells and haemopoietic stem cells migrate along vessels
  • Osteoprogenitor cells differentiate into osteoblasts and deposit bone matrix on residual calcified cartilage spicules → "mixed spicules" (basophilic calcified cartilage core + eosinophilic bone layer)
  • This first site of bone formation in the diaphysis = PRIMARY OSSIFICATION CENTRE (~8th-12th week in utero for most long bones)
  • The expanding bone cavity = primitive bone marrow cavity
5. Secondary ossification centres (epiphyses)
  • Blood vessels penetrate epiphyseal cartilage after birth (timing varies by bone)
  • Secondary ossification centres form in the epiphyses by the same mechanism
  • No periosteal bony collar forms in the epiphyses (unlike diaphysis)
6. Formation of the epiphyseal growth plate (physis)
  • Cartilage trapped between the primary and secondary ossification centres = epiphyseal growth plate (physis)
  • Provides continued cartilage for longitudinal bone growth throughout childhood and adolescence
  • Articular cartilage persists at joint surfaces

III. Zones of the Epiphyseal Growth Plate

Diagram

Epiphyseal growth plate zones: zone of reserved cartilage (top), zone of proliferation, zone of hypertrophy, zone of calcified cartilage, zone of resorption (with osteoclasts, osteoblasts, osteocytes, calcified cartilage, and bone marrow)
Proceeding from epiphysis toward diaphysis:
ZoneDescriptionKey Events
1. Zone of Reserved (Resting) CartilageSmall chondrocytes scattered randomly in matrixNo proliferation; serves as stem cell reserve for the proliferating zone
2. Zone of ProliferationChondrocytes actively dividing, arranged in distinct columnsCells larger; secrete type II and XI collagen; responsible for longitudinal bone growth
3. Zone of HypertrophyChondrocytes 10-20× enlarged; glycogen-rich clear cytoplasmSecrete VEGF (initiates vascular invasion), RANKL, type X collagen; matrix compressed between columns
4. Zone of Calcified CartilageMatrix becomes calcified; chondrocytes degenerate or transdifferentiateCalcified matrix serves as initial scaffold for bone deposition; some chondrocytes → osteoblasts
5. Zone of ResorptionAdjacent to bone marrow cavityBlood vessels + osteoprogenitor cells invade; osteoclasts resorb calcified cartilage spicules; osteoblasts deposit bone on remaining spicules → endochondral bone
Mnemonic for zones: Resting Prolif Hypertrophy Calcif Resorption = "Really Pretty Hyenas Can Run"

IV. Bone Growth

TypeMechanismResult
Interstitial growthChondrocyte proliferation within growth plateIncrease in bone length
Appositional growthOsteoblasts under periosteum deposit new bone on outer surfaceIncrease in bone width/diameter

V. Epiphyseal Plate Closure

  • Growth plate activity continues throughout childhood and adolescence under the influence of GH, IGF-1, thyroid hormone, sex steroids
  • At puberty, oestrogen/androgens accelerate closure
  • Epiphyseal cartilage is eventually completely replaced by bone → epiphyseal line remains as a marker
  • After closure: no further longitudinal growth is possible

VI. Bone Remodelling

Bone is continuously remodelled throughout life by bone-remodelling units (BMUs) - coupled osteoclast and osteoblast activity:
  • Cutting cone: osteoclasts bore a tunnel ~200 µm in diameter through compact bone
  • Closing cone: osteoblasts fill the tunnel with successive lamellae → forms new osteon (Haversian system)
  • Regulated by: PTH, calcitonin, oestrogen, RANK-RANKL-OPG axis, mechanical loading

Summary Comparison Table

FeatureIntramembranousEndochondral
TemplateMesenchyme (no cartilage)Hyaline cartilage model
Bones formedFlat skull bones, mandible, clavicleLong bones, vertebrae, most bones
Key cellsMesenchymal cell → osteoblastChondrocyte → osteoblast
First bone typeWoven bone trabeculaeBone on calcified cartilage spicules
Ossification centreOne primary centrePrimary (diaphysis) + Secondary (epiphyses)
Growth plateNot presentPresent (epiphyseal plate)
Growth mechanismAppositional onlyInterstitial (length) + appositional (width)
Cartilage at endAbsentArticular cartilage persists
Vascular invasionEarly (mesenchyme already vascular)Required to initiate each ossification centre
Source: Histology: A Text and Atlas with Correlated Cell and Molecular Biology (Ross & Pawlina) - Barash's Clinical Anesthesia 9e

Development of bone

Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
Reading File
Reading File
Finding Sources
Reading File
Reading File
Loading Image
Loading Image
Finding Sources
I now have everything needed for a thorough, well-illustrated answer on bone development. Let me compile it.

Development of Bone

Bone development (osteogenesis) encompasses the embryological origin of the skeleton, the cellular and molecular processes of bone formation, postnatal growth, continuous remodelling, and repair. Note: The mechanisms of ossification (intramembranous and endochondral) were covered in detail in the previous response - this answer builds on those and covers the broader developmental arc.

I. Embryological Origin of the Skeleton

The skeletal elements arise from three distinct mesenchymal sources depending on location:
Skeletal RegionEmbryonic OriginMechanism of Ossification
Flat bones of skull, face, mandibleNeural crest cells (ectomesenchyme)Intramembranous
Base of skull, vertebrae, ribs, sternum, limb bonesParaxial mesoderm (somites - sclerotome)Endochondral
ClavicleBoth neural crest and lateral plate mesodermBoth intramembranous + partial endochondral
Limb bonesLateral plate mesoderm (somatic layer)Endochondral

Somite Contribution

At the end of the third week, intraembryonic mesoderm lateral to the notochord thickens to form paraxial mesoderm, which segments into somites by the fourth week. Each somite divides into:
  • Sclerotome (ventromedial) → forms vertebrae and ribs
  • Dermomyotome (dorsolateral) → myotome (muscle) + dermatome (dermis)
At the end of the fourth week, sclerotome cells disperse to form mesenchyme - the raw material for most of the axial skeleton.

Molecular Regulators of Skeletal Development

Transcription factor network for chondrogenesis and osteogenesis: Sox9, Runx2, β-catenin, BMPs, FGF, PTHrP interactions
Key signalling molecules include:
  • BMPs (BMP5, BMP7) - drive chondrogenesis and osteogenesis
  • Sox9 - master transcription factor for chondrocyte differentiation
  • RUNX2 / CBFA1 - master transcription factor for osteoblast differentiation
  • β-catenin (Wnt pathway) - determines lineage commitment between chondrocyte and osteoblast; high β-catenin → osteoblast fate
  • VEGF - essential for vascular invasion of calcified cartilage
  • TGF-β superfamily, GDF5, FGF, PTHrP - regulate chondrocyte proliferation and hypertrophy

II. Types of Ossification

FeatureIntramembranousEndochondral
Precursor tissueMesenchyme (no cartilage)Hyaline cartilage model
Bones formedFlat skull bones, mandible, clavicleLong bones, vertebrae, most bones
Onset~8th week (human)Slightly later; cartilage model forms 5th week, ossification begins ~8–12th week
First bone typeWoven bone trabeculaeBone on calcified cartilage spicules (mixed spicules)
(Full mechanism details covered in the previous Ossification response)

III. Development of a Long Bone — Sequential Stages

Schematic stages of long bone development (1-10): cartilage model → bony collar → primary ossification centre → marrow cavity → secondary ossification centres → epiphyseal growth plates → epiphyseal line at closure
StageEventTiming
1Mesenchymal condensation at future bone siteWeek 4–5 (in utero)
2Cartilage model (anlage) formed by chondroblastsWeek 5–6
3Periosteal bony collar forms around mid-diaphysis (intramembranous)Week 8
4Chondrocytes hypertrophy, cartilage matrix calcifiesFollows bony collar
5Vascular invasion of diaphysis; Primary ossification centre established~Week 8 of gestation (varies)
6Primitive bone marrow cavity forms; periosteal bone expandsFetal period
7Blood vessels invade proximal epiphyseal cartilageLate fetal / early postnatal
8Secondary ossification centre forms in proximal epiphysisMostly postnatal
9Epiphyseal growth plate (physis) trapped between primary and secondary centresPostnatal; persists until puberty
10Growth plate closes → Epiphyseal lineEnd of puberty (~18–23 years)
Key distinction: The medullary canal forms at ~8 weeks of gestation when the central portion of the cartilage anlage is resorbed. Radial bone growth (cortex) begins simultaneously via periosteal osteoblast deposition. Secondary ossification centres develop postnatally at the epiphyses in centrifugal fashion.

IV. Bone Growth

A. Longitudinal Growth (Increase in Length)

  • Occurs at the epiphyseal growth plate (physis)
  • Chondrocytes in the proliferating zone undergo cell division in columns
  • New cartilage is continuously produced on the epiphyseal side
  • Cartilage is continuously replaced by bone on the diaphyseal side (zone of resorption)
  • Net result: bone elongates
Zones of the Growth Plate (epiphysis → diaphysis):
ZoneKey Activity
Zone of Reserved CartilageStem cell reserve; no active proliferation
Zone of ProliferationActive cell division in columns; produces longitudinal growth; secretes type II, XI collagen
Zone of HypertrophyCells enlarge 10-20×; secrete VEGF (angiogenesis), RANKL, type X collagen
Zone of Calcified CartilageMatrix calcifies; chondrocytes degenerate or transdifferentiate into osteoblasts
Zone of ResorptionVascular invasion; osteoblasts deposit bone on calcified cartilage spicules

B. Appositional Growth (Increase in Width/Diameter)

  • Osteoblasts in the periosteum deposit new bone layer by layer on the outer surface
  • Simultaneously, endosteal osteoclasts resorb bone on the inner surface of the cortex
  • Net result: medullary cavity widens as bone diameter increases

C. Epiphyseal Plate Closure

  • Driven by sex steroids at puberty (oestrogen in both sexes is most potent)
  • Closure timing varies by bone and epiphysis (distal femur last, ~18–20 years in females; some proximal epiphyses close up to ~23 years)
  • After closure, longitudinal growth ceases; epiphyseal line (scar) persists on X-ray
  • Harris growth arrest lines: horizontal dense white lines on X-ray caused by transient cessation of endochondral ossification (illness, nutritional deprivation, hypothyroidism)
Hormonal regulation of growth:
HormoneEffect on Growth Plate
Growth Hormone (GH)Stimulates chondrocyte proliferation via IGF-1; increases bone length and width
IGF-1Mediates GH effects; stimulates chondrocyte division
Thyroid hormoneEssential for normal growth; deficiency → cretinism with stunted growth
Sex steroids (oestrogen, testosterone)Accelerate growth initially; then drive plate closure
Glucocorticoids (excess)Inhibit chondrocyte proliferation → growth retardation
PTH-related protein (PTHrP)Keeps growth plate chondrocytes in proliferating state; delays hypertrophy

V. Bone Remodelling

Bone is constantly remodelled throughout life by Bone Multicellular Units (BMUs) - coupled osteoclast-osteoblast activity. About 10% of the entire adult skeleton is remodelled every year, renewing completely over ~10 years.

Functions of Remodelling

  1. Replace immature woven bone with mature lamellar bone
  2. Adapt bone architecture to mechanical loads (Wolff's Law)
  3. Repair microfractures and material fatigue
  4. Provide rapidly available calcium reservoir for homeostasis

The RANK-RANKL-OPG Axis

RANK-RANKL-OPG paracrine signalling: osteoblast/stromal RANKL binds osteoclast precursor RANK → NF-κB → osteoclast differentiation; WNT → OPG (decoy) blocks RANKL; M-CSF also promotes osteoclastogenesis; PTH, IL-1, glucocorticoids promote; BMPs and sex hormones suppress via OPG
FactorSourceEffect
RANKLOsteoblasts, marrow stromal cells, T lymphocytesBinds RANK on osteoclast precursors → activates NF-κB → drives osteoclast differentiation and survival
RANKOsteoclast precursorsReceptor; activation → osteoclastogenesis
OPG (osteoprotegerin)OsteoblastsDecoy receptor; binds RANKL → prevents RANK-RANKL interaction → inhibits osteoclastogenesis
M-CSFOsteoblastsBinds M-CSF receptor on osteoclast precursors; promotes survival and differentiation
WNT proteinsVarious cellsTrigger OPG production → favour bone formation over resorption
PTH (continuous/high)Parathyroid glandsStimulates RANKL on osteoblasts → promotes osteoclast activity → bone resorption ↑
PTH (pulsatile/low)Via IGF-1/cAMP in osteoblasts → anabolic (bone formation ↑)
Oestrogen / testosteroneGonadsSuppress RANKL; promote OPG → reduce osteoclast activity
IL-1, glucocorticoidsInflammatory/adrenalPromote osteoclast differentiation
BMPsVariousGenerally promote OPG → suppress osteoclast activity
Peak bone mass is reached in early adulthood. From the fourth decade, resorption exceeds formation → gradual decline in skeletal mass. This is accelerated postmenopausally due to oestrogen withdrawal.

VI. Bone Repair (Fracture Healing)

Four stages of fracture healing: (1) fracture hematoma forms; (2) fibrocartilaginous (soft) callus with regenerating blood vessels; (3) hard (bony) callus of woven bone; (4) remodelling to compact bone
Bone has excellent self-repair capacity due to its rich osteoprogenitor stem cell population in the periosteum, endosteum, and bone marrow, and its abundant vascularity.
StageEventsKey Cells
1. Fracture haematoma (hours–days)Torn blood vessels bleed; clot forms; bone cells near break die; osteoclasts resorb damaged boneMacrophages, osteoclasts
2. Soft (procallus) formation (days–weeks)Periosteum and endosteum proliferate; fibrocartilage-like procallus surrounds fracture; blood vessel regeneration beginsFibroblasts, chondroblasts, periosteal cells
3. Hard callus formation (weeks)Fibrocartilage replaced by woven bone (combination of endochondral and intramembranous ossification); hard callus bridges fractureOsteoblasts, osteoclasts
4. Bone remodelling (months–years)Woven bone replaced by lamellar bone; callus remodelled to restore original architecture and cortical continuityOsteoblasts + osteoclasts (BMUs)
Factors promoting healing: adequate immobilisation, good vascularity, periosteum intact, mechanical loading (controlled), adequate nutrition (calcium, vitamin D, protein), growth factors (BMPs, PDGF, TGF-β)
Factors impairing healing: infection, poor blood supply, excessive mobility, malnutrition, glucocorticoids, NSAIDs, smoking, diabetes, old age

VII. Metabolic Role of Bone

The skeleton contains 99% of the body's total calcium in hydroxyapatite crystals. Calcium homeostasis is maintained by:
HormoneSourceEffect on Bone
PTHParathyroid glandsStimulates osteoclasts (indirectly via RANKL on osteoblasts) and osteocytes → bone resorption → ↑ blood Ca²⁺
CalcitoninThyroid C cellsInhibits osteoclastic bone resorption → ↓ blood Ca²⁺
Vitamin D (1,25-OH₂D₃)Kidney activationPromotes intestinal Ca²⁺ absorption; promotes mineralisation; works synergistically with PTH

Summary — Development Timeline of a Long Bone

Week 4-5:  Mesenchymal condensation
Week 5:    Cartilage (hyaline) model forms  ← SOX9 drives chondrogenesis
Week 8:    Periosteal bony collar (intramembranous)
           + Chondrocyte hypertrophy, matrix calcification
           + Vascular invasion → PRIMARY OSSIFICATION CENTRE  ← RUNX2/CBFA1 drives osteogenesis
Fetal:     Medullary cavity expands; cortex thickens
Postnatal: SECONDARY OSSIFICATION CENTRES form in epiphyses
Childhood: Growth plate active → longitudinal growth via GH/IGF-1/thyroid hormone
Puberty:   Growth spurt then epiphyseal plate CLOSURE (sex steroids)
           (~18–23 years for most long bones)
Adult:     Bone remodelling continues lifelong via BMU (osteoclast-osteoblast)
4th decade+: Resorption > formation → bone mass declines
Sources: The Developing Human - Clinically Oriented Embryology (Moore & Persaud) · Robbins & Kumar Basic Pathology · Histology: A Text and Atlas (Ross & Pawlina) · Grainger & Allison's Diagnostic Radiology · Junqueira's Basic Histology
This is a shared conversation. Sign in to Orris to start your own chat.