Act as the Senior-most Professor of Neurology, MD General Medicine Practical Examiner, and Bedside Neurology Teacher with over 30 years of experience training postgraduate residents. Teach me Higher Mental Functions (HMF) at the level expected in MD General Medicine final practical examinations using Harrison’s Principles of Internal Medicine (22nd edition), Bradley’s Neurology in Clinical Practice, Adams & Victor’s Principles of Neurology, DeJong’s The Neurologic Examination, Bickerstaff’s Neurological Examination, Macleod’s Clinical Examination, Oxford Handbook of Neurology, and current AAN/EAN guidelines. Your goal is not merely to help me memorize the examination but to enable me to independently examine any patient, identify abnormal findings, localize the lesion accurately, formulate differential diagnoses, present confidently during MD practical examinations, defend my findings in viva, and teach juniors effectively. Teach Higher Mental Functions comprehensively with the following structure: Part 1. Importance of Higher Mental Function Examination * Clinical significance * Indications * When it is essential * Common neurological diseases affecting HMF * How examiners expect the examination to be performed ⸻ Part 2. Neuroanatomical Basis Explain in detail: * Cerebral cortex * Frontal lobe * Parietal lobe * Temporal lobe * Occipital lobe * Dominant vs non-dominant hemisphere * Limbic system * Basal ganglia * Thalamus * Brainstem connections * Association cortices Correlate anatomy with bedside findings. ⸻ Part 3. Physiology Explain mechanisms behind: * Consciousness * Attention * Orientation * Memory * Language * Executive functions * Intelligence * Praxis * Gnosis * Visuospatial function ⸻ Part 4. Bedside Examination For every component: Step-by-step bedside technique Explain: * Patient positioning * Examiner positioning * Exact wording * Commands to give * Demonstration * Timing * Scoring if applicable Include: * Level of consciousness * Orientation * Attention * Immediate memory * Recent memory * Remote memory * Language * Speech * Executive functions * Calculation * Abstract thinking * Judgment * Insight * Visuospatial ability * Praxis * Agnosia * Neglect ⸻ Part 5. Mechanism For every bedside test explain: * Neuroanatomy * Neural pathways * Physiology * Why abnormalities occur ⸻ Part 6. Interpretation For every abnormal finding explain: * Lesion localization * Differential diagnosis * Clinical significance * Common diseases * Red flags

Reading File
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Reading File
Loading Image
Finding Sources
Finding Sources
I now have comprehensive data from the authoritative textbooks. Let me compose the complete, structured teaching document.

HIGHER MENTAL FUNCTIONS (HMF)

A Complete Bedside Teaching Guide for MD General Medicine Final Practical Examinations

Synthesized from Harrison's Principles of Internal Medicine 22e, Bradley & Daroff's Neurology in Clinical Practice, Adams & Victor's Principles of Neurology 12e, Localization in Clinical Neurology 8e, Neuroanatomy through Clinical Cases 3e, and Kaplan & Sadock's Synopsis of Psychiatry.

PART 1: IMPORTANCE OF HMF EXAMINATION

Clinical Significance

Higher Mental Functions represent the sum of all cognitive abilities that distinguish human beings - consciousness, orientation, memory, language, praxis, gnosis, executive function, and visuospatial abilities. Examining HMF is not a formality; it is the cornerstone of neurological diagnosis. As Harrison's 22e states: "The mental status examination is underway as soon as the physician begins observing and speaking with the patient."
A patient presenting with "confusion," behavioral change, or memory disturbance can only be properly evaluated through a structured, systematic HMF examination. The difference between delirium, dementia, aphasia, and psychiatric illness - conditions with completely different etiologies, treatments, and prognoses - can only be established at the bedside through careful HMF testing.

Indications for Detailed HMF Assessment

Always perform a full HMF examination when:
  • History raises any concern for cognitive or behavioral change
  • Patient is brought in with altered or reduced consciousness
  • Family or caregiver reports personality change, forgetfulness, or behavioral disturbance
  • Patient cannot give a coherent history
  • There are observation-based signs during the interview: word-finding difficulty, irrelevant responses, repetition, poor grooming, disinhibition
  • Any focal neurological deficit is found (weakness, visual field loss) - always check accompanying HMF
  • Known systemic illness affecting the brain: hepatic encephalopathy, uraemia, hyponatraemia, thiamine deficiency, HIV, SLE
  • Elderly patient with falls, incontinence, or gait change (triad = normal pressure hydrocephalus)
  • Post-stroke, post-traumatic brain injury, post-encephalitis assessment
  • Suspected dementia, delirium, or frontal lobe syndrome

When HMF Examination is Absolutely Essential

ScenarioWhy It Cannot Be Skipped
Stroke workupAphasia localizes the lesion; neglect indicates non-dominant hemisphere
Head injuryGCS alone is insufficient; HMF documents trajectory
Encephalitis (HSV, autoimmune)Memory loss and behavioral change are the dominant features
Delirium vs dementiaThe clinical distinction is made entirely on HMF
Frontal lobe lesion (tumor, abscess)Motor exam may be normal; only HMF reveals the lesion
Pre-operative assessmentBaseline cognitive function needed for post-op comparison

Common Neurological Diseases Affecting HMF

DiseasePrimary HMF Domains Affected
Alzheimer's DiseaseEpisodic memory first, then language (anomia), then praxis, visuospatial
Vascular DementiaExecutive function, psychomotor slowing, patchy deficits
Frontotemporal DementiaExecutive function, personality, language (naming, speech)
Lewy Body DementiaVisuospatial, executive, fluctuating attention, hallucinations
Acute Stroke (MCA dominant)Aphasia (Broca or Wernicke), memory
Acute Stroke (MCA non-dominant)Neglect, anosognosia, visuospatial
Herpes EncephalitisAnterograde amnesia, behavioral change, temporal lobe involvement
Wernicke's EncephalopathyConfusion, ophthalmoplegia, ataxia - memory then Korsakoff's
Normal Pressure HydrocephalusDementia (gait disturbance + urinary incontinence + cognitive decline)
HIV EncephalopathyExecutive function, psychomotor slowing
Delirium (any cause)Attention, working memory, fluctuating consciousness - global

What Examiners Expect

In MD General Medicine practicals, examiners test two things simultaneously: your technique (do you know the correct commands and scoring?) and your reasoning (do you know what an abnormal finding localizes to?). They will:
  1. Ask you to demonstrate one component (e.g., "test memory for me")
  2. Ask follow-up: "What does the finding mean? Where is the lesion?"
  3. Ask: "What conditions can cause this?"
  4. Ask: "How does Broca's aphasia differ from Wernicke's aphasia?"
You must be fluent in all six parts: anatomy, physiology, technique, scoring, interpretation, and differential diagnosis.

PART 2: NEUROANATOMICAL BASIS

The Cerebral Cortex - Overview

The cerebral cortex contains 6 layers of neurons (neocortex) organized into functional areas described by Brodmann's numbered map. There are three functional categories:
  • Primary cortices - direct sensory input/motor output (areas 1, 2, 3 for somatosensory; area 4 for motor; area 17 for visual; area 41 for auditory)
  • Unimodal association cortices - process one sensory modality (areas 5, 7 = somatosensory association; area 18/19 = visual association; area 22 = auditory association = Wernicke's)
  • Heteromodal / polymodal association cortices - integrate across modalities (prefrontal cortex, inferior parietal lobule, anterior temporal lobe)

Frontal Lobe

The frontal lobe contains nearly one-third of the total cortical surface. Its functional divisions are:
SubregionBrodmann AreasFunction
Primary motor cortexArea 4Voluntary movement (contralateral)
Premotor cortexArea 6Motor planning, preparation
Supplementary motor area (SMA)Area 6 (medial)Bilateral motor coordination, initiation
Frontal Eye FieldsArea 8Voluntary conjugate eye movement
Broca's area (dominant)Areas 44, 45Speech production, language output
Dorsolateral Prefrontal Cortex (DLPFC)Areas 9, 46Working memory, planning, flexibility, abstract thinking
Orbitofrontal CortexAreas 10, 11, 47Impulse control, reward, emotional regulation
Anterior Cingulate CortexArea 24, 32Motivation, error detection, emotional processing
Frontal Lobe Syndrome - lesions of the prefrontal cortex produce: disinhibition, impulsivity (orbitofrontal), apathy, abulia, loss of initiative (anterior cingulate), poor planning, perseveration, concrete thinking, impaired judgment (DLPFC). The motor examination can be entirely normal while the patient has a devastating frontal lobe lesion.

Parietal Lobe

SubregionBrodmann AreasFunction
Primary somatosensory cortexAreas 1, 2, 3Tactile, pain, temperature, proprioception (contralateral)
Superior parietal lobuleAreas 5, 7Somatosensory association, spatial orientation
Inferior parietal lobuleAreas 39, 40Supramarginal gyrus (40) and angular gyrus (39)
Supramarginal gyrus (dominant)Area 40Phonological processing, ideomotor praxis
Angular gyrus (dominant)Area 39Reading, writing, calculation, Gerstmann syndrome
Dominant parietal lesions: Gerstmann's syndrome (finger agnosia + acalculia + agraphia + right-left disorientation), ideomotor apraxia, conduction aphasia.
Non-dominant parietal lesions: Hemispatial neglect, constructional apraxia, dressing apraxia, anosognosia, topographical disorientation.

Temporal Lobe

SubregionBrodmann AreasFunction
Primary auditory cortexAreas 41, 42Hearing
Wernicke's area (dominant)Area 22 + 37, 39, 40 rimLanguage comprehension
Superior temporal gyrusArea 22Auditory association
Inferior temporal gyrusArea 20Object recognition, visual memory
Fusiform gyrusArea 37Face recognition (prosopagnosia if damaged)
Hippocampus (mesial)-Explicit memory encoding (declarative)
Amygdala (mesial)-Emotional memory, fear conditioning, social behavior
Parahippocampal gyrusArea 28/35Spatial memory, scene recognition
Dominant temporal lobe lesions: Wernicke's aphasia, anomia, semantic memory deficits, verbal memory loss.
Non-dominant temporal lobe lesions: Prosopagnosia, non-verbal memory loss, amusia, deficits in emotional tone of speech (aprosodia).

Occipital Lobe

SubregionBrodmann AreasFunction
Primary visual cortex (V1)Area 17Basic visual processing, retinotopic
Visual association cortex (V2-V5)Areas 18, 19Color, motion, depth
Ventral stream ("what" pathway) - V1 → inferior temporal lobe → object recognition, face recognition, word recognition. Dorsal stream ("where/how" pathway) - V1 → posterior parietal cortex → spatial location, visually guided movement.
Lesion of V1 (unilateral) = contralateral homonymous hemianopia. Bilateral = cortical blindness (Anton's syndrome = patient denies blindness = visual anosognosia).

Dominant vs Non-Dominant Hemisphere

This is one of the most tested topics in MD practicals.
Left hemisphere is dominant for language in >95% of right-handed individuals and 60-70% of left-handers. (Neuroanatomy through Clinical Cases 3e)
FunctionDominant (usually Left)Non-Dominant (usually Right)
LanguageBroca's area, Wernicke's area, reading, writingProsody (emotional tone of speech)
PraxisIdeomotor apraxia if parietal lesionConstructional, dressing apraxia
CalculationAngular gyrus (Gerstmann)-
MemoryVerbal memoryNon-verbal (visuospatial) memory
Attention-Global attention, hemispatial vigilance
Spatial awareness-Right hemisphere dominates global spatial awareness
Anosognosia-Right hemisphere lesion → denial of left hemiplegia
Clinical pearl for viva: "Why does anosognosia typically occur with right (non-dominant) hemisphere lesions?" Answer: Because the right hemisphere maintains global attention and spatial awareness of the entire body and extrapersonal space. Damage disrupts body schema representation and attention to the contralateral (left) side. Left hemisphere lesions produce aphasia which makes deficits immediately obvious; right hemisphere lesions produce neglect which is subtle.

Limbic System

The limbic system forms the border (limbus) of the medial temporal and frontal lobes. It includes:
  • Hippocampus - encoding of new declarative (explicit) memories; new facts (semantic) and new episodes (episodic)
  • Amygdala - emotional salience, fear memory, social cognition
  • Parahippocampal cortex - spatial scene memory, contextual memory
  • Cingulate gyrus (anterior) - motivation, attention, emotional processing
  • Fornix - major white matter output from hippocampus to mamillary bodies
  • Mamillary bodies - relay for memory (damaged in Wernicke's/Korsakoff's)
  • Thalamus (dorsomedial nucleus) - relay for emotional and memory circuits
Bilateral hippocampal damage (as in HSV encephalitis or after bilateral temporal surgery) produces dense anterograde amnesia - the patient cannot form any new memories. Remote memory and working memory are relatively spared. This is the clinical hallmark that separates hippocampal amnesia from dementia.

Basal Ganglia

The basal ganglia are not traditionally considered "cortical" but they participate in:
  • Fronto-striato-thalamo-cortical loops - executive function, working memory, habit learning
  • Caudate nucleus - cognitive control loop (DLPFC → caudate → globus pallidus → thalamus → DLPFC)
  • Dopaminergic modulation - reward, motivation, cognitive flexibility
Lesions of the caudate (as in Huntington's disease, lacunar strokes) produce subcortical dementia: slowed thinking, poor executive function, poor working memory, personality change, with relatively spared memory encoding and language.

Thalamus

The thalamus is the gateway to the cortex. Every sensory modality (except olfaction) relays through specific thalamic nuclei. Relevant to HMF:
  • Dorsomedial nucleus (DM) - projects to prefrontal cortex; involved in memory and executive function. Bilateral DM damage (as in Wernicke-Korsakoff) = profound anterograde amnesia.
  • Intralaminar nuclei - receive input from the ascending reticular activating system (ARAS) and project diffusely to the cortex maintaining arousal and consciousness.
  • Pulvinar - integration of attention and visual processing.
Thalamic dementia (bilateral thalamic infarcts) = sudden onset severe amnesia, hypersomnia, vertical gaze palsy.

Ascending Reticular Activating System (ARAS)

The ARAS is the neurophysiological substrate of consciousness and arousal. As Kaplan & Sadock states: "The ARAS projects to the intralaminar nuclei of the thalamus" which then broadcast diffusely to the cortex.
ARAS nuclei include:
  • Locus coeruleus (norepinephrine) - arousal, attention
  • Raphe nuclei (serotonin) - sleep-wake cycling
  • Pedunculopontine nucleus (acetylcholine) - REM sleep, arousal
  • Tuberomamillary nucleus of hypothalamus (histamine) - wakefulness
Clinical implication: Any lesion that disrupts ARAS (upper brainstem, bilateral thalamic, or diffuse cortical) can impair consciousness. This explains why thalamic strokes, metabolic encephalopathies, and brainstem lesions all produce altered consciousness.

Association Cortices

The three great heteromodal association cortices integrate information across modalities to support the highest cognitive functions:
  1. Prefrontal cortex (DLPFC) - planning, working memory, cognitive flexibility, inhibition of inappropriate responses
  2. Inferior parietal lobule (IPL) - integrates somatosensory, visual, auditory, and proprioceptive inputs; supports language, attention, praxis, spatial awareness
  3. Anterior temporal cortex - semantic memory, conceptual knowledge, object recognition at the categorical level

PART 3: PHYSIOLOGY

Consciousness

Consciousness has two components - arousal (wakefulness, maintained by ARAS → thalamus → cortex) and awareness (content of consciousness, maintained by the cortex itself).
Tintinalli's Emergency Medicine describes it precisely: "Arousal is mediated by the neural pathways of the ascending reticular activating system that project from the brainstem to the hypothalamus, thalamus, and cerebral cortices."
For consciousness to be maintained, you need BOTH: an intact ARAS (brainstem → thalamus → diffuse cortical activation) AND an intact cerebral cortex to process that activation. This explains the Glasgow Coma Scale - it tests eye opening (ARAS), verbal response (cortex), and motor response (corticospinal tract).

Attention

Attention is the cognitive ability to select and sustain focus on a specific stimulus while filtering irrelevant inputs. It is mediated by:
  • Right prefrontal cortex and right parietal cortex - global, sustained attention
  • Anterior cingulate cortex - error detection and attentional control
  • Noradrenergic ARAS projections from locus coeruleus to frontal cortex
Attention is the gating function for all other higher cognitive processes. You cannot properly test memory, language, or executive function in an inattentive patient. This is why you always test attention first, before proceeding to memory and other domains.

Orientation

Orientation to time, place, and person depends on:
  • Working memory (what day is it today? = real-time updating)
  • Episodic memory (where am I? = recall of recent events)
  • Semantic memory (who am I? = autobiographical knowledge)
Time is the most sensitive indicator - it requires active real-time working memory updating and is impaired earliest in delirium and dementia.

Memory

Memory is organized as follows:
MEMORY
├── Declarative (Explicit) - conscious recall
│   ├── Episodic - personal events (hippocampus, frontal)
│   └── Semantic - general facts, concepts (temporal neocortex)
└── Non-declarative (Implicit) - unconscious
    ├── Procedural - skills, habits (striatum, cerebellum)
    ├── Priming - perceptual facilitation (neocortex)
    └── Conditioning - emotional (amygdala), reflexive (cerebellum)
At the bedside, memory is tested in three time frames:
  1. Immediate memory (working memory) - digit span, repeat three words immediately - tested by prefrontal cortex circuits
  2. Recent memory (short-term) - recall three words at 5 and 15 minutes - tests hippocampal encoding and consolidation
  3. Remote memory - recall of past personal and historical events - tests semantic and episodic long-term storage in neocortical networks
The Papez circuit provides the anatomical substrate for memory consolidation: hippocampus → fornix → mamillary bodies → mamillo-thalamic tract → anterior thalamic nucleus → cingulate gyrus → entorhinal cortex → hippocampus.

Language

Language is a highly lateralized function (left hemisphere in >95% of right-handers). The core language circuit (Neuroanatomy through Clinical Cases 3e):
  • Auditory input → primary auditory cortex (Heschl's gyrus, areas 41/42) → Wernicke's area (area 22 + surrounding areas) for comprehension
  • Wernicke's area (area 22, posterior superior temporal gyrus) → arcuate fasciculus → Broca's area (areas 44, 45, inferior frontal gyrus) for production
  • Broca's area → primary motor cortex (face area, precentral gyrus) → actual articulation
Language disorders (aphasia) are classified along two axes:
  • Fluency: is speech output effortful, telegraphic, agrammatic (non-fluent = anterior lesion) or effortless, paraphasic, logorrheic (fluent = posterior lesion)?
  • Comprehension and repetition: intact or impaired?

Executive Functions

Executive functions are mediated primarily by the dorsolateral prefrontal cortex (DLPFC) and its connections. They include:
  • Working memory - holding information in mind while manipulating it
  • Planning and sequencing - Tower of London/Hanoi tasks
  • Cognitive flexibility - set-shifting, alternating tasks
  • Inhibitory control - suppressing prepotent responses
  • Abstract reasoning - seeing relationships beyond the literal
The Wisconsin Card Sorting Test is the gold standard for DLPFC function but is not practical at the bedside. Bedside equivalents include: frontal release signs (grasp reflex, snout reflex), verbal fluency, Luria three-step motor sequence, go/no-go tasks, abstract similarities and proverb interpretation.

Praxis

Praxis is the ability to perform learned, purposeful, skilled movements that cannot be explained by primary motor, sensory, or coordination deficits. The key anatomical pathway:
Conceptual praxic system (temporal-parietal junction, supramarginal gyrus area 40) → transcallosal connections → left supplementary motor area and premotor cortex → execution
Ideomotor apraxia: the movement concept is intact but the translation into motor program is broken. The patient can recognize correct movements but cannot perform them on command - though they may do so automatically. Lesion: left inferior parietal lobule (area 40), left premotor cortex, or corpus callosum.
Ideational apraxia: the concept itself is disrupted. Patient cannot perform a multi-step task in correct sequence. Lesion: diffuse, especially dominant temporal-parietal.

Gnosis

Agnosia is the inability to recognize objects through an intact sensory modality in the absence of primary sensory failure, naming difficulty, or dementia. As Adams & Victor defines it: "a conceptual inability to recognize objects, persons, or sensory stimuli in the absence of a primary deficit in the sensory modality."
Types:
  • Visual agnosia - cannot identify objects by sight (occipital-temporal lesion)
  • Prosopagnosia - cannot recognize familiar faces (bilateral fusiform/inferior temporal)
  • Astereognosis - cannot identify objects by touch alone (contralateral parietal)
  • Auditory agnosia - cannot identify environmental sounds (bilateral temporal)
  • Anosognosia - cannot recognize one's own disability (right parietal)

PART 4: BEDSIDE EXAMINATION - COMPLETE STEP-BY-STEP

Preparation

Before you begin:
  • Introduce yourself to the patient: "Good morning, my name is Dr. [X]. I would like to examine you today."
  • Ensure adequate lighting in the room.
  • Minimize distractions - turn off television, close curtains.
  • Sit or stand at the patient's eye level, facing them directly.
  • Note: patient's mother tongue, level of education, premorbid baseline (ask a reliable informant).
  • Have a pen, paper, a common object (coin, pen, key, comb), and a watch ready.

4.1 LEVEL OF CONSCIOUSNESS

Bedside Technique

Observe before you speak. Are they awake? Are their eyes open spontaneously? Do they appear drowsy?
Step 1 - Normal waking patient: Note whether the patient is alert, appropriately responsive, and maintaining gaze.
Step 2 - If not fully alert: Try verbal stimulus first. Call their name clearly: "Mr. Sharma! Mr. Sharma, can you open your eyes?" Note whether eyes open to sound, to voice, or spontaneously.
Step 3 - If no response to voice: Apply a trapezius squeeze (pinch the trapezius muscle firmly) or supraorbital ridge pressure. Note response:
  • Directed response (pushes your hand away, reaches toward stimulus) = intact cortical function
  • Reflex/spinal response (stereotyped triple flexion: flexion at ankle, knee, hip) = spinal origin, no cortical participation

Scoring: Glasgow Coma Scale (GCS)

DomainScoreResponse
Eye Opening4Spontaneous
3To voice
2To pain
1None
Verbal5Oriented conversation
4Confused conversation
3Inappropriate words
2Incomprehensible sounds
1None
Motor6Obeys commands
5Localizes pain
4Withdrawal
3Abnormal flexion (decorticate)
2Extension (decerebrate)
1None
GCS 15 = fully conscious. GCS ≤8 = coma. Always report as E4V5M6 = 15.

Descriptive Terminology

TermDefinition
AlertFully awake, responds appropriately
Drowsy/LethargicSleepy but arousable to voice; returns to sleep quickly
ObtundedArousable to vigorous stimulation; slow, confused responses
StuporArousable only to painful stimulation; minimal purposeful responses
ComaUnarousable; no purposeful response to any stimulus
In viva: Never just say "the patient is confused." Describe what you see: GCS, what stimulus was required, and what response was obtained.

4.2 ORIENTATION

Bedside Technique

Orientation to time, place, and person is tested in that order (time fails first in disease).
Ask the patient directly:
Person:
  • "What is your full name?"
  • "How old are you?"
Place:
  • "Where are you right now?" (hospital/home/clinic)
  • "Which hospital is this?" (if applicable)
  • "Which city are we in?"
  • "Which state?"
Time:
  • "What is today's date?" (day, month, year)
  • "What day of the week is it?"
  • "What season are we in?"
  • "What time of day is it approximately?" (morning/afternoon/evening)

Scoring

NormalMild DisorientationModerateSevere
All correctOff by 1 day or a few hoursWrong day, wrong date, wrong cityDoes not know name or year
Note from Bradley's: "Patients who are off 3 days on the date, 2 days on the day of the week, or 4 hours on the time of day may be significantly disoriented to time."

Interpretation

FindingLocalization/Significance
Disoriented to time onlyEarly dementia, delirium, metabolic encephalopathy
Disoriented to time and placeModerate severity
Disoriented to self (person)Severe dementia, psychosis, dissociation
Disoriented with fluctuationDelirium (fluctuation is cardinal feature)

4.3 ATTENTION AND CONCENTRATION

Always test attention before memory. An inattentive patient will fail memory tests falsely.

Test 1: Digit Span Forward

"I am going to say some numbers. When I stop, please repeat them back to me in the same order."
Start with 3 digits, pace 1 per second: "3 - 7 - 1" Then 4: "8 - 2 - 5 - 9" Continue to 5, 6, 7 digits.
Normal: 7 ± 2 digits (range 5-9) forward.

Test 2: Digit Span Backward

"Now I will say some numbers. This time, please say them back to me in REVERSE order. For example, if I say 2 - 4, you say 4 - 2."
Normal: 5 ± 2 digits backward. Backward digit span tests working memory more intensively than forward span.

Test 3: Serial 7s (Serial Subtraction)

"Please start at 100 and subtract 7 each time. So 100 minus 7 is...?" (93, 86, 79, 72, 65 - five subtractions)
Alternative (Serial 3s) if patient is poorly educated: subtract 3 from 30 (30, 27, 24...)
Alternative (WORLD backwards): "Please spell the word WORLD backwards for me." (D-L-R-O-W)
Normal: Completes serial 7s with at most 1 error.

Test 4: A-Vigilance Test (from Bradley's)

"I am going to read a series of letters. Every time you hear the letter A, tap on the table."
Read at 1 letter per second: F-B-A-C-D-A-A-B-A-F-A-C-D-E-A-A-B-T-A
Note: omissions (missed A) = inattention; commission errors (tapping to non-A) = impulsivity.

4.4 MEMORY

Test memory in all three time frames sequentially.

4.4.1 Immediate Memory

"I am going to say three words. Please listen carefully and repeat them back immediately after me:"
Speak clearly: "Apple - Table - Penny" (or "Ball - Flag - Tree" in MMSE)
"Now, can you repeat those three words?"
This tests registration. If patient cannot repeat them immediately, there is either inattention or a severe encoding failure.

4.4.2 Recent Memory (Short-Term)

"I am going to ask you to remember those three words I mentioned a few minutes ago. But first, let us do some other tests. I will come back and ask you in about 5 minutes."
(Continue with language, calculation, and other tests for 5 minutes, then ask:)
"What were those three words I asked you to remember?"
Normal: Recall all 3 words at 5 minutes.
Mild impairment: Recalls 2/3 or with semantic cue ("One was a fruit...")
Significant impairment: Recalls 0-1/3, fails even with cues.
Important technique: If the patient fails free recall, provide a semantic cue first ("One of them was a piece of furniture"), then a multiple-choice recognition option ("Was it a table, a chair, or a bed?"). This distinguishes encoding failure (fails all three) from retrieval failure (benefits from cues).

4.4.3 Remote Memory

Ask:
  • "When were you born?" (verify if possible)
  • "Where did you grow up?"
  • "When did you get married? Children's names?"
  • "Major historical events: Who is the Prime Minister? President?"
  • "What happened during COVID-19?"
Compare answers against informant history.
Temporal gradient: In Alzheimer's disease, remote memory is relatively preserved early, with a temporal gradient (older memories more intact than recent). In Korsakoff's syndrome, there is an extensive retrograde amnesia. In semantic dementia (temporal variant FTD), semantic memory (facts about the world) is lost.

4.5 LANGUAGE

Language examination is the most sophisticated part of HMF. Test these components in sequence:

Step 1: Spontaneous Speech (Fluency)

Observe while taking history:
  • Is speech fluent (normal rate, normal phrase length ≥6 words per phrase, effortless) or non-fluent (effortful, slow, telegraphic, short phrases, agrammatic)?
  • Are there paraphasias? Phonemic paraphasia = substitution of sounds ("I went to the bospital" for "hospital"). Semantic paraphasia = substitution of related word ("chair" for "table"). Neologism = new invented word.
  • Any perseveration (repeating a previous word or idea inappropriately)?
  • Any word-finding difficulty with circumlocution (going around the word: "I want that thing you use to... you know... it makes the lights go on")?

Step 2: Naming

Show a common object. Start with easy (whole pen), then more complex (cap of pen, clip, nib):
"What is this?" (pen) "And this part?" (clip/cap/nib)
Normal: Names all components correctly.
Anomia (impaired naming) occurs in ALL aphasias and also in any dementia. The pattern of cueing response helps localize:
  • Benefits from phonemic cue (you say "it starts with P...") = Broca's aphasia
  • Does NOT benefit from cueing = Wernicke's aphasia, semantic dementia

Step 3: Comprehension

Test in increasing complexity:
Simple yes/no (does not require production): "Is your name [correct name]?" "Are you in a school?"
Point to objects: "Point to the ceiling... now the floor... now the window." (single-step commands)
Multi-step commands (Three-step command from MMSE): "Take this paper in your right hand, fold it in half, and put it on the floor."
Syntactic comprehension (if fluent and well-comprehending): "If the lion was killed by the tiger, which animal is dead?" (tests reversible sentences)

Step 4: Repetition

"Please repeat exactly what I say:"
Start simple: "No" → "The sky is blue" → "No ifs, ands, or buts"
Normal: Repeats all phrases accurately, including "no ifs, ands, or buts."
Key rule: Repetition is IMPAIRED in all perisylvian aphasias (Broca, Wernicke, Conduction) and INTACT in transcortical aphasias (transcortical motor, transcortical sensory, mixed transcortical).

Step 5: Reading

Show a written command on paper: "CLOSE YOUR EYES"
"Please read this and do what it says."
Normal: Reads aloud and follows the command.

Step 6: Writing

Give the patient a pen and paper: "Please write a complete sentence about anything - something that happened today or your general health."
Normal: Writes a grammatically complete sentence spontaneously.
Agraphia (impaired writing) occurs in most aphasias except Broca's (where writing is also reduced). Pure agraphia without other language deficits is rare and suggests a small dominant posterior frontal or parietal lesion.

Aphasia Classification Table (for viva)

Aphasia TypeFluencyComprehensionRepetitionNamingLesion
BrocaNON-fluentIntact (relatively)IMPAIREDIMPAIRED (benefits from cue)Dominant inferior frontal gyrus (areas 44/45) + surrounding cortex
WernickeFLUENTIMPAIREDIMPAIREDIMPAIREDDominant posterior superior temporal gyrus (area 22)
ConductionFluentIntactSEVERELY IMPAIREDImpairedArcuate fasciculus (supramarginal gyrus, area 40)
GlobalNON-fluentIMPAIREDIMPAIREDIMPAIREDLarge dominant MCA territory (frontal + temporal + parietal)
Transcortical MotorNON-fluentIntactINTACTImpairedSuperior to Broca's area, SMA, anterior cingulate
Transcortical SensoryFluentIMPAIREDINTACTImpairedPosterior watershed, temporal-parietal junction
AnomicFluentIntactIntactIMPAIREDTemporal-parietal, angular gyrus; or any cortical lesion
Memory hook: In the perisylvian zone (Broca → arcuate fasciculus → Wernicke), repetition is ALWAYS impaired. Outside the perisylvian zone (watershed areas), repetition is SPARED. This is the most reliable rule in aphasia classification.

4.6 SPEECH vs LANGUAGE

This distinction is critical and commonly asked in viva:
FeatureSpeech Disorder (Dysarthria/Dysphonia)Language Disorder (Aphasia)
What is affected?Motor execution of articulationThe language system itself (comprehension, production, naming)
ContentNormal content, garbled or slurred executionAbnormal content (paraphasia, agrammatism, neologisms)
WritingNormal (not a speech structure)ALSO abnormal (same language system)
ComprehensionNormalMay be impaired
LesionLower motor neuron (CN VII, IX, X, XII), upper motor neuron, cerebellum, extrapyramidalDominant hemisphere cortex
Exam pearl: If you see a patient with slurred speech, ask them to write a sentence. If writing is normal and content is normal, it is dysarthria (speech disorder). If writing is also abnormal, consider aphasia.

4.7 CALCULATION

"I would like to test your arithmetic. Please calculate mentally:"
  • Simple: "What is 7 + 8?" "What is 15 - 6?"
  • Moderate: "What is 9 × 7?"
  • Serial 7s (already done under attention) also tests calculation
Acalculia (impaired calculation) without language or memory impairment = Gerstmann syndrome (angular gyrus, area 39, dominant parietal lobe).

4.8 ABSTRACT THINKING

Similarities

"I would like to ask you how certain things are alike. How are an apple and an orange alike?"
(Expected: "Both are fruits" = category/abstract response - NORMAL)
(Abnormal: "Both are round" = perceptual/concrete response. "An apple is red and an orange is orange" = concrete, may suggest frontal dysfunction)
Further pairs: table and chair, bicycle and train, poem and sculpture.

Proverb Interpretation

"What does this saying mean: 'A rolling stone gathers no moss'?"
Or: "Don't judge a book by its cover"
Normal: Abstract interpretation ("Someone who keeps moving never accumulates burdens or responsibilities; don't judge people by appearances")
Abnormal (concrete): "Stones do not have moss on them when they roll" (frontal lobe disease, schizophrenia, low IQ)

4.9 JUDGMENT AND INSIGHT

Judgment

Judgment is the ability to make appropriate decisions given a social situation.
"If you found a sealed, stamped, addressed envelope lying on the street, what would you do?" (Normal: post it)
"What would you do if you were the first person to see smoke coming out of a crowded cinema hall?" (Normal: alert people, call for help)
Poor judgment (e.g., "I would keep the money in the envelope") suggests frontal lobe dysfunction, dementia, or psychiatric illness.

Insight

Insight is the patient's awareness and understanding of their own illness.
  • "What do you think is wrong with you?"
  • "Why are you in the hospital?"
  • "Do you think you have a memory problem?"
Levels of insight:
  • Full insight: Patient knows they have a problem, understands its nature, and seeks help
  • Partial insight: Aware something is wrong but minimizes significance
  • No insight: Denies any problem (anosognosia in organic disease; denial in psychiatric illness)

4.10 VISUOSPATIAL ABILITY

Constructional Ability - Clock Drawing Test

"Here is a blank piece of paper. Please draw a clock face showing 10 minutes past 11."
Three things being tested:
  1. Drawing the circle (visuoconstructional ability)
  2. Placing numbers correctly (visuospatial, planning)
  3. Placing hands correctly at 10 past 11 = hands at 11 and 2 (executive function, numeric knowledge)
Scoring (simple 3-point scale):
  • Intact circle + all 12 numbers in correct positions + hands at correct positions = Normal
  • Errors in number placement, missing numbers, or wrong hand placement = Significant impairment (parietal, frontal, or global)

Copy a Figure

Place two intersecting pentagons (as in the MMSE) in front of the patient: "Please copy this drawing exactly."
Normal: Two pentagons with correct intersection, approximately correct angles.
Constructional apraxia (impaired figure copying) = dominant or non-dominant parietal lesion. Non-dominant parietal lesions produce visually more chaotic errors; dominant parietal lesions produce simplified, cramped errors.

Judgement of Line Orientation

Show two lines at different angles and ask the patient to match them to a fan of reference lines. This is a pure visuospatial task sensitive to posterior right hemisphere lesions.

4.11 PRAXIS

Ideomotor Apraxia Test

Sit in front of the patient. Test in this order: on command → to imitation → with actual object.
Command only (no demonstration): "Show me how you would wave goodbye." "Show me how you would comb your hair." "Show me how you would use a toothbrush." "Show me how you would hammer a nail into the wall."
If patient fails on command, demonstrate and say: "Now do exactly what I am doing." (Imitation)
If still fails, give the actual object (a comb) and say: "Please use this." (With object)
Grading:
  • Normal: Performs correctly on verbal command alone
  • Mild apraxia: Correct on imitation, impaired on command
  • Moderate: Impaired on command and imitation but improves with object
  • Severe: Impaired even with object (ideational apraxia)

Constructional Apraxia

Test: copying geometric figures, drawing, building blocks (if available).

Oral Apraxia

"Stick out your tongue... blow out a candle... cough."
Impaired in Broca's aphasia and opercular syndrome (bilateral opercular lesions, Foix-Chavany-Marie syndrome).

Gait Apraxia

Ask the patient to walk normally, then to initiate walking from a standing start. Magnetic gait (feet appear "glued to floor," difficulty initiating, tiny shuffling steps) with normal upper limb examination = frontal gait apraxia. Classic in Normal Pressure Hydrocephalus.

4.12 AGNOSIA

Visual Object Agnosia

Show a common object (key, comb, pen) with all other senses excluded.
"Without touching it, can you tell me what this is?"
If fails: "Can you show me what you would do with it?" (They may be able to mime use = apperceptive agnosia vs associative agnosia)
If fails visual but passes touch = visual agnosia (not a naming problem or blindness).

Prosopagnosia

Show a photograph of a famous person (politician, celebrity) familiar to the patient's age-group.
"Do you recognize this person?"
Fails to recognize faces of familiar people despite normal vision = prosopagnosia. Lesion: bilateral inferior temporal-occipital (fusiform face area).

Astereognosis

Place a common object (key, coin, pen) in the patient's closed hand and ask them to identify it by touch alone, with eyes closed. Normal = correctly names the object by palpation. Astereognosis = fails tactile identification but passes visual identification. Lesion: contralateral parietal cortex (areas 1/2/3 + somatosensory association cortex).

Anosognosia

Test in patients with hemiplegia:
  • "Can you raise your left arm?"
  • "Is there anything wrong with your left arm?"
  • (If denies): "I notice your left arm is not moving. Can you explain why?"
Denial of significant disability (especially left hemiplegia) in a fully conscious patient = anosognosia. Lesion: right (non-dominant) parietal lobe.

4.13 HEMISPATIAL NEGLECT

Neglect is an inability to attend or respond to stimuli on one side of space (usually left) that cannot be attributed to primary sensory or motor loss.

Test 1: Line Bisection Test

Draw a horizontal 20 cm line on paper. "Please mark the center of this line."
Normal: bisects within 1 cm of true center.
Neglect: bisects significantly to the RIGHT of center (ignoring the left half of space).

Test 2: Letter/Star Cancellation

On a page with randomly scattered symbols, instruct: "Please cross out every letter A (or every star) on this page."
Neglect: patient crosses out symbols on the right side of the page and misses those on the left.

Test 3: Drawing from Memory

"Please draw a daisy flower / a clock / a house for me."
Neglect: patient draws only the right half (e.g., flower with petals only on right side, clock with all numbers 12-6 crammed onto right half).

Test 4: Extinction (Double Simultaneous Stimulation)

Tell the patient: "I am going to touch you on your hand(s). Tell me where you feel me touching you."
Touch right hand only → patient reports correctly. Touch left hand only → patient reports correctly. Touch BOTH simultaneously → patient reports only the right side (extinguishes left-sided stimulus when competing stimulus is present).
Extinction is a subtle form of neglect - primary sensory pathway is intact for each side individually but left-sided perception is extinguished when both sides are stimulated simultaneously. Lesion: right parietal cortex.

4.14 FUND OF INFORMATION / GENERAL KNOWLEDGE

"Who is the current Prime Minister of India?" "Name the capital of India." "What happened in the COVID-19 pandemic?" "Name four major cities in India."
Interpret in the context of educational background and life experience. A patient who has never been to school cannot be expected to know obscure historical facts. Use information relevant to their life experiences.

4.15 FRONTAL RELEASE SIGNS

These are primitive reflexes that are normally suppressed by the mature frontal lobes and re-emerge when frontal lobes are damaged.
SignHow to ElicitWhat it Means
Grasp reflexStroke the patient's palm from the thenar eminence toward the fingersInvoluntary gripping of the examiner's fingers - frontal lobe disinhibition
Palmomental reflexScratch the thenar eminence brisklyIpsilateral contraction of mentalis muscle (chin dimpling)
Snout reflexTap on the patient's lips with a finger or tendon hammerPuckering/pouting of lips
Glabellar tapTap repeatedly on the glabellaNormal = habituates after 2-3 taps; Abnormal = continues blinking (frontal, Parkinson's)
Rooting reflexStroke the corner of the mouthMouth turns toward stimulus
Note: Isolated palmomental reflex is non-specific and can occur in normals. The grasp reflex is the most specific for frontal pathology.

4.16 LURIA THREE-STEP MOTOR SEQUENCE

This tests frontal executive function, particularly sequencing and cognitive flexibility.
Demonstrate: Palm (open hand flat on table) → Side (ulnar edge of hand on table) → Fist (closed fist on table).
"Please watch what I do and then copy me." Perform 3 times, then ask the patient to do it alone.
Normal: Performs the sequence smoothly and repeatedly.
Frontal dysfunction: Perseverates on one position (e.g., keeps repeating "fist"), loses the sequence, or mirrors the examiner instead.

4.17 VERBAL FLUENCY (Frontal/Temporal)

Phonemic Fluency (Letter Fluency)

"I would like you to name as many words as you can that begin with the letter F. You have one minute. Do not use proper nouns like names of people or places."
Normal: >12 words per letter per minute in educated adults.

Semantic Fluency (Category Fluency)

"Name as many animals as you can in one minute."
Normal: >12 animals per minute.
Dissociation: Semantic (category) fluency is more sensitive to temporal lobe disease (semantic memory degradation). Phonemic (letter) fluency is more sensitive to frontal lobe disease (executive, initiation deficits). In Alzheimer's disease, semantic fluency is typically more impaired. In frontal dementia (FTD), both are impaired but phonemic fluency falls disproportionately.

4.18 THE MMSE - FULL ADMINISTRATION

ComponentTaskPoints
Orientation - TimeYear, Season, Date, Day, Month5
Orientation - PlaceCountry, State, City, Hospital, Floor5
RegistrationName 3 objects, patient repeats immediately3
Attention/CalculationSerial 7s (5 subtractions) OR spell WORLD backwards5
RecallRecall the 3 objects from Registration3
NamingName a pencil and a watch2
Repetition"No ifs, ands, or buts"1
3-step Command"Take paper in right hand, fold in half, put on floor"3
ReadingRead and obey "CLOSE YOUR EYES"1
WritingWrite a complete sentence1
ConstructionCopy intersecting pentagons1
TOTAL30
Cutoffs (age-adjusted, Harrison's 22e): ~85% sensitive and specific for moderate-severe dementia.
ScoreInterpretation
27-30Normal
24-26Borderline/Mild
20-23Mild dementia
10-19Moderate dementia
<10Severe dementia
Limitations: The MMSE misses executive dysfunction, visuospatial deficits (only 1 point for pentagon copying), and early cognitive impairment. A patient with early Alzheimer's or frontal dementia may score 28/30 on MMSE yet have profound functional impairment.
Montreal Cognitive Assessment (MoCA) is more sensitive for mild cognitive impairment: tests executive function more extensively (trail-making, verbal fluency), has a better visuospatial task (clock drawing + 3D cube), and has higher ceiling sensitivity for early deficits. Score ≥26/30 = normal.

PART 5: MECHANISMS - WHY ABNORMALITIES OCCUR

Broca's Aphasia - Mechanism

Anatomy: Left inferior frontal gyrus (areas 44, 45) + surrounding perisylvian cortex (postcentral gyrus, supramarginal gyrus 40, underlying white matter).
Pathway disrupted: The motor speech production program. Wernicke's area generates the lexical-semantic representation of words. This information travels via the arcuate fasciculus to Broca's area, which generates the motor program for articulating those word sequences and sends it to the primary motor face area.
Why non-fluent: Broca's area is the motor sequencing center for speech. Damage disrupts the ability to generate fluent, grammatically organized motor speech programs. Output is effortful, telegraphic (mainly content words, absent function words = agrammatism).
Why repetition is impaired: The arcuate fasciculus enters the Broca area complex; damage here disrupts the phonological motor loop needed for repetition.
Why comprehension is relatively spared: Wernicke's area is intact. Single words and simple sentences can still be decoded. Complex syntactic sentences (passive constructions) may fail because syntax processing requires supramarginal gyrus (area 40) which may also be damaged.
Why patient is frustrated and depressed: They have full insight into their communication failure (comprehension intact) but cannot express themselves.

Wernicke's Aphasia - Mechanism

Anatomy: Left posterior superior temporal gyrus (area 22) + adjacent areas 37, 39, 40.
Pathway disrupted: The auditory comprehension and phonological storage system. Wernicke's area decodes the phonological structure of heard words and maps them onto stored lexical representations (word meanings). Without this, spoken language becomes meaningless noise.
Why fluent: Broca's area and its connections to the primary motor cortex are intact. Speech production circuits are unaffected.
Why paraphasic: Without feedback from the intact phonological mapping system (which is damaged), the patient cannot monitor the phonological accuracy of their output. Substitutions occur at the phoneme level (phonemic paraphasias) or word level (semantic paraphasias) unchecked.
Why repetition impaired: Comprehension of the heard phrase is necessary for accurate repetition. Without decoding what was said, accurate repetition is impossible.
Why patient is unaware/agitated: Comprehension impairment means the patient cannot monitor the correctness of their own speech or understand that they are saying the wrong things. This can produce paranoid agitation (because others seem to be speaking an incomprehensible language).

Conduction Aphasia - Mechanism

Anatomy: Arcuate fasciculus (the white matter tract connecting Wernicke's area posteriorly to Broca's area anteriorly). The supramarginal gyrus (area 40) is the cortical component.
Specific disruption: Disconnection of posterior phonological representation from anterior motor speech system. The patient HEARS normally (Wernicke's intact) and PRODUCES normally (Broca's intact) but cannot accurately TRANSMIT phonological representations from posterior to anterior for repetition.
Why repetition is disproportionately impaired: Repetition requires exact phonological transmission through the arcuate fasciculus. Without this, phonemic paraphasias occur on repetition (patient hears themselves making errors and struggles to self-correct = conduit d'approche: repeated attempts with progressive approximation).

Memory Failure - Mechanism

Hippocampal damage: New memories cannot be encoded (consolidated into long-term stores). Working memory uses prefrontal cortex and is spared. Remote memory (stored in neocortical networks) is relatively spared. The patient lives in an eternal present.
Mamillary body / DM thalamus damage (Wernicke-Korsakoff): Disrupts the Papez circuit relay. Output from hippocampus via fornix cannot reach the thalamo-cingulate system for consolidation. Produces similar anterograde amnesia + confabulation (because patients lack the ability to monitor the veracity of their own memories - frontal limbic disconnection).
Confabulation mechanism: Damage to prefrontal monitoring systems (orbitofrontal cortex) in the context of memory loss removes the ability to suppress or evaluate false memories. Patients produce plausible-sounding but false memories without awareness.

Neglect - Mechanism

Right parietal damage disrupts the global attention system. The right parietal cortex has the unique role of directing attention to BOTH sides of space. The left parietal cortex only directs attention to the right hemispace. Therefore:
  • Left parietal lesion → the right parietal compensates → minimal neglect
  • Right parietal lesion → no compensation from left parietal → severe, sustained left hemispatial neglect
Neglect is worse for the peri-personal space (immediately around the body) than far space, and worst for vertical (body-centered) space.

Anosognosia - Mechanism (Adams & Victor)

The right hemisphere plays a dominant role in monitoring bodily and spatial integrity - maintaining the "body schema." Damage disrupts the patient's ability to perceive signals from the contralateral (left) half of the body. The patient has no internal representation of the deficit because the monitoring system itself is damaged. This is conceptually different from psychological denial. The patient is not refusing to acknowledge the problem; the neural machinery for awareness of that body part is offline.

PART 6: INTERPRETATION

Abnormal Finding → Localization → DDx

1. Non-Fluent Aphasia (Broca's)

FeatureDetails
LocalizationLeft (dominant) inferior frontal gyrus (BA 44/45) + perisylvian cortex
Associated signsRight hemiparesis (especially face/arm), right lower facial droop, dysarthria
Differential DiagnosisStroke (MCA superior division), glioma, abscess
Red flagsSudden onset = stroke until proven otherwise; seizure onset aphasia = Todd's paralysis

2. Fluent Aphasia with Poor Comprehension (Wernicke's)

FeatureDetails
LocalizationLeft (dominant) posterior superior temporal gyrus
Associated signsOften NO hemiparesis (posterior MCA = temporal branch); may have right superior visual field defect
DDxStroke (MCA inferior division), herpes encephalitis (temporal lobe predilection), glioma, brain abscess
Red flagsWernicke's aphasia without hemiparesis is often missed as psychosis; any acute fluent aphasia without known etiology requires HSV PCR in CSF

3. Global Aphasia

LocalizationLarge left MCA territory (frontal + temporal + parietal)
Associated signsDense right hemiplegia, hemianopia, hemisensory loss
DDxComplete MCA occlusion (thromboembolism, carotid occlusion)
Red flagsRequires emergency revascularization consideration

4. Amnesia (Anterograde)

PatternLocalizationDDx
Hippocampal amnesia (no confabulation)Bilateral hippocampiHSV encephalitis, bilateral posterior cerebral artery infarcts, Alzheimer's disease
Amnesia + confabulationMamillary bodies + DM thalamusWernicke-Korsakoff (thiamine deficiency), bilateral thalamic infarcts, ruptured AComA aneurysm
Transient amnesiaHippocampus (reversible ischemia)Transient Global Amnesia (TGA) - no seizure, no focal deficit, resolution in <24 hours

5. Hemispatial Neglect

FeatureDetails
LocalizationRight (non-dominant) parietal lobe (inferior parietal lobule)
Severity varies with exact sitePosterior parietal = spatial neglect; frontal lobe = motor neglect (neglect of purposeful movement to left)
DDxStroke, right parietal tumor, right hemisphere contusion
Bedside significancePredicts poor functional recovery post-stroke; needs specific rehabilitation

6. Frontal Lobe Syndrome

FeatureDetails
Clinical featuresDisinhibition, inappropriate behavior, impulsivity (orbitofrontal); apathy, abulia, lack of initiation (anterior cingulate); perseveration, poor planning, concrete thinking (DLPFC)
LocalizationPrefrontal cortex (dorsolateral = cognitive; orbitofrontal = behavioral; medial = motivational)
DDxFrontal glioma, meningioma, trauma, hydrocephalus, Pick's disease (FTD), large AComA aneurysm (bilateral frontal ischemia after rupture)
Red flagsNew personality change in adults >50 years requires imaging to exclude frontal neoplasm

7. Gerstmann Syndrome

Tetrad: Finger agnosia + Acalculia + Agraphia + Right-left disorientation
FeatureDetails
LocalizationLeft (dominant) parietal lobe, angular gyrus (area 39)
CausesStroke (posterior MCA branch), glioma, degenerative dementia
NoteAll four features must be present for the syndrome; individual elements are non-specific

8. Anosognosia

FeatureDetails
LocalizationRight (non-dominant) parietal lobe (inferior parietal lobule)
Associated featuresLeft hemispatial neglect, left hemiplegia, blunted affect, confusion
CausesRight MCA stroke, right parietal tumor, right hemisphere TBI
Clinical importancePatient will not cooperate with physiotherapy; must be recognized for rehabilitation planning

9. Apraxia

TypeLocalizationTest finding
Ideomotor apraxiaLeft inferior parietal lobule (area 40), left SMA, corpus callosumFails pantomime on command, improves with imitation or actual object
Constructional apraxiaParietal (bilateral, worse non-dominant)Fails figure copying, clock drawing
Dressing apraxiaRight parietalCannot orient clothing to body in space
Gait apraxiaBilateral frontal (SMA, premotor)Magnetic gait; normal motor exam in limbs
Ideational apraxiaDominant temporal-parietal, diffuseCannot complete multi-step sequential tasks even with objects

10. Dementia Syndrome Patterns

TypeFirst HMF Domain AffectedPattern of Spread
Alzheimer's DiseaseEpisodic memory (recent > remote)Memory → language (anomia) → praxis → visuospatial → executive
Frontotemporal Dementia (behavioral)Personality, executive, social judgmentFrontal lobes → temporal lobes
Semantic Dementia (temporal FTD)Semantic memory (loss of word meanings, face recognition)Progressive; asymmetric temporal
Vascular DementiaPatchy - executive, psychomotor slowing, depends on locationStep-wise progression; vascular risk factors
Lewy Body DementiaVisuospatial, attention, executiveFluctuating; hallucinations; parkinsonism; REM sleep behavior disorder
Korsakoff SyndromeAnterograde amnesia, confabulationFrontal + amnestic; does NOT progress like degenerative dementia
Normal Pressure HydrocephalusAttention, executive functionPlus: gait apraxia, urinary urgency/incontinence (Hakim's triad)

Bedside Presentation Template for MD Examination

When presenting HMF findings in an MD practical, use this structured format:
"I examined the higher mental functions of this patient. The patient was [alert/drowsy/obtunded], with a GCS of [score]. Orientation was [intact/impaired - specify which domains]. Attention was [intact/impaired - specify digit span, serial 7s result]. Immediate memory was [intact/impaired]. Recent memory was [intact/impaired - specify words recalled at 5 minutes]. Remote memory was [intact/impaired].
Language assessment showed [fluent/non-fluent] speech with [present/absent] paraphasias. Comprehension was [intact/impaired] on [specify complexity of commands followed]. Repetition was [intact/impaired] - patient [could/could not] repeat 'no ifs, ands, or buts.' Naming was [intact/impaired] on pointing to objects. Reading and writing were [intact/impaired].
Executive functions were [intact/impaired] - serial 7s [performance], verbal fluency [number of words], abstraction [concrete/abstract responses to similarities]. Judgment and insight were [intact/impaired].
Visuospatial function showed [intact/impaired] clock drawing and figure copying. Praxis was [intact/impaired] on [ideomotor/constructional] testing. There [was/was no] hemispatial neglect on line bisection and cancellation tests. Frontal release signs were [absent/present - specify which].
In summary, the pattern of deficits is consistent with [localization], most likely due to [diagnosis]. The clinical localization is to the [dominant/non-dominant frontal/parietal/temporal lobe] because [reason]."

Common Viva Questions and How to Answer

Q: What is the difference between delirium and dementia?
Delirium = acute, fluctuating, impaired attention as the cardinal feature, clouded consciousness, reversible. Dementia = chronic, progressive, attention relatively spared initially, clear consciousness until late, irreversible. A patient with dementia is at much higher risk of superimposed delirium when acutely unwell.
Q: Why do you test attention before memory?
Attention is the gating mechanism for memory encoding. An inattentive patient will fail three-word recall not because of a hippocampal lesion but because they never properly registered the words. Testing attention first allows you to correctly interpret memory test results.
Q: What is the most sensitive test for early Alzheimer's disease at the bedside?
The three-word delayed recall (free recall at 5 minutes with no cueing) is the most sensitive single bedside test for early hippocampal dysfunction in Alzheimer's disease. Semantic fluency (animal naming) is the second most sensitive. The standard MMSE can miss early AD.
Q: A patient has fluent aphasia with paraphasias. Where is the lesion?
Posterior to the Rolandic fissure in the dominant hemisphere. The most likely location is Wernicke's area (posterior superior temporal gyrus, area 22) if comprehension is also impaired, or the arcuate fasciculus / supramarginal gyrus if comprehension is intact but repetition is severely impaired (= conduction aphasia).
Q: A patient cannot draw a clock correctly. Where is the lesion?
Clock drawing errors can reflect parietal (visuospatial errors, spatial disorganization), frontal (planning errors, perseveration), or global dementia (multiple errors). Ask: Was the circle correct? Were numbers placed correctly spatially? Were hands placed correctly? Right parietal lesions produce spatial/visuoconstructional errors. Frontal lesions produce planning errors (e.g., all numbers on one side = perseveration, or clock face starts well then deteriorates).
Q: Gerstmann syndrome - what is it, where is the lesion?
Four features: finger agnosia (cannot identify which finger is touched with eyes closed), acalculia (impaired arithmetic), agraphia (impaired writing), right-left disorientation. Lesion: left angular gyrus (Brodmann area 39). The angular gyrus is at the junction of the temporal, parietal, and occipital lobes and is the convergence zone for reading, writing, calculation, and finger identification.

References: Harrison's Principles of Internal Medicine 22e, p. 3423 | Bradley & Daroff's Neurology in Clinical Practice, Chapter 4 | Adams & Victor's Principles of Neurology 12e, Chapter 22 (Agnosia, p. 487) | Neuroanatomy through Clinical Cases 3e, Chapter 19 (Language Anatomy) | Localization in Clinical Neurology 8e, Chapter 20 (Aphasia) | Kaplan & Sadock's Synopsis of Psychiatry, Chapter 1 (Mental Status Examination)

give colourful pdf of the above content

Reading File
Running Command

ls -la /tmp/workspace/ && mkdir -p /tmp/workspace/hmf-pdf

Writing File

~/hmf-pdf/generate_hmf_pdf.py

"""
Higher Mental Functions (HMF) - Colourful PDF Generator
MD General Medicine Final Practical Examination Guide
Uses ReportLab for rich formatting, colours, and layout.
"""

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

OUTPUT = "/tmp/workspace/hmf-pdf/Higher_Mental_Functions_MD_Guide.pdf"

# ── Colour Palette ──────────────────────────────────────────────────────────
DEEP_NAVY    = colors.HexColor("#0D1B3E")
ROYAL_BLUE   = colors.HexColor("#1A4A9C")
SKY_BLUE     = colors.HexColor("#3A7BD5")
TEAL         = colors.HexColor("#0F7B6C")
EMERALD      = colors.HexColor("#1D7A4A")
CRIMSON      = colors.HexColor("#C0392B")
ORANGE       = colors.HexColor("#E67E22")
GOLD         = colors.HexColor("#D4A017")
PURPLE       = colors.HexColor("#6C3483")
DARK_PURPLE  = colors.HexColor("#4A235A")
LIGHT_BLUE   = colors.HexColor("#D6EAF8")
LIGHT_TEAL   = colors.HexColor("#D1F2EB")
LIGHT_GREEN  = colors.HexColor("#D5F5E3")
LIGHT_ORANGE = colors.HexColor("#FDEBD0")
LIGHT_PURPLE = colors.HexColor("#E8DAEF")
LIGHT_YELLOW = colors.HexColor("#FEF9E7")
LIGHT_PINK   = colors.HexColor("#FDEDEC")
LIGHT_GREY   = colors.HexColor("#F2F3F4")
WHITE        = colors.white
BLACK        = colors.black
DARK_GREY    = colors.HexColor("#2C3E50")
MID_GREY     = colors.HexColor("#7F8C8D")

# ── Page dimensions ──────────────────────────────────────────────────────────
PAGE_W, PAGE_H = A4  # 595 x 842 pts

# ── Document ─────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT,
    pagesize=A4,
    leftMargin=1.8*cm, rightMargin=1.8*cm,
    topMargin=2.5*cm,  bottomMargin=2.0*cm,
    title="Higher Mental Functions – MD General Medicine Guide",
    author="Orris AI"
)

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

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

TITLE_STYLE = S("DocTitle",
    fontName="Helvetica-Bold", fontSize=26, leading=32,
    textColor=WHITE, alignment=TA_CENTER, spaceAfter=4)

SUBTITLE_STYLE = S("DocSubtitle",
    fontName="Helvetica", fontSize=12, leading=16,
    textColor=colors.HexColor("#BDC3C7"), alignment=TA_CENTER, spaceAfter=2)

PART_STYLE = S("PartHeading",
    fontName="Helvetica-Bold", fontSize=17, leading=22,
    textColor=WHITE, spaceAfter=6, spaceBefore=8)

H2_STYLE = S("H2",
    fontName="Helvetica-Bold", fontSize=13, leading=17,
    textColor=WHITE, spaceAfter=4, spaceBefore=8)

H3_STYLE = S("H3",
    fontName="Helvetica-Bold", fontSize=11, leading=15,
    textColor=DEEP_NAVY, spaceAfter=3, spaceBefore=6)

H4_STYLE = S("H4",
    fontName="Helvetica-Bold", fontSize=10, leading=14,
    textColor=ROYAL_BLUE, spaceAfter=2, spaceBefore=4)

BODY_STYLE = S("Body",
    fontName="Helvetica", fontSize=9.5, leading=14,
    textColor=DARK_GREY, spaceAfter=5, alignment=TA_JUSTIFY)

BODY_BOLD = S("BodyBold",
    fontName="Helvetica-Bold", fontSize=9.5, leading=14,
    textColor=DARK_GREY, spaceAfter=4)

BULLET_STYLE = S("Bullet",
    fontName="Helvetica", fontSize=9.5, leading=13,
    textColor=DARK_GREY, leftIndent=14, firstLineIndent=-10,
    spaceAfter=3)

PEARL_STYLE = S("Pearl",
    fontName="Helvetica-BoldOblique", fontSize=9.5, leading=14,
    textColor=DARK_PURPLE, spaceAfter=4, leftIndent=8, rightIndent=8)

NOTE_STYLE = S("Note",
    fontName="Helvetica-Oblique", fontSize=9, leading=13,
    textColor=TEAL, spaceAfter=4, leftIndent=8)

CODE_STYLE = S("Code",
    fontName="Courier", fontSize=8.5, leading=12,
    textColor=DARK_GREY, spaceAfter=4, leftIndent=10)

SMALL_STYLE = S("Small",
    fontName="Helvetica", fontSize=8, leading=11,
    textColor=MID_GREY, spaceAfter=2)

REF_STYLE = S("Ref",
    fontName="Helvetica-Oblique", fontSize=8, leading=11,
    textColor=MID_GREY, spaceAfter=2, alignment=TA_CENTER)

# ── Helper Flowables ──────────────────────────────────────────────────────────

class ColourBanner(Flowable):
    """A full-width solid colour banner (used for part headings)."""
    def __init__(self, text, bg_color, text_style, height=28, radius=6):
        super().__init__()
        self.text = text
        self.bg_color = bg_color
        self.text_style = text_style
        self.banner_height = height
        self.radius = radius

    def wrap(self, availWidth, availHeight):
        self.avail_w = availWidth
        return (availWidth, self.banner_height + 4)

    def draw(self):
        c = self.canv
        w = self.avail_w
        h = self.banner_height
        r = self.radius
        c.setFillColor(self.bg_color)
        c.roundRect(0, 0, w, h, r, stroke=0, fill=1)
        c.setFillColor(WHITE)
        c.setFont(self.text_style.fontName, self.text_style.fontSize)
        c.drawCentredString(w / 2, h / 2 - self.text_style.fontSize / 3, self.text)


class SideBar(Flowable):
    """A coloured left-side vertical bar with text (for callouts)."""
    def __init__(self, text, bar_color, bg_color, width, style):
        super().__init__()
        self._text = text
        self.bar_color = bar_color
        self.bg_color = bg_color
        self._width = width
        self._style = style

    def wrap(self, availWidth, availHeight):
        from reportlab.platypus import Paragraph
        self.avail_w = availWidth
        p = Paragraph(self._text, self._style)
        _, h = p.wrap(availWidth - 20, availHeight)
        self._h = h + 12
        return (availWidth, self._h)

    def draw(self):
        c = self.canv
        w = self.avail_w
        h = self._h
        c.setFillColor(self.bg_color)
        c.roundRect(0, 0, w, h, 4, stroke=0, fill=1)
        c.setFillColor(self.bar_color)
        c.rect(0, 0, 5, h, stroke=0, fill=1)
        from reportlab.platypus import Paragraph
        p = Paragraph(self._text, self._style)
        p.wrapOn(c, w - 20, h)
        p.drawOn(c, 14, 6)


def spacer(h=6):
    return Spacer(1, h)

def hr(color=SKY_BLUE, thickness=1):
    return HRFlowable(width="100%", thickness=thickness, color=color, spaceAfter=4, spaceBefore=4)

def part_banner(text, color=ROYAL_BLUE):
    return ColourBanner(text, color, PART_STYLE, height=32, radius=6)

def h2_banner(text, color=SKY_BLUE):
    return ColourBanner(text, color, H2_STYLE, height=24, radius=4)

def h3(text):
    return Paragraph(text, H3_STYLE)

def h4(text):
    return Paragraph(text, H4_STYLE)

def body(text):
    return Paragraph(text, BODY_STYLE)

def bold(text):
    return Paragraph(text, BODY_BOLD)

def bullet(text, symbol="•"):
    return Paragraph(f"{symbol} {text}", BULLET_STYLE)

def pearl(text):
    return Paragraph(f"⭐ {text}", PEARL_STYLE)

def note(text):
    return Paragraph(f"📌 {text}", NOTE_STYLE)

def ref(text):
    return Paragraph(text, REF_STYLE)

# ── Table helpers ─────────────────────────────────────────────────────────────

def make_table(data, col_widths=None, header_bg=ROYAL_BLUE, alt_bg=LIGHT_BLUE,
               header_text_color=WHITE):
    """Build a formatted table with coloured header and alternating rows."""
    t = Table(data, colWidths=col_widths, repeatRows=1)
    n_rows = len(data)
    n_cols = len(data[0])

    style_cmds = [
        # Header
        ("BACKGROUND", (0, 0), (-1, 0), header_bg),
        ("TEXTCOLOR",  (0, 0), (-1, 0), header_text_color),
        ("FONTNAME",   (0, 0), (-1, 0), "Helvetica-Bold"),
        ("FONTSIZE",   (0, 0), (-1, 0), 9),
        ("ALIGN",      (0, 0), (-1, 0), "CENTER"),
        ("VALIGN",     (0, 0), (-1, -1), "MIDDLE"),
        ("GRID",       (0, 0), (-1, -1), 0.4, colors.HexColor("#BDC3C7")),
        ("FONTNAME",   (0, 1), (-1, -1), "Helvetica"),
        ("FONTSIZE",   (0, 1), (-1, -1), 8.5),
        ("LEFTPADDING",  (0, 0), (-1, -1), 5),
        ("RIGHTPADDING", (0, 0), (-1, -1), 5),
        ("TOPPADDING",   (0, 0), (-1, -1), 4),
        ("BOTTOMPADDING",(0, 0), (-1, -1), 4),
        ("ROWBACKGROUNDS", (0, 1), (-1, -1), [WHITE, alt_bg]),
    ]
    t.setStyle(TableStyle(style_cmds))
    return t

def cell(text, bold_=False, color=DARK_GREY, size=8.5):
    fn = "Helvetica-Bold" if bold_ else "Helvetica"
    return Paragraph(f'<font name="{fn}" size="{size}" color="{color.hexval() if hasattr(color,"hexval") else "#2C3E50"}">{text}</font>', BODY_STYLE)

# ── Cover Page ────────────────────────────────────────────────────────────────

def cover_page(story):
    # Gradient banner effect with nested rectangles
    story.append(spacer(10))
    story.append(ColourBanner(
        "HIGHER MENTAL FUNCTIONS (HMF)",
        DEEP_NAVY, PART_STYLE, height=60, radius=10
    ))
    story.append(spacer(4))
    story.append(ColourBanner(
        "Complete Bedside Guide for MD General Medicine Final Practical Examinations",
        ROYAL_BLUE, PART_STYLE, height=36, radius=6
    ))
    story.append(spacer(8))
    story.append(Paragraph(
        "Based on: Harrison's 22e · Bradley & Daroff · Adams & Victor · Localization in Clinical Neurology · "
        "Neuroanatomy through Clinical Cases · DeJong's · Bickerstaff's · Macleod's · Oxford Handbook",
        REF_STYLE
    ))
    story.append(spacer(6))
    story.append(hr(GOLD, 2))
    story.append(spacer(4))

    toc_data = [
        [cell("PART", bold_=True, color=WHITE), cell("TOPIC", bold_=True, color=WHITE), cell("COLOUR", bold_=True, color=WHITE)],
        ["1", "Importance of HMF Examination", "Navy Blue"],
        ["2", "Neuroanatomical Basis", "Royal Blue"],
        ["3", "Physiology of HMF", "Teal"],
        ["4", "Bedside Examination (Step-by-Step)", "Emerald Green"],
        ["5", "Mechanisms – Why Abnormalities Occur", "Purple"],
        ["6", "Interpretation – Localization & DDx", "Crimson"],
    ]
    toc = make_table(toc_data, col_widths=[1.5*cm, 12*cm, 3.5*cm],
                     header_bg=DEEP_NAVY, alt_bg=LIGHT_BLUE)
    story.append(toc)
    story.append(spacer(10))
    story.append(hr(GOLD, 2))
    story.append(spacer(4))
    story.append(Paragraph(
        "\"The mental status examination is underway as soon as the physician begins observing and speaking with the patient.\" "
        "— Harrison's Principles of Internal Medicine, 22nd Edition",
        PEARL_STYLE
    ))
    story.append(PageBreak())

# ── PART 1 ────────────────────────────────────────────────────────────────────

def part1(story):
    story.append(part_banner("PART 1: IMPORTANCE OF HMF EXAMINATION", DEEP_NAVY))
    story.append(spacer(6))

    story.append(h2_banner("1.1 Clinical Significance", ROYAL_BLUE))
    story.append(spacer(4))
    story.append(body(
        "Higher Mental Functions (HMF) represent the sum of all cognitive abilities that distinguish human beings — "
        "consciousness, orientation, memory, language, praxis, gnosis, executive function, and visuospatial abilities. "
        "Examining HMF is not a formality; it is the cornerstone of neurological diagnosis."
    ))
    story.append(body(
        "The difference between <b>delirium, dementia, aphasia, and psychiatric illness</b> — conditions with completely "
        "different etiologies, treatments, and prognoses — can only be established at the bedside through careful HMF testing."
    ))
    story.append(spacer(4))

    story.append(h2_banner("1.2 Indications for Detailed HMF Assessment", SKY_BLUE))
    story.append(spacer(4))
    indications = [
        "History raises concern for cognitive or behavioral change",
        "Patient is brought in with altered or reduced consciousness",
        "Family/caregiver reports personality change, forgetfulness, or behavioral disturbance",
        "Patient cannot give a coherent history",
        "Observation-based signs during interview: word-finding difficulty, repetition, poor grooming, disinhibition",
        "Any focal neurological deficit found — always check accompanying HMF",
        "Known systemic illness affecting the brain: hepatic encephalopathy, uraemia, hyponatraemia, thiamine deficiency, HIV, SLE",
        "Elderly patient with falls, incontinence, or gait change (NPH triad)",
        "Post-stroke, post-TBI, post-encephalitis assessment",
        "Suspected dementia, delirium, or frontal lobe syndrome",
    ]
    for i in indications:
        story.append(bullet(i))
    story.append(spacer(4))

    story.append(h2_banner("1.3 When HMF is Absolutely Essential", TEAL))
    story.append(spacer(4))
    data = [
        [cell("Clinical Scenario", bold_=True, color=WHITE), cell("Why It Cannot Be Skipped", bold_=True, color=WHITE)],
        ["Stroke workup", "Aphasia localizes the lesion; neglect indicates non-dominant hemisphere"],
        ["Head injury", "GCS alone is insufficient; HMF documents trajectory"],
        ["Encephalitis (HSV, autoimmune)", "Memory loss and behavioral change are dominant features"],
        ["Delirium vs dementia", "The clinical distinction is made entirely on HMF"],
        ["Frontal lobe lesion", "Motor exam may be normal; only HMF reveals the lesion"],
        ["Pre-operative assessment", "Baseline cognitive function needed for post-op comparison"],
    ]
    story.append(make_table(data, col_widths=[6*cm, 11*cm], header_bg=TEAL, alt_bg=LIGHT_TEAL))
    story.append(spacer(6))

    story.append(h2_banner("1.4 Common Neurological Diseases Affecting HMF", EMERALD))
    story.append(spacer(4))
    data2 = [
        [cell("Disease", bold_=True, color=WHITE), cell("Primary HMF Domains Affected", bold_=True, color=WHITE)],
        ["Alzheimer's Disease", "Episodic memory first, then language (anomia), then praxis, visuospatial"],
        ["Vascular Dementia", "Executive function, psychomotor slowing, patchy deficits"],
        ["Frontotemporal Dementia", "Executive function, personality, language (naming, speech)"],
        ["Lewy Body Dementia", "Visuospatial, executive, fluctuating attention, hallucinations"],
        ["Acute Stroke (MCA dominant)", "Aphasia (Broca or Wernicke), memory"],
        ["Acute Stroke (MCA non-dominant)", "Neglect, anosognosia, visuospatial"],
        ["Herpes Encephalitis", "Anterograde amnesia, behavioral change, temporal lobe"],
        ["Wernicke's Encephalopathy", "Confusion, ophthalmoplegia, ataxia → Korsakoff's amnesia"],
        ["Normal Pressure Hydrocephalus", "Dementia + gait apraxia + urinary incontinence"],
        ["HIV Encephalopathy", "Executive function, psychomotor slowing"],
        ["Delirium (any cause)", "Attention, working memory, fluctuating consciousness — global"],
    ]
    story.append(make_table(data2, col_widths=[6.5*cm, 10.5*cm], header_bg=EMERALD, alt_bg=LIGHT_GREEN))
    story.append(spacer(6))

    story.append(h2_banner("1.5 What Examiners Expect in MD Practicals", CRIMSON))
    story.append(spacer(4))
    story.append(body(
        "Examiners test two things simultaneously: your <b>technique</b> (correct commands, scoring) "
        "and your <b>reasoning</b> (what does an abnormal finding localize to?). They will:"
    ))
    for pt in [
        "Ask you to demonstrate one component (e.g., 'test memory for me')",
        "Follow up: 'What does the finding mean? Where is the lesion?'",
        "Ask: 'What conditions can cause this?'",
        "Ask: 'How does Broca's aphasia differ from Wernicke's aphasia?'",
    ]:
        story.append(bullet(pt, "➤"))
    story.append(pearl(
        "You must be fluent in all six parts: anatomy, physiology, technique, scoring, interpretation, and differential diagnosis."
    ))
    story.append(PageBreak())

# ── PART 2 ────────────────────────────────────────────────────────────────────

def part2(story):
    story.append(part_banner("PART 2: NEUROANATOMICAL BASIS", ROYAL_BLUE))
    story.append(spacer(6))

    story.append(h2_banner("2.1 Cerebral Cortex Overview", ROYAL_BLUE))
    story.append(spacer(4))
    story.append(body(
        "The cerebral cortex contains 6 layers of neurons (neocortex) organized into functional areas described by Brodmann's numbered map."
    ))
    data = [
        [cell("Category", bold_=True, color=WHITE), cell("Areas", bold_=True, color=WHITE), cell("Function", bold_=True, color=WHITE)],
        ["Primary cortices", "1,2,3 / 4 / 17 / 41", "Direct sensory input / motor output"],
        ["Unimodal association", "5,7 / 18,19 / 22", "Process one sensory modality each"],
        ["Heteromodal association", "PFC / IPL / ant. temporal", "Integrate across modalities — substrate of HMF"],
    ]
    story.append(make_table(data, col_widths=[5*cm, 4.5*cm, 7.5*cm], header_bg=ROYAL_BLUE, alt_bg=LIGHT_BLUE))
    story.append(spacer(6))

    story.append(h2_banner("2.2 Frontal Lobe", SKY_BLUE))
    story.append(spacer(4))
    data = [
        [cell("Subregion", bold_=True, color=WHITE), cell("Brodmann Areas", bold_=True, color=WHITE), cell("Function", bold_=True, color=WHITE)],
        ["Primary motor cortex", "Area 4", "Voluntary movement (contralateral)"],
        ["Premotor cortex", "Area 6", "Motor planning, preparation"],
        ["Supplementary motor area", "Area 6 (medial)", "Bilateral motor coordination, initiation"],
        ["Frontal eye fields", "Area 8", "Voluntary conjugate eye movement"],
        ["Broca's area (dominant)", "Areas 44, 45", "Speech production, language output"],
        ["DLPFC", "Areas 9, 46", "Working memory, planning, flexibility, abstract thinking"],
        ["Orbitofrontal cortex", "Areas 10, 11, 47", "Impulse control, reward, emotional regulation"],
        ["Anterior cingulate cortex", "Areas 24, 32", "Motivation, error detection, emotional processing"],
    ]
    story.append(make_table(data, col_widths=[5.5*cm, 3.5*cm, 8*cm], header_bg=SKY_BLUE, alt_bg=LIGHT_BLUE))
    story.append(spacer(4))
    story.append(note(
        "Frontal lobe lesions may produce ZERO motor signs. A patient with a large prefrontal tumour "
        "can have normal power, tone, reflexes — yet be profoundly disinhibited, perseverative, and have "
        "lost all executive function. HMF examination is the ONLY way to detect this."
    ))
    story.append(spacer(6))

    story.append(h2_banner("2.3 Parietal Lobe", TEAL))
    story.append(spacer(4))
    data = [
        [cell("Subregion", bold_=True, color=WHITE), cell("Areas", bold_=True, color=WHITE), cell("Function", bold_=True, color=WHITE)],
        ["Primary somatosensory cortex", "1, 2, 3", "Tactile, pain, temp, proprioception (contralateral)"],
        ["Superior parietal lobule", "5, 7", "Somatosensory association, spatial orientation"],
        ["Supramarginal gyrus (dominant)", "40", "Phonological processing, ideomotor praxis"],
        ["Angular gyrus (dominant)", "39", "Reading, writing, calculation — Gerstmann syndrome"],
    ]
    story.append(make_table(data, col_widths=[5.5*cm, 2.5*cm, 9*cm], header_bg=TEAL, alt_bg=LIGHT_TEAL))
    story.append(spacer(6))

    story.append(h2_banner("2.4 Temporal Lobe", PURPLE))
    story.append(spacer(4))
    data = [
        [cell("Subregion", bold_=True, color=WHITE), cell("Areas", bold_=True, color=WHITE), cell("Function", bold_=True, color=WHITE)],
        ["Primary auditory cortex", "41, 42", "Hearing"],
        ["Wernicke's area (dominant)", "22 + 37,39,40", "Language comprehension"],
        ["Inferior temporal gyrus", "20", "Object recognition, visual memory"],
        ["Fusiform gyrus", "37", "Face recognition — prosopagnosia if damaged"],
        ["Hippocampus (mesial)", "—", "Explicit memory encoding (declarative)"],
        ["Amygdala (mesial)", "—", "Emotional memory, fear conditioning, social behavior"],
        ["Parahippocampal gyrus", "28, 35", "Spatial memory, scene recognition"],
    ]
    story.append(make_table(data, col_widths=[5.5*cm, 2.5*cm, 9*cm], header_bg=PURPLE, alt_bg=LIGHT_PURPLE))
    story.append(spacer(6))

    story.append(h2_banner("2.5 Dominant vs Non-Dominant Hemisphere", CRIMSON))
    story.append(spacer(4))
    story.append(body(
        "<b>Left hemisphere is dominant for language</b> in >95% of right-handed individuals and 60–70% of left-handers "
        "(Neuroanatomy through Clinical Cases 3e). This is one of the most tested topics in MD practicals."
    ))
    story.append(spacer(4))
    data = [
        [cell("Function", bold_=True, color=WHITE), cell("Dominant (usually Left)", bold_=True, color=WHITE), cell("Non-Dominant (usually Right)", bold_=True, color=WHITE)],
        ["Language", "Broca, Wernicke, reading, writing", "Prosody (emotional tone)"],
        ["Praxis", "Ideomotor apraxia if parietal", "Constructional, dressing apraxia"],
        ["Calculation", "Angular gyrus (Gerstmann)", "—"],
        ["Memory", "Verbal memory", "Non-verbal (visuospatial) memory"],
        ["Attention", "—", "Global attention, hemispatial vigilance"],
        ["Spatial awareness", "—", "Right hemisphere dominates global spatial map"],
        ["Anosognosia", "—", "Right lesion → denial of left hemiplegia"],
    ]
    story.append(make_table(data, col_widths=[5*cm, 6*cm, 6*cm], header_bg=CRIMSON, alt_bg=LIGHT_PINK))
    story.append(spacer(4))
    story.append(pearl(
        "VIVA KEY: Why does anosognosia occur with RIGHT hemisphere lesions? Because the right hemisphere maintains "
        "global attention and spatial awareness of the ENTIRE body and extrapersonal space. Left hemisphere lesions "
        "produce aphasia which makes deficits immediately obvious; right hemisphere lesions produce neglect which is subtle."
    ))
    story.append(spacer(6))

    story.append(h2_banner("2.6 Limbic System, Thalamus & ARAS", ORANGE))
    story.append(spacer(4))
    data = [
        [cell("Structure", bold_=True, color=WHITE), cell("Role in HMF", bold_=True, color=WHITE)],
        ["Hippocampus", "Encodes new declarative (explicit) memories; anterograde amnesia if damaged bilaterally"],
        ["Amygdala", "Emotional salience, fear memory, social cognition"],
        ["Fornix → Mamillary bodies", "Papez circuit relay; damaged in Wernicke-Korsakoff"],
        ["Dorsomedial thalamic nucleus", "Projects to PFC; bilateral damage → profound anterograde amnesia"],
        ["Intralaminar thalamic nuclei", "Receive ARAS input → broadcast to cortex → arousal/consciousness"],
        ["Anterior cingulate", "Motivation, attention, error detection"],
        ["ARAS (brainstem → thalamus → cortex)", "Neurophysiological substrate of arousal — norepinephrine, serotonin, ACh, histamine"],
    ]
    story.append(make_table(data, col_widths=[6*cm, 11*cm], header_bg=ORANGE, alt_bg=LIGHT_ORANGE))
    story.append(PageBreak())

# ── PART 3 ────────────────────────────────────────────────────────────────────

def part3(story):
    story.append(part_banner("PART 3: PHYSIOLOGY OF HMF", TEAL))
    story.append(spacer(6))

    physiology_sections = [
        ("3.1 Consciousness", TEAL,
         [
             ("Components", "Arousal (wakefulness) maintained by ARAS → thalamus → cortex; "
              "Awareness (content) maintained by cerebral cortex itself."),
             ("Substrate", "ARAS projects from upper brainstem (locus coeruleus, raphe, pedunculopontine nucleus) "
              "via thalamic intralaminar nuclei to diffusely activate the cortex."),
             ("For normal consciousness", "BOTH intact ARAS AND intact cortex are required. "
              "Explains why GCS tests eye opening (ARAS), verbal response (cortex), and motor response (corticospinal tract)."),
         ]),
        ("3.2 Attention", SKY_BLUE,
         [
             ("Mediated by", "Right prefrontal + right parietal cortex (global sustained attention); "
              "anterior cingulate (error detection); noradrenergic ARAS projections from locus coeruleus."),
             ("Gating function", "Attention is the GATE for all other HMF — you cannot properly test memory, "
              "language, or executive function in an inattentive patient. Always test attention FIRST."),
             ("Right hemisphere dominance", "Right hemisphere directs attention to BOTH sides of space. "
              "Left hemisphere only directs to right hemispace. Therefore right parietal damage → left neglect."),
         ]),
        ("3.3 Memory Organisation", PURPLE,
         [
             ("Declarative (Explicit)", "Conscious recall: Episodic (personal events — hippocampus + frontal) and "
              "Semantic (general facts — temporal neocortex)."),
             ("Non-declarative (Implicit)", "Procedural skills (striatum, cerebellum); priming (neocortex); "
              "emotional conditioning (amygdala)."),
             ("Papez Circuit", "Hippocampus → fornix → mamillary bodies → mamillo-thalamic tract → "
              "anterior thalamus → cingulate gyrus → entorhinal cortex → hippocampus."),
             ("Time frames at bedside", "Immediate (working memory, PFC) → Recent 5–15 min (hippocampal encoding) → "
              "Remote (neocortical long-term stores)."),
         ]),
        ("3.4 Language", ROYAL_BLUE,
         [
             ("Core circuit", "Auditory input → primary auditory cortex (41/42) → Wernicke's area (22) for comprehension "
              "→ arcuate fasciculus → Broca's area (44/45) for production → primary motor cortex (face area) for articulation."),
             ("Classification axes", "FLUENCY (anterior lesion = non-fluent; posterior lesion = fluent) + "
              "COMPREHENSION (intact or impaired) + REPETITION (intact or impaired)."),
             ("Key rule", "In perisylvian aphasias (Broca, Wernicke, Conduction), repetition is ALWAYS impaired. "
              "Outside the perisylvian zone (watershed areas), repetition is SPARED."),
         ]),
        ("3.5 Executive Functions", DARK_PURPLE,
         [
             ("Mediated by", "Dorsolateral prefrontal cortex (DLPFC, areas 9/46) and fronto-striato-thalamo-cortical loops."),
             ("Components", "Working memory; planning & sequencing; cognitive flexibility (set-shifting); "
              "inhibitory control; abstract reasoning."),
             ("Bedside tests", "Serial 7s, verbal fluency, Luria 3-step, go/no-go, similarities, proverb interpretation, "
              "frontal release signs."),
         ]),
        ("3.6 Praxis", EMERALD,
         [
             ("Definition", "Ability to perform learned, purposeful, skilled movements NOT explained by primary motor, "
              "sensory, or coordination deficits."),
             ("Pathway", "Conceptual system (temporal-parietal junction, area 40) → "
              "transcallosal → left SMA and premotor cortex → execution."),
             ("Ideomotor vs Ideational", "Ideomotor: movement concept intact, translation to motor program broken "
              "(parietal or callosal). Ideational: concept itself disrupted (diffuse dominant temporal-parietal)."),
         ]),
        ("3.7 Gnosis & Agnosia", CRIMSON,
         [
             ("Definition (Adams & Victor)", "Conceptual inability to recognize objects, persons, or sensory stimuli "
              "in the ABSENCE of a primary sensory deficit."),
             ("Types", "Visual agnosia (occipital-temporal); prosopagnosia (bilateral fusiform); "
              "astereognosis (contralateral parietal); auditory agnosia (bilateral temporal); "
              "anosognosia (right parietal)."),
             ("Body schema", "Right hemisphere maintains body schema — spatial representation of body and "
              "extrapersonal space. Damage → anosognosia, hemispatial neglect, amorphosynthesis."),
         ]),
    ]

    for title, color, points in physiology_sections:
        story.append(h2_banner(title, color))
        story.append(spacer(4))
        data = [[cell("Aspect", bold_=True, color=WHITE), cell("Detail", bold_=True, color=WHITE)]]
        for aspect, detail in points:
            data.append([aspect, detail])
        bg = {TEAL: LIGHT_TEAL, SKY_BLUE: LIGHT_BLUE, PURPLE: LIGHT_PURPLE,
              ROYAL_BLUE: LIGHT_BLUE, DARK_PURPLE: LIGHT_PURPLE, EMERALD: LIGHT_GREEN,
              CRIMSON: LIGHT_PINK}.get(color, LIGHT_GREY)
        story.append(make_table(data, col_widths=[4.5*cm, 12.5*cm], header_bg=color, alt_bg=bg))
        story.append(spacer(6))

    story.append(PageBreak())

# ── PART 4 ────────────────────────────────────────────────────────────────────

def part4(story):
    story.append(part_banner("PART 4: BEDSIDE EXAMINATION — STEP BY STEP", EMERALD))
    story.append(spacer(4))
    story.append(note(
        "PREPARATION: Introduce yourself. Ensure adequate lighting. Minimise distractions. "
        "Sit at patient's eye level. Note mother tongue, education level, premorbid baseline. "
        "Have ready: pen, paper, common objects (coin, pen, key, comb), watch."
    ))
    story.append(spacer(6))

    # ── 4.1 Level of Consciousness ──
    story.append(h2_banner("4.1 Level of Consciousness", EMERALD))
    story.append(spacer(4))
    story.append(body("<b>Observe before you speak.</b> Are they awake? Drowsy? Maintaining gaze?"))
    steps = [
        ("Step 1", "If patient appears awake, note alertness and appropriateness of responses."),
        ("Step 2", "If not fully alert: Call name clearly — 'Mr. Sharma! Can you open your eyes?' "
         "Note if eyes open spontaneously, to voice, or only to pain."),
        ("Step 3", "If no response to voice: Apply trapezius squeeze or supraorbital ridge pressure. "
         "Distinguish directed responses (cortical) from reflex/spinal responses (triple flexion)."),
    ]
    for step, desc in steps:
        story.append(bullet(f"<b>{step}:</b> {desc}", "▶"))

    story.append(spacer(4))
    story.append(bold("Glasgow Coma Scale (GCS)"))
    gcs_data = [
        [cell("Domain", bold_=True, color=WHITE), cell("Score", bold_=True, color=WHITE), cell("Response", bold_=True, color=WHITE)],
        ["Eye Opening", "4 / 3 / 2 / 1", "Spontaneous / To voice / To pain / None"],
        ["Verbal", "5 / 4 / 3 / 2 / 1", "Oriented / Confused / Inappropriate words / Sounds / None"],
        ["Motor", "6 / 5 / 4 / 3 / 2 / 1", "Obeys / Localizes / Withdrawal / Flex (decorticate) / Ext (decerebrate) / None"],
    ]
    story.append(make_table(gcs_data, col_widths=[4*cm, 3.5*cm, 9.5*cm], header_bg=EMERALD, alt_bg=LIGHT_GREEN))
    story.append(spacer(4))

    desc_data = [
        [cell("Term", bold_=True, color=WHITE), cell("Definition", bold_=True, color=WHITE)],
        ["Alert", "Fully awake, responds appropriately"],
        ["Drowsy / Lethargic", "Sleepy but arousable to voice; returns to sleep quickly"],
        ["Obtunded", "Arousable to vigorous stimulation; slow, confused responses"],
        ["Stupor", "Arousable only to pain; minimal purposeful responses"],
        ["Coma", "Unarousable; no purposeful response to any stimulus"],
    ]
    story.append(make_table(desc_data, col_widths=[5*cm, 12*cm], header_bg=DARK_GREY, alt_bg=LIGHT_GREY))
    story.append(spacer(4))
    story.append(pearl("VIVA: Never just say 'the patient is confused.' Always report GCS (E_V_M_), "
                       "what stimulus was required, and what response was obtained."))
    story.append(spacer(6))

    # ── 4.2 Orientation ──
    story.append(h2_banner("4.2 Orientation (Time → Place → Person)", TEAL))
    story.append(spacer(4))
    story.append(body("Test in this order: Time fails FIRST in disease, so it is the most sensitive indicator."))
    orient_data = [
        [cell("Domain", bold_=True, color=WHITE), cell("Questions to Ask", bold_=True, color=WHITE)],
        ["Person", "'What is your full name?' / 'How old are you?'"],
        ["Place", "'Where are you right now?' / 'Which hospital/city/state?'"],
        ["Time", "'What is today's date?' / 'Day of the week?' / 'Season?' / 'Approximate time of day?'"],
    ]
    story.append(make_table(orient_data, col_widths=[3.5*cm, 13.5*cm], header_bg=TEAL, alt_bg=LIGHT_TEAL))
    story.append(spacer(4))
    story.append(note(
        "Bradley's: Patients off 3 days on date, 2 days on day of week, or 4 hours on time may be "
        "significantly disoriented to time."
    ))
    story.append(spacer(6))

    # ── 4.3 Attention ──
    story.append(h2_banner("4.3 Attention and Concentration", SKY_BLUE))
    story.append(spacer(4))
    story.append(pearl("Always test attention BEFORE memory — an inattentive patient will fail memory tests falsely."))
    story.append(spacer(4))

    attn_data = [
        [cell("Test", bold_=True, color=WHITE), cell("Method", bold_=True, color=WHITE), cell("Normal", bold_=True, color=WHITE)],
        ["Digit Span Forward",
         "'I will say numbers. Repeat in the same order.' Start 3 digits → 7+. 1 digit/sec.",
         "7 ± 2 digits"],
        ["Digit Span Backward",
         "'Now say them in REVERSE order.' (e.g., 2-4 → say 4-2)",
         "5 ± 2 digits"],
        ["Serial 7s",
         "'Start at 100, subtract 7 each time.' (93, 86, 79, 72, 65) — 5 subtractions.",
         "≤1 error"],
        ["WORLD backwards",
         "'Spell WORLD backwards.' (D-L-R-O-W)",
         "Correct"],
        ["A-Vigilance",
         "Read letters 1/sec — patient taps every time they hear 'A'.",
         "No omissions or commission errors"],
    ]
    story.append(make_table(attn_data, col_widths=[4*cm, 9.5*cm, 3.5*cm], header_bg=SKY_BLUE, alt_bg=LIGHT_BLUE))
    story.append(spacer(6))

    # ── 4.4 Memory ──
    story.append(h2_banner("4.4 Memory Examination", PURPLE))
    story.append(spacer(4))

    mem_data = [
        [cell("Time Frame", bold_=True, color=WHITE), cell("Test", bold_=True, color=WHITE), cell("Normal", bold_=True, color=WHITE), cell("Lesion if Impaired", bold_=True, color=WHITE)],
        ["Immediate\n(Working Memory)",
         "Say 3 words (Apple–Table–Penny). Ask immediate repetition.",
         "Repeats all 3",
         "Prefrontal cortex (PFC)"],
        ["Recent Memory\n(5–15 min)",
         "Recall same 3 words at 5 min (continue other tests during interval). If fails free recall → try semantic cue → then recognition.",
         "3/3 at 5 min",
         "Hippocampus (mesial temporal)"],
        ["Remote Memory\n(Long-term)",
         "DOB, personal history, historical events (PM of India, COVID), children's names. Verify with informant.",
         "Coherent chronological history",
         "Neocortical networks; if impaired early → semantic dementia"],
    ]
    story.append(make_table(mem_data, col_widths=[3*cm, 7*cm, 3*cm, 4*cm], header_bg=PURPLE, alt_bg=LIGHT_PURPLE))
    story.append(spacer(4))
    story.append(note(
        "If patient fails free recall → provide semantic cue ('One was a fruit') → then recognition ('Was it apple, mango, or banana?'). "
        "Encoding failure = fails all 3 options. Retrieval failure = benefits from cue or recognition."
    ))
    story.append(spacer(6))

    # ── 4.5 Language ──
    story.append(h2_banner("4.5 Language Examination", ROYAL_BLUE))
    story.append(spacer(4))

    lang_steps = [
        ("Spontaneous Speech", "Observe during history. Is speech <b>fluent</b> (≥6 words/phrase, effortless) or "
         "<b>non-fluent</b> (effortful, telegraphic, agrammatic)? Are there paraphasias (phonemic, semantic, neologisms)?"),
        ("Naming", "Show pen → 'What is this?' Then: 'And this part?' (cap/clip/nib). "
         "Anomia occurs in ALL aphasias. Benefits from phonemic cue = Broca; No benefit = Wernicke/semantic."),
        ("Comprehension", "'Is your name [X]?' (yes/no) → 'Point to ceiling... floor... window' (single-step) → "
         "'Take paper in right hand, fold in half, put on floor' (3-step command)."),
        ("Repetition", "'Please repeat: No ifs, ands, or buts.' "
         "IMPAIRED in perisylvian aphasias; INTACT in transcortical aphasias."),
        ("Reading", "Show written card: CLOSE YOUR EYES. 'Read this and do what it says.'"),
        ("Writing", "Give pen and paper: 'Write a complete sentence about anything.'"),
    ]
    for step, detail in lang_steps:
        story.append(bullet(f"<b>{step}:</b> {detail}", "➤"))
    story.append(spacer(6))

    story.append(bold("Aphasia Classification — The Most Important Table in HMF"))
    aphasia_data = [
        [cell("Type", bold_=True, color=WHITE), cell("Fluency", bold_=True, color=WHITE),
         cell("Comprehension", bold_=True, color=WHITE), cell("Repetition", bold_=True, color=WHITE),
         cell("Lesion", bold_=True, color=WHITE)],
        ["Broca", "NON-fluent", "Intact*", "IMPAIRED", "Dominant inf. frontal gyrus (44/45)"],
        ["Wernicke", "FLUENT", "IMPAIRED", "IMPAIRED", "Dominant post. sup. temporal (22)"],
        ["Conduction", "Fluent", "Intact", "SEVERELY impaired", "Arcuate fasciculus / SM gyrus (40)"],
        ["Global", "NON-fluent", "IMPAIRED", "IMPAIRED", "Large dominant MCA territory"],
        ["Transcortical Motor", "NON-fluent", "Intact", "INTACT ✓", "SMA, ant. cingulate (above Broca)"],
        ["Transcortical Sensory", "Fluent", "IMPAIRED", "INTACT ✓", "Posterior watershed, TPJ"],
        ["Anomic", "Fluent", "Intact", "Intact", "Angular gyrus (39) or any cortical"],
    ]
    story.append(make_table(aphasia_data, col_widths=[3.5*cm, 2.5*cm, 3*cm, 3*cm, 5*cm], header_bg=ROYAL_BLUE, alt_bg=LIGHT_BLUE))
    story.append(spacer(4))
    story.append(pearl(
        "MEMORY HOOK: Perisylvian zone (Broca → arcuate fasciculus → Wernicke) → repetition ALWAYS impaired. "
        "Outside perisylvian zone (watershed areas) → repetition SPARED. This is the single most reliable rule."
    ))
    story.append(spacer(4))

    story.append(bold("Speech vs Language — Critical Distinction"))
    sv_data = [
        [cell("Feature", bold_=True, color=WHITE), cell("Speech Disorder (Dysarthria)", bold_=True, color=WHITE), cell("Language Disorder (Aphasia)", bold_=True, color=WHITE)],
        ["What is affected?", "Motor execution of articulation", "The language system itself"],
        ["Content", "Normal content, garbled execution", "Abnormal content (paraphasia, agrammatism)"],
        ["Writing", "NORMAL", "ALSO abnormal"],
        ["Comprehension", "Normal", "May be impaired"],
        ["Lesion", "LMN/UMN/cerebellar/extrapyramidal", "Dominant hemisphere cortex"],
    ]
    story.append(make_table(sv_data, col_widths=[4*cm, 6*cm, 7*cm], header_bg=DARK_GREY, alt_bg=LIGHT_GREY))
    story.append(spacer(6))

    # ── 4.6 Calculation, Abstract Thinking, Judgment/Insight ──
    story.append(h2_banner("4.6 Calculation · Abstract Thinking · Judgment · Insight", ORANGE))
    story.append(spacer(4))
    cog_data = [
        [cell("Component", bold_=True, color=WHITE), cell("Bedside Test", bold_=True, color=WHITE), cell("Abnormal = Lesion", bold_=True, color=WHITE)],
        ["Calculation",
         "'7+8=?' / '15-6=?' / '9×7=?' / Serial 7s.",
         "Acalculia in isolation = angular gyrus (39) — Gerstmann"],
        ["Abstract Thinking (Similarities)",
         "'How are apple and orange alike?' (Abstract: both are fruits; Concrete: both round)",
         "Concrete responses = frontal lobe dysfunction"],
        ["Proverb Interpretation",
         "'What does a rolling stone gathers no moss mean?'",
         "Literal/concrete interpretation = frontal lobe"],
        ["Judgment",
         "'What would you do if you found a sealed stamped envelope on the street?' (Normal: post it)",
         "Poor judgment = frontal lobe, dementia, psychiatric"],
        ["Insight",
         "'What do you think is wrong with you?' / 'Do you think you have a memory problem?'",
         "No insight (anosognosia) = right parietal (organic) or psychiatric"],
    ]
    story.append(make_table(cog_data, col_widths=[4*cm, 7*cm, 6*cm], header_bg=ORANGE, alt_bg=LIGHT_ORANGE))
    story.append(spacer(6))

    # ── 4.7 Visuospatial ──
    story.append(h2_banner("4.7 Visuospatial Ability", TEAL))
    story.append(spacer(4))
    vs_data = [
        [cell("Test", bold_=True, color=WHITE), cell("Method", bold_=True, color=WHITE), cell("What is Tested", bold_=True, color=WHITE)],
        ["Clock Drawing Test",
         "'Draw a clock showing 10 past 11.' Assess: circle, number placement, hand placement.",
         "Visuoconstructional + planning + numeric knowledge"],
        ["Pentagon Copying (MMSE)",
         "Show intersecting pentagons. 'Copy this drawing exactly.'",
         "Visuoconstructional ability — parietal"],
        ["Line Bisection",
         "Draw 20 cm line. 'Mark the centre.' Normal = within 1 cm.",
         "Hemispatial neglect (right parietal → bisects right of center)"],
        ["Figure Drawing from Memory",
         "'Draw a house / flower / bicycle from memory.'",
         "Visuospatial + constructional"],
    ]
    story.append(make_table(vs_data, col_widths=[3.5*cm, 8*cm, 5.5*cm], header_bg=TEAL, alt_bg=LIGHT_TEAL))
    story.append(spacer(6))

    # ── 4.8 Praxis ──
    story.append(h2_banner("4.8 Praxis Examination", EMERALD))
    story.append(spacer(4))
    praxis_data = [
        [cell("Type", bold_=True, color=WHITE), cell("Test Commands", bold_=True, color=WHITE), cell("Grading", bold_=True, color=WHITE)],
        ["Ideomotor Apraxia",
         "1. On command: 'Show me how you would wave goodbye / comb hair / use a toothbrush / hammer a nail.'\n"
         "2. Imitation: 'Do exactly what I do.' (demonstrate)\n"
         "3. With actual object: hand the object and say 'Please use this.'",
         "Normal: correct on verbal command\nMild: needs imitation\nModerate: needs object\nSevere: fails with object"],
        ["Constructional Apraxia",
         "Copy geometric figures, clock drawing, intersecting pentagons.",
         "Errors = parietal (bilateral, worse non-dominant)"],
        ["Oral Apraxia",
         "'Stick out tongue / blow out candle / cough / whistle.'",
         "Impaired in Broca's aphasia, opercular syndrome"],
        ["Gait Apraxia",
         "Ask patient to walk. Observe initiation, stride length, foot clearance.",
         "Magnetic gait + normal limb exam = frontal gait apraxia (NPH)"],
    ]
    story.append(make_table(praxis_data, col_widths=[3.5*cm, 9*cm, 4.5*cm], header_bg=EMERALD, alt_bg=LIGHT_GREEN))
    story.append(spacer(6))

    # ── 4.9 Agnosia & Neglect ──
    story.append(h2_banner("4.9 Agnosia and Hemispatial Neglect", CRIMSON))
    story.append(spacer(4))
    agn_data = [
        [cell("Test", bold_=True, color=WHITE), cell("Method", bold_=True, color=WHITE), cell("Significance", bold_=True, color=WHITE)],
        ["Visual Object Agnosia",
         "'Without touching it, what is this?' If fails: 'Show me what you'd do with it.'",
         "Visual agnosia = occipital-temporal; not a naming problem"],
        ["Prosopagnosia",
         "Show photo of famous person. 'Do you recognise this person?'",
         "Bilateral fusiform / inf. temporal lesion"],
        ["Astereognosis",
         "Eyes closed, common object in hand. 'What is this?' Fails touch, passes vision.",
         "Contralateral parietal cortex"],
        ["Anosognosia",
         "'Can you raise your left arm?' / 'Is there anything wrong with your left arm?'",
         "Right parietal lesion"],
        ["Line Bisection",
         "20 cm line — 'Mark the centre.' Bisects to right of centre.",
         "Left hemispatial neglect — right parietal"],
        ["Letter Cancellation",
         "Cancel all letter A / stars on a page. Misses left-sided targets.",
         "Left hemispatial neglect — right parietal"],
        ["Extinction",
         "Single stimulation each side — normal. Bilateral simultaneous — reports only right side.",
         "Right parietal — subtle neglect"],
    ]
    story.append(make_table(agn_data, col_widths=[3.5*cm, 8*cm, 5.5*cm], header_bg=CRIMSON, alt_bg=LIGHT_PINK))
    story.append(spacer(6))

    # ── 4.10 Frontal Tests ──
    story.append(h2_banner("4.10 Frontal Lobe Tests", DARK_PURPLE))
    story.append(spacer(4))
    frontal_data = [
        [cell("Test", bold_=True, color=WHITE), cell("Method", bold_=True, color=WHITE), cell("Abnormal Response", bold_=True, color=WHITE)],
        ["Luria 3-Step Sequence",
         "Demonstrate: Palm → Side → Fist (3×). 'Now you do it.'",
         "Perseverates on one position; loses sequence; mirrors examiner"],
        ["Verbal Fluency — Phonemic",
         "'Name words beginning with F. 1 minute. No proper nouns.'",
         "<12 words/min = frontal initiation deficit"],
        ["Verbal Fluency — Semantic",
         "'Name animals. 1 minute.'",
         "<12 animals/min = temporal semantic memory or frontal"],
        ["Grasp Reflex",
         "Stroke palm from thenar toward fingers.",
         "Involuntary gripping = frontal disinhibition"],
        ["Snout Reflex",
         "Tap lips with finger.",
         "Lip puckering/pouting = frontal release sign"],
        ["Glabellar Tap",
         "Repeatedly tap glabella.",
         "Fails to habituate after 2–3 taps = frontal / Parkinson's"],
        ["Palmomental Reflex",
         "Scratch thenar eminence briskly.",
         "Ipsilateral chin dimpling (non-specific alone)"],
    ]
    story.append(make_table(frontal_data, col_widths=[3.5*cm, 7.5*cm, 6*cm], header_bg=DARK_PURPLE, alt_bg=LIGHT_PURPLE))
    story.append(spacer(6))

    # ── 4.11 MMSE ──
    story.append(h2_banner("4.11 Mini-Mental State Examination (MMSE) — Full 30-Point Scale", ROYAL_BLUE))
    story.append(spacer(4))
    mmse_data = [
        [cell("Component", bold_=True, color=WHITE), cell("Task", bold_=True, color=WHITE), cell("Points", bold_=True, color=WHITE)],
        ["Orientation — Time", "Year / Season / Date / Day / Month", "5"],
        ["Orientation — Place", "Country / State / City / Hospital / Floor", "5"],
        ["Registration", "Name 3 objects, patient repeats immediately", "3"],
        ["Attention / Calculation", "Serial 7s (5 subtractions) OR spell WORLD backwards", "5"],
        ["Recall", "Recall the 3 registered objects at ~5 minutes", "3"],
        ["Naming", "Name a pencil and a watch", "2"],
        ["Repetition", "'No ifs, ands, or buts'", "1"],
        ["3-Step Command", "'Take paper in right hand, fold in half, put on floor'", "3"],
        ["Reading", "Read and obey 'CLOSE YOUR EYES'", "1"],
        ["Writing", "Write a complete spontaneous sentence", "1"],
        ["Construction", "Copy two intersecting pentagons", "1"],
        ["TOTAL", "", "30"],
    ]
    story.append(make_table(mmse_data, col_widths=[5*cm, 10*cm, 2*cm], header_bg=ROYAL_BLUE, alt_bg=LIGHT_BLUE))
    story.append(spacer(4))
    score_data = [
        [cell("Score", bold_=True, color=WHITE), cell("Interpretation", bold_=True, color=WHITE)],
        ["27–30", "Normal"],
        ["24–26", "Borderline / Mild impairment"],
        ["20–23", "Mild dementia"],
        ["10–19", "Moderate dementia"],
        ["<10", "Severe dementia"],
    ]
    story.append(make_table(score_data, col_widths=[3*cm, 14*cm], header_bg=DARK_GREY, alt_bg=LIGHT_GREY))
    story.append(spacer(4))
    story.append(pearl(
        "LIMITATIONS: MMSE misses executive dysfunction and early cognitive impairment. "
        "A patient with early Alzheimer's or frontal dementia may score 28/30 yet have profound functional impairment. "
        "MoCA (≥26/30 normal) is more sensitive for MCI — tests executive function, has clock drawing, better ceiling."
    ))
    story.append(PageBreak())

    # ── Presentation Template ──
    story.append(h2_banner("4.12 Bedside Presentation Template for MD Examination", GOLD))
    story.append(spacer(4))
    template_text = (
        "\"I examined the higher mental functions of this patient. The patient was [alert/drowsy/obtunded], "
        "GCS [E_V_M_]. Orientation was [intact/impaired — specify domains]. Attention was [intact/impaired — "
        "digit span forward ___/backward ___, serial 7s: ___ errors]. Immediate memory was [intact/impaired]. "
        "Recent memory was [intact/impaired — recalled ___/3 words at 5 minutes with/without cueing]. "
        "Remote memory was [intact/impaired].\n\n"
        "Language: speech was [fluent/non-fluent] with [present/absent] paraphasias. Comprehension was "
        "[intact/impaired] on [single-step/three-step commands]. Repetition was [intact/impaired]. "
        "Naming was [intact/impaired]. Reading and writing were [intact/impaired].\n\n"
        "Executive functions: serial 7s [___ errors], verbal fluency [F-words: ___], abstraction "
        "[concrete/abstract]. Judgment and insight were [intact/impaired].\n\n"
        "Visuospatial function: clock drawing [intact/impaired — describe errors]. Figure copying [intact/impaired]. "
        "Praxis: [intact/impaired — ideomotor/constructional]. Neglect: [absent/present — describe test results]. "
        "Frontal release signs: [absent/present — specify].\n\n"
        "In summary, the pattern is consistent with [localization] most likely due to [diagnosis], because [reason].\""
    )
    story.append(SideBar(template_text, GOLD, LIGHT_YELLOW,
                         doc.width, NOTE_STYLE))
    story.append(PageBreak())

# ── PART 5 ────────────────────────────────────────────────────────────────────

def part5(story):
    story.append(part_banner("PART 5: MECHANISMS — WHY ABNORMALITIES OCCUR", PURPLE))
    story.append(spacer(6))

    mechanisms = [
        ("Broca's Aphasia", ROYAL_BLUE, [
            ("Anatomy", "Left inferior frontal gyrus (areas 44/45) + surrounding perisylvian cortex "
             "(postcentral + supramarginal gyrus 40 + underlying white matter)."),
            ("Why non-fluent", "Broca's area is the motor sequencing centre for speech. Damage disrupts the ability "
             "to generate fluent, grammatically organized motor speech programs. Output is effortful, telegraphic "
             "(content words preserved, function words absent = agrammatism)."),
            ("Why repetition impaired", "Arcuate fasciculus enters the Broca complex; damage disrupts the "
             "phonological motor loop needed for accurate repetition."),
            ("Why comprehension relatively spared", "Wernicke's area is intact. Single words and simple sentences "
             "can still be decoded."),
            ("Why patient is depressed/frustrated", "Full insight (comprehension intact) but cannot express themselves."),
        ]),
        ("Wernicke's Aphasia", TEAL, [
            ("Anatomy", "Left posterior superior temporal gyrus (area 22) + adjacent areas 37, 39, 40."),
            ("Why fluent", "Broca's area and connections to primary motor cortex are intact. Speech production circuits unaffected."),
            ("Why paraphasic", "Without feedback from the intact phonological mapping system (damaged), patient cannot "
             "monitor phonological accuracy of output. Substitutions occur unchecked."),
            ("Why repetition impaired", "Comprehension of heard phrase is necessary for accurate repetition. Without "
             "decoding what was said, repetition is impossible."),
            ("Why patient unaware/agitated", "Comprehension impairment means patient cannot monitor correctness of own "
             "speech. Can produce paranoid agitation."),
        ]),
        ("Conduction Aphasia", SKY_BLUE, [
            ("Anatomy", "Arcuate fasciculus (white matter connecting Wernicke's posteriorly to Broca's anteriorly). "
             "Supramarginal gyrus (area 40) is the cortical component."),
            ("Specific disruption", "Disconnection of posterior phonological representation from anterior motor speech system."),
            ("Why repetition disproportionately impaired", "Repetition requires exact phonological transmission through "
             "arcuate fasciculus. Phonemic paraphasias occur on repetition; patient hears errors and struggles to "
             "self-correct (conduit d'approche: repeated attempts with progressive approximation)."),
        ]),
        ("Hippocampal Amnesia", PURPLE, [
            ("Mechanism", "New memories cannot be encoded (consolidated into long-term stores). Working memory (PFC) "
             "is spared. Remote memory (neocortical networks) relatively spared."),
            ("Patient lives in an eternal present", "Papez circuit is disrupted. Hippocampus cannot pass "
             "information to mamillary bodies → anterior thalamus → cingulate → neocortex."),
        ]),
        ("Korsakoff Amnesia + Confabulation", ORANGE, [
            ("Anatomy", "Bilateral mamillary body damage (+ dorsomedial thalamic nucleus) disrupts Papez circuit relay. "
             "Fornix output cannot reach thalamo-cingulate system for consolidation."),
            ("Why confabulation", "Prefrontal orbitofrontal monitoring systems are also damaged (thiamine-dependent). "
             "Without frontal monitoring, false memories are produced without awareness. Patient generates plausible "
             "but incorrect accounts without the ability to suppress or evaluate them."),
        ]),
        ("Hemispatial Neglect", CRIMSON, [
            ("Right hemisphere dominance", "Right parietal directs attention to BOTH sides of space. Left parietal "
             "only directs to right hemispace. Therefore: left parietal lesion → right parietal compensates → minimal neglect. "
             "Right parietal lesion → no compensation → severe sustained left neglect."),
            ("Anosognosia mechanism (Adams & Victor)", "Right hemisphere maintains body schema — spatial representation "
             "of body and extrapersonal space. Damage means the monitoring system itself is offline. Patient does not "
             "refuse to acknowledge the problem; the neural machinery for awareness of that body part is destroyed."),
        ]),
        ("Frontal Lobe Syndrome", DARK_PURPLE, [
            ("DLPFC lesion", "Loss of working memory, planning, cognitive flexibility. Cannot hold information in mind "
             "while manipulating it. Perseverates — cannot shift set. Concrete thinking — cannot abstract."),
            ("Orbitofrontal lesion", "Loss of impulse control, reward evaluation, emotional regulation. "
             "Disinhibition, inappropriate social behavior, Witzelsucht (pathological jocularity)."),
            ("Anterior cingulate lesion", "Apathy, abulia, loss of motivation, akinetic mutism in severe cases. "
             "No motor deficit — patient CAN move, but has no drive to initiate."),
        ]),
    ]

    for title, color, points in mechanisms:
        story.append(h2_banner(title, color))
        story.append(spacer(4))
        data = [[cell("Aspect", bold_=True, color=WHITE), cell("Mechanism", bold_=True, color=WHITE)]]
        for aspect, detail in points:
            data.append([aspect, detail])
        bg = {ROYAL_BLUE: LIGHT_BLUE, TEAL: LIGHT_TEAL, SKY_BLUE: LIGHT_BLUE,
              PURPLE: LIGHT_PURPLE, ORANGE: LIGHT_ORANGE, CRIMSON: LIGHT_PINK,
              DARK_PURPLE: LIGHT_PURPLE}.get(color, LIGHT_GREY)
        story.append(make_table(data, col_widths=[4.5*cm, 12.5*cm], header_bg=color, alt_bg=bg))
        story.append(spacer(6))

    story.append(PageBreak())

# ── PART 6 ────────────────────────────────────────────────────────────────────

def part6(story):
    story.append(part_banner("PART 6: INTERPRETATION — LOCALIZATION & DIFFERENTIAL DIAGNOSIS", CRIMSON))
    story.append(spacer(6))

    story.append(h2_banner("6.1 Aphasia Localization Summary", ROYAL_BLUE))
    story.append(spacer(4))
    aph_loc = [
        [cell("Aphasia", bold_=True, color=WHITE), cell("Lesion Site", bold_=True, color=WHITE),
         cell("Associated Signs", bold_=True, color=WHITE), cell("Common Causes", bold_=True, color=WHITE)],
        ["Broca", "Dominant inferior frontal (44/45) + surrounding cortex",
         "Right hemiparesis (face/arm), right lower facial droop",
         "MCA superior division stroke, glioma, abscess"],
        ["Wernicke", "Dominant post. sup. temporal (22)",
         "Often NO hemiparesis; right superior visual field defect",
         "MCA inferior division stroke, HSV encephalitis, glioma"],
        ["Conduction", "Arcuate fasciculus / supramarginal gyrus (40)",
         "Mild arm/hand weakness possible",
         "MCA branch, Rolandic/parietal infarct"],
        ["Global", "Large dominant MCA territory (frontal+temporal+parietal)",
         "Dense right hemiplegia, hemianopia, hemisensory loss",
         "Complete MCA occlusion, ICA occlusion"],
        ["Transcortical Motor", "SMA, anterior cingulate, above Broca's",
         "Reduced spontaneous speech, right leg weakness",
         "ACA territory stroke, parasagittal meningioma"],
        ["Transcortical Sensory", "Posterior watershed, angular/TPJ",
         "May have right visual field defect",
         "ICA stenosis watershed infarct"],
        ["Anomic", "Angular gyrus (39) or diffuse",
         "May be isolated",
         "Early AD, any focal lesion, metabolic encephalopathy"],
    ]
    story.append(make_table(aph_loc, col_widths=[3*cm, 5*cm, 4.5*cm, 4.5*cm], header_bg=ROYAL_BLUE, alt_bg=LIGHT_BLUE))
    story.append(spacer(4))
    story.append(pearl(
        "RED FLAG: Wernicke's aphasia without hemiparesis is frequently misdiagnosed as acute psychosis. "
        "Any acute fluent aphasia without known etiology requires HSV PCR in CSF."
    ))
    story.append(spacer(6))

    story.append(h2_banner("6.2 Memory Disorders — Localization", PURPLE))
    story.append(spacer(4))
    mem_loc = [
        [cell("Pattern", bold_=True, color=WHITE), cell("Localization", bold_=True, color=WHITE), cell("DDx", bold_=True, color=WHITE)],
        ["Anterograde amnesia — no confabulation",
         "Bilateral hippocampi",
         "HSV encephalitis, bilateral PCA infarcts, early AD"],
        ["Anterograde amnesia + confabulation",
         "Mamillary bodies + DM thalamus",
         "Wernicke-Korsakoff, bilateral thalamic infarcts, ruptured AComA aneurysm"],
        ["Transient global amnesia",
         "Hippocampus (reversible ischemia/venous)",
         "TGA: no seizure, no focal deficit, resolves <24h"],
        ["Semantic memory loss (words, faces, concepts)",
         "Anterior temporal neocortex (asymmetric)",
         "Semantic variant FTD (semantic dementia)"],
        ["Working memory impaired, episodic spared",
         "Prefrontal cortex, DLPFC",
         "Frontal lobe lesion, delirium, ADHD"],
    ]
    story.append(make_table(mem_loc, col_widths=[5.5*cm, 5*cm, 6.5*cm], header_bg=PURPLE, alt_bg=LIGHT_PURPLE))
    story.append(spacer(6))

    story.append(h2_banner("6.3 Apraxia — Localization", EMERALD))
    story.append(spacer(4))
    apr_loc = [
        [cell("Type", bold_=True, color=WHITE), cell("Localization", bold_=True, color=WHITE), cell("Bedside Finding", bold_=True, color=WHITE)],
        ["Ideomotor apraxia", "Left inferior parietal (area 40), left SMA, corpus callosum",
         "Fails pantomime on command; improves with imitation or object"],
        ["Ideational apraxia", "Dominant temporal-parietal, diffuse",
         "Cannot complete multi-step sequential tasks even with objects"],
        ["Constructional apraxia", "Parietal (bilateral, worse non-dominant)",
         "Fails figure copying, clock drawing"],
        ["Dressing apraxia", "Right parietal",
         "Cannot orient clothing correctly to body in space"],
        ["Gait apraxia", "Bilateral frontal (SMA, premotor)",
         "Magnetic gait; normal motor exam in upper limbs"],
    ]
    story.append(make_table(apr_loc, col_widths=[4*cm, 6*cm, 7*cm], header_bg=EMERALD, alt_bg=LIGHT_GREEN))
    story.append(spacer(6))

    story.append(h2_banner("6.4 Dementia Syndromes — Pattern Recognition", ORANGE))
    story.append(spacer(4))
    dem_data = [
        [cell("Type", bold_=True, color=WHITE), cell("First HMF Affected", bold_=True, color=WHITE),
         cell("Pattern of Spread", bold_=True, color=WHITE), cell("Key Distinguishing Feature", bold_=True, color=WHITE)],
        ["Alzheimer's Disease",
         "Episodic memory (recent > remote)",
         "Memory → anomia → praxis → visuospatial → executive",
         "Temporal gradient; benefits from scaffolded cues initially"],
        ["Frontotemporal Dementia (bvFTD)",
         "Personality, executive, social judgment",
         "Frontal → temporal lobes",
         "Dramatic personality change; disinhibition / apathy; early frontal release signs"],
        ["Semantic Dementia (svFTD)",
         "Semantic memory — loss of word meanings, face recognition",
         "Progressive asymmetric temporal",
         "Cannot name or understand words despite fluent spontaneous speech"],
        ["Vascular Dementia",
         "Patchy — executive, psychomotor slowing",
         "Step-wise progression",
         "Vascular risk factors; focal signs; neuroimaging shows infarcts/WMH"],
        ["Lewy Body Dementia",
         "Visuospatial, attention, executive",
         "Fluctuating; visual hallucinations; parkinsonism",
         "REM sleep behaviour disorder; sensitivity to antipsychotics"],
        ["Korsakoff Syndrome",
         "Anterograde amnesia + confabulation",
         "Does NOT progress like degenerative dementia",
         "History of alcoholism; thiamine deficiency; mamillary body atrophy on MRI"],
        ["Normal Pressure Hydrocephalus",
         "Attention, executive function",
         "Plus gait apraxia + urinary urgency/incontinence",
         "Hakim's triad; responds to CSF diversion; large ventricles on imaging"],
    ]
    story.append(make_table(dem_data, col_widths=[3.5*cm, 4*cm, 4.5*cm, 5*cm], header_bg=ORANGE, alt_bg=LIGHT_ORANGE))
    story.append(spacer(6))

    story.append(h2_banner("6.5 Frontal Lobe Syndrome — Localisation & DDx", DARK_PURPLE))
    story.append(spacer(4))
    fr_data = [
        [cell("Circuit", bold_=True, color=WHITE), cell("Clinical Features", bold_=True, color=WHITE), cell("DDx", bold_=True, color=WHITE)],
        ["DLPFC (areas 9/46)",
         "Poor planning, perseveration, concrete thinking, impaired working memory, loss of cognitive flexibility",
         "Glioma, trauma, FTD, large AComA rupture"],
        ["Orbitofrontal (10/11/47)",
         "Disinhibition, impulsivity, inappropriate social behavior, Witzelsucht, poor decision-making",
         "Meningioma (olfactory groove/sphenoid wing), FTD, OFC contusion"],
        ["Anterior cingulate (24/32)",
         "Apathy, abulia, loss of initiation, akinetic mutism (severe)",
         "ACA infarct, hydrocephalus, bilateral mesial frontal glioma"],
    ]
    story.append(make_table(fr_data, col_widths=[4.5*cm, 7.5*cm, 5*cm], header_bg=DARK_PURPLE, alt_bg=LIGHT_PURPLE))
    story.append(spacer(4))
    story.append(pearl(
        "RED FLAG: New personality change in adults >50 years always requires brain imaging to exclude frontal neoplasm."
    ))
    story.append(spacer(6))

    story.append(h2_banner("6.6 Gerstmann Syndrome", TEAL))
    story.append(spacer(4))
    gest_data = [
        [cell("Component", bold_=True, color=WHITE), cell("Test", bold_=True, color=WHITE)],
        ["Finger agnosia", "Eyes closed — touch a finger — 'Which finger did I touch?'"],
        ["Acalculia", "Simple and serial arithmetic — 'What is 9 × 7?'"],
        ["Agraphia", "'Write a complete sentence.' (pure agraphia — no other aphasia)"],
        ["Right-left disorientation", "'Show me your right hand.' / 'Touch your left ear with your right hand.'"],
    ]
    story.append(make_table(gest_data, col_widths=[5*cm, 12*cm], header_bg=TEAL, alt_bg=LIGHT_TEAL))
    story.append(spacer(4))
    story.append(body(
        "<b>Lesion:</b> Left (dominant) parietal lobe, angular gyrus (Brodmann area 39) — at the junction of temporal, parietal, and occipital lobes. "
        "All four features must be present for the syndrome. <b>Causes:</b> Posterior MCA branch stroke, glioma, degenerative dementia."
    ))
    story.append(spacer(6))

    story.append(h2_banner("6.7 Common Viva Questions & Model Answers", CRIMSON))
    story.append(spacer(4))

    viva = [
        ("What is the difference between delirium and dementia?",
         "Delirium: acute, fluctuating, impaired ATTENTION as cardinal feature, clouded consciousness, reversible. "
         "Dementia: chronic, progressive, attention relatively spared initially, clear consciousness until late, irreversible. "
         "A patient with dementia is at much higher risk of superimposed delirium when acutely unwell."),
        ("Why test attention before memory?",
         "Attention is the gating mechanism for memory encoding. An inattentive patient will fail three-word recall not "
         "because of hippocampal lesion but because they never properly registered the words. Testing attention first "
         "allows correct interpretation of memory test results."),
        ("Most sensitive bedside test for early Alzheimer's?",
         "Three-word delayed recall (free recall at 5 min, no cueing) is the most sensitive single bedside test for "
         "hippocampal dysfunction. Semantic fluency (animal naming) is the second most sensitive. Standard MMSE can miss early AD."),
        ("Patient has fluent aphasia with paraphasias — where is the lesion?",
         "Posterior to the Rolandic fissure in the dominant hemisphere. If comprehension is also impaired → Wernicke's area "
         "(post. sup. temporal, area 22). If comprehension is intact but repetition is severely impaired → "
         "arcuate fasciculus / supramarginal gyrus (area 40) = conduction aphasia."),
        ("Patient cannot draw a clock correctly — where is the lesion?",
         "Clock errors can reflect: Parietal (spatial disorganization — numbers placed incorrectly in space, crowded to one side); "
         "Frontal (planning errors — perseveration, clock starts well then deteriorates); or Global dementia (multiple errors). "
         "Ask: Was circle correct? Numbers spatial? Hands correct? Right parietal = spatial errors; Frontal = planning errors."),
        ("What is Gerstmann syndrome and where is the lesion?",
         "Tetrad: finger agnosia + acalculia + agraphia + right-left disorientation. "
         "Lesion: left angular gyrus (Brodmann area 39), at the TPO junction. "
         "The angular gyrus is the convergence zone for reading, writing, calculation, and finger identification."),
        ("Why does anosognosia occur with right hemisphere lesions?",
         "The right hemisphere dominates global spatial and body monitoring. It directs attention to both sides. "
         "Left parietal lesions produce aphasia (obvious deficit); right parietal lesions disrupt the spatial monitoring "
         "system itself — the patient lacks the neural machinery to perceive the deficit. Not psychological denial."),
        ("What is the perisylvian rule for aphasia classification?",
         "In the perisylvian zone (Broca → arcuate fasciculus → Wernicke), repetition is ALWAYS impaired. "
         "Outside the perisylvian zone (transcortical aphasias — watershed areas), repetition is SPARED. "
         "This is the most reliable single rule for aphasia classification at the bedside."),
    ]

    for q, a in viva:
        story.append(KeepTogether([
            Paragraph(f"Q: {q}", ParagraphStyle("Q", fontName="Helvetica-Bold", fontSize=9.5,
                                                 textColor=CRIMSON, spaceAfter=2, leading=13)),
            SideBar(f"A: {a}", EMERALD, LIGHT_GREEN, doc.width,
                    ParagraphStyle("A", fontName="Helvetica", fontSize=9, textColor=DARK_GREY,
                                   leading=13, leftIndent=4)),
            Spacer(1, 6),
        ]))

    story.append(spacer(6))
    story.append(hr(GOLD, 2))
    story.append(spacer(4))
    story.append(Paragraph(
        "References: Harrison's Principles of Internal Medicine 22e · Bradley & Daroff's Neurology in Clinical Practice · "
        "Adams & Victor's Principles of Neurology 12e · Localization in Clinical Neurology 8e · "
        "Neuroanatomy through Clinical Cases 3e · Kaplan & Sadock's Synopsis of Psychiatry",
        REF_STYLE
    ))

# ── Build Story ───────────────────────────────────────────────────────────────

def build():
    story = []
    cover_page(story)
    part1(story)
    part2(story)
    part3(story)
    part4(story)
    part5(story)
    part6(story)

    def on_page(canvas, doc_):
        canvas.saveState()
        canvas.setFont("Helvetica", 8)
        canvas.setFillColor(MID_GREY)
        canvas.drawCentredString(PAGE_W / 2, 1.2*cm,
            f"Higher Mental Functions — MD General Medicine Examination Guide   |   Page {doc_.page}")
        canvas.setStrokeColor(ROYAL_BLUE)
        canvas.setLineWidth(0.5)
        canvas.line(1.8*cm, 1.5*cm, PAGE_W - 1.8*cm, 1.5*cm)
        canvas.restoreState()

    doc.build(story, onFirstPage=on_page, onLaterPages=on_page)
    print(f"PDF written: {OUTPUT}")

if __name__ == "__main__":
    build()
Running Command

cd /tmp/workspace/hmf-pdf && python generate_hmf_pdf.py 2>&1

Running Command

ls -lh /tmp/workspace/hmf-pdf/Higher_Mental_Functions_MD_Guide.pdf

Your colourful PDF is ready for download:

Higher Mental Functions MD Guide

PDF Document · PDF


What is inside the PDF (57 KB, A4, fully formatted):
FeatureDetail
Cover pageDark navy title banner, table of contents, opening Harrison's quote
Colour coding by partEach of the 6 parts has its own distinctive colour theme (Navy → Royal Blue → Teal → Emerald Green → Purple → Crimson)
Section bannersEvery section heading is a rounded, full-width coloured banner
Colour-coded tablesEvery table has a coloured header row with alternating row shading — a different colour palette per section
Call-out boxes⭐ Pearl (clinical pearls, viva keys) in purple sidebars; 📌 Notes in teal sidebars
Viva Q&A sectionAll 8 common viva questions with model answers in green answer boxes
Page footerBlue rule with page number and document title on every page
All 6 partsPart 1 (Importance) → Part 2 (Neuroanatomy) → Part 3 (Physiology) → Part 4 (Bedside Exam) → Part 5 (Mechanisms) → Part 6 (Interpretation/DDx)

Part 7. Clinical Correlation Correlate findings with: * Stroke * Dementia * Alzheimer’s disease * Frontotemporal dementia * Parkinson disease * Wilson disease * Encephalitis * Brain tumors * Delirium * Hepatic encephalopathy * Autoimmune encephalitis * Metabolic encephalopathy ⸻ Part 8. Case Presentation Teach how to present abnormal HMF findings during MD practical examinations. Include: * Model presentation * Examiner expectations * Common mistakes ⸻ Part 9. Viva Questions Generate 100 MD-level viva questions with model answers. ⸻ Part 10. Common Traps Explain examiner traps. Explain how to avoid them. ⸻ Part 11. High-Yield Summary * Flowcharts * Tables * Memory aids * One-page revision sheet * Teaching script for juniors.

Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Finding Sources
Finding Sources

Part 7. Clinical Correlation Correlate findings with: * Stroke * Dementia * Alzheimer’s disease * Frontotemporal dementia * Parkinson disease * Wilson disease * Encephalitis * Brain tumors * Delirium * Hepatic encephalopathy * Autoimmune encephalitis * Metabolic encephalopathy ⸻ Part 8. Case Presentation Teach how to present abnormal HMF findings during MD practical examinations. Include: * Model presentation * Examiner expectations * Common mistakes ⸻ Part 9. Viva Questions Generate 100 MD-level viva questions with model answers. ⸻ Part 10. Common Traps Explain examiner traps. Explain how to avoid them. ⸻ Part 11. High-Yield Summary * Flowcharts * Tables * Memory aids * One-page revision sheet * Teaching script for juniors.

Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File

Part 7. Clinical Correlation Correlate findings with: * Stroke * Dementia * Alzheimer’s disease * Frontotemporal dementia * Parkinson disease * Wilson disease * Encephalitis * Brain tumors * Delirium * Hepatic encephalopathy * Autoimmune encephalitis * Metabolic encephalopathy ⸻ Part 8. Case Presentation Teach how to present abnormal HMF findings during MD practical examinations. Include: * Model presentation * Examiner expectations * Common mistakes ⸻ Part 9. Viva Questions Generate 100 MD-level viva questions with model answers. ⸻ Part 10. Common Traps Explain examiner traps. Explain how to avoid them. ⸻ Part 11. High-Yield Summary * Flowcharts * Tables * Memory aids * One-page revision sheet * Teaching script for juniors.

Your credits are exhausted. You can purchase a top-up or subscribe to a plan to continue using Orris. If you're already subscribed, your daily credits will reset tomorrow.
This is a shared conversation. Sign in to Orris to start your own chat.