This is a masters thesis repo for drug redistribution to reduce expiry in Nigeria.
# MedShare — Inter-Pharmacy Drug Redistribution Framework
An integrated decision-support framework that helps community and hospital
pharmacies redistribute surplus, near-expiry medicines to other pharmacies that
need them — before the stock expires and the value is lost.
The framework combines three models behind a single platform:
1. **Expiry-risk classifier** — predicts which stock batches are likely to expire unsold.
2. **Demand forecaster** — estimates near-term demand per pharmacy and drug, with uncertainty.
3. **Redistribution matcher** — pairs at-risk surplus with pharmacies that can sell it in time.
It is delivered as a PostgreSQL database, a FastAPI backend, and a Streamlit
pharmacist application, evaluated by Monte Carlo simulation. This repository is the
reference implementation accompanying the MSc thesis.
> **Scope.** The system is evaluated on a **calibrated synthetic network** anchored to
> a 39-pharmacy survey. Reported impact figures are **simulation-based projections**,
> not measured field outcomes. See Data & honesty.
---
## Architecture
```
Survey (39 pharmacies, real) +------------------------------+
data/*.xlsx --> generator --> | PostgreSQL database |
(hybrid 150- | stock . sales . scores . |
pharmacy network) | forecasts . recommendations . |
| transfers . requests . waste |
+--------------+-----------------+
+------------------------------+ |
| Models (nightly pipeline) | score -> forecast -> match -> notify) |
| `python -m src.evaluate --runs 200 --curve` | Monte Carlo evaluation: waste-reduction curve, break-even, sensitivity |
| `python chapter4_stats.py` | Print the operational snapshot for the results chapter |
| `streamlit run app/streamlit_app.py` | Launch the pharmacist app |
| `uvicorn api.main:app --reload --port 8000` | Launch the FastAPI backend (docs at /docs) |
The Streamlit app lets a pharmacy **log newly received stock**, view its at-risk
batches, offer s …