End-to-end pipeline for forecasting medication stock needs at healthcare facilities using time-series AI.
Initially focused on hypertension; easily extendable to diabetes and other therapies.
medication-stock-forecast/
├── data/
│ └── metabase_report.csv # Raw Metabase export (git-ignored)
├── scripts/
│ ├── prepare_prophet_input.py # Transforms raw CSV → prophet_input.csv
│ └── run_forecasts.py # Fits Prophet and writes forecast CSVs
├── outputs/
│ ├── prophet_input.csv # Model-ready data (git-ignored)
│ ├── forecast_results_12mo.csv # Raw forecasts (git-ignored)
│ └── forecast_results_pivot.csv # Pivoted forecasts (git-ignored)
├── .gitignore
├── requirements.txt # Python dependencies
└── README.md # Project overview and instructions
-
Clone the repository
git clone <repo-url> cd medication-stock-forecast
-
Create and activate a virtual environment
python3 -m venv .venv source .venv/bin/activate -
Install dependencies
pip install --upgrade pip pip install -r requirements.txt
-
Export data from Metabase
- Open this question in Metabase:
Monthly Hypertension Patient-Days by Drug Class for top 5 uhc facilities - Click Export → CSV → save as
data/metabase_report.csv
- Open this question in Metabase:
-
Prepare data for Prophet
python3 scripts/prepare_prophet_input.py
- Reads
data/metabase_report.csv - Writes
outputs/prophet_input.csv.
- Reads
-
Run forecasts
python3 scripts/run_forecasts.py
- Reads
outputs/prophet_input.csv - Writes
outputs/forecast_results_12mo.csv(long) - Writes
outputs/forecast_results_pivot.csv(wide)
- Reads
-
Inspect outputs
outputs/forecast_results_pivot.csvhas one row per month & facility, columns for each drug class forecast.
- To support diabetes or other conditions, update the Metabase query and adjust the
class_colspattern inprepare_prophet_input.py.