Notes on DKA

Reading File
DKA (Diabetic Ketoacidosis) is a life-threatening complication of diabetes characterized by hyperglycemia, ketosis, and metabolic acidosis, most commonly in Type 1 diabetes. Let me pull comprehensive notes from the medical library now.
Searching sources...
Finding Sources
Finding Sources
Searching PubMed

"diabetic ketoacidosis" management

Good - I have several strong sources. Let me read the most comprehensive ones in parallel: Goldman-Cecil (core medicine), Rosen's EM (emergency management), and Tintinalli's.
Reading File
Reading File
Reading File
Excellent content. Let me now read the Goldman-Cecil treatment section and the Rosen's EM clinical section for the diagnostic criteria and management protocol details.
Reading File
Reading File
Let me get the full treatment/management section from Rosen's EM and the diagnostic criteria table from Goldman-Cecil.
Reading File
Reading File
Now let me get the full treatment section from Rosen's EM (fluid, insulin, electrolytes management) and the diagnostic criteria table.
Reading File
I now have comprehensive content. Let me compile the full DKA notes.

Diabetic Ketoacidosis (DKA) - Clinical Notes


Definition

DKA is a hyperglycemic emergency defined by three core biochemical features (the "DKA triad"):
  • D - Hyperglycemia (blood glucose >250 mg/dL, though euglycemic DKA can occur) OR a known history of diabetes
  • K - Ketonemia (urine ketones 2+ or serum β-hydroxybutyrate ≥3.0 mmol/L in adults; ≥3.8 mmol/L in children)
  • A - Acidosis (arterial or venous pH <7.3, serum HCO₃⁻ <18 mmol/L)
Most common in Type 1 DM; ~25% of DKA episodes occur in patients with previously undiagnosed diabetes. Can also occur in Type 2 DM under stress.
  • Goldman-Cecil Medicine, p. 2483-2484

Pathophysiology

The entire pathophysiology stems from insulin deficiency + glucagon excess (counter-regulatory hormone excess):
Insulin deficiency
       ↓
┌──────────────────────────────────┐
│ LIVER                            │
│  ↑ Gluconeogenesis               │
│  ↑ Glycogenolysis                │
│  ↑ Ketogenesis (β-OHB, AcAc)    │
└──────────────────────────────────┘
       ↓
┌──────────────────────────────────┐
│ ADIPOSE TISSUE                   │
│  ↑ Hormone-sensitive lipase      │
│  ↑ Free fatty acids → liver      │
└──────────────────────────────────┘
       ↓
┌──────────────────────────────────┐
│ MUSCLE                           │
│  ↑ Proteolysis                   │
│  ↑ Amino acids → liver           │
└──────────────────────────────────┘
Consequences:
  1. Hyperglycemia → osmotic diuresis → dehydration, electrolyte loss (Na⁺, K⁺, Mg²⁺, PO₄³⁻, Ca²⁺, Cl⁻)
  2. Ketone production (β-hydroxybutyrate > acetoacetate > acetone) → anion gap metabolic acidosis
  3. Hemoconcentration → further worsens hyperglycemia and hyperosmolality
The anion gap acidosis evolves in stages:
  • Early DKA: ECF volume near-normal → ketoacid anions rapidly excreted as Na⁺/K⁺ salts in urine, with NaCl retention → normal gap (hyperchloremic) metabolic acidosis
  • Established DKA: Volume depletion reduces renal excretion → ketoacid anions retained → elevated anion gap metabolic acidosis
  • During treatment: ECF restored, Na⁺ salts of ketoacids excreted again, NaCl administered → anion gap acidosis transitions back to hyperchloremic normal gap acidosis (may take days to fully resolve)
  • Comprehensive Clinical Nephrology, 7th Ed; Rosen's Emergency Medicine

Precipitating Factors

Most Common:
  • Infections (most frequent trigger)
  • Inadequate insulin / non-adherence
  • New-onset diabetes
  • Acute coronary syndrome
  • Unknown
Other:
  • Intercurrent illness: stroke, pulmonary embolism, acute pancreatitis, mesenteric thrombosis
  • Alcohol intoxication
  • Endocrinopathies: Cushing's syndrome, thyrotoxicosis, acromegaly
  • Drugs: corticosteroids, clozapine, olanzapine, cocaine, lithium, sympathomimetics, thiazide diuretics, SGLT2 inhibitors (can cause euglycemic DKA)
  • Severe burns, hyperthermia/hypothermia
  • Goldman-Cecil Medicine

Clinical Features

Symptoms (gradual onset over hours to days):
  • Polyuria, polydipsia, polyphagia
  • Weakness, lethargy, weight loss
  • Nausea, vomiting
  • Abdominal pain (~50% of cases, especially in children; in adults, may represent true abdominal disease triggering DKA)
  • Visual blurring, anorexia
Signs:
  • Kussmaul breathing - deep, rapid respirations (compensatory respiratory alkalosis for metabolic acidosis)
  • Fruity/acetone breath
  • Tachycardia, orthostatic hypotension or frank hypotension
  • Dry skin and mucous membranes (dehydration)
  • Depressed sensorium/coma (reflects hyperosmolality - this, NOT acidosis alone, is the prime determinant of mental status depression)
  • Elevated temperature suggests precipitating infection (DKA itself rarely causes fever)
  • Rosen's Emergency Medicine; Goldman-Cecil Medicine

Diagnosis

Diagnostic Criteria (Severity Classification)

ParameterMildModerateSevere
Glucose (mg/dL)>250>250>250
pH (arterial)7.25-7.307.00-7.24<7.00
HCO₃⁻ (mmol/L)15-1810-14<10
Anion gap>10>12>12
Urine/serum ketonesPositivePositivePositive
Mental statusAlertAlert/drowsyStupor/coma

DKA vs. HHS (Comparison)

FeatureDKAHHS
Glucose (mg/dL)>350>700
Sodium (mEq/L)Low 130s140s
Potassium (mEq/L)~4.5-6.0~5
Bicarbonate (mEq/L)<10>15
Ketones+++Absent/minimal
pH<7.3Usually >7.3
OsmolalityMildly elevatedMarkedly elevated
  • Rosen's Emergency Medicine

Lab Workup

  • Serum glucose, BMP (electrolytes, BUN/Cr, anion gap)
  • Venous or arterial blood gas (venous pH correlates well with arterial; use arterial if respiratory compensation concerns exist)
  • Serum/urine ketones - note: nitroprusside tests detect only acetoacetate and acetone, NOT β-hydroxybutyrate (the predominant ketone). This can give falsely low results. Direct β-OHB measurement is preferred.
  • Serum magnesium (deficits common)
  • ECG - if immediate K⁺ not available; can detect hyperkalemia/hypokalemia
  • Urinalysis (confirm ketones, rule out UTI as precipitant)
  • Blood/urine cultures as clinically indicated
  • Serum amylase may be elevated (usually non-pancreatic in origin - avoid erroneous pancreatitis diagnosis)
Electrolyte Interpretation Pitfalls:
  • Sodium: Often pseudohyponatremia due to hyperglycemia (osmotic shift of water into vasculature). Corrected Na = Measured Na + 1.6 × [(glucose - 100)/100]
  • Potassium: Initial level may be normal or HIGH (acidosis shifts K⁺ out of cells) despite profound total-body K⁺ depletion. As insulin is given and acidosis corrects, K⁺ shifts back intracellularly → life-threatening hypokalemia can develop.
  • WBC: Often elevated even without infection (metabolic acidosis itself can cause leukocytosis)
Average fluid and electrolyte deficits in severe DKA (per kg body weight):
  • Water: 70-120 mL/kg
  • Sodium: 8-10 mEq/L
  • Potassium: 5-7 mEq/L
  • Chloride: 6-8 mEq/L
  • Phosphorus: 3 mEq/L
  • Rosen's Emergency Medicine; Goldman-Cecil Medicine

Treatment

1. Fluid Resuscitation

  • Immediate IV fluid replacement to correct profound dehydration and restore renal perfusion
  • Start with 0.9% Normal Saline (NS)
  • Typical initial rate: 15-20 mL/kg/h in first 1-2 hours, then adjusted based on hemodynamics and urinary output
  • When blood glucose drops to 250-300 mg/dL, switch to dextrose-containing fluids (e.g., D5 0.45% NS) to prevent hypoglycemia and rapid osmolarity shifts
  • Euglycemic DKA (common with SGLT2 inhibitors): add dextrose to fluids from the START of insulin therapy

2. Insulin

  • IV regular insulin is the route of choice in moderate-to-severe DKA
  • Start at 0.1 units/kg/h (up to 5-10 units/h)
  • No IV bolus before infusion - no longer recommended
  • IV insulin has a half-life of 3-10 minutes; infusion maintains steady levels better than bolus
  • In selected mild DKA patients who are well-hydrated: subcutaneous or IM insulin (lispro or regular) is proven safe and effective - outpatient management may be feasible with good follow-up
  • Goal: Reduce blood glucose by ~50-75 mg/dL/h; close the anion gap; clear ketones

3. Potassium Replacement (Critical)

  • Do NOT start insulin if K⁺ <3.5 mEq/L - insulin will worsen hypokalemia dangerously
  • If K⁺ <3.5: replace K⁺ first, then start insulin
  • If K⁺ 3.5-5.0: add 20-40 mEq KCl per liter of IV fluid
  • If K⁺ >5.0: hold K⁺, monitor every 2 hours
  • Ongoing potassium losses continue during therapy; anticipate significant supplementation

4. Phosphate

  • Deficits are common; typically repleted when significant hypophosphatemia develops during treatment
  • Routine aggressive phosphate replacement not shown to improve outcomes

5. Magnesium

  • Deficiency common in DKA (both from initial pathophysiology and therapy-induced diuresis)
  • Hypomagnesemia can cause vomiting, mental changes, recalcitrant hypokalemia/hypocalcemia, and fatal cardiac arrhythmias
  • Typical adult repletion: 1-3 g MgSO₄ IV

6. Bicarbonate

  • Controversial - generally NOT recommended except in severe cases (pH <6.9 or life-threatening hyperkalemia)
  • Bicarbonate can paradoxically worsen intracellular/CSF acidosis, worsen hypokalemia, and delay ketone clearance
  • Insulin and fluids alone are sufficient to correct acidosis in most cases

7. Monitor and Switch to Subcutaneous Insulin

  • Resolution criteria: glucose <200-250 mg/dL, anion gap closed, pH >7.3, HCO₃⁻ >15 mmol/L, patient tolerating oral intake
  • Overlap subcutaneous basal insulin with IV insulin for 1-2 hours before stopping infusion to prevent rebound ketosis

Special Populations

Pediatric DKA

  • Cerebral edema is the most feared complication (~1% incidence overall, but significant mortality)
  • Degree of acidosis/uremia predicts cerebral edema better than specific fluid or insulin regimens
  • Recent large prospective study (n=1255) showed similar cerebral edema risk with restrictive vs. permissive fluid resuscitation
  • Treat suspected cerebral edema immediately with mannitol

SGLT2 Inhibitor-Associated DKA (Euglycemic DKA)

  • Blood glucose may be ≤300 mg/dL in up to 18% of DKA patients; more common with SGLT2 inhibitors
  • High index of suspicion needed; do not be falsely reassured by near-normal glucose

Pregnancy


Differential Diagnosis

Other causes of elevated anion gap metabolic acidosis (MUDPILES / GOLDMARK):
  • Alcoholic ketoacidosis - euglycemic/hypoglycemic; alkalemia common; β-OHB predominates
  • Starvation ketosis - mild; common in 3rd trimester and nursing mothers
  • Lactic acidosis
  • Toxic ingestions (methanol, ethylene glycol, salicylates)
  • Uremia
  • Sepsis
The presence of DKA does not exclude other causes - physiologic stress from any of the above can simultaneously precipitate DKA.
  • Rosen's Emergency Medicine

Complications

  • Hypokalemia (most dangerous during treatment)
  • Hypoglycemia (iatrogenic, from insulin)
  • Cerebral edema (especially in pediatric patients)
  • Aspiration (ileus/vomiting + altered mental status)
  • Thrombosis (hypercoagulable state from dehydration)
  • Acute kidney injury (prerenal from dehydration)
  • Hyperchloremic non-anion gap acidosis (expected, post-treatment, from large NS administration)

Prevention

  • Sick-day rules education: continue insulin even when not eating; frequent glucose monitoring; check urine/serum ketones when ill; small frequent carbohydrate-containing fluids; increase insulin as needed
  • Follow-up with diabetes educator or specialist after any DKA episode

Prognosis

  • DKA mortality: ~4%
  • HHS mortality: up to 20% (comparatively worse due to older patient population and severity of precipitating illness)
  • Risk factors for death: extremes of age, comorbidities, severity of precipitating illness
  • Goldman-Cecil Medicine, p. 2485

Recent Evidence (2024-2026)


Sources: Goldman-Cecil Medicine (2 Vol), Rosen's Emergency Medicine, Comprehensive Clinical Nephrology 7e, Tintinalli's Emergency Medicine

Now need a note on HHS

HHS (Hyperosmolar Hyperglycemic State) is a hyperglycemic emergency predominantly in Type 2 DM, characterized by extreme hyperglycemia (>600 mg/dL), hyperosmolality (>320 mOsm/kg), and profound dehydration — without significant ketoacidosis.
Searching sources...
Finding Sources
Searching PubMed

"hyperosmolar hyperglycemic state" management

Good sources found. Reading Harrison's 22e (most current), Rosen's EM, Goldman-Cecil, and Washington Manual in parallel.
Reading File
Reading File
Reading File
Reading File
Good content from Harrison's and Rosen's. Let me now get the full treatment protocol from the Washington Manual and the Rosen's treatment section.
Reading File
Reading File
I also need to read the rest of the Goldman-Cecil HHS content and the Harrison's treatment section for completeness.
Reading File
Reading File
I have comprehensive material from four authoritative sources. Here are the complete HHS notes:

Hyperosmolar Hyperglycemic State (HHS) - Clinical Notes


Definition & Overview

HHS (formerly called HHNK - Hyperosmolar Hyperglycemic Nonketotic Coma) is an acute hyperglycemic emergency characterized by:
  • Marked hyperglycemia (glucose typically >600 mg/dL, can exceed 1000 mg/dL)
  • Severe hyperosmolality (>320 mOsm/kg)
  • Profound dehydration
  • Altered mental status - ranging from confusion to frank coma
  • Absence or only mild ketonemia/acidosis (pH >7.3, HCO₃⁻ >18-20 mmol/L)
The terminology has moved away from "nonketotic coma" because: (1) mild ketosis can be present, and (2) coma is not universal.
Primarily a disease of elderly patients with Type 2 DM. In 20-30% of cases, it is the initial presentation of diabetes.
  • Rosen's Emergency Medicine; Washington Manual of Medical Therapeutics

Epidemiology

  • Incidence: <1 case per 1000 person-years (significantly less common than DKA)
  • 30-40% of cases represent first presentation of T2DM
  • ~85% of patients have underlying renal or cardiac impairment as a predisposing factor
  • ~20% have no known history of diabetes at presentation
  • Most common associated comorbidities: chronic renal insufficiency, GI bleeding, gram-negative pneumonia, gram-negative sepsis
  • Washington Manual; Rosen's EM

Pathophysiology

Core mechanism: Relative insulin deficiency (not absolute) + inadequate fluid intake
Relative insulin deficiency
         ↓
↑ Hepatic glucose production (glycogenolysis + gluconeogenesis)
↓ Peripheral glucose uptake (skeletal muscle)
         ↓
     Hyperglycemia
         ↓
  Osmotic diuresis → hypotonic urine (Na 50-70 mEq/L vs. ECF 140 mEq/L)
         ↓
Profound intravascular volume depletion
+ Patient cannot compensate (old age, dementia, stroke, physical infirmity)
         ↓
↓ GFR → ↓ renal glucose excretion → worsening hyperglycemia
↑ Hemoconcentration → ↑ osmolality → ↑ Na⁺
Why no significant ketosis? The insulin deficiency is only relative - enough residual insulin remains to:
  • Suppress lipolysis (free fatty acid levels lower than in DKA)
  • Suppress hepatic ketogenesis (portal vein insulin concentrations are higher than in DKA)
  • The insulin/glucagon ratio does not favor ketone body synthesis
Some patients with severely depressed insulin secretion may present with a mixed DKA + HHS picture - mild acidosis is possible, but arterial pH rarely drops below 7.30 and HCO₃⁻ rarely falls below 18 mmol/L from hyperglycemia alone.
Small anion-gap acidosis can occur from: lactic acidosis (from ischemia/sepsis), starvation ketosis, or prerenal azotemia.
  • Goldman-Cecil Medicine; Harrison's 22e; Rosen's EM

Precipitating Factors

CategoryExamples
Infection (most common)Gram-negative pneumonia, gram-negative sepsis, UTI
CardiovascularAcute MI, stroke
DehydrationInadequate fluid access, physical infirmity, dementia
Medications non-complianceMissed hypoglycemic agents
DietaryDietary indiscretion
DrugsCorticosteroids, thiazides, alcohol, cocaine
Other illnessAcute pancreatitis, GI bleeding, mesenteric thrombosis, burns, dialysis
IatrogenicParenteral hyperalimentation, peritoneal dialysis, hemodialysis
Note: Decreased renal clearance of glucose with age contributes in elderly patients.

Clinical Features

Onset: Insidious - develops over days to weeks (much longer prodrome than DKA)
Symptoms:
  • Polyuria, polydipsia, thirst
  • Progressive lethargy and confusion
  • Weakness, weight loss
  • Oliguria (late - as volume depletion reduces urine output)
  • Fever (from precipitating infection, not HHS itself)
Notably ABSENT (vs. DKA):
  • Nausea and vomiting (less prominent)
  • Abdominal pain
  • Kussmaul breathing (no acidosis to compensate for)
  • Fruity/acetone breath
Signs:
  • Orthostatic hypotension or frank hypotension
  • Tachycardia
  • Marked dehydration (dry mucous membranes, poor skin turgor)
  • Altered mental status - severity correlates directly with degree and rate of osmolality rise
    • 10% present with frank coma
    • 10% have no mental status changes at all
  • Focal neurologic findings - common and can mimic stroke: hemisensory/motor deficits, aphasia, extensor plantar reflexes
  • Seizures (focal or generalized)
  • Arterial and venous thromboses are common
  • Harrison's 22e; Goldman-Cecil Medicine; Rosen's EM

Diagnosis

Diagnostic Criteria

ParameterHHS
Glucose>600 mg/dL (can exceed 1000 mg/dL)
Serum osmolality>320 mOsm/kg (often >350)
pH>7.3
Bicarbonate>15-20 mmol/L
KetonesAbsent or trace
Mental statusVariable - confusion to coma

HHS vs. DKA (Side-by-Side)

FeatureDKAHHS
Typical patientT1DM, any ageElderly T2DM
OnsetHours to daysDays to weeks
Glucose>250 mg/dL>600 mg/dL
OsmolalityMildly elevatedMarkedly elevated (>320)
Ketones++ to +++Absent/trace
pH<7.3>7.3
HCO₃⁻<18 mmol/L>18-20 mmol/L
Kussmaul breathingPresentAbsent
Anion gapElevatedNormal (unless concurrent lactic acidosis)
Fluid deficit3-6 L9-12 L (more severe)
Mental status changesLess prominentMore prominent
Mortality~4%Up to 15-20%

Lab Workup

  • Serum glucose, BMP (electrolytes, BUN/Cr)
  • Serum osmolality (measured: 2×Na + glucose/18 + BUN/2.8)
  • Blood gas (venous acceptable) - to confirm no significant acidosis
  • Corrected serum sodium: Add 1.6 mEq to measured Na for each 100 mg/dL rise in glucose above 100 mg/dL (or per some sources: add 1.6 for each 5.6 mmol/L rise)
  • Urine ketones (typically absent or minimal)
  • ECG (to exclude ACS as precipitant; assess K⁺ status)
  • Blood cultures, CXR, urinalysis (to identify precipitating infection)
  • Consider troponin, lipase as clinically indicated
  • Lactate (if hemodynamically compromised)
Electrolyte pitfalls:
  • Measured sodium often LOW or normal despite extreme hyperglycemia (pseudohyponatremia) - corrected Na is usually ELEVATED
  • Potassium: initial level may appear normal or high, but total body stores are depleted. Because acidosis is less severe than in DKA, the gap between serum K⁺ and actual stores is smaller than in DKA - levels more accurately reflect total body K⁺ than in DKA.

Treatment

1. Fluids (Most Important Intervention)

Fluid replacement is the cornerstone of HHS treatment - fluids alone will lower glucose substantially by restoring renal perfusion and GFR.
Phase 1 - Hemodynamic resuscitation:
  • 0.9% Normal Saline: 1-3 L over the first 2-3 hours
  • Goal: restore hemodynamic stability and intravascular volume
Phase 2 - Free water deficit replacement:
  • If Na >150 mEq/L: switch to 0.45% saline (hypotonic)
  • Then transition to D5W to replace free water deficit
  • Free water deficit can be 9-12 L - reverse over 24-72 hours
  • Typical infusion rate: 200-300 mL/h of hypotonic solution
  • Key principle: Do NOT correct osmolality too rapidly - overly rapid reversal of hyperosmolality risks worsening neurologic function (osmotic encephalopathy / cerebral edema)
  • Rate of glucose reduction: avoid correcting >100 mg/dL/hour
Monitoring: In elderly patients with cardiac or renal comorbidity, hemodynamic monitoring may be required (risk of volume overload and pulmonary edema).

2. Insulin (Secondary Role)

Insulin plays a more secondary role in HHS compared to DKA - fluids are the priority.
  • Do NOT start insulin if K⁺ <3.5 mEq/L (same rule as DKA)
  • Washington Manual: Bolus 5-10 units IV (if glucose >600 mg/dL; smaller bolus if glucose <600), then infusion at 0.10-0.15 units/kg/h
  • Harrison's: Bolus 0.1 units/kg then infusion at 0.1 units/kg/h
  • Avoid IV insulin infusion at high rates if not needed - fluid rehydration alone often brings glucose down significantly
  • When glucose drops to 250-300 mg/dL: add D5 to IV fluids and reduce insulin to 1-2 units/h
  • When patient is eating and hemodynamically stable: transition to subcutaneous insulin; administer SC basal insulin 2 hours before stopping the infusion
  • Some patients can later transition to oral agents

3. Potassium

  • Add KCl 10-20 mEq/h to fluids as soon as urine output is confirmed and K⁺ <5 mEq/L
  • Goal: maintain K⁺ 4-5 mEq/L during treatment
  • In patients on diuretics: K⁺ deficit may be large and accompanied by magnesium deficiency

4. Phosphate and Magnesium

  • Hypophosphatemia can develop during therapy; use KPO₄ when replacing K⁺ and begin nutrition
  • Magnesium repletion as needed, especially if patient was on diuretics

5. Bicarbonate

  • Not routinely recommended
  • May be required only if concurrent significant lactic acidosis is present

6. Treat the Precipitant (Critical)

Finding and treating the precipitating illness is as important as treating the metabolic emergency:
  • Broad-spectrum antibiotics early if infection is known or suspected
  • Maintain high suspicion for: pancreatitis, GI bleeding, renal failure, acute MI, thromboembolic events (mesenteric thrombosis, DVT/PE)

Complications

  • Thromboembolic events - very common due to hemoconcentration and hyperviscosity:
    • Cerebral venous thrombosis
    • Mesenteric thrombosis
    • Acute MI
    • DVT/PE
  • Hypokalemia (from insulin and fluid therapy)
  • Hypoglycemia (iatrogenic)
  • Cerebral edema - rare in adults (mainly reported with glucose >700 mg/dL); more likely reflects severity of illness rather than fluid regimen
  • Osmotic encephalopathy - from too-rapid correction of hyperosmolality
  • Acute kidney injury (prerenal → intrinsic if severe)
  • Aspiration pneumonia (from altered mental status)
  • Rhabdomyolysis (from severe dehydration)

Differential Diagnosis

The altered mental status of HHS mimics many neurologic emergencies:
  • Ischemic or hemorrhagic stroke
  • Hypoglycemia
  • Hyponatremia
  • Uremia / hyperammonemia
  • Drug overdose / intoxication
  • Septic encephalopathy
  • Meningitis/encephalitis
Focal neurologic deficits and seizures in HHS are reversible with treatment - do not rush to neuroimaging without first correcting the metabolic derangement.

Prognosis

  • Mortality: up to 15-20% (some series) - substantially higher than DKA (~4%)
  • Higher mortality reflects: older patient population, severity of precipitating illness, multiple comorbidities
  • Outcome correlates with degree and duration of hyperosmolarity and with the nature of the precipitating condition

Key Differences from DKA - Summary

DKAHHS
Insulin deficiencyAbsoluteRelative
KetosisMajor featureAbsent/minimal
AcidosisCentral featureAbsent unless concurrent
Fluid deficit3-6 L9-12 L
Mental statusLess impairedMore impaired
OnsetHours-daysDays-weeks
Priority in treatmentInsulin + fluidsFluids first, insulin secondary
Cerebral edema risk~1% (children > adults)Rare; overly rapid correction is the risk
Mortality~4%~15-20%
Mixed DKA + HHS can occur in T2DM patients with severely depressed insulin secretion - mild acidosis with markedly elevated glucose and osmolality.

Sources: Harrison's Principles of Internal Medicine 22e (2025), Rosen's Emergency Medicine, Goldman-Cecil Medicine, Washington Manual of Medical Therapeutics

PDF

Reading the PDF skill first.
Reading File
Running Command

ls /home/daytona/workspace/

Running Command

mkdir -p /home/daytona/workspace/dka-hhs

Writing File

~/dka-hhs/generate_pdf.py

from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm
from reportlab.lib import colors
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
    HRFlowable, PageBreak, KeepTogether
)
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY
from reportlab.platypus import ListFlowable, ListItem

OUTPUT = "/home/daytona/workspace/dka-hhs/DKA_HHS_Notes.pdf"

doc = SimpleDocTemplate(
    OUTPUT,
    pagesize=A4,
    rightMargin=2*cm, leftMargin=2*cm,
    topMargin=2.2*cm, bottomMargin=2*cm,
    title="DKA & HHS Clinical Notes",
    author="Orris Medical"
)

W = A4[0] - 4*cm  # usable width

# ── Colour palette ──────────────────────────────────────────────────────────
DKA_DARK   = colors.HexColor("#1a3a5c")   # deep navy
DKA_MID    = colors.HexColor("#2e6da4")   # mid-blue
DKA_LIGHT  = colors.HexColor("#ddeeff")   # pale blue tint
HHS_DARK   = colors.HexColor("#7b2d00")   # deep rust
HHS_MID    = colors.HexColor("#c0520f")   # rust-orange
HHS_LIGHT  = colors.HexColor("#fde8d8")   # pale rust tint
NEUTRAL    = colors.HexColor("#f5f5f5")
BORDER     = colors.HexColor("#cccccc")
TBL_HDR_BG = colors.HexColor("#2e6da4")
TBL_ALT    = colors.HexColor("#eef4fb")
RED_WARN   = colors.HexColor("#c0392b")
GREEN_OK   = colors.HexColor("#1a7a3c")
TEXT_MAIN  = colors.HexColor("#1a1a1a")
TEXT_MUTED = colors.HexColor("#555555")

# ── Styles ───────────────────────────────────────────────────────────────────
base = getSampleStyleSheet()

def style(name, **kw):
    s = ParagraphStyle(name, **kw)
    return s

COVER_TITLE = style("CoverTitle",
    fontName="Helvetica-Bold", fontSize=32, textColor=colors.white,
    leading=40, alignment=TA_CENTER, spaceAfter=6)
COVER_SUB = style("CoverSub",
    fontName="Helvetica", fontSize=14, textColor=colors.HexColor("#cce0ff"),
    leading=20, alignment=TA_CENTER)
COVER_FOOT = style("CoverFoot",
    fontName="Helvetica-Oblique", fontSize=10, textColor=colors.HexColor("#aaaaaa"),
    alignment=TA_CENTER)

CH_DKA = style("ChDKA",
    fontName="Helvetica-Bold", fontSize=20, textColor=colors.white,
    leading=26, spaceBefore=0, spaceAfter=0, alignment=TA_LEFT)
CH_HHS = style("ChHHS",
    fontName="Helvetica-Bold", fontSize=20, textColor=colors.white,
    leading=26, spaceBefore=0, spaceAfter=0, alignment=TA_LEFT)

H1 = style("H1",
    fontName="Helvetica-Bold", fontSize=13, textColor=DKA_DARK,
    leading=17, spaceBefore=14, spaceAfter=4,
    borderPad=0)
H1_HHS = style("H1_HHS",
    fontName="Helvetica-Bold", fontSize=13, textColor=HHS_DARK,
    leading=17, spaceBefore=14, spaceAfter=4)
H2 = style("H2",
    fontName="Helvetica-Bold", fontSize=11, textColor=DKA_MID,
    leading=15, spaceBefore=8, spaceAfter=3)
H2_HHS = style("H2_HHS",
    fontName="Helvetica-Bold", fontSize=11, textColor=HHS_MID,
    leading=15, spaceBefore=8, spaceAfter=3)

BODY = style("Body",
    fontName="Helvetica", fontSize=9.5, textColor=TEXT_MAIN,
    leading=14, spaceAfter=4, alignment=TA_JUSTIFY)
BODY_SM = style("BodySm",
    fontName="Helvetica", fontSize=8.8, textColor=TEXT_MAIN,
    leading=13, spaceAfter=3)
BULLET = style("Bullet",
    fontName="Helvetica", fontSize=9.5, textColor=TEXT_MAIN,
    leading=13.5, spaceAfter=2, leftIndent=14, firstLineIndent=-10)
BULLET_B = style("BulletB",
    fontName="Helvetica-Bold", fontSize=9.5, textColor=TEXT_MAIN,
    leading=13.5, spaceAfter=2, leftIndent=14, firstLineIndent=-10)
SUB_BULLET = style("SubBullet",
    fontName="Helvetica", fontSize=9, textColor=TEXT_MUTED,
    leading=12, spaceAfter=1, leftIndent=26, firstLineIndent=-10)
WARN = style("Warn",
    fontName="Helvetica-Bold", fontSize=9.5, textColor=RED_WARN,
    leading=13, spaceAfter=3, leftIndent=14, firstLineIndent=-10)
NOTE = style("Note",
    fontName="Helvetica-Oblique", fontSize=8.5, textColor=TEXT_MUTED,
    leading=12, spaceAfter=6, alignment=TA_LEFT)
SOURCE = style("Source",
    fontName="Helvetica-Oblique", fontSize=7.8, textColor=TEXT_MUTED,
    leading=11, spaceAfter=2)

# ── Helpers ───────────────────────────────────────────────────────────────────
def b(txt): return f"<b>{txt}</b>"
def i(txt): return f"<i>{txt}</i>"
def c(txt, col): return f'<font color="{col}">{txt}</font>'

def hr(col=BORDER, thickness=0.5): return HRFlowable(width="100%", thickness=thickness, color=col, spaceAfter=4, spaceBefore=4)

def section_banner(text, bg, style_):
    data = [[Paragraph(text, style_)]]
    t = Table(data, colWidths=[W])
    t.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), bg),
        ("LEFTPADDING",  (0,0), (-1,-1), 10),
        ("RIGHTPADDING", (0,0), (-1,-1), 10),
        ("TOPPADDING",   (0,0), (-1,-1), 8),
        ("BOTTOMPADDING",(0,0), (-1,-1), 8),
        ("ROUNDEDCORNERS", (0,0), (-1,-1), 4),
    ]))
    return t

def info_box(text, bg, border_col, text_style):
    data = [[Paragraph(text, text_style)]]
    t = Table(data, colWidths=[W])
    t.setStyle(TableStyle([
        ("BACKGROUND",   (0,0), (-1,-1), bg),
        ("LEFTPADDING",  (0,0), (-1,-1), 10),
        ("RIGHTPADDING", (0,0), (-1,-1), 10),
        ("TOPPADDING",   (0,0), (-1,-1), 6),
        ("BOTTOMPADDING",(0,0), (-1,-1), 6),
        ("BOX",          (0,0), (-1,-1), 1, border_col),
        ("ROUNDEDCORNERS",(0,0),(-1,-1), 3),
    ]))
    return t

def make_table(headers, rows, col_widths=None, accent=DKA_MID):
    hdr_style = ParagraphStyle("TblH", fontName="Helvetica-Bold", fontSize=8.5,
                                textColor=colors.white, leading=11)
    cell_style = ParagraphStyle("TblC", fontName="Helvetica", fontSize=8.5,
                                 textColor=TEXT_MAIN, leading=12)
    data = [[Paragraph(h, hdr_style) for h in headers]]
    for r in rows:
        data.append([Paragraph(str(c), cell_style) for c in r])
    if col_widths is None:
        col_widths = [W / len(headers)] * len(headers)
    t = Table(data, colWidths=col_widths, repeatRows=1)
    ts = [
        ("BACKGROUND",    (0,0), (-1,0),  accent),
        ("ROWBACKGROUNDS",(0,1), (-1,-1), [colors.white, TBL_ALT]),
        ("GRID",          (0,0), (-1,-1), 0.4, BORDER),
        ("LEFTPADDING",   (0,0), (-1,-1), 6),
        ("RIGHTPADDING",  (0,0), (-1,-1), 6),
        ("TOPPADDING",    (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ]
    t.setStyle(TableStyle(ts))
    return t

def bp(text): return Paragraph(f"\u2022  {text}", BULLET)
def bp_b(text): return Paragraph(f"\u2022  {text}", BULLET_B)
def sbp(text): return Paragraph(f"\u25e6  {text}", SUB_BULLET)
def wp(text): return Paragraph(f"\u26a0  {text}", WARN)

# ════════════════════════════════════════════════════════════════════════════
# BUILD STORY
# ════════════════════════════════════════════════════════════════════════════
story = []

# ── COVER PAGE ────────────────────────────────────────────────────────────────
cover_bg = Table([[""]], colWidths=[W + 4*cm], rowHeights=[A4[1]])
cover_bg.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1), DKA_DARK)]))

# We simulate cover with a large coloured block + centred text
# Use a full-page table trick:
cover_data = [[
    Paragraph("DKA &amp; HHS", COVER_TITLE),
], [
    Paragraph("Diabetic Ketoacidosis &amp; Hyperosmolar Hyperglycemic State", COVER_SUB),
], [
    Spacer(1, 0.4*cm),
], [
    Paragraph("Clinical Notes  •  Based on Harrison's 22e, Goldman-Cecil Medicine,<br/>Rosen's Emergency Medicine, Washington Manual", COVER_FOOT),
], [
    Spacer(1, 0.2*cm),
], [
    Paragraph("July 2026", COVER_FOOT),
]]
cover_tbl = Table(cover_data, colWidths=[W])
cover_tbl.setStyle(TableStyle([
    ("BACKGROUND",   (0,0), (-1,-1), DKA_DARK),
    ("LEFTPADDING",  (0,0), (-1,-1), 20),
    ("RIGHTPADDING", (0,0), (-1,-1), 20),
    ("TOPPADDING",   (0,0), (-1,-1), 8),
    ("BOTTOMPADDING",(0,0), (-1,-1), 8),
    ("VALIGN",       (0,0), (-1,-1), "MIDDLE"),
    ("BOX",          (0,0), (-1,-1), 3, DKA_MID),
    ("ROUNDEDCORNERS",(0,0),(-1,-1), 8),
]))
story.append(Spacer(1, 5*cm))
story.append(cover_tbl)
story.append(PageBreak())

# ════════════════════════════════════════════════════════════════════════════
# SECTION 1 — DKA
# ════════════════════════════════════════════════════════════════════════════
story.append(section_banner("SECTION 1 — DIABETIC KETOACIDOSIS (DKA)", DKA_DARK, CH_DKA))
story.append(Spacer(1, 0.3*cm))

# Definition
story.append(Paragraph("1. Definition", H1))
story.append(hr(DKA_MID, 1))
story.append(info_box(
    "DKA is defined by the triad of: <b>Hyperglycemia</b> (glucose >250 mg/dL or known DM) + "
    "<b>Ketonemia</b> (urine ketones 2+ or serum β-hydroxybutyrate ≥3.0 mmol/L) + "
    "<b>Acidosis</b> (pH <7.3 or HCO₃⁻ <18 mmol/L).",
    DKA_LIGHT, DKA_MID,
    style("DefBody", fontName="Helvetica", fontSize=9.5, textColor=TEXT_MAIN, leading=14, leftIndent=4)
))
story.append(Spacer(1, 0.2*cm))
story.append(bp("Most common in <b>Type 1 DM</b>; ~25% of episodes occur in previously undiagnosed diabetes"))
story.append(bp("Can occur in Type 2 DM under physiologic stress"))
story.append(bp("<b>Euglycemic DKA</b>: glucose ≤300 mg/dL in up to 18% of cases — more common with SGLT2 inhibitors"))

# Severity classification
story.append(Spacer(1, 0.3*cm))
story.append(Paragraph("Severity Classification", H2))
story.append(make_table(
    ["Parameter", "Mild", "Moderate", "Severe"],
    [
        ["Glucose (mg/dL)", ">250", ">250", ">250"],
        ["pH", "7.25–7.30", "7.00–7.24", "<7.00"],
        ["HCO₃⁻ (mmol/L)", "15–18", "10–14", "<10"],
        ["Anion gap", ">10", ">12", ">12"],
        ["Mental status", "Alert", "Alert/drowsy", "Stupor/coma"],
    ],
    col_widths=[W*0.34, W*0.22, W*0.22, W*0.22],
    accent=DKA_MID
))

# Pathophysiology
story.append(Paragraph("2. Pathophysiology", H1))
story.append(hr(DKA_MID, 1))
story.append(Paragraph(
    "All derangements stem from <b>absolute insulin deficiency + counter-regulatory hormone excess</b> "
    "(glucagon, cortisol, catecholamines, GH):",
    BODY))
story.append(make_table(
    ["Tissue", "Effect of Insulin Deficiency", "Consequence"],
    [
        ["Liver", "↑ Gluconeogenesis, ↑ glycogenolysis, ↑ ketogenesis (FFA → β-OHB, AcAc)", "Hyperglycemia + ketones"],
        ["Adipose", "↑ Hormone-sensitive lipase → ↑ free fatty acids delivered to liver", "Substrate for ketogenesis"],
        ["Muscle", "↑ Proteolysis → amino acids to liver; ↓ glucose uptake", "Worsens hyperglycemia"],
    ],
    col_widths=[W*0.16, W*0.5, W*0.34],
    accent=DKA_MID
))
story.append(Spacer(1, 0.25*cm))
story.append(Paragraph("<b>Cascade:</b> Hyperglycemia → osmotic diuresis → dehydration + electrolyte loss (Na⁺, K⁺, Mg²⁺, PO₄³⁻) → hemoconcentration → worsens hyperglycemia (vicious cycle).", BODY))

story.append(Paragraph("Anion Gap Evolution", H2))
story.append(make_table(
    ["Stage", "Acid-Base Finding", "Mechanism"],
    [
        ["Early DKA", "Normal-gap (hyperchloremic) metabolic acidosis", "Ketoacid anions excreted as Na⁺/K⁺ salts; kidney retains NaCl"],
        ["Established DKA", "Elevated anion gap metabolic acidosis", "Volume depletion → ↓ renal excretion → ketoacid anions retained"],
        ["During treatment", "Anion gap closes; hyperchloremic acidosis re-emerges", "ECF restored, Na⁺ salts excreted, NaCl administered; resolves over days"],
    ],
    col_widths=[W*0.22, W*0.34, W*0.44],
    accent=DKA_MID
))

# Precipitants
story.append(Paragraph("3. Precipitating Factors", H1))
story.append(hr(DKA_MID, 1))

precip_data = [
    [Paragraph("<b>Most Common</b>", style("TH2", fontName="Helvetica-Bold", fontSize=9, textColor=colors.white, leading=12)),
     Paragraph("<b>Other / Drug-Induced</b>", style("TH2", fontName="Helvetica-Bold", fontSize=9, textColor=colors.white, leading=12))],
    [
        Paragraph("• Infections (most frequent)\n• Inadequate insulin / non-adherence\n• New-onset diabetes\n• Acute coronary syndrome\n• Unknown", BODY_SM),
        Paragraph("• Intercurrent illness: stroke, PE, pancreatitis, mesenteric thrombosis\n• Endocrinopathies: Cushing's, thyrotoxicosis, acromegaly\n• Drugs: corticosteroids, clozapine, olanzapine, cocaine, lithium, sympathomimetics, thiazides, <b>SGLT2 inhibitors</b>\n• Alcohol intoxication, severe burns, hyper/hypothermia", BODY_SM),
    ]
]
precip_tbl = Table(precip_data, colWidths=[W*0.45, W*0.55])
precip_tbl.setStyle(TableStyle([
    ("BACKGROUND",   (0,0), (-1,0), DKA_MID),
    ("BACKGROUND",   (0,1), (-1,-1), DKA_LIGHT),
    ("GRID",         (0,0), (-1,-1), 0.4, BORDER),
    ("VALIGN",       (0,0), (-1,-1), "TOP"),
    ("LEFTPADDING",  (0,0), (-1,-1), 8),
    ("RIGHTPADDING", (0,0), (-1,-1), 8),
    ("TOPPADDING",   (0,0), (-1,-1), 5),
    ("BOTTOMPADDING",(0,0), (-1,-1), 5),
]))
story.append(precip_tbl)

# Clinical Features
story.append(Paragraph("4. Clinical Features", H1))
story.append(hr(DKA_MID, 1))

story.append(Paragraph("<b>Symptoms</b> (onset over hours–days):", BODY))
for s_ in ["Polyuria, polydipsia, polyphagia", "Weakness, lethargy, weight loss",
           "Nausea, vomiting, anorexia",
           "Abdominal pain (~50%, especially children — usually idiopathic; in adults suggests actual abdominal disease)",
           "Visual blurring"]:
    story.append(bp(s_))

story.append(Spacer(1, 0.2*cm))
story.append(Paragraph("<b>Signs:</b>", BODY))
signs_data = [
    ["Sign", "Notes"],
    ["Kussmaul breathing", "Deep, rapid respirations — compensatory respiratory alkalosis for metabolic acidosis"],
    ["Fruity/acetone breath", "From acetone (non-enzymatic decarboxylation of acetoacetate)"],
    ["Tachycardia / hypotension", "From dehydration; orthostatic changes common"],
    ["Dry mucous membranes", "Reflects profound dehydration"],
    ["Depressed sensorium / coma", "Hyperosmolality is the prime determinant — NOT acidosis alone"],
    ["Elevated temperature", "Suggests precipitating infection (DKA itself rarely causes fever)"],
]
story.append(make_table(
    ["Sign", "Notes"],
    [r[1:] for r in signs_data[1:]],
    col_widths=[W*0.32, W*0.68], accent=DKA_MID
))

# Diagnosis
story.append(Paragraph("5. Diagnosis & Lab Workup", H1))
story.append(hr(DKA_MID, 1))
story.append(Paragraph("<b>Essential Labs:</b>", BODY))
for s_ in [
    "Serum glucose + BMP (electrolytes, BUN/Cr, anion gap)",
    "Venous or arterial blood gas — venous pH correlates well with arterial; use arterial if respiratory compensation concerns",
    "Serum/urine ketones — <b>note:</b> nitroprusside tests detect only acetoacetate + acetone, NOT β-OHB (predominant ketone) → can give falsely low result; <b>direct β-OHB measurement preferred</b>",
    "Serum magnesium (deficits very common)",
    "ECG if immediate K⁺ unavailable — can detect hyper/hypokalemia",
    "Urinalysis — ketones + rule out UTI as precipitant",
    "Lactate, troponin, lipase as clinically indicated",
]:
    story.append(bp(s_))

story.append(Spacer(1, 0.2*cm))
story.append(Paragraph("<b>Electrolyte Interpretation Pitfalls:</b>", BODY))
pitfalls = [
    ["Electrolyte", "Pitfall", "Explanation"],
    ["Sodium", "Pseudohyponatremia", "Hyperglycemia causes osmotic shift of water into vasculature → dilution. Corrected Na = Measured Na + 1.6 × [(glucose − 100)/100]"],
    ["Potassium", "Initial normal/HIGH despite depletion", "Acidosis shifts K⁺ out of cells. As insulin corrects acidosis → K⁺ shifts back intracellularly → life-threatening hypokalemia can develop. Total body deficit = several hundred mEq."],
    ["WBC", "Elevated without infection", "Metabolic acidosis itself causes leukocytosis"],
    ["Amylase", "Elevated — may mimic pancreatitis", "Usually of non-pancreatic origin in DKA"],
    ["Ketone test", "False negative β-OHB", "Nitroprusside only detects AcAc + acetone; if lactic acidosis coexists, AcAc → β-OHB conversion → test appears negative"],
]
story.append(make_table(
    pitfalls[0], [r[1:] for r in pitfalls[1:]],
    col_widths=[W*0.16, W*0.28, W*0.56], accent=DKA_MID
))

story.append(Spacer(1, 0.2*cm))
story.append(Paragraph("<b>Average Fluid & Electrolyte Deficits in Severe DKA (per kg body weight):</b>", BODY))
story.append(make_table(
    ["Water (mL/kg)", "Sodium (mEq/kg)", "Potassium (mEq/kg)", "Chloride (mEq/kg)", "Phosphorus (mEq/kg)"],
    [["70–120", "8–10", "5–7", "6–8", "3"]],
    col_widths=[W*0.2]*5, accent=DKA_MID
))

# Treatment
story.append(Paragraph("6. Treatment", H1))
story.append(hr(DKA_MID, 1))

# 6.1 Fluids
story.append(Paragraph("6.1  IV Fluids", H2))
story.append(bp("Start <b>0.9% Normal Saline</b> immediately"))
story.append(bp("Typical initial rate: 15–20 mL/kg/h for first 1–2 hours, then adjusted to hemodynamics + urine output"))
story.append(bp("When glucose drops to <b>250–300 mg/dL</b>: add dextrose (D5 0.45% NS) to prevent hypoglycemia and rapid osmolarity shifts"))
story.append(wp("Euglycemic DKA (SGLT2 inhibitor-associated): add dextrose to fluids FROM THE START of insulin therapy"))

# 6.2 Insulin
story.append(Spacer(1, 0.1*cm))
story.append(Paragraph("6.2  Insulin", H2))
story.append(bp("<b>IV regular insulin</b> is route of choice in moderate-to-severe DKA"))
story.append(bp("Rate: <b>0.1 units/kg/h</b> (up to 5–10 units/h) — no IV bolus required"))
story.append(bp("IV insulin half-life = 3–10 min → infusion maintains steadier levels than bolus"))
story.append(bp("Mild DKA, well-hydrated: subcutaneous or IM insulin (lispro or regular) is safe and effective"))
story.append(bp("Goal: reduce glucose ~50–75 mg/dL/h; close anion gap; clear ketones"))

# 6.3 Potassium — CRITICAL
story.append(Spacer(1, 0.1*cm))
story.append(Paragraph("6.3  Potassium (Critical)", H2))
story.append(info_box(
    "⚠  DO NOT start insulin if K⁺ < 3.5 mEq/L — insulin will worsen hypokalemia dangerously. Replace K⁺ first, THEN start insulin.",
    colors.HexColor("#fff0f0"), RED_WARN,
    style("WarnBox", fontName="Helvetica-Bold", fontSize=9.5, textColor=RED_WARN, leading=14)
))
story.append(Spacer(1, 0.15*cm))
story.append(make_table(
    ["Serum K⁺", "Action"],
    [
        ["< 3.5 mEq/L", "Replete K⁺ (IV KCl); hold insulin until K⁺ ≥ 3.5"],
        ["3.5–5.0 mEq/L", "Add 20–40 mEq KCl per litre of IV fluid; start insulin"],
        ["> 5.0 mEq/L", "Hold K⁺ supplementation; recheck every 2 h"],
    ],
    col_widths=[W*0.3, W*0.7], accent=DKA_MID
))

# 6.4-6.7
story.append(Spacer(1, 0.1*cm))
story.append(Paragraph("6.4  Phosphate", H2))
story.append(bp("Deficits common; replete when significant hypophosphatemia develops during treatment"))
story.append(bp("Routine aggressive phosphate replacement not shown to improve outcomes"))

story.append(Paragraph("6.5  Magnesium", H2))
story.append(bp("Deficiency common (from osmotic diuresis + insulin therapy)"))
story.append(bp("Hypomagnesemia → vomiting, mental changes, recalcitrant hypokalemia/hypocalcemia, fatal arrhythmias"))
story.append(bp("Typical repletion: <b>1–3 g MgSO₄ IV</b>"))

story.append(Paragraph("6.6  Bicarbonate", H2))
story.append(bp("<b>NOT routinely recommended</b> — insulin + fluids correct acidosis in most cases"))
story.append(bp("Consider only for <b>pH < 6.9</b> or life-threatening hyperkalemia"))
story.append(bp("Risks: worsens intracellular/CSF acidosis, worsens hypokalemia, paradoxical CNS acidosis"))

story.append(Paragraph("6.7  Transition to Subcutaneous Insulin", H2))
story.append(bp("Resolution criteria: glucose <200–250 mg/dL, anion gap closed, pH >7.3, HCO₃⁻ >15 mmol/L, tolerating oral intake"))
story.append(bp("Overlap SC basal insulin with IV infusion for <b>1–2 hours</b> before stopping infusion to prevent rebound ketosis"))

# Special populations
story.append(Paragraph("7. Special Populations", H1))
story.append(hr(DKA_MID, 1))
story.append(Paragraph("<b>Pediatric DKA:</b>", BODY))
story.append(bp("Cerebral edema — most feared complication (~1% incidence, but significant mortality)"))
story.append(bp("Degree of acidosis/uremia predicts cerebral edema better than any specific fluid or insulin regimen"))
story.append(bp("Recent large RCT (n=1255): similar cerebral edema risk with restrictive vs. permissive fluid resuscitation"))
story.append(wp("Treat suspected cerebral edema immediately with <b>Mannitol</b>"))
story.append(Spacer(1, 0.15*cm))
story.append(Paragraph("<b>SGLT2 Inhibitor-Associated (Euglycemic) DKA:</b>", BODY))
story.append(bp("Glucose ≤300 mg/dL in up to 18% of patients — do not be reassured by near-normal glucose"))
story.append(bp("Maintain high index of suspicion in any SGLT2i patient with malaise, nausea, or metabolic acidosis"))
story.append(bp("Add dextrose to fluids from the start of insulin therapy"))

# Complications
story.append(Paragraph("8. Complications", H1))
story.append(hr(DKA_MID, 1))
comps = [
    ("Hypokalemia", "Most dangerous during treatment; from insulin and correction of acidosis"),
    ("Hypoglycemia", "Iatrogenic; avoid by adding dextrose when glucose <250–300 mg/dL"),
    ("Cerebral edema", "Especially in children; associated with degree of acidosis/uremia"),
    ("Aspiration pneumonia", "Risk from vomiting + ileus + altered mental status"),
    ("Acute kidney injury", "Prerenal from dehydration; may become intrinsic"),
    ("Thrombosis", "Hypercoagulable from dehydration/hemoconcentration"),
    ("Hyperchloremic acidosis", "Expected post-treatment from large NS volumes; resolves over days"),
]
story.append(make_table(
    ["Complication", "Notes"],
    comps, col_widths=[W*0.32, W*0.68], accent=DKA_MID
))

# Prognosis + Prevention
story.append(Paragraph("9. Prognosis & Prevention", H1))
story.append(hr(DKA_MID, 1))
story.append(make_table(
    ["", "DKA", "HHS"],
    [["Mortality", "~4%", "~15–20%"]],
    col_widths=[W*0.4, W*0.3, W*0.3], accent=DKA_MID
))
story.append(Spacer(1, 0.2*cm))
story.append(Paragraph("<b>Prevention — sick-day rules:</b>", BODY))
for s_ in ["Continue insulin even when not eating",
           "Frequent blood glucose monitoring; check urine/serum ketones when ill",
           "Small but frequent carbohydrate-containing fluids",
           "Increase insulin as needed during illness",
           "Diabetes educator/specialist follow-up after every DKA episode"]:
    story.append(bp(s_))

story.append(Spacer(1, 0.3*cm))
story.append(NOTE, )
story.append(Paragraph(
    "Sources: Goldman-Cecil Medicine (2 Vol), Rosen's Emergency Medicine, Comprehensive Clinical Nephrology 7e, Tintinalli's Emergency Medicine",
    SOURCE))

# ════════════════════════════════════════════════════════════════════════════
# SECTION 2 — HHS
# ════════════════════════════════════════════════════════════════════════════
story.append(PageBreak())
story.append(section_banner("SECTION 2 — HYPEROSMOLAR HYPERGLYCEMIC STATE (HHS)", HHS_DARK, CH_HHS))
story.append(Spacer(1, 0.3*cm))

# Definition
story.append(Paragraph("1. Definition", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(info_box(
    "HHS is an acute hyperglycemic emergency characterised by: <b>Marked hyperglycemia</b> (glucose >600 mg/dL, may exceed 1000 mg/dL) "
    "+ <b>Severe hyperosmolality</b> (>320 mOsm/kg) + <b>Profound dehydration</b> + <b>Altered mental status</b> — "
    "with <b>absent or minimal ketoacidosis</b> (pH >7.3, HCO₃⁻ >15–20 mmol/L).",
    HHS_LIGHT, HHS_MID,
    style("DefBodyHHS", fontName="Helvetica", fontSize=9.5, textColor=TEXT_MAIN, leading=14, leftIndent=4)
))
story.append(Spacer(1, 0.2*cm))
story.append(bp("Formerly called HHNK (Hyperosmolar Hyperglycemic Nonketotic Coma) — name changed because mild ketosis can occur and coma is not universal"))
story.append(bp("Primarily affects <b>elderly patients with Type 2 DM</b>"))
story.append(bp("In 20–30% of cases, it is the <b>initial presentation</b> of diabetes"))
story.append(bp("~85% of patients have underlying renal or cardiac impairment"))

# Epidemiology
story.append(Paragraph("2. Epidemiology", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(bp("Incidence: <1 case per 1000 person-years (significantly less common than DKA)"))
story.append(bp("30–40% of cases are the initial presentation of T2DM"))
story.append(bp("Most common associated comorbidities: chronic renal insufficiency, GI bleeding, gram-negative pneumonia/sepsis"))

# Pathophysiology
story.append(Paragraph("3. Pathophysiology", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(Paragraph(
    "<b>Core mechanism:</b> Relative insulin deficiency (NOT absolute) + inadequate fluid intake. "
    "The cycle below is the key to understanding HHS:",
    BODY))

path_steps = [
    ["Step", "Event"],
    ["1", "Relative insulin deficiency → ↑ hepatic glucose production + ↓ peripheral uptake"],
    ["2", "Hyperglycemia → osmotic diuresis (urine Na 50–70 mEq/L vs ECF 140 mEq/L — hypotonic losses)"],
    ["3", "Patient cannot compensate with fluid intake (elderly, dementia, stroke, physical infirmity)"],
    ["4", "Profound intravascular depletion → ↓ GFR → ↓ renal glucose excretion → worsening hyperglycaemia"],
    ["5", "Hemoconcentration → ↑ Na⁺ → marked hyperosmolality → CNS depression"],
    ["6", "Full-blown HHS: syndrome does not usually manifest until urine output has dropped"],
]
story.append(make_table(
    path_steps[0], [r[1:] for r in path_steps[1:]],
    col_widths=[W*0.06, W*0.94], accent=HHS_MID
))
story.append(Spacer(1, 0.2*cm))
story.append(Paragraph("<b>Why no significant ketosis?</b>", BODY))
story.append(bp("Insulin deficiency is only <i>relative</i> — residual insulin suppresses lipolysis"))
story.append(bp("FFA levels are lower than in DKA → less hepatic substrate for ketogenesis"))
story.append(bp("Portal vein insulin concentration higher than in DKA → liver produces fewer ketone bodies"))
story.append(bp("<b>Mixed DKA + HHS</b> can occur in T2DM with severely depressed insulin secretion — mild acidosis possible, but pH rarely <7.30 from hyperglycaemia alone"))

# Precipitants
story.append(Paragraph("4. Precipitating Factors", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(make_table(
    ["Category", "Examples"],
    [
        ["Infection (most common)", "Gram-negative pneumonia, gram-negative sepsis, UTI"],
        ["Cardiovascular", "Acute MI, stroke"],
        ["Reduced fluid access", "Dementia, prior stroke, physical infirmity, social isolation"],
        ["Medication non-compliance", "Missed oral hypoglycaemics or insulin"],
        ["Drugs", "Corticosteroids, thiazides, alcohol, cocaine, sympathomimetics"],
        ["Other illness", "Pancreatitis, GI bleeding, mesenteric thrombosis, burns"],
        ["Iatrogenic", "Parenteral hyperalimentation, peritoneal/haemodialysis"],
        ["Renal impairment", "↓ glucose clearance with ageing or pre-existing CKD"],
    ],
    col_widths=[W*0.35, W*0.65], accent=HHS_MID
))

# Clinical Features
story.append(Paragraph("5. Clinical Features", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(info_box(
    "<b>Onset:</b> Insidious — develops over <b>days to weeks</b> (much longer prodrome than DKA's hours–days).",
    HHS_LIGHT, HHS_MID,
    style("OnsetBox", fontName="Helvetica", fontSize=9.5, textColor=TEXT_MAIN, leading=14)
))
story.append(Spacer(1, 0.2*cm))

cf_data = [
    [Paragraph("<b>Symptoms Present</b>", style("TH", fontName="Helvetica-Bold", fontSize=9, textColor=colors.white, leading=12)),
     Paragraph("<b>Notably ABSENT (vs DKA)</b>", style("TH", fontName="Helvetica-Bold", fontSize=9, textColor=colors.white, leading=12))],
    [
        Paragraph("• Polyuria, polydipsia, thirst\n• Progressive confusion/lethargy\n• Weakness, weight loss\n• Oliguria (late)\n• Fever (from precipitating infection)", BODY_SM),
        Paragraph("• Kussmaul breathing (no acidosis)\n• Fruity/acetone breath\n• Nausea/vomiting (less prominent)\n• Abdominal pain", BODY_SM),
    ]
]
cf_tbl = Table(cf_data, colWidths=[W*0.5, W*0.5])
cf_tbl.setStyle(TableStyle([
    ("BACKGROUND",   (0,0), (-1,0), HHS_MID),
    ("BACKGROUND",   (0,1), (-1,-1), HHS_LIGHT),
    ("GRID",         (0,0), (-1,-1), 0.4, BORDER),
    ("VALIGN",       (0,0), (-1,-1), "TOP"),
    ("LEFTPADDING",  (0,0), (-1,-1), 8),
    ("RIGHTPADDING", (0,0), (-1,-1), 8),
    ("TOPPADDING",   (0,0), (-1,-1), 5),
    ("BOTTOMPADDING",(0,0), (-1,-1), 5),
]))
story.append(cf_tbl)
story.append(Spacer(1, 0.2*cm))

story.append(Paragraph("<b>Signs:</b>", BODY))
story.append(bp("Orthostatic hypotension or frank hypotension + tachycardia"))
story.append(bp("Marked dehydration (dry mucous membranes, poor skin turgor, sunken eyes)"))
story.append(bp("Altered mental status — severity correlates directly with degree and rate of osmolality rise"))
story.append(sbp("10% present with frank coma; 10% have no mental status changes"))
story.append(bp("<b>Focal neurological deficits</b> common — hemisensory/motor, aphasia, extensor plantar reflexes (reversible with treatment)"))
story.append(bp("Seizures — focal or generalised"))
story.append(bp("Arterial and venous thromboses are common"))

# Diagnosis
story.append(Paragraph("6. Diagnosis & Lab Workup", H1_HHS))
story.append(hr(HHS_MID, 1))

story.append(Paragraph("<b>Diagnostic Criteria:</b>", BODY))
story.append(make_table(
    ["Parameter", "HHS"],
    [
        ["Glucose", ">600 mg/dL (can exceed 1000 mg/dL)"],
        ["Serum osmolality", ">320 mOsm/kg (often >350)"],
        ["pH", ">7.3"],
        ["Bicarbonate", ">15–20 mmol/L"],
        ["Ketones", "Absent or trace"],
        ["Mental status", "Variable — confusion to coma"],
    ],
    col_widths=[W*0.35, W*0.65], accent=HHS_MID
))

story.append(Spacer(1, 0.3*cm))
story.append(Paragraph("<b>Serum Osmolality Calculation:</b>", BODY))
story.append(info_box(
    "Measured osmolality = 2×Na⁺ (mEq/L)  +  Glucose (mg/dL)/18  +  BUN (mg/dL)/2.8",
    NEUTRAL, BORDER,
    style("Formula", fontName="Helvetica-Bold", fontSize=10, textColor=DKA_DARK, leading=16, alignment=TA_CENTER)
))
story.append(Spacer(1, 0.15*cm))
story.append(Paragraph("<b>Corrected Sodium:</b>", BODY))
story.append(info_box(
    "Corrected Na = Measured Na + 1.6 mEq  for each 100 mg/dL rise in glucose above 100 mg/dL\n"
    "(Corrected Na is usually ELEVATED despite measured Na appearing normal or low)",
    HHS_LIGHT, HHS_MID,
    style("Formula2", fontName="Helvetica", fontSize=9.5, textColor=TEXT_MAIN, leading=14)
))

story.append(Spacer(1, 0.2*cm))
story.append(Paragraph("<b>Essential Labs:</b>", BODY))
for s_ in [
    "Serum glucose + BMP (electrolytes, BUN/Cr, anion gap)",
    "Serum osmolality (measured)",
    "Venous blood gas (confirm no significant acidosis)",
    "Urine ketones — typically absent/minimal",
    "ECG — exclude ACS as precipitant; assess K⁺",
    "Blood cultures, CXR, urinalysis — identify precipitating infection",
    "Troponin, lactate — if hemodynamically compromised",
]:
    story.append(bp(s_))

story.append(Spacer(1, 0.15*cm))
story.append(Paragraph("<b>Electrolyte Pitfalls (vs DKA):</b>", BODY))
story.append(bp("Measured Na: often LOW (pseudohyponatremia); corrected Na usually HIGH — use corrected value to guide fluid choice"))
story.append(bp("K⁺: initial level may appear normal/high despite total body depletion — because acidosis is mild, the discrepancy between serum K⁺ and body stores is <i>smaller</i> than in DKA; serum levels more accurately reflect true stores"))
story.append(bp("Electrolyte deficit is generally more profound than in DKA given longer illness duration"))

# Treatment
story.append(Paragraph("7. Treatment", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(info_box(
    "<b>Priority in HHS:</b> Fluids FIRST, then insulin. "
    "Fluid rehydration alone substantially lowers glucose by restoring renal perfusion and GFR.",
    HHS_LIGHT, HHS_MID,
    style("PrioBox", fontName="Helvetica-Bold", fontSize=9.5, textColor=HHS_DARK, leading=14)
))
story.append(Spacer(1, 0.2*cm))

story.append(Paragraph("7.1  IV Fluids", H2_HHS))
story.append(Paragraph("<b>Phase 1 — Hemodynamic resuscitation:</b>", BODY))
story.append(bp("<b>0.9% Normal Saline: 1–3 L over first 2–3 hours</b>"))
story.append(bp("Goal: restore hemodynamic stability + intravascular volume"))
story.append(Spacer(1, 0.1*cm))
story.append(Paragraph("<b>Phase 2 — Free water deficit replacement:</b>", BODY))
story.append(bp("If Na >150 mEq/L: switch to <b>0.45% saline</b>; then transition to D5W"))
story.append(bp("Total free water deficit: up to <b>9–12 L</b> — reverse over <b>24–72 hours</b>"))
story.append(bp("Infusion rate: 200–300 mL/h of hypotonic solution"))
story.append(wp("Do NOT correct osmolality too rapidly — risk of osmotic encephalopathy / cerebral edema"))
story.append(wp("Rate of glucose reduction: avoid correcting >100 mg/dL/hour"))
story.append(bp("In elderly with cardiac/renal comorbidity: consider haemodynamic monitoring (risk of pulmonary oedema)"))

story.append(Paragraph("7.2  Insulin (Secondary Role)", H2_HHS))
story.append(wp("Do NOT start insulin if K⁺ < 3.5 mEq/L — same rule as DKA"))
story.append(bp("IV bolus: <b>5–10 units</b> (if glucose >600); smaller if glucose <600"))
story.append(bp("Infusion: <b>0.10–0.15 units/kg/h</b>"))
story.append(bp("When glucose <250–300 mg/dL: add D5 to fluids; reduce insulin to 1–2 units/h"))
story.append(bp("Transition to SC: administer SC basal insulin <b>2 hours before</b> stopping IV infusion"))
story.append(bp("Some patients can later transition to oral agents"))

story.append(Paragraph("7.3  Potassium", H2_HHS))
story.append(bp("Add KCl 10–20 mEq/h to fluids as soon as urine output confirmed and K⁺ <5 mEq/L"))
story.append(bp("In patients on diuretics: K⁺ deficit may be large, often accompanied by magnesium deficiency"))

story.append(Paragraph("7.4  Treat the Precipitant (Critical)", H2_HHS))
story.append(bp("Broad-spectrum antibiotics early if infection known or suspected"))
story.append(bp("High suspicion for: pancreatitis, GI bleeding, renal failure, acute MI, thromboembolic events"))
story.append(bp("Repeated neurologic assessment recommended throughout treatment"))

story.append(Paragraph("7.5  Bicarbonate", H2_HHS))
story.append(bp("<b>Not routinely recommended</b>"))
story.append(bp("May be required if concurrent significant lactic acidosis"))

# Complications
story.append(Paragraph("8. Complications", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(make_table(
    ["Complication", "Notes"],
    [
        ["Thromboembolic events", "Very common — cerebral venous thrombosis, mesenteric thrombosis, DVT/PE, acute MI; from hemoconcentration/hyperviscosity"],
        ["Hypokalemia", "From insulin and fluid therapy; anticipate and monitor"],
        ["Hypoglycemia", "Iatrogenic; add dextrose when glucose <250–300"],
        ["Osmotic encephalopathy", "From too-rapid correction of hyperosmolality"],
        ["Cerebral edema", "Rare in adults; mainly with glucose >700 mg/dL"],
        ["Acute kidney injury", "Prerenal initially; can become intrinsic"],
        ["Aspiration pneumonia", "Altered mental status + poor gag reflex"],
        ["Rhabdomyolysis", "From severe dehydration and muscle hypoperfusion"],
    ],
    col_widths=[W*0.3, W*0.7], accent=HHS_MID
))

# Differential Diagnosis
story.append(Paragraph("9. Differential Diagnosis", H1_HHS))
story.append(hr(HHS_MID, 1))
story.append(Paragraph(
    "The altered mental status and focal neurological signs of HHS closely mimic neurological emergencies. "
    "Always correct the metabolic derangement before attributing deficits to a structural cause.",
    BODY))
story.append(make_table(
    ["Differential", "Distinguishing Feature"],
    [
        ["Ischaemic/haemorrhagic stroke", "No metabolic abnormality; neuroimaging confirms"],
        ["Hypoglycaemia", "Low glucose; rapid response to dextrose"],
        ["Hyponatraemia", "Low Na⁺; no marked hyperglycemia"],
        ["Uraemia", "Elevated BUN/Cr out of proportion"],
        ["Drug overdose / intoxication", "Toxicology screen; specific history"],
        ["Septic encephalopathy", "Sepsis criteria met; glucose less extreme"],
        ["DKA", "Ketosis + acidosis predominate; younger T1DM patient typically"],
    ],
    col_widths=[W*0.35, W*0.65], accent=HHS_MID
))

# DKA vs HHS comparison
story.append(PageBreak())
story.append(section_banner("DKA vs HHS — Side-by-Side Comparison", colors.HexColor("#2c2c2c"),
    style("CompHead", fontName="Helvetica-Bold", fontSize=18, textColor=colors.white, leading=24, alignment=TA_CENTER)))
story.append(Spacer(1, 0.4*cm))

comp_hdr_style = ParagraphStyle("CompH", fontName="Helvetica-Bold", fontSize=9, textColor=colors.white, leading=12)
comp_cell = ParagraphStyle("CompC", fontName="Helvetica", fontSize=9, textColor=TEXT_MAIN, leading=13)
comp_bold = ParagraphStyle("CompB", fontName="Helvetica-Bold", fontSize=9, textColor=TEXT_MAIN, leading=13)

comp_rows = [
    ["Feature", "DKA", "HHS"],
    ["Typical patient", "T1DM; any age", "Elderly T2DM"],
    ["Onset", "Hours to days", "Days to weeks"],
    ["Insulin deficiency", "Absolute", "Relative"],
    ["Glucose", ">250 mg/dL", ">600 mg/dL"],
    ["Osmolality", "Mildly elevated", "Markedly elevated (>320)"],
    ["Ketones", "+++ (prominent)", "Absent / trace"],
    ["pH", "<7.3", ">7.3"],
    ["HCO₃⁻", "<18 mmol/L", ">15–20 mmol/L"],
    ["Anion gap", "Elevated", "Normal (unless concurrent lactic acidosis)"],
    ["Kussmaul breathing", "Present", "Absent"],
    ["Mental status changes", "Less prominent", "More prominent"],
    ["Fluid deficit", "3–6 L", "9–12 L"],
    ["Treatment priority", "Insulin + fluids", "Fluids FIRST; insulin secondary"],
    ["Cerebral edema risk", "~1% (children > adults)", "Rare; risk from too-rapid correction"],
    ["Mortality", "~4%", "~15–20%"],
]

comp_data = [[Paragraph(comp_rows[0][i], comp_hdr_style) for i in range(3)]]
for r in comp_rows[1:]:
    comp_data.append([Paragraph(r[i], comp_bold if i == 0 else comp_cell) for i in range(3)])

comp_tbl = Table(comp_data, colWidths=[W*0.35, W*0.325, W*0.325], repeatRows=1)
comp_style_ts = [
    ("BACKGROUND",   (0,0), (-1,0), colors.HexColor("#2c2c2c")),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [colors.white, NEUTRAL]),
    ("GRID",         (0,0), (-1,-1), 0.4, BORDER),
    ("LEFTPADDING",  (0,0), (-1,-1), 7),
    ("RIGHTPADDING", (0,0), (-1,-1), 7),
    ("TOPPADDING",   (0,0), (-1,-1), 5),
    ("BOTTOMPADDING",(0,0), (-1,-1), 5),
    ("VALIGN",       (0,0), (-1,-1), "MIDDLE"),
    # Highlight mortality row
    ("BACKGROUND", (1, len(comp_rows)-1), (1, len(comp_rows)-1), colors.HexColor("#ddeeff")),
    ("BACKGROUND", (2, len(comp_rows)-1), (2, len(comp_rows)-1), colors.HexColor("#fde8d8")),
]
comp_tbl.setStyle(TableStyle(comp_style_ts))
story.append(comp_tbl)

story.append(Spacer(1, 0.5*cm))
story.append(Paragraph(
    "Note: Mixed DKA + HHS can occur in T2DM with severely depressed insulin secretion — "
    "mild acidosis with markedly elevated glucose and osmolality.",
    NOTE))

story.append(Spacer(1, 0.5*cm))
story.append(hr(BORDER))
story.append(Paragraph(
    "Sources: Harrison's Principles of Internal Medicine 22e (2025, McGraw-Hill) · Goldman-Cecil Medicine, International Edition · "
    "Rosen's Emergency Medicine, 10e · Washington Manual of Medical Therapeutics · "
    "Comprehensive Clinical Nephrology 7e · Tintinalli's Emergency Medicine",
    SOURCE))

# ── Build PDF ─────────────────────────────────────────────────────────────────
doc.build(story)
print(f"PDF written to {OUTPUT}")
Your credits are exhausted. You can purchase a top-up or subscribe to a plan to continue using Orris. If you're already subscribed, your daily credits will reset tomorrow.

How to subscribe?

Your credits are exhausted. You can purchase a top-up or subscribe to a plan to continue using Orris. If you're already subscribed, your daily credits will reset tomorrow.

Visit orris.ai/subscribe for pricing plans

Your credits are exhausted. You can purchase a top-up or subscribe to a plan to continue using Orris. If you're already subscribed, your daily credits will reset tomorrow.

PDF

I'll generate that PDF now — the script is already written from our last session, I just need to run it.
Running Command

python /home/daytona/workspace/dka-hhs/generate_pdf.py

There's a stray ParagraphStyle object being appended to the story instead of a Paragraph. Let me fix it.
Searching Content

"story.append(NOTE" in ~/dka-hhs

Editing File

~/dka-hhs/generate_pdf.py

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/dka-hhs/generate_pdf.py'
Now I need to check what that Paragraph( looked like after the NOTE line to make sure the fix is coherent.
Searching Content

"story.append(Paragraph(" in ~/dka-hhs

Let me look at the specific area around line 474 to confirm the fix looks right.
Reading File
Good — the fix looks clean. Now run it.
Running Command

python /home/daytona/workspace/dka-hhs/generate_pdf.py

Your PDF is ready:

DKA HHS Notes

PDF Document · PDF

The document contains:
  • Cover page with title and source credits
  • Section 1 — DKA: Definition + severity grading, pathophysiology, precipitants, clinical features, diagnosis/labs, full treatment protocol (fluids, insulin, K⁺, Mg²⁺, PO₄, bicarbonate, transition), special populations (pediatric, SGLT2i), complications, prognosis
  • Section 2 — HHS: Definition, epidemiology, pathophysiology, precipitants, clinical features (with DKA contrast), diagnosis, treatment (fluids-first protocol), complications, differentials
  • Final page: DKA vs HHS side-by-side comparison table with all key parameters
This is a shared conversation. Sign in to Orris to start your own chat.