Notes on DKA
"diabetic ketoacidosis" management
Insulin deficiency
↓
┌──────────────────────────────────┐
│ LIVER │
│ ↑ Gluconeogenesis │
│ ↑ Glycogenolysis │
│ ↑ Ketogenesis (β-OHB, AcAc) │
└──────────────────────────────────┘
↓
┌──────────────────────────────────┐
│ ADIPOSE TISSUE │
│ ↑ Hormone-sensitive lipase │
│ ↑ Free fatty acids → liver │
└──────────────────────────────────┘
↓
┌──────────────────────────────────┐
│ MUSCLE │
│ ↑ Proteolysis │
│ ↑ Amino acids → liver │
└──────────────────────────────────┘
| Parameter | Mild | Moderate | Severe |
|---|---|---|---|
| Glucose (mg/dL) | >250 | >250 | >250 |
| pH (arterial) | 7.25-7.30 | 7.00-7.24 | <7.00 |
| HCO₃⁻ (mmol/L) | 15-18 | 10-14 | <10 |
| Anion gap | >10 | >12 | >12 |
| Urine/serum ketones | Positive | Positive | Positive |
| Mental status | Alert | Alert/drowsy | Stupor/coma |
| Feature | DKA | HHS |
|---|---|---|
| Glucose (mg/dL) | >350 | >700 |
| Sodium (mEq/L) | Low 130s | 140s |
| Potassium (mEq/L) | ~4.5-6.0 | ~5 |
| Bicarbonate (mEq/L) | <10 | >15 |
| Ketones | +++ | Absent/minimal |
| pH | <7.3 | Usually >7.3 |
| Osmolality | Mildly elevated | Markedly elevated |
Now need a note on HHS
"hyperosmolar hyperglycemic state" management
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⁺
| Category | Examples |
|---|---|
| Infection (most common) | Gram-negative pneumonia, gram-negative sepsis, UTI |
| Cardiovascular | Acute MI, stroke |
| Dehydration | Inadequate fluid access, physical infirmity, dementia |
| Medications non-compliance | Missed hypoglycemic agents |
| Dietary | Dietary indiscretion |
| Drugs | Corticosteroids, thiazides, alcohol, cocaine |
| Other illness | Acute pancreatitis, GI bleeding, mesenteric thrombosis, burns, dialysis |
| Iatrogenic | Parenteral hyperalimentation, peritoneal dialysis, hemodialysis |
| 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 |
| Feature | DKA | HHS |
|---|---|---|
| Typical patient | T1DM, any age | Elderly T2DM |
| Onset | Hours to days | Days to weeks |
| Glucose | >250 mg/dL | >600 mg/dL |
| Osmolality | Mildly elevated | Markedly elevated (>320) |
| Ketones | ++ to +++ | Absent/trace |
| pH | <7.3 | >7.3 |
| HCO₃⁻ | <18 mmol/L | >18-20 mmol/L |
| Kussmaul breathing | Present | Absent |
| Anion gap | Elevated | Normal (unless concurrent lactic acidosis) |
| Fluid deficit | 3-6 L | 9-12 L (more severe) |
| Mental status changes | Less prominent | More prominent |
| Mortality | ~4% | Up to 15-20% |
| DKA | HHS | |
|---|---|---|
| Insulin deficiency | Absolute | Relative |
| Ketosis | Major feature | Absent/minimal |
| Acidosis | Central feature | Absent unless concurrent |
| Fluid deficit | 3-6 L | 9-12 L |
| Mental status | Less impaired | More impaired |
| Onset | Hours-days | Days-weeks |
| Priority in treatment | Insulin + fluids | Fluids first, insulin secondary |
| Cerebral edema risk | ~1% (children > adults) | Rare; overly rapid correction is the risk |
| Mortality | ~4% | ~15-20% |
ls /home/daytona/workspace/
mkdir -p /home/daytona/workspace/dka-hhs
~/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 & HHS", COVER_TITLE),
], [
Paragraph("Diabetic Ketoacidosis & 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}")
How to subscribe?
Visit orris.ai/subscribe for pricing plans
python /home/daytona/workspace/dka-hhs/generate_pdf.py
ParagraphStyle object being appended to the story instead of a Paragraph. Let me fix it."story.append(NOTE" in ~/dka-hhs
~/dka-hhs/generate_pdf.py
Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/dka-hhs/generate_pdf.py'
Paragraph( looked like after the NOTE line to make sure the fix is coherent."story.append(Paragraph(" in ~/dka-hhs
python /home/daytona/workspace/dka-hhs/generate_pdf.py
DKA HHS Notes
PDF Document · PDF