#!/usr/bin/env python3 """ Stroke Emergency Care Dataset ================================= Each record = ONE acute stroke presentation. Literature-Grounded Parameterization: [1] Hertz JT et al. (2018). Stroke treatments, disability, mortality in urban Tanzania. Int J Qual Health Care. DOI: 10.1093/intqhc/mzy183 KEY FINDINGS: - 149 subjects: 46% ischemic, 54% hemorrhagic - Mean age 57; 48% female; median NIHSS 19 - No thrombolysis or thrombectomy available - Treatments: dysphagia screening 80%, aspirin 83%, antihypertensives 89%, statins 95%, DVT prophylaxis 0% - Ischemic: 19% died, 56% severe disability at discharge; 49% dead by 90d - Hemorrhagic: 33% died, 49% severe disability at discharge; 50% dead by 90d [2] Bateman BT et al. (2013). Thrombolysis for acute ischemic stroke in South Africa. Int J Stroke. DOI: 10.1111/j.1747-4949.2012.00835.x - SICH 4.8%, overall mortality 7.1% - Safety/efficacy similar to developed countries [3] Sarfo FS et al. (2017). Towards best practice acute stroke care Ghana. BMC Health Serv Res. DOI: 10.1186/s12913-017-2061-9 - Limited/variable evidence-based stroke services - Low priority for stroke care in resource-poor settings [4] Owolabi MO et al. (2022). Current management acute ischemic stroke Africa: review. Eur J Neurol. DOI: 10.1111/ene.15498 - Lack of imaging, personnel, stroke units - Poor public awareness → delayed presentation - Telehealth suggested to mitigate scarcity [5] Ogeng'o JA et al. (2014). Stroke in Africa. Afr J Neurol Sci. - Hemorrhagic stroke higher proportion (30-50%) vs HIC (15-20%) - Hypertension main risk factor (60-80%) - Younger mean age (55-60 vs 70+ in HIC) """ import numpy as np, pandas as pd, argparse, os SCENARIOS = { 'stroke_unit_available': { 'exemplar': 'South Africa/Kenya (private)/Mauritius', 'ct_scan_available': 0.80, # [2] SA has CT 'ct_within_1hr': 0.35, 'thrombolysis_given': 0.08, # [2] limited but available 'thrombectomy': 0.02, 'stroke_unit': 0.25, 'neurologist_available': 0.30, 'aspirin_given': 0.80, # [1] 83% 'antihypertensive': 0.85, # [1] 89% 'dvt_prophylaxis': 0.35, # [1] 0% Tanzania; SA better 'dysphagia_screening': 0.65, # [1] 80% 'rehabilitation': 0.30, 'in_hospital_mortality': 0.18, 'hemorrhagic_pct': 0.35, # [5] higher than HIC }, 'basic_stroke_care': { 'exemplar': 'Kenya (public)/Ghana/Tanzania/Ethiopia', 'ct_scan_available': 0.40, 'ct_within_1hr': 0.10, 'thrombolysis_given': 0.01, # [1] none at MNH 'thrombectomy': 0.00, 'stroke_unit': 0.05, 'neurologist_available': 0.10, 'aspirin_given': 0.65, 'antihypertensive': 0.75, 'dvt_prophylaxis': 0.05, # [1] 0% Tanzania 'dysphagia_screening': 0.40, 'rehabilitation': 0.10, 'in_hospital_mortality': 0.28, # [1] ischemic 19%, hemorrhagic 33% 'hemorrhagic_pct': 0.45, # [1] 54% at MNH }, 'no_stroke_services': { 'exemplar': 'DRC/CAR/Sierra Leone/Niger', 'ct_scan_available': 0.08, 'ct_within_1hr': 0.02, 'thrombolysis_given': 0.00, 'thrombectomy': 0.00, 'stroke_unit': 0.00, 'neurologist_available': 0.02, 'aspirin_given': 0.30, 'antihypertensive': 0.40, 'dvt_prophylaxis': 0.02, 'dysphagia_screening': 0.10, 'rehabilitation': 0.03, 'in_hospital_mortality': 0.40, 'hemorrhagic_pct': 0.50, }, } def generate_dataset(n=10000, seed=42, scenario='basic_stroke_care'): rng = np.random.default_rng(seed) sc = SCENARIOS[scenario] records = [] for idx in range(n): rec = {'id': idx + 1} rec['age'] = int(np.clip(rng.normal(58, 14), 20, 95)) # [1][5] younger rec['sex'] = rng.choice(['male','female'], p=[0.52, 0.48]) # [1] 48% female # Risk factors — [5] hypertension 60-80% rec['hypertension'] = 1 if rng.random() < 0.68 else 0 rec['diabetes'] = 1 if rng.random() < 0.22 else 0 rec['atrial_fibrillation'] = 1 if rng.random() < 0.08 else 0 rec['smoking'] = 1 if rng.random() < 0.18 else 0 rec['hiv_positive'] = 1 if rng.random() < 0.07 else 0 rec['prior_stroke'] = 1 if rng.random() < 0.12 else 0 rec['alcohol_heavy'] = 1 if rng.random() < 0.15 else 0 rec['sickle_cell'] = 1 if rng.random() < 0.02 else 0 # Stroke type — [1][5] rec['stroke_type'] = rng.choice(['ischemic','hemorrhagic'], p=[1-sc['hemorrhagic_pct'], sc['hemorrhagic_pct']]) # Presentation rec['onset_to_arrival_hrs'] = round(max(0.5, rng.lognormal( np.log(12), 0.9)), 1) rec['arrived_within_4_5hrs'] = 1 if rec['onset_to_arrival_hrs'] <= 4.5 else 0 rec['arrived_by_ems'] = 1 if rng.random() < 0.08 else 0 rec['wake_up_stroke'] = 1 if rng.random() < 0.20 else 0 rec['nihss_score'] = int(np.clip(rng.lognormal(np.log(12), 0.7), 1, 42)) # [1] median 19 rec['gcs'] = int(np.clip(rng.choice([15,14,12,10,8,6,3], p=[0.25,0.15,0.15,0.15,0.12,0.10,0.08]), 3, 15)) rec['systolic_bp'] = int(np.clip(rng.normal(170, 30), 90, 280)) # [5] hypertension rec['blood_glucose'] = round(np.clip(rng.lognormal(np.log(7), 0.4), 3, 30), 1) # Diagnostics — [1][4] rec['ct_scan_done'] = 1 if rng.random() < sc['ct_scan_available'] else 0 rec['ct_within_1hr'] = 1 if (rec['ct_scan_done'] and rng.random() < sc['ct_within_1hr']) else 0 rec['stroke_type_confirmed'] = 1 if rec['ct_scan_done'] else 0 rec['ecg_done'] = 1 if rng.random() < sc['ct_scan_available'] * 0.8 else 0 rec['echo_done'] = 1 if rng.random() < sc['ct_scan_available'] * 0.3 else 0 rec['labs_complete'] = 1 if rng.random() < sc['ct_scan_available'] * 0.7 else 0 # Treatment — [1][2] rec['thrombolysis_given'] = 1 if ( rec['stroke_type'] == 'ischemic' and rec['ct_scan_done'] and rec['arrived_within_4_5hrs'] and rng.random() < sc['thrombolysis_given'] * 5 ) else 0 rec['thrombectomy_done'] = 1 if ( rec['stroke_type'] == 'ischemic' and rng.random() < sc['thrombectomy'] ) else 0 rec['aspirin_given'] = 1 if (rec['stroke_type'] == 'ischemic' and rng.random() < sc['aspirin_given']) else 0 rec['antihypertensive_given'] = 1 if rng.random() < sc['antihypertensive'] else 0 rec['statin_given'] = 1 if rng.random() < sc['aspirin_given'] * 0.9 else 0 rec['dvt_prophylaxis'] = 1 if rng.random() < sc['dvt_prophylaxis'] else 0 rec['dysphagia_screening'] = 1 if rng.random() < sc['dysphagia_screening'] else 0 rec['ngt_feeding'] = 1 if (not rec['dysphagia_screening'] and rec['gcs'] < 12 and rng.random() < 0.20) else 0 rec['stroke_unit_admitted'] = 1 if rng.random() < sc['stroke_unit'] else 0 rec['neurologist_consulted'] = 1 if rng.random() < sc['neurologist_available'] else 0 rec['surgical_evacuation'] = 1 if ( rec['stroke_type'] == 'hemorrhagic' and rec['nihss_score'] > 20 and rng.random() < sc['neurologist_available'] * 0.3 ) else 0 # Complications rec['aspiration_pneumonia'] = 1 if (not rec['dysphagia_screening'] and rng.random() < 0.15) else 0 rec['dvt_pe'] = 1 if (not rec['dvt_prophylaxis'] and rng.random() < 0.08) else 0 rec['hemorrhagic_transformation'] = 1 if (rec['stroke_type'] == 'ischemic' and rec['thrombolysis_given'] and rng.random() < 0.05) else 0 rec['seizure'] = 1 if rng.random() < 0.08 else 0 rec['raised_icp'] = 1 if (rec['stroke_type'] == 'hemorrhagic' and rec['nihss_score'] > 15 and rng.random() < 0.25) else 0 # Outcome — [1] mort = sc['in_hospital_mortality'] mort *= 1.5 if rec['stroke_type'] == 'hemorrhagic' else 0.7 # [1] mort *= (rec['nihss_score'] / 15) # severity mort *= 0.5 if rec['stroke_unit_admitted'] else 1 mort *= 0.6 if rec['thrombolysis_given'] else 1 mort *= 1.5 if rec['aspiration_pneumonia'] else 1 mort *= 1.3 if rec['gcs'] < 9 else 1 rec['died_in_hospital'] = 1 if rng.random() < min(0.85, mort) else 0 rec['mrs_discharge'] = int(rng.choice([0,1,2,3,4,5,6], p=[0.02,0.05,0.08,0.15,0.25,0.25,0.20])) if not rec['died_in_hospital'] else 6 rec['rehabilitation_received'] = 1 if (not rec['died_in_hospital'] and rng.random() < sc['rehabilitation']) else 0 rec['los_days'] = max(1, int(rng.lognormal(np.log(7), 0.6))) if not rec['died_in_hospital'] else 0 rec['year'] = rng.choice([2019,2020,2021,2022,2023], p=[0.12,0.18,0.20,0.25,0.25]) records.append(rec) df = pd.DataFrame(records) print(f"\n{'='*60}\nStroke Emergency Care — {scenario} ({sc['exemplar']})") print(f" Hemorrhagic: {(df['stroke_type']=='hemorrhagic').mean()*100:.1f}% | CT done: {df['ct_scan_done'].mean()*100:.1f}%") print(f" Thrombolysis: {df['thrombolysis_given'].mean()*100:.1f}% | Stroke unit: {df['stroke_unit_admitted'].mean()*100:.1f}%") print(f" In-hospital mortality: {df['died_in_hospital'].mean()*100:.1f}%") return df if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--all-scenarios', action='store_true') parser.add_argument('--n', type=int, default=10000) parser.add_argument('--seed', type=int, default=42) args = parser.parse_args() os.makedirs('data', exist_ok=True) if args.all_scenarios: for sc in SCENARIOS: df = generate_dataset(n=args.n, seed=args.seed, scenario=sc) df.to_csv(os.path.join('data', f'stroke_{sc}.csv'), index=False) print(f" -> Saved\n") else: df = generate_dataset(n=args.n, seed=args.seed) df.to_csv(os.path.join('data', 'stroke_basic_stroke_care.csv'), index=False)