Act as best general surgery professor and make a presentation from latest standard surgery text book and recent guidelines on "Iatrogenic bile duct injuries ' on following heading

Asking for Preferences
Reading File
Reading File
Reading File
Finding Sources
Finding Sources
Searching PubMed

"bile duct injury" AND "cholecystectomy" AND management

Reading File
Reading File
Reading File
Reading File
Reading File
Reading Article

PMID: 41266841

Reading Article

PMID: 41193912

Reading File
Searching Images

Strasberg classification bile duct injury diagram

Searching Images

critical view of safety cholecystectomy Calot triangle

Running Command

ls -la /home/daytona/workspace/ 2>/dev/null && mkdir -p /home/daytona/workspace/bile-duct-injury-ppt

Running Command

mkdir -p /home/daytona/workspace/bile-duct-injury-ppt && echo "Directory created"

Writing File

~/bile-duct-injury-ppt/create_presentation.js

const pptxgen = require("pptxgenjs");
const { execSync } = require("child_process");

// Fetch images as base64
const imageUrls = [
  "https://cdn.orris.care/cdss_images/BAILY_1760532652473_86d2d620-07e3-47b2-815a-0724c22dd5a3.png",
  "https://cdn.orris.care/cdss_images/pmc_clinical_VQA_cf141f5bb2761a46b4cbc38dbcb441acbe311007eedc3e6ac18d21a26db2e4d2.jpg",
  "https://cdn.orris.care/cdss_images/pmc_clinical_VQA_d0a23b62e802060232314d7ecdae4547ea40e4467397d58ca1b7c78f3fc86627.jpg",
  "https://cdn.orris.care/cdss_images/pmc_clinical_VQA_1e85fb83ecdf0f535f383e3eedc56c72717b662cab7986297849afdfd2ffbe64.jpg",
  "https://cdn.orris.care/cdss_images/pmc_clinical_VQA_6d70d692d9759a77f80da024a0a5cfa622d8c5a3a31b43a4cf1783ee8677a1cb.jpg"
];

let images = [];
try {
  const result = execSync(
    `node /home/daytona/skills/shared/scripts/fetch_images.js ${imageUrls.map(u => `"${u}"`).join(" ")}`,
    { maxBuffer: 50 * 1024 * 1024 }
  ).toString();
  images = JSON.parse(result);
  console.log("Images fetched:", images.map(i => i.error ? "ERROR: " + i.error : "OK").join(", "));
} catch (e) {
  console.error("Image fetch error:", e.message);
  images = imageUrls.map(url => ({ url, base64: null, error: e.message }));
}

const pres = new pptxgen();
pres.layout = "LAYOUT_WIDE";
pres.title = "Iatrogenic Bile Duct Injuries";
pres.author = "General Surgery Grand Rounds";

// ─── COLOR PALETTE ───────────────────────────────────────────────────────────
const DEEP_NAVY   = "0A1F44";   // dominant background
const MED_BLUE    = "1A3D6E";   // section headers / shapes
const ACCENT_GOLD = "E8A020";   // accent / highlights
const LIGHT_GRAY  = "EEF2F7";   // text-area backgrounds
const WHITE       = "FFFFFF";
const RED_ALERT   = "C0392B";   // danger / alert callouts
const TEAL        = "1ABC9C";   // positive/safe steps

// ─── HELPERS ─────────────────────────────────────────────────────────────────
function titleSlide(slide) {
  // Full background
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 13.3, h: 7.5, fill: { color: DEEP_NAVY } });
  // Gold accent bar
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 5.5, w: 13.3, h: 0.12, fill: { color: ACCENT_GOLD } });
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 6.8, w: 13.3, h: 0.7, fill: { color: MED_BLUE } });
}

function sectionBg(slide) {
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 13.3, h: 7.5, fill: { color: DEEP_NAVY } });
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 0.15, h: 7.5, fill: { color: ACCENT_GOLD } });
}

function contentBg(slide) {
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 13.3, h: 7.5, fill: { color: LIGHT_GRAY } });
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 13.3, h: 1.05, fill: { color: DEEP_NAVY } });
  slide.addShape(pres.ShapeType.rect, { x: 0, y: 1.05, w: 13.3, h: 0.06, fill: { color: ACCENT_GOLD } });
}

function addHeader(slide, title, subtitle) {
  contentBg(slide);
  slide.addText(title, {
    x: 0.3, y: 0.1, w: 12.7, h: 0.75,
    fontSize: 24, bold: true, color: WHITE, fontFace: "Calibri", align: "left", margin: 0
  });
  if (subtitle) {
    slide.addText(subtitle, {
      x: 0.3, y: 0.78, w: 12.7, h: 0.32,
      fontSize: 13, color: ACCENT_GOLD, fontFace: "Calibri", italic: true, margin: 0
    });
  }
}

function addBullets(slide, items, x, y, w, h, opts) {
  const o = opts || {};
  const fontSize = o.fontSize || 16;
  const textItems = items.map((item, idx) => {
    if (typeof item === "string") {
      return { text: item, options: { bullet: true, breakLine: idx < items.length - 1, fontSize, color: o.color || "1A1A2E", fontFace: "Calibri", paraSpaceAfter: 4 } };
    } else {
      return { text: item.text, options: { bullet: item.sub ? { indent: 25 } : true, breakLine: idx < items.length - 1, fontSize: item.sub ? fontSize - 2 : fontSize, color: item.color || o.color || "1A1A2E", fontFace: "Calibri", bold: item.bold || false, paraSpaceAfter: 3 } };
    }
  });
  slide.addText(textItems, { x, y, w, h, valign: "top", margin: 6 });
}

function calloutBox(slide, text, x, y, w, h, color) {
  slide.addShape(pres.ShapeType.roundRect, {
    x, y, w, h,
    fill: { color: color || ACCENT_GOLD },
    line: { color: WHITE, width: 1 },
    rectRadius: 0.08
  });
  slide.addText(text, {
    x: x + 0.1, y: y + 0.05, w: w - 0.2, h: h - 0.1,
    fontSize: 13, color: WHITE, bold: true, fontFace: "Calibri", align: "center", valign: "middle"
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 1 — TITLE
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  titleSlide(s);

  // Decorative circle
  s.addShape(pres.ShapeType.ellipse, { x: 9.5, y: -1.5, w: 6, h: 6, fill: { color: MED_BLUE }, line: { color: MED_BLUE } });
  s.addShape(pres.ShapeType.ellipse, { x: 10, y: -1, w: 5, h: 5, fill: { color: "0D2550" }, line: { color: "0D2550" } });

  s.addText("IATROGENIC", {
    x: 0.8, y: 0.8, w: 9, h: 0.9,
    fontSize: 48, bold: true, color: ACCENT_GOLD, fontFace: "Calibri", charSpacing: 6, margin: 0
  });
  s.addText("BILE DUCT INJURIES", {
    x: 0.8, y: 1.65, w: 9, h: 0.9,
    fontSize: 44, bold: true, color: WHITE, fontFace: "Calibri", margin: 0
  });
  s.addShape(pres.ShapeType.rect, { x: 0.8, y: 2.65, w: 6.5, h: 0.06, fill: { color: ACCENT_GOLD } });
  s.addText("A Comprehensive Review: Classification | Mechanisms | Prevention | Management | Outcomes", {
    x: 0.8, y: 2.85, w: 10, h: 0.6,
    fontSize: 16, color: "B8C8E0", fontFace: "Calibri", italic: true, margin: 0
  });
  s.addText("Sources: Sabiston Textbook of Surgery | Current Surgical Therapy 14e | Mulholland & Greenfield 7e\nSAGES-AHPBA 2025 Guideline | Surg Endosc 2026", {
    x: 0.8, y: 3.65, w: 10, h: 0.8,
    fontSize: 13, color: "8899BB", fontFace: "Calibri", margin: 0
  });
  s.addText("General Surgery Grand Rounds  •  2026", {
    x: 0.5, y: 6.85, w: 12, h: 0.45,
    fontSize: 13, color: "AABBCC", fontFace: "Calibri", align: "center", margin: 0
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 2 — SCOPE & OUTLINE
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Presentation Outline", "Structured for clinical understanding and surgical decision-making");
  const topics = [
    "1.  Scope of the Problem & Epidemiology",
    "2.  Surgical Anatomy & Mechanism of Injury",
    "3.  Risk Factors",
    "4.  Classification Systems (Bismuth, Strasberg, Stewart-Way)",
    "5.  Prevention — Critical View of Safety & IOC",
    "6.  Clinical Presentation & Diagnosis",
    "7.  Intraoperative Recognition",
    "8.  Postoperative Workup (Labs, Imaging, ERCP, PTC)",
    "9.  Management Principles",
    "10. Timing of Repair (SAGES-AHPBA 2025 Guideline)",
    "11. Surgical Repair Techniques",
    "12. Non-operative & Endoscopic Management",
    "13. Outcomes & Long-term Follow-up",
    "14. Medicolegal Considerations",
    "15. Key Takeaways",
  ];
  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 6.1, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE", width: 1 } });
  s.addShape(pres.ShapeType.rect, { x: 6.7, y: 1.2, w: 6.1, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE", width: 1 } });
  const left = topics.slice(0, 8);
  const right = topics.slice(8);
  addBullets(s, left, 0.35, 1.25, 5.9, 5.8, { fontSize: 14, color: DEEP_NAVY });
  addBullets(s, right, 6.8, 1.25, 5.9, 5.8, { fontSize: 14, color: DEEP_NAVY });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 3 — EPIDEMIOLOGY
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Scope of the Problem", "Epidemiology & Public Health Impact");

  // Stat boxes
  const stats = [
    { val: "0.1–0.6%", label: "Incidence\nLaparoscopic" },
    { val: "0.1%", label: "Incidence\nOpen" },
    { val: "~1M", label: "Cholecystectomies\nper year (USA)" },
    { val: "1 in 3", label: "Surgeons will cause\na BDI in career" },
  ];
  stats.forEach((st, i) => {
    const x = 0.35 + i * 3.2;
    s.addShape(pres.ShapeType.roundRect, { x, y: 1.2, w: 2.9, h: 1.6, fill: { color: DEEP_NAVY }, line: { color: ACCENT_GOLD, width: 2 }, rectRadius: 0.1 });
    s.addText(st.val, { x: x + 0.1, y: 1.25, w: 2.7, h: 0.9, fontSize: 28, bold: true, color: ACCENT_GOLD, fontFace: "Calibri", align: "center", valign: "middle" });
    s.addText(st.label, { x: x + 0.1, y: 2.1, w: 2.7, h: 0.6, fontSize: 12, color: WHITE, fontFace: "Calibri", align: "center", valign: "middle" });
  });

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 3.0, w: 12.8, h: 4.1, fill: { color: WHITE }, line: { color: "CCDDEE", width: 1 } });

  const bullets = [
    { text: ">80% of all bile duct injuries occur during cholecystectomy", bold: true },
    "Laparoscopic cholecystectomy: incidence 0.1–0.6% (open: ~0.1%)",
    "Increased incidence at introduction of laparoscopic era (early 1990s); improved with experience",
    { text: "New data suggest robotic cholecystectomy may have higher BDI rate than laparoscopic", bold: true, color: RED_ALERT },
    "BDI causes: significant morbidity, reduced quality of life, financial burden, malpractice claims, mortality",
    "Benign biliary strictures can also arise from: inflammatory disease, gallstones, non-iatrogenic trauma",
    { text: "Key principle: Misperception of anatomy is more common than surgical skill failure", bold: true, color: MED_BLUE },
  ];
  addBullets(s, bullets, 0.4, 3.05, 12.5, 4.0, { fontSize: 15, color: "1A1A2E" });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 4 — ANATOMY & MECHANISMS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Mechanism of Injury", "Why bile duct injuries happen — anatomy and perception");

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 7.5, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });
  s.addShape(pres.ShapeType.rect, { x: 8.1, y: 1.2, w: 4.9, h: 5.9, fill: { color: MED_BLUE }, line: { color: MED_BLUE } });

  const mechanismBullets = [
    { text: "Classic Mechanism (\"Tenting\" Injury):", bold: true, color: RED_ALERT },
    { text: "Excessive cephalad retraction of fundus → cystic duct aligns parallel to CBD", sub: true },
    { text: "Surgeon misidentifies CBD as cystic duct → clips and divides CBD", sub: true },
    { text: "Confirmation bias prevents intraoperative recognition", sub: true },
    { text: "Factors Contributing to Misidentification:", bold: true, color: MED_BLUE },
    { text: "Insufficient lateral retraction of infundibulum", sub: true },
    { text: "Dissection medial to CBD instead of lateral to cystic duct", sub: true },
    { text: "Laparoscopic 2D vision & restricted field of view", sub: true },
    { text: "Other Mechanisms:", bold: true, color: MED_BLUE },
    { text: "Aberrant biliary anatomy (low cystic duct insertion, parallel course) — up to 25% patients", sub: true },
    { text: "Right posterior sectoral duct draining into CBD — up to 6%", sub: true },
    { text: "Excessive electrocautery → thermal injury → delayed stricture", sub: true },
    { text: "Traction injury; top-down dissection (open surgery)", sub: true },
    { text: "Vasculobiliary injury — right hepatic artery injury increases stricture risk", bold: true, color: RED_ALERT },
  ];
  addBullets(s, mechanismBullets, 0.35, 1.25, 7.3, 5.8, { fontSize: 13.5, color: "1A1A2E" });

  s.addText("DANGER ZONES", { x: 8.2, y: 1.3, w: 4.7, h: 0.45, fontSize: 15, bold: true, color: ACCENT_GOLD, fontFace: "Calibri", align: "center" });
  const dangerItems = [
    "Short / absent cystic duct",
    "Parallel cystic-CBD course",
    "Mirizzi syndrome",
    "Severe acute cholecystitis",
    "Cirrhosis / portal HTN",
    "Prior biliary surgery",
    "Aberrant right hepatic duct",
    "Obesity / difficult exposure",
  ];
  dangerItems.forEach((txt, i) => {
    s.addShape(pres.ShapeType.roundRect, { x: 8.2, y: 1.85 + i * 0.61, w: 4.7, h: 0.52, fill: { color: i % 2 === 0 ? "0D2550" : DEEP_NAVY }, line: { color: ACCENT_GOLD, width: 1 }, rectRadius: 0.05 });
    s.addText("⚠ " + txt, { x: 8.3, y: 1.87 + i * 0.61, w: 4.5, h: 0.48, fontSize: 13, color: WHITE, fontFace: "Calibri", valign: "middle" });
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 5 — STRASBERG CLASSIFICATION WITH IMAGE
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Classification of Bile Duct Injuries", "Strasberg-Bismuth Classification (most widely used)");

  // Table for classification
  const tableRows = [
    [{ text: "Type", options: { bold: true, color: WHITE, fill: DEEP_NAVY } }, { text: "Description", options: { bold: true, color: WHITE, fill: DEEP_NAVY } }, { text: "Notes", options: { bold: true, color: WHITE, fill: DEEP_NAVY } }],
    ["A", "Bile leak from cystic duct stump or duct of Luschka", "Minor — ERCP ± stent usually curative"],
    ["B", "Occlusion (clip) of aberrant right hepatic duct", "Stricture — often silent, discovered late"],
    ["C", "Transection of aberrant R hepatic duct — bile leak", "Requires bilioenteric anastomosis"],
    ["D", "Lateral injury to main bile duct without tissue loss", "T-tube repair; may be managed endoscopically"],
    ["E1", "CBD stricture >2 cm below bifurcation", "Surgical reconstruction usually needed"],
    ["E2", "CBD stricture <2 cm below bifurcation", "Hepaticojejunostomy preferred"],
    ["E3", "Stricture at confluence — R & L ducts in communication", "More complex repair required"],
    ["E4", "Stricture separating R & L hepatic ducts", "High hilar reconstruction"],
    ["E5", "Injury to aberrant R sectoral duct + main duct", "Two-duct repair"],
  ];

  s.addTable(tableRows, {
    x: 0.25, y: 1.2, w: 7.8, h: 5.9,
    colW: [0.7, 4.5, 2.5],
    fontSize: 12,
    fontFace: "Calibri",
    color: DEEP_NAVY,
    border: { type: "solid", color: "CCDDEE", pt: 1 },
    fill: { color: WHITE },
    rowH: 0.55,
    align: "left",
    valign: "middle",
  });

  if (images[0] && images[0].base64) {
    s.addImage({ data: images[0].base64, x: 8.2, y: 1.2, w: 4.8, h: 5.9 });
  } else {
    s.addShape(pres.ShapeType.rect, { x: 8.2, y: 1.2, w: 4.8, h: 5.9, fill: { color: MED_BLUE } });
    s.addText("Strasberg Classification Diagram\n(Bailey & Love, p.1273)", { x: 8.3, y: 3.2, w: 4.6, h: 1.5, fontSize: 14, color: WHITE, align: "center", valign: "middle" });
  }
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 6 — STEWART-WAY CLASSIFICATION
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Stewart-Way Classification", "Mechanism-based classification — guides intraoperative decision");

  const classes = [
    { cls: "Class I", desc: "CBD incised (not transected); mistaken for cystic duct — incision < circumference", mgmt: "Primary closure ± T-tube" },
    { cls: "Class II", desc: "CHD damaged laterally; mistaken for cystic duct; partial clip / clip + cautery", mgmt: "Repair over stent or hepaticojejunostomy" },
    { cls: "Class III", desc: "CHD transected and excised; CBD mistaken for cystic duct (most common, classic)", mgmt: "Hepaticojejunostomy" },
    { cls: "Class IV", desc: "RHD transected ± CHD; right ductal structures mistaken for cystic duct", mgmt: "Right-sided reconstruction — most complex" },
  ];

  classes.forEach((c, i) => {
    const y = 1.3 + i * 1.45;
    const bg = i % 2 === 0 ? WHITE : "F0F4FA";
    s.addShape(pres.ShapeType.roundRect, { x: 0.25, y, w: 12.8, h: 1.35, fill: { color: bg }, line: { color: "CCDDEE", width: 1 }, rectRadius: 0.07 });
    s.addShape(pres.ShapeType.roundRect, { x: 0.3, y: y + 0.08, w: 1.3, h: 1.1, fill: { color: MED_BLUE }, line: { color: MED_BLUE }, rectRadius: 0.06 });
    s.addText(c.cls, { x: 0.3, y: y + 0.28, w: 1.3, h: 0.7, fontSize: 14, bold: true, color: WHITE, fontFace: "Calibri", align: "center" });
    s.addText(c.desc, { x: 1.75, y: y + 0.1, w: 8.0, h: 0.65, fontSize: 13.5, color: DEEP_NAVY, fontFace: "Calibri", valign: "middle" });
    s.addShape(pres.ShapeType.roundRect, { x: 10.0, y: y + 0.1, w: 3.0, h: 1.1, fill: { color: DEEP_NAVY }, line: { color: ACCENT_GOLD, width: 1 }, rectRadius: 0.06 });
    s.addText("Repair:\n" + c.mgmt, { x: 10.1, y: y + 0.15, w: 2.8, h: 1.0, fontSize: 11.5, color: WHITE, fontFace: "Calibri", valign: "middle", align: "center" });
  });

  calloutBox(s, "Class III is the most common injury pattern — accounts for ~75% of all laparoscopic BDIs", 0.25, 7.0, 12.8, 0.45, MED_BLUE);
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 7 — PREVENTION: CRITICAL VIEW OF SAFETY (with image)
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Prevention — Critical View of Safety (CVS)", "Strasberg & Soper, 1995 — the single most effective preventive measure");

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 6.0, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });

  const cvsBullets = [
    { text: "THREE CRITERIA for CVS (ALL must be met):", bold: true, color: DEEP_NAVY },
    { text: "① Hepatocystic triangle completely cleared of fat and fibrous tissue", sub: true, color: TEAL, bold: true },
    { text: "② Lower one-third of gallbladder separated from cystic plate (liver bed)", sub: true, color: TEAL, bold: true },
    { text: "③ Only TWO structures seen entering the gallbladder (cystic duct + cystic artery)", sub: true, color: TEAL, bold: true },
    { text: "Technique:", bold: true },
    { text: "Retract fundus superiorly; Hartmann's pouch laterally and inferiorly", sub: true },
    { text: "Dissect from gallbladder infundibulum — NOT from triangle of Calot directly", sub: true },
    { text: "Initiate dissection lateral to cystic duct to avoid CBD misidentification", sub: true },
    { text: "When CVS Cannot Be Achieved:", bold: true, color: RED_ALERT },
    { text: "Consider subtotal cholecystectomy (fenestrating or reconstituting)", sub: true },
    { text: "Cholecystostomy tube placement", sub: true },
    { text: "Conversion to open — BUT only if surgeon experienced in open CBD surgery", sub: true },
    { text: "Document CVS with intraoperative photograph", bold: true, color: MED_BLUE },
  ];
  addBullets(s, cvsBullets, 0.35, 1.25, 5.8, 5.8, { fontSize: 13.5, color: "1A1A2E" });

  if (images[1] && images[1].base64) {
    s.addImage({ data: images[1].base64, x: 6.5, y: 1.2, w: 6.5, h: 5.9 });
    s.addText("Critical View of Safety — intraoperative CVS with labeled anatomy", { x: 6.5, y: 6.8, w: 6.5, h: 0.3, fontSize: 9, color: MED_BLUE, italic: true, align: "center" });
  } else {
    s.addShape(pres.ShapeType.rect, { x: 6.5, y: 1.2, w: 6.5, h: 5.9, fill: { color: DEEP_NAVY } });
    s.addText("CVS Intraoperative Image", { x: 6.6, y: 3.8, w: 6.3, h: 1, fontSize: 16, color: WHITE, align: "center" });
  }
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 8 — IOC & SUBTOTAL CHOLECYSTECTOMY
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Prevention — IOC & Bailout Strategies", "Intraoperative Cholangiography and Subtotal Cholecystectomy");

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 6.2, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });
  s.addShape(pres.ShapeType.rect, { x: 6.75, y: 1.2, w: 6.3, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });

  s.addText("Intraoperative Cholangiography (IOC)", { x: 0.35, y: 1.25, w: 6.0, h: 0.45, fontSize: 15, bold: true, color: DEEP_NAVY, fontFace: "Calibri" });
  const iocBullets = [
    "Role in BDI prevention remains controversial",
    "Minority of surgeons use routinely",
    "Most recent population data: IOC does NOT reduce BDI rate",
    { text: "BUT: IOC facilitates EARLY RECOGNITION when injury occurs → reduces morbidity", bold: true, color: TEAL },
    "Selective use recommended (difficult anatomy, suspected CBD stones, anomalies)",
    { text: "MRCP / Fluorescence cholangiography (ICG): emerging alternatives", bold: true, color: MED_BLUE },
    "Near-infrared fluorescence with ICG — growing evidence for real-time biliary anatomy",
  ];
  addBullets(s, iocBullets, 0.35, 1.75, 6.0, 5.3, { fontSize: 13, color: "1A1A2E" });

  s.addText("Subtotal Cholecystectomy (Bailout)", { x: 6.85, y: 1.25, w: 6.0, h: 0.45, fontSize: 15, bold: true, color: DEEP_NAVY, fontFace: "Calibri" });
  const stcBullets = [
    { text: "Fenestrating (open / reconstituting) technique:", bold: true, color: MED_BLUE },
    "Used when CVS unachievable due to severe inflammation",
    "Avoids blind dissection near CBD",
    "Leave posterior gallbladder wall on liver bed",
    "Drain cystic duct stump or pack open",
    { text: "Reconstituting subtotal cholecystectomy:", bold: true, color: MED_BLUE },
    "Divide gallbladder neck, oversew stump, evacuate stones",
    { text: "Both approaches have LOW BDI rates compared to forced dissection", bold: true, color: TEAL },
    { text: "Meta-analysis 2024 (PMID 37739875): no significant difference between fenestrating vs reconstituting for major outcomes", bold: false, color: MED_BLUE },
  ];
  addBullets(s, stcBullets, 6.85, 1.75, 6.1, 5.3, { fontSize: 13, color: "1A1A2E" });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 9 — CLINICAL PRESENTATION & DIAGNOSIS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Clinical Presentation & Diagnosis", "Recognition: intraoperative vs. postoperative");

  // Two-column layout
  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 6.2, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });
  s.addShape(pres.ShapeType.rect, { x: 6.75, y: 1.2, w: 6.3, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });

  s.addText("Intraoperative Recognition", { x: 0.35, y: 1.25, w: 6.0, h: 0.4, fontSize: 15, bold: true, color: RED_ALERT, fontFace: "Calibri" });
  const intraBullets = [
    { text: "RARE — <30% identified at time of injury", bold: true, color: RED_ALERT },
    "Confirmation bias is a major barrier to intraop recognition",
    { text: "Clues during surgery:", bold: true },
    { text: "Unexpected bile leak / bilious fluid", sub: true },
    { text: "Two structures clipped/divided (double-structure sign)", sub: true },
    { text: "IOC shows injury or unexpected anatomy", sub: true },
    { text: "If suspected intraoperatively:", bold: true, color: MED_BLUE },
    { text: "Convert to open (if not already)", sub: true },
    { text: "Perform on-table cholangiogram", sub: true },
    { text: "Call hepatobiliary surgeon immediately", sub: true, color: RED_ALERT, bold: true },
    { text: "Do NOT attempt repair without expertise", sub: true, color: RED_ALERT, bold: true },
  ];
  addBullets(s, intraBullets, 0.35, 1.7, 6.0, 5.3, { fontSize: 13, color: "1A1A2E" });

  s.addText("Postoperative Presentation", { x: 6.85, y: 1.25, w: 6.0, h: 0.4, fontSize: 15, bold: true, color: MED_BLUE, fontFace: "Calibri" });
  const postBullets = [
    { text: "Bile leak pattern (early — days to 1 week):", bold: true },
    { text: "Fever, increasing abdominal pain, nausea", sub: true },
    { text: "Jaundice (if bile flows into peritoneum)", sub: true },
    { text: "Wound/drain bile drainage", sub: true },
    { text: "Biloma → peritonitis → sepsis (if unrecognized)", sub: true },
    { text: "Stricture pattern (weeks to months):", bold: true, color: MED_BLUE },
    { text: "<10% strictures identified in first week", sub: true },
    { text: ">70% diagnosed within 6 months", sub: true },
    { text: "Progressive jaundice ± cholangitis", sub: true },
    { text: "Abnormal LFTs: elevated bili, ALP, GGT", sub: true },
    { text: "RUQ pain, fever, chills (Charcot's triad if obstructed)", sub: true },
  ];
  addBullets(s, postBullets, 6.85, 1.7, 6.1, 5.3, { fontSize: 13, color: "1A1A2E" });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 10 — INVESTIGATIONS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Investigations", "Systematic workup to define anatomy before any repair");

  if (images[2] && images[2].base64) {
    s.addImage({ data: images[2].base64, x: 7.8, y: 1.2, w: 5.2, h: 4.0 });
    s.addText("ERCP / MRCP / PTC — multi-modality BDI imaging (Strasberg A, E2, E3)", { x: 7.8, y: 5.2, w: 5.2, h: 0.35, fontSize: 9, color: MED_BLUE, italic: true, align: "center" });
  }

  const investigations = [
    { title: "Laboratory", items: ["Serum bilirubin (direct & total)", "Alkaline phosphatase, GGT, ALT, AST", "CBC, CRP — infection markers", "Coagulation profile (if septic)"] },
    { title: "Ultrasound (initial)", items: ["Biloma / fluid collection", "Biliary dilatation", "Assess liver parenchyma"] },
    { title: "CT Abdomen", items: ["Biloma localization", "Associated vascular injury", "Liver ischemia assessment", "Abscess / peritonitis"] },
    { title: "MRCP (gold standard anatomy)", items: ["Non-invasive biliary map", "Defines level of injury", "Detects stricture vs transection", "Replaced diagnostic ERCP"] },
    { title: "ERCP (diagnostic + therapeutic)", items: ["Identify leak site", "Stent placement (Type A, D)", "Sphincterotomy for low-grade leaks"] },
    { title: "PTC (Percutaneous Transhepatic)", items: ["When ERCP fails / high injury", "Drains obstructed system", "Places transhepatic stents for repair guidance"] },
  ];
  const cols = 2;
  investigations.forEach((inv, i) => {
    const col = i % cols;
    const row = Math.floor(i / cols);
    const x = 0.25 + col * 3.8;
    const y = 1.25 + row * 2.0;
    s.addShape(pres.ShapeType.roundRect, { x, y, w: 3.6, h: 1.85, fill: { color: WHITE }, line: { color: "CCDDEE", width: 1 }, rectRadius: 0.07 });
    s.addShape(pres.ShapeType.rect, { x, y, w: 3.6, h: 0.38, fill: { color: MED_BLUE }, line: { color: MED_BLUE } });
    s.addText(inv.title, { x: x + 0.1, y: y + 0.05, w: 3.4, h: 0.3, fontSize: 12, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle" });
    inv.items.forEach((item, j) => {
      s.addText("• " + item, { x: x + 0.1, y: y + 0.42 + j * 0.35, w: 3.4, h: 0.33, fontSize: 11, color: DEEP_NAVY, fontFace: "Calibri" });
    });
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 11 — MANAGEMENT PRINCIPLES & GOALS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Management Principles", "Goals of therapy — Sabiston Box 88.1 framework");

  // Goals boxes
  const goals = [
    { icon: "①", title: "Control Sepsis", desc: "Drain biloma, treat cholangitis, stabilize patient FIRST" },
    { icon: "②", title: "Define Anatomy", desc: "Complete biliary mapping before any repair (MRCP, PTC, ERCP)" },
    { icon: "③", title: "Tension-free Repair", desc: "All anastomoses must be tension-free with good blood supply" },
    { icon: "④", title: "Expert Surgeon", desc: "Repair by experienced HPB surgeon — reduces need for re-do surgery" },
    { icon: "⑤", title: "Timing", desc: "Delayed repair (>6 weeks) preferred over early repair (SAGES 2025)" },
    { icon: "⑥", title: "Long-term Follow-up", desc: "Annual LFTs; cholangiography if symptomatic; 5-yr surveillance" },
  ];

  goals.forEach((g, i) => {
    const col = i % 3;
    const row = Math.floor(i / 3);
    const x = 0.25 + col * 4.35;
    const y = 1.2 + row * 3.1;
    s.addShape(pres.ShapeType.roundRect, { x, y, w: 4.1, h: 2.9, fill: { color: WHITE }, line: { color: ACCENT_GOLD, width: 2 }, rectRadius: 0.1 });
    s.addShape(pres.ShapeType.ellipse, { x: x + 1.55, y: y + 0.2, w: 1.0, h: 1.0, fill: { color: MED_BLUE }, line: { color: MED_BLUE } });
    s.addText(g.icon, { x: x + 1.55, y: y + 0.25, w: 1.0, h: 0.9, fontSize: 22, bold: true, color: ACCENT_GOLD, align: "center", valign: "middle" });
    s.addText(g.title, { x: x + 0.1, y: y + 1.3, w: 3.9, h: 0.5, fontSize: 15, bold: true, color: DEEP_NAVY, fontFace: "Calibri", align: "center" });
    s.addText(g.desc, { x: x + 0.1, y: y + 1.85, w: 3.9, h: 0.9, fontSize: 12, color: MED_BLUE, fontFace: "Calibri", align: "center", valign: "top" });
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 12 — TIMING OF REPAIR (SAGES 2025)
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Timing of Repair — SAGES-AHPBA 2025 Guideline", "Evidence-based recommendations — Surg Endosc 2026 (PMID 41266841)");

  // Guideline box
  s.addShape(pres.ShapeType.roundRect, { x: 0.25, y: 1.2, w: 12.8, h: 1.4, fill: { color: DEEP_NAVY }, line: { color: ACCENT_GOLD, width: 2 }, rectRadius: 0.1 });
  s.addText("SAGES-AHPBA 2025 GUIDELINE — Key Recommendations (GRADE Methodology, Dec 2024 literature)", {
    x: 0.4, y: 1.25, w: 12.5, h: 0.4, fontSize: 14, bold: true, color: ACCENT_GOLD, fontFace: "Calibri"
  });

  const recs = [
    { q: "Timing", rec: "DELAYED (>6 weeks) vs Early (<6 weeks)", strength: "Conditional", evidence: "Low", detail: "Early repair: OR 3.31↑ reoperation, OR 7.41↑ stricture, OR 2.83↑ mortality (meta-analysis)" },
    { q: "Approach", rec: "MIS or Open repair equally acceptable", strength: "Conditional", evidence: "Very Low", detail: "No significant difference in outcomes; surgeon expertise and patient factors guide choice" },
    { q: "Op vs Non-op", rec: "Operative management preferred for major BDI", strength: "Conditional", evidence: "Very Low", detail: "Non-op: OR 16.60↑ reoperation, OR 2.44↑ stricture vs operative management" },
    { q: "Anastomosis", rec: "Hepaticojejunostomy or Hepaticoduodenostomy both acceptable", strength: "Conditional", evidence: "Very Low", detail: "No significant difference in stricture or reintervention rates between the two approaches" },
  ];

  recs.forEach((r, i) => {
    const y = 2.7 + i * 1.15;
    const bgCol = i % 2 === 0 ? WHITE : "F0F4FA";
    s.addShape(pres.ShapeType.roundRect, { x: 0.25, y, w: 12.8, h: 1.05, fill: { color: bgCol }, line: { color: "CCDDEE", width: 1 }, rectRadius: 0.06 });
    s.addShape(pres.ShapeType.rect, { x: 0.25, y, w: 1.5, h: 1.05, fill: { color: MED_BLUE }, line: { color: MED_BLUE } });
    s.addText(r.q, { x: 0.3, y: y + 0.25, w: 1.4, h: 0.55, fontSize: 13, bold: true, color: WHITE, fontFace: "Calibri", align: "center" });
    s.addText("Recommendation: " + r.rec, { x: 1.85, y: y + 0.05, w: 5.5, h: 0.45, fontSize: 13, bold: true, color: DEEP_NAVY, fontFace: "Calibri" });
    s.addText(r.detail, { x: 1.85, y: y + 0.55, w: 7.0, h: 0.45, fontSize: 11, color: MED_BLUE, fontFace: "Calibri" });
    s.addShape(pres.ShapeType.roundRect, { x: 9.0, y: y + 0.1, w: 1.9, h: 0.4, fill: { color: ACCENT_GOLD }, line: { color: ACCENT_GOLD }, rectRadius: 0.04 });
    s.addText(r.strength, { x: 9.0, y: y + 0.1, w: 1.9, h: 0.4, fontSize: 10, bold: true, color: WHITE, align: "center", valign: "middle" });
    s.addShape(pres.ShapeType.roundRect, { x: 11.05, y: y + 0.1, w: 2.0, h: 0.4, fill: { color: r.evidence === "Low" ? RED_ALERT : "888888" }, line: { color: "666" }, rectRadius: 0.04 });
    s.addText("Evidence: " + r.evidence, { x: 11.05, y: y + 0.1, w: 2.0, h: 0.4, fontSize: 10, bold: true, color: WHITE, align: "center", valign: "middle" });
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 13 — SURGICAL REPAIR TECHNIQUES (with image)
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Surgical Repair Techniques", "Based on injury type, level, and tissue quality");

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 7.2, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });

  const repairBullets = [
    { text: "INTRAOPERATIVE RECOGNITION:", bold: true, color: RED_ALERT },
    { text: "Convert to open; perform on-table cholangiogram", sub: true },
    { text: "Call HPB specialist — resist urge to repair without expertise", sub: true, bold: true, color: RED_ALERT },
    { text: "Partial (Lateral) Injury (Type D):", bold: true, color: MED_BLUE },
    { text: "Primary repair over T-tube with 5-0 absorbable suture + external drain", sub: true },
    { text: "Remove clip; repair small choledochotomy; drain externally", sub: true },
    { text: "Short Segment Transection (<1 cm):", bold: true, color: MED_BLUE },
    { text: "End-to-end anastomosis (4-0 or 5-0 absorbable) + T-tube through separate choledochotomy", sub: true },
    { text: "Kocher maneuver to reduce tension", sub: true },
    { text: "HIGH stricture risk long-term — requires endoscopic surveillance", sub: true, color: RED_ALERT },
    { text: "Proximal / Long-Segment Injury (>1 cm, E2–E5 — PREFERRED):", bold: true, color: MED_BLUE },
    { text: "Roux-en-Y Hepaticojejunostomy (60–70 cm Roux limb)", sub: true, bold: true },
    { text: "Distal duct oversewn; proximal duct debrided; tension-free end-to-side anastomosis", sub: true },
    { text: "Transanastomotic Silastic stents (12–22F) externalized through liver", sub: true },
    { text: "Interrupted 4-0 or 5-0 absorbable sutures; closed suction drain posteriorly", sub: true },
    { text: "Hepaticoduodenostomy: comparable outcomes (SAGES 2025) — but risk of bile reflux", sub: true },
    { text: "High Hilar Injuries (E4, E5):", bold: true, color: RED_ALERT },
    { text: "Separate anastomosis to R and L hepatic ducts over individual stents", sub: true },
    { text: "Requires expert HPB center — best outcomes at high-volume centers", sub: true, bold: true, color: RED_ALERT },
  ];
  addBullets(s, repairBullets, 0.35, 1.25, 7.0, 5.8, { fontSize: 12.5, color: "1A1A2E" });

  if (images[3] && images[3].base64) {
    s.addImage({ data: images[3].base64, x: 7.65, y: 1.2, w: 5.4, h: 5.0 });
    s.addText("MRCP showing E1 BDI + intraoperative hepaticojejunostomy with stent", { x: 7.65, y: 6.2, w: 5.4, h: 0.35, fontSize: 9, color: MED_BLUE, italic: true, align: "center" });
  } else {
    s.addShape(pres.ShapeType.rect, { x: 7.65, y: 1.2, w: 5.4, h: 5.9, fill: { color: DEEP_NAVY } });
    s.addText("Hepaticojejunostomy\nDiagram", { x: 7.75, y: 3.5, w: 5.2, h: 1, fontSize: 16, color: WHITE, align: "center" });
  }
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 14 — NON-OPERATIVE / ENDOSCOPIC MANAGEMENT
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Non-operative & Endoscopic Management", "Role of ERCP, PTC, and percutaneous drainage");

  const sections = [
    {
      title: "Type A (Cystic Duct Leak / Duct of Luschka)",
      color: TEAL,
      items: [
        "First-line: ERCP + sphincterotomy ± biliary stent",
        "Stent bridges pressure gradient — allows cystic stump to seal",
        "Success rate >90% for low-grade leaks",
        "Stent removed after 6–8 weeks; repeat ERCP confirms healing",
      ]
    },
    {
      title: "Type D (Lateral Main Duct Injury without complete transection)",
      color: MED_BLUE,
      items: [
        "ERCP + stenting: effective for partial injuries",
        "If stricture develops postoperatively: endoscopic dilation + stenting",
        "Excellent long-term outcomes with serial dilation protocols",
      ]
    },
    {
      title: "Biloma / Bile Peritonitis",
      color: ACCENT_GOLD,
      items: [
        "Percutaneous drainage (IR-guided) of collections",
        "External biliary drainage if bile peritonitis / sepsis",
        "Nutritional support during biliary diversion period",
        "Replace bile salts / electrolytes (complete biliary diversion)",
      ]
    },
    {
      title: "Established Strictures (Post-repair)",
      color: RED_ALERT,
      items: [
        "PTC: balloon dilation ± plastic stents (multiple sessions)",
        "SEMS (fully covered) for refractory benign strictures — growing evidence",
        "Endoscopic approach for stenosed hepaticojejunostomies (via balloon-assisted enteroscopy)",
        "Liver transplantation: last resort for failed reconstructions (PMID 37633743)",
      ]
    },
  ];

  sections.forEach((sec, i) => {
    const col = i % 2;
    const row = Math.floor(i / 2);
    const x = 0.25 + col * 6.55;
    const y = 1.2 + row * 3.1;
    s.addShape(pres.ShapeType.roundRect, { x, y, w: 6.3, h: 2.9, fill: { color: WHITE }, line: { color: sec.color, width: 2 }, rectRadius: 0.08 });
    s.addShape(pres.ShapeType.rect, { x, y, w: 6.3, h: 0.4, fill: { color: sec.color }, line: { color: sec.color } });
    s.addText(sec.title, { x: x + 0.1, y: y + 0.05, w: 6.1, h: 0.32, fontSize: 12.5, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle" });
    sec.items.forEach((item, j) => {
      s.addText("• " + item, { x: x + 0.15, y: y + 0.48 + j * 0.55, w: 6.0, h: 0.5, fontSize: 12, color: DEEP_NAVY, fontFace: "Calibri" });
    });
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 15 — VASCULOBILIARY INJURIES
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Vasculobiliary Injuries", "A distinct and high-risk category");

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 12.8, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });

  calloutBox(s, "Vasculobiliary injury: Simultaneous bile duct + hepatic artery / portal vein injury — significantly worsens prognosis", 0.35, 1.28, 12.5, 0.55, RED_ALERT);

  const vbiBullets = [
    { text: "Most common: right hepatic artery injury (stricture or occlusion) concurrent with BDI", bold: true },
    "Portal vein injuries less common but reported",
    { text: "Mechanism: excessive dissection medial to CBD, aggressive bleeding control", bold: false },
    { text: "Why it matters:", bold: true, color: RED_ALERT },
    { text: "Biliary blood supply compromised → ischemic stricture even after perfect repair", sub: true },
    { text: "Substantially increases stricture formation rate post-hepaticojejunostomy", sub: true },
    { text: "Increases liver failure risk, especially right lobe atrophy", sub: true },
    { text: "Diagnosis:", bold: true, color: MED_BLUE },
    { text: "CT angiography / MR angiography + MRCP — essential before repair", sub: true },
    { text: "Doppler ultrasound: assess hepatic artery flow", sub: true },
    { text: "Management:", bold: true, color: MED_BLUE },
    { text: "Vascular repair / reconstruction concurrent with biliary repair when possible", sub: true },
    { text: "Refer to high-volume HPB center with vascular surgery availability", sub: true, bold: true, color: RED_ALERT },
    { text: "Liver transplantation may be required in cases of liver failure (systematic review PMID 37633743)", sub: true },
  ];
  addBullets(s, vbiBullets, 0.35, 1.92, 12.5, 5.1, { fontSize: 14, color: "1A1A2E" });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 16 — OUTCOMES
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Outcomes & Long-term Follow-up", "Results after repair and predictors of success");

  // Outcome stat boxes row
  const outcomeStats = [
    { val: "70–90%", label: "5-yr success\nhepaticojejunostomy", color: TEAL },
    { val: "20–30%", label: "Long-term\nstricture rate", color: ACCENT_GOLD },
    { val: "↑3.3x", label: "Reoperation risk\nearly vs late repair", color: RED_ALERT },
    { val: "↑7.4x", label: "Stricture risk\nearly vs late repair", color: RED_ALERT },
  ];
  outcomeStats.forEach((o, i) => {
    const x = 0.25 + i * 3.2;
    s.addShape(pres.ShapeType.roundRect, { x, y: 1.2, w: 3.0, h: 1.6, fill: { color: o.color }, line: { color: WHITE, width: 1 }, rectRadius: 0.1 });
    s.addText(o.val, { x: x + 0.1, y: 1.22, w: 2.8, h: 0.85, fontSize: 26, bold: true, color: WHITE, fontFace: "Calibri", align: "center", valign: "middle" });
    s.addText(o.label, { x: x + 0.1, y: 2.05, w: 2.8, h: 0.65, fontSize: 11.5, color: WHITE, fontFace: "Calibri", align: "center" });
  });

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 3.0, w: 12.8, h: 4.1, fill: { color: WHITE }, line: { color: "CCDDEE" } });
  const outcomeBullets = [
    { text: "Predictor of success: repair by HPB specialist, delayed repair, tension-free anastomosis, adequate stenting", bold: true, color: TEAL },
    "Bismuth E3–E5 injuries have lower success rates and higher complication rates than E1–E2",
    { text: "Re-stricture rate: 10–30% within 5 years; most amenable to re-dilation or re-do hepaticojejunostomy", bold: false },
    { text: "Quality of life: significantly impaired post-BDI — comparable to other major abdominal morbidities", bold: false, color: RED_ALERT },
    "Mortality from BDI: 0.2–0.8% directly; higher with vasculobiliary injury",
    { text: "Long-term follow-up protocol: Annual LFTs (bilirubin, ALP, GGT) for life; cholangiography if LFTs abnormal", bold: true, color: MED_BLUE },
    "Cholangitis episodes: treated with antibiotics + endoscopic/percutaneous re-intervention",
    { text: "Liver transplantation outcomes: acceptable (systematic review 2023, PMID 37633743) — but high morbidity", bold: false, color: RED_ALERT },
  ];
  addBullets(s, outcomeBullets, 0.35, 3.05, 12.5, 4.0, { fontSize: 14, color: "1A1A2E" });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 17 — MEDICOLEGAL CONSIDERATIONS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Medicolegal Considerations", "BDI is a leading cause of surgical malpractice claims");

  s.addShape(pres.ShapeType.rect, { x: 0.25, y: 1.2, w: 12.8, h: 5.9, fill: { color: WHITE }, line: { color: "CCDDEE" } });

  calloutBox(s, "BDI is ONE of the most common reasons for surgical malpractice litigation — informed consent, documentation, and early disclosure are critical", 0.35, 1.28, 12.5, 0.55, RED_ALERT);

  const legalBullets = [
    { text: "Informed consent:", bold: true, color: MED_BLUE },
    { text: "Patient must be counseled about BDI risk (<1%) BEFORE cholecystectomy", sub: true },
    { text: "Document discussion of bile leak, stricture, conversion to open", sub: true },
    { text: "Intraoperative documentation:", bold: true, color: MED_BLUE },
    { text: "Always photograph/document CVS achievement before clipping", sub: true, bold: true },
    { text: "Document IOC findings if performed", sub: true },
    { text: "Document any conversion decision and rationale", sub: true },
    { text: "When BDI occurs:", bold: true, color: RED_ALERT },
    { text: "Transparent, prompt disclosure to patient and family", sub: true, bold: true },
    { text: "Immediate referral to experienced HPB surgeon (critical for outcome AND medicolegal protection)", sub: true },
    { text: "Incident reporting through institutional channels", sub: true },
    { text: "Do NOT attempt complex repair without HPB expertise — worsens outcome AND liability", sub: true, bold: true, color: RED_ALERT },
    { text: "Key principle:", bold: true, color: MED_BLUE },
    { text: "It is not the injury itself, but the delay in diagnosis and failed repair, that drive most successful litigation", sub: true, bold: true, color: RED_ALERT },
  ];
  addBullets(s, legalBullets, 0.35, 1.9, 12.5, 5.1, { fontSize: 13.5, color: "1A1A2E" });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 18 — ALGORITHM (flowchart text-based)
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  addHeader(s, "Management Algorithm", "Stepwise approach to suspected BDI");

  const steps = [
    { label: "SUSPECTED BDI\n(Intraop or Postop)", color: RED_ALERT, x: 5.0, y: 1.2, w: 3.3 },
    { label: "STABILIZE: Control sepsis\nDrain biloma (IR) / ABx", color: MED_BLUE, x: 0.3, y: 2.3, w: 3.4 },
    { label: "DEFINE ANATOMY:\nMRCP + CT angiography ± PTC", color: MED_BLUE, x: 4.8, y: 2.3, w: 3.7 },
    { label: "REFER TO\nHPB SPECIALIST", color: TEAL, x: 9.7, y: 2.3, w: 3.2 },
    { label: "TYPE A / D Injury\nBile leak / partial", color: ACCENT_GOLD, x: 0.3, y: 4.0, w: 3.0 },
    { label: "TYPE E (complete\ntransection / stricture)", color: RED_ALERT, x: 5.2, y: 4.0, w: 3.0 },
    { label: "Vasculobiliary\nInjury", color: "8B0000", x: 9.9, y: 4.0, w: 3.2 },
    { label: "ERCP + Stent\n(90% success)", color: TEAL, x: 0.3, y: 5.5, w: 2.5 },
    { label: "Delayed repair\n>6 weeks\nRoux-en-Y HJ", color: TEAL, x: 3.5, y: 5.5, w: 3.0 },
    { label: "High-volume\nHPB center\n± Vascular repair", color: MED_BLUE, x: 7.2, y: 5.5, w: 3.0 },
    { label: "Annual LFT surveillance — cholangiography if abnormal", color: DEEP_NAVY, x: 0.3, y: 6.9, w: 12.7 },
  ];

  steps.forEach(st => {
    s.addShape(pres.ShapeType.roundRect, { x: st.x, y: st.y, w: st.w, h: st.h > 0 ? st.h : 0.85, fill: { color: st.color }, line: { color: WHITE, width: 1 }, rectRadius: 0.07 });
    s.addText(st.label, { x: st.x + 0.05, y: st.y + 0.05, w: st.w - 0.1, h: (st.h || 0.85) - 0.1, fontSize: 11.5, bold: true, color: WHITE, fontFace: "Calibri", align: "center", valign: "middle" });
  });

  // Arrows (lines)
  const arrowOpts = { line: { color: ACCENT_GOLD, width: 2 }, headEnd: { type: "arrow" } };
  [[6.65, 2.05, 6.65, 2.3], [1.95, 3.15, 1.95, 4.0], [6.65, 3.15, 6.65, 4.0], [11.3, 3.15, 11.3, 4.0],
   [1.75, 4.85, 1.5, 5.5], [6.7, 4.85, 5.0, 5.5], [11.3, 4.85, 8.7, 5.5],
   [4.6, 6.35, 4.6, 6.9]].forEach(([x1, y1, x2, y2]) => {
    s.addShape(pres.ShapeType.line, { x: x1, y: y1, w: Math.abs(x2 - x1) || 0.01, h: Math.abs(y2 - y1) || 0.01, line: { color: ACCENT_GOLD, width: 2 } });
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 19 — KEY TAKEAWAYS
// ═══════════════════════════════════════════════════════════════════════════════
{
  const s = pres.addSlide();
  titleSlide(s);
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 0.2, h: 7.5, fill: { color: ACCENT_GOLD } });

  s.addText("KEY TAKEAWAYS", {
    x: 0.5, y: 0.25, w: 12, h: 0.65,
    fontSize: 32, bold: true, color: ACCENT_GOLD, fontFace: "Calibri", charSpacing: 4, margin: 0
  });
  s.addShape(pres.ShapeType.rect, { x: 0.5, y: 0.9, w: 10, h: 0.05, fill: { color: ACCENT_GOLD } });

  const takeaways = [
    { num: "1", text: "Misidentification of anatomy (NOT skill) drives most BDIs — confirmation bias is the enemy" },
    { num: "2", text: "Critical View of Safety: the single most effective BDI prevention strategy — document it photographically" },
    { num: "3", text: "When in doubt: subtotal cholecystectomy, cholecystostomy, or IOC — not forced dissection" },
    { num: "4", text: "Strasberg-Bismuth E3–E5 injuries require specialist HPB surgery — do NOT attempt at the index operation without expertise" },
    { num: "5", text: "SAGES-AHPBA 2025: delayed repair (>6 weeks) is superior to early repair — lower stricture, reoperation, mortality" },
    { num: "6", text: "Roux-en-Y hepaticojejunostomy is the gold standard for major BDI reconstruction; hepaticoduodenostomy is an alternative" },
    { num: "7", text: "Always assess for vasculobiliary injury — it dramatically increases stricture risk even after perfect repair" },
    { num: "8", text: "Transparent disclosure + early HPB referral = best medicolegal and clinical protection" },
  ];

  takeaways.forEach((t, i) => {
    const y = 1.05 + i * 0.78;
    s.addShape(pres.ShapeType.ellipse, { x: 0.5, y: y + 0.05, w: 0.5, h: 0.5, fill: { color: ACCENT_GOLD }, line: { color: ACCENT_GOLD } });
    s.addText(t.num, { x: 0.5, y: y + 0.05, w: 0.5, h: 0.5, fontSize: 14, bold: true, color: DEEP_NAVY, align: "center", valign: "middle" });
    s.addText(t.text, { x: 1.15, y: y, w: 11.8, h: 0.68, fontSize: 14.5, color: WHITE, fontFace: "Calibri", valign: "middle" });
  });

  s.addText("Sources: Sabiston Surgery 21e • Current Surgical Therapy 14e • Mulholland & Greenfield 7e • SAGES-AHPBA 2025 Guideline (Surg Endosc 2026)", {
    x: 0.5, y: 6.88, w: 12.6, h: 0.45,
    fontSize: 10, color: "8899BB", fontFace: "Calibri", align: "center", italic: true
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// WRITE FILE
// ═══════════════════════════════════════════════════════════════════════════════
const outputPath = "/home/daytona/workspace/bile-duct-injury-ppt/Iatrogenic_Bile_Duct_Injuries.pptx";
pres.writeFile({ fileName: outputPath })
  .then(() => console.log("SUCCESS: " + outputPath))
  .catch(err => console.error("ERROR:", err));
You've run out of free credits. Sign up for a free account to continue using Orris.
This is a shared conversation. Sign in to Orris to start your own chat.