A comprehensive hospital management system built with Next.js 16, TypeScript, Prisma, SQLite, and NextAuth for authentication.
- NextAuth.js integration with credentials provider
- Role-based access control (RBAC) with 8 user roles:
- Admin, Doctor, Nurse, Receptionist, Lab Technician, Radiologist, Pharmacist, Accountant
- Secure password hashing with bcrypt
- Protected routes with middleware
- Session management
- Patient registration with comprehensive form validation
- Patient search by name, MRN, phone, or email
- Patient details view with medical history
- Visit history tracking
- Allergy and blood group management
- Emergency contact information
- Responsive design with mobile and desktop views
- Role-based dashboard with different views per user type
- Real-time statistics including:
- Total patients
- Today's appointments
- Pending lab orders
- Low stock drugs
- Bed occupancy rates
- Unpaid bills
- Quick actions for common tasks
- Notification system for important alerts
- Comprehensive SQLite database with 30+ tables
- Proper relationships and foreign keys
- Data integrity with constraints
- Activity logging for audit trails
- Soft delete for important records
- Appointment booking system with conflict checking
- OPD/IPD workflows
- Laboratory management
- Pharmacy management
- Ward and bed management
- Radiology module
- Prescription management
- Billing and invoicing
- Reports and analytics
- Framework: Next.js 16 with App Router
- Language: TypeScript
- Database: SQLite with Prisma ORM
- Authentication: NextAuth.js
- UI Components: shadcn/ui + Radix UI
- Styling: Tailwind CSS
- Forms: React Hook Form + Zod validation
- Icons: Lucide React
- Date Handling: date-fns
- Node.js 18.0.0 or higher
- npm or yarn package manager
npm installThe .env file is already configured with:
- SQLite database connection
- NextAuth secret and URL
- Default admin credentials
# Generate Prisma client
npx prisma generate
# Run migrations (already done)
npx prisma migrate dev
# Seed the database with sample data
npx prisma db seednpm run dev
# or
yarn devOpen http://localhost:3000 with your browser to access the application.
| Role | Password | Access | |
|---|---|---|---|
| Admin | admin@hospital.com | admin123 | Full system access |
| Doctor | doctor@hospital.com | admin123 | Patient care, prescriptions |
| Nurse | nurse@hospital.com | admin123 | Ward management, vitals |
| Lab Technician | lab@hospital.com | admin123 | Laboratory tests |
| Pharmacist | pharmacy@hospital.com | admin123 | Medication management |
src/
βββ app/ # Next.js App Router
β βββ api/ # API routes
β βββ auth/ # Authentication pages
β βββ dashboard/ # Protected dashboard pages
β βββ layout.tsx # Root layout
βββ components/ # React components
β βββ ui/ # shadcn/ui components
β βββ layout/ # Layout components
β βββ patients/ # Patient-specific components
βββ lib/ # Utilities and configurations
β βββ actions/ # Server actions
β βββ validations/ # Zod schemas
β βββ auth.ts # NextAuth configuration
β βββ db.ts # Database connection
βββ types/ # TypeScript type definitions
βββ middleware.ts # Route protection middleware
prisma/
βββ schema.prisma # Database schema
βββ migrations/ # Database migrations
βββ seed.ts # Database seeding script
- Password hashing with bcrypt
- CSRF protection via NextAuth
- SQL injection prevention via Prisma ORM
- Role-based access control
- Input validation with Zod
- Activity logging for audit trails
The system includes comprehensive entities:
- Users & Authentication (Users, Sessions, Accounts)
- Medical Staff (Doctors, Nurses, Lab Technicians, Pharmacists)
- Patients (Patient records, emergency contacts)
- Appointments (Scheduling, doctor availability)
- Medical Records (Visits, vitals, nurse notes)
- Ward Management (Wards, beds, admissions)
- Laboratory (Tests, orders, results)
- Radiology (Imaging tests, reports)
- Pharmacy (Drugs, prescriptions, dispensing)
- Billing (Services, bills, payments)
- Audit (Activity logs)
- Responsive design for all screen sizes
- Clean, modern interface with consistent styling
- Loading states and error handling
- Form validation with real-time feedback
- Toast notifications for user feedback
- Keyboard navigation support
- Accessible components with proper ARIA labels
- Server Components for improved performance
- Client-side caching with React Query patterns
- Optimistic updates for better UX
- Lazy loading for large datasets
- Proper database indexing
- TypeScript for type safety
- ESLint for code quality
- Prettier integration ready
- Hot reload in development
- Error boundaries for graceful error handling
GET/POST /api/auth/*- NextAuth endpoints
createPatient()- Create new patientupdatePatient()- Update patient informationsearchPatients()- Search patients by various criteriagetPatientById()- Get detailed patient information
The application is ready for deployment on:
- Vercel (recommended for Next.js)
- Netlify
- Railway
- Docker containers
For production deployment:
- Update environment variables
- Configure production database
- Set up proper domain and SSL
- Enable database backups
- Authentication system
- Patient management
- Basic dashboard
- Database schema
- Appointment scheduling
- Doctor schedules
- Conflict checking
- OPD workflows
- IPD management
- Ward and bed assignment
- Laboratory module
- Radiology integration
- Pharmacy management
- Prescription workflows
- Billing system
- Reports and analytics
- Database Tables: 30+
- UI Components: 20+ shadcn/ui components
- User Roles: 8 different roles
- Validation Schemas: Comprehensive Zod validation
- Security Features: Multi-layer protection
This is a production-style hospital management system. For contributions:
- Follow TypeScript best practices
- Ensure proper validation with Zod
- Add comprehensive error handling
- Test on multiple screen sizes
- Maintain security standards
This project is ready for deployment to Vercel. See the detailed DEPLOYMENT_GUIDE.md for step-by-step instructions.
- Database Migration: Switch from SQLite to PostgreSQL (already configured)
- Set up PostgreSQL: Use Vercel Postgres, Supabase, or Neon
- Configure Environment Variables: Add DATABASE_URL, NEXTAUTH_SECRET, NEXTAUTH_URL
- Deploy: Push to GitHub or use Vercel CLI
# Quick deploy with Vercel CLI
npm i -g vercel
vercel login
vercel --prod- β Database provider changed to PostgreSQL
- β Build scripts updated for Vercel
- β Environment configuration ready
- β Prisma migrations configured
For issues or questions about the hospital management system, please refer to:
- Database schema documentation in
/prisma/schema.prisma - Component documentation in respective files
- DEPLOYMENT_GUIDE.md for deployment help
- GitHub Issues for bug reports
- Data Security: Ensure proper backup procedures in production
- HIPAA Compliance: Additional measures needed for healthcare data
- Performance: Monitor database performance with larger datasets
- Updates: Keep dependencies updated for security
- Database: PostgreSQL required for Vercel deployment
Built with β€οΈ for modern healthcare management