anorectal malformation ppt with proper classification and diagrams to present in bsc nursing class

Reading File
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Finding Sources
Searching the Web

anorectal malformation Krickenbeck classification diagram imperforate anus types diagram

Running Command

mkdir -p /home/daytona/workspace/anorectal-malformation-ppt && ls /home/daytona/…

Writing File

~/anorectal-malformation-ppt/create_ppt.js

const pptxgen = require("pptxgenjs");

const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Anorectal Malformation";
pres.author = "BSc Nursing Lecture";

// Color palette - deep teal/navy theme suited for medical topic
const COLORS = {
  darkBg: "0D2D4A",       // Deep navy - title slides
  medBg: "134466",        // Mid navy - section headers
  lightBg: "EAF4FB",      // Light blue - content bg
  accent: "E8A127",       // Amber accent
  accent2: "2BB5A0",      // Teal accent
  white: "FFFFFF",
  dark: "1A2B3C",
  textDark: "1A2B3C",
  textLight: "E8F4F8",
  subtleGray: "D6E8F5",
  red: "C0392B",
  green: "1A7F5A",
};

// ─────────────────────────────────────────────
// SLIDE 1 – TITLE SLIDE
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.darkBg } });
  // Decorative accent bar
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 4.5, w: 10, h: 0.12, fill: { color: COLORS.accent } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 4.62, w: 10, h: 0.06, fill: { color: COLORS.accent2 } });

  // Medical cross icon (simple shape simulation)
  slide.addShape(pres.shapes.RECTANGLE, { x: 0.6, y: 1.4, w: 0.12, h: 0.42, fill: { color: COLORS.accent } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0.47, y: 1.54, w: 0.38, h: 0.12, fill: { color: COLORS.accent } });

  slide.addText("ANORECTAL MALFORMATION", {
    x: 0.8, y: 1.0, w: 9.0, h: 0.75,
    fontSize: 36, bold: true, color: COLORS.white,
    charSpacing: 2, fontFace: "Arial",
  });
  slide.addText("(Imperforate Anus & Related Defects)", {
    x: 0.8, y: 1.75, w: 9.0, h: 0.5,
    fontSize: 20, color: COLORS.accent, fontFace: "Arial", italic: true,
  });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0.8, y: 2.35, w: 2.5, h: 0.05, fill: { color: COLORS.accent2 } });
  slide.addText([
    { text: "BSc Nursing – Paediatric Nursing", options: { breakLine: true } },
    { text: "Congenital Disorders of the GI Tract", options: {} },
  ], {
    x: 0.8, y: 2.5, w: 8, h: 0.9,
    fontSize: 16, color: COLORS.textLight, fontFace: "Arial",
  });
  slide.addText("Incidence: 1 in 5000 live births  |  Male predominance 58%", {
    x: 0.8, y: 3.6, w: 8, h: 0.45,
    fontSize: 14, color: COLORS.accent2, fontFace: "Arial", italic: true,
  });
}

// ─────────────────────────────────────────────
// SLIDE 2 – OUTLINE
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.medBg } });
  slide.addText("LECTURE OUTLINE", {
    x: 0.3, y: 0.1, w: 9, h: 0.7,
    fontSize: 24, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  const topics = [
    "1. Definition & Embryology",
    "2. Incidence & Epidemiology",
    "3. Etiology & Risk Factors",
    "4. Classification of Anorectal Malformations",
    "   • Wingspread (Low / Intermediate / High)",
    "   • Krickenbeck International Classification",
    "   • Peña / Anatomic Classification",
    "5. Clinical Features & Diagnosis",
    "6. Associated Anomalies (VACTERL)",
    "7. Nursing Assessment & Management",
    "8. Surgical Treatment",
    "9. Post-operative Nursing Care",
  ];

  slide.addText(topics.map((t, i) => ({
    text: t,
    options: { breakLine: i < topics.length - 1 }
  })), {
    x: 0.5, y: 1.05, w: 9, h: 4.4,
    fontSize: 14, color: COLORS.textDark, fontFace: "Arial",
    lineSpacingMultiple: 1.3,
  });
}

// ─────────────────────────────────────────────
// SLIDE 3 – DEFINITION & EMBRYOLOGY
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("DEFINITION & EMBRYOLOGY", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 24, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  // Definition box
  slide.addShape(pres.shapes.RECTANGLE, {
    x: 0.3, y: 1.1, w: 9.4, h: 1.3,
    fill: { color: COLORS.darkBg }, shadow: { type: "outer", color: "000000", blur: 6, offset: 2, angle: 135, opacity: 0.15 },
  });
  slide.addText([
    { text: "DEFINITION: ", options: { bold: true, color: COLORS.accent } },
    { text: "A spectrum of congenital defects involving the distal anus, rectum, and urogenital tract, resulting in an abnormal or absent anal opening.", options: { color: COLORS.white } }
  ], {
    x: 0.5, y: 1.15, w: 9.0, h: 1.2, fontSize: 15, fontFace: "Arial",
  });

  slide.addText("Embryological Basis:", {
    x: 0.3, y: 2.55, w: 5, h: 0.4, fontSize: 16, bold: true, color: COLORS.darkBg, fontFace: "Arial",
  });

  const embryoPoints = [
    "Week 4–6: Cloaca divides into anterior (urogenital) sinus and posterior (anorectal) canal via the urorectal septum",
    "Week 8: Anal membrane normally resorbs to form anal opening",
    "Failure of urorectal septum → fistula between bowel and urinary/genital tract",
    "Failure of anal membrane resorption → anal stenosis or imperforate anus",
    "Abnormal cloacal fold fusion → anterior displacement of anal opening",
  ];
  slide.addText(embryoPoints.map((p, i) => ({
    text: "• " + p,
    options: { breakLine: i < embryoPoints.length - 1, paraSpaceBefore: 4 }
  })), {
    x: 0.3, y: 3.0, w: 9.4, h: 2.4, fontSize: 13, color: COLORS.textDark, fontFace: "Arial", lineSpacingMultiple: 1.25,
  });
}

// ─────────────────────────────────────────────
// SLIDE 4 – INCIDENCE & ETIOLOGY
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("INCIDENCE & ETIOLOGY", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 24, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  // Incidence stats boxes
  const stats = [
    { label: "Global Incidence", val: "1 in 5000\nlive births" },
    { label: "Male : Female", val: "58% : 42%" },
    { label: "Low defects", val: "~60%\nof cases" },
  ];
  stats.forEach((s, i) => {
    const xPos = 0.3 + i * 3.2;
    slide.addShape(pres.shapes.ROUNDED_RECTANGLE, {
      x: xPos, y: 1.1, w: 2.8, h: 1.3,
      fill: { color: COLORS.darkBg }, rectRadius: 0.1,
    });
    slide.addText(s.label, {
      x: xPos, y: 1.15, w: 2.8, h: 0.45, fontSize: 12, bold: true,
      color: COLORS.accent, align: "center", fontFace: "Arial",
    });
    slide.addText(s.val, {
      x: xPos, y: 1.6, w: 2.8, h: 0.65, fontSize: 18, bold: true,
      color: COLORS.white, align: "center", fontFace: "Arial",
    });
  });

  slide.addText("Etiology & Risk Factors:", {
    x: 0.3, y: 2.55, w: 5, h: 0.4, fontSize: 16, bold: true, color: COLORS.darkBg, fontFace: "Arial",
  });

  const etioPoints = [
    "Multifactorial – combination of genetic and environmental factors",
    "Paternal smoking is associated with increased risk",
    "Maternal obesity – identified risk factor",
    "Maternal pregestational and gestational diabetes",
    "Chromosomal: associated with Trisomy 21 (Down syndrome) – especially rectal atresia",
    "Genetic syndromes: VACTERL, OEIS, Currarino, MURCS",
  ];
  slide.addText(etioPoints.map((p, i) => ({
    text: "• " + p,
    options: { breakLine: i < etioPoints.length - 1, paraSpaceBefore: 3 }
  })), {
    x: 0.3, y: 3.0, w: 9.4, h: 2.4, fontSize: 13, color: COLORS.textDark, fontFace: "Arial", lineSpacingMultiple: 1.25,
  });
}

// ─────────────────────────────────────────────
// SLIDE 5 – CLASSIFICATION OVERVIEW (SECTION HEADER)
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 4.5, w: 10, h: 0.12, fill: { color: COLORS.accent } });
  slide.addText("CLASSIFICATION", {
    x: 1, y: 1.6, w: 8, h: 1.0, fontSize: 44, bold: true,
    color: COLORS.white, align: "center", fontFace: "Arial", charSpacing: 4,
  });
  slide.addText("of Anorectal Malformations", {
    x: 1, y: 2.65, w: 8, h: 0.6, fontSize: 22, italic: true,
    color: COLORS.accent2, align: "center", fontFace: "Arial",
  });
  slide.addText("Three Major Systems: Wingspread  |  Krickenbeck  |  Peña (Anatomic)", {
    x: 1, y: 3.4, w: 8, h: 0.5, fontSize: 14,
    color: COLORS.subtleGray, align: "center", fontFace: "Arial",
  });
}

// ─────────────────────────────────────────────
// SLIDE 6 – WINGSPREAD CLASSIFICATION (OLD)
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.medBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("WINGSPREAD CLASSIFICATION (1984) – Historical", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 22, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  slide.addText("Based on relationship of rectal pouch to levator ani muscle:", {
    x: 0.3, y: 1.05, w: 9, h: 0.4, fontSize: 14, italic: true, color: COLORS.textDark, fontFace: "Arial",
  });

  // Three columns
  const cols = [
    {
      title: "LOW DEFECT", color: COLORS.green, textColor: COLORS.white,
      male: ["Perineal fistula", "Anal stenosis", "Anterior perineal anus"],
      female: ["Perineal fistula", "Anal stenosis", "Anterior perineal anus"],
      note: "Rectal pouch descends BELOW levator ani",
    },
    {
      title: "INTERMEDIATE", color: COLORS.accent, textColor: COLORS.dark,
      male: ["Anal agenesis without fistula", "Rectobulbar fistula"],
      female: ["Anal agenesis without fistula", "Rectovestibular fistula", "Rectovaginal fistula (low)"],
      note: "Pouch at level of levator ani",
    },
    {
      title: "HIGH DEFECT", color: COLORS.red, textColor: COLORS.white,
      male: ["Anorectal agenesis without fistula", "Rectoprostatic urethral fistula", "Rectovesical fistula"],
      female: ["Anorectal agenesis without fistula", "Rectovaginal fistula (high)", "Rectal atresia"],
      note: "Pouch is ABOVE levator ani",
    },
  ];

  cols.forEach((col, i) => {
    const xPos = 0.25 + i * 3.3;
    slide.addShape(pres.shapes.RECTANGLE, {
      x: xPos, y: 1.55, w: 3.1, h: 0.5, fill: { color: col.color },
    });
    slide.addText(col.title, {
      x: xPos, y: 1.55, w: 3.1, h: 0.5, fontSize: 13, bold: true,
      color: col.textColor, align: "center", fontFace: "Arial",
    });
    slide.addShape(pres.shapes.RECTANGLE, {
      x: xPos, y: 2.05, w: 3.1, h: 3.1, fill: { color: COLORS.white },
    });
    slide.addText("♂ MALE:", {
      x: xPos + 0.1, y: 2.1, w: 2.9, h: 0.3, fontSize: 11, bold: true, color: COLORS.medBg, fontFace: "Arial",
    });
    slide.addText(col.male.map((m, j) => ({
      text: "• " + m, options: { breakLine: j < col.male.length - 1 }
    })), {
      x: xPos + 0.1, y: 2.4, w: 2.9, h: 0.85, fontSize: 11, color: COLORS.textDark, fontFace: "Arial",
    });
    slide.addText("♀ FEMALE:", {
      x: xPos + 0.1, y: 3.28, w: 2.9, h: 0.3, fontSize: 11, bold: true, color: COLORS.red, fontFace: "Arial",
    });
    slide.addText(col.female.map((f, j) => ({
      text: "• " + f, options: { breakLine: j < col.female.length - 1 }
    })), {
      x: xPos + 0.1, y: 3.58, w: 2.9, h: 0.85, fontSize: 11, color: COLORS.textDark, fontFace: "Arial",
    });
    slide.addShape(pres.shapes.RECTANGLE, {
      x: xPos, y: 5.15, w: 3.1, h: 0.35, fill: { color: col.color },
    });
    slide.addText(col.note, {
      x: xPos, y: 5.15, w: 3.1, h: 0.35, fontSize: 10, italic: true,
      color: col.textColor, align: "center", fontFace: "Arial",
    });
  });
}

// ─────────────────────────────────────────────
// SLIDE 7 – KRICKENBECK CLASSIFICATION (CURRENT STANDARD)
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("KRICKENBECK CLASSIFICATION (2005) – CURRENT STANDARD", {
    x: 0.3, y: 0.1, w: 9.4, h: 0.7, fontSize: 20, bold: true, color: COLORS.white, fontFace: "Arial",
  });
  slide.addText("International consensus – classifies by fistula site (anatomic/functional basis)", {
    x: 0.3, y: 1.02, w: 9.4, h: 0.35, fontSize: 13, italic: true, color: COLORS.textDark, fontFace: "Arial",
  });

  // Two columns: Major groups + Rare/Regional variants
  // Left column
  slide.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 1.42, w: 4.5, h: 0.45, fill: { color: COLORS.medBg } });
  slide.addText("MAJOR CLINICAL GROUPS", {
    x: 0.25, y: 1.42, w: 4.5, h: 0.45, fontSize: 13, bold: true,
    color: COLORS.white, align: "center", fontFace: "Arial",
  });

  const majorGroups = [
    { cat: "MALE", items: ["Rectoperineal (cutaneous) fistula", "Rectourethral fistula – Bulbar", "Rectourethral fistula – Prostatic", "Recto-bladder neck fistula", "Imperforate anus WITHOUT fistula"] },
    { cat: "FEMALE", items: ["Rectoperineal (cutaneous) fistula", "Rectovestibular fistula", "Imperforate anus WITHOUT fistula", "Cloaca (common channel)"] },
  ];

  let yOffset = 1.92;
  majorGroups.forEach(g => {
    slide.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: yOffset, w: 4.5, h: 0.32, fill: { color: g.cat === "MALE" ? COLORS.accent2 : COLORS.accent } });
    slide.addText(g.cat === "MALE" ? "♂ Male" : "♀ Female", {
      x: 0.25, y: yOffset, w: 4.5, h: 0.32, fontSize: 12, bold: true,
      color: COLORS.white, align: "center", fontFace: "Arial",
    });
    yOffset += 0.32;
    g.items.forEach(item => {
      slide.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: yOffset, w: 4.5, h: 0.33, fill: { color: COLORS.white } });
      slide.addText("• " + item, {
        x: 0.35, y: yOffset + 0.03, w: 4.3, h: 0.28, fontSize: 11.5, color: COLORS.textDark, fontFace: "Arial",
      });
      yOffset += 0.33;
    });
    yOffset += 0.05;
  });

  // Right column
  slide.addShape(pres.shapes.RECTANGLE, { x: 5.0, y: 1.42, w: 4.75, h: 0.45, fill: { color: COLORS.medBg } });
  slide.addText("RARE / REGIONAL VARIANTS", {
    x: 5.0, y: 1.42, w: 4.75, h: 0.45, fontSize: 13, bold: true,
    color: COLORS.white, align: "center", fontFace: "Arial",
  });
  const rare = ["Pouch colon", "Rectal atresia / stenosis", "Rectovaginal fistula", "H-type fistula", "Others"];
  rare.forEach((r, i) => {
    slide.addShape(pres.shapes.RECTANGLE, { x: 5.0, y: 1.92 + i * 0.33, w: 4.75, h: 0.33, fill: { color: i % 2 === 0 ? COLORS.white : COLORS.subtleGray } });
    slide.addText("• " + r, {
      x: 5.1, y: 1.95 + i * 0.33, w: 4.55, h: 0.28, fontSize: 12, color: COLORS.textDark, fontFace: "Arial",
    });
  });

  // Note box
  slide.addShape(pres.shapes.ROUNDED_RECTANGLE, {
    x: 5.0, y: 3.7, w: 4.75, h: 1.6, fill: { color: COLORS.darkBg }, rectRadius: 0.08,
  });
  slide.addText([
    { text: "Key Notes:\n", options: { bold: true, color: COLORS.accent, breakLine: true } },
    { text: "• Replaces old low/intermediate/high system\n• Emphasises preoperative anatomic identification\n• Guides surgical planning & prognosis\n• Cloaca is most complex female defect", options: { color: COLORS.white } },
  ], {
    x: 5.15, y: 3.78, w: 4.45, h: 1.45, fontSize: 12, fontFace: "Arial",
  });
}

// ─────────────────────────────────────────────
// SLIDE 8 – PEÑA ANATOMIC CLASSIFICATION (MALE)
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.medBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("PEÑA ANATOMIC CLASSIFICATION – MALE DEFECTS", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 22, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  const maleTypes = [
    {
      title: "1. Rectoperineal Fistula",
      color: COLORS.green,
      desc: "Rectal opening on perineal skin, anterior to sphincter. LOWEST defect. Meconium visible at perineum. Best prognosis. Single-stage PSARP without colostomy.",
      prog: "Excellent",
    },
    {
      title: "2. Rectobulbar Urethral Fistula",
      color: COLORS.accent2,
      desc: "Fistula between rectum and bulbar urethra. MOST COMMON male defect (~50%). Meconium in urine. Requires colostomy + PSARP.",
      prog: "Good",
    },
    {
      title: "3. Rectoprostatic Urethral Fistula",
      color: COLORS.accent,
      desc: "Fistula enters at prostatic urethra. Gas and meconium in urine. Higher sacral defects common. Requires staged repair.",
      prog: "Moderate",
    },
    {
      title: "4. Recto-Bladder Neck Fistula",
      color: COLORS.red,
      desc: "Highest defect – fistula at bladder neck. 90% have urinary tract anomaly. Associated with poor sacral development and poor continence.",
      prog: "Poor",
    },
    {
      title: "5. Imperforate Anus – No Fistula",
      color: "7B3F9E",
      desc: "No anal opening, no fistula. Associated with Down syndrome (Trisomy 21). Pouch confirmed by colostogram. PSARP repair after 1–3 months.",
      prog: "Good",
    },
  ];

  maleTypes.forEach((t, i) => {
    const yPos = 1.05 + i * 0.88;
    slide.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: yPos, w: 0.18, h: 0.72, fill: { color: t.color } });
    slide.addShape(pres.shapes.RECTANGLE, { x: 0.43, y: yPos, w: 7.5, h: 0.72, fill: { color: COLORS.white } });
    slide.addText(t.title, {
      x: 0.55, y: yPos + 0.04, w: 7.3, h: 0.28, fontSize: 13, bold: true, color: COLORS.darkBg, fontFace: "Arial",
    });
    slide.addText(t.desc, {
      x: 0.55, y: yPos + 0.32, w: 6.8, h: 0.36, fontSize: 11, color: COLORS.textDark, fontFace: "Arial",
    });
    // Prognosis tag
    const progColor = t.prog === "Excellent" ? COLORS.green : t.prog === "Good" ? COLORS.accent2 : t.prog === "Moderate" ? COLORS.accent : COLORS.red;
    slide.addShape(pres.shapes.RECTANGLE, { x: 7.93, y: yPos + 0.16, w: 1.8, h: 0.36, fill: { color: progColor } });
    slide.addText("Prognosis: " + t.prog, {
      x: 7.93, y: yPos + 0.18, w: 1.8, h: 0.3, fontSize: 10, bold: true,
      color: COLORS.white, align: "center", fontFace: "Arial",
    });
  });
}

// ─────────────────────────────────────────────
// SLIDE 9 – PEÑA ANATOMIC CLASSIFICATION (FEMALE)
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.red } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("PEÑA ANATOMIC CLASSIFICATION – FEMALE DEFECTS", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 22, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  const femaleTypes = [
    {
      title: "1. Rectoperineal Fistula",
      color: COLORS.green,
      desc: "Most minor female defect. Opening anterior to sphincter on perineum. Visible meconium. Primary repair without colostomy.",
    },
    {
      title: "2. Rectovestibular Fistula",
      color: COLORS.accent2,
      desc: "MOST COMMON female defect (~50%). Fistula opens at vaginal vestibule (introitus). Two perineal openings visible. Good prognosis.",
    },
    {
      title: "3. Imperforate Anus – No Fistula",
      color: COLORS.accent,
      desc: "No fistula visible. Anal opening absent. Down syndrome associated. Colostomy required before definitive repair.",
    },
    {
      title: "4. Cloaca (Common Channel Defect)",
      color: COLORS.red,
      desc: "MOST COMPLEX. Rectum, vagina and urethra fuse into a SINGLE common channel. Only ONE perineal opening. Short common channel (<3cm) = better prognosis vs. Long channel (>3cm). 90% have urinary anomalies.",
    },
    {
      title: "5. Rectal Atresia",
      color: "7B3F9E",
      desc: "Lumen completely or partially interrupted. Upper rectum dilated; lower rectum is blind small canal. Associated with Trisomy 21.",
    },
  ];

  femaleTypes.forEach((t, i) => {
    const yPos = 1.05 + i * 0.88;
    slide.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: yPos, w: 0.18, h: 0.72, fill: { color: t.color } });
    slide.addShape(pres.shapes.RECTANGLE, { x: 0.43, y: yPos, w: 9.32, h: 0.72, fill: { color: COLORS.white } });
    slide.addText(t.title, {
      x: 0.55, y: yPos + 0.04, w: 9.1, h: 0.28, fontSize: 13, bold: true, color: COLORS.darkBg, fontFace: "Arial",
    });
    slide.addText(t.desc, {
      x: 0.55, y: yPos + 0.32, w: 9.1, h: 0.36, fontSize: 11, color: COLORS.textDark, fontFace: "Arial",
    });
  });
}

// ─────────────────────────────────────────────
// SLIDE 10 – DIAGRAMMATIC REPRESENTATION
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: "0D1B2A" } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.medBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("DIAGRAMMATIC OVERVIEW – TYPES OF ARM", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 22, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  // Draw 4 mini diagrams using shapes to represent defect types
  // Each diagram = simplified pelvic anatomy

  const diagrams = [
    { label: "Normal Anatomy", x: 0.15, y: 1.0, color: COLORS.accent2 },
    { label: "Perineal Fistula (Low)", x: 2.6, y: 1.0, color: COLORS.green },
    { label: "Rectourethral\nFistula (Male)", x: 5.1, y: 1.0, color: COLORS.accent },
    { label: "Cloaca\n(Female)", x: 7.6, y: 1.0, color: COLORS.red },
  ];

  diagrams.forEach(d => {
    // Background box
    slide.addShape(pres.shapes.RECTANGLE, {
      x: d.x, y: d.y, w: 2.3, h: 4.4, fill: { color: "1A2B3C" },
    });
    // Title
    slide.addShape(pres.shapes.RECTANGLE, {
      x: d.x, y: d.y, w: 2.3, h: 0.4, fill: { color: d.color },
    });
    slide.addText(d.label, {
      x: d.x, y: d.y, w: 2.3, h: 0.4, fontSize: 10, bold: true,
      color: COLORS.white, align: "center", fontFace: "Arial",
    });
  });

  // NORMAL: Draw colon, rectum, sphincter, normal anus
  const drawBody = (slide, bx, by) => {
    // Sacrum (dark rectangle)
    slide.addShape(pres.shapes.RECTANGLE, { x: bx + 0.6, y: by + 0.5, w: 0.5, h: 1.1, fill: { color: "3D2B1A" } });
    // Rectum
    slide.addShape(pres.shapes.RECTANGLE, { x: bx + 0.35, y: by + 0.5, w: 0.25, h: 1.0, fill: { color: "C0392B" } });
    // Levator ani
    slide.addShape(pres.shapes.RECTANGLE, { x: bx + 0.1, y: by + 1.55, w: 1.55, h: 0.12, fill: { color: "2BB5A0" } });
    // Sphincter label
    slide.addText("Levator ani", { x: bx + 0.05, y: by + 1.7, w: 1.65, h: 0.22, fontSize: 8, color: COLORS.accent2, fontFace: "Arial", align: "center" });
  };

  // Normal: anus at base
  const nx = diagrams[0].x, ny = diagrams[0].y;
  drawBody(slide, nx, ny);
  // Anal canal
  slide.addShape(pres.shapes.RECTANGLE, { x: nx + 0.35, y: ny + 1.55, w: 0.25, h: 0.65, fill: { color: "C0392B" } });
  slide.addShape(pres.shapes.ELLIPSE, { x: nx + 0.32, y: ny + 2.2, w: 0.31, h: 0.16, fill: { color: COLORS.accent } });
  slide.addText("✓ Normal Anus", { x: nx + 0.05, y: ny + 2.4, w: 1.9, h: 0.3, fontSize: 9, color: COLORS.accent2, fontFace: "Arial", align: "center" });

  // Perineal fistula: opening anterior but anus absent
  const px = diagrams[1].x, py = diagrams[1].y;
  drawBody(slide, px, py);
  // Blind rectal pouch
  slide.addShape(pres.shapes.RECTANGLE, { x: px + 0.35, y: py + 1.55, w: 0.25, h: 0.4, fill: { color: "C0392B" } });
  slide.addShape(pres.shapes.ELLIPSE, { x: px + 0.32, y: py + 1.95, w: 0.31, h: 0.12, fill: { color: "8B0000" } });
  // Fistula track going anteriorly
  slide.addShape(pres.shapes.RECTANGLE, { x: px + 0.22, y: py + 2.02, w: 0.4, h: 0.07, fill: { color: "E8A127" } });
  slide.addShape(pres.shapes.ELLIPSE, { x: px + 0.57, y: py + 1.98, w: 0.16, h: 0.16, fill: { color: "E8A127" } });
  slide.addText("Fistula opening\non perineum", { x: px + 0.05, y: py + 2.2, w: 1.9, h: 0.35, fontSize: 8.5, color: COLORS.accent, fontFace: "Arial", align: "center" });
  slide.addText("No normal anal\nopening", { x: px + 0.05, y: py + 2.6, w: 1.9, h: 0.35, fontSize: 8.5, color: COLORS.red, fontFace: "Arial", align: "center" });
  slide.addText("→ Lowest defect\n→ Best prognosis\n→ PSARP, no ostomy", { x: px + 0.05, y: py + 3.0, w: 1.9, h: 0.7, fontSize: 8, color: COLORS.textLight, fontFace: "Arial", align: "center" });

  // Rectourethral fistula
  const ux = diagrams[2].x, uy = diagrams[2].y;
  drawBody(slide, ux, uy);
  // Rectum ending blind above levator
  slide.addShape(pres.shapes.RECTANGLE, { x: ux + 0.35, y: uy + 0.5, w: 0.25, h: 0.8, fill: { color: "C0392B" } });
  slide.addShape(pres.shapes.ELLIPSE, { x: ux + 0.32, y: uy + 1.3, w: 0.31, h: 0.12, fill: { color: "8B0000" } });
  // Fistula to urethra
  slide.addShape(pres.shapes.RECTANGLE, { x: ux + 0.3, y: uy + 1.38, w: 0.5, h: 0.07, fill: { color: "E8A127" } });
  // Urethra
  slide.addShape(pres.shapes.RECTANGLE, { x: ux + 0.78, y: uy + 1.0, w: 0.12, h: 0.72, fill: { color: "2980B9" } });
  slide.addText("Bladder", { x: ux + 0.75, y: uy + 0.65, w: 0.7, h: 0.22, fontSize: 7, color: "2980B9", fontFace: "Arial" });
  slide.addText("Fistula →\nUrethra", { x: ux + 0.05, y: uy + 2.2, w: 1.9, h: 0.4, fontSize: 8.5, color: COLORS.accent, fontFace: "Arial", align: "center" });
  slide.addText("→ High defect\n→ Colostomy first\n→ Meconium in urine", { x: ux + 0.05, y: py + 3.0, w: 1.9, h: 0.65, fontSize: 8, color: COLORS.textLight, fontFace: "Arial", align: "center" });

  // Cloaca (female)
  const cx = diagrams[3].x, cy = diagrams[3].y;
  drawBody(slide, cx, cy);
  // Three structures merging
  // Rectum
  slide.addShape(pres.shapes.RECTANGLE, { x: cx + 0.15, y: cy + 0.5, w: 0.2, h: 0.9, fill: { color: "C0392B" } });
  // Vagina
  slide.addShape(pres.shapes.RECTANGLE, { x: cx + 0.38, y: cy + 0.55, w: 0.18, h: 0.85, fill: { color: "E91E8C" } });
  // Urethra
  slide.addShape(pres.shapes.RECTANGLE, { x: cx + 0.6, y: cy + 0.6, w: 0.12, h: 0.8, fill: { color: "2980B9" } });
  // Convergence
  slide.addShape(pres.shapes.RECTANGLE, { x: cx + 0.15, y: cy + 1.42, w: 0.57, h: 0.2, fill: { color: COLORS.accent } });
  slide.addText("Common Channel", { x: cx + 0.05, y: cy + 1.65, w: 1.9, h: 0.3, fontSize: 8.5, color: COLORS.accent, fontFace: "Arial", align: "center" });
  slide.addShape(pres.shapes.ELLIPSE, { x: cx + 0.35, y: cy + 2.0, w: 0.2, h: 0.15, fill: { color: COLORS.accent } });
  slide.addText("Single opening\n(1 perineal orifice)", { x: cx + 0.05, y: cy + 2.2, w: 1.9, h: 0.4, fontSize: 8.5, color: COLORS.accent, fontFace: "Arial", align: "center" });
  slide.addText("R = Rectum | V = Vagina\nU = Urethra", { x: cx + 0.05, y: cy + 2.65, w: 1.9, h: 0.4, fontSize: 8.5, color: COLORS.textLight, fontFace: "Arial", align: "center" });
  slide.addText("→ Most complex\n→ 90% urinary anomaly\n→ Worst prognosis", { x: cx + 0.05, y: cy + 3.1, w: 1.9, h: 0.65, fontSize: 8, color: COLORS.red, fontFace: "Arial", align: "center" });
}

// ─────────────────────────────────────────────
// SLIDE 11 – CLINICAL FEATURES & DIAGNOSIS
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("CLINICAL FEATURES & DIAGNOSIS", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 24, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  // Left: Clinical Features
  slide.addShape(pres.shapes.RECTANGLE, { x: 0.2, y: 1.0, w: 4.6, h: 0.42, fill: { color: COLORS.medBg } });
  slide.addText("Clinical Features", { x: 0.2, y: 1.0, w: 4.6, h: 0.42, fontSize: 14, bold: true, color: COLORS.white, align: "center", fontFace: "Arial" });
  const clinFeatures = [
    "Absent or abnormal anal opening at birth",
    "No passage of meconium within 24–48 hours",
    "Meconium in urine (fistula to urinary tract)",
    "Abdominal distension (intestinal obstruction)",
    "Vomiting (intestinal obstruction)",
    "Meconium on perineum (perineal fistula)",
    "Single perineal opening in females → cloaca",
    "Flat perineum / absent gluteal crease",
  ];
  slide.addText(clinFeatures.map((f, i) => ({
    text: "• " + f, options: { breakLine: i < clinFeatures.length - 1, paraSpaceBefore: 3 }
  })), {
    x: 0.2, y: 1.42, w: 4.6, h: 4.0, fontSize: 11.5, color: COLORS.textDark, fontFace: "Arial",
    lineSpacingMultiple: 1.25, fill: { color: COLORS.white },
  });

  // Right: Diagnosis
  slide.addShape(pres.shapes.RECTANGLE, { x: 5.2, y: 1.0, w: 4.6, h: 0.42, fill: { color: COLORS.accent2 } });
  slide.addText("Diagnostic Workup", { x: 5.2, y: 1.0, w: 4.6, h: 0.42, fontSize: 14, bold: true, color: COLORS.white, align: "center", fontFace: "Arial" });
  const diagTests = [
    ["Perineal inspection", "Clinical – look for fistula, anal opening"],
    ["Invertogram / Cross-table lateral X-ray", "Shows level of rectal pouch (gas bubble)"],
    ["Distal colostogram", "Gold standard to delineate fistula site"],
    ["Renal ultrasound", "Detect VUR, hydronephrosis, renal agenesis"],
    ["Voiding cystourethrogram", "Assess urinary tract and fistula"],
    ["Spinal MRI", "Tethered cord, sacral agenesis"],
    ["Echocardiogram", "Rule out cardiac defects (VACTERL)"],
    ["OGT tube placement", "Rule out esophageal atresia"],
  ];
  diagTests.forEach((t, i) => {
    slide.addShape(pres.shapes.RECTANGLE, { x: 5.2, y: 1.42 + i * 0.51, w: 4.6, h: 0.49, fill: { color: i % 2 === 0 ? COLORS.white : COLORS.subtleGray } });
    slide.addText(t[0], { x: 5.3, y: 1.45 + i * 0.51, w: 4.4, h: 0.2, fontSize: 11, bold: true, color: COLORS.darkBg, fontFace: "Arial" });
    slide.addText(t[1], { x: 5.3, y: 1.65 + i * 0.51, w: 4.4, h: 0.2, fontSize: 10.5, color: COLORS.textDark, fontFace: "Arial" });
  });
}

// ─────────────────────────────────────────────
// SLIDE 12 – ASSOCIATED ANOMALIES (VACTERL)
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("ASSOCIATED ANOMALIES – VACTERL & OTHERS", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 22, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  // VACTERL acronym boxes
  const vacterl = [
    { letter: "V", meaning: "Vertebral anomalies", detail: "~30–44% of ARM patients" },
    { letter: "A", meaning: "Anal atresia", detail: "= ARM itself" },
    { letter: "C", meaning: "Cardiac malformations", detail: "Check with Echo before surgery" },
    { letter: "T", meaning: "Tracheo-Esophageal fistula", detail: "Exclude with OGT tube" },
    { letter: "E", meaning: "Esophageal atresia", detail: "OGT tube placement" },
    { letter: "R", meaning: "Renal anomalies", detail: "VUR, hydronephrosis, horseshoe kidney" },
    { letter: "L", meaning: "Limb abnormalities", detail: "Radial ray defects" },
  ];

  vacterl.forEach((v, i) => {
    const xPos = 0.2 + (i % 4) * 2.45;
    const yPos = 1.1 + Math.floor(i / 4) * 1.45;
    slide.addShape(pres.shapes.RECTANGLE, { x: xPos, y: yPos, w: 2.25, h: 1.3, fill: { color: COLORS.white }, shadow: { type: "outer", color: "000000", blur: 4, offset: 2, angle: 135, opacity: 0.12 } });
    slide.addShape(pres.shapes.RECTANGLE, { x: xPos, y: yPos, w: 0.6, h: 1.3, fill: { color: COLORS.darkBg } });
    slide.addText(v.letter, { x: xPos, y: yPos + 0.3, w: 0.6, h: 0.65, fontSize: 28, bold: true, color: COLORS.accent, align: "center", fontFace: "Arial" });
    slide.addText(v.meaning, { x: xPos + 0.65, y: yPos + 0.1, w: 1.55, h: 0.5, fontSize: 11, bold: true, color: COLORS.darkBg, fontFace: "Arial" });
    slide.addText(v.detail, { x: xPos + 0.65, y: yPos + 0.62, w: 1.55, h: 0.55, fontSize: 10, color: COLORS.textDark, fontFace: "Arial", italic: true });
  });

  // Other syndromes
  slide.addShape(pres.shapes.RECTANGLE, { x: 0.2, y: 3.85, w: 9.6, h: 1.55, fill: { color: COLORS.darkBg } });
  slide.addText("Other Syndromes Associated with ARM:", {
    x: 0.4, y: 3.92, w: 5, h: 0.35, fontSize: 13, bold: true, color: COLORS.accent, fontFace: "Arial",
  });
  slide.addText([
    { text: "• OEIS: ", options: { bold: true, color: COLORS.accent2 } }, { text: "Omphalocele, Exstrophy, Imperforate anus, Spinal defects\n", options: { color: COLORS.white } },
    { text: "• MURCS: ", options: { bold: true, color: COLORS.accent2 } }, { text: "Müllerian duct aplasia, Renal aplasia, Cervicothoracic somite dysplasia\n", options: { color: COLORS.white } },
    { text: "• Currarino syndrome: ", options: { bold: true, color: COLORS.accent2 } }, { text: "ARM + Sacrococcygeal defect + Presacral mass (tethered cord >80%)", options: { color: COLORS.white } },
  ], {
    x: 0.4, y: 4.3, w: 9.2, h: 1.0, fontSize: 12, fontFace: "Arial",
  });
}

// ─────────────────────────────────────────────
// SLIDE 13 – NURSING ASSESSMENT
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.accent2 } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("NURSING ASSESSMENT", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 24, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  const assessData = [
    {
      cat: "IMMEDIATE NEONATAL",
      color: COLORS.red,
      items: ["Inspect perineum within first 24 hours of birth", "Note number of perineal openings (female)", "Look for meconium on perineum / in urine", "Assess for abdominal distension", "Note passage of meconium via rectum or elsewhere"],
    },
    {
      cat: "VITAL SIGNS & SYSTEMIC",
      color: COLORS.medBg,
      items: ["Temperature, pulse, respiratory rate, oxygen saturation", "Signs of intestinal obstruction: bilious vomiting, distension", "Assess for VACTERL anomalies: spine, limbs, cardiac, renal"],
    },
    {
      cat: "PSYCHOSOCIAL",
      color: COLORS.accent,
      items: ["Parental anxiety and coping", "Explain diagnosis and planned management to family", "Refer to social worker/support group as needed"],
    },
  ];

  let yStart = 1.05;
  assessData.forEach(a => {
    slide.addShape(pres.shapes.RECTANGLE, { x: 0.2, y: yStart, w: 9.6, h: 0.38, fill: { color: a.color } });
    slide.addText(a.cat, { x: 0.3, y: yStart + 0.03, w: 9.4, h: 0.32, fontSize: 13, bold: true, color: COLORS.white, fontFace: "Arial" });
    yStart += 0.38;
    a.items.forEach(item => {
      slide.addShape(pres.shapes.RECTANGLE, { x: 0.2, y: yStart, w: 9.6, h: 0.34, fill: { color: COLORS.white } });
      slide.addText("• " + item, { x: 0.35, y: yStart + 0.04, w: 9.3, h: 0.28, fontSize: 12, color: COLORS.textDark, fontFace: "Arial" });
      yStart += 0.34;
    });
    yStart += 0.1;
  });
}

// ─────────────────────────────────────────────
// SLIDE 14 – MANAGEMENT & SURGERY
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("SURGICAL MANAGEMENT", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 24, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  const mgmtSteps = [
    {
      step: "LOW DEFECTS",
      color: COLORS.green,
      action: "Primary single-stage repair (PSARP or cutback anoplasty) – NO colostomy required. Perineal fistula, vestibular fistula → primary repair. Serial dilatation for anal stenosis.",
    },
    {
      step: "HIGH / INTERMEDIATE DEFECTS",
      color: COLORS.accent,
      action: "STAGED repair: Step 1 = Divided sigmoid loop colostomy within first 24–48 h of life. Step 2 = Distal colostogram to delineate fistula (at 1–3 months). Step 3 = PSARP (Posterior Sagittal AnorRectoPlasty) – main definitive repair. Step 4 = Colostomy closure 4–8 weeks after PSARP.",
    },
    {
      step: "CLOACA (FEMALE)",
      color: COLORS.red,
      action: "Most complex. Colostomy + vaginal drainage at birth. Total urogenital mobilization (TUM) for short channel (<3 cm). Long channel (>3 cm) requires separate bowel, vaginal, and urethral reconstruction.",
    },
    {
      step: "POST-OPERATIVE DILATATION",
      color: COLORS.accent2,
      action: "Begin serial anal dilatations 2 weeks after repair. Gradual size increase over several months. Colostomy closed once calibration is adequate.",
    },
  ];

  let yPos = 1.06;
  mgmtSteps.forEach(m => {
    slide.addShape(pres.shapes.RECTANGLE, { x: 0.2, y: yPos, w: 2.6, h: 0.98, fill: { color: m.color } });
    slide.addText(m.step, { x: 0.25, y: yPos + 0.08, w: 2.5, h: 0.82, fontSize: 12, bold: true, color: COLORS.white, fontFace: "Arial", align: "center", valign: "middle" });
    slide.addShape(pres.shapes.RECTANGLE, { x: 2.8, y: yPos, w: 6.95, h: 0.98, fill: { color: COLORS.white } });
    slide.addText(m.action, { x: 2.9, y: yPos + 0.06, w: 6.75, h: 0.86, fontSize: 11.5, color: COLORS.textDark, fontFace: "Arial" });
    yPos += 1.05;
  });
}

// ─────────────────────────────────────────────
// SLIDE 15 – POST-OP NURSING CARE
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.accent2 } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("POST-OPERATIVE NURSING CARE", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 24, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  const nursingCols = [
    {
      title: "Colostomy Care",
      color: COLORS.medBg,
      items: [
        "Monitor stoma for color, size, output",
        "Peristomal skin care – protective barriers",
        "Empty and measure colostomy output",
        "Teach parents colostomy bag change",
        "Watch for prolapse, retraction, stenosis",
      ],
    },
    {
      title: "Post-PSARP Care",
      color: COLORS.darkBg,
      items: [
        "Keep wound clean and dry – avoid diaper",
        "Position: prone or lateral to avoid pressure on wound",
        "Monitor for wound dehiscence, infection",
        "Anal dilatation programme – parent education",
        "Adequate pain management (opioids, paracetamol)",
      ],
    },
    {
      title: "Long-term Outcomes",
      color: COLORS.accent2,
      items: [
        "Fecal continence (depends on defect level & sacral anatomy)",
        "Constipation management (high fibre, laxatives, bowel irrigation)",
        "Urinary continence monitoring (neurogenic bladder risk)",
        "Regular follow-up – growth & development",
        "Psychosocial support for child and family",
      ],
    },
  ];

  nursingCols.forEach((col, i) => {
    const xPos = 0.2 + i * 3.3;
    slide.addShape(pres.shapes.RECTANGLE, { x: xPos, y: 1.05, w: 3.1, h: 0.42, fill: { color: col.color } });
    slide.addText(col.title, { x: xPos, y: 1.05, w: 3.1, h: 0.42, fontSize: 12, bold: true, color: COLORS.white, align: "center", fontFace: "Arial" });
    col.items.forEach((item, j) => {
      slide.addShape(pres.shapes.RECTANGLE, { x: xPos, y: 1.47 + j * 0.78, w: 3.1, h: 0.77, fill: { color: j % 2 === 0 ? COLORS.white : COLORS.subtleGray } });
      slide.addText("• " + item, { x: xPos + 0.1, y: 1.5 + j * 0.78, w: 2.9, h: 0.7, fontSize: 11, color: COLORS.textDark, fontFace: "Arial" });
    });
  });
}

// ─────────────────────────────────────────────
// SLIDE 16 – QUICK SUMMARY TABLE
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.lightBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 0.9, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0.9, w: 10, h: 0.06, fill: { color: COLORS.accent } });
  slide.addText("QUICK SUMMARY – TYPES AT A GLANCE", {
    x: 0.3, y: 0.1, w: 9, h: 0.7, fontSize: 22, bold: true, color: COLORS.white, fontFace: "Arial",
  });

  const tableRows = [
    ["Type", "Sex", "Fistula Site", "Prognosis", "Colostomy?"],
    ["Perineal fistula", "Both", "Perineal skin", "Excellent", "No"],
    ["Rectovestibular fistula", "Female", "Vaginal vestibule", "Good", "Usually No"],
    ["Rectobulbar urethral fistula", "Male", "Bulbar urethra", "Good", "Yes"],
    ["Rectoprostatic fistula", "Male", "Prostatic urethra", "Moderate", "Yes"],
    ["Recto-bladder neck fistula", "Male", "Bladder neck", "Poor", "Yes"],
    ["Imperforate anus – No fistula", "Both", "None", "Good", "Yes"],
    ["Cloaca", "Female", "Single channel", "Variable/Poor", "Yes"],
    ["Rectal atresia", "Both", "None", "Moderate", "Yes"],
  ];

  const colWidths = [2.8, 0.9, 1.9, 1.3, 1.1];
  const colStarts = [0.15, 2.95, 3.85, 5.75, 7.05];
  const rowHeight = 0.48;
  const headerBg = COLORS.medBg;
  const altBg = COLORS.subtleGray;

  tableRows.forEach((row, ri) => {
    row.forEach((cell, ci) => {
      const bg = ri === 0 ? headerBg : ri % 2 === 0 ? altBg : COLORS.white;
      const textColor = ri === 0 ? COLORS.white : COLORS.textDark;
      slide.addShape(pres.shapes.RECTANGLE, {
        x: colStarts[ci], y: 1.06 + ri * rowHeight, w: colWidths[ci] - 0.05, h: rowHeight,
        fill: { color: bg },
      });
      slide.addText(cell, {
        x: colStarts[ci] + 0.05, y: 1.09 + ri * rowHeight, w: colWidths[ci] - 0.1, h: rowHeight - 0.06,
        fontSize: ri === 0 ? 12 : 11, bold: ri === 0, color: textColor, fontFace: "Arial",
        valign: "middle",
      });
    });
  });
}

// ─────────────────────────────────────────────
// SLIDE 17 – THANK YOU / QUESTIONS
// ─────────────────────────────────────────────
{
  const slide = pres.addSlide();
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 10, h: 5.625, fill: { color: COLORS.darkBg } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 4.5, w: 10, h: 0.14, fill: { color: COLORS.accent } });
  slide.addShape(pres.shapes.RECTANGLE, { x: 0, y: 4.64, w: 10, h: 0.07, fill: { color: COLORS.accent2 } });

  slide.addText("KEY TAKEAWAYS", {
    x: 0.5, y: 0.5, w: 9, h: 0.55, fontSize: 26, bold: true,
    color: COLORS.accent, align: "center", fontFace: "Arial",
  });

  const takeaways = [
    "ARM = spectrum of defects involving distal rectum, anus, urogenital tract",
    "Incidence: 1 in 5000 births; male predominance (58%)",
    "Krickenbeck (2005) is the current international classification standard",
    "Most common male defect = rectobulbar urethral fistula; female = rectovestibular fistula",
    "Cloaca = most complex female defect with single perineal opening",
    "Always screen for VACTERL anomalies",
    "Low defects → primary repair; High defects → staged (colostomy → PSARP → closure)",
    "PSARP (Posterior Sagittal AnorRectoPlasty) by Peña = gold standard surgery",
    "Long-term nursing focus: continence, colostomy care, family education, psychosocial support",
  ];

  slide.addText(takeaways.map((t, i) => ({
    text: "• " + t,
    options: { breakLine: i < takeaways.length - 1, paraSpaceBefore: 3 }
  })), {
    x: 0.5, y: 1.15, w: 9, h: 3.15, fontSize: 13.5, color: COLORS.white, fontFace: "Arial", lineSpacingMultiple: 1.3,
  });

  slide.addText("Questions Welcome  |  BSc Nursing – Paediatric Nursing", {
    x: 0.5, y: 4.7, w: 9, h: 0.4, fontSize: 13, italic: true, color: COLORS.accent2, align: "center", fontFace: "Arial",
  });
}

// ─────────────────────────────────────────────
// SAVE FILE
// ─────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/anorectal-malformation-ppt/Anorectal_Malformation_BSc_Nursing.pptx" })
  .then(() => console.log("PPT created successfully!"))
  .catch(err => console.error("Error:", err));
Running Command

cd /home/daytona/workspace/anorectal-malformation-ppt && node create_ppt.js

Running Command

node -e "const p = require('pptxgenjs'); const pres = new p(); console.log(Objec…

Running Command

sed -i 's/pres\.shapes\.ELLIPSE/pres.shapes.OVAL/g' /home/daytona/workspace/anor…

Editing File

~/anorectal-malformation-ppt/create_ppt.js

Error: String not found in file: '    slide.addShape(pres.shapes.ELLIPSE, { x: nx + 0.32, y: ny + 2.2, w: 0.31, h: 0.16, fill: { color: COLORS.accent } });'
Searching Content

"ELLIPSE" in ~/anorectal-malformation-ppt

Reading File
Editing File

~/anorectal-malformation-ppt/create_ppt.js

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/anorectal-malformation-ppt/create_ppt.js'
Editing File

~/anorectal-malformation-ppt/create_ppt.js

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

node /home/daytona/workspace/anorectal-malformation-ppt/create_ppt.js 2>&1

Model call limits exceeded: run limit (20/20)

Create a quick reference PDF handout from this presentation content

Reading File
Writing File

~/anorectal-malformation-ppt/create_handout.py

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

OUTPUT = "/home/daytona/workspace/anorectal-malformation-ppt/ARM_Quick_Reference_Handout.pdf"

# ── Colour palette ───────────────────────────────────────────
NAVY      = colors.HexColor("#0D2D4A")
MID_BLUE  = colors.HexColor("#134466")
LIGHT_BG  = colors.HexColor("#EAF4FB")
AMBER     = colors.HexColor("#E8A127")
TEAL      = colors.HexColor("#2BB5A0")
WHITE     = colors.white
RED       = colors.HexColor("#C0392B")
GREEN     = colors.HexColor("#1A7F5A")
PURPLE    = colors.HexColor("#7B3F9E")
SUBTLE    = colors.HexColor("#D6E8F5")
TXT_DARK  = colors.HexColor("#1A2B3C")
GREY_TEXT = colors.HexColor("#4A5568")

PAGE_W, PAGE_H = A4
MARGIN = 1.4 * cm

doc = SimpleDocTemplate(
    OUTPUT,
    pagesize=A4,
    leftMargin=MARGIN,
    rightMargin=MARGIN,
    topMargin=MARGIN,
    bottomMargin=1.8 * cm,
    title="Anorectal Malformation – Quick Reference Handout",
    author="BSc Nursing – Paediatric Nursing",
)

# ── Styles ───────────────────────────────────────────────────
styles = getSampleStyleSheet()

def S(name, **kw):
    return ParagraphStyle(name, **kw)

base = S("base", fontName="Helvetica", fontSize=9, leading=13, textColor=TXT_DARK)
bold_base = S("bold_base", fontName="Helvetica-Bold", fontSize=9, leading=13, textColor=TXT_DARK)
small = S("small", fontName="Helvetica", fontSize=8, leading=11, textColor=GREY_TEXT)
small_bold = S("small_bold", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=TXT_DARK)
white_bold = S("white_bold", fontName="Helvetica-Bold", fontSize=9, leading=12, textColor=WHITE)
white_sm = S("white_sm", fontName="Helvetica", fontSize=8, leading=11, textColor=WHITE)
center = S("center", fontName="Helvetica", fontSize=9, leading=13, textColor=TXT_DARK, alignment=TA_CENTER)
center_bold = S("center_bold", fontName="Helvetica-Bold", fontSize=9, leading=12, textColor=TXT_DARK, alignment=TA_CENTER)

def section_title(text, color=NAVY):
    return Table(
        [[Paragraph(f"<font color='white'><b>{text}</b></font>", center_bold)]],
        colWidths=[PAGE_W - 2 * MARGIN],
        style=TableStyle([
            ("BACKGROUND", (0,0), (-1,-1), color),
            ("TOPPADDING", (0,0), (-1,-1), 4),
            ("BOTTOMPADDING", (0,0), (-1,-1), 4),
            ("LEFTPADDING", (0,0), (-1,-1), 6),
        ])
    )

def subsection_bar(text, color=MID_BLUE):
    return Table(
        [[Paragraph(f"<font color='white'><b>{text}</b></font>",
                    S("_sb", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE))]],
        colWidths=[PAGE_W - 2 * MARGIN],
        style=TableStyle([
            ("BACKGROUND", (0,0), (-1,-1), color),
            ("TOPPADDING", (0,0), (-1,-1), 3),
            ("BOTTOMPADDING", (0,0), (-1,-1), 3),
            ("LEFTPADDING", (0,0), (-1,-1), 6),
        ])
    )

def bullet(text, indent=0.3):
    return Paragraph(f"<bullet>&bull;</bullet> {text}", S(
        "_b", fontName="Helvetica", fontSize=8.5, leading=12,
        textColor=TXT_DARK, leftIndent=indent*cm, bulletIndent=0,
    ))

def amber_bullet(text):
    return Paragraph(f"<bullet><font color='#E8A127'>&#9654;</font></bullet> {text}", S(
        "_ab", fontName="Helvetica", fontSize=8.5, leading=12,
        textColor=TXT_DARK, leftIndent=0.4*cm, bulletIndent=0,
    ))

def sp(h=0.18):
    return Spacer(1, h * cm)

def hr(color=AMBER, thickness=1.5):
    return HRFlowable(width="100%", thickness=thickness, color=color, spaceAfter=2, spaceBefore=2)

CONTENT_W = PAGE_W - 2 * MARGIN

# ── Page header / footer callbacks ───────────────────────────
def on_page(canvas, doc):
    canvas.saveState()
    # Top stripe
    canvas.setFillColor(NAVY)
    canvas.rect(0, PAGE_H - 1.0*cm, PAGE_W, 1.0*cm, fill=1, stroke=0)
    canvas.setFillColor(AMBER)
    canvas.rect(0, PAGE_H - 1.05*cm, PAGE_W, 0.05*cm, fill=1, stroke=0)
    canvas.setFillColor(WHITE)
    canvas.setFont("Helvetica-Bold", 9)
    canvas.drawString(MARGIN, PAGE_H - 0.65*cm, "ANORECTAL MALFORMATION – Quick Reference Handout")
    canvas.setFont("Helvetica", 8)
    canvas.drawRightString(PAGE_W - MARGIN, PAGE_H - 0.65*cm, "BSc Nursing | Paediatric Nursing")
    # Bottom stripe
    canvas.setFillColor(NAVY)
    canvas.rect(0, 0, PAGE_W, 1.0*cm, fill=1, stroke=0)
    canvas.setFillColor(WHITE)
    canvas.setFont("Helvetica", 7.5)
    canvas.drawString(MARGIN, 0.35*cm, "Sources: Sabiston Textbook of Surgery • Campbell-Walsh Wein Urology • Krickenbeck International Classification (2005)")
    canvas.drawRightString(PAGE_W - MARGIN, 0.35*cm, f"Page {doc.page}")
    canvas.restoreState()

# ═══════════════════════════════════════════════════════════════
# BUILD CONTENT
# ═══════════════════════════════════════════════════════════════
story = []

# ── TITLE BLOCK ──────────────────────────────────────────────
title_data = [[
    Paragraph("<font color='white'><b>ANORECTAL MALFORMATION (ARM)</b></font>",
              S("_tt", fontName="Helvetica-Bold", fontSize=18, leading=22, textColor=WHITE, alignment=TA_CENTER)),
    Paragraph("<font color='white'>Quick Reference Handout</font><br/>"
              "<font color='#E8A127'>BSc Nursing – Paediatric Nursing</font>",
              S("_ts", fontName="Helvetica", fontSize=10, leading=14, textColor=WHITE, alignment=TA_RIGHT)),
]]
title_tbl = Table(title_data, colWidths=[CONTENT_W*0.62, CONTENT_W*0.38],
    style=TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), NAVY),
        ("VALIGN", (0,0), (-1,-1), "MIDDLE"),
        ("TOPPADDING", (0,0), (-1,-1), 8),
        ("BOTTOMPADDING", (0,0), (-1,-1), 8),
        ("LEFTPADDING", (0,0), (0,0), 10),
        ("RIGHTPADDING", (-1,-1), (-1,-1), 10),
    ])
)
story.append(title_tbl)
story.append(sp(0.1))

# Amber + teal bar
bar_data = [[
    Paragraph("<font color='white'><b>Incidence:</b> 1 in 5000 live births</font>", white_sm),
    Paragraph("<font color='white'><b>Male predominance:</b> 58%</font>", white_sm),
    Paragraph("<font color='white'><b>Low defects:</b> ~60% of cases</font>", white_sm),
    Paragraph("<font color='white'><b>Most common ♂:</b> Rectobulbar fistula</font>", white_sm),
    Paragraph("<font color='white'><b>Most common ♀:</b> Rectovestibular fistula</font>", white_sm),
]]
bar_tbl = Table(bar_data, colWidths=[CONTENT_W/5]*5,
    style=TableStyle([
        ("BACKGROUND", (0,0), (2,0), TEAL),
        ("BACKGROUND", (3,0), (4,0), MID_BLUE),
        ("TOPPADDING", (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING", (0,0), (-1,-1), 5),
        ("GRID", (0,0), (-1,-1), 0.5, WHITE),
    ])
)
story.append(bar_tbl)
story.append(sp(0.2))

# ── TWO COLUMN LAYOUT helper ──────────────────────────────────
def two_col(left_items, right_items, left_ratio=0.48):
    cw = [CONTENT_W * left_ratio, CONTENT_W * (1 - left_ratio - 0.02)]
    data = [[left_items, right_items]]
    t = Table(data, colWidths=[cw[0], cw[1]],
        style=TableStyle([
            ("VALIGN", (0,0), (-1,-1), "TOP"),
            ("LEFTPADDING", (0,0), (-1,-1), 0),
            ("RIGHTPADDING", (0,0), (-1,-1), 0),
            ("TOPPADDING", (0,0), (-1,-1), 0),
            ("BOTTOMPADDING", (0,0), (-1,-1), 0),
        ])
    )
    return t


# ── SECTION 1: DEFINITION & EMBRYOLOGY / ETIOLOGY ───────────
story.append(section_title("1.  DEFINITION, EMBRYOLOGY & ETIOLOGY"))
story.append(sp(0.1))

left_def = [
    subsection_bar("Definition", NAVY),
    sp(0.1),
    Paragraph(
        "A <b>spectrum of congenital defects</b> involving the distal anus, rectum and "
        "urogenital tract resulting in an abnormal or absent anal opening.",
        S("_def", fontName="Helvetica", fontSize=8.5, leading=13, textColor=TXT_DARK)
    ),
    sp(0.15),
    subsection_bar("Embryological Basis", MID_BLUE),
    sp(0.06),
    bullet("Week 4–6: Urorectal septum divides cloaca into anterior urogenital sinus + posterior anorectal canal"),
    bullet("Week 8: Anal membrane normally resorbs → anal opening forms"),
    bullet("Septum failure → fistula between bowel and urinary/genital tract"),
    bullet("Membrane resorption failure → anal stenosis or imperforate anus"),
    bullet("Abnormal cloacal fold fusion → anteriorly displaced anus"),
]

right_etio = [
    subsection_bar("Etiology & Risk Factors", MID_BLUE),
    sp(0.06),
    bullet("Multifactorial – genetic + environmental"),
    bullet("Paternal smoking"),
    bullet("Maternal obesity"),
    bullet("Maternal pregestational / gestational diabetes"),
    bullet("Trisomy 21 – especially rectal atresia"),
    sp(0.1),
    subsection_bar("Associated Syndromes", NAVY),
    sp(0.06),
    Paragraph("<b>VACTERL</b> – Vertebral, Anal, Cardiac, Tracheo-Esophageal, Renal, Limb", small),
    Paragraph("<b>OEIS</b> – Omphalocele, Exstrophy, Imperforate anus, Spinal defects", small),
    Paragraph("<b>MURCS</b> – Müllerian aplasia, Renal aplasia, Cervicothoracic somite dysplasia", small),
    Paragraph("<b>Currarino</b> – ARM + Sacrococcygeal defect + Presacral mass", small),
]

story.append(two_col(left_def, right_def := right_etio))
story.append(sp(0.25))


# ── SECTION 2: CLASSIFICATION ────────────────────────────────
story.append(section_title("2.  CLASSIFICATION OF ANORECTAL MALFORMATIONS"))
story.append(sp(0.12))

# 2a – Wingspread
story.append(subsection_bar("A.  WINGSPREAD CLASSIFICATION (1984) – Historical | Based on level relative to levator ani", MID_BLUE))
story.append(sp(0.08))

ws_data = [
    [
        Paragraph("<b>LOW DEFECT</b>\n(Pouch BELOW levator ani)", S("_wh", fontName="Helvetica-Bold", fontSize=8.5, leading=12, textColor=WHITE, alignment=TA_CENTER)),
        Paragraph("<b>INTERMEDIATE DEFECT</b>\n(Pouch AT level of levator ani)", S("_wh2", fontName="Helvetica-Bold", fontSize=8.5, leading=12, textColor=TXT_DARK, alignment=TA_CENTER)),
        Paragraph("<b>HIGH DEFECT</b>\n(Pouch ABOVE levator ani)", S("_wh3", fontName="Helvetica-Bold", fontSize=8.5, leading=12, textColor=WHITE, alignment=TA_CENTER)),
    ],
    [
        Paragraph("<b>♂ Male:</b> Perineal fistula, Anal stenosis, Anterior perineal anus<br/>"
                  "<b>♀ Female:</b> Perineal fistula, Anal stenosis, Anterior perineal anus<br/>"
                  "<b>Prognosis:</b> <font color='#1A7F5A'>Excellent</font>", small),
        Paragraph("<b>♂ Male:</b> Anal agenesis without fistula, Rectobulbar fistula<br/>"
                  "<b>♀ Female:</b> Anal agenesis without fistula, Rectovestibular fistula, Rectovaginal fistula (low)<br/>"
                  "<b>Prognosis:</b> <font color='#E8A127'>Good–Moderate</font>", small),
        Paragraph("<b>♂ Male:</b> Anorectal agenesis, Rectoprostatic urethral fistula, Rectovesical fistula<br/>"
                  "<b>♀ Female:</b> Anorectal agenesis, Rectovaginal fistula (high), Rectal atresia<br/>"
                  "<b>Prognosis:</b> <font color='#C0392B'>Poor</font>", small),
    ],
]
ws_tbl = Table(ws_data, colWidths=[CONTENT_W/3]*3,
    style=TableStyle([
        ("BACKGROUND", (0,0), (0,0), GREEN),
        ("BACKGROUND", (1,0), (1,0), AMBER),
        ("BACKGROUND", (2,0), (2,0), RED),
        ("BACKGROUND", (0,1), (0,1), colors.HexColor("#E8F5EE")),
        ("BACKGROUND", (1,1), (1,1), colors.HexColor("#FFF8EC")),
        ("BACKGROUND", (2,1), (2,1), colors.HexColor("#FDECEA")),
        ("GRID", (0,0), (-1,-1), 0.5, colors.HexColor("#CCDDEE")),
        ("TOPPADDING", (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING", (0,0), (-1,-1), 6),
        ("VALIGN", (0,0), (-1,-1), "TOP"),
    ])
)
story.append(ws_tbl)
story.append(sp(0.2))

# 2b – Krickenbeck
story.append(subsection_bar("B.  KRICKENBECK INTERNATIONAL CLASSIFICATION (2005) – CURRENT STANDARD", NAVY))
story.append(sp(0.08))

krick_header = [
    Paragraph("<b>MAJOR CLINICAL GROUPS</b>", S("_kh", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
    Paragraph("", white_sm),
    Paragraph("<b>RARE / REGIONAL VARIANTS</b>", S("_kh2", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
]
krick_data = [
    [
        Paragraph("<b>♂ Male</b>", S("_km", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
        Paragraph("<b>♀ Female</b>", S("_kf", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
        Paragraph("<b>Both Sexes</b>", S("_kv", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
    ],
    [
        Paragraph("• Rectoperineal (cutaneous) fistula<br/>"
                  "• Rectourethral fistula – <b>Bulbar</b><br/>"
                  "• Rectourethral fistula – <b>Prostatic</b><br/>"
                  "• <b>Recto-bladder neck</b> fistula<br/>"
                  "• Imperforate anus without fistula", small),
        Paragraph("• Rectoperineal (cutaneous) fistula<br/>"
                  "• <b>Rectovestibular</b> fistula<br/>"
                  "• Imperforate anus without fistula<br/>"
                  "• <b>Cloaca</b> (common channel)", small),
        Paragraph("• Pouch colon<br/>"
                  "• Rectal atresia / stenosis<br/>"
                  "• Rectovaginal fistula<br/>"
                  "• H-type fistula<br/>"
                  "• Others", small),
    ],
]
cw3 = CONTENT_W / 3
krick_tbl = Table(
    [[Paragraph("<b>Major Clinical Groups</b>", S("_kk", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
      Paragraph("", white_sm),
      Paragraph("<b>Rare / Regional Variants</b>", S("_kk2", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER))]] +
    [[Paragraph("<b>♂ Male</b>", S("_km2", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
      Paragraph("<b>♀ Female</b>", S("_kf2", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
      Paragraph("<b>Both Sexes</b>", S("_kv2", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER))]] +
    [[
        Paragraph("• Rectoperineal (cutaneous) fistula<br/>"
                  "• Rectourethral fistula – <b>Bulbar</b><br/>"
                  "• Rectourethral fistula – <b>Prostatic</b><br/>"
                  "• <b>Recto-bladder neck</b> fistula<br/>"
                  "• Imperforate anus without fistula", small),
        Paragraph("• Rectoperineal (cutaneous) fistula<br/>"
                  "• <b>Rectovestibular</b> fistula<br/>"
                  "• Imperforate anus without fistula<br/>"
                  "• <b>Cloaca</b> (common channel)", small),
        Paragraph("• Pouch colon<br/>"
                  "• Rectal atresia / stenosis<br/>"
                  "• Rectovaginal fistula<br/>"
                  "• H-type fistula<br/>"
                  "• Others", small),
    ]],
    colWidths=[cw3, cw3, cw3],
    style=TableStyle([
        ("BACKGROUND", (0,0), (1,0), TEAL),
        ("BACKGROUND", (2,0), (2,0), MID_BLUE),
        ("BACKGROUND", (0,1), (1,1), MID_BLUE),
        ("BACKGROUND", (2,1), (2,1), NAVY),
        ("BACKGROUND", (0,2), (1,2), LIGHT_BG),
        ("BACKGROUND", (2,2), (2,2), SUBTLE),
        ("GRID", (0,0), (-1,-1), 0.5, colors.HexColor("#CCDDEE")),
        ("SPAN", (0,0), (1,0)),
        ("TOPPADDING", (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING", (0,0), (-1,-1), 5),
        ("VALIGN", (0,0), (-1,-1), "TOP"),
    ])
)
story.append(krick_tbl)
story.append(sp(0.2))


# ── SECTION 3: DETAILED TYPE TABLE ───────────────────────────
story.append(section_title("3.  TYPES AT A GLANCE – PEÑA ANATOMIC CLASSIFICATION"))
story.append(sp(0.1))

type_headers = ["Type / Defect", "Sex", "Fistula Site", "Clinical Clue", "Colostomy?", "Prognosis"]
type_rows = [
    ["Rectoperineal fistula", "Both", "Perineal skin", "Meconium on perineum", "No", "Excellent"],
    ["Rectovestibular fistula", "♀", "Vaginal vestibule (introitus)", "2 perineal openings in ♀", "Usually No", "Good"],
    ["Rectobulbar urethral fistula", "♂", "Bulbar urethra", "Meconium in urine (most common ♂)", "Yes", "Good"],
    ["Rectoprostatic urethral fistula", "♂", "Prostatic urethra", "Gas/meconium in urine", "Yes", "Moderate"],
    ["Recto-bladder neck fistula", "♂", "Bladder neck", "High defect; 90% urinary anomaly", "Yes", "Poor"],
    ["Imperforate anus – no fistula", "Both", "None", "Associated with Trisomy 21 (Down)", "Yes", "Good"],
    ["Cloaca", "♀", "Single common channel", "Only 1 perineal opening in ♀", "Yes", "Variable/Poor"],
    ["Rectal atresia / stenosis", "Both", "None", "Lumen interrupted; assoc. Trisomy 21", "Yes", "Moderate"],
]

prognosis_colors = {
    "Excellent": colors.HexColor("#D4EDDA"),
    "Good": colors.HexColor("#D1ECF1"),
    "Moderate": colors.HexColor("#FFF3CD"),
    "Poor": colors.HexColor("#F8D7DA"),
    "Variable/Poor": colors.HexColor("#F8D7DA"),
}

table_data = [
    [Paragraph(f"<b>{h}</b>", S("_th", fontName="Helvetica-Bold", fontSize=8, leading=10, textColor=WHITE, alignment=TA_CENTER))
     for h in type_headers]
] + [
    [Paragraph(cell, S("_td", fontName="Helvetica", fontSize=8, leading=10, textColor=TXT_DARK))
     for cell in row]
    for row in type_rows
]

col_widths = [3.8*cm, 1.0*cm, 3.5*cm, 5.0*cm, 2.0*cm, 2.2*cm]

ts = TableStyle([
    ("BACKGROUND", (0,0), (-1,0), NAVY),
    ("GRID", (0,0), (-1,-1), 0.4, colors.HexColor("#CCDDEE")),
    ("TOPPADDING", (0,0), (-1,-1), 3),
    ("BOTTOMPADDING", (0,0), (-1,-1), 3),
    ("LEFTPADDING", (0,0), (-1,-1), 4),
    ("VALIGN", (0,0), (-1,-1), "TOP"),
    ("ROWBACKGROUNDS", (0,1), (-1,-1), [WHITE, SUBTLE]),
])
# Colour prognosis column cells
for i, row in enumerate(type_rows, start=1):
    prog = row[5]
    bg = prognosis_colors.get(prog, WHITE)
    ts.add("BACKGROUND", (5, i), (5, i), bg)

type_tbl = Table(table_data, colWidths=col_widths, style=ts, repeatRows=1)
story.append(type_tbl)
story.append(sp(0.22))


# ── SECTION 4: CLINICAL FEATURES & DIAGNOSIS ─────────────────
story.append(section_title("4.  CLINICAL FEATURES & DIAGNOSTIC WORKUP"))
story.append(sp(0.1))

cf_left = [
    subsection_bar("Clinical Features (Neonate)", MID_BLUE),
    sp(0.06),
    bullet("Absent or abnormal anal opening at birth"),
    bullet("No meconium passage within 24–48 hours"),
    bullet("Meconium in urine → rectourinary fistula"),
    bullet("Abdominal distension (bowel obstruction)"),
    bullet("Bilious vomiting"),
    bullet("Meconium visible on perineum (low fistula)"),
    bullet("Single perineal opening in female → cloaca"),
    bullet("Flat perineum / absent gluteal crease (high defect)"),
]

cf_right = [
    subsection_bar("Diagnostic Workup", NAVY),
    sp(0.06),
    Paragraph("<b>Perineal inspection</b> – number of openings, fistula site", small),
    Paragraph("<b>Invertogram / Cross-table lateral X-ray</b> – level of rectal pouch (gas)", small),
    Paragraph("<b>Distal colostogram</b> – gold standard for fistula delineation", small),
    Paragraph("<b>Renal ultrasound</b> – VUR, hydronephrosis, renal agenesis", small),
    Paragraph("<b>VCUG</b> (Voiding cystourethrogram) – fistula, urinary tract", small),
    Paragraph("<b>Spinal MRI</b> – tethered cord, sacral agenesis (30–44%)", small),
    Paragraph("<b>Echocardiogram</b> – cardiac defects (VACTERL)", small),
    Paragraph("<b>OGT tube</b> – rule out esophageal atresia", small),
    Paragraph("<b>Sacral ratio</b> – poor sacral development → poor continence prognosis", small),
]

story.append(two_col(cf_left, cf_right))
story.append(sp(0.22))


# ── SECTION 5: MANAGEMENT ────────────────────────────────────
story.append(section_title("5.  SURGICAL MANAGEMENT"))
story.append(sp(0.1))

mgmt_data = [
    [
        Paragraph("<b>LOW DEFECTS</b>", S("_ml", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
        Paragraph("<b>HIGH / INTERMEDIATE DEFECTS</b>", S("_mh", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=TXT_DARK, alignment=TA_CENTER)),
        Paragraph("<b>CLOACA (Female)</b>", S("_mc", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
    ],
    [
        Paragraph("• Primary single-stage repair<br/>"
                  "• PSARP or cutback anoplasty<br/>"
                  "• <b>No colostomy</b> required<br/>"
                  "• Perineal &amp; vestibular fistula<br/>"
                  "• Serial dilatation for stenosis", small),
        Paragraph("<b>Staged repair:</b><br/>"
                  "1. Divided sigmoid loop colostomy (day 1–2)<br/>"
                  "2. Distal colostogram (1–3 months)<br/>"
                  "3. PSARP – definitive repair<br/>"
                  "4. Colostomy closure (4–8 wks post PSARP)", small),
        Paragraph("• Colostomy + vaginal drainage at birth<br/>"
                  "• <b>Short channel (&lt;3cm):</b> Total urogenital mobilization (TUM)<br/>"
                  "• <b>Long channel (&gt;3cm):</b> Separate bowel, vaginal and urethral reconstruction<br/>"
                  "• Most complex; 90% urinary anomaly", small),
    ],
]
mgmt_tbl = Table(mgmt_data, colWidths=[CONTENT_W/3]*3,
    style=TableStyle([
        ("BACKGROUND", (0,0), (0,0), GREEN),
        ("BACKGROUND", (1,0), (1,0), AMBER),
        ("BACKGROUND", (2,0), (2,0), RED),
        ("BACKGROUND", (0,1), (0,1), colors.HexColor("#E8F5EE")),
        ("BACKGROUND", (1,1), (1,1), colors.HexColor("#FFF8EC")),
        ("BACKGROUND", (2,1), (2,1), colors.HexColor("#FDECEA")),
        ("GRID", (0,0), (-1,-1), 0.5, colors.HexColor("#CCDDEE")),
        ("TOPPADDING", (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING", (0,0), (-1,-1), 6),
        ("VALIGN", (0,0), (-1,-1), "TOP"),
    ])
)
story.append(mgmt_tbl)

story.append(sp(0.1))
psarp_note = Table(
    [[Paragraph("<b>PSARP</b> (Posterior Sagittal AnorRectoPlasty) by Peña = <b>Gold Standard</b> surgical technique. "
                "It minimises injury to pelvic nerves innervating the pelvic floor and does not cause iatrogenic neurogenic bladder.",
                S("_pn", fontName="Helvetica", fontSize=8, leading=11, textColor=WHITE))]],
    colWidths=[CONTENT_W],
    style=TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), NAVY),
        ("TOPPADDING", (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING", (0,0), (-1,-1), 8),
    ])
)
story.append(psarp_note)
story.append(sp(0.22))


# ── SECTION 6: NURSING CARE ───────────────────────────────────
story.append(section_title("6.  NURSING CARE", color=TEAL))
story.append(sp(0.1))

nsg_data = [
    [
        Paragraph("<b>Neonatal Assessment</b>",
                  S("_nh", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
        Paragraph("<b>Colostomy Care</b>",
                  S("_nh2", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
        Paragraph("<b>Post-PSARP Care</b>",
                  S("_nh3", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
        Paragraph("<b>Long-term Follow-up</b>",
                  S("_nh4", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
    ],
    [
        Paragraph("• Inspect perineum at birth<br/>"
                  "• Count perineal openings<br/>"
                  "• Check for meconium in urine<br/>"
                  "• Assess abdominal distension<br/>"
                  "• Screen for VACTERL anomalies<br/>"
                  "• OGT tube – exclude EA", small),
        Paragraph("• Monitor stoma colour, size, output<br/>"
                  "• Peristomal skin protection<br/>"
                  "• Empty and measure output<br/>"
                  "• Teach parents bag change<br/>"
                  "• Watch for prolapse, retraction, stenosis<br/>"
                  "• Record fluid balance", small),
        Paragraph("• Keep wound clean and dry<br/>"
                  "• Prone/lateral position<br/>"
                  "• Monitor wound dehiscence/infection<br/>"
                  "• Anal dilatation programme<br/>"
                  "• Adequate pain management<br/>"
                  "• Nutritional support (NG/TPN)", small),
        Paragraph("• Fecal continence monitoring<br/>"
                  "• Constipation management<br/>"
                  "• Urinary continence (neurogenic bladder)<br/>"
                  "• Growth &amp; developmental milestones<br/>"
                  "• Psychosocial support<br/>"
                  "• Family education and counselling", small),
    ],
]
nsg_tbl = Table(nsg_data, colWidths=[CONTENT_W/4]*4,
    style=TableStyle([
        ("BACKGROUND", (0,0), (0,0), NAVY),
        ("BACKGROUND", (1,0), (1,0), MID_BLUE),
        ("BACKGROUND", (2,0), (2,0), TEAL),
        ("BACKGROUND", (3,0), (3,0), colors.HexColor("#1A5276")),
        ("BACKGROUND", (0,1), (-1,-1), LIGHT_BG),
        ("GRID", (0,0), (-1,-1), 0.5, colors.HexColor("#CCDDEE")),
        ("TOPPADDING", (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING", (0,0), (-1,-1), 5),
        ("VALIGN", (0,0), (-1,-1), "TOP"),
    ])
)
story.append(nsg_tbl)
story.append(sp(0.22))


# ── SECTION 7: KEY TAKEAWAYS ─────────────────────────────────
story.append(section_title("7.  KEY TAKEAWAYS", color=NAVY))
story.append(sp(0.1))

takeaways = [
    ("ARM", "= spectrum of defects involving distal rectum, anus, and urogenital tract"),
    ("Incidence", "1 in 5000 live births; male predominance (58%)"),
    ("Classification", "Krickenbeck (2005) is the current international standard – classifies by fistula site"),
    ("Most common ♂", "Rectobulbar urethral fistula (~50% of male cases)"),
    ("Most common ♀", "Rectovestibular fistula (~50% of female cases)"),
    ("Cloaca", "Most complex female defect – single perineal opening (rectum + vagina + urethra → 1 channel)"),
    ("VACTERL", "Always screen all ARM patients for vertebral, cardiac, TE, renal, and limb anomalies"),
    ("Low defects", "→ Primary single-stage repair; no colostomy"),
    ("High defects", "→ Staged: colostomy → PSARP → colostomy closure"),
    ("PSARP", "Posterior Sagittal AnorRectoPlasty by Peña = gold standard surgery"),
    ("Nursing priority", "Post-op wound care, colostomy care, anal dilatation programme, long-term continence support"),
]

tak_data = [[
    Paragraph(f"<b>{t[0]}</b>",
              S("_tk", fontName="Helvetica-Bold", fontSize=8.5, leading=11, textColor=WHITE, alignment=TA_CENTER)),
    Paragraph(t[1], S("_tv", fontName="Helvetica", fontSize=8.5, leading=11, textColor=TXT_DARK)),
] for t in takeaways]

tak_tbl = Table(tak_data, colWidths=[3.0*cm, CONTENT_W - 3.0*cm],
    style=TableStyle([
        ("ROWBACKGROUNDS", (0,0), (0,-1), [NAVY, MID_BLUE]),
        ("ROWBACKGROUNDS", (1,0), (1,-1), [WHITE, SUBTLE]),
        ("GRID", (0,0), (-1,-1), 0.4, colors.HexColor("#CCDDEE")),
        ("TOPPADDING", (0,0), (-1,-1), 3),
        ("BOTTOMPADDING", (0,0), (-1,-1), 3),
        ("LEFTPADDING", (0,0), (-1,-1), 5),
        ("VALIGN", (0,0), (-1,-1), "MIDDLE"),
    ])
)
story.append(tak_tbl)
story.append(sp(0.15))

# Footer note
story.append(Table(
    [[Paragraph(
        "<b>Note:</b> Higher the ARM defect → greater frequency of associated urologic anomalies. "
        "Recto-bladder neck fistula and persistent cloaca → ~90% urinary tract anomaly. "
        "Perineal fistula → only ~10% urinary anomaly.",
        S("_fn", fontName="Helvetica-Oblique", fontSize=7.5, leading=10, textColor=WHITE)
    )]],
    colWidths=[CONTENT_W],
    style=TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), MID_BLUE),
        ("TOPPADDING", (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING", (0,0), (-1,-1), 8),
    ])
))

# ── BUILD ─────────────────────────────────────────────────────
doc.build(story, onFirstPage=on_page, onLaterPages=on_page)
print(f"PDF created: {OUTPUT}")
Running Command

cd /home/daytona/workspace/anorectal-malformation-ppt && python3 create_handout.…

Running Command

ls -lh /home/daytona/workspace/anorectal-malformation-ppt/ARM_Quick_Reference_Ha…

Your quick reference PDF handout is ready:

ARM Quick Reference Handout

PDF Document · PDF

Here's what's packed into the handout (A4, colour-coded, print-ready):

What's inside (7 sections):
  1. Title block + stats bar - incidence, sex ratio, most common types at a glance across the top
  2. Definition, Embryology & Etiology - two-column layout with embryological steps + risk factors and associated syndromes (VACTERL, OEIS, MURCS, Currarino)
  3. Classification - all 3 systems
    • Wingspread (Low / Intermediate / High) - colour-coded green/amber/red
    • Krickenbeck International 2005 - current standard, male vs female vs rare variants
  4. Types at a Glance table - all 8 ARM types with sex, fistula site, key clinical clue, colostomy need, and prognosis (prognosis cells colour-coded)
  5. Clinical Features & Diagnostic Workup - two columns; all 8 investigations listed
  6. Surgical Management - three-column table: Low / High-Intermediate / Cloaca with staged repair steps + PSARP note
  7. Nursing Care - four columns: Neonatal assessment / Colostomy care / Post-PSARP care / Long-term follow-up
  8. Key Takeaways - 11-row reference strip with label + explanation
The handout also has a running header (title + subject) and a footer with source citations (Sabiston, Campbell-Walsh, Krickenbeck 2005) and page numbers on every page.

invisble and visible opening classification

Finding Sources
Searching the Web

anorectal malformation "visible" "invisible" fistula classification perineum imperforate anus nursing

Finding Sources
Searching the Web

anorectal malformation classification "no visible fistula" "visible fistula" ARM Pena nursing pediatric

Reading Web Page

https://www.ncbi.nlm.nih.gov/books/NBK542275

Finding Sources
Reading Web Page

https://www.ncbi.nlm.nih.gov/books/NBK542275

Searching the Web

anorectal malformation "visible fistula" "no visible" classification algorithm decision colostomy Pena 2016

The SlideShare result confirms this is a nursing/paediatric surgery teaching classification that groups ARM into 3 categories based on whether the abnormal opening is visible, invisible, or absent on perineal inspection. I have everything I need to give a complete, accurate answer.

Visible vs. Invisible Opening Classification of ARM

This is a clinical / bedside classification used in nursing and paediatric surgery teaching to decide the immediate management of a newborn with ARM, based purely on what you see on perineal inspection in the first 24 hours of life.

The Three Groups

GroupWhat you see on perineumFistula present?Examples
1. Visible abnormal openingAn opening is clearly seen, but NOT in the normal anal positionYes – external/perineal fistulaPerineal (cutaneous) fistula, Rectovestibular fistula (♀)
2. Invisible / No visible openingNo opening seen on perineum at allFistula may be internal (to urinary or genital tract) or absentRectourethral fistula ♂, Rectobladder-neck fistula ♂, Cloaca ♀, Imperforate anus without fistula
3. Covered / MembranousAnus appears present but is covered by a thin membraneNo true fistulaAnal membrane / anal stenosis

Group 1 – VISIBLE Abnormal Opening

The rectal fistula opens externally on the perineum or genitalia - you can see it on inspection.
  • Rectoperineal (cutaneous) fistula - Both sexes - meconium ribbon on the perineal skin, anterior to the sphincter
  • Rectovestibular fistula (♀ only) - Fistula opens at the vaginal vestibule (introitus) - 2 openings visible in a female: urethral/vaginal + fistula
  • Bucket-handle deformity - A skin bridge over a subcutaneous fistula track - meconium expressed on pressure
Clinical significance:
  • Fistula is low (translevator)
  • No colostomy needed in many cases
  • Primary repair possible in neonatal period (PSARP or cutback anoplasty)
  • Best prognosis for continence

Group 2 – INVISIBLE / No Visible Opening

No external fistula is seen on perineum. The fistula is internal (communicates with the urinary or genital tract) or entirely absent.
In males:
  • Rectobulbar urethral fistula - meconium in urine (but nothing seen on perineum)
  • Rectoprostatic urethral fistula - same
  • Recto-bladder neck fistula - same; highest male defect
  • Imperforate anus without fistula - no opening anywhere
In females:
  • Cloaca - only 1 perineal opening (single common channel for rectum + vagina + urethra)
  • Imperforate anus without fistula
Clinical significance:
  • Fistula is high (supralevator) or internal
  • Colostomy required - staged repair
  • Worse prognosis for continence
  • Requires imaging: invertogram / cross-table lateral X-ray, then distal colostogram
  • Watch for meconium in urine (pathognomonic of rectourinary fistula)
  • If no perineal fistula appears by 24 hours - proceed to imaging

Group 3 – Covered Anus / Anal Membrane

A dimple or covered membrane is present where the anus should be.
  • Anal stenosis - opening is in the correct position but abnormally narrow
  • Anal membrane - thin tissue covers a normal underlying anal canal
Clinical significance:
  • Lowest / most minor defect
  • Treatment: serial Hegar dilations or simple membranectomy
  • Excellent prognosis

Decision Algorithm Based on Visible/Invisible Classification

NEWBORN WITH SUSPECTED ARM
         │
         ▼
Inspect perineum carefully
         │
    ┌────┴────┐
    │         │
Visible     No visible
opening     opening
    │         │
    ▼         ▼
Low defect  Wait 24h (air rises to pouch)
(perineal/  ─────────────────────────────
vestibular) MALE → Invertogram / prone lateral X-ray
    │        → Distal colostogram to define fistula
    ▼        → Colostomy + staged PSARP
Primary
repair     FEMALE → Count openings
(no        → 1 opening only = CLOACA
colostomy  → 2 openings = urogenital sinus / no rectal fistula
in most)   → 3 openings = rectovestibular fistula (move to visible group)
           → Colostomy + staged repair

Why This Classification Matters for Nursing

Nursing ActionVisible GroupInvisible Group
Perineal inspectionIdentifies opening siteFlat perineum, absent gluteal fold
Meconium in nappyPresent early (perineal fistula)May be absent - check urine
Colostomy careUsually not needed initiallyLikely needed - prepare parents
FeedingMay be delayed brieflyNPO, IV fluids, NG tube
UrgencyLess acuteMore urgent - bowel obstruction risk
InvestigationsMinimalFull VACTERL workup, invertogram, renal USS

Summary

The visible vs. invisible classification is essentially a bedside triage tool - if the fistula is visible (external/perineal), it is almost always a low defect with good prognosis and primary repair potential. If no opening is visible, suspect an internal (high) fistula or no fistula at all, requiring staged management with colostomy. This directly guides the nurse's first 24-hour assessment and family counselling.

females and males ka classication separate krke diagrams add krdo

Writing File

.../anorectal-malformation-ppt/create_classification_diagrams.py

"""
ARM Classification PDF – Male & Female Separate with Anatomical Diagrams
Uses ReportLab + canvas drawing for inline anatomical diagrams
"""

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.units import cm, mm
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Table, TableStyle,
    Spacer, HRFlowable, KeepTogether, PageBreak
)
from reportlab.lib.enums import TA_CENTER, TA_LEFT
from reportlab.platypus import Flowable
from reportlab.graphics.shapes import (
    Drawing, Rect, Ellipse, Circle, Line, String, Polygon,
    PolyLine, Path, Group
)
from reportlab.graphics import renderPDF
import math

OUTPUT = "/home/daytona/workspace/anorectal-malformation-ppt/ARM_Male_Female_Classification.pdf"

# ── Colours ─────────────────────────────────────────────────
NAVY      = colors.HexColor("#0D2D4A")
MID_BLUE  = colors.HexColor("#134466")
LIGHT_BG  = colors.HexColor("#EAF4FB")
AMBER     = colors.HexColor("#E8A127")
TEAL      = colors.HexColor("#2BB5A0")
WHITE     = colors.white
RED       = colors.HexColor("#C0392B")
GREEN     = colors.HexColor("#1A7F5A")
PURPLE    = colors.HexColor("#7B3F9E")
SUBTLE    = colors.HexColor("#D6E8F5")
TXT_DARK  = colors.HexColor("#1A2B3C")
GREY      = colors.HexColor("#4A5568")
PINK      = colors.HexColor("#D63384")
BLUE_UR   = colors.HexColor("#2980B9")
FLESH     = colors.HexColor("#F4A460")
BONE      = colors.HexColor("#C4A882")
RECTUM_C  = colors.HexColor("#B03A2E")
SPHINCTER = colors.HexColor("#2BB5A0")
FISTULA_C = colors.HexColor("#F39C12")
SKIN_C    = colors.HexColor("#FDEBD0")
MUSCLE_C  = colors.HexColor("#1A7F5A")

PAGE_W, PAGE_H = A4
MARGIN = 1.3 * cm

# ── Styles ───────────────────────────────────────────────────
def S(name, **kw):
    return ParagraphStyle(name, **kw)

base  = S("base",  fontName="Helvetica",      fontSize=9,  leading=13, textColor=TXT_DARK)
sm    = S("sm",    fontName="Helvetica",      fontSize=8,  leading=11, textColor=TXT_DARK)
sm_b  = S("sm_b",  fontName="Helvetica-Bold", fontSize=8,  leading=11, textColor=TXT_DARK)
wh_b  = S("wh_b",  fontName="Helvetica-Bold", fontSize=9,  leading=12, textColor=WHITE, alignment=TA_CENTER)
wh_sm = S("wh_sm", fontName="Helvetica",      fontSize=7.5,leading=10, textColor=WHITE, alignment=TA_CENTER)
cen   = S("cen",   fontName="Helvetica",      fontSize=8,  leading=11, textColor=TXT_DARK, alignment=TA_CENTER)
cen_b = S("cen_b", fontName="Helvetica-Bold", fontSize=8,  leading=11, textColor=TXT_DARK, alignment=TA_CENTER)

CONTENT_W = PAGE_W - 2 * MARGIN

def sp(h=0.2): return Spacer(1, h * cm)

def sec_hdr(txt, color=NAVY):
    return Table([[Paragraph(f"<font color='white'><b>{txt}</b></font>", wh_b)]],
        colWidths=[CONTENT_W],
        style=TableStyle([("BACKGROUND",(0,0),(-1,-1),color),
                          ("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5),
                          ("LEFTPADDING",(0,0),(-1,-1),8)]))

def sub_hdr(txt, color=MID_BLUE):
    return Table([[Paragraph(f"<font color='white'><b>{txt}</b></font>",
                  S("_s",fontName="Helvetica-Bold",fontSize=8.5,leading=11,textColor=WHITE))]],
        colWidths=[CONTENT_W],
        style=TableStyle([("BACKGROUND",(0,0),(-1,-1),color),
                          ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                          ("LEFTPADDING",(0,0),(-1,-1),8)]))

def bullet(txt):
    return Paragraph(f"<bullet>&bull;</bullet> {txt}",
        S("_bl",fontName="Helvetica",fontSize=8.5,leading=12,textColor=TXT_DARK,
          leftIndent=0.35*cm,bulletIndent=0))

# ════════════════════════════════════════════════════════════
# ANATOMICAL DIAGRAM FLOWABLE
# ════════════════════════════════════════════════════════════
class AnatomyDiagram(Flowable):
    """
    Draws a schematic sagittal-section pelvic diagram for a given ARM type.
    diagram_type: string key identifying which variant to draw
    sex: 'M' or 'F'
    w, h: dimensions in points
    """
    def __init__(self, diagram_type, sex, w=160, h=180, title="", prog="", prog_color=None):
        super().__init__()
        self.dtype  = diagram_type
        self.sex    = sex
        self.w      = w
        self.h      = h
        self.title  = title
        self.prog   = prog
        self.prog_color = prog_color or GREEN
        self.width  = w
        self.height = h

    def draw(self):
        c = self.canv
        w, h = self.w, self.h

        # ── background box ───────────────────────────────────
        c.setFillColor(colors.HexColor("#F0F8FF"))
        c.setStrokeColor(colors.HexColor("#AACCEE"))
        c.setLineWidth(0.8)
        c.roundRect(0, 0, w, h, 6, fill=1, stroke=1)

        # ── title bar ────────────────────────────────────────
        c.setFillColor(NAVY)
        c.roundRect(0, h-22, w, 22, 6, fill=1, stroke=0)
        c.setFillColor(WHITE)
        c.setFont("Helvetica-Bold", 7)
        # wrap title
        words = self.title.split()
        line1 = " ".join(words[:4])
        line2 = " ".join(words[4:]) if len(words) > 4 else ""
        if line2:
            c.drawCentredString(w/2, h-10, line1)
            c.drawCentredString(w/2, h-18, line2)
        else:
            c.drawCentredString(w/2, h-14, line1)

        # ── prognosis badge ──────────────────────────────────
        badge_w = 55
        c.setFillColor(self.prog_color)
        c.roundRect(w/2 - badge_w/2, 3, badge_w, 14, 4, fill=1, stroke=0)
        c.setFillColor(WHITE)
        c.setFont("Helvetica-Bold", 7)
        c.drawCentredString(w/2, 8, f"Prognosis: {self.prog}")

        # ── shared anatomy drawing area ──────────────────────
        # Origin at bottom-left of drawing area
        draw_y0 = 22   # above badge
        draw_h  = h - 22 - 24  # below title bar, above badge
        # centre x
        cx = w / 2

        self._draw_anatomy(c, cx, draw_y0, draw_h, w)

    def _draw_anatomy(self, c, cx, y0, dh, w):
        """Draw the specific anatomy for each defect type."""
        dt = self.dtype

        # Common landmarks (scaled proportionally)
        scale = dh / 130.0   # base height = 130 units

        def Y(u):   return y0 + u * scale   # unit → canvas y
        def X(u):   return cx + u * scale   # unit offset from centre

        # ── SACRUM (always present) ─────────────────────────
        c.setFillColor(BONE)
        c.setStrokeColor(colors.HexColor("#8B7355"))
        c.setLineWidth(0.5)
        # Sacrum = tapered trapezoid on right side
        sacrum = [X(12), Y(50), X(22), Y(50), X(18), Y(110), X(8), Y(110)]
        c.setFillColor(BONE)
        p = c.beginPath()
        p.moveTo(sacrum[0], sacrum[1])
        for i in range(2, len(sacrum), 2):
            p.lineTo(sacrum[i], sacrum[i+1])
        p.close()
        c.drawPath(p, fill=1, stroke=1)
        c.setFont("Helvetica", 5.5)
        c.setFillColor(colors.HexColor("#5D4037"))
        c.drawCentredString(X(15), Y(78), "Sacrum")

        # ── LEVATOR ANI muscle (always present) ─────────────
        c.setFillColor(SPHINCTER)
        c.setStrokeColor(colors.HexColor("#1A5C50"))
        c.setLineWidth(0.8)
        # Horizontal band at levator level
        lev_y = Y(45)
        c.rect(X(-30), lev_y - 4*scale, 55*scale, 8*scale, fill=1, stroke=1)
        c.setFillColor(WHITE)
        c.setFont("Helvetica-Bold", 5.5)
        c.drawCentredString(X(-3), lev_y - 0.5*scale, "Levator Ani")

        # ── EXTERNAL ANAL SPHINCTER ──────────────────────────
        sphinc_y = Y(28)
        c.setFillColor(MUSCLE_C)
        c.setStrokeColor(colors.HexColor("#0F4D29"))
        c.ellipse(X(-8), sphinc_y - 4*scale, X(8), sphinc_y + 4*scale, fill=1, stroke=1)
        c.setFillColor(WHITE)
        c.setFont("Helvetica", 5)
        c.drawCentredString(cx, sphinc_y, "EAS")

        # ── RECTUM (common to all) ───────────────────────────
        # Draw rectum from top area downward; terminus depends on type
        rect_x_l = X(-8)
        rect_x_r = X(8)

        if dt == "normal":
            # Rectum connects through levator and sphincter to perineum
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="normal")
            # Normal anal opening
            c.setFillColor(colors.HexColor("#8B4513"))
            c.ellipse(X(-5), Y(18), X(5), Y(24), fill=1, stroke=0)
            c.setFillColor(TXT_DARK)
            c.setFont("Helvetica-Bold", 6)
            c.drawCentredString(cx, Y(12), "✓ Normal Anus")

        elif dt == "perineal_fistula":
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="above_lev")
            # Fistula track going anteriorly along perineum
            c.setStrokeColor(FISTULA_C)
            c.setLineWidth(2)
            c.line(X(-8), Y(40), X(-22), Y(25))
            c.setFillColor(FISTULA_C)
            c.circle(X(-22), Y(25), 4*scale, fill=1, stroke=0)
            c.setFillColor(TXT_DARK)
            c.setFont("Helvetica", 5.5)
            c.drawCentredString(X(-22), Y(18), "Fistula")
            c.drawCentredString(X(-22), Y(13), "on perineum")
            # No normal anus label
            c.setFillColor(RED)
            c.setFont("Helvetica-Bold", 5.5)
            c.drawCentredString(cx, Y(8), "✗ No normal anal opening")

        elif dt == "bulbar":
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="high")
            self._urethra(c, cx, y0, dh, scale, Y, X, sex="M")
            # Fistula to bulbar urethra
            c.setStrokeColor(FISTULA_C)
            c.setLineWidth(2)
            c.line(X(-7), Y(62), X(2), Y(55))
            self._label_fistula(c, cx, scale, Y, X, "→ Bulbar\nurethra", X(-12), Y(55))
            c.setFillColor(RED)
            c.setFont("Helvetica-Bold", 5.5)
            c.drawCentredString(cx, Y(8), "Meconium in urine")

        elif dt == "prostatic":
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="high")
            self._urethra(c, cx, y0, dh, scale, Y, X, sex="M")
            # Fistula to prostatic urethra (higher)
            c.setStrokeColor(FISTULA_C)
            c.setLineWidth(2)
            c.line(X(-7), Y(72), X(2), Y(68))
            self._label_fistula(c, cx, scale, Y, X, "→ Prostatic\nurethra", X(-14), Y(70))
            c.setFillColor(RED)
            c.setFont("Helvetica-Bold", 5.5)
            c.drawCentredString(cx, Y(8), "Meconium in urine")

        elif dt == "bladder_neck":
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="very_high")
            self._bladder(c, cx, y0, dh, scale, Y, X)
            # Fistula to bladder neck
            c.setStrokeColor(FISTULA_C)
            c.setLineWidth(2)
            c.line(X(-7), Y(88), X(5), Y(85))
            self._label_fistula(c, cx, scale, Y, X, "→ Bladder\nneck", X(-16), Y(92))
            c.setFillColor(RED)
            c.setFont("Helvetica-Bold", 5.5)
            c.drawCentredString(cx, Y(8), "Highest defect")

        elif dt == "no_fistula_m":
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="high_blind")
            c.setFillColor(PURPLE)
            c.setFont("Helvetica-Bold", 6)
            c.drawCentredString(cx, Y(70), "Blind-ending")
            c.drawCentredString(cx, Y(63), "rectal pouch")
            c.setFillColor(TXT_DARK)
            c.setFont("Helvetica", 5.5)
            c.drawCentredString(cx, Y(8), "Associated: Trisomy 21")

        elif dt == "vestibular":
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="above_lev")
            self._vagina(c, cx, y0, dh, scale, Y, X)
            # Fistula to vestibule
            c.setStrokeColor(FISTULA_C)
            c.setLineWidth(2)
            c.line(X(-8), Y(40), X(-18), Y(30))
            c.setFillColor(FISTULA_C)
            c.circle(X(-18), Y(30), 3.5*scale, fill=1, stroke=0)
            c.setFillColor(TXT_DARK)
            c.setFont("Helvetica", 5.5)
            c.drawCentredString(X(-20), Y(22), "Opens at")
            c.drawCentredString(X(-20), Y(17), "vestibule")
            c.setFillColor(colors.HexColor("#9B59B6"))
            c.setFont("Helvetica", 5)
            c.drawCentredString(cx, Y(8), "2 perineal openings visible")

        elif dt == "no_fistula_f":
            self._rectum(c, cx, y0, dh, scale, Y, X, terminus="high_blind")
            self._vagina(c, cx, y0, dh, scale, Y, X)
            c.setFillColor(PURPLE)
            c.setFont("Helvetica-Bold", 6)
            c.drawCentredString(cx, Y(70), "Blind-ending")
            c.drawCentredString(cx, Y(63), "rectal pouch")
            c.setFillColor(TXT_DARK)
            c.setFont("Helvetica", 5.5)
            c.drawCentredString(cx, Y(8), "Associated: Trisomy 21")

        elif dt == "cloaca":
            # Three structures merging into one channel
            # Rectum
            c.setFillColor(RECTUM_C)
            c.setStrokeColor(colors.HexColor("#7B241C"))
            c.setLineWidth(0.6)
            c.rect(X(-14), Y(50), 10*scale, 50*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold",5)
            c.drawCentredString(X(-9), Y(78), "Rectum")

            # Vagina
            c.setFillColor(PINK)
            c.setStrokeColor(colors.HexColor("#9B0B4A"))
            c.rect(X(-3), Y(52), 9*scale, 46*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold",5)
            c.drawCentredString(X(1.5), Y(78), "Vag")

            # Urethra
            c.setFillColor(BLUE_UR)
            c.setStrokeColor(colors.HexColor("#1A5276"))
            c.rect(X(7), Y(54), 7*scale, 44*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold",5)
            c.drawCentredString(X(10.5), Y(78), "Ur")

            # Convergence funnel at levator level
            c.setFillColor(AMBER)
            pts = [X(-14), Y(50), X(14), Y(50), X(4), Y(38), X(-4), Y(38)]
            p = c.beginPath()
            p.moveTo(pts[0], pts[1])
            p.lineTo(pts[2], pts[3])
            p.lineTo(pts[4], pts[5])
            p.lineTo(pts[6], pts[7])
            p.close()
            c.drawPath(p, fill=1, stroke=0)
            c.setFillColor(WHITE)
            c.setFont("Helvetica-Bold", 5.5)
            c.drawCentredString(cx, Y(44), "Common Channel")

            # Single opening
            c.setFillColor(AMBER)
            c.circle(cx, Y(30), 5*scale, fill=1, stroke=0)
            c.setFillColor(WHITE)
            c.setFont("Helvetica-Bold", 6)
            c.drawCentredString(cx, Y(29), "1")
            c.setFillColor(TXT_DARK)
            c.setFont("Helvetica", 5.5)
            c.drawCentredString(cx, Y(18), "Single perineal")
            c.drawCentredString(cx, Y(13), "opening only")
            c.setFillColor(RED)
            c.setFont("Helvetica-Bold", 5.5)
            c.drawCentredString(cx, Y(8), "Most complex defect")

        elif dt == "rectal_atresia":
            # Upper rectum dilated
            c.setFillColor(RECTUM_C)
            c.setStrokeColor(colors.HexColor("#7B241C"))
            c.setLineWidth(0.6)
            c.rect(X(-12), Y(72), 24*scale, 30*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold",5.5)
            c.drawCentredString(cx, Y(88), "Dilated upper")
            c.drawCentredString(cx, Y(82), "rectum")

            # Interruption band
            c.setFillColor(RED)
            c.rect(X(-12), Y(66), 24*scale, 6*scale, fill=1, stroke=0)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold",5.5)
            c.drawCentredString(cx, Y(69), "ATRESIA / INTERRUPTION")

            # Lower small anal canal
            c.setFillColor(colors.HexColor("#C0392B"))
            c.setStrokeColor(colors.HexColor("#7B241C"))
            c.rect(X(-5), Y(40), 10*scale, 26*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica",5)
            c.drawCentredString(cx, Y(56), "Small anal")
            c.drawCentredString(cx, Y(51), "canal")
            c.setFillColor(TXT_DARK); c.setFont("Helvetica",5.5)
            c.drawCentredString(cx, Y(8), "Lumen interrupted")

    def _rectum(self, c, cx, y0, dh, scale, Y, X, terminus="normal"):
        """Draw the rectum as a column."""
        c.setFillColor(RECTUM_C)
        c.setStrokeColor(colors.HexColor("#7B241C"))
        c.setLineWidth(0.6)
        if terminus == "normal":
            # Runs from top down through levator and sphincter
            c.rect(X(-8), Y(24), 16*scale, 76*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 5)
            c.drawCentredString(cx, Y(80), "Rectum")
        elif terminus == "above_lev":
            # Ends just above levator (low defect - fistula before exiting)
            c.rect(X(-8), Y(42), 16*scale, 58*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 5)
            c.drawCentredString(cx, Y(78), "Rectum")
        elif terminus == "high":
            c.rect(X(-8), Y(55), 16*scale, 45*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 5)
            c.drawCentredString(cx, Y(80), "Rectum")
        elif terminus == "very_high":
            c.rect(X(-8), Y(75), 16*scale, 25*scale, fill=1, stroke=1)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 5)
            c.drawCentredString(cx, Y(88), "Rectum")
        elif terminus in ("high_blind", ):
            c.rect(X(-8), Y(55), 16*scale, 45*scale, fill=1, stroke=1)
            # Blind end cap
            c.setFillColor(colors.HexColor("#7B241C"))
            c.ellipse(X(-8), Y(52), X(8), Y(58), fill=1, stroke=0)
            c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 5)
            c.drawCentredString(cx, Y(80), "Rectum")

    def _urethra(self, c, cx, y0, dh, scale, Y, X, sex="M"):
        c.setFillColor(BLUE_UR)
        c.setStrokeColor(colors.HexColor("#1A5276"))
        c.setLineWidth(0.5)
        c.rect(X(10), Y(28), 8*scale, 60*scale, fill=1, stroke=1)
        c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 5)
        c.drawCentredString(X(14), Y(60), "Ure-")
        c.drawCentredString(X(14), Y(55), "thra")
        # Bladder outline
        c.setFillColor(colors.HexColor("#AED6F1"))
        c.setStrokeColor(BLUE_UR)
        c.ellipse(X(4), Y(88), X(24), Y(105), fill=1, stroke=1)
        c.setFillColor(BLUE_UR); c.setFont("Helvetica-Bold", 5)
        c.drawCentredString(X(14), Y(97), "Bladder")

    def _bladder(self, c, cx, y0, dh, scale, Y, X):
        c.setFillColor(colors.HexColor("#AED6F1"))
        c.setStrokeColor(BLUE_UR)
        c.setLineWidth(0.6)
        c.ellipse(X(2), Y(78), X(24), Y(100), fill=1, stroke=1)
        c.setFillColor(BLUE_UR); c.setFont("Helvetica-Bold", 5.5)
        c.drawCentredString(X(13), Y(90), "Bladder")
        # Bladder neck marker
        c.setFillColor(AMBER)
        c.circle(X(10), Y(78), 4*scale, fill=1, stroke=0)
        c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 4.5)
        c.drawCentredString(X(10), Y(77), "BN")

    def _vagina(self, c, cx, y0, dh, scale, Y, X):
        c.setFillColor(PINK)
        c.setStrokeColor(colors.HexColor("#9B0B4A"))
        c.setLineWidth(0.5)
        c.rect(X(10), Y(30), 8*scale, 50*scale, fill=1, stroke=1)
        c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 5)
        c.drawCentredString(X(14), Y(56), "Vag-")
        c.drawCentredString(X(14), Y(51), "ina")
        # Uterus
        c.setFillColor(colors.HexColor("#E8A0CC"))
        c.setStrokeColor(colors.HexColor("#9B0B4A"))
        c.ellipse(X(7), Y(80), X(21), Y(95), fill=1, stroke=1)
        c.setFillColor(WHITE); c.setFont("Helvetica-Bold", 4.5)
        c.drawCentredString(X(14), Y(88), "Uterus")

    def _label_fistula(self, c, cx, scale, Y, X, label, lx, ly):
        c.setFillColor(FISTULA_C)
        c.circle(lx, ly, 4*scale, fill=1, stroke=0)
        c.setFillColor(TXT_DARK); c.setFont("Helvetica", 5.5)
        lines = label.split("\n")
        for i, ln in enumerate(lines):
            c.drawCentredString(lx, ly - (i+1)*8, ln)


# ════════════════════════════════════════════════════════════
# BUILD DOCUMENT
# ════════════════════════════════════════════════════════════
doc = SimpleDocTemplate(OUTPUT, pagesize=A4,
    leftMargin=MARGIN, rightMargin=MARGIN,
    topMargin=MARGIN, bottomMargin=1.6*cm,
    title="ARM Classification – Male & Female with Diagrams",
    author="BSc Nursing – Paediatric Nursing")

def on_page(canvas, doc):
    canvas.saveState()
    canvas.setFillColor(NAVY)
    canvas.rect(0, PAGE_H - 0.9*cm, PAGE_W, 0.9*cm, fill=1, stroke=0)
    canvas.setFillColor(AMBER)
    canvas.rect(0, PAGE_H - 0.94*cm, PAGE_W, 0.04*cm, fill=1, stroke=0)
    canvas.setFillColor(WHITE)
    canvas.setFont("Helvetica-Bold", 8.5)
    canvas.drawString(MARGIN, PAGE_H - 0.6*cm, "ARM Classification – Male & Female Types with Anatomical Diagrams")
    canvas.setFont("Helvetica", 8)
    canvas.drawRightString(PAGE_W - MARGIN, PAGE_H - 0.6*cm, "BSc Nursing | Paediatric Nursing")
    canvas.setFillColor(NAVY)
    canvas.rect(0, 0, PAGE_W, 0.9*cm, fill=1, stroke=0)
    canvas.setFillColor(WHITE)
    canvas.setFont("Helvetica", 7)
    canvas.drawString(MARGIN, 0.3*cm, "Krickenbeck International Classification (2005) | Peña Anatomic Classification")
    canvas.drawRightString(PAGE_W - MARGIN, 0.3*cm, f"Page {doc.page}")
    canvas.restoreState()

story = []

# ─────────────────────────────────────────────────────────────
# TITLE
# ─────────────────────────────────────────────────────────────
title_tbl = Table([[
    Paragraph("<font color='white'><b>ANORECTAL MALFORMATION</b><br/>Classification by Sex – With Anatomical Diagrams</font>",
              S("_tt", fontName="Helvetica-Bold", fontSize=16, leading=20, textColor=WHITE, alignment=TA_CENTER)),
]], colWidths=[CONTENT_W],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),NAVY),
                      ("TOPPADDING",(0,0),(-1,-1),10),("BOTTOMPADDING",(0,0),(-1,-1),10)]))
story.append(title_tbl)
story.append(sp(0.1))

# Legend bar
legend = Table([[
    Paragraph("<font color='white'><b>Visible Opening</b> = Fistula on perineum/genitalia (LOW defect)</font>",
              S("_l1", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=WHITE)),
    Paragraph("<font color='white'><b>Invisible Opening</b> = Internal fistula / no fistula (HIGH defect)</font>",
              S("_l2", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=WHITE)),
]], colWidths=[CONTENT_W/2]*2,
    style=TableStyle([
        ("BACKGROUND",(0,0),(0,0), GREEN),
        ("BACKGROUND",(1,0),(1,0), RED),
        ("TOPPADDING",(0,0),(-1,-1),4),("BOTTOMPADDING",(0,0),(-1,-1),4),
        ("LEFTPADDING",(0,0),(-1,-1),8),
        ("GRID",(0,0),(-1,-1),1,WHITE),
    ]))
story.append(legend)
story.append(sp(0.25))

# ═════════════════════════════════════════════════════════════
#  MALE SECTION
# ═════════════════════════════════════════════════════════════
story.append(sec_hdr("♂  MALE – ANORECTAL MALFORMATION CLASSIFICATION", MID_BLUE))
story.append(sp(0.12))

# --- Intro table for males ---
male_intro = Table([[
    Paragraph("<b>Total types:</b> 5 + rectal atresia", sm),
    Paragraph("<b>Most common:</b> Rectobulbar urethral fistula (~50%)", sm),
    Paragraph("<b>Key sign:</b> Meconium in urine → internal fistula", sm),
    Paragraph("<b>~70%</b> have rectourinary fistula", sm),
]], colWidths=[CONTENT_W/4]*4,
    style=TableStyle([
        ("BACKGROUND",(0,0),(-1,-1), SUBTLE),
        ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#AACCEE")),
        ("TOPPADDING",(0,0),(-1,-1),4),("BOTTOMPADDING",(0,0),(-1,-1),4),
        ("LEFTPADDING",(0,0),(-1,-1),5),
    ]))
story.append(male_intro)
story.append(sp(0.2))

# ── MALE: VISIBLE OPENING GROUP ─────────────────────────────
story.append(sub_hdr("👁  VISIBLE OPENING (External Fistula) – LOW DEFECT – Primary Repair, No Colostomy", GREEN))
story.append(sp(0.1))

DW = (CONTENT_W - 0.3*cm) / 2   # diagram width per column
DH = 4.8 * cm                    # diagram height

# Type 1: Normal (reference) + Perineal fistula
male_vis_diags = Table([[
    AnatomyDiagram("normal",         "M", w=int(DW*2.83), h=int(DH*2.83),
                   title="NORMAL ANATOMY Reference",
                   prog="N/A", prog_color=MID_BLUE),
    AnatomyDiagram("perineal_fistula","M", w=int(DW*2.83), h=int(DH*2.83),
                   title="1. Rectoperineal (Cutaneous) Fistula",
                   prog="Excellent", prog_color=GREEN),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2)]))
story.append(male_vis_diags)
story.append(sp(0.1))

# Info boxes for visible male types
vis_male_info = Table([[
    Table([
        [Paragraph("<b>NORMAL ANATOMY</b> (Reference)", S("_nh",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Rectum → anal canal → normal anal opening<br/>"
                   "• Levator ani muscle intact<br/>• External anal sphincter present<br/>• Anus in normal perineal position", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),MID_BLUE),("BACKGROUND",(0,1),(0,1),LIGHT_BG),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5),])),

    Table([
        [Paragraph("<b>1. RECTOPERINEAL FISTULA</b><br/><i>(Visible – Low defect)</i>",
                   S("_1h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Rectal opening on <b>perineal skin</b>, anterior to sphincter<br/>"
                   "• <b>Meconium visible on perineum</b> at birth<br/>"
                   "• Lowest ARM defect in males<br/>"
                   "• Fistula is <b>below levator ani</b><br/>"
                   "• <b>Rx:</b> Primary PSARP / cutback anoplasty<br/>"
                   "• <b>No colostomy</b> required<br/>"
                   "• <b>Prognosis: Excellent</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),GREEN),("BACKGROUND",(0,1),(0,1),colors.HexColor("#E8F5EE")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5),])),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0)]))
story.append(vis_male_info)
story.append(sp(0.25))

# ── MALE: INVISIBLE OPENING GROUP ───────────────────────────
story.append(sub_hdr("🔍  INVISIBLE / NO VISIBLE OPENING (Internal Fistula / No Fistula) – HIGH DEFECT – Colostomy Required", RED))
story.append(sp(0.12))

# Row 1 diagrams: bulbar + prostatic
inv_male_row1_diags = Table([[
    AnatomyDiagram("bulbar",   "M", w=int(DW*2.83), h=int(DH*2.83),
                   title="2. Rectobulbar Urethral Fistula  MOST COMMON",
                   prog="Good", prog_color=GREEN),
    AnatomyDiagram("prostatic","M", w=int(DW*2.83), h=int(DH*2.83),
                   title="3. Rectoprostatic Urethral Fistula",
                   prog="Moderate", prog_color=AMBER),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2)]))
story.append(inv_male_row1_diags)
story.append(sp(0.08))

inv_male_row1_info = Table([[
    Table([
        [Paragraph("<b>2. RECTOBULBAR URETHRAL FISTULA</b><br/><i>(Most common ♂ ARM – ~50%)</i>",
                   S("_2h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Fistula: rectum → <b>bulbar urethra</b><br/>"
                   "• <b>Nothing visible on perineum</b> (invisible)<br/>"
                   "• <b>Meconium / gas in urine</b> → diagnostic<br/>"
                   "• Rectum above levator ani<br/>"
                   "• <b>Rx:</b> Colostomy → PSARP → closure<br/>"
                   "• Screen: renal USS, VCUG, spinal MRI<br/>"
                   "• <b>Prognosis: Good</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),MID_BLUE),("BACKGROUND",(0,1),(0,1),LIGHT_BG),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),

    Table([
        [Paragraph("<b>3. RECTOPROSTATIC URETHRAL FISTULA</b>",
                   S("_3h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Fistula: rectum → <b>prostatic urethra</b><br/>"
                   "• Higher fistula than bulbar type<br/>"
                   "• <b>Meconium in urine</b> (higher entry point)<br/>"
                   "• Common sacral/vertebral anomalies<br/>"
                   "• <b>Rx:</b> Colostomy → PSARP (± laparoscopic)<br/>"
                   "• Higher risk of urinary incontinence<br/>"
                   "• <b>Prognosis: Moderate</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),AMBER),("BACKGROUND",(0,1),(0,1),colors.HexColor("#FFF8EC")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0)]))
story.append(inv_male_row1_info)
story.append(sp(0.2))

# Row 2 diagrams: bladder_neck + no_fistula_m
inv_male_row2_diags = Table([[
    AnatomyDiagram("bladder_neck","M", w=int(DW*2.83), h=int(DH*2.83),
                   title="4. Recto-Bladder Neck Fistula",
                   prog="Poor", prog_color=RED),
    AnatomyDiagram("no_fistula_m","M", w=int(DW*2.83), h=int(DH*2.83),
                   title="5. Imperforate Anus No Fistula",
                   prog="Good", prog_color=GREEN),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2)]))
story.append(inv_male_row2_diags)
story.append(sp(0.08))

inv_male_row2_info = Table([[
    Table([
        [Paragraph("<b>4. RECTO-BLADDER NECK FISTULA</b><br/><i>(Highest male defect)</i>",
                   S("_4h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Fistula: rectum → <b>bladder neck</b><br/>"
                   "• <b>Highest ARM in males</b><br/>"
                   "• <b>90%</b> have associated urinary tract anomaly<br/>"
                   "• Poor sacral development common<br/>"
                   "• <b>Rx:</b> Colostomy → PSARP + laparoscopy<br/>"
                   "• Lowest continence rate<br/>"
                   "• <b>Prognosis: Poor</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),RED),("BACKGROUND",(0,1),(0,1),colors.HexColor("#FDECEA")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),

    Table([
        [Paragraph("<b>5. IMPERFORATE ANUS – NO FISTULA</b>",
                   S("_5h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• <b>No fistula</b> to urinary or perineal skin<br/>"
                   "• Rectal pouch ends blindly<br/>"
                   "• Strongly associated with <b>Trisomy 21</b> (Down syndrome)<br/>"
                   "• Diagnosis: invertogram / colostogram<br/>"
                   "• <b>Rx:</b> Colostomy → PSARP at 1–3 months<br/>"
                   "• Good sphincter development possible<br/>"
                   "• <b>Prognosis: Good</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),PURPLE),("BACKGROUND",(0,1),(0,1),colors.HexColor("#F3E8FA")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0)]))
story.append(inv_male_row2_info)
story.append(sp(0.2))

# Male summary comparison table
story.append(sub_hdr("♂  MALE – QUICK COMPARISON TABLE", NAVY))
story.append(sp(0.08))

male_table_data = [
    [Paragraph(h, S("_mth",fontName="Helvetica-Bold",fontSize=8,leading=10,textColor=WHITE,alignment=TA_CENTER))
     for h in ["Type", "Fistula Site", "Perineal Finding", "Urine Finding", "Colostomy?", "Prognosis"]],
    ["Rectoperineal fistula", "Perineal skin", "Meconium ribbon/spot", "Normal", "No", "Excellent"],
    ["Rectobulbar urethral", "Bulbar urethra", "No perineal opening", "Meconium in urine ✓", "Yes", "Good"],
    ["Rectoprostatic urethral", "Prostatic urethra", "No perineal opening", "Meconium in urine ✓", "Yes", "Moderate"],
    ["Recto-bladder neck", "Bladder neck", "No perineal opening", "Meconium in urine ✓", "Yes", "Poor"],
    ["No fistula", "None", "No perineal opening", "Normal / no passage", "Yes", "Good"],
]
prog_bg_m = {"Excellent": colors.HexColor("#D4EDDA"), "Good": colors.HexColor("#D1ECF1"),
             "Moderate": colors.HexColor("#FFF3CD"), "Poor": colors.HexColor("#F8D7DA")}

mt_data = [[Paragraph(str(c), S("_mt",fontName="Helvetica",fontSize=8,leading=10,textColor=TXT_DARK))
            if not isinstance(c, Paragraph) else c for c in row]
           if ri > 0 else row
           for ri, row in enumerate(male_table_data)]
mt_data[0] = male_table_data[0]

mts = TableStyle([
    ("BACKGROUND",(0,0),(-1,0), NAVY),
    ("GRID",(0,0),(-1,-1),0.4, colors.HexColor("#CCDDEE")),
    ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
    ("LEFTPADDING",(0,0),(-1,-1),4),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[WHITE, SUBTLE]),
    ("VALIGN",(0,0),(-1,-1),"MIDDLE"),
])
for i, row in enumerate(male_table_data[1:], 1):
    prog = row[5]
    mts.add("BACKGROUND",(5,i),(5,i), prog_bg_m.get(prog, WHITE))
    mts.add("FONTNAME",(0,i),(0,i),"Helvetica-Bold")

male_sum = Table(mt_data, colWidths=[3.5*cm, 3.0*cm, 2.8*cm, 3.0*cm, 1.8*cm, 2.0*cm],
                 style=mts, repeatRows=1)
story.append(male_sum)

# ═════════════════════════════════════════════════════════════
#  PAGE BREAK → FEMALE SECTION
# ═════════════════════════════════════════════════════════════
story.append(PageBreak())

story.append(sec_hdr("♀  FEMALE – ANORECTAL MALFORMATION CLASSIFICATION", colors.HexColor("#8B1A4A")))
story.append(sp(0.12))

female_intro = Table([[
    Paragraph("<b>Total types:</b> 4 + cloaca + rectal atresia", sm),
    Paragraph("<b>Most common:</b> Rectovestibular fistula (~50%)", sm),
    Paragraph("<b>Key sign:</b> Count perineal openings", sm),
    Paragraph("<b>1 opening only</b> = Cloaca (most complex)", sm),
]], colWidths=[CONTENT_W/4]*4,
    style=TableStyle([
        ("BACKGROUND",(0,0),(-1,-1), colors.HexColor("#FDE8F0")),
        ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#E8A0CC")),
        ("TOPPADDING",(0,0),(-1,-1),4),("BOTTOMPADDING",(0,0),(-1,-1),4),
        ("LEFTPADDING",(0,0),(-1,-1),5),
    ]))
story.append(female_intro)
story.append(sp(0.2))

# ── FEMALE: VISIBLE OPENING GROUP ───────────────────────────
story.append(sub_hdr("👁  VISIBLE OPENING (External Fistula) – LOW DEFECT – Primary Repair Possible", GREEN))
story.append(sp(0.1))

fem_vis_diags = Table([[
    AnatomyDiagram("normal",      "F", w=int(DW*2.83), h=int(DH*2.83),
                   title="NORMAL FEMALE ANATOMY Reference",
                   prog="N/A", prog_color=MID_BLUE),
    AnatomyDiagram("vestibular",  "F", w=int(DW*2.83), h=int(DH*2.83),
                   title="2. Rectovestibular Fistula  MOST COMMON F",
                   prog="Good", prog_color=GREEN),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2)]))
story.append(fem_vis_diags)
story.append(sp(0.08))

fem_vis_info = Table([[
    Table([
        [Paragraph("<b>1. RECTOPERINEAL FISTULA</b><br/><i>(Visible – Lowest female defect)</i>",
                   S("_fv1h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Rectal opening on <b>perineal skin</b>, anterior to sphincter<br/>"
                   "• <b>Meconium visible on perineum</b> at birth<br/>"
                   "• Same as male perineal fistula<br/>"
                   "• Fistula below levator ani<br/>"
                   "• <b>Rx:</b> Primary PSARP / cutback anoplasty<br/>"
                   "• <b>No colostomy</b> required<br/>"
                   "• <b>Prognosis: Excellent</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),GREEN),("BACKGROUND",(0,1),(0,1),colors.HexColor("#E8F5EE")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),

    Table([
        [Paragraph("<b>2. RECTOVESTIBULAR FISTULA</b><br/><i>(Most common female ARM ~50%)</i>",
                   S("_fv2h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Fistula opens at <b>vaginal vestibule (introitus)</b><br/>"
                   "• <b>2 perineal openings</b> visible in female<br/>"
                   "• Meconium passes through vestibular fistula<br/>"
                   "• Fistula at/just above levator ani<br/>"
                   "• Can initially dilate fistula and delay repair<br/>"
                   "• <b>Rx:</b> PSARP (± colostomy)<br/>"
                   "• <b>Prognosis: Good</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),TEAL),("BACKGROUND",(0,1),(0,1),LIGHT_BG),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0)]))
story.append(fem_vis_info)
story.append(sp(0.2))

# ── FEMALE: INVISIBLE OPENING GROUP ─────────────────────────
story.append(sub_hdr("🔍  INVISIBLE / NO VISIBLE OPENING (Internal / No Fistula) – HIGH DEFECT – Colostomy Required", RED))
story.append(sp(0.12))

fem_inv_diags = Table([[
    AnatomyDiagram("cloaca",      "F", w=int(DW*2.83), h=int(DH*2.83),
                   title="3. CLOACA Most Complex Female ARM",
                   prog="Variable/Poor", prog_color=RED),
    AnatomyDiagram("no_fistula_f","F", w=int(DW*2.83), h=int(DH*2.83),
                   title="4. Imperforate Anus No Fistula",
                   prog="Good", prog_color=GREEN),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2)]))
story.append(fem_inv_diags)
story.append(sp(0.08))

fem_inv_info = Table([[
    Table([
        [Paragraph("<b>3. CLOACA</b><br/><i>(Most complex female ARM – single perineal opening)</i>",
                   S("_fc3h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Rectum + Vagina + Urethra → <b>1 common channel</b><br/>"
                   "• <b>Only 1 perineal opening</b> (pathognomonic for cloaca)<br/>"
                   "• <b>Short channel &lt;3cm</b> → better prognosis (TUM)<br/>"
                   "• <b>Long channel &gt;3cm</b> → poor prognosis (complex repair)<br/>"
                   "• <b>90%</b> associated urinary tract anomaly<br/>"
                   "• <b>Rx:</b> Colostomy at birth → Total Urogenital Mobilization<br/>"
                   "• <b>Prognosis: Variable → Poor</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),RED),("BACKGROUND",(0,1),(0,1),colors.HexColor("#FDECEA")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),

    Table([
        [Paragraph("<b>4. IMPERFORATE ANUS – NO FISTULA</b>",
                   S("_ff4h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• <b>No fistula</b> to vagina, perineum, or urinary tract<br/>"
                   "• Rectal pouch ends blindly<br/>"
                   "• Strongly associated with <b>Trisomy 21</b> (Down syndrome)<br/>"
                   "• Diagnosis: invertogram / distal colostogram<br/>"
                   "• <b>Rx:</b> Colostomy → PSARP at 1–3 months<br/>"
                   "• No urine contamination<br/>"
                   "• <b>Prognosis: Good</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),PURPLE),("BACKGROUND",(0,1),(0,1),colors.HexColor("#F3E8FA")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0)]))
story.append(fem_inv_info)
story.append(sp(0.12))

# Rectal atresia (both sexes, shown in female section)
story.append(sub_hdr("⚠  RECTAL ATRESIA / STENOSIS – Both Sexes – Rare Variant", NAVY))
story.append(sp(0.08))

rec_at_row = Table([[
    AnatomyDiagram("rectal_atresia","F", w=int(DW*2.83), h=int(DH*2.83),
                   title="5. Rectal Atresia / Stenosis",
                   prog="Moderate", prog_color=AMBER),
    Table([
        [Paragraph("<b>5. RECTAL ATRESIA / STENOSIS</b><br/><i>(Both sexes – rare; Krickenbeck regional variant)</i>",
                   S("_ra_h",fontName="Helvetica-Bold",fontSize=8,leading=11,textColor=WHITE,alignment=TA_CENTER))],
        [Paragraph("• Lumen of rectum is <b>completely or partially interrupted</b><br/>"
                   "• <b>Upper rectum</b>: dilated (normal wall)<br/>"
                   "• <b>Lower rectum / anal canal</b>: narrow, small or fibrotic<br/>"
                   "• Unlike other ARM: anal opening may look normal externally<br/>"
                   "• Associated with <b>Trisomy 21</b><br/>"
                   "• Diagnosis: contrast enema, MRI<br/>"
                   "• <b>Rx:</b> Colostomy → posterior sagittal repair<br/>"
                   "• <b>Prognosis: Moderate</b>", sm)],
    ], colWidths=[DW - 0.2*cm],
       style=TableStyle([("BACKGROUND",(0,0),(0,0),AMBER),("BACKGROUND",(0,1),(0,1),colors.HexColor("#FFF8EC")),
                         ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                         ("LEFTPADDING",(0,0),(-1,-1),5)])),
]], colWidths=[DW, DW],
    style=TableStyle([("VALIGN",(0,0),(-1,-1),"TOP"),
                      ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0),
                      ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2)]))
story.append(rec_at_row)
story.append(sp(0.2))

# Female summary table
story.append(sub_hdr("♀  FEMALE – QUICK COMPARISON TABLE", colors.HexColor("#8B1A4A")))
story.append(sp(0.08))

female_table_data = [
    [Paragraph(h, S("_fth",fontName="Helvetica-Bold",fontSize=8,leading=10,textColor=WHITE,alignment=TA_CENTER))
     for h in ["Type", "Fistula Site", "Perineal Finding", "# Openings", "Colostomy?", "Prognosis"]],
    ["Rectoperineal fistula", "Perineal skin", "Meconium on perineum", "2 (fistula + urethra/vagina)", "No", "Excellent"],
    ["Rectovestibular fistula", "Vaginal vestibule", "Fistula at introitus", "2 (fistula + urethra)", "Usually No", "Good"],
    ["Cloaca – short (<3cm)", "Common channel", "Single perineal opening", "1 ONLY", "Yes", "Variable"],
    ["Cloaca – long (>3cm)", "Common channel", "Single perineal opening", "1 ONLY", "Yes", "Poor"],
    ["No fistula", "None", "No anal opening, no fistula", "0 (normal urethral only)", "Yes", "Good"],
    ["Rectal atresia", "None", "May appear normal externally", "External looks normal", "Yes", "Moderate"],
]
prog_bg_f = {"Excellent": colors.HexColor("#D4EDDA"), "Good": colors.HexColor("#D1ECF1"),
             "Variable": colors.HexColor("#FFF3CD"), "Poor": colors.HexColor("#F8D7DA"),
             "Moderate": colors.HexColor("#FFE8CC")}

fts = TableStyle([
    ("BACKGROUND",(0,0),(-1,0), colors.HexColor("#8B1A4A")),
    ("GRID",(0,0),(-1,-1),0.4, colors.HexColor("#CCDDEE")),
    ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
    ("LEFTPADDING",(0,0),(-1,-1),4),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[WHITE, colors.HexColor("#FDE8F0")]),
    ("VALIGN",(0,0),(-1,-1),"MIDDLE"),
])
for i, row in enumerate(female_table_data[1:], 1):
    prog = row[5]
    fts.add("BACKGROUND",(5,i),(5,i), prog_bg_f.get(prog, WHITE))
    fts.add("FONTNAME",(0,i),(0,i),"Helvetica-Bold")

ft_data = [[Paragraph(str(c), S("_ft",fontName="Helvetica",fontSize=8,leading=10,textColor=TXT_DARK))
            if not isinstance(c, Paragraph) else c for c in row]
           if ri > 0 else row for ri, row in enumerate(female_table_data)]
ft_data[0] = female_table_data[0]

female_sum = Table(ft_data, colWidths=[3.5*cm, 3.0*cm, 3.3*cm, 2.8*cm, 1.8*cm, 1.7*cm],
                   style=fts, repeatRows=1)
story.append(female_sum)
story.append(sp(0.2))

# ═════════════════════════════════════════════════════════════
# FINAL COMPARISON: VISIBLE vs INVISIBLE
# ═════════════════════════════════════════════════════════════
story.append(sec_hdr("VISIBLE vs INVISIBLE OPENING – CLINICAL DECISION GUIDE", NAVY))
story.append(sp(0.08))

vis_invis = Table([
    [Paragraph("<b>VISIBLE OPENING</b>", S("_vi1",fontName="Helvetica-Bold",fontSize=10,leading=13,textColor=WHITE,alignment=TA_CENTER)),
     Paragraph("<b>INVISIBLE / NO OPENING</b>", S("_vi2",fontName="Helvetica-Bold",fontSize=10,leading=13,textColor=WHITE,alignment=TA_CENTER))],
    [
        Paragraph("• Fistula opens on <b>perineal skin or vestibule</b><br/>"
                  "• Meconium visible at birth on perineum<br/>"
                  "• Defect is <b>LOW</b> (below/at levator ani)<br/>"
                  "• Males: Rectoperineal fistula<br/>"
                  "• Females: Rectoperineal + Rectovestibular fistula<br/><br/>"
                  "<b>Nursing action:</b><br/>"
                  "• Observe fistula site, note meconium passage<br/>"
                  "• Prepare for primary repair (no colostomy usually)<br/>"
                  "• Parent education re PSARP procedure<br/>"
                  "• <b>Prognosis: Excellent to Good</b>",
                  S("_vit1",fontName="Helvetica",fontSize=8.5,leading=13,textColor=TXT_DARK)),
        Paragraph("• No external fistula visible on perineum<br/>"
                  "• Defect is <b>HIGH</b> (above levator ani) or no fistula<br/>"
                  "• Males: Rectourethral / Recto-bladder neck / No fistula<br/>"
                  "• Females: Cloaca (1 opening) / No fistula<br/><br/>"
                  "<b>Key diagnostic signs:</b><br/>"
                  "• <b>Meconium in urine</b> → internal fistula (males)<br/>"
                  "• <b>Only 1 perineal opening</b> in female → Cloaca<br/>"
                  "• No meconium by 24–48h → urgent investigation<br/><br/>"
                  "<b>Nursing action:</b><br/>"
                  "• NPO, IV access, NG tube<br/>"
                  "• Invertogram / X-ray at 24h (males with no fistula)<br/>"
                  "• Prepare for colostomy (urgent bowel decompression)<br/>"
                  "• Renal USS, echo, spine X-ray (VACTERL screen)<br/>"
                  "• <b>Prognosis: Good (no fistula/low) → Poor (cloaca/BN)</b>",
                  S("_vit2",fontName="Helvetica",fontSize=8.5,leading=13,textColor=TXT_DARK)),
    ],
], colWidths=[CONTENT_W/2, CONTENT_W/2],
    style=TableStyle([
        ("BACKGROUND",(0,0),(0,0), GREEN),
        ("BACKGROUND",(1,0),(1,0), RED),
        ("BACKGROUND",(0,1),(0,1), colors.HexColor("#E8F5EE")),
        ("BACKGROUND",(1,1),(1,1), colors.HexColor("#FDECEA")),
        ("GRID",(0,0),(-1,-1),0.8,WHITE),
        ("TOPPADDING",(0,0),(-1,-1),6),("BOTTOMPADDING",(0,0),(-1,-1),6),
        ("LEFTPADDING",(0,0),(-1,-1),8),("VALIGN",(0,0),(-1,-1),"TOP"),
    ]))
story.append(vis_invis)

# build
doc.build(story, onFirstPage=on_page, onLaterPages=on_page)
print(f"PDF created: {OUTPUT}")
Running Command

cd /home/daytona/workspace/anorectal-malformation-ppt && python3 create_classifi…

Running Command

ls -lh /home/daytona/workspace/anorectal-malformation-ppt/ARM_Male_Female_Classi…

!

Failed to create session: bad request: failed to resolve container IP after 3 attempts: no IP address found. Is the Sandbox started?

We encountered an error while processing your request. Please try again or reach out to us for help.

??

Running Command

ls -lh /home/daytona/workspace/anorectal-malformation-ppt/

The file was successfully created before the connection dropped. Everything is ready!

Your PDF is here:

ARM Male Female Classification

PDF Document · PDF


PDF mein kya hai (2 pages, A4):
Page 1 – Male (♂) Classification
  • Normal anatomy reference diagram
  • Visible opening group (green): Rectoperineal fistula with diagram
  • Invisible opening group (red):
    • Rectobulbar urethral fistula (most common ♂)
    • Rectoprostatic urethral fistula
    • Recto-bladder neck fistula
    • Imperforate anus – no fistula
  • Male quick comparison table (fistula site, urine finding, colostomy, prognosis)
Page 2 – Female (♀) Classification
  • Normal female anatomy reference diagram
  • Visible opening group (green):
    • Rectoperineal fistula
    • Rectovestibular fistula (most common ♀)
  • Invisible opening group (red):
    • Cloaca – single perineal opening (most complex)
    • Imperforate anus – no fistula
  • Rectal atresia (both sexes)
  • Female quick comparison table (# perineal openings column added)
Bottom section: Visible vs Invisible clinical decision guide - nursing actions for each group
Har diagram mein - sacrum, levator ani, rectum, fistula track, urethra/vagina, bladder sab colour-coded shapes se clearly show kiya gaya hai.
This is a shared conversation. Sign in to Orris to start your own chat.