| |
| """ |
| Literature-Informed Synthetic Community Health Worker iCCM Triage Dataset |
| ========================================================================= |
| |
| Generates realistic synthetic datasets of sick child assessments by community |
| health workers (CHWs) using integrated Community Case Management (iCCM) |
| protocols. Children aged 2-59 months presenting with acute illness at |
| community level in LMIC settings. |
| |
| iCCM covers three core conditions: |
| - Malaria (fever + RDT) |
| - Pneumonia (cough + fast breathing) |
| - Diarrhoea (loose stools + dehydration assessment) |
| Plus danger sign assessment for referral decisions. |
| |
| DAG (Sampling Order): |
| 1. age_months, sex (roots) |
| 2. presenting_complaint (from prevalence) |
| 3. true_diagnosis (conditional on complaint + scenario) |
| 4. symptoms & signs (conditional on diagnosis) |
| 5. rdt_result (conditional on malaria status + test performance) |
| 6. respiratory_rate, fast_breathing (conditional on pneumonia) |
| 7. muac_cm (age-conditional, used for malnutrition screening) |
| 8. danger_signs (conditional on severity) |
| 9. chw_classification (iCCM algorithm output) |
| 10. chw_action (treat/refer) |
| |
| References: |
| ----------- |
| [1] WHO/UNICEF (2012). Caring for the sick child in the community. Geneva. |
| [2] WHO/UNICEF (2014). Integrated Community Case Management (iCCM): |
| Evidence review. Geneva. |
| [3] Marsh DR, et al. (2012). Introduction to a special supplement on iCCM. |
| Am J Trop Med Hyg, 87(5 Suppl):1-5. |
| [4] Druetz T, et al. (2015). Impact of iCCM on child mortality: a systematic |
| review. Paediatrics & International Child Health, 35(1):18-29. |
| [5] WHO (2023). World Malaria Report 2023. Geneva. |
| [6] UNICEF (2019). Diarrhoea treatment guidelines. New York. |
| [7] WHO (2014). Revised WHO classification and treatment of pneumonia in |
| children at health facilities. Geneva. |
| [8] DHS/MICS Program. Treatment-seeking and CHW utilization data. |
| """ |
|
|
| import numpy as np |
| import pandas as pd |
| import argparse |
| import os |
|
|
| |
| |
| |
|
|
| SCENARIOS = { |
| 'low_burden': { |
| 'description': 'Lower burden LMIC community (e.g., urban peri-urban)', |
| 'malaria_pct': 0.20, |
| 'pneumonia_pct': 0.15, |
| 'diarrhoea_pct': 0.25, |
| 'mixed_pct': 0.08, |
| 'other_febrile_pct': 0.32, |
| 'danger_sign_rate': 0.04, |
| 'malnutrition_sam_rate': 0.02, |
| 'malnutrition_mam_rate': 0.05, |
| }, |
| 'moderate_burden': { |
| 'description': 'Average LMIC community (e.g., rural Kenya, Senegal)', |
| 'malaria_pct': 0.35, |
| 'pneumonia_pct': 0.18, |
| 'diarrhoea_pct': 0.22, |
| 'mixed_pct': 0.10, |
| 'other_febrile_pct': 0.15, |
| 'danger_sign_rate': 0.07, |
| 'malnutrition_sam_rate': 0.04, |
| 'malnutrition_mam_rate': 0.08, |
| }, |
| 'high_burden': { |
| 'description': 'High burden / conflict (e.g., Sahel, DRC)', |
| 'malaria_pct': 0.45, |
| 'pneumonia_pct': 0.20, |
| 'diarrhoea_pct': 0.18, |
| 'mixed_pct': 0.12, |
| 'other_febrile_pct': 0.05, |
| 'danger_sign_rate': 0.12, |
| 'malnutrition_sam_rate': 0.08, |
| 'malnutrition_mam_rate': 0.12, |
| }, |
| } |
|
|
| |
| RDT_SENSITIVITY = 0.93 |
| RDT_SPECIFICITY = 0.95 |
|
|
| |
| |
| RR_PNEUMONIA = {'mean': 56, 'sd': 8} |
| RR_NORMAL = {'mean': 32, 'sd': 6} |
|
|
| |
| MUAC_NORMAL = {'mean': 14.8, 'sd': 1.2} |
| MUAC_MAM = {'mean': 12.0, 'sd': 0.3} |
| MUAC_SAM = {'mean': 10.8, 'sd': 0.5} |
|
|
|
|
| |
| |
| |
|
|
| def generate_iccm_dataset(n=10000, seed=42, scenario='moderate_burden'): |
| rng = np.random.default_rng(seed) |
| sc = SCENARIOS[scenario] |
|
|
| |
| sex = rng.choice(['M', 'F'], size=n, p=[0.512, 0.488]) |
| age_months = rng.integers(2, 60, size=n) |
|
|
| |
| diag_probs = [sc['malaria_pct'], sc['pneumonia_pct'], sc['diarrhoea_pct'], |
| sc['mixed_pct'], sc['other_febrile_pct']] |
| diagnoses = ['malaria', 'pneumonia', 'diarrhoea', 'mixed', 'other_febrile'] |
| true_diagnosis = rng.choice(diagnoses, size=n, p=diag_probs) |
|
|
| |
| mixed_type = np.array(['none'] * n, dtype=object) |
| for i in range(n): |
| if true_diagnosis[i] == 'mixed': |
| mixed_type[i] = rng.choice(['malaria_pneumonia', 'malaria_diarrhoea'], |
| p=[0.55, 0.45]) |
|
|
| |
| fever = np.zeros(n, dtype=int) |
| temperature = np.zeros(n) |
| for i in range(n): |
| if true_diagnosis[i] in ('malaria', 'other_febrile'): |
| fever[i] = 1 if rng.random() < 0.88 else 0 |
| elif true_diagnosis[i] == 'pneumonia': |
| fever[i] = 1 if rng.random() < 0.65 else 0 |
| elif true_diagnosis[i] == 'diarrhoea': |
| fever[i] = 1 if rng.random() < 0.35 else 0 |
| elif true_diagnosis[i] == 'mixed': |
| fever[i] = 1 if rng.random() < 0.90 else 0 |
|
|
| if fever[i]: |
| temperature[i] = rng.normal(38.6, 0.7) |
| else: |
| temperature[i] = rng.normal(37.0, 0.3) |
| temperature = np.clip(np.round(temperature, 1), 35.5, 41.5) |
| fever_duration_days = np.where(fever, np.clip(rng.poisson(3, n), 1, 14), 0) |
|
|
| |
| cough = np.zeros(n, dtype=int) |
| respiratory_rate = np.zeros(n, dtype=int) |
| for i in range(n): |
| has_resp = true_diagnosis[i] == 'pneumonia' or \ |
| (true_diagnosis[i] == 'mixed' and 'pneumonia' in mixed_type[i]) |
| if has_resp: |
| cough[i] = 1 if rng.random() < 0.90 else 0 |
| respiratory_rate[i] = max(15, int(rng.normal(RR_PNEUMONIA['mean'], RR_PNEUMONIA['sd']))) |
| else: |
| cough[i] = 1 if rng.random() < 0.25 else 0 |
| respiratory_rate[i] = max(15, int(rng.normal(RR_NORMAL['mean'], RR_NORMAL['sd']))) |
|
|
| |
| fast_breathing = np.zeros(n, dtype=int) |
| for i in range(n): |
| threshold = 50 if age_months[i] < 12 else 40 |
| fast_breathing[i] = 1 if respiratory_rate[i] >= threshold else 0 |
|
|
| |
| diarrhoea = np.zeros(n, dtype=int) |
| diarrhoea_days = np.zeros(n, dtype=int) |
| blood_in_stool = np.zeros(n, dtype=int) |
| dehydration_status = np.array(['none'] * n, dtype=object) |
|
|
| for i in range(n): |
| has_diarr = true_diagnosis[i] == 'diarrhoea' or \ |
| (true_diagnosis[i] == 'mixed' and 'diarrhoea' in mixed_type[i]) |
| if has_diarr: |
| diarrhoea[i] = 1 |
| diarrhoea_days[i] = max(1, rng.poisson(4)) |
| blood_in_stool[i] = 1 if rng.random() < 0.08 else 0 |
| r = rng.random() |
| if r < 0.10: |
| dehydration_status[i] = 'severe' |
| elif r < 0.35: |
| dehydration_status[i] = 'some' |
| else: |
| dehydration_status[i] = 'none' |
| else: |
| diarrhoea[i] = 1 if rng.random() < 0.08 else 0 |
| if diarrhoea[i]: |
| diarrhoea_days[i] = max(1, rng.poisson(2)) |
|
|
| diarrhoea_days = np.clip(diarrhoea_days, 0, 21) |
|
|
| |
| has_malaria = np.array([ |
| true_diagnosis[i] == 'malaria' or |
| (true_diagnosis[i] == 'mixed' and 'malaria' in mixed_type[i]) |
| for i in range(n) |
| ]) |
|
|
| rdt_result = np.zeros(n, dtype=int) |
| for i in range(n): |
| if has_malaria[i]: |
| rdt_result[i] = 1 if rng.random() < RDT_SENSITIVITY else 0 |
| else: |
| rdt_result[i] = 1 if rng.random() < (1 - RDT_SPECIFICITY) else 0 |
|
|
| |
| muac = np.zeros(n) |
| nutrition_status = np.array(['normal'] * n, dtype=object) |
| for i in range(n): |
| r = rng.random() |
| if r < sc['malnutrition_sam_rate']: |
| muac[i] = rng.normal(MUAC_SAM['mean'], MUAC_SAM['sd']) |
| nutrition_status[i] = 'SAM' |
| elif r < sc['malnutrition_sam_rate'] + sc['malnutrition_mam_rate']: |
| muac[i] = rng.normal(MUAC_MAM['mean'], MUAC_MAM['sd']) |
| nutrition_status[i] = 'MAM' |
| else: |
| muac[i] = rng.normal(MUAC_NORMAL['mean'], MUAC_NORMAL['sd']) |
| muac = np.clip(np.round(muac, 1), 7.0, 20.0) |
| |
| nutrition_status = np.where(muac < 11.5, 'SAM', |
| np.where(muac < 12.5, 'MAM', 'normal')) |
|
|
| |
| unable_to_drink = np.zeros(n, dtype=int) |
| vomiting_everything = np.zeros(n, dtype=int) |
| convulsions = np.zeros(n, dtype=int) |
| lethargic_unconscious = np.zeros(n, dtype=int) |
| chest_indrawing = np.zeros(n, dtype=int) |
|
|
| for i in range(n): |
| is_severe = rng.random() < sc['danger_sign_rate'] |
| |
| if age_months[i] < 12: |
| is_severe = is_severe or rng.random() < sc['danger_sign_rate'] * 0.5 |
| if nutrition_status[i] == 'SAM': |
| is_severe = is_severe or rng.random() < 0.15 |
|
|
| if is_severe: |
| unable_to_drink[i] = 1 if rng.random() < 0.45 else 0 |
| vomiting_everything[i] = 1 if rng.random() < 0.40 else 0 |
| convulsions[i] = 1 if rng.random() < 0.20 else 0 |
| lethargic_unconscious[i] = 1 if rng.random() < 0.25 else 0 |
| chest_indrawing[i] = 1 if rng.random() < 0.35 else 0 |
| else: |
| |
| vomiting_everything[i] = 1 if rng.random() < 0.02 else 0 |
| chest_indrawing[i] = 1 if rng.random() < 0.01 else 0 |
|
|
| any_danger_sign = ((unable_to_drink + vomiting_everything + convulsions + |
| lethargic_unconscious + chest_indrawing) > 0).astype(int) |
|
|
| |
| chw_classification = np.array(['other'] * n, dtype=object) |
| for i in range(n): |
| classifications = [] |
| if rdt_result[i] == 1: |
| classifications.append('malaria') |
| if cough[i] and fast_breathing[i]: |
| classifications.append('pneumonia') |
| if diarrhoea[i]: |
| classifications.append('diarrhoea') |
| if nutrition_status[i] == 'SAM': |
| classifications.append('severe_malnutrition') |
|
|
| if len(classifications) == 0: |
| chw_classification[i] = 'other_febrile' if fever[i] else 'well_child' |
| elif len(classifications) == 1: |
| chw_classification[i] = classifications[0] |
| else: |
| chw_classification[i] = '+'.join(sorted(classifications)) |
|
|
| |
| chw_action = np.array(['treat_at_community'] * n, dtype=object) |
| for i in range(n): |
| if any_danger_sign[i]: |
| chw_action[i] = 'refer_urgently' |
| elif nutrition_status[i] == 'SAM': |
| chw_action[i] = 'refer_urgently' |
| elif dehydration_status[i] == 'severe': |
| chw_action[i] = 'refer_urgently' |
| elif age_months[i] < 2: |
| chw_action[i] = 'refer_urgently' |
| elif rdt_result[i] and fast_breathing[i]: |
| chw_action[i] = 'treat_and_refer' |
| elif blood_in_stool[i]: |
| chw_action[i] = 'refer' |
|
|
| |
| act_given = ((rdt_result == 1) & (chw_action != 'refer_urgently')).astype(int) |
| amoxicillin_given = ((cough == 1) & (fast_breathing == 1) & |
| (chw_action != 'refer_urgently')).astype(int) |
| ors_given = ((diarrhoea == 1) & (chw_action != 'refer_urgently')).astype(int) |
| zinc_given = ors_given.copy() |
|
|
| |
| df = pd.DataFrame({ |
| 'id': np.arange(1, n + 1), |
| 'age_months': age_months, |
| 'sex': sex, |
| 'fever': fever, |
| 'temperature_c': temperature, |
| 'fever_duration_days': fever_duration_days, |
| 'cough': cough, |
| 'respiratory_rate_bpm': respiratory_rate, |
| 'fast_breathing': fast_breathing, |
| 'chest_indrawing': chest_indrawing, |
| 'diarrhoea': diarrhoea, |
| 'diarrhoea_duration_days': diarrhoea_days, |
| 'blood_in_stool': blood_in_stool, |
| 'dehydration_status': dehydration_status, |
| 'rdt_result': rdt_result, |
| 'muac_cm': muac, |
| 'nutrition_status': nutrition_status, |
| 'unable_to_drink': unable_to_drink, |
| 'vomiting_everything': vomiting_everything, |
| 'convulsions': convulsions, |
| 'lethargic_unconscious': lethargic_unconscious, |
| 'any_danger_sign': any_danger_sign, |
| 'true_diagnosis': true_diagnosis, |
| 'chw_classification': chw_classification, |
| 'chw_action': chw_action, |
| 'act_given': act_given, |
| 'amoxicillin_given': amoxicillin_given, |
| 'ors_given': ors_given, |
| 'zinc_given': zinc_given, |
| }) |
|
|
| |
| print(f"\n{'='*60}") |
| print(f"iCCM CHW Triage — {scenario} (n={n}, seed={seed})") |
| print(f"{'='*60}") |
| print(f"\nTrue diagnosis:") |
| for d in diagnoses: |
| print(f" {d:20s}: {(true_diagnosis==d).mean()*100:.1f}%") |
| print(f"\nRDT+: {rdt_result.mean()*100:.1f}%") |
| print(f"Fast breathing: {fast_breathing.mean()*100:.1f}%") |
| print(f"Diarrhoea: {(diarrhoea==1).mean()*100:.1f}%") |
| print(f"Any danger sign: {any_danger_sign.mean()*100:.1f}%") |
| print(f"SAM: {(nutrition_status=='SAM').mean()*100:.1f}%") |
| print(f"Referral rate: {np.mean(['refer' in str(a) for a in chw_action])*100:.1f}%") |
| print(f"ACT given: {act_given.mean()*100:.1f}%") |
| print(f"Amoxicillin given: {amoxicillin_given.mean()*100:.1f}%") |
| print(f"ORS given: {ors_given.mean()*100:.1f}%") |
|
|
| return df |
|
|
|
|
| |
| |
| |
|
|
| if __name__ == '__main__': |
| parser = argparse.ArgumentParser( |
| description='Generate synthetic iCCM CHW triage dataset') |
| parser.add_argument('--scenario', type=str, default='moderate_burden', |
| choices=list(SCENARIOS.keys())) |
| parser.add_argument('--n', type=int, default=10000) |
| parser.add_argument('--seed', type=int, default=42) |
| parser.add_argument('--output', type=str, default=None) |
| parser.add_argument('--all-scenarios', action='store_true') |
| args = parser.parse_args() |
|
|
| os.makedirs('data', exist_ok=True) |
|
|
| if args.all_scenarios: |
| for sc_name in SCENARIOS: |
| df = generate_iccm_dataset(n=args.n, seed=args.seed, scenario=sc_name) |
| out = os.path.join('data', f'iccm_{sc_name}.csv') |
| df.to_csv(out, index=False) |
| print(f" → Saved to {out}\n") |
| else: |
| df = generate_iccm_dataset(n=args.n, seed=args.seed, scenario=args.scenario) |
| out = args.output or os.path.join('data', f'iccm_{args.scenario}.csv') |
| df.to_csv(out, index=False) |
| print(f" → Saved to {out}") |
|
|