Atrial fibrillation - I have to deliver lecture seminar on this topic as pg medicine resident so please make me 20 slides ppt .....by taking reference from harrison and make it in such manner that I can deliver detailed knowledge in easy manner and you can use flowchart and box .....and it should cover all aspects of atrial fibrillation......

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

ls -la /home/daytona/workspace/ 2>/dev/null || mkdir -p /home/daytona/workspace

Running Command

mkdir -p /home/daytona/workspace/af-ppt

Writing File

~/af-ppt/create_af_ppt.js

const pptxgen = require("pptxgenjs");
const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Atrial Fibrillation - Comprehensive Seminar";
pres.author = "PG Medicine Resident";

// ─── COLOR PALETTE ───────────────────────────────────────────────────────────
const C = {
  navy:    "0D1B40",   // dominant dark bg
  red:     "C0392B",   // AF accent / danger
  teal:    "1A7F8E",   // section heading band
  lightB:  "D6EAF8",   // light blue box fill
  lightG:  "D5F5E3",   // light green box fill
  lightY:  "FEF9E7",   // light yellow box fill
  lightR:  "FADBD8",   // light red box fill
  white:   "FFFFFF",
  offW:    "F4F6F7",
  darkT:   "1B2631",
  gold:    "F0B429",
  gray:    "566573",
  lgray:   "ECF0F1",
};

// ─── HELPER: Add standard slide header bar ───────────────────────────────────
function addHeader(slide, title, sub) {
  // Top banner
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 0.72, fill: { color: C.navy } });
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0.72, w: 10, h: 0.055, fill: { color: C.gold } });
  slide.addText(title.toUpperCase(), {
    x: 0.22, y: 0.05, w: 8.5, h: 0.62, margin: 0,
    fontSize: 21, bold: true, color: C.white, fontFace: "Calibri",
    charSpacing: 1.5
  });
  if (sub) {
    slide.addText(sub, {
      x: 0.22, y: 0.05, w: 8.5, h: 0.62, margin: 0,
      fontSize: 12, color: C.gold, fontFace: "Calibri", align: "right", valign: "bottom"
    });
  }
  // Source tag
  slide.addText("Reference: Harrison's Principles of Internal Medicine 22E", {
    x: 0, y: 5.42, w: 10, h: 0.21, margin: 0,
    fontSize: 7.5, color: C.gray, align: "right", fontFace: "Calibri",
    italic: true
  });
}

// ─── HELPER: Colored Box ────────────────────────────────────────────────────
function addBox(slide, x, y, w, h, fillColor, borderColor, text, txtSize, bold, txtColor) {
  slide.addShape(pres.ShapeType.roundRect, {
    x, y, w, h,
    fill: { color: fillColor },
    line: { color: borderColor || C.navy, width: 1.2 },
    rectRadius: 0.07
  });
  if (text) {
    slide.addText(text, {
      x: x + 0.06, y, w: w - 0.12, h,
      fontSize: txtSize || 11, bold: !!bold,
      color: txtColor || C.navy, fontFace: "Calibri",
      align: "center", valign: "middle", wrap: true, margin: 3
    });
  }
}

// ─── HELPER: Arrow ─────────────────────────────────────────────────────────
function addArrow(slide, x1, y1, x2, y2) {
  slide.addShape(pres.ShapeType.line, {
    x: x1, y: y1, w: x2 - x1, h: y2 - y1,
    line: { color: C.teal, width: 2, endArrowType: "triangle" }
  });
}

// ─── HELPER: Section label ──────────────────────────────────────────────────
function addSectionLabel(slide, label, x, y, w) {
  slide.addShape(pres.ShapeType.rect, {
    x, y, w: w || 2.8, h: 0.28,
    fill: { color: C.teal },
    line: { color: C.teal }
  });
  slide.addText(label, {
    x: x + 0.05, y, w: (w || 2.8) - 0.1, h: 0.28, margin: 0,
    fontSize: 9.5, bold: true, color: C.white, fontFace: "Calibri",
    align: "center", valign: "middle"
  });
}

// ─── HELPER: Bullet list ─────────────────────────────────────────────────────
function makeBullets(items, size, clr) {
  return items.map((item, i) => ({
    text: item,
    options: {
      bullet: { type: "bullet", characterCode: "25CF", indent: 14 },
      fontSize: size || 12.5,
      color: clr || C.navy,
      fontFace: "Calibri",
      breakLine: i < items.length - 1
    }
  }));
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 1 — TITLE SLIDE
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.navy } });
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 4.0, w: 10, h: 1.625, fill: { color: C.teal } });
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 3.88, w: 10, h: 0.13, fill: { color: C.gold } });

  // ECG line decoration (decorative zigzag using shapes)
  for (let i = 0; i < 10; i++) {
    sl.addShape(pres.ShapeType.line, {
      x: i * 1.0, y: 2.6, w: 0.3, h: 0,
      line: { color: "1A7F8E55", width: 1 }
    });
  }

  sl.addText("ATRIAL FIBRILLATION", {
    x: 0.5, y: 0.7, w: 9, h: 1.1,
    fontSize: 42, bold: true, color: C.white, fontFace: "Calibri",
    align: "center", charSpacing: 3
  });

  sl.addText("A Comprehensive Seminar for PG Medicine", {
    x: 0.5, y: 1.85, w: 9, h: 0.5,
    fontSize: 18, color: C.gold, fontFace: "Calibri", align: "center"
  });

  sl.addText("Definition  •  Epidemiology  •  Pathophysiology  •  Classification  •  Clinical Features\nECG Diagnosis  •  Risk Stratification  •  Rate & Rhythm Control  •  Anticoagulation  •  Ablation", {
    x: 0.5, y: 2.45, w: 9, h: 0.8,
    fontSize: 11.5, color: "A9CCE3", fontFace: "Calibri", align: "center"
  });

  sl.addText("Reference: Harrison's Principles of Internal Medicine, 22nd Edition (2025)", {
    x: 0.5, y: 4.15, w: 9, h: 0.35,
    fontSize: 11, color: C.white, fontFace: "Calibri", align: "center", italic: true
  });

  sl.addText("2023 ACC/AHA/ACCP/HRS Guidelines incorporated", {
    x: 0.5, y: 4.58, w: 9, h: 0.3,
    fontSize: 10, color: C.gold, fontFace: "Calibri", align: "center"
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 2 — DEFINITION & OVERVIEW
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Definition & Overview", "Slide 2 / 20");

  // Large definition box
  addBox(sl, 0.3, 0.9, 9.4, 1.1, C.navy, C.gold,
    "Atrial fibrillation (AF) is the most common SUSTAINED cardiac arrhythmia, characterized by chaotic rapid atrial electrical activity with ABSENT P waves and IRREGULAR R-R intervals on ECG.",
    13, true, C.white);

  // 4 key fact boxes
  const facts = [
    ["Most common\narrhythmia", C.lightB, C.teal],
    ["Atrial rate\n350–700 / min", C.lightG, "1E8449"],
    ["Ventricular rate\nirregularly irregular", C.lightY, "B7950B"],
    ["5× increased\nstroke risk", C.lightR, C.red],
  ];
  facts.forEach((f, i) => {
    addBox(sl, 0.22 + i * 2.4, 2.15, 2.25, 0.95, f[1], f[2], f[0], 12, true, C.darkT);
  });

  // Classification brief intro
  addSectionLabel(sl, "4-STAGE CONTINUUM (2023 ACC/AHA)", 0.3, 3.3, 4.5);
  const stages = [
    ["AT RISK", C.lightB, "0.30"],
    ["PRE-AF", C.lightG, "1.55"],
    ["AF", C.lightY, "2.80"],
    ["PERMANENT AF", C.lightR, "4.05"],
  ];
  stages.forEach(s => {
    addBox(sl, parseFloat(s[2]), 3.65, 1.15, 0.72, s[1], C.teal, s[0], 10, true, C.darkT);
    if (parseFloat(s[2]) < 4.05) {
      addArrow(sl, parseFloat(s[2]) + 1.15, 4.02, parseFloat(s[2]) + 1.55, 4.02);
    }
  });

  sl.addText("AF is a disease CONTINUUM, not just an arrhythmia. Prevention, screening & therapy required at each stage.", {
    x: 0.3, y: 4.5, w: 9.4, h: 0.45,
    fontSize: 11, color: C.teal, fontFace: "Calibri", bold: true, align: "center"
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 3 — EPIDEMIOLOGY
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Epidemiology", "Slide 3 / 20");

  const stats = [
    ["~2–4%", "Prevalence in\ngeneral population"],
    ["~12%", "Prevalence in\nage ≥75 years"],
    ["~18%", "Prevalence in\nage ≥85 years"],
    ["~1/3", "AF patients\nare ≥80 years"],
  ];
  stats.forEach((s, i) => {
    sl.addShape(pres.ShapeType.rect, { x: 0.22 + i * 2.4, y: 0.88, w: 2.2, h: 1.15, fill: { color: C.navy }, line: { color: C.gold, width: 2 } });
    sl.addText(s[0], { x: 0.22 + i * 2.4, y: 0.92, w: 2.2, h: 0.58, fontSize: 28, bold: true, color: C.gold, fontFace: "Calibri", align: "center" });
    sl.addText(s[1], { x: 0.22 + i * 2.4, y: 1.5, w: 2.2, h: 0.5, fontSize: 10.5, color: C.white, fontFace: "Calibri", align: "center" });
  });

  addSectionLabel(sl, "COMORBIDITIES ASSOCIATED WITH AF", 0.3, 2.22, 5.5);
  const comor = ["Hypertension (most common)", "Coronary Heart Disease", "Obesity & Metabolic Syndrome", "Heart Failure (bidirectional)", "Sleep Apnea", "Hyperlipidemia", "Thyroid disease (hyperthyroid)", "Valvular disease (esp. Mitral Stenosis)"];
  sl.addText(makeBullets(comor.slice(0, 4), 11), { x: 0.3, y: 2.57, w: 4.4, h: 2.35, fontFace: "Calibri" });
  sl.addText(makeBullets(comor.slice(4), 11), { x: 4.9, y: 2.57, w: 4.8, h: 2.35, fontFace: "Calibri" });

  addSectionLabel(sl, "GENDER & AGE NOTE", 5.85, 2.22, 3.8);
  sl.addText("AF prevalence doubles every decade after age 50. More common in males, but women with AF have higher stroke risk and worse outcomes.", {
    x: 5.85, y: 2.57, w: 3.8, h: 1.0,
    fontSize: 10.5, color: C.darkT, fontFace: "Calibri", wrap: true
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 4 — CLASSIFICATION
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Classification of Atrial Fibrillation", "Slide 4 / 20");

  // Classic classification
  addSectionLabel(sl, "TRADITIONAL CLASSIFICATION (Duration-Based)", 0.3, 0.85, 6.0);

  const trad = [
    ["PAROXYSMAL", "Self-terminating within 7 days\n(usually <48 h)\nMay recur", C.lightB, C.teal],
    ["PERSISTENT", "Lasts >7 days\nRequires cardioversion\n(elec. or pharmacologic)", C.lightY, "D4AC0D"],
    ["LONG-STANDING PERSISTENT", "Continuous AF >12 months;\nRhythm control still pursued", C.lightR, C.red],
    ["PERMANENT", "Accepted by patient & physician;\nNo further rhythm control", C.lgray, C.gray],
  ];
  trad.forEach((t, i) => {
    addBox(sl, 0.22 + i * 2.39, 1.2, 2.28, 1.45, t[2], t[3], `${t[0]}\n\n${t[1]}`, 9.5, false, C.darkT);
  });

  // New 4-stage classification
  addSectionLabel(sl, "NEW 4-STAGE CLASSIFICATION (ACC/AHA 2023) — Disease Continuum", 0.3, 2.88, 9.4);

  const newStages = [
    ["STAGE 1\nAt Risk for AF", "Risk factors: HTN, obesity,\nsleep apnea, smoking, alcohol\nNo AF yet — PREVENT", C.lightB, C.teal, "Prevention\nRisk factor\nmodification"],
    ["STAGE 2\nPre-AF", "Structural/electrical changes:\nAtrial enlargement, PACs,\nshort runs — Monitor closely", C.lightG, "1E8449", "Screening\nMonitoring"],
    ["STAGE 3\nAF", "Documented AF (paroxysmal,\npersistent, or long-standing)\nFull treatment required", C.lightY, "B7950B", "Rate control\nRhythm control\nAnticoagulation"],
    ["STAGE 4\nPermanent AF", "Accepted chronic AF; rhythm\ncontrol abandoned; focus\non rate + anticoagulation", C.lightR, C.red, "Rate control\nAnticoagulation\nQoL"],
  ];
  newStages.forEach((s, i) => {
    addBox(sl, 0.22 + i * 2.39, 3.22, 2.28, 1.58, s[2], s[3], `${s[0]}\n${s[1]}`, 8.5, false, C.darkT);
    addBox(sl, 0.22 + i * 2.39, 4.87, 2.28, 0.52, s[3], s[3], s[4], 8, true, C.white);
    if (i < 3) addArrow(sl, 0.22 + i * 2.39 + 2.28, 4.0, 0.22 + (i + 1) * 2.39, 4.0);
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 5 — PATHOPHYSIOLOGY
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Pathophysiology", "Slide 5 / 20");

  // Left column: Triggers
  addSectionLabel(sl, "TRIGGERS", 0.25, 0.85, 2.9);
  addBox(sl, 0.25, 1.18, 2.9, 1.8, C.lightB, C.teal,
    "• Pulmonary vein ectopy\n  (primary source)\n• PACs triggering reentry\n• Autonomic changes\n• Electrolyte imbalance\n• Alcohol (holiday heart)", 10.5, false, C.darkT);

  // Middle: Substrate
  addSectionLabel(sl, "SUBSTRATE", 3.35, 0.85, 3.3);
  addBox(sl, 3.35, 1.18, 3.3, 1.8, C.lightY, "B7950B",
    "• Atrial fibrosis & structural remodeling\n• Shortened atrial refractory periods\n  (electrical remodeling)\n• Conduction heterogeneity\n• Increased atrial size / dilation\n• Age-related changes", 10.5, false, C.darkT);

  // Right: Perpetuators
  addSectionLabel(sl, "PERPETUATORS", 6.85, 0.85, 2.9);
  addBox(sl, 6.85, 1.18, 2.9, 1.8, C.lightR, C.red,
    "• Autonomic imbalance\n• Inflammation\n  (CRP, IL-6 elevated)\n• Oxidative stress\n• Valvular disease\n• Elevated filling pressure", 10.5, false, C.darkT);

  // Main mechanism box
  addSectionLabel(sl, "MECHANISM: MULTIPLE WAVELET REENTRY", 0.25, 3.1, 5.5);
  addBox(sl, 0.25, 3.42, 5.5, 1.65, C.lightG, "1E8449",
    "Multiple simultaneous wavelets of depolarization circulate chaotically through the atria, perpetuated by short refractory periods and slow/inhomogeneous conduction. No single stable reentrant circuit — hence 'fibrillation'.\n\nPulmonary vein isolation (PVI) is the cornerstone of ablation based on this mechanism.", 10.5, false, C.darkT);

  // Key concept box right
  addSectionLabel(sl, "KEY CONCEPT: AF BEGETS AF", 5.95, 3.1, 3.8);
  addBox(sl, 5.95, 3.42, 3.8, 1.65, C.lightR, C.red,
    "Prolonged AF causes progressive electrical & structural atrial remodeling → lowers threshold for AF → makes AF harder to terminate and maintain sinus rhythm. This is the basis for early rhythm control!", 10.5, false, C.darkT);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 6 — RISK FACTORS & LIFESTYLE
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Risk Factors & Lifestyle Impact", "Slide 6 / 20");

  addSectionLabel(sl, "MODIFIABLE RISK FACTORS", 0.25, 0.85, 4.6);
  const modRF = [
    ["Obesity\n(BMI > 30)", C.lightR, C.red],
    ["Hypertension\n(most common)", C.lightB, C.teal],
    ["Smoking", C.lightY, "B7950B"],
    ["Alcohol", C.lightR, C.red],
  ];
  const modRF2 = [
    ["Sleep Apnea\n(OSA)", C.lightG, "1E8449"],
    ["Physical\nInactivity", C.lightB, C.teal],
    ["Diabetes\nMellitus", C.lightY, "B7950B"],
    ["Stress /\nPsychological", C.lightR, C.red],
  ];
  modRF.forEach((r, i) => addBox(sl, 0.25 + i * 1.15, 1.2, 1.08, 0.8, r[1], r[2], r[0], 9, true, C.darkT));
  modRF2.forEach((r, i) => addBox(sl, 0.25 + i * 1.15, 2.08, 1.08, 0.8, r[1], r[2], r[0], 9, true, C.darkT));

  addSectionLabel(sl, "NON-MODIFIABLE", 4.95, 0.85, 2.5);
  sl.addText(makeBullets(["Increasing age", "Male sex", "Family history / Genetics", "Structural heart disease", "Congenital heart disease"], 10.5), {
    x: 4.95, y: 1.2, w: 2.5, h: 1.65, fontFace: "Calibri"
  });

  addSectionLabel(sl, "EXERCISE & AF RISK", 7.55, 0.85, 2.2);
  addBox(sl, 7.55, 1.2, 2.2, 1.65, C.lightY, "B7950B",
    "MALES: U-shaped curve\n• Very low exercise → ↑AF\n• Extreme endurance → ↑AF\n• Moderate = lowest risk\n\nFEMALES: Linear — more exercise = less AF", 9.5, false, C.darkT);

  addSectionLabel(sl, "IMPORTANT NOTE ON CAFFEINE", 0.25, 3.0, 4.5);
  addBox(sl, 0.25, 3.33, 4.5, 0.9, C.lightG, "1E8449",
    "Large cohort studies show MODEST CAFFEINE INTAKE is associated with a DECREASED risk of AF — contrary to popular belief. Caffeine restriction is NOT routinely recommended.", 10.5, false, C.darkT);

  addSectionLabel(sl, "UPSTREAM THERAPY PRINCIPLE", 5.0, 3.0, 4.75);
  addBox(sl, 5.0, 3.33, 4.75, 0.9, C.lightB, C.teal,
    "Aggressive treatment of modifiable risk factors (weight loss, BP control, OSA treatment, alcohol reduction) can SUBSTANTIALLY reduce AF episodes — this is 'Upstream Therapy' and is a Class I recommendation.", 10.5, false, C.darkT);

  addBox(sl, 0.25, 4.32, 9.5, 0.68, C.navy, C.gold,
    "KEY MESSAGE: AF management is not just drugs and procedures — lifestyle modification is a cornerstone of treatment!", 11.5, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 7 — CLINICAL FEATURES & SYMPTOMS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Clinical Features & Presentation", "Slide 7 / 20");

  addSectionLabel(sl, "SYMPTOMS (Variable — can be asymptomatic!)", 0.25, 0.85, 6.5);
  const symptoms = [
    ["Palpitations", "Most common in young;\nless prominent in elderly", C.lightB, C.teal],
    ["Dyspnea /\nBreathlessness", "Exertional or rest;\ndue to rate + loss of AV sync", C.lightY, "B7950B"],
    ["Fatigue /\nExercise intolerance", "Reduced cardiac output;\ntachycardia-mediated", C.lightG, "1E8449"],
    ["Chest discomfort", "May indicate ischemia\nor rate-related pain", C.lightR, C.red],
    ["Dizziness /\nLight-headedness", "Reduced cerebral flow;\ncommon in elderly", C.lightB, C.teal],
  ];
  symptoms.forEach((s, i) => {
    addBox(sl, 0.22 + i * 1.91, 1.18, 1.84, 1.2, s[2], s[3], `${s[0]}\n\n${s[1]}`, 9, false, C.darkT);
  });

  addSectionLabel(sl, "SERIOUS PRESENTATIONS", 0.25, 2.57, 4.5);
  const serious = [
    "Acute pulmonary edema — abrupt loss of atrial kick in stiff LV",
    "Stroke / TIA — first presentation in up to 15-20% of cases",
    "Syncope / Fall (esp. in elderly) — reduced cardiac output",
    "Tachycardia-induced cardiomyopathy — prolonged rapid rates → dilated CMP",
  ];
  sl.addText(makeBullets(serious, 10.5, C.red), { x: 0.25, y: 2.9, w: 4.5, h: 1.85, fontFace: "Calibri" });

  addSectionLabel(sl, "PHYSICAL EXAMINATION", 4.9, 2.57, 4.85);
  const exam = [
    "Irregularly irregular pulse — hallmark finding",
    "Pulse deficit (apical > radial rate)",
    "Variation in S1 intensity",
    "Absent a-wave in JVP",
    "Signs of heart failure (crepitations, raised JVP, edema)",
    "Signs of underlying cause (thyroid, valvular)",
  ];
  sl.addText(makeBullets(exam, 10.5), { x: 4.9, y: 2.9, w: 4.85, h: 1.85, fontFace: "Calibri" });

  addBox(sl, 0.25, 4.82, 9.5, 0.48, C.teal, C.teal,
    "IMPORTANT: In elderly patients — palpitations are LESS prominent; AF may present as syncope, fall, stroke, or cognitive decline!", 11, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 8 — ECG DIAGNOSIS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "ECG Diagnosis of AF", "Slide 8 / 20");

  // Main ECG features box
  addSectionLabel(sl, "CLASSIC ECG FEATURES OF AF", 0.25, 0.85, 5.5);

  const ecgFeatures = [
    ["1. ABSENT P WAVES", "No discrete P waves; replaced by chaotic fibrillatory (f) waves at 350-700/min", C.lightR, C.red],
    ["2. IRREGULAR R-R INTERVALS", "Ventricular response is \"irregularly irregular\" — hallmark feature on ECG", C.lightB, C.teal],
    ["3. FIBRILLATORY BASELINE", "Fine or coarse oscillations replacing isoelectric baseline; best seen in V1, II", C.lightY, "B7950B"],
    ["4. NORMAL QRS MORPHOLOGY", "QRS usually narrow (unless BBB, WPW, or aberrancy present)", C.lightG, "1E8449"],
  ];
  ecgFeatures.forEach((f, i) => {
    addBox(sl, 0.25, 1.18 + i * 0.95, 9.5, 0.88, f[2], f[3], `${f[0]}:  ${f[1]}`, 11, false, C.darkT);
  });

  addSectionLabel(sl, "SPECIAL ECG PATTERNS", 0.25, 5.0, 4.5);
  sl.addText("• COARSE AF: larger f waves — suggests ↑atrial pressure or recent onset\n• FINE AF: smaller f waves — suggests long-standing AF or dilated atria\n• WPW + AF: Irregular WIDE complex with delta waves — DANGEROUS! Rate can exceed 300/min → VF", {
    x: 0.25, y: 5.0, w: 9.5, h: 0.5,
    fontSize: 9.5, color: C.navy, fontFace: "Calibri"
  });
  // This slide is compact with 4 boxes + footer note
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 9 — INVESTIGATIONS & WORKUP
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Investigations & Initial Workup", "Slide 9 / 20");

  addSectionLabel(sl, "MANDATORY INVESTIGATIONS", 0.25, 0.85, 4.6);
  const mandatory = [
    "12-lead ECG — confirm AF, assess rate, look for ischemia / WPW",
    "Echocardiogram (Echo) — LV function, valve disease, LA size, thrombus",
    "Thyroid function tests (TFTs) — hyperthyroidism triggers AF",
    "Complete Blood Count (CBC) — anemia, infection",
    "Renal function, electrolytes — for drug dosing, rate control",
    "Liver function tests — warfarin / amiodarone dosing",
    "INR / coagulation — if starting anticoagulation",
    "Blood glucose / HbA1c — metabolic assessment",
  ];
  sl.addText(makeBullets(mandatory, 11), { x: 0.25, y: 1.18, w: 4.6, h: 3.6, fontFace: "Calibri" });

  addSectionLabel(sl, "ADDITIONAL / SELECTIVE INVESTIGATIONS", 5.05, 0.85, 4.7);
  const additional = [
    "Holter monitoring / Ambulatory ECG — for paroxysmal AF detection",
    "Event recorder / Loop recorder — if symptoms infrequent",
    "Exercise stress test — if rate control adequacy suspected",
    "Cardiac MRI — atrial fibrosis assessment pre-ablation",
    "Transesophageal Echo (TEE) — rule out LA appendage thrombus before cardioversion",
    "CT angiography (delayed) — LA thrombus with high sensitivity",
    "Sleep study (polysomnography) — if OSA suspected",
    "Chest X-ray — cardiomegaly, pulmonary edema",
  ];
  sl.addText(makeBullets(additional, 11), { x: 5.05, y: 1.18, w: 4.7, h: 3.6, fontFace: "Calibri" });

  addBox(sl, 0.25, 4.92, 9.5, 0.48, C.teal, C.teal,
    "TEE or cardiac CT is required before cardioversion if AF duration >48 h or unknown, to exclude LA appendage thrombus!", 11, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 10 — THROMBOEMBOLIC RISK (CHA2DS2-VASc)
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Thromboembolic Risk — CHA₂DS₂-VASc Score", "Slide 10 / 20");

  // Score table
  addSectionLabel(sl, "CHA₂DS₂-VASc SCORING", 0.25, 0.85, 5.5);

  const rows = [
    ["C", "Congestive Heart Failure", "1"],
    ["H", "Hypertension", "1"],
    ["A₂", "Age ≥ 75 years", "2"],
    ["D", "Diabetes Mellitus", "1"],
    ["S₂", "Stroke / TIA / thromboembolism (prior)", "2"],
    ["V", "Vascular disease (MI, PAD, aortic plaque)", "1"],
    ["A", "Age 65–74 years", "1"],
    ["Sc", "Sex category (Female)", "1"],
  ];

  // Table header
  sl.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.18, w: 5.5, h: 0.32, fill: { color: C.navy } });
  sl.addText("Letter  |  Risk Factor  |  Score", { x: 0.3, y: 1.18, w: 5.4, h: 0.32, fontSize: 10, bold: true, color: C.white, fontFace: "Calibri", valign: "middle" });

  rows.forEach((r, i) => {
    const fill = i % 2 === 0 ? C.lightB : C.white;
    sl.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.5 + i * 0.34, w: 5.5, h: 0.34, fill: { color: fill }, line: { color: "BFC9CA", width: 0.5 } });
    sl.addText(r[0], { x: 0.3, y: 1.5 + i * 0.34, w: 0.5, h: 0.34, fontSize: 11, bold: true, color: C.teal, fontFace: "Calibri", valign: "middle" });
    sl.addText(r[1], { x: 0.85, y: 1.5 + i * 0.34, w: 4.1, h: 0.34, fontSize: 10.5, color: C.darkT, fontFace: "Calibri", valign: "middle" });
    sl.addText(r[2], { x: 5.0, y: 1.5 + i * 0.34, w: 0.75, h: 0.34, fontSize: 12, bold: true, color: C.red, fontFace: "Calibri", align: "center", valign: "middle" });
  });
  sl.addShape(pres.ShapeType.rect, { x: 0.25, y: 4.22, w: 5.5, h: 0.32, fill: { color: C.gold } });
  sl.addText("MAXIMUM SCORE = 9", { x: 0.3, y: 4.22, w: 5.4, h: 0.32, fontSize: 11, bold: true, color: C.navy, fontFace: "Calibri", align: "center", valign: "middle" });

  // Right: interpretation + anticoagulation decision
  addSectionLabel(sl, "ANTICOAGULATION DECISION", 6.0, 0.85, 3.75);
  const decisions = [
    ["Score 0\n(Male)", "No anticoagulation\nneeded", C.lightG, "1E8449"],
    ["Score 1\n(Male)", "Consider OAC\n(individualize)", C.lightY, "B7950B"],
    ["Score ≥ 2\n(Male)\nScore ≥ 1\n(Female)", "ANTICOAGULATION\nRECOMMENDED\n(Class I)", C.lightR, C.red],
  ];
  decisions.forEach((d, i) => addBox(sl, 6.0, 1.18 + i * 1.07, 3.75, 1.0, d[2], d[3], `${d[0]}\n→ ${d[1]}`, 10, true, C.darkT));

  addBox(sl, 6.0, 4.4, 3.75, 0.62, C.navy, C.gold,
    "All patients ≥75 yrs have CHA₂DS₂-VASc ≥2 automatically — anticoagulate regardless of AF type!", 10, true, C.white);

  addBox(sl, 0.25, 4.62, 5.5, 0.62, C.teal, C.teal,
    "Nonvalvular AF: 5× increased stroke risk. Valvular AF (MS, mechanical valve): always anticoagulate!", 10.5, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 11 — BLEEDING RISK (HAS-BLED)
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Bleeding Risk — HAS-BLED Score", "Slide 11 / 20");

  addSectionLabel(sl, "HAS-BLED SCORING SYSTEM", 0.25, 0.85, 5.5);

  const hasbled = [
    ["H", "Hypertension (uncontrolled, SBP >160)", "1"],
    ["A", "Abnormal renal / liver function", "1 each (max 2)"],
    ["S", "Stroke history", "1"],
    ["B", "Bleeding history or predisposition", "1"],
    ["L", "Labile INR (if on warfarin, TTR <60%)", "1"],
    ["E", "Elderly (age >65 years)", "1"],
    ["D", "Drugs (antiplatelet, NSAIDs) or alcohol", "1 each (max 2)"],
  ];

  sl.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.18, w: 5.5, h: 0.3, fill: { color: C.navy } });
  sl.addText("Factor  |  Definition  |  Points", { x: 0.3, y: 1.18, w: 5.4, h: 0.3, fontSize: 10, bold: true, color: C.white, fontFace: "Calibri", valign: "middle" });
  hasbled.forEach((h, i) => {
    sl.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.48 + i * 0.38, w: 5.5, h: 0.38, fill: { color: i % 2 === 0 ? C.lightR : C.white }, line: { color: "BFC9CA", width: 0.5 } });
    sl.addText(h[0], { x: 0.3, y: 1.48 + i * 0.38, w: 0.4, h: 0.38, fontSize: 11, bold: true, color: C.red, fontFace: "Calibri", valign: "middle" });
    sl.addText(h[1], { x: 0.76, y: 1.48 + i * 0.38, w: 3.8, h: 0.38, fontSize: 10, color: C.darkT, fontFace: "Calibri", valign: "middle" });
    sl.addText(h[2], { x: 4.6, y: 1.48 + i * 0.38, w: 1.15, h: 0.38, fontSize: 10, bold: true, color: C.red, fontFace: "Calibri", align: "center", valign: "middle" });
  });

  // Right panel
  addSectionLabel(sl, "INTERPRETATION", 5.95, 0.85, 3.8);
  const interp = [
    ["0–2", "Low bleeding risk\nAnticoagulate", C.lightG, "1E8449"],
    ["3", "Moderate risk\nCaution, review modifiable factors", C.lightY, "B7950B"],
    ["≥ 4", "High risk\nNOT a contraindication — correct modifiable factors!", C.lightR, C.red],
  ];
  interp.forEach((it, i) => addBox(sl, 5.95, 1.18 + i * 0.9, 3.8, 0.84, it[2], it[3], `Score ${it[0]}:  ${it[1]}`, 10, false, C.darkT));

  addBox(sl, 5.95, 3.9, 3.8, 0.62, C.teal, C.teal,
    "HAS-BLED is NOT used to withhold anticoagulation — it identifies CORRECTABLE risk factors (e.g., uncontrolled BP, NSAIDs, alcohol).", 9.5, true, C.white);

  addSectionLabel(sl, "MODIFIABLE HAS-BLED FACTORS TO CORRECT", 0.25, 4.12, 5.5);
  sl.addText("• Control BP  • Reduce alcohol  • Stop NSAIDs/antiplatelets  • Correct anaemia  • Stabilize INR (or switch to DOAC)", {
    x: 0.25, y: 4.45, w: 5.5, h: 0.55,
    fontSize: 10.5, color: C.darkT, fontFace: "Calibri"
  });

  addBox(sl, 0.25, 5.05, 9.5, 0.38, C.navy, C.gold,
    "KEY PRINCIPLE: Net clinical benefit of anticoagulation almost always outweighs bleeding risk in high-stroke-risk patients!", 10.5, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 12 — OVERVIEW OF MANAGEMENT
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Overview of Management — 3 Pillars", "Slide 12 / 20");

  // Three pillars
  const pillars = [
    ["PILLAR 1\nSYMPTOM CONTROL", "Rate Control\n+\nRhythm Control", C.navy, C.gold, "Rate-lowering drugs,\ncardioversion, ablation"],
    ["PILLAR 2\nSTROKE PREVENTION", "Anticoagulation\n(CHA₂DS₂-VASc guided)", C.teal, C.white, "Warfarin / DOACs,\nWatchman device"],
    ["PILLAR 3\nRISK FACTOR MODIFICATION", "Upstream Therapy\n+\nLifestyle Modification", C.red, C.white, "Weight loss, BP control,\nOSA, alcohol, exercise"],
  ];
  pillars.forEach((p, i) => {
    sl.addShape(pres.ShapeType.rect, { x: 0.25 + i * 3.17, y: 0.88, w: 3.0, h: 0.85, fill: { color: p[2] }, line: { color: p[3], width: 2 } });
    sl.addText(p[0], { x: 0.25 + i * 3.17, y: 0.88, w: 3.0, h: 0.85, fontSize: 12, bold: true, color: p[3], fontFace: "Calibri", align: "center", valign: "middle" });
    addBox(sl, 0.25 + i * 3.17, 1.8, 3.0, 0.72, C.lightB, p[2], p[1], 11, true, C.darkT);
    addBox(sl, 0.25 + i * 3.17, 2.6, 3.0, 0.65, C.white, p[2], p[4], 10, false, C.darkT);
  });

  // Acute Management Flowchart
  addSectionLabel(sl, "ACUTE MANAGEMENT FLOWCHART", 0.25, 3.38, 9.5);

  addBox(sl, 0.25, 3.72, 9.5, 0.48, C.navy, C.navy, "NEW ONSET AF — Is patient HEMODYNAMICALLY UNSTABLE?  (Hypotension, pulm. edema, acute ischemia)", 11, true, C.white);
  addArrow(sl, 2.2, 4.2, 2.2, 4.52);
  addArrow(sl, 7.5, 4.2, 7.5, 4.52);

  addBox(sl, 0.25, 4.52, 4.1, 0.72, C.lightR, C.red, "YES → EMERGENT ELECTRICAL\nCARDIOVERSION\n(QRS-synchronized DC shock)", 10.5, true, C.red);
  addBox(sl, 4.5, 4.52, 5.25, 0.72, C.lightG, "1E8449", "NO → Rate control first → Consider anticoagulation → Assess rhythm control strategy → Evaluate/correct risk factors", 10, false, C.darkT);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 13 — RATE CONTROL
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Rate Control Strategy", "Slide 13 / 20");

  addSectionLabel(sl, "RATE CONTROL TARGETS", 0.25, 0.85, 3.2);
  addBox(sl, 0.25, 1.18, 3.2, 1.08, C.lightB, C.teal,
    "LENIENT: HR < 110 bpm at rest\n(preferred if asymptomatic)\n\nSTRICT: HR < 80 bpm at rest\n(if symptomatic or LV dysfunction)", 10.5, false, C.darkT);

  addSectionLabel(sl, "RATE CONTROL DRUGS", 3.65, 0.85, 6.1);

  const drugs = [
    ["BETA-BLOCKERS\n(1st line)", "Metoprolol, Bisoprolol, Carvedilol\n• Best for high sympathetic tone\n• Safe in HF with EF (HFrEF)\n• Avoid in acute decompensation, severe asthma", C.lightB, C.teal],
    ["NON-DIHYDROPYRIDINE\nCCBs", "Verapamil, Diltiazem\n• Effective rate control\n• CONTRAINDICATED in HFrEF!\n• Avoid in decompensated HF, WPW", C.lightY, "B7950B"],
    ["DIGOXIN", "0.125–0.25 mg daily\n• Add-on in HFrEF or hypotension\n• Poor rate control with exercise\n• Monitor toxicity (narrow TI)", C.lightG, "1E8449"],
    ["AMIODARONE\n(rescue / ICU)", "IV amiodarone for rate control\nwhen other drugs fail or contraindicated\n• Multiple side effects (chronic use)", C.lightR, C.red],
  ];
  drugs.forEach((d, i) => {
    addBox(sl, 3.65 + (i % 2) * 3.05, 1.18 + Math.floor(i / 2) * 1.45, 2.98, 1.38, d[2], d[3], `${d[0]}\n${d[1]}`, 9, false, C.darkT);
  });

  addSectionLabel(sl, "SPECIAL SITUATIONS IN RATE CONTROL", 0.25, 3.56, 9.5);
  const special = [
    ["WPW + AF", "AVOID AV nodal blockers (digoxin, CCB, beta-blockers)\nUse Procainamide / Ibutilide / Electrical cardioversion → Ablation", C.lightR, C.red],
    ["Pre-excited AF", "Wide complex irregular tachycardia >250/min → can cause VF\nIV Procainamide; Emergency cardioversion if hemodynamically unstable", C.lightR, C.red],
  ];
  special.forEach((s, i) => addBox(sl, 0.25 + i * 4.88, 3.9, 4.7, 0.88, s[2], s[3], `${s[0]}: ${s[1]}`, 9.5, false, C.darkT));

  addBox(sl, 0.25, 4.88, 9.5, 0.42, C.navy, C.gold,
    "Rate control alone (vs rhythm control) has NOT been shown to be inferior for mortality in stable patients — AFFIRM Trial", 10.5, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 14 — RHYTHM CONTROL & CARDIOVERSION
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Rhythm Control & Cardioversion", "Slide 14 / 20");

  addSectionLabel(sl, "WHEN TO PURSUE RHYTHM CONTROL", 0.25, 0.85, 5.5);
  const indications = [
    "Persistent or bothersome symptoms despite rate control",
    "Young patients with first presentation",
    "Tachycardia-induced cardiomyopathy (reversible with rhythm control)",
    "AF in structurally normal heart",
    "Difficulty achieving adequate rate control",
    "Patient preference",
    "EARLY RHYTHM CONTROL (EAST-AFNET 4): reduces cardiovascular events if initiated within 1 year of AF diagnosis",
  ];
  sl.addText(makeBullets(indications, 10.5), { x: 0.25, y: 1.18, w: 5.5, h: 2.75, fontFace: "Calibri" });

  addSectionLabel(sl, "PHARMACOLOGIC CARDIOVERSION", 5.95, 0.85, 3.8);
  addBox(sl, 5.95, 1.18, 3.8, 1.55, C.lightB, C.teal,
    "IBUTILIDE (IV) — Class III\n• Most effective for acute conversion\n• Risk: Torsades de Pointes\n• AVOID: prolonged QT, severe LV dysfunction\n\nFlecainide / Propafenone — Pill-in-pocket\n• Only in structurally normal heart\n• Patient self-administers at onset of AF", 9.5, false, C.darkT);

  addSectionLabel(sl, "ELECTRICAL CARDIOVERSION", 5.95, 2.83, 3.8);
  addBox(sl, 5.95, 3.16, 3.8, 0.9, C.lightY, "B7950B",
    "QRS-synchronized DC shock (100–200 J biphasic)\nSedate patient first\nIf AF >48h or unknown: TEE/anticoag. before CV\nMust anticoagulate 4 weeks AFTER CV (atrial stunning)", 9.5, false, C.darkT);

  // Anticoag around CV flowchart
  addSectionLabel(sl, "ANTICOAGULATION AROUND CARDIOVERSION", 0.25, 4.15, 5.5);
  addBox(sl, 0.25, 4.48, 2.55, 0.78, C.lightG, "1E8449", "AF < 48h\nAnticoagulate &\nCardiovert immediately", 9.5, false, C.darkT);
  addBox(sl, 2.95, 4.48, 2.8, 0.78, C.lightR, C.red, "AF > 48h or unknown\nTEE to exclude LA thrombus\nOR anticoag. ≥3 weeks, then CV", 9.5, false, C.darkT);
  addBox(sl, 0.25, 4.48, 5.5, 0.78, C.white, C.white, "", 9); // spacer
  // redo the boxes without overlap
  sl.addShape(pres.ShapeType.roundRect, { x: 0.25, y: 4.48, w: 2.55, h: 0.78, fill: { color: C.lightG }, line: { color: "1E8449", width: 1 }, rectRadius: 0.07 });
  sl.addText("AF < 48h\nAnticoagulate &\nCardiovert soon", { x: 0.25, y: 4.48, w: 2.55, h: 0.78, fontSize: 9.5, color: C.darkT, fontFace: "Calibri", align: "center", valign: "middle" });
  sl.addShape(pres.ShapeType.roundRect, { x: 3.0, y: 4.48, w: 2.7, h: 0.78, fill: { color: C.lightR }, line: { color: C.red, width: 1 }, rectRadius: 0.07 });
  sl.addText("AF > 48h or UNKNOWN\nTEE or ≥3wk anticoag\nthen cardioversion", { x: 3.0, y: 4.48, w: 2.7, h: 0.78, fontSize: 9.5, color: C.darkT, fontFace: "Calibri", align: "center", valign: "middle" });
  sl.addShape(pres.ShapeType.roundRect, { x: 5.85, y: 4.48, w: 3.9, h: 0.78, fill: { color: C.navy }, line: { color: C.gold, width: 1 }, rectRadius: 0.07 });
  sl.addText("BOTH: Anticoagulate ≥4 weeks AFTER cardioversion (atrial stunning!) — then reassess CHA₂DS₂-VASc", { x: 5.85, y: 4.48, w: 3.9, h: 0.78, fontSize: 9.5, bold: true, color: C.gold, fontFace: "Calibri", align: "center", valign: "middle" });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 15 — ANTIARRHYTHMIC DRUGS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Antiarrhythmic Drugs for Rhythm Control", "Slide 15 / 20");

  addSectionLabel(sl, "CHOICE OF AAD BASED ON CARDIAC SUBSTRATE", 0.25, 0.85, 9.5);

  const aadRows = [
    { drug: "Flecainide\n(Class IC)", use: "No structural heart disease (SHD)", dose: "100–150 mg BD", key: "AVOID in CAD, HF, WPW; most effective in normal heart", fill: C.lightG, border: "1E8449" },
    { drug: "Propafenone\n(Class IC)", use: "No structural heart disease", dose: "150–300 mg TDS", key: "AVOID in SHD; minor beta-blocking effect; same as flecainide", fill: C.lightG, border: "1E8449" },
    { drug: "Sotalol\n(Class III)", use: "CAD, mild LVH (EF >40%)", dose: "80–160 mg BD", key: "QT monitoring essential; prolongs QT → TdP risk; also beta-blocker", fill: C.lightY, border: "B7950B" },
    { drug: "Dronedarone\n(Class III)", use: "Non-permanent AF, no severe HF", dose: "400 mg BD", key: "AVOID in permanent AF, severe HF; ↓hospitalization; monitor liver", fill: C.lightY, border: "B7950B" },
    { drug: "Amiodarone\n(Class III)", use: "Any structural disease, HFrEF", dose: "200 mg OD (maintenance)", key: "Most effective AAD; MULTIPLE toxicities (thyroid, pulm, liver, cornea, skin); last resort", fill: C.lightR, border: C.red },
    { drug: "Dofetilide\n(Class III)", use: "HF, CAD", dose: "Renal dose-adjusted", key: "Torsades risk — in-hospital initiation required; rarely used", fill: C.lightR, border: C.red },
  ];

  // Table headers
  sl.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.18, w: 9.5, h: 0.3, fill: { color: C.navy } });
  ["Drug (Class)", "Indication", "Dose", "Key Points"].forEach((h, i) => {
    const widths = [1.9, 2.0, 1.5, 4.1];
    const xpos = [0.28, 2.18, 4.18, 5.68];
    sl.addText(h, { x: xpos[i], y: 1.18, w: widths[i], h: 0.3, fontSize: 9.5, bold: true, color: C.white, fontFace: "Calibri", valign: "middle" });
  });

  aadRows.forEach((r, i) => {
    sl.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.48 + i * 0.53, w: 9.5, h: 0.53, fill: { color: r.fill }, line: { color: "BFC9CA", width: 0.5 } });
    sl.addText(r.drug, { x: 0.28, y: 1.48 + i * 0.53, w: 1.9, h: 0.53, fontSize: 9.5, bold: true, color: r.border, fontFace: "Calibri", valign: "middle" });
    sl.addText(r.use, { x: 2.18, y: 1.48 + i * 0.53, w: 2.0, h: 0.53, fontSize: 9, color: C.darkT, fontFace: "Calibri", valign: "middle", wrap: true });
    sl.addText(r.dose, { x: 4.18, y: 1.48 + i * 0.53, w: 1.5, h: 0.53, fontSize: 9, color: C.darkT, fontFace: "Calibri", valign: "middle" });
    sl.addText(r.key, { x: 5.68, y: 1.48 + i * 0.53, w: 4.07, h: 0.53, fontSize: 8.5, color: C.darkT, fontFace: "Calibri", valign: "middle", wrap: true });
  });

  addBox(sl, 0.25, 4.7, 9.5, 0.65, C.navy, C.gold,
    "RULE: In structural heart disease (HFrEF/CAD), use Amiodarone or Dofetilide.\nIn no SHD: Flecainide or Propafenone preferred (most effective, best tolerated).", 10, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 16 — ANTICOAGULATION: WARFARIN vs DOACs
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Anticoagulation — Warfarin vs DOACs", "Slide 16 / 20");

  addSectionLabel(sl, "WARFARIN", 0.25, 0.85, 4.6);
  const warfPoints = [
    "Vitamin K antagonist — inhibits Factors II, VII, IX, X",
    "Target INR: 2–3 (2–2.5 in elderly)",
    "Requires regular INR monitoring (monthly)",
    "Multiple drug & food interactions (dietary Vit K)",
    "Dose 2–5 mg/day (lower in elderly)",
    "Risk of osteoporosis with long-term use",
    "INDICATED in mechanical valves & Mitral Stenosis (moderate-severe)",
  ];
  sl.addText(makeBullets(warfPoints, 10), { x: 0.25, y: 1.18, w: 4.6, h: 2.75, fontFace: "Calibri" });

  addSectionLabel(sl, "DOACs (PREFERRED in non-valvular AF)", 5.05, 0.85, 4.7);
  const doacTable = [
    ["Dabigatran", "Direct thrombin inhibitor", "150 mg BD (110 mg BD if >80 yrs)"],
    ["Rivaroxaban", "Factor Xa inhibitor", "20 mg OD with evening meal"],
    ["Apixaban", "Factor Xa inhibitor", "5 mg BD (2.5 mg BD if ≥2 criteria*)"],
    ["Edoxaban", "Factor Xa inhibitor", "60 mg OD (30 mg if CrCl 15-50)"],
  ];
  sl.addShape(pres.ShapeType.rect, { x: 5.05, y: 1.18, w: 4.7, h: 0.28, fill: { color: C.teal } });
  sl.addText("Drug  |  Mechanism  |  Dose", { x: 5.1, y: 1.18, w: 4.6, h: 0.28, fontSize: 9, bold: true, color: C.white, fontFace: "Calibri", valign: "middle" });
  doacTable.forEach((d, i) => {
    sl.addShape(pres.ShapeType.rect, { x: 5.05, y: 1.46 + i * 0.42, w: 4.7, h: 0.42, fill: { color: i % 2 === 0 ? C.lightB : C.white }, line: { color: "BFC9CA", width: 0.5 } });
    sl.addText(d[0], { x: 5.08, y: 1.46 + i * 0.42, w: 1.2, h: 0.42, fontSize: 9, bold: true, color: C.teal, fontFace: "Calibri", valign: "middle" });
    sl.addText(d[1], { x: 6.3, y: 1.46 + i * 0.42, w: 1.5, h: 0.42, fontSize: 8.5, color: C.darkT, fontFace: "Calibri", valign: "middle" });
    sl.addText(d[2], { x: 7.82, y: 1.46 + i * 0.42, w: 1.93, h: 0.42, fontSize: 8.5, color: C.darkT, fontFace: "Calibri", valign: "middle", wrap: true });
  });
  sl.addText("*Apixaban dose reduction: ≥2 of: age ≥80, weight ≤60kg, creatinine ≥1.5 mg/dL", {
    x: 5.05, y: 3.15, w: 4.7, h: 0.28, fontSize: 8, color: C.gray, fontFace: "Calibri", italic: true
  });

  addSectionLabel(sl, "DOACs vs WARFARIN — KEY ADVANTAGES", 5.05, 3.48, 4.7);
  const doacAdv = ["No routine monitoring needed", "Fewer drug interactions", "No dietary restrictions", "Similar or better stroke prevention", "Similar or LESS bleeding (especially ICH)", "Rapid onset and offset"];
  sl.addText(makeBullets(doacAdv, 9.5), { x: 5.05, y: 3.78, w: 4.7, h: 1.42, fontFace: "Calibri" });

  addSectionLabel(sl, "WHEN TO USE WARFARIN (Not DOACs)", 0.25, 4.0, 4.6);
  sl.addText("• Mechanical prosthetic heart valves\n• Moderate-to-severe Mitral Stenosis (rheumatic)\n• Severe CKD (CrCl <15 mL/min) — most DOACs not studied\n• DOACs not available / unaffordable", {
    x: 0.25, y: 4.3, w: 4.6, h: 0.9,
    fontSize: 9.5, color: C.darkT, fontFace: "Calibri"
  });

  addBox(sl, 0.25, 5.25, 9.5, 0.22, C.teal, C.teal,
    "DOACs are preferred over warfarin in non-valvular AF — ACC/AHA Class I Recommendation", 9.5, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 17 — CATHETER ABLATION
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Catheter Ablation of AF", "Slide 17 / 20");

  // Core concept
  addBox(sl, 0.25, 0.85, 9.5, 0.68, C.navy, C.gold,
    "PULMONARY VEIN ISOLATION (PVI) — The cornerstone of AF ablation. Electrically isolates trigger foci in the PVs from the left atrium using radiofrequency energy or cryotherapy.", 11, true, C.white);

  addSectionLabel(sl, "INDICATIONS FOR ABLATION", 0.25, 1.68, 4.6);
  const indAbl = [
    "Symptomatic paroxysmal AF — failed ≥1 AAD (Class I)",
    "Symptomatic persistent AF — reasonable option",
    "Tachycardia-induced cardiomyopathy from AF",
    "Patient preference for rhythm control without drugs",
    "HFrEF with AF — ablation improves EF (CASTLE-AF trial)",
    "As first-line rhythm control option in selected patients",
  ];
  sl.addText(makeBullets(indAbl, 10.5), { x: 0.25, y: 1.98, w: 4.6, h: 2.2, fontFace: "Calibri" });

  addSectionLabel(sl, "CONTRAINDICATIONS / CAUTION", 5.05, 1.68, 4.7);
  const contIndAbl = [
    "LA thrombus present (require TEE before procedure)",
    "Severe LV dysfunction (relative; may still benefit)",
    "Unable to anticoagulate peri-procedurally",
    "Permanent AF with accepted rate strategy",
    "High surgical risk (comorbidities)",
  ];
  sl.addText(makeBullets(contIndAbl, 10.5, C.red), { x: 5.05, y: 1.98, w: 4.7, h: 1.7, fontFace: "Calibri" });

  addSectionLabel(sl, "SUCCESS RATES", 5.05, 3.72, 4.7);
  addBox(sl, 5.05, 4.05, 2.25, 0.88, C.lightG, "1E8449", "Paroxysmal AF\n~70-80% single procedure\n~90% with redo", 10, false, C.darkT);
  addBox(sl, 7.4, 4.05, 2.35, 0.88, C.lightY, "B7950B", "Persistent AF\n~50-70% single procedure\nLower success rate", 10, false, C.darkT);

  addSectionLabel(sl, "COMPLICATIONS (<3%)", 0.25, 3.72, 4.6);
  const comp = ["Cardiac tamponade / pericardial effusion", "Pulmonary vein stenosis", "Atrioesophageal fistula (rare but fatal)", "Stroke / TIA (peri-procedural)", "Phrenic nerve injury", "Vascular access complications"];
  sl.addText(makeBullets(comp, 9.5, C.red), { x: 0.25, y: 4.05, w: 4.6, h: 1.3, fontFace: "Calibri" });

  addBox(sl, 0.25, 5.2, 9.5, 0.22, C.teal, C.teal,
    "CABANA Trial: Ablation did not reduce primary endpoint (mortality, stroke, etc.) in ITT analysis but showed benefit in per-protocol analysis and quality of life", 9, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 18 — AF IN SPECIAL POPULATIONS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "AF in Special Populations", "Slide 18 / 20");

  const populations = [
    {
      title: "AF in HEART FAILURE",
      content: "• Bidirectional relationship — HF causes AF, AF worsens HF\n• Rate control with beta-blockers or digoxin\n• AVOID verapamil/diltiazem in HFrEF\n• Consider ablation — CASTLE-AF trial: ablation reduced mortality + HF hospitalization\n• Anticoagulate if CHA₂DS₂-VASc ≥1 (male) / ≥2 (female)",
      fill: C.lightB, border: C.teal
    },
    {
      title: "AF in PREGNANCY",
      content: "• Rare but can occur in structural heart disease\n• Rate control: Digoxin or metoprolol (safe in pregnancy)\n• AVOID warfarin in 1st trimester (teratogenic)\n• AVOID DOACs (not studied, may cross placenta)\n• Use LMWH throughout; warfarin in 2nd-3rd trimester for mechanical valves",
      fill: C.lightG, border: "1E8449"
    },
    {
      title: "AF in ELDERLY (>75 yrs)",
      content: "• All have CHA₂DS₂-VASc ≥2 → anticoagulate!\n• Atypical presentation: falls, syncope, cognitive decline\n• DOACs preferred over warfarin\n• Higher bleeding risk — correct modifiable factors\n• Reduced digoxin/drug doses (renal clearance ↓)\n• Symptom control, QoL focus",
      fill: C.lightY, border: "B7950B"
    },
    {
      title: "AF in CKD",
      content: "• DOACs: dose-adjust for renal function\n  - Apixaban: preferred even in CKD stage 3-4\n  - Dabigatran: AVOID if CrCl <30 mL/min\n  - Rivaroxaban: reduce dose if CrCl 15-49\n• Warfarin: acceptable but variable INR in CKD\n• Dialysis patients: anticoagulation controversial",
      fill: C.lightR, border: C.red
    },
  ];

  populations.forEach((p, i) => {
    const col = i % 2;
    const row = Math.floor(i / 2);
    addSectionLabel(sl, p.title, 0.22 + col * 5.0, 0.85 + row * 2.28, 4.7);
    addBox(sl, 0.22 + col * 5.0, 1.18 + row * 2.28, 4.7, 1.8, p.fill, p.border, p.content, 9.5, false, C.darkT);
  });

  addBox(sl, 0.25, 5.2, 9.5, 0.22, C.navy, C.gold,
    "WPW + AF: NEVER use AV nodal blockers — risk of VF! → IV Procainamide / emergent cardioversion → refer for ablation", 9.5, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 19 — STROKE PREVENTION: LAA OCCLUSION & INTEGRATED CARE
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.offW } });
  addHeader(sl, "Stroke Prevention & Integrated AF Care", "Slide 19 / 20");

  addSectionLabel(sl, "STROKE PATHOPHYSIOLOGY IN AF", 0.25, 0.85, 5.5);
  addBox(sl, 0.25, 1.18, 5.5, 1.15, C.lightB, C.teal,
    "PRIMARY SOURCE: Left Atrial Appendage (LAA) — stagnant blood flow → thrombus formation → embolism → cardioembolic stroke.\n\nAfter cardioversion: 'ATRIAL STUNNING' — mechanical function impaired for weeks even after electrical sinus rhythm → thrombus can still form!\n\nValvular AF (Mitral Stenosis): higher thrombus risk; always warfarin.", 10, false, C.darkT);

  addSectionLabel(sl, "LAA OCCLUSION — WATCHMAN DEVICE", 0.25, 2.48, 5.5);
  addBox(sl, 0.25, 2.8, 5.5, 1.35, C.lightG, "1E8449",
    "INDICATIONS: High stroke risk + contraindication to long-term anticoagulation\n\n• Transcatheter device implanted in LAA\n• Reduces AF-related stroke comparable to warfarin\n• Short-term anticoagulation required after device placement\n• TEE pre-procedure to confirm no peri-device leak\n• PROTECT-AF & PREVAIL trials support use\n• May allow eventual discontinuation of OAC", 9.5, false, C.darkT);

  addSectionLabel(sl, "SURGICAL AF ABLATION (MAZE PROCEDURE)", 0.25, 4.25, 5.5);
  addBox(sl, 0.25, 4.58, 5.5, 0.65, C.lightY, "B7950B",
    "Creates electrical barriers to prevent AF. Useful in patients undergoing cardiac surgery (concomitant). Surgical LAA closure may reduce stroke risk but thrombus can form in remnant.", 9.5, false, C.darkT);

  addSectionLabel(sl, "INTEGRATED / ABC PATHWAY (ESC/ACC)", 5.95, 0.85, 3.8);
  const abc = [
    ["A — Anticoagulation", "Stroke prevention first\nCHA₂DS₂-VASc guided OAC", C.lightB, C.teal],
    ["B — Better symptom control", "Rate + rhythm control\n+ lifestyle modification", C.lightG, "1E8449"],
    ["C — Cardiovascular risk factor\n& comorbidity management", "HTN, DM, OSA, obesity, HF\n= upstream therapy", C.lightY, "B7950B"],
  ];
  abc.forEach((a, i) => addBox(sl, 5.95, 1.18 + i * 1.2, 3.8, 1.12, a[2], a[3], `${a[0]}\n${a[1]}`, 10, false, C.darkT));

  addBox(sl, 5.95, 4.78, 3.8, 0.52, C.navy, C.gold,
    "Integrated AF care with ABC pathway reduces hospitalizations & mortality (AFFIRM, RACE II, EAST-AFNET 4)", 9, true, C.white);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 20 — SUMMARY & KEY TAKEAWAYS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const sl = pres.addSlide();
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: C.navy } });
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 0.72, w: 10, h: 0.06, fill: { color: C.gold } });
  sl.addShape(pres.ShapeType.rect, { x: 0, y: 4.7, w: 10, h: 0.925, fill: { color: C.teal } });

  sl.addText("KEY TAKEAWAYS", {
    x: 0.3, y: 0.06, w: 9.4, h: 0.64, margin: 0,
    fontSize: 24, bold: true, color: C.white, fontFace: "Calibri",
    charSpacing: 3, align: "center"
  });

  const takeaways = [
    ["1", "AF is the most common SUSTAINED arrhythmia. It is a disease continuum (4 stages). Define & stage it properly.", C.lightB, C.teal],
    ["2", "Pathophysiology: Multiple wavelet reentry + PV ectopy. AF begets AF — early rhythm control matters.", C.lightG, "1E8449"],
    ["3", "THREE PILLARS: Symptom control, stroke prevention, risk factor modification. All three must be addressed.", C.lightY, "B7950B"],
    ["4", "CHA₂DS₂-VASc guides anticoagulation. DOACs are preferred over warfarin in non-valvular AF.", C.lightB, C.teal],
    ["5", "Rate control first in most stable patients. Rhythm control for symptomatic, young, or tachycardiomyopathy patients.", C.lightG, "1E8449"],
    ["6", "HAS-BLED identifies correctable bleeding risk — NOT a reason to withhold anticoagulation.", C.lightY, "B7950B"],
    ["7", "ABLATION (PVI) is first-line option in symptomatic paroxysmal AF. CASTLE-AF supports ablation in HFrEF.", C.lightR, C.red],
    ["8", "WPW + AF is a MEDICAL EMERGENCY — never AV nodal blockers — IV Procainamide / cardioversion + ablation.", C.lightR, C.red],
  ];

  takeaways.forEach((t, i) => {
    const col = i % 2;
    const row = Math.floor(i / 2);
    sl.addShape(pres.ShapeType.roundRect, {
      x: 0.22 + col * 5.0, y: 0.88 + row * 0.87, w: 4.72, h: 0.8,
      fill: { color: t[2] }, line: { color: t[3], width: 1.2 }, rectRadius: 0.07
    });
    sl.addShape(pres.ShapeType.ellipse, {
      x: 0.26 + col * 5.0, y: 0.93 + row * 0.87, w: 0.32, h: 0.32,
      fill: { color: t[3] }, line: { color: t[3] }
    });
    sl.addText(t[0], { x: 0.26 + col * 5.0, y: 0.93 + row * 0.87, w: 0.32, h: 0.32, fontSize: 9, bold: true, color: C.white, fontFace: "Calibri", align: "center", valign: "middle" });
    sl.addText(t[1], { x: 0.62 + col * 5.0, y: 0.88 + row * 0.87, w: 4.28, h: 0.8, fontSize: 9.5, color: C.darkT, fontFace: "Calibri", valign: "middle", wrap: true, margin: 3 });
  });

  sl.addText("\"AF management is not just about drugs — it's about addressing the whole patient: their lifestyle, comorbidities, and stroke risk.\"", {
    x: 0.3, y: 4.73, w: 9.4, h: 0.45,
    fontSize: 11, color: C.white, fontFace: "Calibri", italic: true, align: "center", valign: "middle"
  });

  sl.addText("Harrison's Principles of Internal Medicine 22E (2025)  |  2023 ACC/AHA/ACCP/HRS AF Guidelines", {
    x: 0.3, y: 5.2, w: 9.4, h: 0.25, margin: 0,
    fontSize: 8.5, color: C.gold, fontFace: "Calibri", align: "center", italic: true
  });
}

// ─── Write file ───────────────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/af-ppt/Atrial_Fibrillation_Seminar.pptx" })
  .then(() => console.log("SUCCESS: Atrial_Fibrillation_Seminar.pptx created!"))
  .catch(e => console.error("ERROR:", e));
Running Command

cd /home/daytona/workspace/af-ppt && node create_af_ppt.js 2>&1

Running Command

ls -lh /home/daytona/workspace/af-ppt/Atrial_Fibrillation_Seminar.pptx

Editing File

~/af-ppt/create_af_ppt.js

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

cd /home/daytona/workspace/af-ppt && node create_af_ppt.js 2>&1 | tail -5

Clean build. Your presentation is ready!

Your Atrial Fibrillation Seminar PPT is Ready

Atrial Fibrillation Seminar

Presentation · PPTX


What's inside — all 20 slides:

#Slide TitleKey Features
1Title SlideNavy/gold professional design with full topic overview
2Definition & OverviewHighlighted definition box, 4-key-fact tiles, 4-stage continuum flowchart
3EpidemiologyStat cards (12%, 18%, 1/3), comorbidity checklist
4ClassificationTraditional (paroxysmal/persistent/long-standing/permanent) + NEW 2023 4-stage continuum with arrows
5PathophysiologyTriggers → Substrate → Perpetuators boxes + "AF begets AF" concept
6Risk Factors & LifestyleModifiable/non-modifiable grid, U-shaped curve explanation, caffeine myth correction
7Clinical FeaturesSymptom tiles, serious presentations, physical exam findings
8ECG Diagnosis4 classic ECG features in colored boxes, WPW-AF warning
9InvestigationsMandatory vs selective workup in two columns
10CHA₂DS₂-VASc ScoreFull scoring table + anticoagulation decision flowchart
11HAS-BLED ScoreFull table + interpretation + correctable factors
12Management Overview3-pillar framework + acute management flowchart (hemodynamically stable vs unstable)
13Rate ControlDrug table (beta-blockers, CCBs, digoxin, amiodarone) with targets + WPW caution
14Rhythm Control & CardioversionIndications, cardioversion types, anticoagulation-around-CV flowchart
15Antiarrhythmic DrugsFull AAD table: flecainide, propafenone, sotalol, dronedarone, amiodarone, dofetilide — color-coded by SHD
16AnticoagulationWarfarin vs DOACs comparison table, when to use warfarin
17Catheter AblationPVI concept, indications, success rates, CABANA/CASTLE-AF trial references
18Special Populations4 boxes: HF, Pregnancy, Elderly, CKD — with drug-specific guidance
19Stroke Prevention & Integrated CareLAA/Watchman device, ABC pathway, surgical Maze
20Key Takeaways8 numbered gold-circle highlights for closing the lecture
Design: Navy/teal/gold color palette, colored boxes, flowcharts with arrows, comparison tables, and section labels throughout. All content sourced from Harrison's Principles of Internal Medicine 22nd Edition (2025) with 2023 ACC/AHA/ACCP/HRS guidelines integrated.
This is a shared conversation. Sign in to Orris to start your own chat.