This cookbook details how to deploy a localized, containerized neurocritical care, vascular neurosurgery, and stroke intensive care decision-support engine for neuro-ICUs, emergency stroke resuscitation units, and comprehensive stroke centers to ingest Glasgow Coma Scale ($\text{GCS}$) scores, focal neurological deficits, non-contrast head $\text{CT}$ subarachnoid clot volumes, Transcranial Doppler ($\text{TCD}$) cerebral blood flow velocities, and hemodynamic arterial line telemetry, calculate the Hunt & Hess Grade ($1 - 5$) and World Federation of Neurological Surgeons ($\text{WFNS}$) Grade ($1 - 5$), stage radiologic vasospasm risk via the Modified Fisher CT Scale (Grades $0 - 4$), compute the TCD Lindegaard Ratio ($\text{LR} = \text{MFV}{\text{MCA}} / \text{MFV}{\text{ICA}}$) to distinguish true cerebral vasospasm from hyperemic flow, guide Oral Enteral Nimodipine ($60\text{ mg}$ q4h $\times 21\text{ days}$) prophylaxis, and enforce Delayed Cerebral Ischemia ($\text{DCI}$) Induced Hypertension Protocols (Target $\text{SBP } 160 - 180\text{ mmHg}$) according to Neurocritical Care Society ($\text{NCS}$), AHA / ASA 2023, and European Stroke Organisation ($\text{ESO}$) consensus guidelines without external cloud API reliance.
Aneurysmal Subarachnoid Hemorrhage ($\text{aSAH}$) is a devastating neurosurgical emergency caused by intracranial cerebral aneurysm rupture. Survivors of initial ictus face high risks of secondary neurological injury from Delayed Cerebral Ischemia ($\text{DCI}$) and angiographic vasospasm during the critical Days $4 - 14$ peak vulnerability window:
[Patient Telemetry: GCS, Headache, Cranial Nerves, CT Cisternal Clot, TCD Velocities]
│
▼
[Clinical Severity Engine: Hunt-Hess (1-5) & WFNS (1-5) Clinical Classification]
│
▼
[Radiologic Staging: Modified Fisher Grade 0-4 (Thick Clot >= 1mm + Bilateral IVH)]
│
▼
[TCD Hemodynamic Engine: Lindegaard Ratio (MFV_MCA / MFV_ICA) -> Vasospasm vs Hyperemia]
│
▼
[Oral Nimodipine 60mg q4h x 21d Protocol + Strict IV Nimodipine Black-Box Sentinel]
│
▼
[DCI Induced Hypertension Engine: MAP > 100-110 mmHg + Interventional Referral Gate]
Install required scientific Python and neurocritical care modeling packages:
pip install numpy scipy pandas torch torchvision matplotlib
"""
Cookbook 333: Offline Neurocritical Care Subarachnoid Hemorrhage, Hunt-Hess & TCD Engine
OpenPHR Clinical AI Working Group (https://openphr.org)
"""
import math
import numpy as np
import pandas as pd
from typing import Dict, List, Tuple, Optional
from dataclasses import dataclass
@dataclass
class SAHPatientTelemetry:
patient_id: str
age_years: float = 54.0
day_post_ictus: int = 7 # Day 7 (Peak vasospasm window: Days 4-14)
# Clinical Neurological Examination Telemetry
glasgow_coma_scale: int = 14 # GCS 3-15
headache_severity: str = "Severe" # "None/Mild", "Moderate", "Severe"
nuchal_rigidity_present: bool = True
cranial_nerve_palsy: bool = True # e.g. CN III oculomotor palsy
motor_deficit_present: bool = False # Hemiparesis/hemiplegia
deep_coma_or_decerebrate: bool = False
# Radiologic CT Subarachnoid Hemorrhage Telemetry
ct_thick_cisternal_clot_ge_1mm: bool = True # Modified Fisher: Thick SAH >= 1mm
ct_bilateral_intraventricular_hemorrhage: bool = True # Modified Fisher: Bilateral IVH
# Transcranial Doppler (TCD) Telemetry
tcd_mca_mean_flow_velocity_cm_s: float = 215.0 # cm/s (>= 200 = Severe Vasospasm)
tcd_ica_extracranial_velocity_cm_s: float = 32.0 # cm/s
# Aneurysm Treatment Status & Hemodynamics
aneurysm_secured: bool = True # Coiled / Clipped
current_sbp_mmhg: float = 135.0 # mmHg
current_map_mmhg: float = 88.0 # mmHg
is_euvolemic: bool = True
# Active Medication Warnings
active_nimodipine_route: str = "Enteral / Oral" # "Enteral / Oral" vs "Intravenous" (🚨 FATAL!)
@dataclass
class SAHEvaluationReport:
patient_id: str
hunt_hess_grade: int # 1 - 5
hunt_hess_description: str
wfns_grade: int # 1 - 5
modified_fisher_grade: int # 0 - 4
modified_fisher_vasospasm_risk: str
tcd_lindegaard_ratio: float
tcd_vasospasm_interpretation: str
nimodipine_order_protocol: List[str]
dci_hemodynamic_management: List[str]
safety_sentinels: List[str]
clinical_ncs_aha_directive: str
class SubarachnoidHemorrhageDecisionEngine:
"""
Offline clinical engine for Hunt-Hess / WFNS grading, Modified Fisher CT staging,
TCD Lindegaard ratio computation, and delayed cerebral ischemia (DCI) management.
"""
def calculate_hunt_hess_grade(self, d: SAHPatientTelemetry) -> Tuple[int, str]:
if d.deep_coma_or_decerebrate:
return 5, "Grade 5: Deep coma, decerebrate posturing, moribund appearance."
elif d.glasgow_coma_scale <= 8 or d.motor_deficit_present:
return 4, "Grade 4: Stupor, moderate-to-severe hemiparesis, vegetative disturbance."
elif d.glasgow_coma_scale <= 13 or d.headache_severity == "Severe":
return 3, "Grade 3: Drowsiness, confusion, or mild focal neurological deficit."
elif d.headache_severity in ["Moderate", "Severe"] or d.nuchal_rigidity_present or d.cranial_nerve_palsy:
return 2, "Grade 2: Moderate-to-severe headache, nuchal rigidity, cranial nerve palsy (no other deficit)."
else:
return 1, "Grade 1: Asymptomatic or mild headache and slight nuchal rigidity."
def calculate_wfns_grade(self, gcs: int, motor_deficit: bool) -> int:
if gcs == 15 and not motor_deficit:
return 1
elif gcs in [13, 14] and not motor_deficit:
return 2
elif gcs in [13, 14] and motor_deficit:
return 3
elif 7 <= gcs <= 12:
return 4
else:
return 5
def calculate_modified_fisher_scale(self, d: SAHPatientTelemetry) -> Tuple[int, str]:
thick = d.ct_thick_cisternal_clot_ge_1mm
ivh = d.ct_bilateral_intraventricular_hemorrhage
if thick and ivh:
return 4, "Grade 4: Thick cisternal SAH (>= 1 mm) WITH bilateral IVH -> HIGHEST DCI Vasospasm Risk (~38-42% incidence)."
elif thick and not ivh:
return 3, "Grade 3: Thick cisternal SAH (>= 1 mm) WITHOUT IVH -> High DCI Vasospasm Risk (~30% incidence)."
elif not thick and ivh:
return 2, "Grade 2: Thin SAH (< 1 mm) WITH bilateral IVH -> Moderate DCI Vasospasm Risk (~20% incidence)."
else:
return 1, "Grade 1: Thin SAH (< 1 mm) WITHOUT IVH -> Low DCI Vasospasm Risk (~12% incidence)."
def evaluate_tcd_lindegaard(self, mca_vel: float, ica_vel: float) -> Tuple[float, str]:
lr = round(mca_vel / max(ica_vel, 5.0), 2)
if mca_vel >= 200.0 or lr >= 6.0:
interp = f"SEVERE ANGIOGRAPHIC VASOSPASM (MCA MFV {mca_vel:.0f} cm/s >= 200, Lindegaard Ratio {lr:.2f} >= 6.0) -> Critical luminal constriction; high risk of DCI infarction."
elif (140.0 <= mca_vel < 200.0) and lr >= 3.0:
interp = f"MODERATE VASOSPASM (MCA MFV {mca_vel:.0f} cm/s, Lindegaard Ratio {lr:.2f} between 3.0-5.9)."
elif (120.0 <= mca_vel < 140.0) and lr >= 3.0:
interp = f"MILD VASOSPASM (MCA MFV {mca_vel:.0f} cm/s, Lindegaard Ratio {lr:.2f} between 3.0-5.9)."
elif mca_vel >= 120.0 and lr < 3.0:
interp = f"HYPEREMIA / HIGH CARDIAC OUTPUT (MCA MFV {mca_vel:.0f} cm/s elevated, but Lindegaard Ratio {lr:.2f} < 3.0 rules out true vasospasm)."
else:
interp = f"NORMAL CEREBRAL HEMODYNAMICS (MCA MFV {mca_vel:.0f} cm/s < 120, Lindegaard Ratio {lr:.2f} < 3.0)."
return lr, interp
def generate_management_protocols(self, d: SAHPatientTelemetry, is_severe_spasm: bool) -> Tuple[List[str], List[str], List[str]]:
nimodipine_orders = []
dci_plan = []
sentinels = []
# 1. Enteral Nimodipine Protocol
nimodipine_orders.append("1. ENTERAL NIMODIPINE ORDER: Administer Nimodipine 60 mg orally or via nasogastric/orogastric tube every 4 hours for exactly 21 consecutive days.")
nimodipine_orders.append(" • If transient hypotension occurs, reduce dosing interval to 30 mg every 2 hours; do NOT discontinue.")
# 2. Safety Sentinel: Black Box Prohibition on IV Nimodipine
if d.active_nimodipine_route == "Intravenous":
sentinels.append("🚨 FATAL BLACK BOX CONTRAINDICATION: Intravenous Nimodipine administration causes profound, irreversible hypotension and fatal cardiovascular arrest. Nimodipine MUST STRICTLY BE GIVEN ENTERALLY (PO/NG). STAT CEASE IV INFUSION!")
# 3. Delayed Cerebral Ischemia (DCI) Hemodynamics
dci_plan.append("1. STRICT EUVOLEMIA: Maintain normovolemia using isotonic crystalloids (Plasmalyte / 0.9% Normal Saline). Avoid prophylactic hypervolemia (Triple-H is obsolete; causes pulmonary edema and hyponatremia).")
if is_severe_spasm or d.day_post_ictus in range(4, 15):
if d.aneurysm_secured:
dci_plan.append("2. INDUCED HYPERTENSION (Aneurysm Secured):")
dci_plan.append(f" • Titrate IV Norepinephrine or Phenylephrine to elevate blood pressure by 20-30% above baseline.")
dci_plan.append(f" • Hemodynamic Target: SBP 160 - 180 mmHg or MAP > 100 - 110 mmHg (Current MAP {d.current_map_mmhg:.0f} mmHg).")
dci_plan.append("3. ENDOVASCULAR RESCUE TRIGGER: If neurological deficits or severe TCD vasospasm persist despite induced hypertension, immediately transfer for intra-arterial Nicardipine/Verapamil infusion or transluminal balloon angioplasty.")
else:
dci_plan.append("2. ⚠️ UNSECURED ANEURYSM: Maintain SBP < 140 - 160 mmHg until aneurysm is coiled or clipped to prevent catastrophic rebleeding.")
sentinels.append("HYPONATREMIA / CSW SENTINEL: Cerebral Salt Wasting (CSW) and SIADH are frequent in aSAH. Never fluid-restrict in SAH. Treat hyponatremia (Na < 135 mEq/L) with hypertonic 3% saline infusions.")
return nimodipine_orders, dci_plan, sentinels
def evaluate_case(self, data: SAHPatientTelemetry) -> SAHEvaluationReport:
hh_grade, hh_desc = self.calculate_hunt_hess_grade(data)
wfns_grade = self.calculate_wfns_grade(data.glasgow_coma_scale, data.motor_deficit_present)
mf_grade, mf_desc = self.calculate_modified_fisher_scale(data)
lr_val, lr_desc = self.evaluate_tcd_lindegaard(data.tcd_mca_mean_flow_velocity_cm_s, data.tcd_ica_extracranial_velocity_cm_s)
is_severe = "SEVERE" in lr_desc
nimo_orders, dci_plan, sentinels = self.generate_management_protocols(data, is_severe)
directives = []
directives.append(f"HUNT-HESS: Grade {hh_grade} (WFNS Grade {wfns_grade}).")
directives.append(f"MODIFIED FISHER: Grade {mf_grade} ({mf_desc}).")
directives.append(f"TCD VASOSPASM: {lr_desc}.")
return SAHEvaluationReport(
patient_id=data.patient_id,
hunt_hess_grade=hh_grade,
hunt_hess_description=hh_desc,
wfns_grade=wfns_grade,
modified_fisher_grade=mf_grade,
modified_fisher_vasospasm_risk=mf_desc,
tcd_lindegaard_ratio=lr_val,
tcd_vasospasm_interpretation=lr_desc,
nimodipine_order_protocol=nimo_orders,
dci_hemodynamic_management=dci_plan,
safety_sentinels=sentinels,
clinical_ncs_aha_directive=" ".join(directives)
)
# Example Execution & Verification
if __name__ == "__main__":
engine = SubarachnoidHemorrhageDecisionEngine()
print("=" * 80)
print("OpenPHR Clinical Neurocritical Care Subarachnoid Hemorrhage & TCD Engine")
print("=" * 80)
# Test Case 1: 54-year-old female on Day 7 post-aneurysm coiling presenting with severe headache,
# GCS 14, CN III palsy (Hunt-Hess Grade 2, WFNS Grade 2).
# CT: Thick cisternal blood >= 1mm + Bilateral IVH (Modified Fisher Grade 4 - 40% DCI risk!).
# TCD: MCA velocity 215 cm/s, ICA 32 cm/s -> Lindegaard Ratio: 6.72 (Severe Vasospasm!).
# Triage: Enteral Nimodipine 60mg q4h x 21d + Norepinephrine Induced Hypertension (MAP > 100 mmHg)!
sah1 = SAHPatientTelemetry(
patient_id="NEURO-SAH-7701",
age_years=54.0,
day_post_ictus=7,
glasgow_coma_scale=14,
headache_severity="Severe",
nuchal_rigidity_present=True,
cranial_nerve_palsy=True,
motor_deficit_present=False,
ct_thick_cisternal_clot_ge_1mm=True,
ct_bilateral_intraventricular_hemorrhage=True,
tcd_mca_mean_flow_velocity_cm_s=215.0,
tcd_ica_extracranial_velocity_cm_s=32.0,
aneurysm_secured=True,
current_sbp_mmhg=135.0,
current_map_mmhg=88.0,
is_euvolemic=True,
active_nimodipine_route="Enteral / Oral"
)
rep1 = engine.evaluate_case(sah1)
print(f"\n[Patient {rep1.patient_id} - Neuro-ICU SAH Assessment]")
print(f"Clinical Severity: Hunt & Hess Grade {rep1.hunt_hess_grade} ({rep1.hunt_hess_description})")
print(f"WFNS Scale: Grade {rep1.wfns_grade}")
print(f"Radiologic Vasospasm Risk: Modified Fisher Grade {rep1.modified_fisher_grade} ({rep1.modified_fisher_vasospasm_risk})")
print(f"\nTCD Hemodynamics (Lindegaard Ratio: {rep1.tcd_lindegaard_ratio:.2f}):\n {rep1.tcd_vasospasm_interpretation}")
print("\nNimodipine Neuroprotection Protocol:")
for n in rep1.nimodipine_order_protocol:
print(f" {n}")
print("\nDelayed Cerebral Ischemia (DCI) Hemodynamic Protocols:")
for dci in rep1.dci_hemodynamic_management:
print(f" {dci}")
if rep1.safety_sentinels:
print("\nSafety Sentinels:")
for s in rep1.safety_sentinels:
print(f" 🚨 {s}")
print(f"\nNCS / AHA Consensus Directive:\n{rep1.clinical_ncs_aha_directive}")