Ppt with proper flow chart and diagram on pneumonia with advanced management and recovery...for a medicine resident doctor

Reading File
Reading File
Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Running Command

ls /home/daytona/workspace/ 2>/dev/null && echo "exists" || echo "empty"

Running Command

mkdir -p /home/daytona/workspace/pneumonia-ppt && echo "created"

Writing File

~/pneumonia-ppt/build_pneumonia.js

const pptxgen = require("pptxgenjs");
const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Pneumonia: Advanced Management & Recovery";
pres.author = "Medicine Resident Reference";

// ===================== COLOR PALETTE =====================
const C = {
  navy:    "0D2B55",  // dominant dark
  teal:    "1A7FA0",  // supporting blue-teal
  orange:  "E87722",  // accent / warning
  green:   "2E7D32",  // improvement / recovery
  red:     "C0392B",  // danger / severe
  white:   "FFFFFF",
  offwhite:"F0F4F8",
  ltblue:  "D6EAF8",
  ltgreen: "D5F5E3",
  ltyellow:"FEF9E7",
  ltred:   "FADBD8",
  gray:    "5D6D7E",
  lgray:   "BDC3C7",
  charcoal:"1C2833",
};

const FONT = "Calibri";

// Helper: slide title band
function addTitleBand(slide, title, subtitle) {
  // dark header band
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 0.85, fill: { color: C.navy } });
  slide.addText(title, {
    x: 0.25, y: 0.05, w: 9.5, h: 0.75,
    fontSize: 22, bold: true, color: C.white, fontFace: FONT, valign: "middle",
  });
  if (subtitle) {
    slide.addShape(pres.ShapeType.rect, { x: 0, y: 0.85, w: 10, h: 0.3, fill: { color: C.teal } });
    slide.addText(subtitle, {
      x: 0.25, y: 0.87, w: 9.5, h: 0.26,
      fontSize: 11, color: C.white, fontFace: FONT, italic: true, valign: "middle",
    });
  }
}

// Helper: section accent bar on left
function addAccentBar(slide, color) {
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 0.12, h: 5.625, fill: { color: color || C.teal } });
}

// Helper: small category badge
function badge(slide, text, x, y, w, color, textColor) {
  slide.addShape(pres.ShapeType.roundRect, { x, y, w, h: 0.32, fill: { color }, line: { color } });
  slide.addText(text, { x, y, w, h: 0.32, fontSize: 9, bold: true, color: textColor || C.white, fontFace: FONT, align: "center", valign: "middle" });
}

// Helper: arrow right shape
function arrowBox(slide, text, x, y, w, h, fillColor, textColor, fontSize) {
  slide.addShape(pres.ShapeType.chevron, {
    x, y, w, h,
    fill: { color: fillColor || C.teal },
    line: { color: C.navy, width: 0.5 },
  });
  slide.addText(text, {
    x: x + 0.05, y, w: w - 0.1, h,
    fontSize: fontSize || 9, bold: true, color: textColor || C.white, fontFace: FONT,
    align: "center", valign: "middle", wrap: true,
  });
}

function roundBox(slide, text, x, y, w, h, fillColor, textColor, fontSize, bold) {
  slide.addShape(pres.ShapeType.roundRect, {
    x, y, w, h,
    fill: { color: fillColor || C.ltblue },
    line: { color: C.teal, width: 1 },
  });
  slide.addText(text, {
    x, y, w, h,
    fontSize: fontSize || 9, bold: bold !== false, color: textColor || C.navy, fontFace: FONT,
    align: "center", valign: "middle", wrap: true,
  });
}

function diamondBox(slide, text, x, y, w, h, fillColor, textColor) {
  slide.addShape(pres.ShapeType.diamond, {
    x, y, w, h,
    fill: { color: fillColor || C.ltyellow },
    line: { color: C.orange, width: 1.5 },
  });
  slide.addText(text, {
    x, y, w, h,
    fontSize: 8.5, bold: true, color: textColor || C.charcoal, fontFace: FONT,
    align: "center", valign: "middle", wrap: true,
  });
}

function connector(slide, x1, y1, x2, y2) {
  slide.addShape(pres.ShapeType.line, {
    x: x1, y: y1, w: x2 - x1, h: y2 - y1,
    line: { color: C.gray, width: 1, dashType: "solid",
      endArrowType: "arrow" },
  });
}

// =========================================================
// SLIDE 1 — TITLE
// =========================================================
{
  const s = pres.addSlide();
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.navy } });
  // teal diagonal accent
  s.addShape(pres.ShapeType.rect, { x: 0, y: 3.6, w: 10, h: 0.15, fill: { color: C.orange } });
  s.addShape(pres.ShapeType.rect, { x: 0, y: 3.75, w: 10, h: 1.875, fill: { color: C.teal } });

  s.addText("PNEUMONIA", {
    x: 0.5, y: 0.6, w: 9, h: 1.0,
    fontSize: 48, bold: true, color: C.white, fontFace: FONT, align: "center",
    charSpacing: 8,
  });
  s.addText("Advanced Management & Recovery", {
    x: 0.5, y: 1.7, w: 9, h: 0.7,
    fontSize: 26, bold: false, color: C.orange, fontFace: FONT, align: "center", italic: true,
  });
  s.addText("A Clinical Reference for Medicine Residents", {
    x: 0.5, y: 2.5, w: 9, h: 0.5,
    fontSize: 14, color: C.lgray, fontFace: FONT, align: "center",
  });
  s.addText([
    { text: "Sources: ", options: { bold: true } },
    { text: "Goldman-Cecil Medicine | Murray & Nadel's Respiratory Medicine | Fishman's Pulmonary Diseases | IDSA/ATS Guidelines" },
  ], {
    x: 0.5, y: 4.0, w: 9, h: 0.5,
    fontSize: 9.5, color: C.white, fontFace: FONT, align: "center",
  });
}

// =========================================================
// SLIDE 2 — TABLE OF CONTENTS
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.navy);
  addTitleBand(s, "Contents Overview", "Flow: Epidemiology → Pathophysiology → Diagnosis → Severity → Management → Recovery");

  const topics = [
    ["1", "Epidemiology & Classification", C.teal],
    ["2", "Pathophysiology & Pathogen Profile", C.teal],
    ["3", "Clinical Presentation & Diagnosis", C.navy],
    ["4", "Severity Assessment: CURB-65 & PSI Flowchart", C.navy],
    ["5", "Radiological & Lab Workup Algorithm", C.navy],
    ["6", "Empiric Antibiotic Management: CAP / HAP / VAP", C.orange],
    ["7", "ICU-Level & Refractory Pneumonia", C.red],
    ["8", "Complications & Differential Diagnosis", C.red],
    ["9", "De-escalation, Discharge & Recovery Protocol", C.green],
    ["10", "Special Populations & Emerging Therapies", C.green],
  ];

  topics.forEach(([num, title, color], i) => {
    const col = i < 5 ? 0 : 1;
    const row = i < 5 ? i : i - 5;
    const x = col === 0 ? 0.25 : 5.2;
    const y = 1.3 + row * 0.78;
    s.addShape(pres.ShapeType.roundRect, { x, y, w: 4.7, h: 0.6, fill: { color: C.offwhite }, line: { color: color, width: 1.5 } });
    s.addShape(pres.ShapeType.ellipse, { x: x + 0.05, y: y + 0.1, w: 0.4, h: 0.4, fill: { color: color } });
    s.addText(num, { x: x + 0.05, y: y + 0.1, w: 0.4, h: 0.4, fontSize: 10, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(title, { x: x + 0.55, y, w: 4.1, h: 0.6, fontSize: 11, color: C.charcoal, fontFace: FONT, valign: "middle", bold: false });
  });
}

// =========================================================
// SLIDE 3 — EPIDEMIOLOGY & CLASSIFICATION
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.teal);
  addTitleBand(s, "Epidemiology & Classification", "Pneumonia: one of the leading causes of infection-related mortality worldwide");

  // Stats row
  const stats = [
    ["~450M", "Global CAP cases/yr"],
    ["5–15%", "Require ICU admission"],
    ["5–10%", "Overall mortality (CAP)"],
    [">30%", "ICU mortality (severe CAP)"],
    ["#1", "Infectious cause of death"],
  ];
  stats.forEach(([val, lbl], i) => {
    const x = 0.25 + i * 1.92;
    s.addShape(pres.ShapeType.roundRect, { x, y: 1.15, w: 1.75, h: 0.95, fill: { color: C.navy }, line: { color: C.teal, width: 1 } });
    s.addText(val, { x, y: 1.15, w: 1.75, h: 0.55, fontSize: 18, bold: true, color: C.orange, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(lbl, { x, y: 1.65, w: 1.75, h: 0.42, fontSize: 8, color: C.white, fontFace: FONT, align: "center", valign: "middle", wrap: true });
  });

  // Classification table
  s.addText("Classification by Setting", {
    x: 0.2, y: 2.2, w: 9.5, h: 0.35,
    fontSize: 13, bold: true, color: C.navy, fontFace: FONT,
  });

  const cols = ["Type", "Abbreviation", "Definition / Setting", "Key Pathogens"];
  const rows = [
    ["Community-Acquired", "CAP", "Acquired outside hospital / <48h of admission", "S. pneumoniae, H. influenzae, Atypicals, Viruses"],
    ["Hospital-Acquired", "HAP", "≥48h after admission, not intubated", "MRSA, P. aeruginosa, Gram-neg enteric bacilli"],
    ["Ventilator-Associated", "VAP", "≥48–72h after intubation", "MDR Gram-neg, MRSA, Acinetobacter"],
    ["Healthcare-Associated", "HCAP", "Nursing home, dialysis, prior hospitalization (older concept – now subsumed into HAP/CAP)", "Mixed – MDR risk factors apply"],
    ["Aspiration", "—", "Witnessed aspiration / altered consciousness", "Anaerobes, mixed oral flora, S. aureus"],
  ];

  const cw = [1.6, 0.9, 3.6, 3.5];
  const cx = [0.2, 1.85, 2.8, 6.45];

  // header
  cols.forEach((c, i) => {
    s.addShape(pres.ShapeType.rect, { x: cx[i], y: 2.6, w: cw[i], h: 0.38, fill: { color: C.navy } });
    s.addText(c, { x: cx[i], y: 2.6, w: cw[i], h: 0.38, fontSize: 9.5, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });
  });
  rows.forEach((row, ri) => {
    const bg = ri % 2 === 0 ? C.offwhite : C.ltblue;
    row.forEach((cell, ci) => {
      s.addShape(pres.ShapeType.rect, { x: cx[ci], y: 3.0 + ri * 0.45, w: cw[ci], h: 0.45, fill: { color: bg }, line: { color: C.lgray, width: 0.3 } });
      s.addText(cell, { x: cx[ci] + 0.04, y: 3.0 + ri * 0.45, w: cw[ci] - 0.08, h: 0.45, fontSize: 7.5, color: C.charcoal, fontFace: FONT, valign: "middle", wrap: true });
    });
  });
}

// =========================================================
// SLIDE 4 — PATHOPHYSIOLOGY DIAGRAM
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.teal);
  addTitleBand(s, "Pathophysiology of Pneumonia", "Invasion → Innate Response → Exudate → Consolidation → Resolution or Complications");

  // Central lung icon representation
  s.addShape(pres.ShapeType.ellipse, { x: 4.15, y: 2.1, w: 1.7, h: 1.8, fill: { color: C.ltblue }, line: { color: C.teal, width: 2 } });
  s.addText("LUNG\nParenchyma", { x: 4.15, y: 2.1, w: 1.7, h: 1.8, fontSize: 10, bold: true, color: C.navy, fontFace: FONT, align: "center", valign: "middle" });

  // Pathogen entry boxes around lung
  const pathways = [
    { text: "Microaspiration\n(most common)\nOropharyngeal colonization", x: 0.18, y: 1.1, color: C.orange },
    { text: "Macroaspiration\nAltered consciousness\nGERD / dysphagia", x: 0.18, y: 2.5, color: C.orange },
    { text: "Inhalation\nAirborne droplets\n(Legionella, TB, Viruses)", x: 0.18, y: 3.8, color: C.teal },
    { text: "Hematogenous\nSeeding from bacteremia\n(S. aureus endocarditis)", x: 7.5, y: 1.1, color: C.red },
    { text: "Direct spread\nPost-op / trauma\nContiguous focus", x: 7.5, y: 3.8, color: C.navy },
  ];

  pathways.forEach(p => {
    roundBox(s, p.text, p.x, p.y, 1.9, 0.95, p.color, C.white, 7.5);
  });

  // Arrows pointing to lung
  s.addShape(pres.ShapeType.line, { x: 2.1, y: 1.55, w: 2.05, h: 0.9, line: { color: C.orange, width: 1.5, endArrowType: "arrow" } });
  s.addShape(pres.ShapeType.line, { x: 2.1, y: 2.97, w: 2.05, h: 0.1, line: { color: C.orange, width: 1.5, endArrowType: "arrow" } });
  s.addShape(pres.ShapeType.line, { x: 2.1, y: 4.27, w: 2.05, h: -0.9, line: { color: C.teal, width: 1.5, endArrowType: "arrow" } });
  s.addShape(pres.ShapeType.line, { x: 7.5, y: 1.55, w: -1.65, h: 0.9, line: { color: C.red, width: 1.5, endArrowType: "arrow" } });
  s.addShape(pres.ShapeType.line, { x: 7.5, y: 4.27, w: -1.65, h: -0.9, line: { color: C.navy, width: 1.5, endArrowType: "arrow" } });

  // Inflammatory cascade below lung
  const cascade = [
    { t: "Pathogen\nRecognition\n(TLRs/PRRs)", c: C.ltblue },
    { t: "Cytokine\nRelease\n(IL-6, TNF-α)", c: C.ltyellow },
    { t: "Neutrophil\nRecruitment", c: C.orange },
    { t: "Alveolar\nExudate &\nConsolidation", c: C.red },
  ];
  cascade.forEach((item, i) => {
    const x = 1.0 + i * 2.0;
    roundBox(s, item.t, x, 4.7, 1.6, 0.72, item.c, C.charcoal, 7.5);
    if (i < cascade.length - 1) {
      s.addShape(pres.ShapeType.line, {
        x: x + 1.6, y: 5.06, w: 0.4, h: 0,
        line: { color: C.gray, width: 1.2, endArrowType: "arrow" },
      });
    }
  });
}

// =========================================================
// SLIDE 5 — CLINICAL PRESENTATION
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.navy);
  addTitleBand(s, "Clinical Presentation & Diagnosis", "Classic triad + ancillary features; atypical presentations in elderly / immunocompromised");

  // Two columns
  // Col 1 — Symptoms
  s.addShape(pres.ShapeType.roundRect, { x: 0.2, y: 1.1, w: 4.5, h: 0.38, fill: { color: C.navy }, line: { color: C.navy } });
  s.addText("SYMPTOMS", { x: 0.2, y: 1.1, w: 4.5, h: 0.38, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });

  const sx = [
    ["Fever / chills", "≥38°C; rigors common in S. pneumoniae"],
    ["Cough", "Productive (purulent/rusty) or dry (atypical)"],
    ["Dyspnea", "Proportional to extent of consolidation"],
    ["Pleuritic chest pain", "Suggests pleural involvement"],
    ["Hemoptysis", "Blood-streaked – S. pyogenes, Klebsiella"],
    ["Myalgia / malaise", "Prominent in Mycoplasma, viral pneumonia"],
    ["Diarrhea / headache", "Legionella – extrapulmonary features"],
  ];
  sx.forEach(([sym, detail], i) => {
    const y = 1.55 + i * 0.52;
    s.addShape(pres.ShapeType.rect, { x: 0.2, y, w: 4.5, h: 0.5, fill: { color: i % 2 === 0 ? C.offwhite : C.ltblue }, line: { color: C.lgray, width: 0.3 } });
    s.addText([
      { text: sym + "  ", options: { bold: true, color: C.navy } },
      { text: detail, options: { bold: false, color: C.gray } },
    ], { x: 0.25, y, w: 4.4, h: 0.5, fontSize: 9, fontFace: FONT, valign: "middle", wrap: true });
  });

  // Col 2 — Exam & Diagnosis
  s.addShape(pres.ShapeType.roundRect, { x: 5.0, y: 1.1, w: 4.7, h: 0.38, fill: { color: C.teal }, line: { color: C.teal } });
  s.addText("PHYSICAL EXAM & DIAGNOSIS", { x: 5.0, y: 1.1, w: 4.7, h: 0.38, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });

  const pe = [
    ["Dullness to percussion", "Lobar consolidation / effusion"],
    ["Bronchial breath sounds", "Over consolidated lobe"],
    ["Egophony (E→A)", "Consolidation sign"],
    ["Crackles / crepitations", "Exudate-filled alveoli"],
    ["Reduced air entry", "Effusion, collapse"],
    ["Tachypnea (>30/min)", "Key severity marker"],
    ["Tachycardia / hypotension", "Sepsis / septic shock"],
  ];
  pe.forEach(([sign, detail], i) => {
    const y = 1.55 + i * 0.52;
    s.addShape(pres.ShapeType.rect, { x: 5.0, y, w: 4.7, h: 0.5, fill: { color: i % 2 === 0 ? C.offwhite : C.ltblue }, line: { color: C.lgray, width: 0.3 } });
    s.addText([
      { text: sign + "  ", options: { bold: true, color: C.navy } },
      { text: detail, options: { bold: false, color: C.gray } },
    ], { x: 5.05, y, w: 4.6, h: 0.5, fontSize: 9, fontFace: FONT, valign: "middle", wrap: true });
  });

  // Diagnostic criteria footnote
  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 5.15, w: 9.5, h: 0.32, fill: { color: C.ltyellow }, line: { color: C.orange, width: 0.5 } });
  s.addText("Diagnostic confirmation: New infiltrate on CXR/CT + ≥2 of: fever/hypothermia, leukocytosis/penia, purulent sputum, hypoxia", {
    x: 0.2, y: 5.15, w: 9.5, h: 0.32, fontSize: 8.5, color: C.charcoal, fontFace: FONT, align: "center", valign: "middle", italic: true,
  });
}

// =========================================================
// SLIDE 6 — SEVERITY ASSESSMENT FLOWCHART
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.orange);
  addTitleBand(s, "Severity Assessment: CURB-65 & PSI Flowchart", "Use CURB-65 for rapid bedside triage; PSI for in-depth risk stratification");

  // CURB-65 Criteria boxes
  const criteria = [
    { letter: "C", full: "Confusion", sub: "new onset AMT ≤8", x: 0.22 },
    { letter: "U", full: "Urea", sub: ">7 mmol/L\n(BUN >19 mg/dL)", x: 2.12 },
    { letter: "R", full: "Resp Rate", sub: "≥30 breaths/min", x: 4.02 },
    { letter: "B", full: "BP", sub: "Systolic <90\nor Diastolic ≤60", x: 5.92 },
    { letter: "65", full: "Age", sub: "≥65 years", x: 7.82 },
  ];

  criteria.forEach(cr => {
    s.addShape(pres.ShapeType.roundRect, { x: cr.x, y: 0.95, w: 1.75, h: 1.05, fill: { color: C.navy }, line: { color: C.teal, width: 1.5 } });
    s.addText(cr.letter, { x: cr.x, y: 0.95, w: 1.75, h: 0.45, fontSize: 20, bold: true, color: C.orange, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(cr.full, { x: cr.x, y: 1.38, w: 1.75, h: 0.28, fontSize: 9.5, bold: true, color: C.white, fontFace: FONT, align: "center" });
    s.addText(cr.sub, { x: cr.x, y: 1.66, w: 1.75, h: 0.34, fontSize: 7.5, color: C.lgray, fontFace: FONT, align: "center", wrap: true });
  });

  // Score triage
  s.addText("Score → Triage Decision", { x: 0.22, y: 2.08, w: 9.5, h: 0.3, fontSize: 11, bold: true, color: C.navy, fontFace: FONT });

  const triage = [
    { score: "0–1", label: "Low Risk", action: "Outpatient treatment\nOral antibiotics", color: C.green },
    { score: "2", label: "Moderate Risk", action: "Consider hospital admission\nClose follow-up", color: C.orange },
    { score: "3–5", label: "High Risk", action: "Hospital admission\nConsider ICU if ≥4", color: C.red },
  ];

  triage.forEach((t, i) => {
    const x = 0.22 + i * 3.26;
    s.addShape(pres.ShapeType.roundRect, { x, y: 2.42, w: 3.0, h: 1.0, fill: { color: t.color }, line: { color: C.charcoal, width: 1 } });
    s.addText(t.score, { x, y: 2.42, w: 1.0, h: 1.0, fontSize: 22, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(t.label, { x: x + 1.0, y: 2.42, w: 2.0, h: 0.45, fontSize: 10, bold: true, color: C.white, fontFace: FONT, valign: "middle" });
    s.addText(t.action, { x: x + 1.0, y: 2.87, w: 2.0, h: 0.55, fontSize: 8, color: C.white, fontFace: FONT, valign: "top", wrap: true });
  });

  // ATS/IDSA Severe CAP Criteria
  s.addShape(pres.ShapeType.rect, { x: 0.22, y: 3.52, w: 9.5, h: 0.32, fill: { color: C.navy } });
  s.addText("IDSA/ATS Criteria for SEVERE CAP (requires ICU)", {
    x: 0.22, y: 3.52, w: 9.5, h: 0.32, fontSize: 11, bold: true, color: C.orange, fontFace: FONT, align: "center", valign: "middle",
  });

  // Minor / Major criteria side by side
  const minor = ["RR ≥30/min", "PaO₂/FiO₂ <250", "Multilobar infiltrates", "Confusion/disorientation", "BUN ≥20 mg/dL", "WBC <4000/mm³", "Platelets <100k/mm³", "Temp <36°C", "Hypotension needing IV fluids"];
  const major = ["Invasive mechanical ventilation", "Septic shock (vasopressors required)"];

  s.addShape(pres.ShapeType.roundRect, { x: 0.22, y: 3.88, w: 4.5, h: 1.55, fill: { color: C.ltyellow }, line: { color: C.orange, width: 1 } });
  s.addText("MINOR CRITERIA (≥3 = severe CAP)", { x: 0.25, y: 3.88, w: 4.44, h: 0.3, fontSize: 9, bold: true, color: C.orange, fontFace: FONT, align: "center", valign: "middle" });
  minor.forEach((m, i) => {
    s.addText("• " + m, { x: 0.3, y: 4.18 + i * 0.135, w: 4.3, h: 0.14, fontSize: 7.5, color: C.charcoal, fontFace: FONT });
  });

  s.addShape(pres.ShapeType.roundRect, { x: 5.15, y: 3.88, w: 4.57, h: 1.55, fill: { color: C.ltred }, line: { color: C.red, width: 1.5 } });
  s.addText("MAJOR CRITERIA (1 = direct ICU admission)", { x: 5.18, y: 3.88, w: 4.5, h: 0.3, fontSize: 9, bold: true, color: C.red, fontFace: FONT, align: "center", valign: "middle" });
  major.forEach((m, i) => {
    s.addShape(pres.ShapeType.roundRect, { x: 5.25, y: 4.28 + i * 0.55, w: 4.35, h: 0.48, fill: { color: C.red }, line: { color: C.red } });
    s.addText(m, { x: 5.25, y: 4.28 + i * 0.55, w: 4.35, h: 0.48, fontSize: 10, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });
  });
}

// =========================================================
// SLIDE 7 — DIAGNOSTIC WORKUP ALGORITHM
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.teal);
  addTitleBand(s, "Diagnostic Workup Algorithm", "Systematic approach: rapid initial assessment → targeted microbiological workup");

  // Flowchart: top to bottom
  roundBox(s, "Patient Presents\nwith Respiratory Symptoms", 3.5, 0.95, 3.0, 0.65, C.navy, C.white, 9);
  s.addShape(pres.ShapeType.line, { x: 5.0, y: 1.6, w: 0, h: 0.35, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });

  roundBox(s, "Chest X-Ray\n(CXR — first line)", 3.5, 1.95, 3.0, 0.6, C.teal, C.white, 9);
  s.addShape(pres.ShapeType.line, { x: 5.0, y: 2.55, w: 0, h: 0.3, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });

  diamondBox(s, "Infiltrate\nconfirmed?", 3.8, 2.85, 2.4, 0.7, C.ltyellow, C.charcoal);

  // Yes branch (down)
  s.addShape(pres.ShapeType.line, { x: 5.0, y: 3.55, w: 0, h: 0.25, line: { color: C.green, width: 1.5, endArrowType: "arrow" } });
  s.addText("YES", { x: 5.05, y: 3.55, w: 0.5, h: 0.22, fontSize: 8, bold: true, color: C.green, fontFace: FONT });

  // No branch (right)
  s.addShape(pres.ShapeType.line, { x: 6.2, y: 3.2, w: 1.5, h: 0, line: { color: C.red, width: 1.5, endArrowType: "arrow" } });
  s.addText("NO", { x: 6.25, y: 3.02, w: 0.4, h: 0.2, fontSize: 8, bold: true, color: C.red, fontFace: FONT });
  roundBox(s, "Consider CT Chest\nor alternate Dx\n(PE, cardiac, etc.)", 7.7, 2.95, 2.05, 0.7, C.ltred, C.charcoal, 7.5);

  // Labs panel
  const labs = [
    { t: "BLOODS", items: "CBC, CMP, LFT\nLDH, CRP, Procalcitonin\nABG / SpO₂\nBlood cultures ×2\nHIV if indicated", c: C.ltblue },
    { t: "MICRO", items: "Sputum G/S & Culture\n(adequate: >25 WBC, <10 epi)\nLegionella urinary Ag\nPneumococcal urinary Ag\nRespiratory viral PCR panel\nBAL if intubated / immunocomp.", c: C.ltgreen },
    { t: "IMAGING", items: "CXR (PA + Lateral)\nCT Chest (if CXR unclear,\nempyema, lung abscess,\nor poor response at 72h)\nUS chest for effusion", c: C.ltyellow },
  ];
  labs.forEach((lab, i) => {
    const x = 0.22 + i * 3.25;
    s.addShape(pres.ShapeType.roundRect, { x, y: 3.8, w: 3.05, h: 1.65, fill: { color: lab.c }, line: { color: C.teal, width: 1 } });
    s.addText(lab.t, { x, y: 3.8, w: 3.05, h: 0.32, fontSize: 10, bold: true, color: C.navy, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(lab.items, { x: x + 0.08, y: 4.12, w: 2.9, h: 1.3, fontSize: 8, color: C.charcoal, fontFace: FONT, valign: "top", wrap: true });
  });
}

// =========================================================
// SLIDE 8 — EMPIRIC ANTIBIOTIC MANAGEMENT
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.orange);
  addTitleBand(s, "Empiric Antibiotic Management", "CAP / HAP / VAP — stratified by severity and risk factors per IDSA/ATS 2019 Guidelines");

  // CAP Non-ICU
  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 1.05, w: 9.5, h: 0.35, fill: { color: C.teal } });
  s.addText("COMMUNITY-ACQUIRED PNEUMONIA (CAP)", { x: 0.2, y: 1.05, w: 9.5, h: 0.35, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });

  const cap = [
    { setting: "Outpatient\n(Low risk / CURB 0-1)", regimen: "Amoxicillin 1g TDS × 5d\nOR Doxycycline 100mg BD × 5d\nOR Azithromycin 500mg OD × 5d (if low macrolide resistance)", color: C.ltgreen },
    { setting: "Inpatient\nNon-ICU", regimen: "β-lactam (Amox-Clav / Ceftriaxone 1g IV OD)\n+ Azithromycin 500mg OD\nOR Respiratory Fluoroquinolone monotherapy\n(Levofloxacin 750mg OD / Moxifloxacin 400mg OD)", color: C.ltyellow },
    { setting: "ICU / Severe CAP\n(no MRSA/Pseudomonas risk)", regimen: "β-lactam (Ceftriaxone 2g IV OD)\n+ Azithromycin OR Fluoroquinolone\nDuration: 5–7 days; de-escalate when afebrile ≥48h\n+ clinical stability", color: C.ltred },
  ];

  cap.forEach((item, i) => {
    const x = 0.22 + i * 3.26;
    s.addShape(pres.ShapeType.roundRect, { x, y: 1.45, w: 3.1, h: 1.3, fill: { color: item.color }, line: { color: C.teal, width: 1 } });
    s.addText(item.setting, { x, y: 1.45, w: 3.1, h: 0.42, fontSize: 8.5, bold: true, color: C.navy, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(item.regimen, { x: x + 0.06, y: 1.87, w: 2.98, h: 0.88, fontSize: 7.5, color: C.charcoal, fontFace: FONT, wrap: true, valign: "top" });
  });

  // HAP/VAP
  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 2.82, w: 9.5, h: 0.35, fill: { color: C.navy } });
  s.addText("HOSPITAL-ACQUIRED (HAP) & VENTILATOR-ASSOCIATED PNEUMONIA (VAP)", { x: 0.2, y: 2.82, w: 9.5, h: 0.35, fontSize: 11, bold: true, color: C.orange, fontFace: FONT, align: "center", valign: "middle" });

  const hap = [
    { h: "Low Risk\n(no MDR factors)", r: "Piperacillin-Tazobactam 4.5g IV q6h\nOR Ceftriaxone 2g IV OD\nOR Levofloxacin 750mg IV OD", c: C.ltyellow },
    { h: "High Risk / MDR\nPseudomonas cover", r: "Piperacillin-Tazobactam 4.5g IV q6h\nOR Cefepime 2g IV q8h\nOR Meropenem 1g IV q8h (if ESBL risk)\n+ Consider Tobramycin / Amikacin if structural lung disease", c: C.ltblue },
    { h: "MRSA Risk\n(prior MRSA, NF score ≥2)", r: "Add Vancomycin 15–20 mg/kg IV q8-12h\n(target trough 15–20 or AUC 400-600)\nOR Linezolid 600mg IV/PO BD", c: C.ltred },
  ];

  hap.forEach((item, i) => {
    const x = 0.22 + i * 3.26;
    s.addShape(pres.ShapeType.roundRect, { x, y: 3.22, w: 3.1, h: 1.5, fill: { color: item.c }, line: { color: C.navy, width: 1 } });
    s.addText(item.h, { x, y: 3.22, w: 3.1, h: 0.42, fontSize: 8.5, bold: true, color: C.navy, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(item.r, { x: x + 0.06, y: 3.64, w: 2.98, h: 1.08, fontSize: 7.5, color: C.charcoal, fontFace: FONT, wrap: true, valign: "top" });
  });

  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 4.78, w: 9.5, h: 0.7, fill: { color: C.offwhite }, line: { color: C.orange, width: 0.5 } });
  s.addText([
    { text: "Duration: ", options: { bold: true, color: C.navy } },
    { text: "HAP/VAP → 7 days (IDSA 2016); short-course non-inferior to long-course in most settings. ", options: { color: C.charcoal } },
    { text: "De-escalation: ", options: { bold: true, color: C.navy } },
    { text: "Reassess at 48–72h; guided by culture results and clinical response. Stop antipseudomonal/MRSA cover if cultures negative. PCT-guided cessation reduces antibiotic exposure.", options: { color: C.charcoal } },
  ], { x: 0.25, y: 4.78, w: 9.4, h: 0.7, fontSize: 7.5, fontFace: FONT, valign: "middle", wrap: true });
}

// =========================================================
// SLIDE 9 — ICU MANAGEMENT & REFRACTORY PNEUMONIA
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.red);
  addTitleBand(s, "ICU-Level Management & Refractory Pneumonia", "Ventilatory strategy | Adjunct therapies | Rescue approaches");

  // Ventilation strategy
  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 1.05, w: 9.5, h: 0.32, fill: { color: C.red } });
  s.addText("VENTILATORY MANAGEMENT (Lung-Protective Strategy)", { x: 0.2, y: 1.05, w: 9.5, h: 0.32, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });

  const vent = [
    { t: "Initial\nOxygen", b: "Titrate O₂: SpO₂ target\n94–98% (88–92% if COPD)\nHigh-flow nasal O₂\n(HFNC): first-line in\nhypoxaemic resp failure" },
    { t: "NIV /\nBiPAP", b: "COPD exacerbation,\ncardiogenic pulm edema\nCaution: delay intubation\nin non-responsive patients\nMonitor closely" },
    { t: "Invasive MV\n(ARDSnet)", b: "TV 6 mL/kg IBW\nPplat ≤30 cmH₂O\nFiO₂ minimization\nPEEP titration\nProne positioning ≥16h if\nP:F ratio <150" },
    { t: "Refractory\nHypoxia", b: "ECMO (VV): last resort\nfor P:F <80 unresponsive\nto conventional Rx\nConsult early if eligible\n(age <65, reversible cause)" },
  ];

  vent.forEach((v, i) => {
    const x = 0.22 + i * 2.42;
    s.addShape(pres.ShapeType.roundRect, { x, y: 1.42, w: 2.25, h: 1.6, fill: { color: C.ltblue }, line: { color: C.red, width: 1 } });
    s.addText(v.t, { x, y: 1.42, w: 2.25, h: 0.4, fontSize: 9.5, bold: true, color: C.navy, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(v.b, { x: x + 0.06, y: 1.82, w: 2.13, h: 1.2, fontSize: 7.5, color: C.charcoal, fontFace: FONT, wrap: true, valign: "top" });
  });

  // Adjunct therapies
  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 3.1, w: 9.5, h: 0.32, fill: { color: C.navy } });
  s.addText("ADJUNCT & SUPPORTIVE THERAPIES", { x: 0.2, y: 3.1, w: 9.5, h: 0.32, fontSize: 11, bold: true, color: C.orange, fontFace: FONT, align: "center", valign: "middle" });

  const adj = [
    { t: "Corticosteroids", d: "Methylprednisolone 0.5mg/kg q12h × 5d in severe CAP (RECOVERY-like evidence). Benefit in ARDS (low-moderate quality). Avoid in influenza-related pneumonia." },
    { t: "Fluid Management", d: "Conservative fluid strategy in ARDS. Maintain MAP ≥65 mmHg. Norepinephrine first-line vasopressor in septic shock." },
    { t: "DVT Prophylaxis", d: "LMWH + sequential compression devices in all ICU patients unless contraindicated." },
    { t: "Nutrition", d: "Early enteral nutrition within 24–48h of ICU admission. Avoid overfeeding. Gastric residuals not routinely monitored." },
    { t: "Stress Ulcer Ppx", d: "PPI / H₂ blocker if: MV >48h, coagulopathy, or prior GI bleed history." },
  ];

  adj.forEach((a, i) => {
    const col = i % 3;
    const row = Math.floor(i / 3);
    const x = 0.22 + col * 3.26;
    const y = 3.5 + row * 1.0;
    s.addShape(pres.ShapeType.roundRect, { x, y, w: 3.1, h: 0.92, fill: { color: C.offwhite }, line: { color: C.teal, width: 0.8 } });
    s.addText(a.t, { x, y, w: 3.1, h: 0.28, fontSize: 9, bold: true, color: C.navy, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(a.d, { x: x + 0.06, y: y + 0.28, w: 2.98, h: 0.64, fontSize: 7, color: C.charcoal, fontFace: FONT, wrap: true, valign: "top" });
  });
}

// =========================================================
// SLIDE 10 — COMPLICATIONS
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.red);
  addTitleBand(s, "Complications of Pneumonia", "Pulmonary → Extrapulmonary → Life-threatening — recognise early, intervene promptly");

  // Radial layout of complications around central box
  s.addShape(pres.ShapeType.ellipse, { x: 3.8, y: 2.0, w: 2.4, h: 1.6, fill: { color: C.navy }, line: { color: C.orange, width: 2 } });
  s.addText("PNEUMONIA\nComplications", { x: 3.8, y: 2.0, w: 2.4, h: 1.6, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });

  const comps = [
    { t: "Parapneumonic Effusion\n& Empyema", sub: "Drain if exudative / purulent\n(Light's criteria)\nChest tube / VATS", x: 0.15, y: 1.0, c: C.red },
    { t: "Lung Abscess", sub: "Usually anaerobes / MRSA\nProlonged IV antibiotics\n4–6 weeks; percutaneous drain if large", x: 0.15, y: 3.2, c: C.red },
    { t: "Respiratory Failure\n/ ARDS", sub: "P:F <300 → ALI\nP:F <200 → moderate ARDS\nP:F <100 → severe ARDS", x: 7.6, y: 1.0, c: C.orange },
    { t: "Sepsis / Septic Shock", sub: "Surviving Sepsis Campaign\nBundles: cultures, antibiotics\nwithin 1h, fluid resuscitation", x: 7.6, y: 3.2, c: C.orange },
    { t: "Meningitis / Brain Abscess", sub: "S. pneumoniae bacteremia\nAdd CSF assessment if neurological signs", x: 0.15, y: 4.5, c: C.navy },
    { t: "Endocarditis / Pericarditis", sub: "Haematogenous seeding\nEcho if persistent bacteremia", x: 7.6, y: 4.5, c: C.navy },
  ];

  comps.forEach(c => {
    s.addShape(pres.ShapeType.roundRect, { x: c.x, y: c.y, w: 2.65, h: 1.1, fill: { color: c.c }, line: { color: C.charcoal, width: 1 } });
    s.addText(c.t, { x: c.x, y: c.y, w: 2.65, h: 0.42, fontSize: 8.5, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle", wrap: true });
    s.addText(c.sub, { x: c.x + 0.05, y: c.y + 0.42, w: 2.55, h: 0.68, fontSize: 7, color: C.white, fontFace: FONT, wrap: true, valign: "top" });
  });
}

// =========================================================
// SLIDE 11 — DE-ESCALATION & DISCHARGE FLOWCHART
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.green);
  addTitleBand(s, "De-escalation, Discharge & Recovery Protocol", "Evidence-based step-down — minimise resistance, optimise outcomes");

  // Flowchart
  roundBox(s, "Inpatient on IV Antibiotics\n(≥48h)", 3.5, 0.95, 3.0, 0.6, C.navy, C.white, 9);
  s.addShape(pres.ShapeType.line, { x: 5.0, y: 1.55, w: 0, h: 0.3, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });

  diamondBox(s, "Clinical Stability\nCriteria met?", 3.8, 1.85, 2.4, 0.7, C.ltyellow, C.charcoal);

  // criteria for stability
  s.addShape(pres.ShapeType.roundRect, { x: 0.2, y: 1.75, w: 3.4, h: 0.9, fill: { color: C.ltgreen }, line: { color: C.green, width: 1 } });
  s.addText("Stability Criteria (ALL required):", { x: 0.2, y: 1.75, w: 3.4, h: 0.28, fontSize: 8.5, bold: true, color: C.green, fontFace: FONT, align: "center", valign: "middle" });
  const stability = ["T ≤37.8°C", "HR ≤100 bpm", "RR ≤24/min", "SpO₂ ≥90% on RA (or baseline)", "BP systolic ≥90 mmHg", "Tolerating oral intake"];
  stability.forEach((item, i) => {
    s.addText("✓ " + item, { x: 0.25, y: 2.03 + i * 0.1, w: 3.3, h: 0.1, fontSize: 7, color: C.charcoal, fontFace: FONT });
  });

  // YES branch
  s.addShape(pres.ShapeType.line, { x: 5.0, y: 2.55, w: 0, h: 0.3, line: { color: C.green, width: 1.5, endArrowType: "arrow" } });
  s.addText("YES", { x: 5.05, y: 2.55, w: 0.5, h: 0.2, fontSize: 8, bold: true, color: C.green, fontFace: FONT });

  roundBox(s, "Switch to Oral Antibiotics\n(Step-down therapy)", 3.5, 2.85, 3.0, 0.6, C.green, C.white, 9);
  s.addShape(pres.ShapeType.line, { x: 5.0, y: 3.45, w: 0, h: 0.3, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });

  diamondBox(s, "Meets Discharge\nCriteria?", 3.8, 3.75, 2.4, 0.7, C.ltyellow, C.charcoal);

  // No → continue
  s.addShape(pres.ShapeType.line, { x: 6.2, y: 4.1, w: 1.2, h: 0, line: { color: C.red, width: 1.5, endArrowType: "arrow" } });
  roundBox(s, "Continue hospital\nmonitoring\n& reassess q24h", 7.4, 3.78, 2.4, 0.64, C.ltred, C.charcoal, 7.5);
  s.addText("NO", { x: 6.3, y: 3.92, w: 0.4, h: 0.2, fontSize: 8, bold: true, color: C.red, fontFace: FONT });

  // YES → discharge
  s.addShape(pres.ShapeType.line, { x: 5.0, y: 4.45, w: 0, h: 0.3, line: { color: C.green, width: 1.5, endArrowType: "arrow" } });
  s.addText("YES", { x: 5.05, y: 4.45, w: 0.5, h: 0.2, fontSize: 8, bold: true, color: C.green, fontFace: FONT });

  roundBox(s, "Discharge + Follow-up\nRepeat CXR at 6–8 weeks (exclude malignancy)\nVaccination: Pneumococcal + Influenza\nSmoking cessation counselling", 2.8, 4.75, 4.4, 0.7, C.ltgreen, C.charcoal, 8);
}

// =========================================================
// SLIDE 12 — RECOVERY & PREVENTION
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.green);
  addTitleBand(s, "Recovery, Prevention & Special Populations", "Post-discharge care | Vaccination | Immunocompromised host");

  // Recovery timeline
  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 1.08, w: 9.5, h: 0.32, fill: { color: C.green } });
  s.addText("RECOVERY TIMELINE (Typical CAP)", { x: 0.2, y: 1.08, w: 9.5, h: 0.32, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });

  const timeline = [
    { t: "24–48h", d: "Fever resolution\nHaemodynamic stability", c: C.ltgreen },
    { t: "3–5 days", d: "Step-down oral Abx\nImproved dyspnea", c: C.ltblue },
    { t: "1–2 weeks", d: "Radiological improvement\nReturn to daily activity", c: C.ltyellow },
    { t: "6–8 weeks", d: "CXR clearance\nOutpatient review\nSputum cytology if >50y, smoker", c: C.orange + "33" },
    { t: "3–6 months", d: "Full recovery\n(elderly may take longer)\nPulm rehab if persisting symptoms", c: C.ltred },
  ];

  timeline.forEach((item, i) => {
    const x = 0.22 + i * 1.92;
    s.addShape(pres.ShapeType.roundRect, { x, y: 1.45, w: 1.78, h: 1.1, fill: { color: item.c }, line: { color: C.green, width: 1 } });
    s.addText(item.t, { x, y: 1.45, w: 1.78, h: 0.3, fontSize: 9, bold: true, color: C.navy, fontFace: FONT, align: "center", valign: "middle" });
    s.addText(item.d, { x: x + 0.06, y: 1.75, w: 1.66, h: 0.8, fontSize: 7.5, color: C.charcoal, fontFace: FONT, wrap: true, valign: "top" });
    if (i < timeline.length - 1) {
      s.addShape(pres.ShapeType.line, { x: x + 1.78, y: 2.0, w: 0.14, h: 0, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });
    }
  });

  // Prevention
  s.addShape(pres.ShapeType.rect, { x: 0.2, y: 2.63, w: 4.6, h: 0.32, fill: { color: C.navy } });
  s.addText("PREVENTION", { x: 0.2, y: 2.63, w: 4.6, h: 0.32, fontSize: 11, bold: true, color: C.orange, fontFace: FONT, align: "center", valign: "middle" });
  const prev = [
    "PCV15/PCV20 (pneumococcal): adults ≥65y, immunocompromised, chronic disease",
    "PPSV23 (polysaccharide): additional cover – follow CDC/WHO schedule",
    "Annual influenza vaccination: all adults, especially high-risk groups",
    "Smoking cessation: single most modifiable risk factor",
    "Aspiration precautions: HOB elevation 30–45°, oral hygiene in ventilated patients",
    "Hand hygiene & respiratory etiquette: nosocomial prevention",
  ];
  prev.forEach((p, i) => {
    s.addText("• " + p, { x: 0.25, y: 3.0 + i * 0.3, w: 4.5, h: 0.3, fontSize: 8, color: C.charcoal, fontFace: FONT, wrap: true });
  });

  // Special populations
  s.addShape(pres.ShapeType.rect, { x: 5.1, y: 2.63, w: 4.6, h: 0.32, fill: { color: C.teal } });
  s.addText("SPECIAL POPULATIONS", { x: 5.1, y: 2.63, w: 4.6, h: 0.32, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });

  const sp = [
    ["HIV/Immunocompromised", "Broader cover: include PCP (TMP-SMX), Cryptococcus, CMV, Aspergillus. CD4 <200: PCP prophylaxis"],
    ["Elderly (>65y)", "Atypical presentation: confusion/falls without fever. High aspiration risk. Longer treatment, careful fluid balance"],
    ["Pregnancy", "Avoid fluoroquinolones, tetracyclines. Azithromycin or amoxicillin safe. High-risk for preterm delivery"],
    ["Structural lung disease\n(Bronchiectasis / CF)", "Always cover Pseudomonas. Use tobramycin or cefepime. Treat underlying condition"],
    ["Viral Pneumonia (Influenza)", "Oseltamivir within 48h; bacterial co-infection common (S. aureus/MRSA). Treat empirically"],
  ];
  sp.forEach(([pop, mgmt], i) => {
    s.addShape(pres.ShapeType.roundRect, { x: 5.1, y: 3.0 + i * 0.48, w: 4.6, h: 0.46, fill: { color: i % 2 === 0 ? C.offwhite : C.ltblue }, line: { color: C.lgray, width: 0.3 } });
    s.addText([
      { text: pop + ": ", options: { bold: true, color: C.navy } },
      { text: mgmt, options: { bold: false, color: C.gray } },
    ], { x: 5.15, y: 3.0 + i * 0.48, w: 4.5, h: 0.46, fontSize: 7.5, fontFace: FONT, valign: "middle", wrap: true });
  });
}

// =========================================================
// SLIDE 13 — SUMMARY ALGORITHM (Final Flowchart)
// =========================================================
{
  const s = pres.addSlide();
  addAccentBar(s, C.navy);
  addTitleBand(s, "Master Management Algorithm", "End-to-end flowchart: Presentation → Severity → Site → Rx → De-escalation");

  // Full management flowchart in narrow columns
  const fw = 1.7; const fh = 0.5; const fx0 = 0.22; const fy0 = 0.95;

  // Row 1: Presentation
  roundBox(s, "PRESENTATION\nFever, Cough, Dyspnea", fx0, fy0, 9.5, fh, C.navy, C.white, 10);
  s.addShape(pres.ShapeType.line, { x: fx0 + 4.75, y: fy0 + fh, w: 0, h: 0.2, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });

  // Row 2: Workup
  roundBox(s, "WORKUP: CXR + Bloods + Cultures + SpO₂", fx0, fy0 + 0.7, 9.5, fh, C.teal, C.white, 10);
  s.addShape(pres.ShapeType.line, { x: fx0 + 4.75, y: fy0 + 1.2, w: 0, h: 0.2, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });

  // Row 3: Severity → branches
  diamondBox(s, "SEVERITY\nCURB-65 / IDSA-ATS", fx0 + 3.3, fy0 + 1.4, 2.9, 0.75, C.ltyellow, C.charcoal);

  // Low severity
  s.addShape(pres.ShapeType.line, { x: fx0 + 1.8, y: fy0 + 1.775, w: 1.5, h: 0, line: { color: C.green, width: 1.5, endArrowType: "arrow" } });
  s.addText("LOW", { x: fx0 + 2.3, y: fy0 + 1.6, w: 0.6, h: 0.2, fontSize: 8, bold: true, color: C.green, fontFace: FONT });
  roundBox(s, "OUTPATIENT\nOral Amox/Doxy\n5 days", fx0, fy0 + 1.525, 1.8, 0.7, C.green, C.white, 8);

  // Moderate
  s.addShape(pres.ShapeType.line, { x: fx0 + 4.75, y: fy0 + 2.15, w: 0, h: 0.25, line: { color: C.orange, width: 1.5, endArrowType: "arrow" } });
  s.addText("MOD/HIGH", { x: fx0 + 4.8, y: fy0 + 2.15, w: 0.9, h: 0.2, fontSize: 8, bold: true, color: C.orange, fontFace: FONT });

  // High ICU
  s.addShape(pres.ShapeType.line, { x: fx0 + 6.6, y: fy0 + 1.775, w: 1.0, h: 0, line: { color: C.red, width: 1.5, endArrowType: "arrow" } });
  s.addText("SEVERE", { x: fx0 + 6.65, y: fy0 + 1.6, w: 0.7, h: 0.2, fontSize: 8, bold: true, color: C.red, fontFace: FONT });
  roundBox(s, "ICU\nβ-lactam +\nMacrolide/FQ\n± Vanco/Pip-Tazo", fx0 + 7.6, fy0 + 1.525, 1.78, 0.7, C.red, C.white, 7.5);

  // Row 4: Ward
  roundBox(s, "INPATIENT WARD\nIV β-lactam + Macrolide OR FQ\nBlood cultures, procalcitonin monitoring", fx0, fy0 + 2.4, 9.5, fh, C.navy, C.white, 9);
  s.addShape(pres.ShapeType.line, { x: fx0 + 4.75, y: fy0 + 2.9, w: 0, h: 0.2, line: { color: C.gray, width: 1.5, endArrowType: "arrow" } });

  // Row 5: 48-72h reassess
  diamondBox(s, "48–72h: Clinical Response?", fx0 + 3.0, fy0 + 3.1, 3.5, 0.65, C.ltyellow, C.charcoal);

  // No response
  s.addShape(pres.ShapeType.line, { x: fx0 + 6.5, y: fy0 + 3.425, w: 1.5, h: 0, line: { color: C.red, width: 1.5, endArrowType: "arrow" } });
  s.addText("NO", { x: fx0 + 6.7, y: fy0 + 3.25, w: 0.4, h: 0.2, fontSize: 8, bold: true, color: C.red, fontFace: FONT });
  roundBox(s, "Broaden cover\nRepeat CT/cultures\nID consult\nExclude complications", fx0 + 8.0, fy0 + 3.2, 1.78, 0.65, C.ltred, C.charcoal, 7);

  // Yes response
  s.addShape(pres.ShapeType.line, { x: fx0 + 4.75, y: fy0 + 3.75, w: 0, h: 0.2, line: { color: C.green, width: 1.5, endArrowType: "arrow" } });
  s.addText("YES", { x: fx0 + 4.8, y: fy0 + 3.75, w: 0.5, h: 0.2, fontSize: 8, bold: true, color: C.green, fontFace: FONT });

  // Row 6: step-down + discharge
  roundBox(s, "STEP-DOWN → ORAL Abx → DISCHARGE → CXR F/U at 6–8 weeks → VACCINATE", fx0, fy0 + 3.95, 9.5, fh, C.green, C.white, 10);
}

// =========================================================
// SLIDE 14 — KEY TAKEAWAYS
// =========================================================
{
  const s = pres.addSlide();
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.navy } });
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0.85, w: 10, h: 0.12, fill: { color: C.orange } });

  s.addText("Key Takeaways for the Resident", {
    x: 0.5, y: 0.1, w: 9, h: 0.72,
    fontSize: 22, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle",
  });

  const pts = [
    ["1", "Classify first", "CAP vs HAP vs VAP — each has distinct pathogens, empiric regimens, and outcome predictors."],
    ["2", "Assess severity early", "CURB-65 and IDSA/ATS major criteria guide site-of-care decisions. Do not delay ICU admission."],
    ["3", "Cultures before antibiotics", "Blood cultures ×2 and sputum G/S before first antibiotic dose — but never delay antibiotics waiting for cultures."],
    ["4", "Antibiotic stewardship", "7 days for CAP/HAP/VAP in responders. PCT-guided de-escalation reduces exposure and resistance."],
    ["5", "Lung-protective ventilation", "TV 6 mL/kg IBW, Pplat ≤30 cmH₂O. Prone positioning for severe ARDS. ECMO if refractory."],
    ["6", "Reassess at 48–72h", "Non-response: repeat imaging, cultures, broadened cover, exclude complications (empyema, abscess)."],
    ["7", "Recovery is not discharge", "CXR clearance at 6–8 weeks, vaccinate (PCV + influenza), smoking cessation, pulm rehab PRN."],
  ];

  pts.forEach((p, i) => {
    const y = 1.05 + i * 0.63;
    s.addShape(pres.ShapeType.ellipse, { x: 0.3, y: y + 0.1, w: 0.42, h: 0.42, fill: { color: C.orange } });
    s.addText(p[0], { x: 0.3, y: y + 0.1, w: 0.42, h: 0.42, fontSize: 11, bold: true, color: C.white, fontFace: FONT, align: "center", valign: "middle" });
    s.addText([
      { text: p[1] + ": ", options: { bold: true, color: C.orange } },
      { text: p[2], options: { bold: false, color: C.white } },
    ], { x: 0.82, y, w: 9.0, h: 0.6, fontSize: 10, fontFace: FONT, valign: "middle", wrap: true });
  });

  s.addText("Sources: Goldman-Cecil Medicine | Murray & Nadel's Respiratory Medicine | Fishman's Pulmonary Diseases | IDSA/ATS Guidelines 2007/2016/2019", {
    x: 0.3, y: 5.35, w: 9.4, h: 0.25,
    fontSize: 7, color: C.lgray, fontFace: FONT, align: "center", italic: true,
  });
}

// WRITE
pres.writeFile({ fileName: "/home/daytona/workspace/pneumonia-ppt/Pneumonia_Advanced_Management.pptx" })
  .then(() => console.log("SUCCESS: Pneumonia_Advanced_Management.pptx written"))
  .catch(e => { console.error("ERROR:", e); process.exit(1); });
Running Command

cd /home/daytona/workspace/pneumonia-ppt && node build_pneumonia.js 2>&1

Editing File

~/pneumonia-ppt/build_pneumonia.js

Error: String not found in file: '    { t: "5 days", d: "CXR clearance\nOutpatient review\nSputum cytology if >50y, smoker", c: C.orange + "33" },'
Running Command

grep -n "E87722" /home/daytona/workspace/pneumonia-ppt/build_pneumonia.js | head…

Running Command

grep -n 'C\.orange.*"33"\|"33"' /home/daytona/workspace/pneumonia-ppt/build_pneu…

Running Command

sed -i 's/c: C\.orange + "33"/c: "F5CBA7"/' /home/daytona/workspace/pneumonia-pp…

Editing File

~/pneumonia-ppt/build_pneumonia.js

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/pneumonia-ppt/build_pneumonia.js'
Running Command

node /home/daytona/workspace/pneumonia-ppt/build_pneumonia.js 2>&1

Running Command

ls -lh /home/daytona/workspace/pneumonia-ppt/Pneumonia_Advanced_Management.pptx

Your presentation is ready. Download it here:

Pneumonia Advanced Management

Presentation · PPTX


What's inside (14 slides, Navy/Teal/Orange palette)

SlideContent
1Title slide - Bold typographic design
2Contents overview - Colour-coded table of contents with 10 topic badges
3Epidemiology & Classification - Stats row + full CAP/HAP/VAP/Aspiration table with pathogens
4Pathophysiology diagram - Radial flowchart: 5 entry routes → lung parenchyma → inflammatory cascade (TLR → cytokines → neutrophil → consolidation)
5Clinical Presentation & Diagnosis - Two-column table: symptoms + physical signs + diagnostic criteria footnote
6Severity Assessment - Full CURB-65 criteria boxes + score→triage decision + IDSA/ATS Major/Minor ICU criteria side-by-side
7Diagnostic Workup Algorithm - CXR → infiltrate diamond decision → Bloods/Micro/Imaging panels
8Empiric Antibiotic Management - Stratified by CAP outpatient/ward/ICU and HAP/VAP low-risk/MDR/MRSA + de-escalation footnote
9ICU Management - HFNC → NIV → ARDSnet MV → ECMO progression + adjuncts (steroids, fluids, DVT ppx, nutrition)
10Complications - Radial diagram: empyema, lung abscess, ARDS, septic shock, meningitis, endocarditis
11De-escalation & Discharge Flowchart - Step-by-step: IV → oral stability criteria → discharge criteria → follow-up
12Recovery & Prevention - Timeline arrow (24h → 6 months) + vaccination schedule + special populations (HIV, elderly, pregnancy, CF, influenza)
13Master Management Algorithm - End-to-end resident flowchart: presentation → workup → severity branch → ward → 48h reassessment → step-down
147 Key Takeaways - Dark slide with numbered clinical pearls

Sources: Goldman-Cecil Medicine, Murray & Nadel's Textbook of Respiratory Medicine, Fishman's Pulmonary Diseases, IDSA/ATS CAP Guidelines 2007, IDSA HAP/VAP Guidelines 2016, IDSA CAP Guidelines 2019.

Pptx

The file was already built and is ready to download right now:

Pneumonia Advanced Management

Presentation · PPTX

This is the same 14-slide deck from the previous response - 470 KB, fully built with all flowcharts, diagrams, and management algorithms. Just click the link above to download it.

Create a printable PDF summary of the Master Algorithm for pocket reference

Reading File
Writing File

~/pneumonia-ppt/build_pocket_pdf.py

"""
Pneumonia Master Algorithm - Pocket Reference PDF
A5 size (148 x 210 mm), print-ready, high-contrast
"""

from reportlab.lib.pagesizes import A5
from reportlab.lib.units import mm
from reportlab.lib import colors
from reportlab.pdfgen import canvas
from reportlab.lib.colors import HexColor
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
import math

OUTPUT = "/home/daytona/workspace/pneumonia-ppt/Pneumonia_Pocket_Reference.pdf"

# --- Colors ---
NAVY    = HexColor("#0D2B55")
TEAL    = HexColor("#1A7FA0")
ORANGE  = HexColor("#E87722")
GREEN   = HexColor("#2E7D32")
RED     = HexColor("#C0392B")
WHITE   = HexColor("#FFFFFF")
OFFWHITE= HexColor("#F0F4F8")
LGRAY   = HexColor("#BDC3C7")
DGRAY   = HexColor("#5D6D7E")
LTBLUE  = HexColor("#D6EAF8")
LTGREEN = HexColor("#D5F5E3")
LTYELLOW= HexColor("#FEF9E7")
LTRED   = HexColor("#FADBD8")
CHARCOAL= HexColor("#1C2833")

W, H = A5  # 419.5 x 595.3 pt  (148 x 210 mm)

def draw_rounded_rect(c, x, y, w, h, r, fill_color, stroke_color=None, stroke_width=0.5):
    c.saveState()
    c.setFillColor(fill_color)
    if stroke_color:
        c.setStrokeColor(stroke_color)
        c.setLineWidth(stroke_width)
    else:
        c.setStrokeColor(fill_color)
        c.setLineWidth(0)
    p = c.beginPath()
    p.moveTo(x + r, y)
    p.lineTo(x + w - r, y)
    p.arcTo(x + w - 2*r, y, x + w, y + 2*r, -90, 90)
    p.lineTo(x + w, y + h - r)
    p.arcTo(x + w - 2*r, y + h - 2*r, x + w, y + h, 0, 90)
    p.lineTo(x + r, y + h)
    p.arcTo(x, y + h - 2*r, x + 2*r, y + h, 90, 90)
    p.lineTo(x, y + r)
    p.arcTo(x, y, x + 2*r, y + 2*r, 180, 90)
    p.close()
    c.drawPath(p, fill=1, stroke=1 if stroke_color else 0)
    c.restoreState()

def draw_diamond(c, cx, cy, hw, hh, fill_color, stroke_color=None):
    c.saveState()
    c.setFillColor(fill_color)
    if stroke_color:
        c.setStrokeColor(stroke_color)
        c.setLineWidth(0.7)
    p = c.beginPath()
    p.moveTo(cx, cy - hh)
    p.lineTo(cx + hw, cy)
    p.lineTo(cx, cy + hh)
    p.lineTo(cx - hw, cy)
    p.close()
    c.drawPath(p, fill=1, stroke=1 if stroke_color else 0)
    c.restoreState()

def draw_arrow_down(c, x, y, length=10, color=DGRAY):
    c.saveState()
    c.setStrokeColor(color)
    c.setFillColor(color)
    c.setLineWidth(0.8)
    c.line(x, y, x, y - length + 3)
    # arrowhead
    p = c.beginPath()
    p.moveTo(x - 3, y - length + 4)
    p.lineTo(x + 3, y - length + 4)
    p.lineTo(x, y - length)
    p.close()
    c.drawPath(p, fill=1, stroke=0)
    c.restoreState()

def draw_arrow_right(c, x, y, length=10, color=DGRAY):
    c.saveState()
    c.setStrokeColor(color)
    c.setFillColor(color)
    c.setLineWidth(0.8)
    c.line(x, y, x + length - 3, y)
    p = c.beginPath()
    p.moveTo(x + length - 4, y - 3)
    p.lineTo(x + length - 4, y + 3)
    p.lineTo(x + length, y)
    p.close()
    c.drawPath(p, fill=1, stroke=0)
    c.restoreState()

def draw_arrow_left(c, x, y, length=10, color=DGRAY):
    c.saveState()
    c.setStrokeColor(color)
    c.setFillColor(color)
    c.setLineWidth(0.8)
    c.line(x, y, x - length + 3, y)
    p = c.beginPath()
    p.moveTo(x - length + 4, y - 3)
    p.lineTo(x - length + 4, y + 3)
    p.lineTo(x - length, y)
    p.close()
    c.drawPath(p, fill=1, stroke=0)
    c.restoreState()

def centered_text(c, text, cx, cy, font, size, color=CHARCOAL):
    c.saveState()
    c.setFont(font, size)
    c.setFillColor(color)
    tw = c.stringWidth(text, font, size)
    c.drawString(cx - tw/2, cy - size/3, text)
    c.restoreState()

def multiline_text_box(c, lines, x, y, w, h, font, size, color=CHARCOAL, align="center", leading=None):
    """Draw multiple lines centered in a box. y is the TOP of the box."""
    if leading is None:
        leading = size * 1.25
    total_h = len(lines) * leading
    start_y = y - (h - total_h) / 2 - leading * 0.8
    c.saveState()
    c.setFont(font, size)
    c.setFillColor(color)
    for i, line in enumerate(lines):
        ly = start_y - i * leading
        if align == "center":
            tw = c.stringWidth(line, font, size)
            c.drawString(x + (w - tw)/2, ly, line)
        else:
            c.drawString(x + 3, ly, line)
    c.restoreState()

# =====================================================================
# PAGE 1 — MASTER ALGORITHM FLOWCHART
# =====================================================================
c = canvas.Canvas(OUTPUT, pagesize=A5)
c.setTitle("Pneumonia Pocket Reference – Master Algorithm")
c.setAuthor("Medicine Resident Reference")

margin = 8 * mm
cw = W - 2 * margin   # usable width ~132 mm = ~374 pt

# ---- HEADER ----
c.setFillColor(NAVY)
c.rect(0, H - 22*mm, W, 22*mm, fill=1, stroke=0)
c.setFillColor(ORANGE)
c.rect(0, H - 22*mm - 2, W, 3, fill=1, stroke=0)

c.setFont("Helvetica-Bold", 13)
c.setFillColor(WHITE)
tw = c.stringWidth("PNEUMONIA", "Helvetica-Bold", 13)
c.drawString((W - tw)/2, H - 10*mm, "PNEUMONIA")
c.setFont("Helvetica", 8)
tw2 = c.stringWidth("Master Management Algorithm  •  Pocket Reference", "Helvetica", 8)
c.drawString((W - tw2)/2, H - 16*mm, "Master Management Algorithm  •  Pocket Reference")
c.setFont("Helvetica-Oblique", 6.5)
tw3 = c.stringWidth("Medicine Resident | Sources: Goldman-Cecil, Murray & Nadel, IDSA/ATS Guidelines", "Helvetica-Oblique", 6.5)
c.drawString((W - tw3)/2, H - 20*mm, "Medicine Resident | Sources: Goldman-Cecil, Murray & Nadel, IDSA/ATS Guidelines")

# ---- FLOWCHART LAYOUT ----
# Each node: (label_lines, x_center, y_top, width, height, shape, fill, text_color)
# y measured from bottom of page

# We'll use a fixed column center
cx = W / 2

# Starting y (from top of usable area)
y_start = H - 26*mm
node_h = 10*mm
node_w = 80*mm
gap = 5*mm     # between nodes
diam_h = 9*mm
diam_w = 48*mm

# Helper: draw a standard box node
def box_node(c, lines, cx, y_top, w, h, fill, text_color=WHITE, stroke=None, font_size=7):
    x = cx - w/2
    draw_rounded_rect(c, x, y_top - h, w, h, 2*mm, fill, stroke or fill, 0.5)
    multiline_text_box(c, lines, x, y_top, w, h, "Helvetica-Bold", font_size, text_color)

def diag_node(c, lines, cx, cy, hw, hh, fill, stroke, text_color=CHARCOAL, font_size=6.5):
    draw_diamond(c, cx, cy, hw, hh, fill, stroke)
    # center text in diamond
    total_h = len(lines) * 7.5
    for i, line in enumerate(lines):
        ly = cy + total_h/2 - (i+0.85) * 7.5
        c.setFont("Helvetica-Bold", font_size)
        c.setFillColor(text_color)
        tw = c.stringWidth(line, "Helvetica-Bold", font_size)
        c.drawString(cx - tw/2, ly, line)

# Row 1: Presentation
y1 = y_start
box_node(c, ["PATIENT PRESENTS", "Fever  •  Cough  •  Dyspnea  •  Hypoxia"], cx, y1, node_w, node_h, NAVY)
draw_arrow_down(c, cx, y1 - node_h, gap, DGRAY)

# Row 2: Workup
y2 = y1 - node_h - gap
box_node(c, ["INITIAL WORKUP", "CXR  |  CBC, CMP, CRP, PCT  |  Blood Cultures ×2  |  SpO₂  |  ABG"], cx, y2, node_w, node_h, TEAL)
draw_arrow_down(c, cx, y2 - node_h, gap, DGRAY)

# Row 3: Classify
y3 = y2 - node_h - gap
box_node(c, ["CLASSIFY PNEUMONIA", "CAP  vs  HAP  vs  VAP  vs  Aspiration"], cx, y3, node_w, node_h, DGRAY)
draw_arrow_down(c, cx, y3 - node_h, gap, DGRAY)

# Row 4: Severity diamond
y4 = y3 - node_h - gap
dcy4 = y4 - diam_h  # center y of diamond
diag_node(c, ["SEVERITY ASSESSMENT", "CURB-65  +  IDSA/ATS Criteria"], cx, dcy4, diam_w, diam_h, LTYELLOW, ORANGE)

# Three branches from diamond
# LEFT: Low (outpatient)
bx_left = margin + 22*mm
bx_w = 37*mm
bx_h = 19*mm
draw_arrow_left(c, cx - diam_w, dcy4, cx - diam_w - bx_left - bx_w/2 + 1, GREEN)
c.setFont("Helvetica-Bold", 6); c.setFillColor(GREEN)
c.drawString(margin + 1*mm, dcy4 + 1, "LOW")
c.drawString(margin + 1*mm, dcy4 - 5, "CURB 0-1")
draw_rounded_rect(c, margin, dcy4 - diam_h - bx_h + diam_h, bx_w, bx_h, 2*mm, LTGREEN, GREEN, 0.6)
lines_low = ["OUTPATIENT", "Amoxicillin 1g TDS ×5d", "OR Doxycycline 100mg BD", "OR Azithromycin 500mg OD"]
multiline_text_box(c, lines_low, margin, dcy4 - diam_h + diam_h, bx_w, bx_h, "Helvetica", 5.5, CHARCOAL)

# RIGHT: Severe/ICU
bx_right_x = W - margin - bx_w
draw_arrow_right(c, cx + diam_w, dcy4, bx_right_x - (cx + diam_w) + 1, RED)
c.setFont("Helvetica-Bold", 6); c.setFillColor(RED)
c.drawString(W - margin - bx_w + 1*mm, dcy4 + 1, "SEVERE")
c.drawString(W - margin - bx_w + 1*mm, dcy4 - 5, "Major ≥1 / Minor ≥3")
draw_rounded_rect(c, bx_right_x, dcy4 - diam_h - bx_h + diam_h, bx_w, bx_h, 2*mm, LTRED, RED, 0.6)
lines_sev = ["ICU ADMISSION", "β-lactam + Macrolide/FQ", "± Vanco (MRSA risk)", "± Pip-Tazo (Pseudo risk)"]
multiline_text_box(c, lines_sev, bx_right_x, dcy4 - diam_h + diam_h, bx_w, bx_h, "Helvetica", 5.5, CHARCOAL)

# DOWN: Moderate → Inpatient
draw_arrow_down(c, cx, dcy4 - diam_h, gap, DGRAY)
c.setFont("Helvetica-Bold", 6); c.setFillColor(ORANGE)
lbl = "MODERATE  CURB 2-3"
tlw = c.stringWidth(lbl, "Helvetica-Bold", 6)
c.drawString(cx - tlw/2, dcy4 - diam_h - 2, lbl)

# Row 5: Ward admission
y5 = dcy4 - diam_h - gap - 2
box_node(c, ["INPATIENT WARD", "IV β-lactam + Macrolide  OR  Resp. Fluoroquinolone (Levoflox 750mg / Moxi 400mg)"], cx, y5, node_w, node_h, NAVY)
draw_arrow_down(c, cx, y5 - node_h, gap, DGRAY)

# Row 6: 48-72h diamond
y6 = y5 - node_h - gap
dcy6 = y6 - diam_h
diag_node(c, ["48–72h REASSESS", "Clinical response?"], cx, dcy6, diam_w, diam_h, LTYELLOW, ORANGE)

# RIGHT: No response
no_x = cx + diam_w
no_box_x = W - margin - 42*mm
draw_arrow_right(c, no_x, dcy6, no_box_x - no_x + 1, RED)
c.setFont("Helvetica-Bold", 6); c.setFillColor(RED)
c.drawString(no_x + 2, dcy6 + 1, "NO RESPONSE")
draw_rounded_rect(c, no_box_x, dcy6 - 10*mm, 42*mm, 10*mm, 2*mm, LTRED, RED, 0.6)
lines_no = ["BROADEN / ESCALATE", "CT + repeat cultures", "Exclude: empyema, abscess", "ID consult  •  Bronchoscopy"]
multiline_text_box(c, lines_no, no_box_x, dcy6, 42*mm, 10*mm, "Helvetica", 5.5, CHARCOAL)

# DOWN: Yes response
draw_arrow_down(c, cx, dcy6 - diam_h, gap, GREEN)
c.setFont("Helvetica-Bold", 6); c.setFillColor(GREEN)
lbl2 = "RESPONDING"
tlw2 = c.stringWidth(lbl2, "Helvetica-Bold", 6)
c.drawString(cx - tlw2/2, dcy6 - diam_h - 2, lbl2)

# Row 7: Step-down
y7 = dcy6 - diam_h - gap - 2
box_node(c, ["STEP-DOWN TO ORAL ANTIBIOTICS", "Once afebrile ≥48h  •  HR ≤100  •  RR ≤24  •  SpO₂ ≥90%  •  Tolerating PO"], cx, y7, node_w, node_h, GREEN)
draw_arrow_down(c, cx, y7 - node_h, gap, DGRAY)

# Row 8: Discharge
y8 = y7 - node_h - gap
box_node(c, ["DISCHARGE  +  FOLLOW-UP", "CXR at 6–8 wks  •  Vaccinate (PCV + Flu)  •  Smoking cessation  •  Pulm rehab PRN"], cx, y8, node_w, node_h, TEAL)

# ---- FOOTER ----
c.setFillColor(NAVY)
c.rect(0, 0, W, 6*mm, fill=1, stroke=0)
c.setFont("Helvetica", 5.5)
c.setFillColor(LGRAY)
footer = "Goldman-Cecil Medicine  |  Murray & Nadel's Respiratory Medicine  |  IDSA/ATS CAP 2007/2019  |  IDSA HAP/VAP 2016"
ftw = c.stringWidth(footer, "Helvetica", 5.5)
c.drawString((W - ftw)/2, 1.5*mm, footer)

c.showPage()

# =====================================================================
# PAGE 2 — QUICK REFERENCE TABLES (CURB-65 + Antibiotics + Complications)
# =====================================================================

# Header
c.setFillColor(NAVY)
c.rect(0, H - 18*mm, W, 18*mm, fill=1, stroke=0)
c.setFillColor(ORANGE)
c.rect(0, H - 18*mm - 2, W, 3, fill=1, stroke=0)

c.setFont("Helvetica-Bold", 11)
c.setFillColor(WHITE)
tw = c.stringWidth("QUICK REFERENCE TABLES", "Helvetica-Bold", 11)
c.drawString((W - tw)/2, H - 10*mm, "QUICK REFERENCE TABLES")
c.setFont("Helvetica", 7)
tw2 = c.stringWidth("CURB-65  •  Antibiotic Dosing  •  Severity  •  Complications", "Helvetica", 7)
c.drawString((W - tw2)/2, H - 15.5*mm, "CURB-65  •  Antibiotic Dosing  •  Severity  •  Complications")

y_cur = H - 22*mm

# ---- TABLE 1: CURB-65 ----
def section_header(c, title, y, fill=TEAL):
    c.setFillColor(fill)
    c.rect(margin, y - 7*mm, cw, 7*mm, fill=1, stroke=0)
    c.setFont("Helvetica-Bold", 8)
    c.setFillColor(WHITE)
    tw = c.stringWidth(title, "Helvetica-Bold", 8)
    c.drawString((W - tw)/2, y - 5*mm, title)
    return y - 7*mm

def table_row(c, cols, widths, y, row_h, fill, text_color=CHARCOAL, bold=False, sizes=None):
    x = margin
    for i, (text, w) in enumerate(zip(cols, widths)):
        c.setFillColor(fill)
        c.rect(x, y - row_h, w, row_h, fill=1, stroke=1)
        c.setStrokeColor(LGRAY)
        c.setLineWidth(0.3)
        fnt = "Helvetica-Bold" if bold else "Helvetica"
        sz = sizes[i] if sizes else 6.5
        c.setFont(fnt, sz)
        c.setFillColor(text_color)
        # wrap long text
        tw2 = c.stringWidth(text, fnt, sz)
        if tw2 > w - 4:
            sz = max(4.5, sz - 1)
            c.setFont(fnt, sz)
        c.drawString(x + 2, y - row_h + 2, text)
        x += w
    return y - row_h

y_cur = section_header(c, "CURB-65 SEVERITY SCORING", y_cur, NAVY)
curb_widths = [28*mm, 52*mm, 28*mm, 24*mm]
y_cur = table_row(c, ["Criterion", "Definition", "Score", "Action"], curb_widths, y_cur, 6*mm, NAVY, WHITE, bold=True)
curb_data = [
    ("Confusion", "New onset AMT ≤8 or disorientation", "1", ""),
    ("Urea", "Blood urea >7 mmol/L (BUN >19 mg/dL)", "1", ""),
    ("Resp Rate", "≥30 breaths/min", "1", ""),
    ("Blood Pressure", "Systolic <90 or Diastolic ≤60 mmHg", "1", ""),
    ("Age ≥65", "Age 65 years or older", "1", ""),
    ("SCORE 0–1", "Low risk", "–", "Outpatient"),
    ("SCORE 2", "Moderate risk", "–", "Consider admit"),
    ("SCORE 3–5", "High risk", "–", "Admit / ICU"),
]
fills = [OFFWHITE, LTBLUE, OFFWHITE, LTBLUE, OFFWHITE, LTGREEN, LTYELLOW, LTRED]
for row, fill in zip(curb_data, fills):
    y_cur = table_row(c, list(row), curb_widths, y_cur, 5.2*mm, fill)

y_cur -= 3*mm

# ---- TABLE 2: Antibiotic Quick Guide ----
y_cur = section_header(c, "EMPIRIC ANTIBIOTIC GUIDE", y_cur, TEAL)
ab_widths = [30*mm, 44*mm, 26*mm, 32*mm]
y_cur = table_row(c, ["Setting", "First-line Regimen", "Duration", "Alternatives"], ab_widths, y_cur, 6*mm, NAVY, WHITE, bold=True)
ab_data = [
    ("CAP Outpatient", "Amox 1g TDS OR Doxy 100mg BD", "5 days", "Azithromycin 500mg OD"),
    ("CAP Ward", "Ceftriaxone 1g IV + Azithro 500mg", "5–7 days", "Resp FQ (Levo/Moxi)"),
    ("CAP Severe/ICU", "Ceftriaxone 2g IV + Azithro/FQ", "5–7 days", "Add Vanco if MRSA risk"),
    ("HAP Low-risk", "Pip-Tazo 4.5g q6h IV", "7 days", "Ceftriaxone OR Levo"),
    ("HAP MDR risk", "Cefepime 2g q8h OR Meropenem 1g q8h", "7 days", "+ Tobramycin/Amikacin"),
    ("HAP + MRSA risk", "Above + Vancomycin 15–20mg/kg q8-12h", "7 days", "OR Linezolid 600mg BD"),
    ("VAP", "Anti-pseudomonal β-lactam ± MRSA cover", "7 days", "PCT-guided stop"),
    ("Aspiration", "Amox-Clav OR Pip-Tazo", "5–7 days", "Add metronidazole if gross"),
]
ab_fills = [LTGREEN, LTGREEN, LTRED, LTYELLOW, LTYELLOW, LTRED, LTBLUE, OFFWHITE]
for row, fill in zip(ab_data, ab_fills):
    y_cur = table_row(c, list(row), ab_widths, y_cur, 5.2*mm, fill)

y_cur -= 3*mm

# ---- TABLE 3: Key Complications ----
y_cur = section_header(c, "COMPLICATIONS & RED FLAGS", y_cur, RED)
comp_widths = [35*mm, 42*mm, 55*mm]
y_cur = table_row(c, ["Complication", "Clue / Trigger", "Management"], comp_widths, y_cur, 6*mm, NAVY, WHITE, bold=True)
comp_data = [
    ("Parapneumonic / Empyema", "pH <7.2, LDH >1000, glucose <2.2", "Chest drain; VATS if loculated"),
    ("Lung Abscess", "Putrid sputum; cavity on CXR", "Prolonged Abx 4–6 wks; percutaneous drain"),
    ("ARDS", "P:F <200; bilateral infiltrates", "ARDSnet ventilation; prone ≥16h"),
    ("Septic Shock", "MAP <65 despite fluids", "Norepinephrine; Surviving Sepsis bundle"),
    ("Non-resolving Pneumonia", "No improvement at 72h", "CT; cultures; ID/Pulm consult"),
]
comp_fills_l = [LTRED, LTYELLOW, LTBLUE, LTRED, LTYELLOW]
for row, fill in zip(comp_data, comp_fills_l):
    y_cur = table_row(c, list(row), comp_widths, y_cur, 5.5*mm, fill)

# ---- FOOTER ----
c.setFillColor(NAVY)
c.rect(0, 0, W, 6*mm, fill=1, stroke=0)
c.setFont("Helvetica", 5.5)
c.setFillColor(LGRAY)
footer = "Goldman-Cecil Medicine  |  Murray & Nadel's Respiratory Medicine  |  IDSA/ATS CAP 2007/2019  |  IDSA HAP/VAP 2016"
ftw = c.stringWidth(footer, "Helvetica", 5.5)
c.drawString((W - ftw)/2, 1.5*mm, footer)

c.showPage()

# =====================================================================
# PAGE 3 — RECOVERY TIMELINE + SPECIAL POPULATIONS
# =====================================================================

# Header
c.setFillColor(GREEN)
c.rect(0, H - 18*mm, W, 18*mm, fill=1, stroke=0)
c.setFillColor(ORANGE)
c.rect(0, H - 18*mm - 2, W, 3, fill=1, stroke=0)
c.setFont("Helvetica-Bold", 11)
c.setFillColor(WHITE)
tw = c.stringWidth("RECOVERY, PREVENTION & SPECIAL POPULATIONS", "Helvetica-Bold", 11)
# shrink if too wide
sz = 11
while c.stringWidth("RECOVERY, PREVENTION & SPECIAL POPULATIONS", "Helvetica-Bold", sz) > cw and sz > 7:
    sz -= 0.5
c.setFont("Helvetica-Bold", sz)
tw = c.stringWidth("RECOVERY, PREVENTION & SPECIAL POPULATIONS", "Helvetica-Bold", sz)
c.drawString((W - tw)/2, H - 10*mm, "RECOVERY, PREVENTION & SPECIAL POPULATIONS")
c.setFont("Helvetica", 7)
tw2 = c.stringWidth("Recovery Timeline  •  Discharge Checklist  •  Vaccination  •  Special Populations", "Helvetica", 7)
c.drawString((W - tw2)/2, H - 15.5*mm, "Recovery Timeline  •  Discharge Checklist  •  Vaccination  •  Special Populations")

yp = H - 22*mm

# ---- Recovery Timeline horizontal arrow ----
yp = section_header(c, "TYPICAL RECOVERY TIMELINE (CAP)", yp, NAVY)

tl_items = [
    ("24–48h", "Fever\nresolution", LTGREEN),
    ("3–5d", "Step-down\noral Abx", LTBLUE),
    ("1–2 wk", "Improved\ndyspnea", LTYELLOW),
    ("6–8 wk", "CXR\nclearance", HexColor("#F5CBA7")),
    ("3–6 mo", "Full\nrecovery", LTRED),
]
n = len(tl_items)
tl_w = cw / n
tl_h = 14*mm
tl_y = yp - tl_h

for i, (time, desc, col) in enumerate(tl_items):
    x = margin + i * tl_w
    draw_rounded_rect(c, x + 1, tl_y, tl_w - 2, tl_h, 2*mm, col, TEAL, 0.5)
    c.setFont("Helvetica-Bold", 7)
    c.setFillColor(NAVY)
    tw = c.stringWidth(time, "Helvetica-Bold", 7)
    c.drawString(x + (tl_w - tw)/2, tl_y + tl_h - 5, time)
    c.setFont("Helvetica", 6)
    c.setFillColor(CHARCOAL)
    for j, line in enumerate(desc.split("\n")):
        lw = c.stringWidth(line, "Helvetica", 6)
        c.drawString(x + (tl_w - lw)/2, tl_y + tl_h - 12 - j*7, line)
    if i < n - 1:
        ax = x + tl_w - 1
        ay = tl_y + tl_h/2
        draw_arrow_right(c, ax, ay, 3, DGRAY)

yp = tl_y - 4*mm

# ---- Discharge Checklist ----
yp = section_header(c, "DISCHARGE CHECKLIST", yp, TEAL)
checks = [
    "Afebrile ≥24h and haemodynamically stable",
    "SpO₂ ≥90% on room air (or at baseline for COPD patients)",
    "Tolerating oral intake and oral antibiotics",
    "Suitable home environment or step-down facility arranged",
    "Follow-up CXR booked at 6–8 weeks (exclude underlying malignancy)",
    "Pneumococcal (PCV15/20) and annual influenza vaccinations given or scheduled",
    "Smoking cessation advice documented; cessation aids offered",
    "Patient education: return precautions, antibiotic course completion",
]
ch_y = yp
ch_h = 5.5*mm
for i, ch in enumerate(checks):
    fill = OFFWHITE if i % 2 == 0 else LTGREEN
    c.setFillColor(fill)
    c.rect(margin, ch_y - ch_h, cw, ch_h, fill=1, stroke=1)
    c.setStrokeColor(LGRAY); c.setLineWidth(0.3)
    # checkbox
    c.setFillColor(WHITE)
    c.rect(margin + 2, ch_y - ch_h + 1.5, 3.5, 3.5, fill=1, stroke=1)
    c.setFont("Helvetica", 6.5)
    c.setFillColor(CHARCOAL)
    c.drawString(margin + 8, ch_y - ch_h + 2, ch)
    ch_y -= ch_h

yp = ch_y - 4*mm

# ---- Special Populations ----
yp = section_header(c, "SPECIAL POPULATIONS", yp, NAVY)
sp_data = [
    ("HIV / Immunocomp.", "Broaden cover: PCP (TMP-SMX), Cryptococcus, CMV, Aspergillus. CD4 <200 → PCP prophylaxis.", LTBLUE),
    ("Elderly >65y", "Atypical: confusion/falls without fever. Aspiration risk. Conservative fluids. Longer Abx course.", LTYELLOW),
    ("Pregnancy", "Safe: amoxicillin, azithromycin. Avoid FQ, tetracyclines. High preterm delivery risk.", LTGREEN),
    ("Structural Lung (CF/Bronchiect.)", "Always cover Pseudomonas: cefepime or pip-tazo + tobramycin. Treat underlying.", HexColor("#F5CBA7")),
    ("Viral (Influenza)", "Oseltamivir within 48h. Cover bacterial co-infection: MRSA (vancomycin).", LTRED),
]
sp_h = 6*mm
for i, (pop, mgmt, col) in enumerate(sp_data):
    draw_rounded_rect(c, margin, yp - sp_h, cw, sp_h, 1.5*mm, col, TEAL, 0.4)
    c.setFont("Helvetica-Bold", 6.5)
    c.setFillColor(NAVY)
    c.drawString(margin + 2, yp - sp_h + 2, pop + ":")
    pw = c.stringWidth(pop + ": ", "Helvetica-Bold", 6.5)
    c.setFont("Helvetica", 6.5)
    c.setFillColor(CHARCOAL)
    c.drawString(margin + 2 + pw, yp - sp_h + 2, mgmt)
    yp -= sp_h

# Footer
c.setFillColor(NAVY)
c.rect(0, 0, W, 6*mm, fill=1, stroke=0)
c.setFont("Helvetica", 5.5)
c.setFillColor(LGRAY)
footer = "Goldman-Cecil Medicine  |  Murray & Nadel's Respiratory Medicine  |  IDSA/ATS CAP 2007/2019  |  IDSA HAP/VAP 2016"
ftw = c.stringWidth(footer, "Helvetica", 5.5)
c.drawString((W - ftw)/2, 1.5*mm, footer)

c.showPage()
c.save()
print(f"SUCCESS: {OUTPUT}")
Running Command

cd /home/daytona/workspace/pneumonia-ppt && python3 build_pocket_pdf.py 2>&1

Running Command

ls -lh /home/daytona/workspace/pneumonia-ppt/Pneumonia_Pocket_Reference.pdf

Your pocket reference PDF is ready:

Pneumonia Pocket Reference

PDF Document · PDF


What's inside (3 pages, A5 size - fold-and-carry format)

Page 1 — Master Algorithm Flowchart A top-to-bottom decision flowchart covering:
  • Presentation → Workup → Classify (CAP/HAP/VAP)
  • Severity diamond (CURB-65 / IDSA-ATS) with 3 branches: Outpatient (green) / Ward (orange) / ICU (red)
  • Ward admission → 48-72h reassessment diamond → "No response" escalation branch → "Responding" step-down
  • Final: Discharge + Follow-up node
Page 2 — Quick Reference Tables
  • CURB-65 scoring: all 5 criteria + score/action rows colour-coded (green/yellow/red)
  • Empiric antibiotic guide: 8 rows covering CAP/HAP/VAP/Aspiration with first-line, alternatives, duration
  • Complications & red flags: empyema, abscess, ARDS, septic shock, non-resolving pneumonia
Page 3 — Recovery & Special Populations
  • Recovery timeline: horizontal arrow from 24h → 6 months with colour blocks
  • Discharge checklist: 8 tickboxes ready to print and use at bedside
  • Special populations: HIV, elderly, pregnancy, CF/bronchiectasis, influenza - each with specific adjustments
Print tip: Print A5 duplex (flip on short edge) - all 3 pages fit on 1.5 sheets. Laminate for daily ward carry.
This is a shared conversation. Sign in to Orris to start your own chat.