Diagram of brain blood supply

Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Loading Image
Loading Image
Loading Image
Reading File
Loading Image
Here are the diagrams of brain blood supply from authoritative medical textbooks:

Brain Blood Supply

1. Arterial Supply - Full Diagram (Aortic Arch to Circle of Willis)

Arterial supply to the brain from aortic arch to circle of Willis
Gray's Anatomy for Students - Fig. 8.39: Arterial Supply to the Brain, showing the full pathway from the aortic arch (with MR angiogram)

2. Ventral (Base) View - Circle of Willis

Ventral view of brain arterial system showing circle of Willis
Neuroscience: Exploring the Brain - Ventral view showing the Circle of Willis, basilar artery, and all major cerebral arteries

3. Lateral View - Cortical Supply

Lateral view of brain showing middle and anterior cerebral arteries
Neuroscience: Exploring the Brain - Lateral view: the middle cerebral artery (MCA) dominates the lateral cortical surface

4. Medial View - Cortical Supply

Medial view of brain showing anterior and posterior cerebral arteries
Neuroscience: Exploring the Brain - Medial view (brainstem removed): anterior cerebral artery supplies most of the medial wall; posterior cerebral artery supplies the occipital lobe and inferior temporal lobe

Key Points

Two pairs of source vessels:
  • Vertebral arteries - arise from subclavian arteries, enter skull via foramen magnum, fuse below the pons to form the basilar artery
  • Internal carotid arteries - arise from common carotids, enter via carotid canals
Circle of Willis (cerebral arterial circle) connects both systems via:
  • Anterior communicating artery (connects the two anterior cerebral arteries)
  • Posterior communicating arteries (connect internal carotids to posterior cerebral arteries)
Three main cortical territories:
ArteryTerritory
Anterior cerebral artery (ACA)Medial frontal and parietal cortex
Middle cerebral artery (MCA)Lateral hemispheric surface, deep basal structures
Posterior cerebral artery (PCA)Occipital lobe, inferior temporal lobe
Posterior fossa (brainstem/cerebellum):
  • Superior cerebellar artery (SCA)
  • Anterior inferior cerebellar artery (AICA)
  • Posterior inferior cerebellar artery (PICA) - from vertebral artery
Sources: Gray's Anatomy for Students, p. 1016-1018; Neuroscience: Exploring the Brain, 5th ed., pp. 705-708

Create a reference PDF summarizing arterial territories and stroke patterns

Reading File
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
Finding Sources
Loading Image
Loading Image
Running Command

mkdir -p /home/daytona/workspace/brain-blood-supply && ls /home/daytona/workspac…

Writing File

~/brain-blood-supply/build_pdf.py

#!/usr/bin/env python3
"""Build a reference PDF: Cerebral Arterial Territories & Stroke Syndromes."""

import urllib.request
import io
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.units import mm, cm
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle,
    HRFlowable, Image, PageBreak, KeepTogether
)
from reportlab.platypus.flowables import BalancedColumns
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

OUTPUT = "/home/daytona/workspace/brain-blood-supply/Cerebral_Arterial_Territories_Stroke_Reference.pdf"

# ── Colours ──────────────────────────────────────────────────────────────────
NAVY      = colors.HexColor("#1B3A5C")
TEAL      = colors.HexColor("#1D7874")
AMBER     = colors.HexColor("#E8A838")
LIGHT_BG  = colors.HexColor("#F4F7FB")
MID_GREY  = colors.HexColor("#6B7280")
TABLE_HDR = colors.HexColor("#1B3A5C")
TABLE_ALT = colors.HexColor("#EEF2F7")
RED_LITE  = colors.HexColor("#FDECEA")
GREEN_LITE= colors.HexColor("#E8F5E9")
GOLD_LITE = colors.HexColor("#FFF8E1")
BLUE_LITE = colors.HexColor("#E3F2FD")
PURPLE_LITE = colors.HexColor("#F3E5F5")

# ── Styles ────────────────────────────────────────────────────────────────────
styles = getSampleStyleSheet()
W, H = A4

def s(name, **kw):
    base = styles[name]
    return ParagraphStyle(name + str(id(kw)), parent=base, **kw)

TITLE   = s("Title",   fontSize=22, textColor=NAVY, spaceAfter=2, leading=28, alignment=TA_CENTER)
SUBTITLE= s("Normal",  fontSize=11, textColor=MID_GREY, alignment=TA_CENTER, spaceAfter=6)
H1      = s("Heading1",fontSize=14, textColor=colors.white, spaceBefore=14, spaceAfter=4, leading=18)
H2      = s("Heading2",fontSize=11, textColor=NAVY, spaceBefore=8, spaceAfter=3, leading=15)
BODY    = s("Normal",  fontSize=8.5, leading=13, spaceAfter=3, alignment=TA_JUSTIFY, textColor=colors.HexColor("#2D2D2D"))
SMALL   = s("Normal",  fontSize=7.5, leading=11, textColor=MID_GREY, spaceAfter=2)
BOLD_B  = s("Normal",  fontSize=8.5, leading=13, textColor=NAVY)
CAPTION = s("Normal",  fontSize=7, leading=10, textColor=MID_GREY, alignment=TA_CENTER, spaceAfter=4)
BULLET  = s("Normal",  fontSize=8.5, leading=13, leftIndent=10, bulletIndent=2, spaceAfter=2)

def heading_block(text, color=NAVY):
    """Returns a coloured heading bar + paragraph."""
    bar_data = [[Paragraph(f"<b>{text}</b>", ParagraphStyle(
        "hb", fontSize=11, textColor=colors.white, leading=16, leftPadding=8
    ))]]
    t = Table(bar_data, colWidths=[W - 4*cm])
    t.setStyle(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),
        ("RIGHTPADDING",(0,0), (-1,-1), 6),
        ("ROUNDEDCORNERS",[3]),
    ]))
    return t

def fetch_image(url, width, height):
    try:
        req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
        data = urllib.request.urlopen(req, timeout=15).read()
        return Image(io.BytesIO(data), width=width, height=height)
    except Exception as e:
        return Paragraph(f"[Image unavailable: {e}]", SMALL)

def pill(text, bg):
    t = Table([[Paragraph(f"<b>{text}</b>",
                ParagraphStyle("p", fontSize=7.5, textColor=colors.white, leading=10))]],
              colWidths=[3.2*cm])
    t.setStyle(TableStyle([
        ("BACKGROUND",(0,0),(-1,-1),bg),
        ("TOPPADDING",(0,0),(-1,-1),2),("BOTTOMPADDING",(0,0),(-1,-1),2),
        ("LEFTPADDING",(0,0),(-1,-1),5),("RIGHTPADDING",(0,0),(-1,-1),5),
        ("ROUNDEDCORNERS",[3]),
    ]))
    return t

# ── Image URLs ────────────────────────────────────────────────────────────────
IMG_CIRCLE_WILLIS    = "https://cdn.orris.care/cdss_images/062d6d419b01c08162d61f1670dd0f442e299f547de10838083d13a7caa3b44e.png"
IMG_LATERAL          = "https://cdn.orris.care/cdss_images/491a9182d0db80a9be557c08a727fd0da224f47308203d570a1eb32abac1ab1d.png"
IMG_MEDIAL           = "https://cdn.orris.care/cdss_images/34dc33a560dd7e3ff6ab0d0a384a5031b2495e4d5ab7ffd8e12c062edbdeb192.png"
IMG_FULL_SUPPLY      = "https://cdn.orris.care/cdss_images/ece0d9ff464cc985f3694cd22833142ca65edbd0afc88e6dd2cd43bfcde20b6a.png"
IMG_MCA_TERRITORY    = "https://cdn.orris.care/cdss_images/0b29a18cb1b7e2c305a202d3bdfb98edfc048ab07ce4128de3559f6663e70ec4.png"
IMG_CORONAL          = "https://cdn.orris.care/cdss_images/2efef24640944bfdceb58a27d1bb886c32a010ff66786b94753248c4e1fcd35c.png"

# ── Document ──────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    leftMargin=2*cm, rightMargin=2*cm,
    topMargin=2.2*cm, bottomMargin=2.2*cm,
    title="Cerebral Arterial Territories & Stroke Syndromes",
    author="Orris Medical Reference",
    subject="Neurology — Stroke",
)

story = []

# ─── COVER ────────────────────────────────────────────────────────────────────
story.append(Spacer(1, 1.5*cm))

# Title box
title_data = [[
    Paragraph("Cerebral Arterial Territories", TITLE),
    Paragraph("& Stroke Syndromes", TITLE),
    Spacer(1, 4),
    Paragraph("A Clinical Reference Guide", SUBTITLE),
    Spacer(1, 6),
    Paragraph("Sources: Adams &amp; Victor's Principles of Neurology 12e &bull; Goldman-Cecil Medicine &bull;"
              " Gray's Anatomy for Students &bull; Neuroscience: Exploring the Brain 5e",
              SMALL),
]]
t_cover = Table([title_data[0]], colWidths=[W - 4*cm])
t_cover.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,-1), LIGHT_BG),
    ("BOX",(0,0),(-1,-1),1.5,NAVY),
    ("TOPPADDING",(0,0),(-1,-1),18),("BOTTOMPADDING",(0,0),(-1,-1),18),
    ("LEFTPADDING",(0,0),(-1,-1),18),("RIGHTPADDING",(0,0),(-1,-1),18),
    ("ALIGN",(0,0),(-1,-1),"CENTER"),
]))
story.append(t_cover)
story.append(Spacer(1, 0.6*cm))

# Cover image – Circle of Willis base view
img_cov = fetch_image(IMG_CIRCLE_WILLIS, 11*cm, 8.5*cm)
story.append(Table([[img_cov]], colWidths=[W-4*cm],
    style=[("ALIGN",(0,0),(-1,-1),"CENTER"),
           ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0)]))
story.append(Paragraph("Ventral view of the brain showing the Circle of Willis and major cerebral arteries<br/>"
                        "<i>Neuroscience: Exploring the Brain, 5th ed.</i>", CAPTION))

story.append(PageBreak())

# ─── SECTION 1: Overview ──────────────────────────────────────────────────────
story.append(heading_block("1.  Overview of Brain Arterial Supply", NAVY))
story.append(Spacer(1, 4))

story.append(Paragraph(
    "The brain receives blood from <b>two pairs of arteries</b> that are interconnected at the base "
    "of the brain via the <b>Circle of Willis (cerebral arterial circle)</b>:",
    BODY))

story.append(Spacer(1, 4))

src_data = [
    ["Source Vessel", "Route to Brain", "Main Branches"],
    ["Internal carotid arteries (ICA)",
     "Common carotid → ICA → carotid canal",
     "ACA, MCA, ophthalmic, anterior choroidal, posterior communicating"],
    ["Vertebral arteries",
     "Subclavian → foramen transversaria C1–C6 → foramen magnum",
     "PICA, anterior spinal, posterior spinal → basilar → AICA, SCA, PCA"],
]
t_src = Table(src_data, colWidths=[4.2*cm, 5.5*cm, 7.3*cm])
t_src.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), TABLE_HDR),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),
    ("LEADING",(0,0),(-1,-1), 11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, TABLE_ALT]),
    ("GRID",(0,0),(-1,-1), 0.4, colors.HexColor("#BBCCE0")),
    ("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5),
    ("LEFTPADDING",(0,0),(-1,-1),6),("RIGHTPADDING",(0,0),(-1,-1),6),
    ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(t_src)
story.append(Spacer(1, 6))

# Full supply diagram
img_full = fetch_image(IMG_FULL_SUPPLY, 9*cm, 13*cm)
img_coronal = fetch_image(IMG_CORONAL, 7.5*cm, 8*cm)
side_by_side = Table([[img_full, img_coronal]], colWidths=[9.2*cm, 7.8*cm])
side_by_side.setStyle(TableStyle([
    ("ALIGN",(0,0),(-1,-1),"CENTER"),("VALIGN",(0,0),(-1,-1),"TOP"),
    ("TOPPADDING",(0,0),(-1,-1),2),("BOTTOMPADDING",(0,0),(-1,-1),2),
]))
story.append(side_by_side)
story.append(Table([[
    Paragraph("<i>Fig 1. Full arterial supply — aortic arch to Circle of Willis<br/>(Gray's Anatomy for Students)</i>", CAPTION),
    Paragraph("<i>Fig 2. Coronal section showing deep arterial territories<br/>(Adams &amp; Victor's Neurology 12e)</i>", CAPTION),
]], colWidths=[9.2*cm, 7.8*cm]))

story.append(Spacer(1, 8))

# Circle of Willis box
cow_items = [
    "<b>Anterior communicating artery (ACoA)</b> — connects the two ACAs",
    "<b>Anterior cerebral arteries (ACA)</b> — A1 segments from ICA bifurcation",
    "<b>Internal carotid arteries (ICA)</b> — lateral limbs of the circle",
    "<b>Posterior communicating arteries (PCoA)</b> — ICA to PCA",
    "<b>Posterior cerebral arteries (PCA)</b> — terminal basilar bifurcation",
]
story.append(Table([[
    Paragraph("<b>Circle of Willis Components</b>", H2),
    *[Paragraph(f"• {i}", BULLET) for i in cow_items],
]], colWidths=[W-4*cm],
    style=[("BACKGROUND",(0,0),(-1,-1), BLUE_LITE),
           ("BOX",(0,0),(-1,-1),0.8,TEAL),
           ("LEFTPADDING",(0,0),(-1,-1),10),("RIGHTPADDING",(0,0),(-1,-1),10),
           ("TOPPADDING",(0,0),(-1,-1),8),("BOTTOMPADDING",(0,0),(-1,-1),8)]))

story.append(PageBreak())

# ─── SECTION 2: Cortical Territories ─────────────────────────────────────────
story.append(heading_block("2.  Cortical Arterial Territories", TEAL))
story.append(Spacer(1, 6))

img_lat = fetch_image(IMG_LATERAL, 8*cm, 6.5*cm)
img_med = fetch_image(IMG_MEDIAL,  8*cm, 6.5*cm)
story.append(Table([[img_lat, img_med]], colWidths=[8.3*cm, 8.7*cm]))
story.append(Table([[
    Paragraph("<i>Fig 3. Lateral cortical supply — MCA dominant<br/>(Neuroscience: Exploring the Brain 5e)</i>", CAPTION),
    Paragraph("<i>Fig 4. Medial surface — ACA &amp; PCA territories<br/>(Neuroscience: Exploring the Brain 5e)</i>", CAPTION),
]], colWidths=[8.3*cm, 8.7*cm]))

story.append(Spacer(1, 6))

# MCA territory map image
img_mca = fetch_image(IMG_MCA_TERRITORY, 14*cm, 9*cm)
story.append(Table([[img_mca]], colWidths=[W-4*cm],
    style=[("ALIGN",(0,0),(-1,-1),"CENTER")]))
story.append(Paragraph(
    "<i>Fig 5. Left hemisphere lateral aspect — MCA branches, functional areas, and language cortex<br/>"
    "(Adams &amp; Victor's Principles of Neurology 12e, Fig. 33-5)</i>", CAPTION))

story.append(Spacer(1, 8))

# Territory summary table
terr_data = [
    ["Artery", "Cortical Territory", "Deep Structures"],
    ["Anterior cerebral\n(ACA)",
     "Medial frontal lobe, medial parietal lobe, cingulate gyrus, supplementary motor area, paracentral lobule",
     "Head of caudate (via Heubner a.), anterior limb internal capsule"],
    ["Middle cerebral\n(MCA)",
     "Lateral frontal (motor/premotor, Broca), lateral parietal (somatosensory, angular/supramarginal gyri), lateral temporal (Wernicke), insula",
     "Putamen, body of caudate, outer globus pallidus, posterior limb internal capsule, corona radiata (via lenticulostriate aa.)"],
    ["Posterior cerebral\n(PCA)",
     "Occipital lobe (visual cortex), medial temporal lobe (hippocampus, parahippocampal gyrus), inferior temporal lobe, splenium CC",
     "Thalamus, midbrain, subthalamic nucleus (via posterior thalamoperforators)"],
    ["Anterior choroidal\n(AChA)",
     "Small cortical territory (uncus, hippocampus, parahippocampal)",
     "Posterior limb internal capsule (lower 2/3), globus pallidus, amygdala, anterior hippocampus"],
]
t_terr = Table(terr_data, colWidths=[3.2*cm, 8*cm, 5.8*cm])
t_terr.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), TEAL),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),
    ("LEADING",(0,0),(-1,-1), 11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, TABLE_ALT]),
    ("GRID",(0,0),(-1,-1), 0.4, colors.HexColor("#BBCCE0")),
    ("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5),
    ("LEFTPADDING",(0,0),(-1,-1),6),("RIGHTPADDING",(0,0),(-1,-1),6),
    ("VALIGN",(0,0),(-1,-1),"TOP"),
]))
story.append(t_terr)

story.append(PageBreak())

# ─── SECTION 3: Stroke Syndromes ─────────────────────────────────────────────
story.append(heading_block("3.  Stroke Syndromes by Occluded Artery", colors.HexColor("#7B2D8B")))
story.append(Spacer(1, 6))

story.append(Paragraph(
    "Neurologic deficits depend on the vascular territory involved. Embolic strokes typically have "
    "<b>maximal deficit at onset</b>; atherothrombotic strokes may be more <b>gradual or stuttering</b>. "
    "TIAs produce transient deficits in the same distribution without permanent tissue injury.",
    BODY))
story.append(Spacer(1, 8))

# ── ICA ─────────────────────────────────────────────────
story.append(Table([[
    Paragraph("Internal Carotid Artery (ICA) Occlusion", H2),
]], colWidths=[W-4*cm],
    style=[("BACKGROUND",(0,0),(-1,-1), RED_LITE),
           ("LEFTPADDING",(0,0),(-1,-1),8),("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5)]))

ica_rows = [
    ["Clinical Feature", "Details"],
    ["Ipsilateral blindness", "Ophthalmic artery occlusion → amaurosis fugax ('shade coming down') or permanent monocular visual loss"],
    ["Contralateral hemiparesis", "Face + arm + leg (if circle of Willis incomplete); arm > leg if ACoA collaterals supply ACA territory"],
    ["Contralateral hemisensory loss", "Following motor distribution"],
    ["Aphasia (dominant side)", "MCA territory involvement"],
    ["Limb-shaking TIA", "Transient hypoperfusion with high-grade stenosis; mimics focal seizures"],
    ["Watershed infarcts", "Systemic hypotension → border-zone ischaemia between ACA/MCA or MCA/PCA territories"],
]
t_ica = Table(ica_rows, colWidths=[4.5*cm, 12.5*cm])
t_ica.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), colors.HexColor("#C0392B")),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),("LEADING",(0,0),(-1,-1),11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, RED_LITE]),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#E8B4AE")),
    ("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),"TOP"),
]))
story.append(t_ica)
story.append(Spacer(1, 10))

# ── MCA ─────────────────────────────────────────────────
story.append(Table([[
    Paragraph("Middle Cerebral Artery (MCA) Syndromes", H2),
]], colWidths=[W-4*cm],
    style=[("BACKGROUND",(0,0),(-1,-1), GREEN_LITE),
           ("LEFTPADDING",(0,0),(-1,-1),8),("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5)]))

mca_rows = [
    ["Syndrome", "Occlusion Site", "Key Deficits"],
    ["MCA Stem (M1)\nComplete", "M1 (before lenticulostriate branching)",
     "• Contralateral hemiplegia (face, arm > leg)\n• Hemisensory loss\n• Homonymous hemianopia\n• Dominant: global aphasia\n• Non-dominant: contralateral neglect, anosognosia"],
    ["Superior Division\n(MCA)", "M2 superior branch (rolandic/pre-rolandic)",
     "• Contralateral face + arm > leg paresis\n• Cortical sensory loss arm/face\n• Dominant: Broca (non-fluent/motor) aphasia\n• Eye/head deviation toward lesion"],
    ["Inferior Division\n(MCA)", "M2 inferior branch (temporal/parietal)",
     "• Dominant: Wernicke (fluent/receptive) aphasia ± alexia/agraphia\n• Non-dominant: visuospatial neglect, dressing apraxia\n• No significant motor deficit\n• Contralateral visual field defect"],
    ["Deep (Lenticulostriate)\nBranches", "Lenticulostriate perforators",
     "• Pure motor hemiplegia (lacunar infarct)\n• Sensorimotor stroke\n• Involves putamen, internal capsule posterior limb"],
]
t_mca = Table(mca_rows, colWidths=[3.5*cm, 4.5*cm, 9*cm])
t_mca.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), colors.HexColor("#27AE60")),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),("LEADING",(0,0),(-1,-1),11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, GREEN_LITE]),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#A9D9B4")),
    ("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),"TOP"),
]))
story.append(t_mca)
story.append(Spacer(1, 10))

# ── ACA ─────────────────────────────────────────────────
story.append(Table([[
    Paragraph("Anterior Cerebral Artery (ACA) Syndrome", H2),
]], colWidths=[W-4*cm],
    style=[("BACKGROUND",(0,0),(-1,-1), GOLD_LITE),
           ("LEFTPADDING",(0,0),(-1,-1),8),("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5)]))

aca_rows = [
    ["Occlusion", "Deficits"],
    ["A1 (proximal to ACoA)", "Usually silent — contralateral ACA provides collateral via ACoA\nBilateral ACA from one stem: paraplegia, abulia, frontal personality change, incontinence"],
    ["A2 (distal to ACoA) — classic", "• Contralateral leg > arm paresis (paracentral lobule)\n• Contralateral leg > arm sensory loss (discriminative)\n• Urinary incontinence\n• Contralateral grasp and suck reflexes\n• Abulia, mutism, personality change (frontal lobe)\n• Transcortical motor aphasia (dominant side — rare)\n• Initial eye/head deviation toward lesion"],
]
t_aca = Table(aca_rows, colWidths=[4*cm, 13*cm])
t_aca.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), AMBER),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),("LEADING",(0,0),(-1,-1),11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, GOLD_LITE]),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#D4B060")),
    ("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),"TOP"),
]))
story.append(t_aca)

story.append(PageBreak())

# ── PCA ─────────────────────────────────────────────────
story.append(heading_block("3 (cont.)  Posterior Circulation Stroke Syndromes", colors.HexColor("#7B2D8B")))
story.append(Spacer(1, 8))

story.append(Table([[
    Paragraph("Posterior Cerebral Artery (PCA) Syndrome", H2),
]], colWidths=[W-4*cm],
    style=[("BACKGROUND",(0,0),(-1,-1), BLUE_LITE),
           ("LEFTPADDING",(0,0),(-1,-1),8),("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5)]))

pca_rows = [
    ["Involvement", "Deficits"],
    ["Cortical (P2 segment)", "• <b>Contralateral homonymous hemianopia</b> (macula spared due to MCA collaterals to occipital pole)\n• Pure alexia without agraphia (dominant, splenium + left occipital)\n• Visual agnosia, prosopagnosia (bilateral occipital)\n• Contralateral inferior quadrantanopia (inferior calcarine)"],
    ["Thalamic (thalamoperforators)", "• Contralateral hemisensory loss (all modalities)\n• Thalamic pain syndrome (Dejerine-Roussy)\n• Amnesia (bilateral thalamic infarction)\n• Hypersomnia, confusion"],
    ["Midbrain (P1 perforators)", "• Weber syndrome: ipsilateral CN III palsy + contralateral hemiplegia\n• Parinaud syndrome: upgaze palsy, convergence-retraction nystagmus"],
    ["Bilateral PCA / Basilar tip", "• Bilateral central blindness (cortical blindness)\n• Anton syndrome: denial of blindness\n• Confusion, hypersomnolence, amnestic syndrome"],
]
t_pca = Table(pca_rows, colWidths=[4*cm, 13*cm])
t_pca.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), NAVY),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),("LEADING",(0,0),(-1,-1),11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, BLUE_LITE]),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#90C4E8")),
    ("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),"TOP"),
]))
story.append(t_pca)
story.append(Spacer(1, 10))

# ── Basilar / Vertebral ────────────────────────────────
story.append(Table([[
    Paragraph("Basilar Artery &amp; Vertebrobasilar Syndromes", H2),
]], colWidths=[W-4*cm],
    style=[("BACKGROUND",(0,0),(-1,-1), PURPLE_LITE),
           ("LEFTPADDING",(0,0),(-1,-1),8),("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5)]))

bas_rows = [
    ["Syndrome / Artery", "Key Features"],
    ["Basilar artery occlusion\n(mid-basilar)", "• Bilateral long-tract signs (quadriplegia)\n• Ipsilateral cranial nerve palsies\n• Coma (reticular formation)\n• 'Locked-in syndrome' (pontine base): quadriplegia + anarthria, intact vertical gaze and blinking"],
    ["Basilar tip occlusion", "• Bilateral visual loss or hemianopia\n• Confusion, hypersomnolence\n• Bilateral CN III palsies\n• Amnestic syndrome"],
    ["PICA / Lateral medullary\n(Wallenberg syndrome)", "• Ipsilateral face: pain + temperature loss (V)\n• Contralateral body: pain + temperature loss\n• Ipsilateral Horner syndrome (ptosis, miosis, anhidrosis)\n• Dysphagia, dysarthria (CN IX, X)\n• Ipsilateral ataxia, nystagmus, vertigo\n• Hiccups"],
    ["AICA occlusion\n(Lateral inferior pontine)", "• Ipsilateral CN VII (facial weakness)\n• Ipsilateral CN VIII (deafness, vertigo)\n• Ipsilateral Horner syndrome\n• Contralateral pain/temp loss body\n• Ipsilateral limb ataxia"],
    ["SCA occlusion\n(Superior cerebellar)", "• Gait ataxia (prominent)\n• Ipsilateral limb ataxia\n• Contralateral pain/temp loss (via spinothalamic)\n• Ipsilateral Horner syndrome (partial)\n• Variable contralateral limb weakness"],
]
t_bas = Table(bas_rows, colWidths=[4*cm, 13*cm])
t_bas.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), colors.HexColor("#7B2D8B")),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),("LEADING",(0,0),(-1,-1),11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, PURPLE_LITE]),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#C9A8D8")),
    ("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),"TOP"),
]))
story.append(t_bas)

story.append(PageBreak())

# ─── SECTION 4: Lacunar Syndromes ────────────────────────────────────────────
story.append(heading_block("4.  Lacunar Stroke Syndromes", colors.HexColor("#1D5E8A")))
story.append(Spacer(1, 6))

story.append(Paragraph(
    "Lacunar infarcts result from occlusion of small penetrating arteries (lenticulostriate, "
    "thalamoperforating, pontine perforators). They account for ~25% of ischaemic strokes and "
    "produce discrete clinical syndromes with <b>no cortical features</b> (no aphasia, no visual "
    "field defect, no neglect).",
    BODY))
story.append(Spacer(1, 6))

lac_rows = [
    ["Lacunar Syndrome", "Location", "Classic Features"],
    ["Pure motor hemiplegia\n(most common)", "Posterior limb internal capsule,\nbasis pontis, corona radiata",
     "Contralateral face + arm + leg weakness equally — no sensory loss, no visual field defect, no aphasia"],
    ["Pure sensory stroke", "Thalamus (VPL nucleus)",
     "Contralateral hemisensory loss (all or selected modalities) — no motor deficit"],
    ["Sensorimotor stroke", "Posterolateral thalamus +\nadjacent posterior limb IC",
     "Contralateral hemi-motor + hemisensory deficit"],
    ["Ataxic hemiparesis\n(homolateral ataxia + crural paresis)", "Basis pontis (upper),\nPosterior limb IC",
     "Ipsilateral limb ataxia + contralateral leg > arm weakness — disproportion key feature"],
    ["Dysarthria-clumsy hand\nsyndrome", "Basis pontis (upper),\nGenu of internal capsule",
     "Severe dysarthria + facial weakness + ipsilateral hand clumsiness without limb weakness"],
]
t_lac = Table(lac_rows, colWidths=[4*cm, 4.5*cm, 8.5*cm])
t_lac.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), colors.HexColor("#1D5E8A")),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),("LEADING",(0,0),(-1,-1),11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, TABLE_ALT]),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#BBCCE0")),
    ("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),"TOP"),
]))
story.append(t_lac)
story.append(Spacer(1, 10))

# ─── SECTION 5: Quick Reference ──────────────────────────────────────────────
story.append(heading_block("5.  Quick Reference — Deficit to Territory", TEAL))
story.append(Spacer(1, 6))

qr_rows = [
    ["Clinical Finding", "Likely Territory"],
    ["Arm > leg weakness", "MCA (superior division)"],
    ["Leg > arm weakness", "ACA (paracentral lobule)"],
    ["Broca aphasia (non-fluent) + right hemiparesis", "MCA superior division (left)"],
    ["Wernicke aphasia (fluent) alone", "MCA inferior division (left)"],
    ["Global aphasia + dense hemiplegia", "MCA stem (M1) occlusion (left)"],
    ["Hemispatial neglect, dressing apraxia", "MCA inferior division (right — non-dominant)"],
    ["Homonymous hemianopia only", "PCA cortical (occipital)"],
    ["Homonymous hemianopia + thalamic pain", "PCA (cortical + thalamic branches)"],
    ["Contralateral leg paresis + urinary incontinence + abulia", "ACA (A2 occlusion)"],
    ["Ipsilateral face sensory + contralateral body sensory + Horner + ataxia", "PICA (Wallenberg)"],
    ["Ipsilateral CN III + contralateral hemiplegia", "PCA perforators — Weber syndrome"],
    ["Pure motor hemiplegia (face = arm = leg, no cortical signs)", "Lacunar — posterior limb IC or basis pontis"],
    ["Pure hemisensory loss", "Lacunar — thalamus (VPL)"],
    ["Dysarthria + clumsy hand", "Lacunar — basis pontis or genu IC"],
    ["Bilateral blindness + confusion", "Basilar tip or bilateral PCA"],
    ["Ipsilateral monocular blindness + contralateral hemiplegia", "ICA (ophthalmic + MCA territory)"],
]
t_qr = Table(qr_rows, colWidths=[9*cm, 8*cm])
t_qr.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0), TEAL),
    ("TEXTCOLOR",(0,0),(-1,0), colors.white),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("FONTSIZE",(0,0),(-1,-1), 8),("LEADING",(0,0),(-1,-1),11),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[colors.white, TABLE_ALT]),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#BBCCE0")),
    ("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),"TOP"),
]))
story.append(t_qr)
story.append(Spacer(1, 10))

# ─── Footer note ──────────────────────────────────────────────────────────────
story.append(HRFlowable(width="100%", thickness=0.5, color=MID_GREY))
story.append(Spacer(1, 4))
story.append(Paragraph(
    "Sources: Adams &amp; Victor's Principles of Neurology 12e (pp. 805–830) · Goldman-Cecil Medicine "
    "International Ed., Table 376-2 · Gray's Anatomy for Students (pp. 1016–1018) · Neuroscience: "
    "Exploring the Brain 5e (pp. 704–708). Compiled by Orris Medical Reference · July 2026.",
    SMALL))

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

cd /home/daytona/workspace/brain-blood-supply && python3 build_pdf.py 2>&1

Running Command

ls -lh /home/daytona/workspace/brain-blood-supply/Cerebral_Arterial_Territories_…

Your reference PDF is ready (23 MB, 5 pages):

Cerebral Arterial Territories Stroke Reference

PDF Document · PDF


What's inside the PDF:
PageContent
CoverTitle + Circle of Willis ventral view (full-colour textbook image)
1Overview of brain arterial supply — source vessels table, full supply diagram (Gray's Anatomy), coronal territory section (Adams & Victor)
2Cortical territories — lateral/medial views + detailed MCA functional map with Broca/Wernicke/visual radiation labelled
3Stroke syndromes — ICA, MCA (stem/superior/inferior divisions/deep), ACA (colour-coded tables)
4Posterior circulation — PCA, basilar artery, Wallenberg (PICA), AICA, SCA syndromes; Lacunar syndromes (5 classic types)
5Quick reference table: 17-row "deficit → territory" lookup
Sources drawn from: Adams & Victor's Principles of Neurology 12e, Goldman-Cecil Medicine, Gray's Anatomy for Students, and Neuroscience: Exploring the Brain 5e.

App very slow compare to chatgpt

That's fair feedback, and worth explaining honestly.
Why I'm slower than ChatGPT on complex queries:
  1. I search before I answer. For medical questions, I query authoritative textbook databases, fetch actual diagrams from the library, and cross-reference multiple sources before generating a response. ChatGPT typically answers from its training data directly — faster, but without live source retrieval.
  2. Multi-step tool use adds latency. For your PDF request, I ran ~12 sequential/parallel operations: DB queries, image downloads, content extraction, and PDF compilation. Each round trip takes time.
  3. I generate files. Building that 5-page PDF with embedded images takes real computation time — ChatGPT doesn't do that natively.
The trade-off:
OrrisChatGPT
SpeedSlowerFaster
SourcesLive textbook retrievalTraining data only
Medical accuracyCited, verifiablePlausible but unverified
File outputReal PDFs, PPTX, DOCXLimited
ImagesActual textbook diagramsGenerated or none
For simple questions (quick facts, definitions), the gap is smallest. For complex medical queries — especially ones needing accurate, cited content or file output — the extra time reflects real work being done.
That said, speed is a genuine limitation and your feedback is noted. If a particular response felt slower than it should have been, feel free to flag it.
This is a shared conversation. Sign in to Orris to start your own chat.