A modern, secure and scalable Hospital Appointment Management REST API built with Django REST Framework.
Installation • API • Features • Roadmap • Author
Hospital Appointment Management API is a production-ready backend system built with Django REST Framework.
The project provides a complete RESTful API for managing hospital appointments, doctors, patients, billing, authentication, and dashboard analytics.
It follows secure authentication using JWT and role-based authorization for Admin, Doctor, and Patient.
The architecture is modular, clean, scalable, and follows REST API best practices.
✅ JWT Authentication
✅ Role Based Access Control
✅ Doctor Management
✅ Patient Management
✅ Appointment Booking
✅ Billing System
✅ Dashboard Analytics
✅ Search
✅ Filtering
✅ Ordering
✅ Pagination
✅ Profile Management
✅ Password Reset
✅ Custom Middleware
✅ Request Validation
✅ RESTful API Design
| Role | Permissions |
|---|---|
| 👑 Admin | Full System Access |
| 👨⚕️ Doctor | View Assigned Appointments |
| 🧑 Patient | Manage Own Profile & Appointments |
- JWT Login
- Patient Registration
- Refresh Token
- Forgot Password
- Reset Password
- View Profile
- Update Profile
- Partial Update
- Secure Access
- Create Doctor
- Update Doctor
- Delete Doctor
- Department
- Specialization
- Visiting Fee
- Book Appointment
- Appointment Status
- Update Appointment
- Cancel Appointment
- Doctor Assignment
- Consultation Fee
- Discount
- Total Bill
- Appointment Billing
- Total Patients
- Total Doctors
- Total Appointments
- Pending Appointments
- Completed Appointments
- Filtering
- Searching
- Ordering
- Pagination
- Custom Middleware
- Validation
- Python 3
- Django
- Django REST Framework
- JWT Authentication
- SQLite (Development)
PostgreSQL Ready
- JWT Token Authentication
- REST API
- Postman
- VS Code
- Git
- GitHub
- React.js
- Redux Toolkit
- Tailwind CSS
- Axios
- PostgreSQL
- Docker
- Nginx
- Redis
- Celery
hospital-appointment-management-api/
│
├── Accounts/
│
├── AppointmentManagement/
│
├── assets/
│
├── BillManagement/
│
├── DoctorManagement/
│
├── Dashboard/
│
├── core/
│
├── HospitalAppointment/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── asgi.py
│ └── wsgi.py
│
├── .env
├── .env.example
├── .gitignore
├── db.sqlite3
├── manage.py
├── requirements.txt
│
└── README.md
- About
- Features
- User Roles
- Tech Stack
- Project Structure
- Screenshots
- Installation
- Environment Variables
- Running the Project
- API Documentation
- Authentication API
- Profile API
- Doctor API
- Appointment API
- Billing API
- Dashboard API
- Filtering
- Searching
- Ordering
- Pagination
- Middleware
- Validation
- Future Roadmap
- Contributing
- Author
- Social Links
Follow the steps below to set up the project locally.
git clone https://github.com/iamdeveloperrayhan/hospital-appointment-management-api.gitMove into the project directory.
cd hospital-appointment-management-apipython -m venv venvActivate the virtual environment
venv\Scripts\activatepython3 -m venv venvActivate
source venv/bin/activatepip install -r requirements.txtVerify installation
pip freezeCreate a .env file in the project root.
Example:
SECRET_KEY=your_secret_key
DEBUG=True
ALLOWED_HOSTS=127.0.0.1,localhost
DATABASE_NAME=db.sqlite3
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=your_email@gmail.com
EMAIL_HOST_PASSWORD=your_password
EMAIL_USE_TLS=TrueNote: Never commit your
.envfile to GitHub.
Create migrations
python manage.py makemigrationsApply migrations
python manage.py migratepython manage.py createsuperuserExample
Username: admin
Email: admin@example.com
Password: ********
python manage.py runserverServer URL
http://127.0.0.1:8000/
http://127.0.0.1:8000/api/
Production
https://your-domain.com/api/
You can test the API using
- Postman
- Insomnia
- Thunder Client
- Hoppscotch
Register
│
▼
Login
│
▼
Access Token + Refresh Token
│
▼
Authenticated Requests
│
▼
Refresh Token
│
▼
New Access Token
All protected endpoints require the following header.
Authorization: Bearer <access_token>Example
GET /api/profile/
Authorization: Bearer eyJhbGciOi...| Method | Endpoint | Description |
|---|---|---|
| POST | /api/register/ |
Register a new patient |
| POST | /api/login/ |
Login user |
| POST | /api/token/refresh/ |
Refresh access token |
| POST | /api/forgot-password/ |
Forgot password |
| POST | /api/reset-password/ |
Reset password |
POST /api/register/{
"full_name": "John Doe",
"email": "john@example.com",
"phone": "01700000000",
"password": "StrongPassword123",
"address": "Dhaka"
}{
"full_name": "John Doe",
"email": "john@example.com",
"phone": "01700000000",
"address": "Dhaka"
}POST /api/login/{
"email": "john@example.com",
"password": "password123"
}{
"access": "jwt_access_token",
"refresh": "jwt_refresh_token"
}POST /api/token/refresh/{
"refresh": "your_refresh_token"
}{
"access": "new_access_token"
}POST /api/forgot-password/{
"email": "john@example.com"
}{
"message": "Password reset link sent to your email."
}POST /api/reset-password/{
"token": "password_reset_token", // That was send in your email, Frist you need to choice Forget Password Option then we will send a token in your email you should to use this token here.
"password": "NewStrongPassword123?"
}{
"message": "Password reset successful."
}- JWT Authentication is used.
- Access Token is required for all protected APIs.
- Refresh Token generates a new Access Token.
- Password reset is available.
- Patient registration is public.
- All passwords are securely hashed.
- Unauthorized requests return 401 Unauthorized.
Every authenticated user has a personal profile.
Each profile contains:
- Full Name
- Email Address
- Phone Number
- Address
Only the logged-in user can access and update their own profile.
| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/profile/ |
View Profile | Authenticated User |
| PUT | /api/profile/ |
Update Full Profile | Owner |
| PATCH | /api/profile/ |
Partial Update | Owner |
GET /api/profile/Authorization: Bearer <access_token>{
"id": 1,
"full_name": "John Doe",
"email": "john@example.com",
"phone": "01700000000",
"address": "Dhaka"
}PUT /api/profile/{
"full_name": "John Doe",
"email": "john@example.com",
"phone": "01711111111",
"address": "Chittagong"
}{
"full_name": "John Doe",
"email": "john@example.com",
"phone": "01711111111",
"address": "Chittagong"
}PATCH /api/profile/{
"phone": "01800000000"
}{
"phone": "01800000000"
}- Authentication Required
- Email must be unique
- Phone number must be unique
- User can only update own profile
- Admin cannot edit another user's profile through this endpoint
The Doctor module manages all doctors available in the hospital.
Only administrators can create, update, or delete doctors.
Patients and Doctors can view the doctor list.
| Field | Type |
|---|---|
| Name | String |
| Department | String |
| Specialization | String |
| Visiting Fee | Decimal |
| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/doctors/ |
View All Doctors | Public |
| POST | /api/doctors/ |
Create Doctor | Admin |
| GET | /api/doctors/{id}/ |
View Doctor | Public |
| PUT | /api/doctors/{id}/ |
Update Doctor | Admin |
| PATCH | /api/doctors/{id}/ |
Partial Update | Admin |
| DELETE | /api/doctors/{id}/ |
Delete Doctor | Admin |
GET /api/doctors/[
{
"id": 1,
"full_name": "Dr. Rahman",
"department": "Cardiology",
"specialization": "Heart Specialist",
"visiting_fee": 1000
},
{
"id": 2,
"full_name": "Dr. Hasan",
"department": "Neurology",
"specialization": "Brain Specialist",
"visiting_fee": 1500
}
]GET /api/doctors/1/{
"id": 1,
"full_name": "Dr. Rahman",
"department": "Cardiology",
"specialization": "Heart Specialist",
"visiting_fee": 1000
}POST /api/doctors/Authorization: Bearer <admin_access_token>{
"full_name": "Doctor Name",
"email": "doctor_email",
"phone_number": "Doctor_phone",
"password": "StrongPassword123",
"department": "Doctor Department",
"specialization": "Doctor Specialization",
"visiting_fee": "Visiting Fee"
}{
"full_name": "Doctor Name",
"email": "doctor_email",
"phone_number": "Doctor_phone",
"department": "Doctor Department",
"specialization": "Doctor Specialization",
"visiting_fee": "Visiting Fee"
}PUT /api/doctors/1/{
"full_name": "Dr. Rahman",
"department": "Cardiology",
"specialization": "Senior Heart Specialist",
"visiting_fee": 1200
}{
"full_name": "Dr. Rahman",
"department": "Cardiology",
"specialization": "Senior Heart Specialist",
"visiting_fee": 1200
}PATCH /api/doctors/1/{
"visiting_fee": 1500
}{
"visiting_fee": 1500
}DELETE /api/doctors/1/{[]}| User | Permission |
|---|---|
| Admin | Full Access |
| Doctor | Read Only |
| Patient | Read Only |
- Doctor name is required
- Department is required
- Specialization is required
- Visiting fee cannot be negative
- Visiting fee must be numeric
| Code | Meaning |
|---|---|
| 200 | Success |
| 201 | Created |
| 204 | Deleted Successfully |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Permission Denied |
| 404 | Not Found |
| 500 | Internal Server Error |
Admin Login
│
▼
Create Doctor
│
▼
Doctor Appears in Doctor List
│
▼
Patient Views Doctor
│
▼
Patient Books Appointment
The Appointment module allows patients to book appointments with doctors while enabling doctors and administrators to manage appointment workflows.
| Field | Description |
|---|---|
| Patient | Appointment Owner |
| Doctor | Assigned Doctor |
| Appointment Date | Date of Appointment |
| Appointment Time | Time Slot |
| Status | Pending / Confirmed / Completed / Cancelled |
| Status | Description |
|---|---|
| 🟡 Pending | Waiting for confirmation |
| 🔵 Confirmed | Approved by doctor/admin |
| 🟢 Completed | Appointment completed |
| 🔴 Cancelled | Appointment cancelled |
| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/appointments/ |
View Appointments | Authenticated |
| POST | /api/appointments/ |
Book Appointment | Patient |
| GET | /api/appointments/{id}/ |
Appointment Details | Owner/Admin |
| PUT | /api/appointments/{id}/ |
Update Appointment | Owner/Admin |
| PATCH | /api/appointments/{id}/ |
Partial Update | Owner/Admin |
| DELETE | /api/appointments/{id}/ |
Cancel Appointment | Owner/Admin |
POST /api/appointments/Authorization: Bearer <access_token>{
"doctor": 2,
"appointment_date": "2025-08-20",
"appointment_time": "10:30:00"
}{
"doctor": 2,
"appointment_date": "2025-08-20",
"appointment_time": "10:30:00"
}GET /api/appointments/[
{
"id": 1,
"patient": "John Doe",
"doctor": "Dr. Rahman",
"appointment_date": "2025-08-20",
"appointment_time": "10:30",
"status": "Pending"
}
]PUT /api/appointments/1/{
"doctor": 3,
"appointment_date": "2025-08-25",
"appointment_time": "11:00"
}PATCH /api/appointments/1/{
"status":"Completed"
}DELETE /api/appointments/1/Response
{[]}| User | Permission |
|---|---|
| Admin | Manage All Appointments |
| Doctor | View Assigned Appointments |
| Patient | Manage Own Appointments |
- Appointment date cannot be in the past
- Doctor is required
- Time is required
- Patient cannot edit another patient's appointment
- Appointment status must be valid
Bills are automatically created when an appointment is marked as Completed.
| Field | Description |
|---|---|
| Patient | Bill Owner |
| Doctor | Assigned Doctor |
| Appointment | Appointment Reference |
| Consultation Fee | Doctor Fee |
| Discount | Discount Amount |
| Total Amount | Final Bill |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/bills/ |
View Bills |
| POST | /api/bills/ |
Create Bill |
| GET | /api/bills/{id}/ |
Bill Details |
| PUT | /api/bills/{id}/ |
Update Bill |
| PATCH | /api/bills/{id}/ |
Partial Update |
| DELETE | /api/bills/{id}/ |
Delete Bill |
GET /api/bills/[
{
"id":1,
"patient":"John Doe",
"doctor":"Dr. Rahman",
"consultation_fee":1000,
"discount":100,
"total_amount":900
}
]POST /api/bills/{
"appointment":1,
"consultation_fee":1000,
"discount":100
}- Discount cannot exceed consultation fee
- Consultation fee cannot be negative
- Appointment must exist
- Only Admin can Create/Delete/Update a Bill
Dashboard provides an overview of the hospital system.
GET /api/dashboard/{
"total_patients":120,
"total_doctors":18,
"total_appointments":540,
"pending_appointments":34,
"completed_appointments":472
}Filtering allows retrieving specific records using query parameters.
GET /api/doctors/?department=CardiologyGET /api/appointments/?status=CompletedGET /api/appointments/?doctor=2Search doctors and appointments.
GET /api/doctors/?search=RahmanGET /api/appointments/?search=JohnSearch supports
- Patient Name
- Doctor Name
Sort data using query parameters.
Ascending
GET /api/doctors/?ordering=visiting_feeDescending
GET /api/doctors/?ordering=-visiting_feeAscending
GET /api/appointments/?ordering=appointment_dateDescending
GET /api/appointments/?ordering=-appointment_dateThe API returns 10 records per page.
Doctors
GET /api/doctors/?page=2Appointments
GET /api/appointments/?page=3Example Response
{
"count":120,
"next":"http://127.0.0.1:8000/api/doctors/?page=2",
"previous":null,
"results":[]
}| Feature | Admin | Doctor | Patient |
|---|---|---|---|
| View Doctors | ✅ | ✅ | ✅ |
| Create Doctor | ✅ | ❌ | ❌ |
| Update Doctor | ✅ | ❌ | ❌ |
| Delete Doctor | ✅ | ❌ | ❌ |
| Book Appointment | ✅ | ✅ | ✅ |
| View Own Appointment | ✅ | ✅ | ✅ |
| Manage Bills | ✅ | ❌ | ❌ |
| Dashboard | ✅ | ✅ | ✅ |
| Profile Update | ✅ (Own) | ✅ (Own) | ✅ (Own) |
Patient
│
▼
Book Appointment
│
▼
Pending
│
▼
Confirmed
│
▼
Completed
│
▼
Bill Generated
A custom middleware has been implemented to improve request monitoring and debugging.
- Logs every incoming request
- Prints HTTP request method
- Displays requested URL
- Tracks request execution flow
Example Terminal Output
[INFO] GET /api/doctors/
[INFO] POST /api/login/
[INFO] PATCH /api/profile/
You can easily replace this middleware with request execution time logging or custom logging in future versions.
The project includes several built-in validations to ensure data consistency.
| Validation | Description |
|---|---|
| ✅ Unique Email | Every user must have a unique email |
| ✅ Unique Phone | Phone number must be unique |
| ✅ Visiting Fee | Cannot be negative |
| ✅ Appointment Date | Cannot be in the past |
| ✅ Discount | Cannot exceed consultation fee |
| ✅ Required Fields | Mandatory fields are validated |
| ✅ JWT Authentication | Protected routes require authentication |
Create a .env file in the project root.
SECRET_KEY=your_secret_key
DEBUG=True
ALLOWED_HOSTS=127.0.0.1,localhost
DATABASE_NAME=db.sqlite3
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=your_email@gmail.com
EMAIL_HOST_PASSWORD=your_app_password
EMAIL_USE_TLS=TrueThis project will continue to grow with more advanced features.
- ✅ React Frontend
- ✅ Patient Dashboard
- ✅ Doctor Dashboard
- ✅ Admin Dashboard
- ✅ Appointment Calendar
- ✅ Online Payments
- ✅ Email Notifications
- ✅ SMS Notifications
- ✅ Prescription Management
- ✅ Medical History
- ✅ Doctor Availability Schedule
- ✅ Patient Reports
- ✅ File Uploads
- ✅ Docker Support
- ✅ PostgreSQL
- ✅ Redis
- ✅ Celery
- ✅ CI/CD Pipeline
- ✅ Deployment Guide
- ✅ API Versioning
- ✅ Unit Testing
- ✅ Swagger / OpenAPI Documentation
Contributions are always welcome!
If you'd like to contribute:
- Fork the repository
- Create a new branch
git checkout -b feature/your-feature- Commit your changes
git commit -m "Add your feature"- Push to GitHub
git push origin feature/your-feature- Open a Pull Request
If you find a bug, please create an issue with:
- Bug description
- Steps to reproduce
- Expected behavior
- Screenshots (if applicable)
New feature ideas are always appreciated.
Please open an Issue and describe:
- Feature overview
- Why it is useful
- Possible implementation
If you found this project useful, please consider giving it a ⭐ on GitHub.
Your support helps improve the project and motivates future development.
Replace the placeholder links above with your own profile URLs.
You can add the following GitHub cards after creating the repository.
Currently, this project does not have a license.
If you plan to make it open source, consider adding one of the following:
- MIT License
- Apache License 2.0
- GNU GPL v3
Special thanks to the amazing open-source community and the Django ecosystem.
Technologies used in this project include:
- Python
- Django
- Django REST Framework
- JWT Authentication
- SQLite
- Git & GitHub
- Postman



