This repository contains the backend for an Ambulance Dispatch Optimization System built with Python Flask and MySQL. The service manages ambulances, hospitals, emergency requests, dispatch records, and response logs.
- REST API backend using Flask
- MySQL database integration with
mysql-connector-python - Automatic database and table creation on startup
- Simple nearest-available ambulance dispatch logic
- JSON responses with error handling
- Backend: Flask (Python)
- Database: MySQL
- Connector: mysql-connector-python
GET /ambulances- return all ambulancesPOST /ambulance- add a new ambulanceGET /hospitals- return all hospitalsPOST /request- create an emergency requestPOST /dispatch- assign nearest available ambulance to a requestGET /dispatch/history- return all dispatch records with joins
python -m venv .venv
.venv\Scripts\Activatecd backend
pip install -r requirements.txtBy default, the app uses SQLite so it can run without a MySQL server. This is the fastest way to start the backend locally.
If you want to use MySQL later, set DB_TYPE=mysql and configure credentials.
Default SQLite file:
SQLITE_DB_FILE=ambulance_system.db
Optional MySQL settings:
DB_TYPE=mysqlDB_HOST=127.0.0.1DB_USER=rootDB_PASSWORD=(empty)DB_NAME=ambulance_system
Example for MySQL:
set DB_TYPE=mysql
set DB_HOST=127.0.0.1
set DB_USER=root
set DB_PASSWORD=your_password
set DB_NAME=ambulance_systempython app.pyThe backend will run on http://127.0.0.1:5000 in debug mode.
- The app creates the
ambulance_systemdatabase and required tables automatically when first run. - Dispatch selection uses a simple first-available ambulance strategy.
Start the server locally and test the routes with Postman, curl, or any REST client.
This repository is distributed under the terms of the existing license.