| |
| """ |
| Literature-Informed Online Pharmacy & E-Pharmacy Regulation Dataset |
| ===================================================================== |
| |
| Each record = ONE online medicine purchase/listing assessed. |
| |
| Sources (v2.0): |
| [1] WHO (2024). SF products increasingly sold online. Rise of |
| unauthorized e-pharmacy sites exacerbates SF problem. |
| [2] NABP (2023). 95% of online pharmacies globally do not comply |
| with pharmacy laws and practice standards. |
| [3] Interpol Operation Pangea. Annual crackdown on illicit online |
| pharmacies. 2022: 4,000+ websites shut down. |
| [4] LegitScript. ~30,000+ rogue pharmacy websites identified. |
| Most sell prescription medicines without prescriptions. |
| [5] WHO Africa (2023). E-pharmacy regulation nascent in SSA. |
| Only 5-10 countries have specific e-pharmacy legislation. |
| """ |
|
|
| import numpy as np |
| import pandas as pd |
| import argparse |
| import os |
|
|
| PRODUCT_CATEGORIES = [ |
| ('erectile_dysfunction', 'lifestyle', 0.15), |
| ('weight_loss', 'lifestyle', 0.10), |
| ('antibiotic', 'prescription', 0.12), |
| ('opioid_analgesic', 'controlled', 0.08), |
| ('benzodiazepine', 'controlled', 0.05), |
| ('antimalarial', 'essential', 0.08), |
| ('ARV_HIV', 'essential', 0.04), |
| ('antihypertensive', 'NCD', 0.06), |
| ('antidiabetic', 'NCD', 0.05), |
| ('contraceptive', 'reproductive', 0.04), |
| ('skin_lightening', 'cosmetic', 0.06), |
| ('COVID_treatment', 'pandemic', 0.03), |
| ('traditional_herbal', 'unregulated', 0.05), |
| ('supplement_vitamin', 'OTC', 0.05), |
| ('cancer_medicine', 'specialty', 0.04), |
| ] |
|
|
| SCENARIOS = { |
| 'licensed_e_pharmacy': { |
| 'platform_type': 'licensed_e_pharmacy', |
| 'sf_rate': 0.05, |
| 'falsified_rate': 0.01, |
| 'no_prescription_rate': 0.15, |
| 'unregistered_product_rate': 0.08, |
| 'regulatory_compliant': 0.85, |
| 'pharmacist_available': 0.90, |
| 'verified_supplier': 0.88, |
| 'delivery_cold_chain': 0.70, |
| 'consumer_complaint_rate': 0.03, |
| }, |
| 'social_media_marketplace': { |
| 'platform_type': 'social_media', |
| 'sf_rate': 0.35, |
| 'falsified_rate': 0.15, |
| 'no_prescription_rate': 0.92, |
| 'unregistered_product_rate': 0.55, |
| 'regulatory_compliant': 0.02, |
| 'pharmacist_available': 0.05, |
| 'verified_supplier': 0.08, |
| 'delivery_cold_chain': 0.05, |
| 'consumer_complaint_rate': 0.20, |
| }, |
| 'rogue_website_darknet': { |
| 'platform_type': 'rogue_website', |
| 'sf_rate': 0.65, |
| 'falsified_rate': 0.40, |
| 'no_prescription_rate': 0.99, |
| 'unregistered_product_rate': 0.85, |
| 'regulatory_compliant': 0.00, |
| 'pharmacist_available': 0.01, |
| 'verified_supplier': 0.02, |
| 'delivery_cold_chain': 0.01, |
| 'consumer_complaint_rate': 0.45, |
| }, |
| } |
|
|
|
|
| def generate_dataset(n=10000, seed=42, scenario='social_media_marketplace'): |
| rng = np.random.default_rng(seed) |
| sc = SCENARIOS[scenario] |
| records = [] |
| n_prod = len(PRODUCT_CATEGORIES) |
|
|
| for idx in range(n): |
| rec = {'id': idx + 1} |
| rec['platform_type'] = sc['platform_type'] |
| rec['seller_id'] = f"EPHARM_{rng.integers(1, 1000):05d}" |
| rec['platform_name'] = rng.choice( |
| ['WhatsApp', 'Facebook', 'Instagram', 'Telegram', 'TikTok', |
| 'dedicated_website', 'marketplace_app', 'darknet_market'], |
| p=[0.10, 0.15, 0.10, 0.08, 0.05, 0.25, 0.15, 0.12] |
| if scenario == 'social_media_marketplace' |
| else ([0.02, 0.03, 0.02, 0.01, 0.01, 0.80, 0.10, 0.01] |
| if scenario == 'licensed_e_pharmacy' |
| else [0.03, 0.05, 0.03, 0.10, 0.02, 0.30, 0.07, 0.40])) |
|
|
| prod = PRODUCT_CATEGORIES[rng.choice(n_prod, |
| p=[p[2] for p in PRODUCT_CATEGORIES])] |
| rec['product_name'] = prod[0] |
| rec['product_category'] = prod[1] |
|
|
| rec['prescription_required_legally'] = 1 if prod[1] in ( |
| 'prescription', 'controlled', 'essential', 'NCD', 'specialty') else 0 |
| rec['prescription_verified'] = 0 |
| if rec['prescription_required_legally']: |
| rec['prescription_verified'] = 0 if rng.random() < sc['no_prescription_rate'] else 1 |
|
|
| rec['product_registered'] = 0 if rng.random() < sc['unregistered_product_rate'] else 1 |
| rec['seller_licensed'] = 1 if rng.random() < sc['regulatory_compliant'] else 0 |
| rec['pharmacist_consultation'] = 1 if rng.random() < sc['pharmacist_available'] else 0 |
| rec['verified_supply_chain'] = 1 if rng.random() < sc['verified_supplier'] else 0 |
| rec['cold_chain_maintained'] = 1 if rng.random() < sc['delivery_cold_chain'] else 0 |
|
|
| rec['manufacturer_origin'] = rng.choice( |
| ['India', 'China', 'Europe', 'local_SSA', 'unknown', 'USA'], |
| p=[0.30, 0.20, 0.08, 0.07, 0.30, 0.05] |
| if scenario != 'licensed_e_pharmacy' |
| else [0.35, 0.10, 0.15, 0.15, 0.10, 0.15]) |
|
|
| |
| base_sf = sc['sf_rate'] |
| if not rec['product_registered']: |
| base_sf *= 1.4 |
| if not rec['verified_supply_chain']: |
| base_sf *= 1.3 |
| if rec['manufacturer_origin'] == 'unknown': |
| base_sf *= 1.5 |
| if prod[1] == 'controlled': |
| base_sf *= 1.3 |
| if prod[1] == 'lifestyle': |
| base_sf *= 1.2 |
| base_sf = np.clip(base_sf, 0.01, 0.90) |
|
|
| is_sf = rng.random() < base_sf |
| rec['quality_test_result'] = 'fail' if is_sf else 'pass' |
| rec['sf_classification'] = 'compliant' |
| if is_sf: |
| fals_prob = sc['falsified_rate'] / max(sc['sf_rate'], 0.001) |
| rec['sf_classification'] = 'falsified' if rng.random() < fals_prob else 'substandard' |
|
|
| rec['API_content_adequate'] = 1 |
| if is_sf: |
| rec['API_content_adequate'] = 0 if rng.random() < 0.65 else 1 |
|
|
| rec['price_vs_reference'] = round(np.clip( |
| rng.normal(0.40 if scenario == 'rogue_website_darknet' else |
| (0.70 if scenario == 'social_media_marketplace' else 0.90), 0.20), |
| 0.10, 2.0), 2) |
| rec['payment_method'] = rng.choice( |
| ['mobile_money', 'bank_transfer', 'cash_on_delivery', |
| 'cryptocurrency', 'credit_card'], |
| p=[0.35, 0.15, 0.30, 0.05, 0.15] |
| if scenario != 'rogue_website_darknet' |
| else [0.10, 0.10, 0.05, 0.50, 0.25]) |
|
|
| rec['consumer_age_group'] = rng.choice( |
| ['18_24', '25_34', '35_49', '50_plus'], |
| p=[0.25, 0.35, 0.25, 0.15]) |
| rec['consumer_education'] = rng.choice( |
| ['primary', 'secondary', 'tertiary'], |
| p=[0.15, 0.40, 0.45] if scenario != 'rogue_website_darknet' |
| else [0.05, 0.30, 0.65]) |
| rec['consumer_complaint_filed'] = 1 if rng.random() < sc['consumer_complaint_rate'] else 0 |
| rec['adverse_event_reported'] = 0 |
| if is_sf: |
| rec['adverse_event_reported'] = 1 if rng.random() < 0.05 else 0 |
|
|
| rec['website_takedown'] = 0 |
| if scenario == 'rogue_website_darknet' and rng.random() < 0.03: |
| rec['website_takedown'] = 1 |
| elif scenario == 'social_media_marketplace' and rng.random() < 0.01: |
| rec['website_takedown'] = 1 |
|
|
| rec['year'] = rng.choice([2020, 2021, 2022, 2023, 2024], |
| p=[0.08, 0.12, 0.18, 0.28, 0.34]) |
|
|
| records.append(rec) |
|
|
| df = pd.DataFrame(records) |
| sf_rate = df['quality_test_result'].eq('fail').mean() * 100 |
| print(f"\n{'='*65}") |
| print(f"Online Pharmacy — {scenario} (n={n}, seed={seed})") |
| print(f"{'='*65}") |
| print(f" SF rate: {sf_rate:.1f}% (target ~{sc['sf_rate']*100:.0f}%)") |
| print(f" No prescription: {(1-df['prescription_verified'].mean())*100:.1f}%") |
| print(f" Licensed seller: {df['seller_licensed'].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'epharmacy_{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', 'epharmacy_social_media_marketplace.csv'), index=False) |
|
|