A full-stack hospital management system demonstrating advanced DBMS concepts including transactions, triggers, stored procedures, views, indexes, and concurrency control.
- Backend: Node.js + Express.js
- Frontend: React + React Router DOM + Tailwind CSS + PostCSS
- Database: PostgreSQL (pure SQL, no ORM)
- API Client: Axios
- Database Driver: node-postgres (
pg)
- Patient Management: Register and track patient information
- Smart Bed Allocation: Real-time bed availability with concurrency-safe assignment
- Admission System: Transaction-based admission process with automatic bed allocation
- Waiting List: Priority-based queue for bed assignment
- Doctor Assignment: Manage doctor-patient relationships
- Billing System: Automated billing with tax calculation
- Audit Logs: Track all database changes with triggers
- Role-Based Access: Admin, Doctor, Staff, and Billing roles
- Transactions: Multi-step admission process with ACID properties
- Triggers: Automatic audit logging on INSERT/UPDATE/DELETE
- Stored Procedures/Functions: Complex business logic in database
- Views: Materialized queries for reporting
- Indexes: Performance optimization on frequently queried columns
- Constraints: Data integrity with CHECK, FOREIGN KEY, UNIQUE constraints
- Row-Level Locking:
SELECT FOR UPDATEto prevent race conditions - Parameterized Queries: SQL injection prevention
- Node.js (v18 or higher)
- PostgreSQL (v14 or higher)
- npm or yarn
- Install PostgreSQL and create a new database:
psql -U postgres
CREATE DATABASE medicare;
\q- Copy environment files:
# Root level
cp .env.example .env
# Backend level
cp backend/.env.example backend/.env- Edit
.envfiles with your PostgreSQL credentials:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=medicare
DB_USER=postgres
DB_PASSWORD=your_password
JWT_SECRET=your_secret_key
On Windows (PowerShell):
cd db
# Run each SQL file in order
Get-Content schema.sql | psql -U postgres -d medicare
Get-Content functions.sql | psql -U postgres -d medicare
Get-Content triggers.sql | psql -U postgres -d medicare
Get-Content indexes_and_views.sql | psql -U postgres -d medicare
Get-Content seed.sql | psql -U postgres -d medicareOn Linux/Mac:
cd db
chmod +x run_migrations.sh
./run_migrations.shOr manually:
psql -U postgres -d medicare -f db/schema.sql
psql -U postgres -d medicare -f db/functions.sql
psql -U postgres -d medicare -f db/triggers.sql
psql -U postgres -d medicare -f db/indexes_and_views.sql
psql -U postgres -d medicare -f db/seed.sql# Install root dependencies
npm install
# Install all dependencies (backend + frontend)
npm run install-allDevelopment Mode (Both servers concurrently):
npm run devThis will start:
- Backend API: http://localhost:5000
- Frontend: http://localhost:5173
Or run individually:
# Terminal 1 - Backend
cd backend
npm run dev
# Terminal 2 - Frontend
cd frontend
npm run devImport the postman_collection_medicare.json file into Postman to test all API endpoints.
medicare/
βββ README.md
βββ package.json
βββ .env.example
βββ db/
β βββ schema.sql # Database schema with constraints
β βββ functions.sql # Stored procedures and functions
β βββ triggers.sql # Audit triggers
β βββ indexes_and_views.sql # Performance optimizations
β βββ seed.sql # Sample data
β βββ run_migrations.sh # Migration script
βββ backend/
β βββ package.json
β βββ .env.example
β βββ server.js
β βββ config/
β β βββ db.js # PostgreSQL connection pool
β βββ controllers/ # Request handlers
β βββ routes/ # API routes
β βββ services/ # Business logic with transactions
β βββ utils/ # Helper functions
βββ frontend/
βββ package.json
βββ tailwind.config.js
βββ postcss.config.js
βββ src/
β βββ main.jsx
β βββ App.jsx
β βββ api/ # Axios configuration
β βββ pages/ # React page components
β βββ components/ # Reusable UI components
βββ public/
POST /api/auth/login- User loginPOST /api/auth/register- User registration
GET /api/patients- List all patientsGET /api/patients/:id- Get patient detailsPOST /api/patients- Register new patientPUT /api/patients/:id- Update patientDELETE /api/patients/:id- Delete patient
POST /api/admissions- Create admission (with transaction)GET /api/admissions- List admissionsGET /api/admissions/:id- Get admission detailsPUT /api/admissions/:id/discharge- Discharge patient
GET /api/beds- List all beds with availabilityGET /api/beds/available- Get available bedsPUT /api/beds/:id/status- Update bed status
GET /api/doctors- List all doctorsGET /api/doctors/:id/patients- Get doctor's patients
POST /api/billing- Generate billGET /api/billing/:admissionId- Get bill for admissionPUT /api/billing/:id/pay- Mark bill as paid
GET /api/reports/occupancy- Bed occupancy reportGET /api/reports/revenue- Revenue reportGET /api/reports/waiting-list- Waiting list report
- Admin: username:
admin, password:admin123 - Doctor: username:
doctor1, password:doctor123 - Staff: username:
staff1, password:staff123 - Billing: username:
billing1, password:billing123
- Start the application
- Import Postman collection
- Use the login endpoint to get a JWT token
- Test various endpoints with the token
- Create/Select a patient
- Check available beds:
GET /api/beds/available - Create admission:
POST /api/admissions(uses transaction) - System automatically:
- Assigns bed
- Updates bed status
- Creates audit log entry
- Triggers any relevant stored procedures
- Discharge:
PUT /api/admissions/:id/discharge - Generate bill:
POST /api/billing - Mark payment:
PUT /api/billing/:id/pay
- Parameterized queries (prevents SQL injection)
- Password hashing with bcrypt
- JWT authentication
- Input validation
- Transaction rollback on errors
- Normalization: 3NF normalized schema
- Referential Integrity: Foreign key constraints
- Data Validation: CHECK constraints
- Audit Trail: Automatic logging via triggers
- Concurrency Control: Row-level locking for bed allocation
- Performance: Strategic indexes on foreign keys and query columns
This is an educational project demonstrating DBMS concepts. Feel free to extend it with additional features.
MIT License