A Flask-based RESTful API for managing a hospital database, including patient profiles, disease records (Heart Disease, Lung Infection, Hypertension), and billing information. Built with Flask-SQLAlchemy for ORM and Flask-RESTful for API endpoints, with an OpenAPI 3.0 specification for easy testing.
- Patient Management: CRUD operations for user records (name, age, email, etc.).
- Disease Tracking: Manage records for Heart Disease, Lung Infection, and Hypertension with specific metrics.
- Billing System: Track patient admissions, discharges, and billing amounts.
- Relationships: One-to-many links between users and disease/billing records.
- API Documentation: OpenAPI 3.0 YAML (
openapi.yaml
) for Postman/Swagger UI. - Testing: Supports curl, Postman, and Swagger UI.
- Backend: Flask, Flask-SQLAlchemy, Flask-RESTful
- Database: SQLite (configurable for PostgreSQL/MySQL)
- Documentation: OpenAPI 3.0 (YAML)
- Environment: Python 3.8+
- Python 3.8+
- Git
- Postman (for testing)
-
Clone the Repository:
git clone https://github.com/yourusername/Hospital-Management-API.git cd Hospital-Management-API
-
Create Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install flask flask-sqlalchemy flask-restful
-
Run the Application:
python app.py
- Server runs at
http://127.0.0.1:5000
. - SQLite database (
database.db
) is auto-created.
- Server runs at
-
Import API Specification:
- In Postman, click
Import
>File
> Selectopenapi.yaml
. - Set environment variable
baseUrl
tohttp://127.0.0.1:5000
. - Test endpoints (e.g.,
POST /api/users
).
- In Postman, click
-
Sample Request (POST /api/users):
{ "name": "Prajwal", "age": 30, "number": "1258963", "gmail": "prajwal@gmail.com", "gender": "Male", "disease": "Heart Disease" }
-
Curl Commands:
- See
api_curl_commands.md
for examples.
- See
Resource | Method | Endpoint | Description |
---|---|---|---|
Users | GET | /api/users |
List all users |
POST | /api/users |
Create user | |
GET | /api/users/{id} |
Get user by ID | |
PATCH | /api/users/{id} |
Update user | |
DELETE | /api/users/{id} |
Delete user | |
Heart Diseases | GET | /api/heart_diseases |
List records |
POST | /api/heart_diseases |
Create record | |
GET | /api/heart_diseases/{id} |
Get record | |
PATCH | /api/heart_diseases/{id} |
Update record | |
DELETE | /api/heart_diseases/{id} |
Delete record | |
Lung Infections | GET | /api/lung_infections |
List records |
POST | /api/lung_infections |
Create record | |
GET | /api/lung_infections/{id} |
Get record | |
PATCH | /api/lung_infections/{id} |
Update record | |
DELETE | /api/lung_infections/{id} |
Delete record | |
Hypertension | GET | /api/hypertensions |
List records |
POST | /api/hypertensions |
Create record | |
GET | /api/hypertensions/{id} |
Get record | |
PATCH | /api/hypertensions/{id} |
Update record | |
DELETE | /api/hypertensions/{id} |
Delete record | |
Billing | GET | /api/billings |
List records |
POST | /api/billings |
Create record | |
GET | /api/billings/{id} |
Get record | |
PATCH | /api/billings/{id} |
Update record | |
DELETE | /api/billings/{id} |
Delete record |
- Users: Stores patient data (id, name, age, number, gmail, gender, disease, current_date).
- HeartDisease: Tracks heart disease records (user_id, test_date, result).
- LungInfection: Tracks lung infection records (user_id, test_date, result).
- Hypertension: Tracks blood pressure records (user_id, test_date, systolic, diastolic).
- Billing: Manages billing (user_id, joined_date, disease, discharge_date, amount).
Generate the ERD using DBDiagram.io with the provided DBML in api_curl_commands.md
.
Hospital-Management-API/
├── app.py # API routes and resources
├── database_schema.py # Database models and setup
├── openapi.yaml # OpenAPI 3.0 specification
├── api_curl_commands.md # Curl command examples
├── README.md # Project documentation
└── database.db # SQLite database (auto-generated)
- Fork the repo.
- Create a feature branch (
git checkout -b feature/YourFeature
). - Commit changes (
git commit -m 'Add YourFeature'
). - Push to the branch (
git push origin feature/YourFeature
). - Open a Pull Request.
Free to use...!
- Author: Prajwal
- Email: prajwalint1027@gmail.com