Kossisoroyce commited on
Commit
d76d275
·
verified ·
1 Parent(s): 9f18c5e

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - supply-chain
11
+ - medical-oxygen
12
+ - hypoxemia
13
+ - pulse-oximetry
14
+ - concentrator
15
+ - PSA-plant
16
+ - pneumonia
17
+ - neonatal
18
+ - sub-saharan-africa
19
+ - lmic
20
+ pretty_name: "Medical Oxygen Supply (Availability, Equipment, Hypoxemia Mortality, Supply Chain)"
21
+ size_categories:
22
+ - 10K<n<100K
23
+ configs:
24
+ - config_name: referral_hospital
25
+ data_files: data/oxygen_referral_hospital.csv
26
+ - config_name: district_hospital
27
+ data_files: data/oxygen_district_hospital.csv
28
+ default: true
29
+ - config_name: rural_health_centre
30
+ data_files: data/oxygen_rural_health_centre.csv
31
+ ---
32
+
33
+ # Medical Oxygen Supply Dataset
34
+
35
+ ## Abstract
36
+
37
+ This dataset provides **30,000 simulated facility-level observations** (10,000 per scenario) of medical oxygen availability, delivery infrastructure, pulse oximetry access, and patient outcomes across three tiers of healthcare in sub-Saharan Africa. Each record represents one facility observation for one monthly period, capturing 40+ variables including oxygen source type, concentrator and cylinder status, pulse oximetry functionality, patient oxygen demand and coverage, hypoxemia-related mortality, shortage root causes, and logistics metrics. Three scenarios model the oxygen access gradient: referral hospital (82% availability), district hospital (50%), and rural health centre (12%).
38
+
39
+ **This dataset is entirely simulated. It must not be used for clinical decision-making or procurement.**
40
+
41
+ ## 1. Introduction
42
+
43
+ ### 1.1 The Medical Oxygen Crisis
44
+
45
+ Medical oxygen is classified as an essential medicine by the World Health Organization, yet sub-Saharan Africa faces a profound and chronic oxygen deficit. According to analysis by the Institute for Transformative Technologies and Oxygen Hub, most SSA countries have less than 10% of the oxygen volume needed to treat high-burden conditions including childhood pneumonia, COPD, neonatal respiratory distress syndrome, and severe malaria (Oxygen Hub/ITT, 2021). COVID-19 both exacerbated and exposed this gap, triggering emergency investments that remain insufficient for sustained coverage.
46
+
47
+ ### 1.2 Supply Infrastructure
48
+
49
+ Historically, the dominant oxygen supply method in SSA has been compressed gas cylinders filled from cryogenic liquid oxygen (LOX) plants — facilities originally built for industrial applications and concentrated in capital cities. The medical oxygen market is dominated by a small number of LOX providers exhibiting monopolistic tendencies, with nearly 6 in 10 SSA countries dependent on a single supplier (PMC, 2022; PMC9771461).
50
+
51
+ Pressure swing adsorption (PSA) plants have emerged as a decentralised alternative, but maintenance failures are endemic. As of October 2022, at least 165 PSA plants globally needed repair, of which 151 (92%) were located in sub-Saharan Africa (PMC, 2022; PMC9771461). The WHO distributed over 30,000 oxygen concentrators worldwide, yet SSA faces significant challenges related to maintenance, spare parts, and reliable power supply (BMC Health Services Research, 2025; doi:10.1186/s12913-025-12315-6).
52
+
53
+ ### 1.3 Availability at the Facility Level
54
+
55
+ A systematic assessment found that approximately half of health facilities in resource-limited settings had either no or inconsistent supply of medical oxygen and pulse oximeters, with the situation worst in the poorest countries of sub-Saharan Africa (PMC, 2024; PMC11082622). A scoping review of oxygen delivery systems for adults in SSA documented hypoxemia prevalence ranging from 11% to 89% across study populations, with high mortality among those with undetected or untreated hypoxemia (PMC, 2021; PMC8109278).
56
+
57
+ ### 1.4 Pulse Oximetry: The Detection Gap
58
+
59
+ Oxygen therapy depends on the ability to detect hypoxemia. Pulse oximetry is the essential screening tool, yet availability is profoundly limited at lower facility levels. Without pulse oximetry, clinical recognition of hypoxemia relies on subjective signs (cyanosis, respiratory distress) that are unreliable, particularly in dark-skinned patients and neonates. The absence of pulse oximetry means that many hypoxemic patients are never identified and never receive oxygen.
60
+
61
+ ### 1.5 Patient Impact and Mortality
62
+
63
+ Untreated hypoxemia carries high case fatality rates. Childhood pneumonia with hypoxemia has mortality rates of 35–55% without oxygen therapy in LMIC settings, compared with 5–15% when oxygen is provided. Neonatal respiratory distress syndrome, severe malaria, and sepsis all require oxygen as a life-saving intervention. The oxygen-attributable mortality burden in SSA is estimated in the hundreds of thousands annually.
64
+
65
+ ### 1.6 Rationale for This Dataset
66
+
67
+ Despite growing investment post-COVID, no open, standardised dataset integrates oxygen source infrastructure, equipment functionality, pulse oximetry access, patient-level demand and coverage, and mortality outcomes into a single analytical resource. This dataset fills that gap for supply chain modelling, equipment investment prioritisation, and health systems research.
68
+
69
+ ## 2. Methodology
70
+
71
+ ### 2.1 Epidemiological Parameterization
72
+
73
+ | Parameter | Referral Hospital | District Hospital | Rural HC | Source |
74
+ | --- | --- | --- | --- | --- |
75
+ | Oxygen available | 82% | 50% | 12% | [6] ~50% facilities lack oxygen |
76
+ | Sufficient for demand | 65% | 35% | 8% | [1] <10% volume needed |
77
+ | Pulse oximeter functional | 85% | 14% | 0.4% | [4][6] Limited at lower levels |
78
+ | Concentrator functional rate | 70% | 45% | 15% | [5] Maintenance challenges |
79
+ | PSA plant functional | 55% | N/A | N/A | [3] 151/165 needing repair |
80
+ | Cylinder refill interval | 5 days | 21 days | 45 days | [1] Urban vs rural logistics |
81
+ | Mortality untreated hypoxemia | 35% | 45% | 55% | [4] Scoping review |
82
+ | Distance to refill | 15 km | 50 km | 120 km | Geographic analysis |
83
+
84
+ ### 2.2 Scenario Design
85
+
86
+ **Scenario A — Referral/Teaching Hospital**: PSA plant or LOX bulk tank, piped oxygen system, ICU/NICU, pulse oximetry, biomedical technician, reliable power with generator backup. Analogous to Muhimbili (Tanzania), Kenyatta (Kenya), Mulago (Uganda).
87
+
88
+ **Scenario B — District Hospital**: Oxygen concentrators and/or portable cylinders, limited pulse oximetry (35% have device, 40% functional), no ICU, clinical officer manages oxygen, unreliable power. Analogous to district hospitals in Malawi, Rwanda, Mozambique.
89
+
90
+ **Scenario C — Rural Health Centre**: No permanent oxygen source (70% have none), no pulse oximetry, nurse-managed, no power grid. Occasional cylinder if transport available. Analogous to health centres in Niger, DRC, South Sudan, rural Ethiopia.
91
+
92
+ ## 3. Schema
93
+
94
+ ### 3.1 Facility Infrastructure
95
+
96
+ | Column | Type | Description |
97
+ | --- | --- | --- |
98
+ | facility_level | categorical | referral_hospital / district_hospital / rural_health_centre |
99
+ | bed_count | int | Total bed capacity |
100
+ | has_icu | binary | Intensive care unit present |
101
+ | has_nicu | binary | Neonatal ICU present |
102
+ | has_piped_oxygen | binary | Piped oxygen distribution system |
103
+ | has_biomedical_technician | binary | Technician for equipment maintenance |
104
+
105
+ ### 3.2 Oxygen Source & Equipment
106
+
107
+ | Column | Type | Description |
108
+ | --- | --- | --- |
109
+ | primary_oxygen_source | categorical | PSA_plant_onsite / LOX_bulk_tank / oxygen_concentrator / cylinder_piped / cylinder_portable / none |
110
+ | concentrator_count | int | Number of oxygen concentrators |
111
+ | concentrator_functional | int | Number currently functional |
112
+ | concentrator_mean_age_years | float | Average equipment age |
113
+ | concentrator_maintenance_available | binary | Maintenance capacity exists |
114
+ | cylinder_count_full | int | Full cylinders on hand |
115
+ | cylinder_count_empty | int | Empty cylinders awaiting refill |
116
+ | days_since_cylinder_refill | int | Days since last cylinder delivery |
117
+ | PSA_plant_functional | binary | On-site PSA plant operational |
118
+
119
+ ### 3.3 Pulse Oximetry
120
+
121
+ | Column | Type | Description |
122
+ | --- | --- | --- |
123
+ | pulse_oximeter_available | binary | Device present at facility |
124
+ | pulse_oximeter_functional | binary | Device operational |
125
+ | SpO2_screening_routine | binary | Routine SpO2 screening practiced |
126
+
127
+ ### 3.4 Availability & Shortage
128
+
129
+ | Column | Type | Description |
130
+ | --- | --- | --- |
131
+ | oxygen_available_today | binary | Oxygen available on assessment day |
132
+ | oxygen_sufficient_for_demand | binary | Supply meets current patient demand |
133
+ | oxygen_stockout_days_last_month | int | Days without oxygen in past month |
134
+ | shortage_cause | categorical | 11 root cause categories |
135
+
136
+ ### 3.5 Patient Demand & Outcomes
137
+
138
+ | Column | Type | Description |
139
+ | --- | --- | --- |
140
+ | patients_needing_oxygen | int | Patients requiring supplemental oxygen |
141
+ | primary_condition | categorical | 12 clinical conditions requiring oxygen |
142
+ | patients_received_oxygen | int | Patients who actually received oxygen |
143
+ | patients_untreated_hypoxemia | int | Patients with unmet oxygen need |
144
+ | flow_rate_adequate | binary | Oxygen delivered at therapeutic flow rate |
145
+ | deaths_hypoxemia_related | int | Deaths attributable to untreated hypoxemia |
146
+ | referred_for_oxygen | int | Patients referred to higher facility for oxygen |
147
+
148
+ ### 3.6 Logistics & Cost
149
+
150
+ | Column | Type | Description |
151
+ | --- | --- | --- |
152
+ | monthly_oxygen_cost_usd | float | Monthly oxygen expenditure (USD) |
153
+ | distance_to_refill_km | float | Distance to nearest cylinder refill point |
154
+ | transport_available_for_cylinders | binary | Vehicle available for cylinder transport |
155
+ | power_source | categorical | grid_reliable / grid_unreliable / generator_only / solar / none |
156
+ | power_outage_hours_last_week | int | Hours without electricity |
157
+
158
+ ## 4. Validation
159
+
160
+ <p align="center">
161
+ <img src="validation_report.png" alt="Validation Report" width="100%">
162
+ </p>
163
+
164
+ ### 4.1 Key Validation Results
165
+
166
+ | Metric | Referral | District | Rural | Literature |
167
+ | --- | --- | --- | --- | --- |
168
+ | Oxygen available | 82% | 50% | 12% | ~50% lack oxygen [6] |
169
+ | Sufficient supply | 65% | 35% | 8% | <10% volume [1] |
170
+ | Pulse ox functional | 85% | 14% | 0.4% | Limited periphery [4] |
171
+ | Mean patients needing O2 | 40 | 12 | 3 | Facility volume |
172
+ | Mean patients receiving O2 | 26 | 2.5 | 0 | Coverage gap |
173
+ | Mean deaths/observation | 5.0 | 4.3 | 1.7 | High mortality [4] |
174
+
175
+ ## 5. Usage
176
+
177
+ ```python
178
+ from datasets import load_dataset
179
+
180
+ dataset = load_dataset(
181
+ "electricsheepafrica/medical-oxygen-supply",
182
+ "district_hospital"
183
+ )
184
+ df = dataset["train"].to_pandas()
185
+
186
+ # Oxygen coverage gap analysis
187
+ df['coverage_pct'] = df['patients_received_oxygen'] / df['patients_needing_oxygen'].clip(lower=1) * 100
188
+ print(df.groupby('primary_oxygen_source')['coverage_pct'].mean())
189
+ ```
190
+
191
+ ### 5.1 Suggested Analyses
192
+
193
+ - **Oxygen access prediction**: Classify facilities at risk of stockout from infrastructure and logistics features.
194
+ - **Mortality modelling**: Quantify the relationship between oxygen availability, pulse oximetry, and hypoxemia deaths.
195
+ - **Equipment investment**: Compare cost-effectiveness of concentrators vs cylinders vs PSA plants by facility type.
196
+ - **Power dependency**: Model the impact of electrification and solar deployment on oxygen availability.
197
+
198
+ ## 6. Limitations
199
+
200
+ - **Simulated**: Not from real oxygen surveys or health management information systems.
201
+ - **No temporal dynamics**: Cross-sectional observations, not longitudinal supply chain tracking.
202
+ - **Simplified mortality**: Deaths are modelled from a single probability rather than full clinical pathways.
203
+ - **No ambient conditions**: Altitude, temperature, and humidity effects on concentrator performance not modelled.
204
+ - **No cost granularity**: Unit costs for cylinders, concentrators, and PSA are approximated, not market-specific.
205
+
206
+ ## 7. References
207
+
208
+ 1. Oxygen Hub / ITT (2021). Closing the medical oxygen gap in sub-Saharan Africa. oxygenhub.org/psaplants
209
+ 2. PMC (2022). Oxygen inequity in the COVID-19 pandemic and beyond. PMC9972372.
210
+ 3. PMC (2022). A comprehensive approach to medical oxygen ecosystem building. 151/165 broken PSA plants in SSA. PMC9771461.
211
+ 4. PMC (2021). Oxygen delivery systems for adults in sub-Saharan Africa: A scoping review. Hypoxemia prevalence 11–89%. PMC8109278.
212
+ 5. BMC Health Services Research (2025). Design and maintenance of medical oxygen concentrators in SSA. WHO distributed >30,000 OCs. doi:10.1186/s12913-025-12315-6
213
+ 6. PMC (2024). Functional availability of medical oxygen for management of pneumonia. ~50% facilities lack oxygen. PMC11082622.
214
+ 7. WHO (2023). Model List of Essential Medicines, 23rd list. Medical oxygen included.
215
+
216
+ ## Citation
217
+
218
+ ```bibtex
219
+ @dataset{esa_medical_oxygen_supply_2025,
220
+ title = {Medical Oxygen Supply Dataset: Availability, Equipment,
221
+ Hypoxemia Mortality, and Supply Chain Across Three Tiers
222
+ of Healthcare in Sub-Saharan Africa},
223
+ author = {{Electric Sheep Africa}},
224
+ year = {2025},
225
+ publisher = {Hugging Face},
226
+ url = {https://huggingface.co/datasets/electricsheepafrica/medical-oxygen-supply},
227
+ note = {Simulated dataset. Not for clinical or procurement use.}
228
+ }
229
+ ```
230
+
231
+ ## License
232
+
233
+ [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)
data/oxygen_district_hospital.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/oxygen_referral_hospital.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/oxygen_rural_health_centre.csv ADDED
The diff for this file is too large to render. See raw diff
 
generate_dataset.py ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Literature-Informed Medical Oxygen Supply Dataset
4
+ ====================================================
5
+
6
+ Generates realistic synthetic facility-level observations of medical
7
+ oxygen availability, delivery systems, equipment status, and patient
8
+ outcomes across three tiers of healthcare in sub-Saharan Africa.
9
+
10
+ Each record represents ONE facility observation for ONE monthly period.
11
+
12
+ Epidemiological Parameterization (web-searched):
13
+ -------------------------------------------------
14
+ [1] Oxygen Hub / ITT (2021). Closing the medical oxygen gap in SSA.
15
+ Most SSA countries have <10% of volume needed. PSA vs LOX
16
+ trade-offs. Decentralized hub-and-spoke model proposed.
17
+
18
+ [2] PMC (2022). Oxygen inequity in COVID-19 pandemic and beyond.
19
+ Ghana, Senegal SPRINT pilot. UNICEF workgroups. PMC9972372.
20
+
21
+ [3] PMC (2022). Comprehensive approach to medical oxygen ecosystem.
22
+ 165 PSA plants needing repair globally; 151 in SSA. PMC9771461.
23
+
24
+ [4] PMC (2021). Oxygen delivery systems for adults in SSA. Scoping
25
+ review. Hypoxemia prevalence 11-89%. High mortality among
26
+ hypoxemic patients. PMC8109278.
27
+
28
+ [5] BMC Health Services Research (2025). Design and maintenance of
29
+ oxygen concentrators in SSA. WHO distributed >30,000 OCs.
30
+ Maintenance challenges documented. doi:10.1186/s12913-025-12315-6
31
+
32
+ [6] PMC (2024). Functional availability of medical oxygen for
33
+ pneumonia management. ~50% of facilities in resource-limited
34
+ settings had no or inconsistent oxygen. PMC11082622.
35
+
36
+ [7] WHO (2023). Essential medicines list — medical oxygen included.
37
+ Pulse oximetry essential for identifying hypoxemia.
38
+ """
39
+
40
+ import numpy as np
41
+ import pandas as pd
42
+ import argparse
43
+ import os
44
+
45
+ OXYGEN_SOURCES = [
46
+ 'PSA_plant_onsite', 'LOX_bulk_tank', 'oxygen_concentrator',
47
+ 'cylinder_piped', 'cylinder_portable', 'none'
48
+ ]
49
+
50
+ PATIENT_CONDITIONS = [
51
+ 'pneumonia_child', 'pneumonia_adult', 'neonatal_respiratory',
52
+ 'COPD_exacerbation', 'COVID19_severe', 'severe_malaria',
53
+ 'heart_failure', 'surgical_anaesthesia', 'trauma',
54
+ 'asthma_severe', 'sepsis', 'other_hypoxemia'
55
+ ]
56
+
57
+ SHORTAGE_CAUSES = [
58
+ 'cylinder_delivery_delay', 'PSA_plant_breakdown', 'concentrator_malfunction',
59
+ 'power_outage', 'empty_cylinders_not_collected', 'funding_for_refill',
60
+ 'no_oxygen_source', 'demand_surge', 'supplier_stockout',
61
+ 'piping_system_leak', 'regulator_valve_failure',
62
+ ]
63
+
64
+ SCENARIOS = {
65
+ 'referral_hospital': {
66
+ 'description': (
67
+ 'Urban referral/teaching hospital with PSA plant or LOX '
68
+ 'bulk tank, piped oxygen system, pulse oximetry, ICU, '
69
+ 'biomedical technician. Analogous to Muhimbili (TZ), '
70
+ 'Kenyatta (KE), Mulago (UG).'
71
+ ),
72
+ 'facility_level': 'referral_hospital',
73
+ 'has_piped_system': True,
74
+ 'has_icu': True,
75
+ 'has_pulse_oximeter': True,
76
+ 'has_biomedical_tech': True,
77
+ 'oxygen_source_probs': [0.25, 0.30, 0.20, 0.20, 0.05, 0.00],
78
+ 'oxygen_available_rate': 0.82,
79
+ 'sufficient_quantity_rate': 0.65,
80
+ 'concentrator_functional_rate': 0.70,
81
+ 'pulse_ox_functional_rate': 0.85,
82
+ 'cylinder_refill_days': 5,
83
+ 'mortality_hypoxic_untreated': 0.35,
84
+ },
85
+ 'district_hospital': {
86
+ 'description': (
87
+ 'District hospital with oxygen concentrators and/or '
88
+ 'cylinders, limited pulse oximetry, no ICU, clinical '
89
+ 'officer manages oxygen. Analogous to district hospitals '
90
+ 'in Malawi, Rwanda, Mozambique.'
91
+ ),
92
+ 'facility_level': 'district_hospital',
93
+ 'has_piped_system': False,
94
+ 'has_icu': False,
95
+ 'has_pulse_oximeter': False,
96
+ 'has_biomedical_tech': False,
97
+ 'oxygen_source_probs': [0.02, 0.05, 0.35, 0.15, 0.30, 0.13],
98
+ 'oxygen_available_rate': 0.50,
99
+ 'sufficient_quantity_rate': 0.35,
100
+ 'concentrator_functional_rate': 0.45,
101
+ 'pulse_ox_functional_rate': 0.40,
102
+ 'cylinder_refill_days': 21,
103
+ 'mortality_hypoxic_untreated': 0.45,
104
+ },
105
+ 'rural_health_centre': {
106
+ 'description': (
107
+ 'Rural health centre with no permanent oxygen source, '
108
+ 'occasional cylinder if available, no pulse oximetry, '
109
+ 'nurse-managed. Analogous to health centres in Niger, '
110
+ 'DRC, South Sudan, rural Ethiopia.'
111
+ ),
112
+ 'facility_level': 'rural_health_centre',
113
+ 'has_piped_system': False,
114
+ 'has_icu': False,
115
+ 'has_pulse_oximeter': False,
116
+ 'has_biomedical_tech': False,
117
+ 'oxygen_source_probs': [0.00, 0.00, 0.08, 0.02, 0.20, 0.70],
118
+ 'oxygen_available_rate': 0.12,
119
+ 'sufficient_quantity_rate': 0.08,
120
+ 'concentrator_functional_rate': 0.15,
121
+ 'pulse_ox_functional_rate': 0.08,
122
+ 'cylinder_refill_days': 45,
123
+ 'mortality_hypoxic_untreated': 0.55,
124
+ },
125
+ }
126
+
127
+
128
+ def generate_dataset(n=10000, seed=42, scenario='district_hospital'):
129
+ rng = np.random.default_rng(seed)
130
+ sc = SCENARIOS[scenario]
131
+
132
+ records = []
133
+
134
+ for idx in range(n):
135
+ rec = {'id': idx + 1}
136
+
137
+ # ── 1. Facility characteristics ──
138
+ rec['facility_level'] = sc['facility_level']
139
+ rec['facility_id'] = f"O2_{rng.integers(1, 200):04d}"
140
+ rec['region_type'] = rng.choice(
141
+ ['urban', 'peri_urban', 'rural'],
142
+ p=[0.10, 0.15, 0.75] if scenario == 'rural_health_centre'
143
+ else ([0.55, 0.25, 0.20] if scenario == 'referral_hospital'
144
+ else [0.20, 0.35, 0.45]))
145
+ rec['bed_count'] = max(5, int(rng.normal(
146
+ 250 if scenario == 'referral_hospital' else
147
+ (60 if scenario == 'district_hospital' else 12), 40)))
148
+ rec['has_icu'] = 1 if sc['has_icu'] else (1 if rng.random() < 0.02 else 0)
149
+ rec['has_nicu'] = 1 if sc['has_icu'] else (1 if rng.random() < 0.05 else 0)
150
+ rec['has_piped_oxygen'] = 1 if sc['has_piped_system'] else (
151
+ 1 if rng.random() < 0.05 else 0)
152
+ rec['has_biomedical_technician'] = 1 if sc['has_biomedical_tech'] else (
153
+ 1 if rng.random() < 0.05 else 0)
154
+
155
+ # ── 2. Oxygen source & equipment [1][3][5] ──
156
+ rec['primary_oxygen_source'] = rng.choice(
157
+ OXYGEN_SOURCES, p=sc['oxygen_source_probs'])
158
+
159
+ rec['concentrator_count'] = 0
160
+ if rec['primary_oxygen_source'] == 'oxygen_concentrator' or rng.random() < 0.20:
161
+ rec['concentrator_count'] = max(0, int(rng.poisson(
162
+ 5 if scenario == 'referral_hospital' else
163
+ (2 if scenario == 'district_hospital' else 0.3))))
164
+ rec['concentrator_functional'] = 0
165
+ if rec['concentrator_count'] > 0:
166
+ func_rate = sc['concentrator_functional_rate']
167
+ rec['concentrator_functional'] = max(0, min(
168
+ rec['concentrator_count'],
169
+ int(rec['concentrator_count'] * rng.normal(func_rate, 0.2))))
170
+ rec['concentrator_mean_age_years'] = max(0, round(rng.exponential(
171
+ 3 if scenario == 'referral_hospital' else
172
+ (5 if scenario == 'district_hospital' else 8)), 1))
173
+ rec['concentrator_maintenance_available'] = 1 if rec['has_biomedical_technician'] else (
174
+ 1 if rng.random() < 0.10 else 0)
175
+
176
+ rec['cylinder_count_full'] = max(0, int(rng.poisson(
177
+ 10 if scenario == 'referral_hospital' else
178
+ (3 if scenario == 'district_hospital' else 0.5))))
179
+ rec['cylinder_count_empty'] = max(0, int(rng.poisson(
180
+ 5 if scenario == 'referral_hospital' else
181
+ (4 if scenario == 'district_hospital' else 1))))
182
+ rec['days_since_cylinder_refill'] = max(0, int(rng.exponential(
183
+ sc['cylinder_refill_days'])))
184
+
185
+ rec['PSA_plant_functional'] = 0
186
+ if rec['primary_oxygen_source'] == 'PSA_plant_onsite':
187
+ rec['PSA_plant_functional'] = 1 if rng.random() < 0.55 else 0
188
+
189
+ # ── 3. Pulse oximetry [4][6][7] ──
190
+ rec['pulse_oximeter_available'] = 1 if sc['has_pulse_oximeter'] else (
191
+ 1 if rng.random() < (0.35 if scenario == 'district_hospital' else 0.05) else 0)
192
+ rec['pulse_oximeter_functional'] = 0
193
+ if rec['pulse_oximeter_available']:
194
+ rec['pulse_oximeter_functional'] = 1 if rng.random() < sc['pulse_ox_functional_rate'] else 0
195
+ rec['SpO2_screening_routine'] = 0
196
+ if rec['pulse_oximeter_functional']:
197
+ rec['SpO2_screening_routine'] = 1 if rng.random() < (
198
+ 0.70 if scenario == 'referral_hospital' else
199
+ (0.30 if scenario == 'district_hospital' else 0.05)) else 0
200
+
201
+ # ── 4. Oxygen availability [1][6] ──
202
+ rec['oxygen_available_today'] = 1 if rng.random() < sc['oxygen_available_rate'] else 0
203
+ rec['oxygen_sufficient_for_demand'] = 0
204
+ if rec['oxygen_available_today']:
205
+ rec['oxygen_sufficient_for_demand'] = 1 if rng.random() < sc['sufficient_quantity_rate'] / sc['oxygen_available_rate'] else 0
206
+ rec['oxygen_stockout_days_last_month'] = 0
207
+ if not rec['oxygen_available_today']:
208
+ rec['oxygen_stockout_days_last_month'] = max(1, min(30,
209
+ int(rng.exponential(12))))
210
+ elif rng.random() < 0.20:
211
+ rec['oxygen_stockout_days_last_month'] = max(1, min(15,
212
+ int(rng.exponential(5))))
213
+
214
+ rec['shortage_cause'] = 'not_applicable'
215
+ if not rec['oxygen_available_today'] or rec['oxygen_stockout_days_last_month'] > 0:
216
+ if scenario == 'rural_health_centre':
217
+ cause_p = [0.15, 0.02, 0.05, 0.12, 0.05, 0.10, 0.35, 0.08, 0.05, 0.01, 0.02]
218
+ elif scenario == 'district_hospital':
219
+ cause_p = [0.25, 0.05, 0.18, 0.15, 0.08, 0.08, 0.05, 0.06, 0.04, 0.03, 0.03]
220
+ else:
221
+ cause_p = [0.10, 0.20, 0.15, 0.15, 0.05, 0.05, 0.02, 0.15, 0.05, 0.05, 0.03]
222
+ rec['shortage_cause'] = rng.choice(SHORTAGE_CAUSES, p=cause_p)
223
+
224
+ # ── 5. Reporting period ──
225
+ rec['year'] = rng.choice([2021, 2022, 2023, 2024],
226
+ p=[0.15, 0.25, 0.30, 0.30])
227
+ rec['month'] = rng.integers(1, 13)
228
+
229
+ # ── 6. Patient demand & utilisation ──
230
+ rec['patients_needing_oxygen'] = max(0, int(rng.poisson(
231
+ 40 if scenario == 'referral_hospital' else
232
+ (12 if scenario == 'district_hospital' else 3))))
233
+ rec['primary_condition'] = rng.choice(PATIENT_CONDITIONS,
234
+ p=[0.15, 0.12, 0.12, 0.08, 0.10, 0.08, 0.06, 0.08, 0.06, 0.05, 0.05, 0.05])
235
+ rec['patients_received_oxygen'] = 0
236
+ if rec['oxygen_available_today'] and rec['patients_needing_oxygen'] > 0:
237
+ coverage = rng.normal(
238
+ 0.80 if scenario == 'referral_hospital' else
239
+ (0.45 if scenario == 'district_hospital' else 0.10), 0.15)
240
+ rec['patients_received_oxygen'] = max(0, min(
241
+ rec['patients_needing_oxygen'],
242
+ int(rec['patients_needing_oxygen'] * np.clip(coverage, 0, 1))))
243
+ rec['patients_untreated_hypoxemia'] = max(0,
244
+ rec['patients_needing_oxygen'] - rec['patients_received_oxygen'])
245
+
246
+ rec['flow_rate_adequate'] = 0
247
+ if rec['patients_received_oxygen'] > 0:
248
+ rec['flow_rate_adequate'] = 1 if rng.random() < (
249
+ 0.75 if scenario == 'referral_hospital' else
250
+ (0.40 if scenario == 'district_hospital' else 0.15)) else 0
251
+
252
+ # ── 7. Outcomes ──
253
+ rec['deaths_hypoxemia_related'] = 0
254
+ if rec['patients_untreated_hypoxemia'] > 0:
255
+ mort_rate = sc['mortality_hypoxic_untreated']
256
+ rec['deaths_hypoxemia_related'] = max(0,
257
+ int(rng.binomial(rec['patients_untreated_hypoxemia'], mort_rate)))
258
+ rec['referred_for_oxygen'] = 0
259
+ if not rec['oxygen_available_today'] and rec['patients_needing_oxygen'] > 0:
260
+ rec['referred_for_oxygen'] = max(0, int(
261
+ rec['patients_needing_oxygen'] * rng.normal(0.30, 0.15)))
262
+
263
+ # ── 8. Cost & logistics ──
264
+ rec['monthly_oxygen_cost_usd'] = max(0, round(rng.normal(
265
+ 800 if scenario == 'referral_hospital' else
266
+ (200 if scenario == 'district_hospital' else 30),
267
+ 150 if scenario == 'referral_hospital' else
268
+ (80 if scenario == 'district_hospital' else 20)), 0))
269
+ rec['distance_to_refill_km'] = max(0, round(rng.exponential(
270
+ 15 if scenario == 'referral_hospital' else
271
+ (50 if scenario == 'district_hospital' else 120)), 0))
272
+ rec['transport_available_for_cylinders'] = 1 if rng.random() < (
273
+ 0.85 if scenario == 'referral_hospital' else
274
+ (0.40 if scenario == 'district_hospital' else 0.10)) else 0
275
+
276
+ # ── 9. Power supply (critical for concentrators/PSA) ──
277
+ rec['power_source'] = rng.choice(
278
+ ['grid_reliable', 'grid_unreliable', 'generator_only', 'solar', 'none'],
279
+ p=[0.40, 0.30, 0.15, 0.10, 0.05] if scenario == 'referral_hospital'
280
+ else ([0.10, 0.35, 0.15, 0.15, 0.25] if scenario == 'district_hospital'
281
+ else [0.02, 0.10, 0.05, 0.08, 0.75]))
282
+ rec['power_outage_hours_last_week'] = max(0, int(rng.exponential(
283
+ 5 if scenario == 'referral_hospital' else
284
+ (15 if scenario == 'district_hospital' else 60))))
285
+
286
+ records.append(rec)
287
+
288
+ df = pd.DataFrame(records)
289
+
290
+ print(f"\n{'='*65}")
291
+ print(f"Medical Oxygen Supply — {scenario} (n={n}, seed={seed})")
292
+ print(f"{'='*65}")
293
+ print(f"\n Oxygen available today: {df['oxygen_available_today'].mean()*100:.1f}%")
294
+ print(f" Sufficient for demand: {df['oxygen_sufficient_for_demand'].mean()*100:.1f}%")
295
+ print(f" Pulse oximeter functional: {df['pulse_oximeter_functional'].mean()*100:.1f}%")
296
+ print(f" Patients needing O2 (mean): {df['patients_needing_oxygen'].mean():.1f}")
297
+ print(f" Patients received O2 (mean): {df['patients_received_oxygen'].mean():.1f}")
298
+ print(f" Deaths hypoxemia (mean): {df['deaths_hypoxemia_related'].mean():.2f}")
299
+
300
+ return df
301
+
302
+
303
+ if __name__ == '__main__':
304
+ parser = argparse.ArgumentParser(
305
+ description='Generate medical oxygen supply dataset')
306
+ parser.add_argument('--scenario', type=str, default='district_hospital',
307
+ choices=list(SCENARIOS.keys()))
308
+ parser.add_argument('--n', type=int, default=10000)
309
+ parser.add_argument('--seed', type=int, default=42)
310
+ parser.add_argument('--output', type=str, default=None)
311
+ parser.add_argument('--all-scenarios', action='store_true')
312
+ args = parser.parse_args()
313
+
314
+ os.makedirs('data', exist_ok=True)
315
+
316
+ if args.all_scenarios:
317
+ for sc_name in SCENARIOS:
318
+ df = generate_dataset(n=args.n, seed=args.seed, scenario=sc_name)
319
+ out = os.path.join('data', f'oxygen_{sc_name}.csv')
320
+ df.to_csv(out, index=False)
321
+ print(f" -> Saved to {out}\n")
322
+ else:
323
+ df = generate_dataset(n=args.n, seed=args.seed, scenario=args.scenario)
324
+ out = args.output or os.path.join('data', f'oxygen_{args.scenario}.csv')
325
+ df.to_csv(out, index=False)
326
+ print(f" -> Saved to {out}")
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,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Validation & Diagnostic Visualization for Medical Oxygen Supply Dataset."""
3
+
4
+ import pandas as pd
5
+ import numpy as np
6
+ import matplotlib.pyplot as plt
7
+ import os
8
+
9
+ SCENARIOS = ['referral_hospital', 'district_hospital', 'rural_health_centre']
10
+
11
+
12
+ def load_scenarios(data_dir='data'):
13
+ dfs = {}
14
+ for sc in SCENARIOS:
15
+ path = os.path.join(data_dir, f'oxygen_{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
+ 'Medical Oxygen Supply — Validation Report\n'
25
+ '(Referral Hospital → District Hospital → Rural Health Centre)',
26
+ fontsize=15, fontweight='bold', y=0.99)
27
+ colors = ['#2ecc71', '#f39c12', '#e74c3c']
28
+ x = np.arange(len(SCENARIOS))
29
+ labels = ['Referral Hosp', 'District Hosp', 'Rural HC']
30
+
31
+ # Panel 1: Oxygen available today
32
+ ax = axes[0, 0]
33
+ avail = [dfs[sc]['oxygen_available_today'].mean()*100 for sc in SCENARIOS if sc in dfs]
34
+ ax.bar(x, avail, color=colors, alpha=0.8)
35
+ ax.set_xticks(x)
36
+ ax.set_xticklabels(labels, fontsize=9)
37
+ for i, v in enumerate(avail):
38
+ ax.text(i, v + 1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
39
+ ax.set_ylabel('Availability (%)')
40
+ ax.set_title('Oxygen Available on Day of Assessment')
41
+ ax.set_ylim(0, 100)
42
+
43
+ # Panel 2: Oxygen source distribution (district)
44
+ ax = axes[0, 1]
45
+ df = dfs.get('district_hospital', list(dfs.values())[0])
46
+ src = df['primary_oxygen_source'].value_counts()
47
+ ax.barh(range(len(src)), src.values, color='#3498db', alpha=0.7)
48
+ ax.set_yticks(range(len(src)))
49
+ ax.set_yticklabels([s.replace('_', ' ').title() for s in src.index], fontsize=8)
50
+ ax.set_xlabel('Count')
51
+ ax.set_title('Primary Oxygen Source (District Hospital)')
52
+
53
+ # Panel 3: Pulse oximetry functional
54
+ ax = axes[1, 0]
55
+ pox = [dfs[sc]['pulse_oximeter_functional'].mean()*100 for sc in SCENARIOS if sc in dfs]
56
+ ax.bar(x, pox, color=colors, alpha=0.8)
57
+ ax.set_xticks(x)
58
+ ax.set_xticklabels(labels, fontsize=9)
59
+ for i, v in enumerate(pox):
60
+ ax.text(i, v + 1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
61
+ ax.set_ylabel('Rate (%)')
62
+ ax.set_title('Functional Pulse Oximetry')
63
+
64
+ # Panel 4: Patients needing vs receiving oxygen
65
+ ax = axes[1, 1]
66
+ w = 0.3
67
+ need = [dfs[sc]['patients_needing_oxygen'].mean() for sc in SCENARIOS if sc in dfs]
68
+ recv = [dfs[sc]['patients_received_oxygen'].mean() for sc in SCENARIOS if sc in dfs]
69
+ ax.bar(x - w/2, need, w, label='Needing O₂', color='#e74c3c', alpha=0.8)
70
+ ax.bar(x + w/2, recv, w, label='Received O₂', color='#2ecc71', alpha=0.8)
71
+ ax.set_xticks(x)
72
+ ax.set_xticklabels(labels, fontsize=9)
73
+ ax.set_ylabel('Mean Patients/Month')
74
+ ax.set_title('Oxygen Need vs Delivery Gap')
75
+ ax.legend(fontsize=8)
76
+
77
+ # Panel 5: Hypoxemia deaths
78
+ ax = axes[2, 0]
79
+ deaths = [dfs[sc]['deaths_hypoxemia_related'].mean() for sc in SCENARIOS if sc in dfs]
80
+ ax.bar(x, deaths, color=colors, alpha=0.8)
81
+ ax.set_xticks(x)
82
+ ax.set_xticklabels(labels, fontsize=9)
83
+ for i, v in enumerate(deaths):
84
+ ax.text(i, v + 0.1, f'{v:.1f}', ha='center', fontsize=10, fontweight='bold')
85
+ ax.set_ylabel('Mean Deaths/Month')
86
+ ax.set_title('Hypoxemia-Related Deaths (per observation)')
87
+
88
+ # Panel 6: Shortage causes (district)
89
+ ax = axes[2, 1]
90
+ short_df = df[df['shortage_cause'] != 'not_applicable']
91
+ if len(short_df) > 0:
92
+ causes = short_df['shortage_cause'].value_counts().head(8)
93
+ ax.barh(range(len(causes)), causes.values, color='#e74c3c', alpha=0.7)
94
+ ax.set_yticks(range(len(causes)))
95
+ ax.set_yticklabels([s.replace('_', ' ').title() for s in causes.index], fontsize=7)
96
+ ax.set_xlabel('Count')
97
+ ax.set_title('Top Oxygen Shortage Causes (District)')
98
+
99
+ # Panel 7: Concentrator functional rate
100
+ ax = axes[3, 0]
101
+ conc_func = []
102
+ for sc in SCENARIOS:
103
+ if sc in dfs:
104
+ has_conc = dfs[sc][dfs[sc]['concentrator_count'] > 0]
105
+ if len(has_conc) > 0:
106
+ rate = (has_conc['concentrator_functional'] / has_conc['concentrator_count']).mean() * 100
107
+ else:
108
+ rate = 0
109
+ conc_func.append(rate)
110
+ ax.bar(x, conc_func, color=colors, alpha=0.8)
111
+ ax.set_xticks(x)
112
+ ax.set_xticklabels(labels, fontsize=9)
113
+ for i, v in enumerate(conc_func):
114
+ ax.text(i, v + 1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
115
+ ax.set_ylabel('Functional Rate (%)')
116
+ ax.set_title('Concentrator Functionality (among facilities with concentrators)')
117
+
118
+ # Panel 8: Distance to refill & transport
119
+ ax = axes[3, 1]
120
+ dist = [dfs[sc]['distance_to_refill_km'].mean() for sc in SCENARIOS if sc in dfs]
121
+ ax.bar(x, dist, color=colors, alpha=0.8)
122
+ ax.set_xticks(x)
123
+ ax.set_xticklabels(labels, fontsize=9)
124
+ for i, v in enumerate(dist):
125
+ ax.text(i, v + 2, f'{v:.0f}km', ha='center', fontsize=10, fontweight='bold')
126
+ ax.set_ylabel('Distance (km)')
127
+ ax.set_title('Mean Distance to Cylinder Refill Point')
128
+
129
+ plt.tight_layout(rect=[0, 0, 1, 0.97])
130
+ plt.savefig(output, dpi=150, bbox_inches='tight')
131
+ print(f'Saved validation report to {output}')
132
+ plt.close()
133
+
134
+
135
+ if __name__ == '__main__':
136
+ dfs = load_scenarios()
137
+ if dfs:
138
+ make_report(dfs)
validation_report.png ADDED

Git LFS Details

  • SHA256: dacafb2774639f7af867db908ad7dbe23c98133aed18afb0b06be6144d5b0f64
  • Pointer size: 131 Bytes
  • Size of remote file: 296 kB