Skip to content

MedQueue is a centralized platform that tracks hospital bed availability in real-time, helping patients quickly find nearby hospitals with available beds, reducing delays in medical emergencies and saving lives.

Notifications You must be signed in to change notification settings

Aggarwalmansi/MedQueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ MedQueue - Hospital Management System

A comprehensive, real-time hospital management platform that connects patients with healthcare facilities, enabling smart hospital discovery, appointment booking, and live bed availability tracking.

Live Demo Backend Frontend Database


πŸ“‹ Table of Contents


✨ Features

For Patients

  • πŸ” Smart Hospital Search - Semantic search with autocomplete suggestions
  • πŸ“ Location-Based Discovery - Find nearby hospitals using geolocation
  • 🏨 Real-Time Bed Availability - Live updates on ICU, Oxygen, and General beds
  • ⏱️ ER Wait Times - View current emergency room wait times by severity
  • πŸ“… Appointment Booking - Book appointments via triage or calendar
  • ⭐ Hospital Ratings - Rate and review hospitals
  • πŸ“± Virtual Queue - Join virtual waiting lists for emergency care
  • 🎫 Booking Management - View and cancel appointments

For Hospital Managers

  • πŸ“Š Dashboard - Comprehensive overview of hospital operations
  • πŸ›οΈ Inventory Management - Update bed counts and doctor availability
  • πŸ“‹ Booking Management - View and manage all appointments (triage + calendar)
  • ⏰ ER Wait Time Updates - Manage emergency room wait times
  • πŸ₯ Facility Management - Update specializations, diagnostics, and accreditations
  • πŸ”” Real-Time Notifications - Instant alerts for new bookings via WebSocket
  • πŸ“ˆ Profile Completeness - Track and improve hospital profile quality

For Administrators

  • βœ… Hospital Verification - Approve/reject hospital registrations
  • πŸ“Š System Analytics - View platform statistics and metrics
  • πŸ₯ Hospital Management - Activate/deactivate hospitals
  • πŸ‘₯ User Management - Monitor platform users

πŸ› οΈ Tech Stack

Backend

  • Runtime: Node.js (Express.js v5.1.0)
  • Database: PostgreSQL with Prisma ORM (v6.18.0)
  • Authentication: JWT + Google OAuth 2.0 (Passport.js)
  • Real-Time: Socket.io (v4.8.1)
  • Security: bcryptjs, express-session
  • API: RESTful architecture

Frontend

  • Framework: React (v19.1.1)
  • Build Tool: Vite (v7.1.7)
  • Routing: React Router DOM (v7.9.5)
  • Styling: Tailwind CSS (v4.1.17)
  • Maps: Leaflet + React Leaflet
  • Animations: Framer Motion (v12.23.24)
  • Icons: Lucide React
  • Real-Time: Socket.io Client

DevOps

  • Hosting: Vercel (Frontend) + Render/Railway (Backend)
  • Database: PostgreSQL (Cloud)
  • Version Control: Git

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Frontend (React)                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Patient  β”‚  β”‚ Hospital β”‚  β”‚  Admin   β”‚  β”‚   Auth   β”‚   β”‚
β”‚  β”‚Dashboard β”‚  β”‚Dashboard β”‚  β”‚Dashboard β”‚  β”‚  Pages   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↕ HTTP/WebSocket
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Backend (Express + Socket.io)             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Auth   β”‚  β”‚ Patient  β”‚  β”‚ Hospital β”‚  β”‚  Admin   β”‚   β”‚
β”‚  β”‚  Routes  β”‚  β”‚  Routes  β”‚  β”‚  Routes  β”‚  β”‚  Routes  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚  β”‚  Search  β”‚  β”‚   Auth   β”‚  β”‚ Socket   β”‚                 β”‚
β”‚  β”‚Controllerβ”‚  β”‚Middlewareβ”‚  β”‚  Events  β”‚                 β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↕ Prisma ORM
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    PostgreSQL Database                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Users   β”‚  β”‚Hospitals β”‚  β”‚ Bookings β”‚  β”‚ Ratings  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                               β”‚
β”‚  β”‚  Queue   β”‚  β”‚  Tokens  β”‚                               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • PostgreSQL (v14 or higher)
  • npm or yarn
  • Git

Installation

1. Clone the Repository

git clone https://github.com/yourusername/medqueue.git
cd medqueue

2. Backend Setup

cd backend

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration (see Environment Variables section)

# Generate Prisma client
npx prisma generate

# Run database migrations
npx prisma migrate deploy

# (Optional) Seed database with sample data
npx prisma db seed

# Start development server
npm run dev

The backend will run on http://localhost:5001

3. Frontend Setup

cd ../frontend

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env with your backend URL

# Start development server
npm run dev

The frontend will run on http://localhost:5173

Quick Start with Docker (Optional)

# Coming soon
docker-compose up

πŸ“‘ API Documentation

Base URL

  • Development: http://localhost:5001/api
  • Production: https://your-backend-url.com/api

Authentication

All authenticated endpoints require a Bearer token in the Authorization header:

Authorization: Bearer <your_jwt_token>

πŸ” Auth Routes (/api/auth)

Register User

POST /api/auth/register
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "securePassword123",
  "role": "PATIENT | HOSPITAL | ADMIN",
  "fullName": "John Doe",
  "phone": "+1234567890",
  
  // Required if role is HOSPITAL
  "hospitalName": "City General Hospital",
  "address": "123 Main St",
  "city": "New York",
  "latitude": 40.7128,
  "longitude": -74.0060
}

Response:

{
  "message": "User registered successfully",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "refresh_token_here",
  "user": {
    "id": 1,
    "email": "user@example.com",
    "role": "PATIENT",
    "fullName": "John Doe"
  }
}

Login

POST /api/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "securePassword123"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "refresh_token_here",
  "user": {
    "id": 1,
    "email": "user@example.com",
    "role": "PATIENT",
    "fullName": "John Doe"
  }
}

Google OAuth Login

GET /api/auth/google

Redirects to Google OAuth consent screen.

Refresh Token

POST /api/auth/refresh-token
Content-Type: application/json

{
  "refreshToken": "your_refresh_token"
}

Logout

POST /api/auth/logout
Content-Type: application/json

{
  "refreshToken": "your_refresh_token"
}

Get Current User

GET /api/auth/me
Authorization: Bearer <token>

πŸ₯ Patient Routes (/api/patient)

Get Hospitals (with filters)

GET /api/patient/hospitals?lat=40.7128&lng=-74.0060&specialization=Cardiology&page=1&limit=10&sortBy=distance&order=asc&bedType=ICU&minRating=4

Query Parameters:

  • lat (optional): User latitude
  • lng (optional): User longitude
  • specialization (optional): Filter by department
  • page (default: 1): Page number
  • limit (default: 10): Results per page
  • sortBy (default: distance): Sort by distance, rating, name, or availability
  • order (default: asc): asc or desc
  • bedType (optional): Filter by ICU, Oxygen, Ventilator, or General
  • minRating (optional): Minimum average rating

Response:

{
  "hospitals": [
    {
      "id": 1,
      "name": "City General Hospital",
      "address": "123 Main St",
      "city": "New York",
      "latitude": 40.7128,
      "longitude": -74.0060,
      "phone": "+1234567890",
      "bedsGeneral": 50,
      "bedsICU": 20,
      "bedsOxygen": 15,
      "doctorsActive": 30,
      "distance": 2.5,
      "totalBeds": 85,
      "viabilityScore": 837.5,
      "averageRating": 4.5,
      "totalRatings": 120,
      "erWaitTimes": {
        "critical": { "avgWaitMinutes": 10, "currentQueue": 2, "status": "Available" },
        "moderate": { "avgWaitMinutes": 45, "currentQueue": 5, "status": "Busy" },
        "nonUrgent": { "avgWaitMinutes": 120, "currentQueue": 10, "status": "Available" }
      }
    }
  ],
  "pagination": {
    "total": 25,
    "page": 1,
    "limit": 10,
    "totalPages": 3
  }
}

Get Hospital Details

GET /api/patient/hospitals/:id

Get Hospital Facilities

GET /api/patient/hospitals/:id/facilities

Response:

{
  "hospital": { /* full hospital object */ },
  "facilities": {
    "specializations": [
      { "department": "Cardiology", "specialists": 5, "beds": 20 }
    ],
    "diagnostics": {
      "mri": true,
      "ctScan": true,
      "xray": true
    },
    "criticalCare": {
      "ventilators": 10,
      "dialysis": true,
      "bloodBank": true
    },
    "supportServices": {
      "pharmacy": true,
      "cafeteria": true,
      "parking": true
    },
    "accreditations": [
      { "name": "NABH", "validUntil": "2025-12-31" }
    ]
  },
  "profileCompleteness": 85
}

Create Booking

POST /api/patient/bookings
Content-Type: application/json

{
  "hospitalId": 1,
  "patientName": "John Doe",
  "patientPhone": "+1234567890",
  "condition": "Chest Pain",
  "severity": "CRITICAL | MODERATE | LOW",
  "source": "TRIAGE | CALENDAR | WALK_IN",
  "status": "INCOMING | SCHEDULED",
  "appointmentTime": "2024-12-10T14:00:00Z",  // Optional, for calendar bookings
  "userId": 1  // Optional, for authenticated users
}

Response:

{
  "message": "Booking created successfully",
  "booking": {
    "id": 1,
    "hospitalId": 1,
    "patientName": "John Doe",
    "condition": "Chest Pain",
    "severity": "CRITICAL",
    "status": "INCOMING",
    "source": "TRIAGE",
    "createdAt": "2024-12-03T18:30:00Z"
  }
}

Get My Bookings

GET /api/patient/my-bookings
Authorization: Bearer <token>

Cancel Booking

DELETE /api/patient/bookings/:id
Authorization: Bearer <token>

Rate Hospital

POST /api/patient/hospitals/:id/rate
Authorization: Bearer <token>
Content-Type: application/json

{
  "value": 5,  // 1-5
  "comment": "Excellent service and care!"
}

Get ER Wait Times

GET /api/patient/hospitals/:id/er-wait-times

Join Virtual Queue

POST /api/patient/hospitals/:id/virtual-queue
Content-Type: application/json

{
  "patientName": "John Doe",
  "severity": "CRITICAL | MODERATE | LOW",
  "userId": 1  // Optional
}

Response:

{
  "message": "Successfully joined virtual queue",
  "queueEntry": {
    "id": 1,
    "hospitalId": 1,
    "patientName": "John Doe",
    "severity": "MODERATE",
    "status": "WAITING",
    "checkInTime": "2024-12-03T18:30:00Z"
  },
  "position": 5
}

Check Queue Status

GET /api/patient/hospitals/:id/virtual-queue/:entryId

πŸ₯ Hospital Routes (/api/hospital)

All routes require authentication with HOSPITAL role

Get Hospital Profile

GET /api/hospital/profile
Authorization: Bearer <token>

Update Inventory

PATCH /api/hospital/inventory
Authorization: Bearer <token>
Content-Type: application/json

{
  "bedsGeneral": 50,
  "bedsICU": 20,
  "bedsOxygen": 15,
  "doctorsActive": 30
}

Get All Bookings

GET /api/hospital/bookings?status=INCOMING&source=TRIAGE
Authorization: Bearer <token>

Query Parameters:

  • status (optional): Filter by INCOMING, ADMITTED, DIVERTED, CANCELLED, SCHEDULED, COMPLETED, NO_SHOW, or ALL
  • source (optional): Filter by TRIAGE, CALENDAR, WALK_IN, or ALL
  • hId (optional): Hospital ID (if not using authenticated manager)

Update Booking Status

PATCH /api/hospital/bookings/:id/status
Authorization: Bearer <token>
Content-Type: application/json

{
  "status": "ADMITTED | DIVERTED | CANCELLED | COMPLETED | NO_SHOW"
}

Update ER Wait Times

PUT /api/hospital/er-wait-times
Authorization: Bearer <token>
Content-Type: application/json

{
  "critical": {
    "avgWaitMinutes": 10,
    "currentQueue": 2,
    "status": "Available"
  },
  "moderate": {
    "avgWaitMinutes": 45,
    "currentQueue": 5,
    "status": "Busy"
  },
  "nonUrgent": {
    "avgWaitMinutes": 120,
    "currentQueue": 10,
    "status": "Available"
  }
}

Get Virtual Queue

GET /api/hospital/virtual-queue
Authorization: Bearer <token>

Update Queue Entry Status

PATCH /api/hospital/virtual-queue/:id/status
Authorization: Bearer <token>
Content-Type: application/json

{
  "status": "WAITING | CALLED | COMPLETED | EXPIRED | CANCELLED"
}

Remove from Queue

DELETE /api/hospital/virtual-queue/:id
Authorization: Bearer <token>

Update Facilities

PUT /api/hospital/facilities
Authorization: Bearer <token>
Content-Type: application/json

{
  "specializations": [
    { "department": "Cardiology", "specialists": 5, "beds": 20 }
  ],
  "diagnostics": {
    "mri": true,
    "ctScan": true
  },
  "criticalCare": {
    "ventilators": 10,
    "dialysis": true
  },
  "supportServices": {
    "pharmacy": true
  },
  "accreditations": [
    { "name": "NABH", "validUntil": "2025-12-31" }
  ]
}

πŸ‘¨β€πŸ’Ό Admin Routes (/api/admin)

Get System Stats

GET /api/admin/stats

Response:

{
  "totalHospitals": 150,
  "activeHospitals": 120,
  "pendingHospitals": 30,
  "totalUsers": 5000,
  "totalBeds": 12500,
  "systemHealth": "Excellent"
}

Get Pending Hospitals

GET /api/admin/hospitals/pending

Get All Hospitals

GET /api/admin/hospitals/all

Verify/Reject Hospital

PATCH /api/admin/hospitals/:id/verify
Content-Type: application/json

{
  "isVerified": true  // true to approve, false to reject
}

πŸ” Search Routes (/api/search)

Semantic Search

GET /api/search?q=hospitals with ICU beds near me&lat=40.7128&lng=-74.0060&page=1&limit=10

Query Parameters:

  • q (required): Search query (supports natural language)
  • lat, lng (optional): User coordinates
  • page, limit (optional): Pagination

Supported Search Patterns:

  • "hospitals with ICU beds"
  • "cardiac care near me"
  • "emergency room in New York"
  • "pediatric hospital with ventilators"

Get Suggestions (Autocomplete)

GET /api/search/suggestions?q=card

Response:

{
  "hospitals": [
    { "name": "Cardiac Care Center", "id": 5 }
  ],
  "specializations": ["Cardiology"],
  "facilities": ["Cardiac ICU"],
  "bedTypes": ["ICU Beds"]
}

Get Trending Hospitals

GET /api/search/trending

Returns top 5 hospitals by average rating.

Get Recommended Hospitals

GET /api/search/recommended

Returns 3 recommended hospitals with reasons.


πŸ”Œ WebSocket Events

Client β†’ Server

// Join hospital room for real-time updates
socket.emit('join_hospital', hospitalId);

Server β†’ Client

// New booking received
socket.on('new_booking', (booking) => { /* ... */ });

// Booking status updated
socket.on('booking_updated', (booking) => { /* ... */ });

// Hospital inventory updated
socket.on('hospital_updated', (hospital) => { /* ... */ });

// Public hospital update (for patient dashboard)
socket.on('hospital_updated_public', (hospital) => { /* ... */ });

// ER wait times updated
socket.on('er_wait_times_updated', (data) => { /* ... */ });

// Queue entry updated
socket.on('queue_entry_updated', (entry) => { /* ... */ });

// Queue entry removed
socket.on('queue_entry_removed', (data) => { /* ... */ });

πŸ—„οΈ Database Schema

Entity Relationship Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    User     │────────▢│   Hospital   │◀────────│   Booking   β”‚
β”‚             β”‚ manages β”‚              β”‚ receivesβ”‚             β”‚
β”‚ - id        β”‚         β”‚ - id         β”‚         β”‚ - id        β”‚
β”‚ - email     β”‚         β”‚ - name       β”‚         β”‚ - userId    β”‚
β”‚ - password  β”‚         β”‚ - address    β”‚         β”‚ - hospitalIdβ”‚
β”‚ - role      β”‚         β”‚ - latitude   β”‚         β”‚ - condition β”‚
β”‚ - fullName  β”‚         β”‚ - longitude  β”‚         β”‚ - severity  β”‚
β”‚ - phone     β”‚         β”‚ - bedsGeneralβ”‚         β”‚ - status    β”‚
β”‚ - googleId  β”‚         β”‚ - bedsICU    β”‚         β”‚ - source    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚ - bedsOxygen β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚                 β”‚ - managerId  β”‚               β”‚
      β”‚                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
      β”‚                       β”‚                        β”‚
      β”‚                       β”‚                        β”‚
      β–Ό                       β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Rating    β”‚         β”‚VirtualQueue  β”‚         β”‚RefreshToken β”‚
β”‚             β”‚         β”‚              β”‚         β”‚             β”‚
β”‚ - id        β”‚         β”‚ - id         β”‚         β”‚ - id        β”‚
β”‚ - value     β”‚         β”‚ - hospitalId β”‚         β”‚ - token     β”‚
β”‚ - comment   β”‚         β”‚ - patientNameβ”‚         β”‚ - userId    β”‚
β”‚ - userId    β”‚         β”‚ - severity   β”‚         β”‚ - expiresAt β”‚
β”‚ - hospitalIdβ”‚         β”‚ - status     β”‚         β”‚ - revoked   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Models

User

  • Roles: PATIENT, HOSPITAL, ADMIN
  • Authentication: Email/Password + Google OAuth
  • Relations: Can manage one hospital, create multiple bookings and ratings

Hospital

  • Verification: Admin approval required (isVerified)
  • Live Inventory: Real-time bed counts and doctor availability
  • Facilities: JSON fields for specializations, diagnostics, critical care, support services, accreditations
  • Profile Completeness: Calculated score (0-100)

Booking

  • Sources: TRIAGE (emergency), CALENDAR (scheduled), WALK_IN
  • Statuses: INCOMING, ADMITTED, DIVERTED, CANCELLED, SCHEDULED, COMPLETED, NO_SHOW
  • Severity: LOW, MODERATE, CRITICAL

VirtualQueueEntry

  • Statuses: WAITING, CALLED, COMPLETED, EXPIRED, CANCELLED
  • Ordering: By severity (CRITICAL first) then check-in time

πŸ”§ Environment Variables

Backend (.env)

# Server Configuration
PORT=5001
NODE_ENV=development
FRONTEND_URL=http://localhost:5173

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/medqueue?schema=public"

# JWT Authentication
JWT_SECRET=your_super_secret_jwt_key_here_change_in_production
JWT_EXPIRES_IN=1h
REFRESH_TOKEN_EXPIRES_IN=7d

# Session
SESSION_SECRET=your_session_secret_here

# Google OAuth
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=http://localhost:5001/api/auth/google/callback

# CORS
ALLOWED_ORIGINS=http://localhost:5173,https://med-queue.vercel.app

Frontend (.env)

# Backend API
VITE_API_URL=http://localhost:5001/api
VITE_SOCKET_URL=http://localhost:5001

# Google Maps (if using)
VITE_GOOGLE_MAPS_API_KEY=your_google_maps_api_key

πŸš€ Deployment

Backend Deployment (Render/Railway)

  1. Create PostgreSQL Database

    • Set up a PostgreSQL instance
    • Copy the connection string
  2. Deploy Backend

    # On Render/Railway
    - Connect your GitHub repository
    - Set build command: npm install && npx prisma generate && npx prisma migrate deploy
    - Set start command: npm start
    - Add all environment variables
  3. Run Migrations

    npx prisma migrate deploy

Frontend Deployment (Vercel)

  1. Connect Repository

    • Import your GitHub repository to Vercel
  2. Configure Build Settings

    • Framework: Vite
    • Build Command: npm run build
    • Output Directory: dist
    • Install Command: npm install
  3. Set Environment Variables

    • Add VITE_API_URL with your backend URL
    • Add VITE_SOCKET_URL with your backend URL
  4. Deploy

    vercel --prod

πŸ§ͺ Testing

Run Backend Tests

cd backend
npm test

Run Frontend Tests

cd frontend
npm test

Manual Testing Checklist

  • User registration and login
  • Google OAuth flow
  • Hospital search with filters
  • Booking creation and cancellation
  • Real-time bed updates
  • Hospital manager dashboard
  • Admin approval workflow
  • Rating submission
  • Virtual queue functionality

πŸ“Š Performance Optimization

  • Database Indexing: Indexes on latitude, longitude, isVerified, userId, hospitalId
  • Pagination: All list endpoints support pagination
  • Caching: Consider Redis for frequently accessed data
  • WebSocket: Real-time updates without polling
  • Image Optimization: Use CDN for hospital images
  • Code Splitting: React lazy loading for routes

πŸ”’ Security

  • βœ… JWT-based authentication
  • βœ… Password hashing with bcryptjs
  • βœ… CORS protection
  • βœ… SQL injection prevention (Prisma ORM)
  • βœ… XSS protection
  • βœ… Rate limiting (recommended: express-rate-limit)
  • βœ… HTTPS in production
  • βœ… Environment variable protection

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Commit your changes
    git commit -m 'Add some amazing feature'
  4. Push to the branch
    git push origin feature/amazing-feature
  5. Open a Pull Request

Code Style

  • Follow ESLint configuration
  • Use Prettier for formatting
  • Write meaningful commit messages
  • Add comments for complex logic

πŸ“ License

This project is licensed under the ISC License.


πŸ‘₯ Authors

  • Mansi Agarwal - Initial work - GitHub

πŸ™ Acknowledgments

  • React and Vite communities
  • Prisma team for excellent ORM
  • Socket.io for real-time capabilities
  • Leaflet for mapping functionality
  • All contributors and testers

πŸ“ž Support

For support, email support@medqueue.com or open an issue on GitHub.


πŸ—ΊοΈ Roadmap

  • Mobile app (React Native)
  • SMS notifications
  • Multi-language support
  • Advanced analytics dashboard
  • AI-powered hospital recommendations
  • Telemedicine integration
  • Insurance verification
  • Payment gateway integration

Built with ❀️ for better healthcare accessibility

About

MedQueue is a centralized platform that tracks hospital bed availability in real-time, helping patients quickly find nearby hospitals with available beds, reducing delays in medical emergencies and saving lives.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages