"""Generate synthetic pediatric medicine quality & dosing dataset for SSA. Research-based parameterization: - WHO Alert N6/2022: Substandard contaminated paediatric cough syrups in The Gambia; diethylene glycol/ethylene glycol contamination. - PMC10389301: 66+ Gambian children died from contaminated syrups; DEG/EG contamination a recurring global threat. - Nature (2025): Rapid screening methods for DEG/EG needed; GC methods costly and unavailable in many LMICs. - SSA context: Limited child-appropriate formulations; dose splitting of adult tablets common; lack of paediatric QC testing. """ from __future__ import annotations from pathlib import Path import numpy as np import pandas as pd SEED = 42 N_PER_SCENARIO = 10_000 YEAR_RANGE = np.arange(2010, 2025) YEAR_WEIGHTS = np.linspace(0.85, 1.3, len(YEAR_RANGE)) YEAR_WEIGHTS = YEAR_WEIGHTS / YEAR_WEIGHTS.sum() SCENARIOS = { "public_paediatric_care": { "setting_probs": {"paediatric_ward": 0.30, "health_centre": 0.30, "outpatient_clinic": 0.25, "community_health": 0.15}, "formulation_probs": {"syrup": 0.30, "dispersible_tablet": 0.20, "adult_tablet_split": 0.20, "injection": 0.10, "suspension": 0.10, "granule_sachet": 0.10}, "medicine_probs": {"amoxicillin": 0.20, "paracetamol": 0.15, "ORS_zinc": 0.12, "antimalarial": 0.12, "cotrimoxazole": 0.10, "iron_supplement": 0.08, "cough_cold": 0.08, "antiepileptic": 0.05, "ARV_paediatric": 0.05, "other": 0.05}, "sf_prevalence": 0.15, "dosing_error_pct": 0.25, "child_formulation_available": 0.40, "deg_contamination_pct": 0.005, }, "community_otc_children": { "setting_probs": {"community_pharmacy": 0.30, "drug_shop": 0.30, "market_vendor": 0.20, "home_treatment": 0.20}, "formulation_probs": {"syrup": 0.35, "adult_tablet_split": 0.25, "suspension": 0.15, "powder": 0.10, "granule_sachet": 0.08, "other": 0.07}, "medicine_probs": {"paracetamol": 0.20, "cough_cold": 0.15, "amoxicillin": 0.15, "antimalarial": 0.12, "ORS_zinc": 0.10, "cotrimoxazole": 0.08, "multivitamin": 0.08, "anthelmintic": 0.07, "other": 0.05}, "sf_prevalence": 0.25, "dosing_error_pct": 0.40, "child_formulation_available": 0.25, "deg_contamination_pct": 0.01, }, "neonatal_icu_specialist": { "setting_probs": {"neonatal_ICU": 0.35, "paediatric_ICU": 0.25, "special_care_nursery": 0.20, "referral_hospital": 0.20}, "formulation_probs": {"injection": 0.35, "syrup": 0.20, "suspension": 0.15, "adult_tablet_crushed": 0.10, "IV_fluid_additive": 0.10, "other": 0.10}, "medicine_probs": {"gentamicin": 0.15, "ampicillin": 0.12, "caffeine_citrate": 0.08, "phenobarbitone": 0.08, "vitamin_K": 0.08, "surfactant": 0.05, "aminophylline": 0.05, "fluconazole": 0.05, "paracetamol": 0.08, "other": 0.26}, "sf_prevalence": 0.08, "dosing_error_pct": 0.30, "child_formulation_available": 0.35, "deg_contamination_pct": 0.002, }, } SCENARIO_FILES = { "public_paediatric_care": "paed_public_care.csv", "community_otc_children": "paed_community_otc.csv", "neonatal_icu_specialist": "paed_neonatal_icu.csv", } def _choice(rng, prob_map): keys = list(prob_map.keys()) weights = np.array(list(prob_map.values()), dtype=float) weights = weights / weights.sum() return rng.choice(keys, p=weights) def _simulate_scenario(name, params, seed): rng = np.random.default_rng(seed) records = [] for idx in range(N_PER_SCENARIO): year = int(rng.choice(YEAR_RANGE, p=YEAR_WEIGHTS)) setting = _choice(rng, params["setting_probs"]) age_months = int(np.clip(rng.lognormal(np.log(24), 1.0), 0, 180)) sex = rng.choice(["male", "female"], p=[0.52, 0.48]) weight_kg = float(np.clip(rng.normal(age_months * 0.4 + 3, 2), 1, 60)) medicine = _choice(rng, params["medicine_probs"]) formulation = _choice(rng, params["formulation_probs"]) child_formulation_used = int(rng.random() < params["child_formulation_available"]) adult_formulation_adapted = int(not child_formulation_used and rng.random() < 0.60) # Quality is_sf = int(rng.random() < params["sf_prevalence"]) is_falsified = int(is_sf and rng.random() < 0.25) is_substandard = int(is_sf and not is_falsified) deg_contaminated = int(formulation in ("syrup", "suspension") and rng.random() < params["deg_contamination_pct"]) if is_falsified: api_pct = float(np.clip(rng.normal(15, 18), 0, 50)) elif is_substandard: api_pct = float(np.clip(rng.normal(65, 15), 20, 84)) else: api_pct = float(np.clip(rng.normal(97, 4), 85, 115)) # Dosing dosing_error = int(rng.random() < params["dosing_error_pct"]) error_type = rng.choice(["underdose", "overdose", "wrong_frequency", "wrong_calculation", "unmeasured"], p=[0.35, 0.20, 0.15, 0.15, 0.15]) if dosing_error else "none" weight_based_dosing = int(rng.random() < 0.40) measuring_device_used = int(formulation in ("syrup", "suspension") and rng.random() < 0.30) # Health outcomes treatment_failure = int((is_sf or dosing_error) and rng.random() < 0.15) adr = int((is_sf or dosing_error) and rng.random() < 0.05) deg_toxicity = int(deg_contaminated and rng.random() < 0.60) acute_kidney_injury = int(deg_toxicity and rng.random() < 0.70) death = int(acute_kidney_injury and rng.random() < 0.30) hospitalisation = int((treatment_failure and rng.random() < 0.20) or acute_kidney_injury) # Surveillance quality_tested = int(rng.random() < 0.03) adr_reported = int(adr and rng.random() < 0.10) pharmacist_counselled = int(rng.random() < 0.20) any_adverse = int(treatment_failure or adr or deg_toxicity or death) record = { "record_id": f"{name[:3].upper()}-{idx:05d}", "scenario": name, "year": year, "setting": setting, "age_months": age_months, "sex": sex, "weight_kg": round(weight_kg, 1), "medicine": medicine, "formulation": formulation, "child_formulation_used": child_formulation_used, "adult_formulation_adapted": adult_formulation_adapted, "is_substandard_falsified": is_sf, "is_falsified": is_falsified, "deg_contaminated": deg_contaminated, "api_pct_label": round(api_pct, 1), "dosing_error": dosing_error, "error_type": error_type, "weight_based_dosing": weight_based_dosing, "measuring_device_used": measuring_device_used, "treatment_failure": treatment_failure, "adr": adr, "deg_toxicity": deg_toxicity, "acute_kidney_injury": acute_kidney_injury, "hospitalisation": hospitalisation, "death": death, "quality_tested": quality_tested, "adr_reported": adr_reported, "any_adverse": any_adverse, } records.append(record) return pd.DataFrame(records) def main(): output_dir = Path("data") output_dir.mkdir(parents=True, exist_ok=True) for idx, (name, params) in enumerate(SCENARIOS.items()): df = _simulate_scenario(name, params, SEED + idx * 211) df.to_csv(output_dir / SCENARIO_FILES[name], index=False) print(f"Saved {name} -> {SCENARIO_FILES[name]}") if __name__ == "__main__": main()