Teach me Spina Bidfidia in depth as a neonatologist

Reading File
Finding Sources
Finding Sources
Searching PubMed

"spina bifida" AND "neonatal management"

Reading File
Reading File
Finding Sources
Finding Sources
Searching PubMed

"myelomeningocele" AND "newborn" AND "management"

Reading File
Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Loading Image
Loading Image
Now I have comprehensive information from multiple authoritative textbooks. Let me compile the full in-depth neonatology-focused teaching on Spina Bifida.

Spina Bifida: An In-Depth Neonatology Teaching


1. What Is Spina Bifida? Definition & Spectrum

Spina bifida is a congenital malformation caused by failure of the neural tube to close during the 3rd-4th week of gestation. The term encompasses a spectrum from trivial to life-threatening, categorized broadly as:
TypeCore FeatureNeurologic Risk
Spina bifida occultaFailure of vertebral arch fusion; no sac; covered by skinUsually none (~10% of normal adults have it incidentally at L5/S1)
MeningoceleMeninges + CSF herniate through bony defect; spinal cord in normal position; skin-coveredLow to moderate
Myelomeningocele (MMC)Spinal cord AND nerve roots herniate into the meningeal sac; neural tissue exposedSevere, level-dependent
LipomeningoceleSpinal cord protrudes into a fat-filled subcutaneous sacVariable
Meroencephaly / AnencephalySevere MMC + absent calvaria + absent brain; associated with cranial anomaliesFatal
Neonatology pearl: The moment you receive a delivery notification for a fetus with spina bifida, the lesion type, level, and degree of skin coverage determine your entire initial management algorithm. Commit that to memory.

2. Embryology - The "Two-Hit" Hypothesis

Neural tube closure occurs between days 17-30 of gestation:
  • Primary neurulation: Closure of the neural folds to form the brain and spinal cord (cranial-to-caudal)
  • Secondary neurulation: Formation of the caudal spinal cord
MMC pathogenesis follows a Two-Hit Model:
  • Hit 1: Primary failure of neural tube closure at ~4 weeks gestation → open spinal canal
  • Hit 2: Prolonged exposure of the exposed neural placode to amniotic fluid (toxic insult) and direct mechanical trauma throughout pregnancy → secondary neurological destruction
This two-hit model is why fetal surgery (in utero repair) was hypothesized and later proven to reduce morbidity - closing the defect early stops "Hit 2."

3. Epidemiology & Risk Factors

  • Incidence: ~1 in 2,875 births in the US (decreasing due to folic acid fortification and prenatal screening)
  • MMC is the most common serious NTD
  • Neural tube defects overall: ~9:10,000 births
Key risk factors you must know:
CategoryRisk Factor
GeneticFamily history: 1 affected sibling = 20-50x increased maternal risk; individual with spina bifida = 40x normal risk
NutritionalFolate deficiency (most modifiable risk factor)
MedicationsValproic acid, carbamazepine (folate antagonists) - highest pharmacologic risk
Maternal diseasePregestational diabetes, obesity (BMI ≥35)
EnvironmentalHyperthermia (fever/flu in first trimester), passive smoking
DemographicYoung or advanced maternal age, low socioeconomic status
Prevention: Folic acid 400 mcg/day starting at least 1 month before conception and throughout pregnancy reduces NTD occurrence by up to 50%. Women with a previously affected child need 4 mg/day (10x higher dose). - Langman's Medical Embryology

4. Prenatal Diagnosis - The Signs You Need to Know

MMC is typically detected on second-trimester anatomy scan (18-20 weeks).
Spinal findings:
  • Cystic mass protruding from the dorsal vertebral bodies
  • U-shaped or V-shaped splayed vertebral ossification centers on transverse views
  • Lumbosacral lesions are most common, then sacral, thoracic, cervical
Secondary brain signs (look for these - they may be spotted before the spine!):
Second-trimester ultrasound showing myelomeningocele features including U-shaped splayed vertebrae, cystic protruding sac, and classic brain signs
Figure: Second-trimester ultrasound panels showing (A) normal spine, (B) tethered cord with meningolipoma, (C) cystic mass protruding lumbosacrally, (D) ventriculomegaly, (E) 3D reconstruction showing herniated neural tissue (arrows), (F) "banana sign" - abnormal curvature of cerebellar hemispheres. - Creasy & Resnik's Maternal-Fetal Medicine
Ultrasound SignDescriptionSensitivity
"Lemon sign"Concave/scalloped shape of frontal calvariaPresent in ~98% of fetuses with open spinal defect before 24 weeks
"Banana sign"Obliteration of cisterna magna; abnormal anterior curvature of cerebellumPresent in ~95% of spina bifida cases (does NOT resolve with gestation)
VentriculomegalySecondary to CSF obstructionCommon
MicrocephalySmall posterior fossaCommon
Loss of intracranial translucencyFirst-trimester sign; early compression of 4th ventricleCan be seen in T1 screening
Maternal serum AFP is elevated in open NTDs. If elevated, amniocentesis is performed to measure amniotic fluid AFP. - The Developing Human, Moore & Persaud

5. Delivery Room - What Happens When This Baby Arrives

Anticipatory Steps (Before Delivery)

  1. Assemble your neonatal team + neurosurgery on standby
  2. Prepare a warm radiant warmer with side rails; have warm saline-soaked non-adherent gauze ready
  3. Alert anesthesia for potential complex airway (Chiari II may cause vocal cord paralysis)
  4. Set up latex-free environment - MMC patients have high IgE-mediated latex allergy risk due to repeated mucosal latex exposures (catheterizations, surgeries)

Initial Assessment at Delivery

  • Ideally delivery by planned cesarean section at a tertiary center (minimizes trauma to the placode)
  • Place infant PRONE immediately after delivery
  • Assess the lesion: Is it open/closed? Level? Size? Is the sac intact or ruptured?
  • Is there active CSF leak?

Immediate Stabilization (The "ABCDE + Placode" Framework)

A - Airway: Assess for stridor, apnea, vocal cord dysfunction (Chiari II brainstem signs)
B - Breathing: Note respiratory pattern; apnea can be an early Chiari II symptom
C - Circulation: Standard assessment; correct hypothermia aggressively
D - Disability (Neurologic Level): Test spontaneous and reflex leg movements, anal wink reflex, bladder function
E - Expose: Assess the defect thoroughly
Placode Care:
  • Cover the defect with warm, sterile saline-soaked gauze (non-adherent dressing - Xeroform/Adaptic) to prevent desiccation
  • Do NOT apply antiseptic (betadine will destroy neural tissue)
  • Keep the baby prone or lateral - never supine (direct pressure on placode)
  • Place in a "donut ring" if you must handle supine
IV access & bloods: Start broad-spectrum antibiotics immediately (ampicillin + gentamicin or cefotaxime) - meningitis risk from open placode is high

6. Chiari II Malformation - The Brain Consequence

Almost ALL infants born with MMC have Chiari II malformation. This is not coincidental - it is mechanistically linked.
Pathogenesis: The open spinal defect allows CSF to constantly drain inferiorly in utero, depriving the developing posterior fossa of the hydraulic pressure it needs to expand. This results in a small posterior fossa that cannot accommodate the growing cerebellum and brainstem - these structures are forced downward through the foramen magnum.
Anatomy of Chiari II:
  • Caudal displacement of cerebellar vermis through foramen magnum
  • Caudal displacement of medulla oblongata into cervical spine
  • Kinking of the medulla
  • Obliteration of the cisterna magna
  • Small posterior fossa
  • Small or absent fourth ventricle
  • Associated: polymicrogyria, syringomyelia, hydrocephalus
Clinical consequences:
SymptomMechanism
Apnea + bradycardiaMedullary compression of respiratory centers
StridorVocal cord paresis (abductor weakness)
Swallowing dysfunction + aspirationLower cranial nerve involvement (IX, X, XII)
OpisthotonosCervical cord compression
SpasticityUpper motor neuron involvement
Sleep-disordered breathingBrainstem dysfunction
Critical neonatology pearl: If you see apnea or stridor in an MMC baby, think Chiari II first. This carries a mortality rate of 35% among symptomatic patients. - Barash's Clinical Anesthesia
The immediate management of symptomatic Chiari II is VP shunting first (to relieve hydrocephalus), and if no improvement, posterior fossa decompression.

7. Hydrocephalus - The Universal Companion

  • 80-90% of MMC infants will develop hydrocephalus requiring treatment
  • Incidence is higher with thoracic and upper lumbar lesions vs. sacral lesions
  • Mechanism: Chiari II impairs CSF circulation through the 4th ventricle → non-communicating hydrocephalus
  • Starts as early as the 1st trimester (by 19-25 weeks' gestation in most cases)
  • ~50% of children will have a shunt complication in the first year of life
Treatment options:
  1. Ventriculoperitoneal (VP) shunt - traditional standard, placed at same time as MMC closure or delayed until symptomatic
  2. Endoscopic Third Ventriculostomy (ETV) + Choroid Plexus Cauterization (CPC): Avoids shunt in >70% of MMC patients; similar neurocognitive outcomes to VP shunting - Campbell Walsh Wein Urology
Signs of hydrocephalus in the neonate:
  • Increasing head circumference (measure daily)
  • Bulging, tense anterior fontanelle
  • Sunset sign (eyes deviated downward)
  • Irritability
  • Vomiting
  • Bradycardia with advancing ICP

8. Timing of Surgical Closure

Postnatal repair standard: Close the defect within 24-48 hours of birth
  • Rationale: Every hour the placode is exposed risks ascending infection (meningitis), progressive neurological deterioration
  • Closure + VP shunt are often performed simultaneously or within days
  • Infants surviving past 24 hours: approximately 50% reach school age with early closure + antibiotics + shunting - Bailey & Love's Surgery
The MOMS Trial (Management of Myelomeningocele Study): The landmark RCT that changed practice. Prenatal repair before 26 weeks vs. standard postnatal repair:
OutcomePrenatal SurgeryPostnatal Surgery
Death or need for shunt68%98%
Actual shunt placement40%82%
Mean gestational age at delivery34 1/7 weeks37 3/7 weeks
Preterm delivery <30 weeks13%0%
Mental development + motor scoreSignificantly betterStandard
Trade-offs: Prenatal surgery means prematurity (~13% delivered before 30 weeks), pulmonary edema in mothers, abruptio placentae, increased NICU admission. A 2025 meta-analysis (PMID 40492626) confirmed these benefits and complications across multiple populations.
Criteria for prenatal repair: Singleton fetus, MMC with spinal defect at T1-S1, Chiari II with hindbrain herniation confirmed, gestational age 19-26 weeks, no karyotypic abnormalities, no other life-threatening anomaly.

9. Neurologic Level & Functional Prognosis

The level of the lesion is the single biggest determinant of functional outcome. However, note: the bony level and the neurologic level may differ by 1-3 segments - always assess clinically.
Lesion LevelMotor FunctionAmbulation Prognosis
ThoracicNo voluntary lower limb movementWheelchair-dependent; hip flexors absent
L1-L2Hip flexion onlyCommunity mobility with KAFO; often wheelchair
L3-L4Quadriceps function (L4 key level)Ambulation possible with bracing; community ambulator with AFO
L5Ankle dorsiflexionGood prognosis, independent ambulation with bracing
S1-S2Good foot and ankle functionNear-normal ambulation
The L4 Rule: L4 is the most clinically relevant functional level for neonatologists and orthopedic surgeons. Presence of quadriceps function (knee extension) = patient has a reasonable chance of community ambulation.

10. Neurogenic Bladder - The Hidden Morbidity

Often underappreciated at birth, neurogenic bladder is responsible for significant long-term morbidity and mortality in spina bifida.
  • The bladder receives innervation from S2-S4 (sacral micturition center)
  • Almost all MMC patients have some degree of lower urinary tract dysfunction
  • The neurologic lesion is unpredictable from bony level alone - urodynamic evaluation is essential
  • MMC is the most common cause of neurogenic bladder in children
Consequences if untreated:
  • Vesicoureteral reflux (VUR)
  • Hydronephrosis
  • Recurrent UTIs
  • Progressive renal failure (leading cause of death in previously untreated patients)
Neonatal management:
  • Begin clean intermittent catheterization (CIC) in the first days of life before discharge - even before urodynamics
  • Early urodynamics after stabilization
  • Monitor renal ultrasound
  • Some centers start anticholinergics early to protect detrusor from high-pressure dysfunction

11. Associated Anomalies - Your Systems Checklist at Birth

When you receive an MMC baby, systematically evaluate for:
SystemAnomaly to Look For
CNSChiari II (near-universal), hydrocephalus, syringomyelia, tethered cord (later), polymicrogyria
SpineKyphosis, scoliosis (especially with thoracic-level MMC)
OrthopedicClubfoot (talipes equinovarus), hip dislocations, joint contractures, limb deformities
UrologicNeurogenic bladder, VUR, hydronephrosis
GINeurogenic bowel, constipation, anal sphincter dysfunction
SkinPressure injuries (insensate skin = no protective sensation)
MetabolicObesity risk in long-term survivors
CognitiveIQ >80 in >70% of long-term survivors, but non-verbal learning disabilities are common

12. Preoperative Stabilization - The Neonatology Checklist

Before the infant goes to the OR (within 24-48h):
  • Position: Prone or lateral at all times
  • Placode coverage: Sterile saline-soaked non-adherent gauze; change every 2-4h or as needed
  • Temperature: Warm the environment; monitor closely - the large exposed defect accelerates heat loss
  • IV access + fluids: Maintain euvolemia; replace CSF losses from leaking sac with balanced crystalloid
  • Antibiotics: Ampicillin + gentamicin (or per local protocol) started immediately
  • Head circumference: Measure and document at birth; repeat daily
  • Cranial USS: Obtain early to document baseline ventricle size
  • Urologic assessment: Voiding pattern; early bladder ultrasound
  • Latex precautions: ALL equipment, IV sets, gloves must be latex-free from day one
  • Neurologic exam: Document baseline motor level carefully
  • Echo: Screen for congenital heart defects
  • Family counseling: Multidisciplinary team (neurosurgery, urology, orthopedics, physiotherapy, nursing) must be present early

13. Postoperative Care - Neonatal Period

After surgical closure:
  • Continue prone positioning until wound heals
  • Monitor for CSF leak at wound site
  • Watch for signs of hydrocephalus - may worsen rapidly after closure as CSF is no longer "venting" through the open defect
  • Expect many infants to need VP shunt within days to weeks of closure
  • Wound infection monitoring: dehiscence is a serious complication (large defects may require flap closure by plastic surgery)
  • Continue neurological assessments
Complications to anticipate:
  1. Meningitis - most feared early complication
  2. Wound dehiscence
  3. Progressive hydrocephalus / shunt malfunction
  4. Shunt infection
  5. Chiari II symptoms (apnea, stridor) - may emerge post-closure

14. Long-Term Outlook - Setting Family Expectations

  • 5-year mortality: ~79:1000 (7.9%) among those undergoing neonatal repair - Creasy & Resnik
  • Mortality is 35% in those with symptomatic brainstem dysfunction
  • IQ >80 in over 70% of long-term survivors
  • Only 37% can live independently as adults
  • Major long-term disabilities: lower limb paralysis, neurogenic bladder + bowel, sexual dysfunction, scoliosis, pressure ulcers
  • Cognitive profile: typically non-verbal learning disability pattern (visual-spatial deficits, attention issues) with relatively preserved verbal skills
  • Puberty can accelerate tethered cord symptoms and scoliosis

15. Spina Bifida Occulta - The Quiet Form

  • Affects ~10% of the population incidentally (L5/S1)
  • Usually found incidentally on imaging; no symptoms in most cases
  • External markers (the "skin signs" that should prompt spinal MRI in a newborn):
    • Hairy tuft (hypertrichosis) over midline
    • Sacral dimple (especially if deep, off-midline, or >5mm)
    • Dermal sinus tract
    • Lipoma
    • Hemangioma
    • Skin tag or appendage
MRI spine is the imaging of choice to evaluate occult spinal dysraphism.

16. The MRI Image of Spina Bifida

Sagittal T1-weighted MRI showing spina bifida with protruding lipomyelomeningocele (arrowheads), low-lying conus medullaris, and lipomas of the filum terminale
Sagittal T1-weighted MRI showing a low-lying conus medullaris at L4, lipomas of the filum terminale (bright signal in canal), and a lipomyelomeningocele protruding through the spinal defect (arrowheads). - Bradley & Daroff's Neurology

17. High-Yield Summary Table

FeatureKey Point
Most common open NTDMyelomeningocele (MMC)
Incidence~1:2,875 births
Primary preventionFolic acid 400 mcg/day preconceptually
Recurrence supplement4 mg/day in next pregnancy
Teratogenic drug riskValproic acid, carbamazepine
Prenatal US signsLemon sign, banana sign, ventriculomegaly
Nearly universal brain anomalyChiari II malformation
Hydrocephalus rate80-90% of MMC
Timing of postnatal closureWithin 24-48h
Prenatal repair benefit40% vs 82% shunt rate (MOMS trial)
Critical latex ruleLatex-free environment from birth
Key neurologic levelL4 = quadriceps = ambulation predictor
Universal urologic concernNeurogenic bladder; begin CIC early
Cognitive prognosisIQ >80 in >70%; 37% independent adults

Sources: Creasy & Resnik's Maternal-Fetal Medicine; Barash's Clinical Anesthesia 9e; Campbell Walsh Wein Urology; Bradley & Daroff's Neurology in Clinical Practice; Bailey & Love's Surgery 28e; Campbell's Operative Orthopaedics 15e; The Developing Human (Moore & Persaud); Goldman-Cecil Medicine; Langman's Medical Embryology. Recent meta-analysis: Kunpalin et al., 2025 (PMID 40492626) confirming fetal vs. postnatal surgery outcomes.

Generate a quick reference PDF summarizing neonatal Chiari II warning signs and emergency management

Reading File
Reading File
Running Command

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

Running Command

mkdir -p /home/daytona/workspace/chiari2-quickref && echo "dir created"

Writing File

~/chiari2-quickref/generate_pdf.py

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

OUTPUT = "/home/daytona/workspace/chiari2-quickref/Neonatal_ChiariII_Quick_Reference.pdf"

# ─── Colour Palette ─────────────────────────────────────────────────────────
RED_ALERT   = HexColor("#C0392B")
RED_LIGHT   = HexColor("#FADBD8")
ORANGE      = HexColor("#E67E22")
ORANGE_LIGHT= HexColor("#FDEBD0")
YELLOW      = HexColor("#F1C40F")
YELLOW_LIGHT= HexColor("#FEF9E7")
TEAL        = HexColor("#1A7A8A")
TEAL_LIGHT  = HexColor("#D1ECF1")
NAVY        = HexColor("#1B2A4A")
NAVY_MID    = HexColor("#2C3E6B")
GREY_LIGHT  = HexColor("#F4F6F9")
GREY_MID    = HexColor("#BDC3C7")
WHITE       = colors.white
GREEN_DARK  = HexColor("#1E8449")
GREEN_LIGHT = HexColor("#D5F5E3")
PURPLE      = HexColor("#6C3483")
PURPLE_LIGHT= HexColor("#E8DAEF")

# ─── Document ────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    leftMargin=14*mm, rightMargin=14*mm,
    topMargin=12*mm, bottomMargin=12*mm
)

W, H = A4
content_width = W - 28*mm

story = []

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

sBase      = S("base",      fontName="Helvetica",       fontSize=8.5, leading=12, textColor=NAVY)
sSmall     = S("small",     fontName="Helvetica",       fontSize=7.5, leading=11, textColor=NAVY)
sBold      = S("bold",      fontName="Helvetica-Bold",  fontSize=8.5, leading=12, textColor=NAVY)
sTitle     = S("title",     fontName="Helvetica-Bold",  fontSize=18,  leading=22, textColor=WHITE, alignment=TA_CENTER)
sSubtitle  = S("subtitle",  fontName="Helvetica",       fontSize=10,  leading=14, textColor=WHITE, alignment=TA_CENTER)
sSectionH  = S("sectionH",  fontName="Helvetica-Bold",  fontSize=10,  leading=13, textColor=WHITE)
sRedHdr    = S("redHdr",    fontName="Helvetica-Bold",  fontSize=9.5, leading=12, textColor=WHITE)
sCellH     = S("cellH",     fontName="Helvetica-Bold",  fontSize=8,   leading=11, textColor=WHITE, alignment=TA_CENTER)
sCellB     = S("cellB",     fontName="Helvetica",       fontSize=8,   leading=11, textColor=NAVY)
sCellBold  = S("cellBold",  fontName="Helvetica-Bold",  fontSize=8,   leading=11, textColor=NAVY)
sCellRed   = S("cellRed",   fontName="Helvetica-Bold",  fontSize=8,   leading=11, textColor=RED_ALERT)
sFooter    = S("footer",    fontName="Helvetica-Oblique", fontSize=7, leading=10, textColor=GREY_MID, alignment=TA_CENTER)
sBullet    = S("bullet",    fontName="Helvetica",       fontSize=8.5, leading=12, textColor=NAVY, leftIndent=10, bulletIndent=0)
sNote      = S("note",      fontName="Helvetica-Oblique", fontSize=7.5, leading=11, textColor=TEAL)

# ─── Helper: section header bar ─────────────────────────────────────────────
def section_header(text, bg=NAVY_MID, text_style=None):
    if text_style is None:
        text_style = sSectionH
    tbl = Table([[Paragraph(text, text_style)]], colWidths=[content_width])
    tbl.setStyle(TableStyle([
        ("BACKGROUND",  (0,0), (-1,-1), bg),
        ("TOPPADDING",  (0,0), (-1,-1), 5),
        ("BOTTOMPADDING",(0,0),(-1,-1), 5),
        ("LEFTPADDING", (0,0), (-1,-1), 8),
        ("RIGHTPADDING",(0,0), (-1,-1), 8),
        ("ROUNDEDCORNERS", [3]),
    ]))
    return tbl

def red_header(text):
    return section_header(text, bg=RED_ALERT, text_style=sRedHdr)

def orange_header(text):
    return section_header(text, bg=ORANGE, text_style=sRedHdr)

def teal_header(text):
    return section_header(text, bg=TEAL, text_style=sSectionH)

def green_header(text):
    return section_header(text, bg=GREEN_DARK, text_style=sSectionH)

def purple_header(text):
    return section_header(text, bg=PURPLE, text_style=sSectionH)

# ─── 1. TITLE BANNER ─────────────────────────────────────────────────────────
title_tbl = Table([
    [Paragraph("NEONATAL CHIARI II MALFORMATION", sTitle)],
    [Paragraph("Warning Signs &amp; Emergency Management — Quick Reference Card", sSubtitle)],
    [Paragraph("For use in Neonatal Intensive Care Units &amp; Delivery Suites | Compiled from Barash's Clinical Anesthesia, Bradley &amp; Daroff's Neurology, Creasy &amp; Resnik's MFM", sSubtitle)],
], colWidths=[content_width])
title_tbl.setStyle(TableStyle([
    ("BACKGROUND",   (0,0), (-1,-1), NAVY),
    ("TOPPADDING",   (0,0), (-1,-1), 8),
    ("BOTTOMPADDING",(0,0), (-1,-1), 6),
    ("LEFTPADDING",  (0,0), (-1,-1), 10),
    ("RIGHTPADDING", (0,0), (-1,-1), 10),
    ("ROUNDEDCORNERS", [4]),
]))
story.append(title_tbl)
story.append(Spacer(1, 5*mm))

# ─── 2. DEFINITION BOX ───────────────────────────────────────────────────────
story.append(KeepTogether([
    teal_header("WHAT IS CHIARI II MALFORMATION?"),
    Spacer(1, 2),
    Table([[
        Paragraph(
            "<b>Chiari II</b> is a complex hindbrain anomaly that occurs in <b>virtually ALL infants</b> born with "
            "myelomeningocele (MMC). It results from the failure of adequate CSF accumulation in the developing "
            "posterior fossa — due to the open spinal defect acting as a CSF \"drain\" — leaving the posterior fossa "
            "too small to contain the growing cerebellum and brainstem. These structures are forced downward through "
            "the foramen magnum.",
            sBase)
    ]], colWidths=[content_width])
]))
story.append(Spacer(1, 1*mm))

# anatomy table
anatomy_data = [
    [Paragraph("ANATOMICAL FEATURE", sCellH), Paragraph("CHIARI II FINDING", sCellH)],
    [Paragraph("Cerebellar vermis", sCellBold), Paragraph("Herniated caudally through foramen magnum", sCellB)],
    [Paragraph("Medulla oblongata", sCellBold), Paragraph("Caudal displacement + kinking (\"medullary kink\")", sCellB)],
    [Paragraph("4th ventricle", sCellBold), Paragraph("Small or obliterated; compressed", sCellB)],
    [Paragraph("Cisterna magna", sCellBold), Paragraph("Absent / obliterated", sCellB)],
    [Paragraph("Posterior fossa", sCellBold), Paragraph("Small; unable to accommodate hindbrain contents", sCellB)],
    [Paragraph("Cerebral cortex", sCellBold), Paragraph("Polymicrogyria in some patients", sCellB)],
    [Paragraph("Brainstem", sCellBold), Paragraph("Cervical cord compression; abnormal function", sCellB)],
]
anatomy_tbl = Table(anatomy_data, colWidths=[60*mm, content_width - 60*mm])
anatomy_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  TEAL),
    ("BACKGROUND",    (0,1), (-1,1),  TEAL_LIGHT),
    ("BACKGROUND",    (0,2), (-1,2),  WHITE),
    ("BACKGROUND",    (0,3), (-1,3),  TEAL_LIGHT),
    ("BACKGROUND",    (0,4), (-1,4),  WHITE),
    ("BACKGROUND",    (0,5), (-1,5),  TEAL_LIGHT),
    ("BACKGROUND",    (0,6), (-1,6),  WHITE),
    ("BACKGROUND",    (0,7), (-1,7),  TEAL_LIGHT),
    ("GRID",          (0,0), (-1,-1), 0.4, GREY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(anatomy_tbl)
story.append(Spacer(1, 4*mm))

# ─── 3. WARNING SIGNS ────────────────────────────────────────────────────────
story.append(KeepTogether([
    red_header("SECTION 1 — WARNING SIGNS: RECOGNISE CHIARI II BRAINSTEM DYSFUNCTION"),
    Spacer(1, 2),
    Paragraph(
        "<b>Only ~20% of MMC infants show clinical brainstem symptoms</b> — but when present, mortality is 35%. "
        "Recognise these early.",
        sNote),
    Spacer(1, 2),
]))

signs_data = [
    [Paragraph("WARNING SIGN", sCellH), Paragraph("MECHANISM", sCellH), Paragraph("URGENCY", sCellH)],
    [Paragraph("<b>Apnea</b> (central, non-obstructive)", sCellB),
     Paragraph("Medullary respiratory centre compression", sCellB),
     Paragraph("CRITICAL", S("urg", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=RED_ALERT))],
    [Paragraph("<b>Bradycardia</b> (+ apnea = classic pair)", sCellB),
     Paragraph("Vagal nucleus compression in medulla", sCellB),
     Paragraph("CRITICAL", S("urg2", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=RED_ALERT))],
    [Paragraph("<b>Stridor</b> (high-pitched inspiratory)", sCellB),
     Paragraph("Vocal cord paresis — abductor weakness (RLN / nucleus ambiguus)", sCellB),
     Paragraph("HIGH", S("urg3", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=ORANGE))],
    [Paragraph("<b>Swallowing dysfunction / aspiration</b>", sCellB),
     Paragraph("CN IX, X, XII involvement; bulbar palsy", sCellB),
     Paragraph("HIGH", S("urg4", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=ORANGE))],
    [Paragraph("<b>Opisthotonos</b> (back-arching)", sCellB),
     Paragraph("Cervical cord or brainstem compression", sCellB),
     Paragraph("HIGH", S("urg5", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=ORANGE))],
    [Paragraph("<b>Upper limb spasticity / weakness</b>", sCellB),
     Paragraph("Corticospinal tract compression at foramen magnum", sCellB),
     Paragraph("MODERATE", S("urg6", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=YELLOW))],
    [Paragraph("<b>Poor feeding / weak suck</b>", sCellB),
     Paragraph("Brainstem feeding centre + hypoglossal dysfunction", sCellB),
     Paragraph("MODERATE", S("urg7", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=YELLOW))],
    [Paragraph("<b>Sleep-disordered breathing</b>", sCellB),
     Paragraph("Central + obstructive components; brainstem autonomic dysfunction", sCellB),
     Paragraph("MODERATE", S("urg8", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=YELLOW))],
    [Paragraph("<b>Nystagmus / abnormal eye movements</b>", sCellB),
     Paragraph("Cranial nerve nuclei (VI, VIII) or cerebellar dysfunction", sCellB),
     Paragraph("LOW-MOD", S("urg9", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=TEAL))],
    [Paragraph("<b>Increasing head circumference</b>", sCellB),
     Paragraph("Hydrocephalus secondary to impaired CSF flow through 4th ventricle", sCellB),
     Paragraph("HIGH", S("urg10", fontName="Helvetica-Bold", fontSize=8, leading=11, textColor=ORANGE))],
]
c_widths = [65*mm, content_width - 65*mm - 22*mm, 22*mm]
signs_tbl = Table(signs_data, colWidths=c_widths)
signs_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  RED_ALERT),
    ("BACKGROUND",    (0,1), (-1,2),  RED_LIGHT),
    ("BACKGROUND",    (0,3), (-1,5),  ORANGE_LIGHT),
    ("BACKGROUND",    (0,6), (-1,8),  YELLOW_LIGHT),
    ("BACKGROUND",    (0,9), (-1,9),  TEAL_LIGHT),
    ("BACKGROUND",    (0,10),(-1,10), ORANGE_LIGHT),
    ("GRID",          (0,0), (-1,-1), 0.4, GREY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
    ("ALIGN",         (2,0), (2,-1),  "CENTER"),
]))
story.append(signs_tbl)
story.append(Spacer(1, 4*mm))

# ─── 4. DIFFERENTIATING FROM SHUNT MALFUNCTION ───────────────────────────────
story.append(KeepTogether([
    orange_header("SECTION 2 — DIFFERENTIATING CHIARI II SYMPTOMS FROM SHUNT MALFUNCTION"),
    Spacer(1, 2),
    Paragraph(
        "Both Chiari II brainstem dysfunction and raised ICP from shunt failure can cause apnea, bradycardia, "
        "and altered tone. Distinguish them — management differs critically.",
        sNote),
    Spacer(1, 2),
]))

diff_data = [
    [Paragraph("FEATURE", sCellH), Paragraph("CHIARI II BRAINSTEM DYSFUNCTION", sCellH), Paragraph("SHUNT FAILURE / RAISED ICP", sCellH)],
    [Paragraph("Primary cause", sCellBold), Paragraph("Brainstem / CN compression at foramen magnum", sCellB), Paragraph("VP shunt blockage / malfunction", sCellB)],
    [Paragraph("Apnea pattern", sCellBold), Paragraph("Central; may be positional (worse supine)", sCellB), Paragraph("Central; associated with bradycardia", sCellB)],
    [Paragraph("Stridor", sCellBold), Paragraph("<b>YES</b> — vocal cord paresis; inspiratory", sCellB), Paragraph("Uncommon", sCellB)],
    [Paragraph("Fontanelle", sCellBold), Paragraph("Variable; may be normal", sCellB), Paragraph("<b>Tense / bulging</b>", sCellB)],
    [Paragraph("Head circumference", sCellBold), Paragraph("Variable", sCellB), Paragraph("<b>Accelerated growth</b>", sCellB)],
    [Paragraph("Sunset sign", sCellBold), Paragraph("Uncommon", sCellB), Paragraph("<b>Present</b>", sCellB)],
    [Paragraph("Response to shunting", sCellBold), Paragraph("Partial (shunt first; PFD if no improvement)", sCellB), Paragraph("<b>Full improvement expected</b>", sCellB)],
    [Paragraph("Cranial ultrasound", sCellBold), Paragraph("May be normal or mild ventriculomegaly", sCellB), Paragraph("<b>Enlarged ventricles</b>", sCellB)],
    [Paragraph("Definitive imaging", sCellBold), Paragraph("MRI brain/posterior fossa + spinal cord", sCellB), Paragraph("Head US or CT; shunt series X-ray", sCellB)],
    [Paragraph("Urgent intervention", sCellBold), Paragraph("Posterior fossa decompression (if shunt fails)", sCellB), Paragraph("Shunt revision / tap", sCellB)],
]
diff_tbl = Table(diff_data, colWidths=[38*mm, (content_width-38*mm)/2, (content_width-38*mm)/2])
diff_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  ORANGE),
    ("BACKGROUND",    (0,1), (-1,1),  ORANGE_LIGHT),
    ("BACKGROUND",    (0,2), (-1,2),  WHITE),
    ("BACKGROUND",    (0,3), (-1,3),  ORANGE_LIGHT),
    ("BACKGROUND",    (0,4), (-1,4),  WHITE),
    ("BACKGROUND",    (0,5), (-1,5),  ORANGE_LIGHT),
    ("BACKGROUND",    (0,6), (-1,6),  WHITE),
    ("BACKGROUND",    (0,7), (-1,7),  ORANGE_LIGHT),
    ("BACKGROUND",    (0,8), (-1,8),  WHITE),
    ("BACKGROUND",    (0,9), (-1,9),  ORANGE_LIGHT),
    ("BACKGROUND",    (0,10),(-1,10), WHITE),
    ("GRID",          (0,0), (-1,-1), 0.4, GREY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(diff_tbl)
story.append(Spacer(1, 4*mm))

# ─── 5. EMERGENCY MANAGEMENT ALGORITHM ───────────────────────────────────────
story.append(KeepTogether([
    red_header("SECTION 3 — EMERGENCY MANAGEMENT ALGORITHM"),
    Spacer(1, 2),
]))

# Step boxes as a vertical flow
steps = [
    ("STEP 1 — CALL FOR HELP", RED_ALERT,
     "Activate neonatal emergency. Call Neurosurgery STAT. Ensure Anesthesia is available. "
     "Assign roles: Airway lead | IV/drugs | Documentation."),
    ("STEP 2 — SECURE AIRWAY &amp; BREATHING", ORANGE,
     "If apnea/stridor: Jaw thrust first. Avoid neck extension — can worsen foramen magnum compression. "
     "Intubate (RSI preferred; awake if compromised). Bag-mask ventilation with neutral/slight flexion. "
     "Avoid succinylcholine if hyperkalemia risk (>48h post-placode exposure)."),
    ("STEP 3 — CIRCULATION &amp; ACCESS", TEAL,
     "IV/IO access x2. Attach continuous ECG, SpO2, BP. Treat bradycardia (atropine 0.02 mg/kg IV if symptomatic). "
     "Maintain MAP appropriate for gestational age."),
    ("STEP 4 — NEUROIMAGING (URGENT)", NAVY_MID,
     "Cranial ultrasound at bedside FIRST (rapid, no radiation). Look for: ventricular size, midline shift. "
     "Head CT if US unavailable or inconclusive. "
     "MRI brain + posterior fossa + full spine when stable — definitive assessment of Chiari II anatomy."),
    ("STEP 5 — TREAT HYDROCEPHALUS FIRST", TEAL,
     "If ventricles enlarged / shunt present: Urgent shunt tap (neurosurgery). "
     "If no shunt yet: emergent VP shunt placement. "
     "80-90% of MMC infants have hydrocephalus. Relieving it may fully resolve brainstem symptoms."),
    ("STEP 6 — IF NO IMPROVEMENT AFTER SHUNTING", RED_ALERT,
     "Persistent apnea / stridor / opisthotonos despite patent shunt = TRUE Chiari II brainstem dysfunction. "
     "Neurosurgical consultation for POSTERIOR FOSSA DECOMPRESSION (suboccipital craniectomy + C1 laminectomy). "
     "This is a surgical emergency."),
    ("STEP 7 — SUPPORTIVE NICU CARE", GREEN_DARK,
     "Prone / 30 degree head-up positioning. Latex-free environment (high IgE sensitization in MMC). "
     "NG feeds if swallowing unsafe. Respiratory support as needed. "
     "Commence clean intermittent catheterization (neurogenic bladder). "
     "Monitor daily head circumference. Serial cranial US every 24-48h."),
]

for title, bg, body in steps:
    step_tbl = Table([
        [Paragraph(title, sRedHdr)],
        [Paragraph(body, sBase)],
    ], colWidths=[content_width])
    step_tbl.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,0), bg),
        ("BACKGROUND",    (0,1), (-1,1), GREY_LIGHT),
        ("TOPPADDING",    (0,0), (-1,-1), 5),
        ("BOTTOMPADDING", (0,0), (-1,-1), 5),
        ("LEFTPADDING",   (0,0), (-1,-1), 8),
        ("RIGHTPADDING",  (0,0), (-1,-1), 8),
        ("BOX",           (0,0), (-1,-1), 0.5, GREY_MID),
    ]))
    story.append(step_tbl)
    story.append(Spacer(1, 1.5*mm))

story.append(Spacer(1, 3*mm))

# ─── 6. DRUGS ────────────────────────────────────────────────────────────────
story.append(KeepTogether([
    purple_header("SECTION 4 — EMERGENCY DRUG REFERENCE (NEONATE)"),
    Spacer(1, 2),
]))

drug_data = [
    [Paragraph("DRUG", sCellH), Paragraph("DOSE", sCellH), Paragraph("ROUTE", sCellH), Paragraph("INDICATION", sCellH)],
    [Paragraph("Atropine", sCellBold), Paragraph("0.02 mg/kg (min 0.1 mg)", sCellB), Paragraph("IV / IO", sCellB), Paragraph("Symptomatic bradycardia", sCellB)],
    [Paragraph("Epinephrine", sCellBold), Paragraph("0.01 mg/kg (1:10,000)", sCellB), Paragraph("IV / IO / ETT", sCellB), Paragraph("Cardiac arrest / severe bradycardia", sCellB)],
    [Paragraph("Fentanyl (RSI)", sCellBold), Paragraph("1-4 mcg/kg", sCellB), Paragraph("IV slow", sCellB), Paragraph("Analgesia/sedation for intubation", sCellB)],
    [Paragraph("Ketamine (RSI)", sCellBold), Paragraph("1-2 mg/kg", sCellB), Paragraph("IV", sCellB), Paragraph("Induction (haemodynamically stable)", sCellB)],
    [Paragraph("Rocuronium", sCellBold), Paragraph("1 mg/kg", sCellB), Paragraph("IV", sCellB), Paragraph("Neuromuscular blockade for intubation", sCellB)],
    [Paragraph("Morphine", sCellBold), Paragraph("0.05-0.1 mg/kg", sCellB), Paragraph("IV slow", sCellB), Paragraph("Post-intubation sedation/analgesia", sCellB)],
    [Paragraph("Midazolam", sCellBold), Paragraph("0.05-0.1 mg/kg", sCellB), Paragraph("IV", sCellB), Paragraph("Sedation (use cautiously; respiratory depression)", sCellB)],
    [Paragraph("Mannitol", sCellBold), Paragraph("0.5-1 g/kg over 20 min", sCellB), Paragraph("IV", sCellB), Paragraph("Acute ICP crisis (rare in neonate)", sCellB)],
    [Paragraph("Ampicillin", sCellBold), Paragraph("50 mg/kg q12h (term)", sCellB), Paragraph("IV", sCellB), Paragraph("Meningitis prophylaxis/treatment", sCellB)],
    [Paragraph("Gentamicin", sCellBold), Paragraph("4-5 mg/kg q24h", sCellB), Paragraph("IV", sCellB), Paragraph("Cover gram-negative organisms (meningitis)", sCellB)],
]
col_w = [35*mm, 42*mm, 20*mm, content_width - 35*mm - 42*mm - 20*mm]
drug_tbl = Table(drug_data, colWidths=col_w)
drug_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  PURPLE),
    ("ROWBACKGROUNDS",(0,1), (-1,-1), [GREY_LIGHT, WHITE]),
    ("GRID",          (0,0), (-1,-1), 0.4, GREY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(drug_tbl)
story.append(Spacer(1, 2*mm))
story.append(Paragraph(
    "* All doses are approximate guidelines. Always verify with your institution's formulary and adjust for gestational age, postnatal age, and renal function.",
    sNote))
story.append(Spacer(1, 4*mm))

# ─── 7. MONITORING ───────────────────────────────────────────────────────────
story.append(KeepTogether([
    teal_header("SECTION 5 — ONGOING MONITORING IN THE NICU"),
    Spacer(1, 2),
]))

monitor_left = [
    [Paragraph("PARAMETER", sCellH), Paragraph("FREQUENCY", sCellH)],
    [Paragraph("Head circumference", sCellBold), Paragraph("Daily", sCellB)],
    [Paragraph("Cranial ultrasound", sCellBold), Paragraph("Every 24-48h (or per neurosurgery)", sCellB)],
    [Paragraph("Fontanelle assessment", sCellBold), Paragraph("At every nursing assessment", sCellB)],
    [Paragraph("Respiratory pattern", sCellBold), Paragraph("Continuous monitoring + apnea monitor", sCellB)],
    [Paragraph("Heart rate (bradycardia)", sCellBold), Paragraph("Continuous ECG monitoring", sCellB)],
    [Paragraph("SpO2", sCellBold), Paragraph("Continuous", sCellB)],
    [Paragraph("Neurological exam", sCellBold), Paragraph("Minimum twice daily", sCellB)],
    [Paragraph("Urine output / CIC", sCellBold), Paragraph("Every 4-6 hours; document each void", sCellB)],
    [Paragraph("Wound site (placode)", sCellBold), Paragraph("Each dressing change q4-6h", sCellB)],
    [Paragraph("Temperature", sCellBold), Paragraph("Continuous rectal / axillary", sCellB)],
    [Paragraph("Blood cultures / CBC / CRP", sCellBold), Paragraph("If infection suspected; 48h post-op", sCellB)],
]
monitor_tbl = Table(monitor_left, colWidths=[60*mm, content_width - 60*mm])
monitor_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  TEAL),
    ("ROWBACKGROUNDS",(0,1), (-1,-1), [TEAL_LIGHT, WHITE]),
    ("GRID",          (0,0), (-1,-1), 0.4, GREY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(monitor_tbl)
story.append(Spacer(1, 4*mm))

# ─── 8. SURGICAL OPTIONS ─────────────────────────────────────────────────────
story.append(KeepTogether([
    green_header("SECTION 6 — SURGICAL OPTIONS AT A GLANCE"),
    Spacer(1, 2),
]))

surg_data = [
    [Paragraph("PROCEDURE", sCellH), Paragraph("TIMING", sCellH), Paragraph("INDICATION", sCellH), Paragraph("NOTE", sCellH)],
    [Paragraph("MMC closure", sCellBold),
     Paragraph("Within 24-48h of birth", sCellB),
     Paragraph("All open MMC defects", sCellB),
     Paragraph("Latex-free field; primary closure vs. flap", sCellB)],
    [Paragraph("VP Shunt", sCellBold),
     Paragraph("With closure or when symptomatic", sCellB),
     Paragraph("Hydrocephalus (80-90% of MMC)", sCellB),
     Paragraph("50% will have shunt complication in year 1", sCellB)],
    [Paragraph("ETV + CPC", sCellBold),
     Paragraph("Elective; after stabilisation", sCellB),
     Paragraph("Alternative to VP shunt; avoids hardware", sCellB),
     Paragraph(">70% success rate; similar neuro outcomes", sCellB)],
    [Paragraph("Posterior Fossa Decompression", sCellBold),
     Paragraph("URGENT — when symptomatic Chiari II persists after shunting", sCellB),
     Paragraph("Stridor, apnea, opisthotonos not improved by shunting", sCellB),
     Paragraph("Suboccipital craniectomy + C1 laminectomy", sCellB)],
    [Paragraph("Prenatal MMC repair", sCellBold),
     Paragraph("19-26 weeks gestation", sCellB),
     Paragraph("Planned fetal intervention (MOMS criteria)", sCellB),
     Paragraph("Shunt rate 40% vs 82% postnatal (MOMS trial)", sCellB)],
]
surg_tbl = Table(surg_data, colWidths=[33*mm, 38*mm, 50*mm, content_width - 33*mm - 38*mm - 50*mm])
surg_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0),  GREEN_DARK),
    ("ROWBACKGROUNDS",(0,1), (-1,-1), [GREEN_LIGHT, WHITE]),
    ("GRID",          (0,0), (-1,-1), 0.4, GREY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(surg_tbl)
story.append(Spacer(1, 4*mm))

# ─── 9. KEY STATISTICS BOX ────────────────────────────────────────────────────
story.append(KeepTogether([
    section_header("KEY STATISTICS TO KNOW", bg=NAVY_MID),
    Spacer(1, 2),
]))

stats = [
    ("~100%", "of MMC infants have Chiari II malformation (anatomy)"),
    ("~20%",  "of MMC infants develop SYMPTOMATIC brainstem dysfunction"),
    ("35%",   "mortality among symptomatic Chiari II patients"),
    ("80-90%","of MMC infants require treatment for hydrocephalus"),
    ("50%",   "of infants have shunt complication within the first year of life"),
    ("40% vs 82%", "shunt placement rate: prenatal vs. postnatal MMC repair (MOMS)"),
    ("35%",   "mean GA at delivery in prenatal repair group (vs 37+ weeks postnatal)"),
    (">70%",  "of long-term MMC survivors have IQ >80"),
]

stat_rows = []
for i in range(0, len(stats), 2):
    row = []
    for j in range(2):
        if i+j < len(stats):
            num, txt = stats[i+j]
            cell_content = Paragraph(
                f'<font color="#{TEAL.hexval()[2:]}" size="13"><b>{num}</b></font>  '
                f'<font size="8">{txt}</font>', sBase)
            row.append(cell_content)
        else:
            row.append(Paragraph("", sBase))
    stat_rows.append(row)

stats_tbl = Table(stat_rows, colWidths=[content_width/2 - 1*mm, content_width/2 - 1*mm], hAlign='CENTER')
stats_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), GREY_LIGHT),
    ("GRID",          (0,0), (-1,-1), 0.4, GREY_MID),
    ("TOPPADDING",    (0,0), (-1,-1), 6),
    ("BOTTOMPADDING", (0,0), (-1,-1), 6),
    ("LEFTPADDING",   (0,0), (-1,-1), 10),
    ("RIGHTPADDING",  (0,0), (-1,-1), 10),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(stats_tbl)
story.append(Spacer(1, 4*mm))

# ─── 10. LATEX WARNING BOX ───────────────────────────────────────────────────
latex_tbl = Table([[
    Paragraph(
        "<b>LATEX ALLERGY WARNING:</b> All MMC patients have high risk of IgE-mediated latex sensitization "
        "due to repeated mucosal exposures. Use <b>LATEX-FREE</b> gloves, IV lines, airways, and all equipment "
        "from birth onward. Failure to do so risks life-threatening anaphylaxis intraoperatively.",
        S("latexNote", fontName="Helvetica", fontSize=8.5, leading=12, textColor=NAVY))
]], colWidths=[content_width])
latex_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), YELLOW_LIGHT),
    ("BOX",           (0,0), (-1,-1), 1.5, YELLOW),
    ("TOPPADDING",    (0,0), (-1,-1), 6),
    ("BOTTOMPADDING", (0,0), (-1,-1), 6),
    ("LEFTPADDING",   (0,0), (-1,-1), 10),
    ("RIGHTPADDING",  (0,0), (-1,-1), 10),
]))
story.append(latex_tbl)
story.append(Spacer(1, 4*mm))

# ─── FOOTER ──────────────────────────────────────────────────────────────────
story.append(HRFlowable(width="100%", thickness=0.5, color=GREY_MID))
story.append(Spacer(1, 1*mm))
story.append(Paragraph(
    "Sources: Barash's Clinical Anesthesia 9e | Bradley &amp; Daroff's Neurology in Clinical Practice | "
    "Creasy &amp; Resnik's Maternal-Fetal Medicine | Campbell Walsh Wein Urology | "
    "Campbell's Operative Orthopaedics 15e | MOMS Trial (PMID: 21306277) | "
    "Kunpalin et al. meta-analysis 2025 (PMID: 40492626)  |  Generated by Orris AI — July 2026  |  "
    "For educational purposes only. Always apply clinical judgement and local protocols.",
    sFooter))

# ─── BUILD ────────────────────────────────────────────────────────────────────
doc.build(story)
print(f"PDF saved to: {OUTPUT}")
Running Command

cd /home/daytona/workspace/chiari2-quickref && python generate_pdf.py 2>&1

Running Command

ls -lh /home/daytona/workspace/chiari2-quickref/Neonatal_ChiariII_Quick_Referenc…

Your quick reference PDF is ready! Here's what's inside:

Neonatal ChiariII Quick Reference

PDF Document · PDF


The PDF contains 6 color-coded sections:
SectionContent
What is Chiari II?Anatomy table — all 7 structural features and their abnormal findings
Warning Signs10 clinical signs with urgency level (CRITICAL / HIGH / MODERATE) color-coded red-orange-yellow
Chiari II vs Shunt FailureSide-by-side differential diagnosis table — critical for deciding your next intervention
Emergency Management7-step algorithm: Call for help → Airway → Circulation → Imaging → Shunt → PFD → NICU care
Drug Reference11 emergency drugs with neonatal doses, routes, and indications
Monitoring12 parameters with frequencies; Surgical options with timing and indications; Key statistics box
The card closes with a latex allergy warning banner and a footer citing all sources (Barash, Bradley & Daroff, Creasy & Resnik, MOMS Trial, 2025 meta-analysis PMID 40492626).
This is a shared conversation. Sign in to Orris to start your own chat.