Datasets:
Add dataset files
Browse files- README.md +89 -0
- data/pv_emerging_pv_system.csv +0 -0
- data/pv_functional_pv_centre.csv +0 -0
- data/pv_minimal_pv_capacity.csv +0 -0
- generate_dataset.py +195 -0
- requirements.txt +3 -0
- validate_dataset.py +102 -0
- validation_report.png +3 -0
README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
task_categories:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
- tabular-regression
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
tags:
|
| 9 |
+
- healthcare
|
| 10 |
+
- medicine-quality
|
| 11 |
+
- pharmacovigilance
|
| 12 |
+
- ADR
|
| 13 |
+
- VigiBase
|
| 14 |
+
- ICSR
|
| 15 |
+
- drug-safety
|
| 16 |
+
- post-market
|
| 17 |
+
- sub-saharan-africa
|
| 18 |
+
- lmic
|
| 19 |
+
pretty_name: "Post-Market Surveillance & Pharmacovigilance (ADR Reporting, Causality, VigiBase)"
|
| 20 |
+
size_categories:
|
| 21 |
+
- 10K<n<100K
|
| 22 |
+
configs:
|
| 23 |
+
- config_name: functional_pv_centre
|
| 24 |
+
data_files: data/pv_functional_pv_centre.csv
|
| 25 |
+
- config_name: emerging_pv_system
|
| 26 |
+
data_files: data/pv_emerging_pv_system.csv
|
| 27 |
+
default: true
|
| 28 |
+
- config_name: minimal_pv_capacity
|
| 29 |
+
data_files: data/pv_minimal_pv_capacity.csv
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
# Post-Market Surveillance & Pharmacovigilance Dataset
|
| 33 |
+
|
| 34 |
+
## Abstract
|
| 35 |
+
|
| 36 |
+
This dataset provides **30,000 simulated pharmacovigilance reports** (10,000 per scenario) across three PV capacity levels in sub-Saharan Africa. Each record represents one adverse drug reaction report with 30+ variables including adverse event type, seriousness, causality assessment, SF medicine suspicion, ICSR completeness, VigiBase entry, and patient outcomes. Three scenarios: functional PV centre (25% serious, 65% causality assessed), emerging PV (35% serious, 25% assessed), minimal PV (50% serious, 5% assessed).
|
| 37 |
+
|
| 38 |
+
**This dataset is entirely simulated. It must not be used for clinical or pharmacovigilance decisions.**
|
| 39 |
+
|
| 40 |
+
## 1. Introduction
|
| 41 |
+
|
| 42 |
+
Africa contributes <2% of global ICSR reports to VigiBase despite 17% of global population. Only 55% of African countries have functional PV centres. ADR under-reporting is estimated at 90-95% — only 5-10% of ADRs are captured. SF medicines drive a significant share of adverse events, particularly in settings with weak regulatory capacity.
|
| 43 |
+
|
| 44 |
+
## 2. Parameterization Evidence (v2.0)
|
| 45 |
+
|
| 46 |
+
| Parameter | Value Used | Source | Year |
|
| 47 |
+
| --- | --- | --- | --- |
|
| 48 |
+
| Africa <2% of VigiBase reports | <2% | UMC/VigiBase | 2023 |
|
| 49 |
+
| 55% of African countries have PV | 55% | WHO | 2023 |
|
| 50 |
+
| Under-reporting 90-95% | 90-95% | Lancet | 2019 |
|
| 51 |
+
| ADR reporting 0.1-50/million | 0.1-50 | WHO | 2023 |
|
| 52 |
+
|
| 53 |
+
## 3. Validation
|
| 54 |
+
|
| 55 |
+
<p align="center">
|
| 56 |
+
<img src="validation_report.png" alt="Validation Report" width="100%">
|
| 57 |
+
</p>
|
| 58 |
+
|
| 59 |
+
## 4. Usage
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
from datasets import load_dataset
|
| 63 |
+
dataset = load_dataset("electricsheepafrica/postmarket-surveillance-pharmacovigilance", "emerging_pv_system")
|
| 64 |
+
df = dataset["train"].to_pandas()
|
| 65 |
+
print(df.groupby('seriousness').size())
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## 5. References
|
| 69 |
+
|
| 70 |
+
1. Uppsala Monitoring Centre. VigiBase global ADR database.
|
| 71 |
+
2. WHO (2023). Pharmacovigilance in Africa.
|
| 72 |
+
3. Lancet (2019). Under-reporting of ADRs in SSA.
|
| 73 |
+
4. USAID SIAPS/PQM+. PV system strengthening.
|
| 74 |
+
|
| 75 |
+
## Citation
|
| 76 |
+
|
| 77 |
+
```bibtex
|
| 78 |
+
@dataset{esa_pv_2025,
|
| 79 |
+
title = {Post-Market Surveillance and Pharmacovigilance Dataset},
|
| 80 |
+
author = {{Electric Sheep Africa}},
|
| 81 |
+
year = {2025},
|
| 82 |
+
publisher = {Hugging Face},
|
| 83 |
+
url = {https://huggingface.co/datasets/electricsheepafrica/postmarket-surveillance-pharmacovigilance}
|
| 84 |
+
}
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## License
|
| 88 |
+
|
| 89 |
+
[CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)
|
data/pv_emerging_pv_system.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/pv_functional_pv_centre.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/pv_minimal_pv_capacity.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generate_dataset.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Literature-Informed Post-Market Surveillance & Pharmacovigilance Dataset
|
| 4 |
+
=========================================================================
|
| 5 |
+
|
| 6 |
+
Each record = ONE adverse drug reaction (ADR) or quality defect report.
|
| 7 |
+
|
| 8 |
+
Sources (v2.0):
|
| 9 |
+
[1] Uppsala Monitoring Centre (UMC). VigiBase — global ADR database.
|
| 10 |
+
Africa contributes <2% of global ICSR reports despite 17% of
|
| 11 |
+
global population and high SF medicine burden.
|
| 12 |
+
[2] WHO (2023). Only 55% of African countries have functional PV
|
| 13 |
+
centres. ADR reporting rates: 0.1-50 per million population.
|
| 14 |
+
[3] USAID SIAPS/PQM+. PV system strengthening in 15+ African
|
| 15 |
+
countries. Spontaneous reporting is the backbone.
|
| 16 |
+
[4] WHO Global Individual Case Safety Report (ICSR) standards.
|
| 17 |
+
MedDRA coding for adverse events.
|
| 18 |
+
[5] Lancet (2019). Under-reporting factor in SSA estimated at
|
| 19 |
+
90-95% — only 5-10% of ADRs are reported.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
import numpy as np
|
| 23 |
+
import pandas as pd
|
| 24 |
+
import argparse
|
| 25 |
+
import os
|
| 26 |
+
|
| 27 |
+
ADR_CATEGORIES = [
|
| 28 |
+
'hepatotoxicity', 'nephrotoxicity', 'skin_reaction_SJS',
|
| 29 |
+
'anaphylaxis', 'QT_prolongation', 'GI_disturbance',
|
| 30 |
+
'haematological_toxicity', 'neurotoxicity', 'ototoxicity',
|
| 31 |
+
'lactic_acidosis', 'tendon_rupture', 'hypoglycaemia',
|
| 32 |
+
'injection_site_reaction', 'drug_interaction', 'teratogenicity',
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
MEDICINE_CLASSES = [
|
| 36 |
+
'antimalarial', 'antibiotic', 'ARV', 'anti_TB',
|
| 37 |
+
'NSAID_analgesic', 'antihypertensive', 'antidiabetic',
|
| 38 |
+
'anticonvulsant', 'vaccine', 'herbal_traditional',
|
| 39 |
+
'antifungal', 'corticosteroid',
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
SCENARIOS = {
|
| 43 |
+
'functional_pv_centre': {
|
| 44 |
+
'pv_level': 'functional',
|
| 45 |
+
'reporting_rate_per_million': 40,
|
| 46 |
+
'ICSR_completeness': 0.70,
|
| 47 |
+
'causality_assessed': 0.65,
|
| 48 |
+
'sf_related_reports': 0.08,
|
| 49 |
+
'serious_proportion': 0.25,
|
| 50 |
+
'signal_detection_active': True,
|
| 51 |
+
'under_reporting_factor': 10,
|
| 52 |
+
'staff_pharmacovigilance': 8,
|
| 53 |
+
},
|
| 54 |
+
'emerging_pv_system': {
|
| 55 |
+
'pv_level': 'emerging',
|
| 56 |
+
'reporting_rate_per_million': 8,
|
| 57 |
+
'ICSR_completeness': 0.40,
|
| 58 |
+
'causality_assessed': 0.25,
|
| 59 |
+
'sf_related_reports': 0.15,
|
| 60 |
+
'serious_proportion': 0.35,
|
| 61 |
+
'signal_detection_active': False,
|
| 62 |
+
'under_reporting_factor': 25,
|
| 63 |
+
'staff_pharmacovigilance': 3,
|
| 64 |
+
},
|
| 65 |
+
'minimal_pv_capacity': {
|
| 66 |
+
'pv_level': 'minimal',
|
| 67 |
+
'reporting_rate_per_million': 0.5,
|
| 68 |
+
'ICSR_completeness': 0.15,
|
| 69 |
+
'causality_assessed': 0.05,
|
| 70 |
+
'sf_related_reports': 0.30,
|
| 71 |
+
'serious_proportion': 0.50,
|
| 72 |
+
'signal_detection_active': False,
|
| 73 |
+
'under_reporting_factor': 100,
|
| 74 |
+
'staff_pharmacovigilance': 0.5,
|
| 75 |
+
},
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def generate_dataset(n=10000, seed=42, scenario='emerging_pv_system'):
|
| 80 |
+
rng = np.random.default_rng(seed)
|
| 81 |
+
sc = SCENARIOS[scenario]
|
| 82 |
+
records = []
|
| 83 |
+
|
| 84 |
+
for idx in range(n):
|
| 85 |
+
rec = {'id': idx + 1}
|
| 86 |
+
rec['pv_level'] = sc['pv_level']
|
| 87 |
+
rec['reporting_facility_id'] = f"PV_{rng.integers(1, 300):04d}"
|
| 88 |
+
rec['reporter_type'] = rng.choice(
|
| 89 |
+
['physician', 'pharmacist', 'nurse', 'patient', 'CHW', 'other'],
|
| 90 |
+
p=[0.30, 0.25, 0.20, 0.10, 0.10, 0.05] if scenario == 'functional_pv_centre'
|
| 91 |
+
else ([0.20, 0.15, 0.25, 0.15, 0.15, 0.10] if scenario == 'emerging_pv_system'
|
| 92 |
+
else [0.10, 0.05, 0.15, 0.30, 0.25, 0.15]))
|
| 93 |
+
rec['facility_type'] = rng.choice(
|
| 94 |
+
['tertiary_hospital', 'district_hospital', 'health_centre',
|
| 95 |
+
'private_clinic', 'community', 'pharmacy'],
|
| 96 |
+
p=[0.25, 0.25, 0.20, 0.10, 0.10, 0.10] if scenario == 'functional_pv_centre'
|
| 97 |
+
else ([0.15, 0.20, 0.25, 0.15, 0.15, 0.10] if scenario == 'emerging_pv_system'
|
| 98 |
+
else [0.05, 0.10, 0.15, 0.10, 0.40, 0.20]))
|
| 99 |
+
|
| 100 |
+
rec['patient_age_group'] = rng.choice(
|
| 101 |
+
['neonate', 'infant', 'child', 'adolescent', 'adult', 'elderly'],
|
| 102 |
+
p=[0.03, 0.05, 0.10, 0.08, 0.55, 0.19])
|
| 103 |
+
rec['patient_sex'] = rng.choice(['male', 'female'], p=[0.45, 0.55])
|
| 104 |
+
rec['patient_pregnant'] = 1 if rec['patient_sex'] == 'female' and rng.random() < 0.08 else 0
|
| 105 |
+
|
| 106 |
+
rec['suspect_medicine_class'] = rng.choice(MEDICINE_CLASSES,
|
| 107 |
+
p=[0.12, 0.15, 0.12, 0.08, 0.10, 0.08, 0.07, 0.05,
|
| 108 |
+
0.08, 0.06, 0.05, 0.04])
|
| 109 |
+
rec['suspect_medicine_registered'] = 1 if rng.random() < (
|
| 110 |
+
0.90 if scenario == 'functional_pv_centre' else
|
| 111 |
+
(0.65 if scenario == 'emerging_pv_system' else 0.35)) else 0
|
| 112 |
+
rec['suspect_medicine_WHO_PQ'] = 1 if rng.random() < (
|
| 113 |
+
0.40 if scenario == 'functional_pv_centre' else
|
| 114 |
+
(0.15 if scenario == 'emerging_pv_system' else 0.03)) else 0
|
| 115 |
+
|
| 116 |
+
rec['sf_medicine_suspected'] = 1 if rng.random() < sc['sf_related_reports'] else 0
|
| 117 |
+
rec['sf_confirmed'] = 0
|
| 118 |
+
if rec['sf_medicine_suspected']:
|
| 119 |
+
rec['sf_confirmed'] = 1 if rng.random() < (
|
| 120 |
+
0.40 if scenario == 'functional_pv_centre' else
|
| 121 |
+
(0.15 if scenario == 'emerging_pv_system' else 0.03)) else 0
|
| 122 |
+
|
| 123 |
+
rec['adverse_event_type'] = rng.choice(ADR_CATEGORIES,
|
| 124 |
+
p=[0.08, 0.06, 0.07, 0.04, 0.03, 0.18, 0.06, 0.05, 0.03,
|
| 125 |
+
0.03, 0.02, 0.04, 0.08, 0.10, 0.13])
|
| 126 |
+
rec['seriousness'] = rng.choice(
|
| 127 |
+
['non_serious', 'serious_hospitalisation', 'serious_disability',
|
| 128 |
+
'serious_life_threatening', 'fatal'],
|
| 129 |
+
p=[1-sc['serious_proportion'], sc['serious_proportion']*0.50,
|
| 130 |
+
sc['serious_proportion']*0.20, sc['serious_proportion']*0.20,
|
| 131 |
+
sc['serious_proportion']*0.10])
|
| 132 |
+
|
| 133 |
+
rec['causality_assessment'] = 'not_assessed'
|
| 134 |
+
if rng.random() < sc['causality_assessed']:
|
| 135 |
+
rec['causality_assessment'] = rng.choice(
|
| 136 |
+
['certain', 'probable', 'possible', 'unlikely', 'unclassifiable'],
|
| 137 |
+
p=[0.05, 0.25, 0.40, 0.20, 0.10])
|
| 138 |
+
|
| 139 |
+
rec['ICSR_completeness_score'] = int(np.clip(
|
| 140 |
+
rng.normal(sc['ICSR_completeness'] * 100, 15), 5, 100))
|
| 141 |
+
rec['report_within_30_days'] = 1 if rng.random() < (
|
| 142 |
+
0.60 if scenario == 'functional_pv_centre' else
|
| 143 |
+
(0.25 if scenario == 'emerging_pv_system' else 0.05)) else 0
|
| 144 |
+
rec['follow_up_obtained'] = 1 if rng.random() < (
|
| 145 |
+
0.45 if scenario == 'functional_pv_centre' else
|
| 146 |
+
(0.15 if scenario == 'emerging_pv_system' else 0.03)) else 0
|
| 147 |
+
rec['entered_in_vigibase'] = 1 if rng.random() < (
|
| 148 |
+
0.70 if scenario == 'functional_pv_centre' else
|
| 149 |
+
(0.20 if scenario == 'emerging_pv_system' else 0.02)) else 0
|
| 150 |
+
|
| 151 |
+
rec['signal_detected'] = 0
|
| 152 |
+
if sc['signal_detection_active'] and rng.random() < 0.02:
|
| 153 |
+
rec['signal_detected'] = 1
|
| 154 |
+
rec['regulatory_action_triggered'] = 0
|
| 155 |
+
if rec['signal_detected'] or (rec['seriousness'] == 'fatal' and rng.random() < 0.15):
|
| 156 |
+
rec['regulatory_action_triggered'] = 1
|
| 157 |
+
|
| 158 |
+
rec['outcome'] = rng.choice(
|
| 159 |
+
['recovered', 'recovering', 'not_recovered', 'fatal', 'unknown'],
|
| 160 |
+
p=[0.35, 0.20, 0.15, sc['serious_proportion']*0.10,
|
| 161 |
+
0.30 - sc['serious_proportion']*0.10])
|
| 162 |
+
rec['estimated_underreporting_factor'] = sc['under_reporting_factor']
|
| 163 |
+
|
| 164 |
+
rec['year'] = rng.choice([2020, 2021, 2022, 2023, 2024],
|
| 165 |
+
p=[0.10, 0.15, 0.20, 0.25, 0.30])
|
| 166 |
+
|
| 167 |
+
records.append(rec)
|
| 168 |
+
|
| 169 |
+
df = pd.DataFrame(records)
|
| 170 |
+
print(f"\n{'='*65}")
|
| 171 |
+
print(f"Pharmacovigilance — {scenario} (n={n}, seed={seed})")
|
| 172 |
+
print(f"{'='*65}")
|
| 173 |
+
print(f" PV level: {sc['pv_level']}")
|
| 174 |
+
print(f" Serious ADRs: {(df['seriousness']!='non_serious').mean()*100:.1f}%")
|
| 175 |
+
print(f" SF-related: {df['sf_medicine_suspected'].mean()*100:.1f}%")
|
| 176 |
+
print(f" Causality assessed: {(df['causality_assessment']!='not_assessed').mean()*100:.1f}%")
|
| 177 |
+
print(f" VigiBase entry: {df['entered_in_vigibase'].mean()*100:.1f}%")
|
| 178 |
+
return df
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
parser = argparse.ArgumentParser()
|
| 183 |
+
parser.add_argument('--all-scenarios', action='store_true')
|
| 184 |
+
parser.add_argument('--n', type=int, default=10000)
|
| 185 |
+
parser.add_argument('--seed', type=int, default=42)
|
| 186 |
+
args = parser.parse_args()
|
| 187 |
+
os.makedirs('data', exist_ok=True)
|
| 188 |
+
if args.all_scenarios:
|
| 189 |
+
for sc in SCENARIOS:
|
| 190 |
+
df = generate_dataset(n=args.n, seed=args.seed, scenario=sc)
|
| 191 |
+
df.to_csv(os.path.join('data', f'pv_{sc}.csv'), index=False)
|
| 192 |
+
print(f" -> Saved\n")
|
| 193 |
+
else:
|
| 194 |
+
df = generate_dataset(n=args.n, seed=args.seed)
|
| 195 |
+
df.to_csv(os.path.join('data', 'pv_emerging_pv_system.csv'), index=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy>=1.24
|
| 2 |
+
pandas>=2.0
|
| 3 |
+
matplotlib>=3.7
|
validate_dataset.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Validation & Diagnostic Visualization for Post-Market Surveillance & Pharmacovigilance Dataset."""
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
SCENARIOS = ['functional_pv_centre', 'emerging_pv_system', 'minimal_pv_capacity']
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def load_scenarios(data_dir='data'):
|
| 13 |
+
dfs = {}
|
| 14 |
+
for sc in SCENARIOS:
|
| 15 |
+
path = os.path.join(data_dir, f'pv_{sc}.csv')
|
| 16 |
+
if os.path.exists(path):
|
| 17 |
+
dfs[sc] = pd.read_csv(path)
|
| 18 |
+
return dfs
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def make_report(dfs, output='validation_report.png'):
|
| 22 |
+
fig, axes = plt.subplots(4, 2, figsize=(16, 24))
|
| 23 |
+
fig.suptitle(
|
| 24 |
+
'Post-Market Surveillance & Pharmacovigilance — Validation Report\n'
|
| 25 |
+
'(Functional PV → Emerging PV → Minimal PV)',
|
| 26 |
+
fontsize=15, fontweight='bold', y=0.99)
|
| 27 |
+
colors = ['#2ecc71', '#f39c12', '#e74c3c']
|
| 28 |
+
x = np.arange(len(SCENARIOS))
|
| 29 |
+
labels = ['Functional', 'Emerging', 'Minimal']
|
| 30 |
+
|
| 31 |
+
ax = axes[0, 0]
|
| 32 |
+
ser = [(dfs[sc]['seriousness']!='non_serious').mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 33 |
+
ax.bar(x, ser, color=colors, alpha=0.8)
|
| 34 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 35 |
+
for i, v in enumerate(ser):
|
| 36 |
+
ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
|
| 37 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('Serious ADR Proportion')
|
| 38 |
+
|
| 39 |
+
ax = axes[0, 1]
|
| 40 |
+
ca = [(dfs[sc]['causality_assessment']!='not_assessed').mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 41 |
+
ax.bar(x, ca, color=colors, alpha=0.8)
|
| 42 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 43 |
+
for i, v in enumerate(ca):
|
| 44 |
+
ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
|
| 45 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('Causality Assessment Done')
|
| 46 |
+
|
| 47 |
+
ax = axes[1, 0]
|
| 48 |
+
sf = [dfs[sc]['sf_medicine_suspected'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 49 |
+
ax.bar(x, sf, color=colors, alpha=0.8)
|
| 50 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 51 |
+
for i, v in enumerate(sf):
|
| 52 |
+
ax.text(i, v+0.5, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
|
| 53 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('SF Medicine Suspected in ADR Reports')
|
| 54 |
+
|
| 55 |
+
ax = axes[1, 1]
|
| 56 |
+
vb = [dfs[sc]['entered_in_vigibase'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 57 |
+
ax.bar(x, vb, color=colors, alpha=0.8)
|
| 58 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 59 |
+
for i, v in enumerate(vb):
|
| 60 |
+
ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
|
| 61 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('Entered in VigiBase')
|
| 62 |
+
|
| 63 |
+
ax = axes[2, 0]
|
| 64 |
+
df = dfs.get('emerging_pv_system', list(dfs.values())[1])
|
| 65 |
+
ae = df['adverse_event_type'].value_counts().head(10)
|
| 66 |
+
ax.barh(range(len(ae)), ae.values, color='#e74c3c', alpha=0.7)
|
| 67 |
+
ax.set_yticks(range(len(ae)))
|
| 68 |
+
ax.set_yticklabels([s.replace('_', ' ').title() for s in ae.index], fontsize=7)
|
| 69 |
+
ax.set_xlabel('Count'); ax.set_title('Top Adverse Event Types (Emerging)')
|
| 70 |
+
|
| 71 |
+
ax = axes[2, 1]
|
| 72 |
+
mc = df['suspect_medicine_class'].value_counts().head(10)
|
| 73 |
+
ax.barh(range(len(mc)), mc.values, color='#3498db', alpha=0.7)
|
| 74 |
+
ax.set_yticks(range(len(mc)))
|
| 75 |
+
ax.set_yticklabels([s.replace('_', ' ').title() for s in mc.index], fontsize=7)
|
| 76 |
+
ax.set_xlabel('Count'); ax.set_title('Top Suspect Medicine Classes (Emerging)')
|
| 77 |
+
|
| 78 |
+
ax = axes[3, 0]
|
| 79 |
+
sev = df['seriousness'].value_counts()
|
| 80 |
+
ax.pie(sev.values, labels=[s.replace('_', ' ').title() for s in sev.index],
|
| 81 |
+
autopct='%1.0f%%', colors=['#2ecc71', '#f39c12', '#e74c3c', '#9b59b6', '#34495e'][:len(sev)],
|
| 82 |
+
textprops={'fontsize': 7})
|
| 83 |
+
ax.set_title('Seriousness Distribution (Emerging)')
|
| 84 |
+
|
| 85 |
+
ax = axes[3, 1]
|
| 86 |
+
comp = [dfs[sc]['ICSR_completeness_score'].mean() for sc in SCENARIOS if sc in dfs]
|
| 87 |
+
ax.bar(x, comp, color=colors, alpha=0.8)
|
| 88 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 89 |
+
for i, v in enumerate(comp):
|
| 90 |
+
ax.text(i, v+1, f'{v:.0f}', ha='center', fontsize=10, fontweight='bold')
|
| 91 |
+
ax.set_ylabel('Score (0-100)'); ax.set_title('ICSR Completeness Score')
|
| 92 |
+
|
| 93 |
+
plt.tight_layout(rect=[0, 0, 1, 0.97])
|
| 94 |
+
plt.savefig(output, dpi=150, bbox_inches='tight')
|
| 95 |
+
print(f'Saved validation report to {output}')
|
| 96 |
+
plt.close()
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
if __name__ == '__main__':
|
| 100 |
+
dfs = load_scenarios()
|
| 101 |
+
if dfs:
|
| 102 |
+
make_report(dfs)
|
validation_report.png
ADDED
|
Git LFS Details
|