A comprehensive hospital management system built with NestJS, PostgreSQL, and TypeORM. This system provides APIs for managing patients, doctors, appointments, medical records, and hospital operations.
- Patient Management: Registration, profile management, medical history
- Doctor Management: Doctor profiles, specializations, schedules
- Appointment System: Booking, scheduling, and management
- Medical Records: Electronic health records, prescriptions, diagnoses
- Department Management: Hospital departments and staff allocation
- User Authentication: JWT-based authentication with role-based access control
- Billing System: Invoice generation and payment tracking
- Inventory Management: Medical supplies and equipment tracking
- Backend Framework: NestJS
- Database: PostgreSQL
- ORM: TypeORM
- Authentication: JWT (JSON Web Tokens)
- Validation: class-validator
- Documentation: Swagger/OpenAPI
- Testing: Jest
- Environment: Node.js
Before running this application, make sure you have the following installed:
- Node.js (v16 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn package manager
-
Clone the repository
git clone https://github.com/your-username/hospital-management-system.git cd hospital-management-system -
Install dependencies
npm install # or yarn install -
Environment Configuration
Create a
.envfile in the root directory:# Database Configuration DB_HOST=localhost DB_PORT=5432 DB_USERNAME=your_username DB_PASSWORD=your_password DB_NAME=hospital_management # JWT Configuration JWT_SECRET=your_jwt_secret_key JWT_EXPIRATION=24h # Application Configuration PORT=3000 NODE_ENV=development # Email Configuration (optional) SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your_email@gmail.com SMTP_PASS=your_app_password
-
Database Setup
Create a PostgreSQL database:
CREATE DATABASE hospital_management;
-
Run Database Migrations
npm run migration:run # or yarn migration:run -
Seed Initial Data (Optional)
npm run seed # or yarn seed
npm run start:dev
# or
yarn start:devnpm run build
npm run start:prod
# or
yarn build
yarn start:prodnpm run start:watch
# or
yarn start:watchThe application will be available at http://localhost:3000
- Users: System users (doctors, nurses, admins, patients)
- Patients: Patient information and medical history
- Doctors: Doctor profiles and specializations
- Appointments: Appointment scheduling and management
- MedicalRecords: Electronic health records
- Departments: Hospital departments
- Prescriptions: Medicine prescriptions
- Billing: Invoice and payment management
- Inventory: Medical supplies and equipment
Users (1:1) → Patients
Users (1:1) → Doctors
Doctors (1:n) → Appointments
Patients (1:n) → Appointments
Patients (1:n) → MedicalRecords
Doctors (1:n) → MedicalRecords
Departments (1:n) → Doctors
MedicalRecords (1:n) → Prescriptions
Patients (1:n) → Billing
Once the application is running, you can access the Swagger documentation at:
http://localhost:3000/api/docs
POST /auth/login- User loginPOST /auth/register- User registrationPOST /auth/refresh- Refresh JWT token
GET /patients- Get all patientsGET /patients/:id- Get patient by IDPOST /patients- Create new patientPUT /patients/:id- Update patientDELETE /patients/:id- Delete patient
GET /doctors- Get all doctorsGET /doctors/:id- Get doctor by IDPOST /doctors- Create new doctorPUT /doctors/:id- Update doctorDELETE /doctors/:id- Delete doctor
GET /appointments- Get all appointmentsGET /appointments/:id- Get appointment by IDPOST /appointments- Book new appointmentPUT /appointments/:id- Update appointmentDELETE /appointments/:id- Cancel appointment
GET /medical-records- Get all medical recordsGET /medical-records/patient/:patientId- Get patient's medical recordsPOST /medical-records- Create new medical recordPUT /medical-records/:id- Update medical record
# Unit tests
npm run test
# or
yarn test
# End-to-end tests
npm run test:e2e
# or
yarn test:e2e
# Test coverage
npm run test:cov
# or
yarn test:cov{
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"migration:generate": "typeorm migration:generate -d src/config/database.config.ts",
"migration:run": "typeorm migration:run -d src/config/database.config.ts",
"migration:revert": "typeorm migration:revert -d src/config/database.config.ts",
"seed": "ts-node src/database/seeds/seed.ts"
}src/
├── auth/ # Authentication module
├── common/ # Common utilities and decorators
├── config/ # Configuration files
├── database/ # Database configuration and migrations
├── decorators/ # Custom decorators
├── dto/ # Data Transfer Objects
├── entities/ # TypeORM entities
├── filters/ # Exception filters
├── guards/ # Authentication and authorization guards
├── interceptors/ # Request/response interceptors
├── modules/
│ ├── appointments/ # Appointment management
│ ├── billing/ # Billing and payments
│ ├── departments/ # Department management
│ ├── doctors/ # Doctor management
│ ├── inventory/ # Inventory management
│ ├── medical-records/ # Medical records management
│ ├── patients/ # Patient management
│ └── users/ # User management
├── pipes/ # Validation pipes
├── utils/ # Utility functions
├── app.module.ts # Root application module
└── main.ts # Application entry point
| Variable | Description | Default |
|---|---|---|
DB_HOST |
PostgreSQL host | localhost |
DB_PORT |
PostgreSQL port | 5432 |
DB_USERNAME |
Database username | - |
DB_PASSWORD |
Database password | - |
DB_NAME |
Database name | - |
JWT_SECRET |
JWT secret key | - |
JWT_EXPIRATION |
JWT token expiration | 24h |
PORT |
Application port | 3000 |
NODE_ENV |
Environment mode | development |
- JWT-based authentication
- Role-based access control (RBAC)
- Password hashing with bcrypt
- Input validation and sanitization
- CORS configuration
- Rate limiting
- Helmet security headers
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Initial release
- Basic CRUD operations for all entities
- JWT authentication
- Role-based access control
- Swagger documentation