A full-stack Hospital Management System with role-based access control, built with FastAPI, SQLite/PostgreSQL, React, and Tailwind CSS.
- ✅ Role-based authentication (admin, doctor, nurse, pharmacist, receptionist, patient)
- ✅ Patient registration & management with user account linking
- ✅ Appointment scheduling — staff book for patients, patients self-book
- ✅ Doctor management (admin/receptionist can add doctors)
- ✅ Pharmacy inventory with prescription dispensing
- ✅ Billing & invoicing with Stripe payment integration
- ✅ Reports dashboard (summary, appointments, pharmacy stock)
| Feature | Patient | Doctor | Nurse | Pharmacist | Receptionist | Admin |
|---|---|---|---|---|---|---|
| View own appointments | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Book own appointment | ✅ | — | — | — | — | — |
| Cancel own appointment | ✅ | — | — | — | — | — |
| Book appointment for others | — | ✅ | — | — | ✅ | ✅ |
| Manage appointment status | — | ✅ | — | — | ✅ | ✅ |
| View patients | — | ✅ | ✅ | — | ✅ | ✅ |
| Add/edit patients | — | ✅ | ✅ | — | ✅ | ✅ |
| Add doctors | — | — | — | — | ✅ | ✅ |
| View pharmacy | — | ✅ | — | ✅ | — | ✅ |
| Add/edit drugs | — | — | — | ✅ | — | ✅ |
| Create prescriptions | — | ✅ | — | — | — | ✅ |
| Dispense prescriptions | — | — | — | ✅ | — | ✅ |
| View own invoices | ✅ | — | — | — | — | — |
| Pay invoices | ✅ | — | — | — | ✅ | ✅ |
| Create invoices | — | — | — | — | ✅ | ✅ |
| View reports | — | ✅ | — | ✅ | ✅ | ✅ |
| Full dashboard stats | — | — | — | — | — | ✅ |
├── backend/
│ ├── app/
│ │ ├── core/ # config, database, security
│ │ ├── models/ # SQLAlchemy models
│ │ ├── routers/ # API endpoints (auth, patients, pharmacy, billing, reports)
│ │ ├── schemas/ # Pydantic schemas
│ │ └── main.py # FastAPI app entry point
│ ├── requirements.txt
│ └── .env
├── frontend/
│ └── src/
│ ├── pages/ # Dashboard, Patients, Appointments, Pharmacy, Billing, Reports
│ ├── components/ # Layout
│ ├── context/ # AuthContext
│ └── api/ # Axios client
└── docker-compose.yml
- Python 3.8+
- Node.js 16+
- npm
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env # edit if needed, default uses SQLite
uvicorn app.main:app --reloadBackend runs on http://localhost:8000
- Swagger API docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Open a new terminal:
cd frontend
npm install
npm run devFrontend runs on http://localhost:3000
DATABASE_URL=sqlite:///./hms.db
SECRET_KEY=your-secret-key-here
STRIPE_SECRET_KEY=sk_test_your_stripe_key
VITE_API_URL=http://localhost:8000
cp backend/.env.example backend/.env
# Edit backend/.env with your Stripe key if needed
docker-compose up --build- Frontend: http://localhost:3000
- Backend API docs: http://localhost:8000/docs
# Admin
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"admin","email":"admin@hospital.com","password":"admin123","role":"admin"}'
# Receptionist
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"receptionist","email":"receptionist@hospital.com","password":"recep123","role":"receptionist"}'
# Doctor
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"doctor","email":"doctor@hospital.com","password":"doc123","role":"doctor"}'
# Pharmacist
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"pharmacist","email":"pharmacist@hospital.com","password":"pharm123","role":"pharmacist"}'
# Patient
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"patient1","email":"patient1@example.com","password":"patient123","role":"patient"}'- Login → go to Appointments → add a doctor (name, specialization, contact)
- Go to Patients → add a patient, enter the patient's User ID in "Link to User Account" to enable self-booking
- Book an appointment for a patient
- Go to Pharmacy → add drugs to inventory
- Go to Billing → create an invoice for a patient
- View Reports and Dashboard
- Login → Dashboard shows your appointments and invoices
- Go to Appointments → book your own appointment (requires account to be linked to a patient profile by a receptionist/admin)
- Cancel a scheduled appointment
- Go to Billing → view and pay your invoices
- Login → view and manage appointments
- Add/edit patient records
- Create prescriptions in Pharmacy
- View Reports
- Login → manage drug inventory in Pharmacy
- Dispense pending prescriptions
- View pharmacy stock reports
For a patient user to self-book appointments:
- Register a user with role
patient(note the user ID from the response) - Login as admin or receptionist
- Go to Patients → Add Patient
- Fill in the patient details and enter the User ID in the "Link to User Account" field
- The patient can now login and book their own appointments
| Layer | Technology |
|---|---|
| Backend | FastAPI, SQLAlchemy, Pydantic |
| Auth | JWT (python-jose), bcrypt |
| Database | SQLite (default) / PostgreSQL |
| Frontend | React, Vite, TanStack Query |
| Forms | React Hook Form |
| Styling | Tailwind CSS |
| Payments | Stripe |
"Address already in use" when starting backend
pkill -f "uvicorn app.main"
uvicorn app.main:app --reloadPatient can't book appointments The patient user must be linked to a patient profile. Login as admin/receptionist → Patients → Edit patient → enter the User ID in "Link to User Account".
No doctors available in appointment form Login as admin/receptionist → Appointments → use the "Add Doctor" form at the top of the page.
CORS errors in browser
Ensure frontend/.env contains VITE_API_URL=http://localhost:8000 and restart the frontend dev server.