A comprehensive real-time hospital bed management platform that synchronizes patient data, bed availability, and emergency transfers across multiple systems. Built with microservices architecture featuring Hospital API and Bed Manager with real-time Socket.IO communication.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Hospital Bed Management System β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β Hospital API βββββββββββΊβ Bed Manager βββββββββββΊβ Frontend (React)β
β (Port 5000) β Webhooks β (Port 4000) β Socket.IOβ (Port 5173) β
ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β β β
β β β
βΌ βΌ βΌ
MongoDB (Hospital) MongoDB (Bed Mgr) Browser Clients
- Patients - EncounterSnapshots - Doctors
- Staff - EmergencyRequests - Nurses
- Wards - TransferRequests - Ward Managers
- Beds - AlertNotifications - Admins
- Encounters - OccupancySnapshots
-
Hospital API β Bed Manager (Webhooks)
- Bed status changes
- Patient admissions/discharges
- Encounter updates
- Real-time data synchronization
-
Bed Manager β Hospital API (REST API)
- Patient transfers
- Bed status updates
- Emergency admissions
- Periodic data sync (every 5 minutes)
-
Bed Manager β Frontend (Socket.IO)
- Real-time alerts
- Bed availability updates
- Emergency notifications
- Occupancy alerts
- Live Bed Tracking: Instant updates on bed availability across all wards
- Socket.IO Notifications: Real-time alerts for emergencies, transfers, and occupancy
- Auto-Sync: Automatic 5-minute synchronization with Hospital API
- Webhook Integration: Bi-directional data flow with loop prevention
- Smart Bed Allocation: Nearest available bed algorithm based on ward distances
- Priority Routing: Critical patients prioritized for emergency wards
- Auto-Approval: Automatic emergency request processing based on urgency
- Multi-User Alerts: Notifications sent to all relevant ward managers and nurses
- Occupancy Tracking: 15-minute interval snapshots for trend analysis
- Forecasting: Bed demand prediction using historical data
- Alert System: Tiered urgency levels (low/medium/high/critical)
- Activity Logging: Complete audit trail of all bed operations
- Role-Based Access: Doctor, Nurse, Ward Manager, Admin roles
- Ward Assignment: Staff assigned to specific wards
- JWT Authentication: Secure token-based authentication
- Permission System: Granular access control per role
- Runtime: Node.js 18+
- Framework: Express.js 5.x
- Database: MongoDB with Mongoose 7.x
- Real-time: Socket.IO 4.6
- Authentication: JWT (jsonwebtoken)
- Scheduling: node-cron
- HTTP Client: node-fetch
- Runtime: Node.js 18+
- Framework: Express.js 5.x
- Database: MongoDB with Mongoose 8.x
- Webhooks: HMAC-SHA256 signature verification
- Data Seeding: Custom seed scripts
- Framework: React 18.2
- Build Tool: Vite 7.2
- UI Library: Custom medical-themed components
- Charts: Recharts, D3.js
- 3D Visualization: Three.js
- Real-time: Socket.IO Client 4.8
- Icons: React Icons
# Required software
- Node.js >= 18.0.0
- MongoDB >= 4.4
- npm or yarn
- Git- Clone Repository
git clone https://github.com/PranjalSK03/Bed_Manager.git
cd Bed_Manager- Setup environment variables β create .env files in the backend, frontend of Bed Manager, and Hospital API folder, then add the following contents:
Bed Manager - backend (.env):
MONGODB_URI=mongodb+srv://ghelanimeet2002:Meet%405568@cluster0.uv2gcwr.mongodb.net/?appName=
PORT=4000
JWT_SECRET=bed_manager_secret_key_123
HOSPITAL_API_URL=http://localhost:5000/api/v1/hospital
AUTO_SYNC_INTERVAL_MINUTES=5
WEBHOOK_SHARED_SECRET=dev-webhook-secretBed Manager - frontend (.env):
VITE_API_BASE=http://localhost:4000/api/v1/bed_manager
HOSPITAL_API_URL=http://localhost:3000/api/v1/hospitalHospital API (.env):
MongoDB_URL=mongodb+srv://ghelanimeet2002:Meet%405568@hospitaldata.rhee1rm.mongodb.net/?appN
PORT=5000
BED_MANAGER_WEBHOOK_URL=http://localhost:4000/api/v1/bed_manager/webhooks
WEBHOOK_SHARED_SECRET=dev-webhook-secret-
Open three separate terminals: one for Hospital API, one for backend, and one for frontend of Bed Manager.
-
Install backend dependencies β run
npm install(cd to Bed_manager/backend). -
Install frontend dependencies β run
npm install(cd to Bed_manager/frontend). -
Install Hospital API dependencies β run
npm install(cd to Hospital_API). -
Start the services:
# Terminal 1 - Hospital API
cd Hospital_API
npm run dev
# Terminal 2 - Bed Manager Backend
cd Bed_manager/backend
npm run dev
# Terminal 3 - Bed Manager Frontend
cd Bed_manager/frontend
npm run dev- Access Application
Frontend: http://localhost:5173
Bed Manager API: http://localhost:4000
Hospital API: http://localhost:5000
If the above process feels tedious, you can use the hosted version instead (although it may have latency during some operations): https://bed-manager-frontend.onrender.com/
| Role | Username | Password |
|---|---|---|
| Admin | admin | Admin123 |
| ICU Manager | anuradha | 123456 |
| General Ward Manager | karan | 123456 |
| Nurse Cardiology ICU Ward 1 | nurse1 | 123456 |
| Doctor Cardiology | doc1 | 123456 |
Note: The Admin has the ability to assign or edit user credentials. For any credential changes, login as Admin and navigate to the Admin Panel.
End_sem/
βββ Hospital_API/ # Source of truth for patient data
β βββ app.js # Express server setup
β βββ config/ # Database configuration
β βββ controllers/ # Request handlers
β βββ models/ # Mongoose schemas (Patient, Bed, Encounter, Ward, Staff)
β βββ routes/ # API endpoints
β βββ utils/ # Webhook sender utility
β βββ scripts/ # Database seeding scripts
β
βββ Bed_manager/
β βββ backend/ # Real-time bed management server
β β βββ app.js # Express + Socket.IO server
β β βββ config/ # DB config, ward distances
β β βββ controllers/ # Business logic (14 controllers)
β β βββ middleware/ # JWT authentication
β β βββ models/ # Mongoose schemas (13 models)
β β βββ routes/ # API routes (14 route files)
β β βββ services/ # Core services
β β β βββ autoSync.js # Periodic Hospital API sync
β β β βββ hospitalClient.js # HTTP client for Hospital API
β β β βββ nearestBed.js # Smart bed allocation
β β β βββ occupancyAlert.js # Alert generation
β β β βββ socket.js # Socket.IO management
β β βββ schedulers/ # Cron jobs
β β βββ scripts/ # Utility scripts
β β
β βββ frontend/ # React SPA
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ pages/ # Main views (14 pages)
β β βββ theme/ # Medical color scheme
β β βββ api.js # API client
β β βββ socket.js # Socket.IO client
β β βββ App.jsx # Root component
β βββ public/ # Static assets
// Runs every 5 minutes (configurable)
AutoSync Process:
1. Fetch all wards from Hospital API
2. Fetch all beds from Hospital API
3. Fetch active encounters from Hospital API
4. Fetch patient data from Hospital API
5. Update/Create records in Bed Manager MongoDB
6. Track sync in SyncRun collectionHospital API Event β Webhook Sent β Bed Manager Processes β Socket.IO Broadcast
Supported Events:
- bed.updated β Bed status/equipment changed
- bed.created β New bed added
- encounter.updated β Patient admission/transfer
- encounter.created β New patient encounter
- encounter.deleted β Patient discharged
- patient.deleted β Patient record removed// Bed Manager β Hospital API request
Headers: { 'X-Sync-Source': 'bed_manager' }
// Hospital API checks before sending webhook
if (syncSource === 'bed_manager') {
skip_webhook(); // Prevents infinite loop
}- Landing Page: Marketing page with feature highlights
- Login: JWT authentication
- Dashboard: Main control center with navigation
- Beds: Real-time bed status grid with filters
- Wards: Ward management and occupancy overview
- Emergency Requests: Urgent admission queue with auto-allocation
- Patient Transfers: Transfer request workflow
- Analytics: Occupancy trends, forecasting charts
- Alerts: System notifications and warnings
- Users: User management (admin only)
- Profile: User settings and preferences
- 3D Hospital Map: Interactive ward visualization
- Encounter Snapshots: Patient encounter history
- Admin Panel: System configuration
- AlertToast: Real-time notification toasts
- ECGLoader: Medical-themed loading animation
- Icons: Custom medical icon set
- Charts: Recharts for analytics
- 3D Map: Three.js hospital visualization
- JWT token-based authentication
- Secure password hashing with bcrypt
- Token expiration and refresh
- localStorage for token persistence
- Role-based access control (RBAC)
- Ward-specific permissions
- Protected API endpoints
- Middleware authentication guards
- HMAC-SHA256 webhook signatures
- Environment variable secrets
- CORS configuration
- Input validation and sanitization
Thresholds:
- 50-74%: Low urgency
- 75-79%: Medium urgency
- 80-89%: High urgency
- 90%+: Critical urgency
Alert Triggers:
β Occupancy increase β Alert sent
β Occupancy decrease β No alert (improvement)
β No change β No alert (status quo)- User-specific Socket.IO rooms
- Multi-recipient broadcasting
- Seen/unseen tracking
- Auto-dismissal based on urgency
- Sound notifications
# Hospital API
cd Hospital_API
npm run verify
# Test specific routes
node test-routes.js# All services use nodemon for hot reload
npm run dev
# Production mode
npm start# Hospital API - Create sample patients, wards, beds, encounters
cd Hospital_API
npm run seed
# Bed Manager - Create user accounts
cd Bed_manager/backend
npm run seedGET /api/v1/hospital/patients - List patients
POST /api/v1/hospital/patients - Create patient
GET /api/v1/hospital/wards - List wards
GET /api/v1/hospital/beds - List beds
PATCH /api/v1/hospital/beds/:id - Update bed
GET /api/v1/hospital/encounters - List encounters
PATCH /api/v1/hospital/encounters/:id/transfer - Transfer patient
GET /api/v1/hospital/sync/beds - Sync endpoint
POST /api/v1/hospital/sync/beds/patch - Apply bed patch
POST /api/v1/bed_manager/auth/login - User login
GET /api/v1/bed_manager/beds - List beds
PUT /api/v1/bed_manager/beds/:id - Update bed
POST /api/v1/bed_manager/beds/:id/update-and-push - Update & sync to Hospital
GET /api/v1/bed_manager/emergency-requests - List emergency requests
POST /api/v1/bed_manager/emergency-requests - Create emergency
POST /api/v1/bed_manager/emergency-requests/:id/accept - Accept request
GET /api/v1/bed_manager/transfer-requests - List transfers
POST /api/v1/bed_manager/transfer-requests - Create transfer
GET /api/v1/bed_manager/alert-notifications - Get alerts
PUT /api/v1/bed_manager/alert-notifications/:id/mark-seen - Mark seen
POST /api/v1/bed_manager/webhooks - Receive webhooks
Hospital API (.env)
PORT=5000
MONGODB_URI=mongodb://127.0.0.1:27017/hospital_api
BED_MANAGER_WEBHOOK_URL=http://localhost:4000/api/v1/bed_manager/webhooks
WEBHOOK_SHARED_SECRET=your-webhook-secret
ALLOWED_ORIGINS=http://localhost:5173,*Bed Manager Backend (.env)
PORT=4000
MONGODB_URI=mongodb://127.0.0.1:27017/bed_manager
JWT_SECRET=your-jwt-secret
WEBHOOK_SHARED_SECRET=your-webhook-secret
HOSPITAL_API_URL=http://localhost:5000/api/v1/hospital
AUTO_SYNC_INTERVAL_MINUTES=5
FRONTEND_ORIGIN=http://localhost:5173
OCCUPANCY_SNAPSHOT_INTERVAL=*/15 * * * *
OCCUPANCY_CLEANUP_DAYS=90Frontend (.env)
VITE_API_BASE=http://localhost:4000/api/v1/bed_manager- patients: Patient demographics and medical records
- staff: Hospital staff with role and ward assignments
- wards: Ward configuration and metadata
- beds: Bed inventory with equipment and status
- encounters: Active patient admissions and encounters
- users: System users (doctors, nurses, managers, admins)
- wards: Synchronized ward data from Hospital API
- beds: Synchronized bed data with sync status
- encounterSnapshots: Patient encounter snapshots
- emergencyRequests: Urgent admission requests
- transferRequests: Patient transfer workflows
- alertNotifications: User notifications and alerts
- occupancySnapshots: Historical occupancy data
- forecasts: Bed demand predictions
- syncRuns: Sync operation logs
- activityLogs: User action audit trail
- webhookEvents: Webhook delivery tracking
MongoDB Connection Failed
# Ensure MongoDB is running
sudo systemctl status mongod
sudo systemctl start mongodPort Already in Use
# Kill process on port 4000
lsof -ti:4000 | xargs kill -9
# Or change PORT in .env fileWebhook Not Working
# Verify WEBHOOK_SHARED_SECRET matches in both APIs
# Check BED_MANAGER_WEBHOOK_URL is correct
# Ensure both servers are runningSocket.IO Not Connecting
# Check CORS configuration
# Verify frontend connects to correct port
# Check browser console for errors- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project was developed by Team 5:
- Pranjal Singh Katiyar - PranjalSK03
- Meet Ghelani - meet6868
- Prateek Tiwari - Prateek-Tiwari10
- Pavan Reddy - pavanreddy2480
- Sri Charan Peri - sricharanperi
This project was developed as part of the Software System Development course at International Institute of Information Technology, Hyderabad (IIIT Hyderabad) under the guidance of Professor Sai Anirudh Karre.
We would also like to acknowledge:
- MongoDB for NoSQL database
- Socket.IO for real-time communication
- React team for frontend framework
- Express.js for backend framework
- Medical UI inspiration from healthcare systems
For issues and questions:
- GitHub Issues: Create Issue
- Email: Contact repository owner
Version: 1.0.0
Last Updated: December 2025
Node Version: >=18.0.0