# Hospital Management System (HMS)

A full-stack MERN (MongoDB, Express, React, Node.js) application for managing hospital operations including patient records, doctor management, appointments, and reports.

## Features

- **User Authentication**: Secure login system with JWT tokens
- **Dashboard**: Overview of hospital statistics
- **Patient Management**: Add, edit, delete, and search patients
- **Doctor Management**: Add, edit, delete, and search doctors
- **Appointment Scheduling**: Create and manage appointments with status tracking
- **Reports**: View detailed statistics and reports

## Tech Stack

### Backend
- Node.js
- Express.js
- MongoDB with Mongoose
- JWT Authentication
- bcryptjs for password hashing

### Frontend
- React.js with Vite
- React Router v6
- Axios for API calls
- CSS (custom styling)

## Prerequisites

- Node.js (v14 or higher)
- MongoDB (local or cloud instance)

## Installation

### Backend Setup

1. Navigate to the backend directory:
   
```
bash
   cd HMS/backend
   
```

2. Install dependencies:
   
```
bash
   npm install
   
```

3. Configure environment variables in `.env`:
   
```
   PORT=5000
   MONGO_URI=mongodb://localhost:27017/hospital_management
   JWT_SECRET=your_secret_key
   JWT_EXPIRE=7d
   
```

4. Start the backend server:
   
```
bash
   npm start
   
```

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

### Frontend Setup

1. Navigate to the frontend directory:
   
```
bash
   cd HMS/frontend
   
```

2. Install dependencies:
   
```bash
   npm install
   
```

3. Start the development server:
   
```
bash
   npm run dev
   
```

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

## Default Login Credentials

- **Email**: admin@hms.com
- **Password**: admin123

## API Endpoints

### Authentication
- POST `/api/auth/login` - User login
- POST `/api/auth/register` - User registration
- GET `/api/auth/me` - Get current user

### Patients
- GET `/api/patients` - Get all patients
- POST `/api/patients` - Create patient
- PUT `/api/patients/:id` - Update patient
- DELETE `/api/patients/:id` - Delete patient

### Doctors
- GET `/api/doctors` - Get all doctors
- POST `/api/doctors` - Create doctor
- PUT `/api/doctors/:id` - Update doctor
- DELETE `/api/doctors/:id` - Delete doctor

### Appointments
- GET `/api/appointments` - Get all appointments
- POST `/api/appointments` - Create appointment
- PUT `/api/appointments/:id` - Update appointment
- DELETE `/api/appointments/:id` - Delete appointment

### Reports
- GET `/api/reports/overview` - Dashboard overview
- GET `/api/reports/patients` - Patient statistics
- GET `/api/reports/doctors` - Doctor statistics
- GET `/api/reports/appointments` - Appointment statistics

## Project Structure

```
HMS/
├── backend/
│   ├── config/
│   │   └── db.js
│   ├── middleware/
│   │   └── auth.js
│   ├── models/
│   │   ├── User.js
│   │   ├── Patient.js
│   │   ├── Doctor.js
│   │   └── Appointment.js
│   ├── routes/
│   │   ├── auth.js
│   │   ├── patients.js
│   │   ├── doctors.js
│   │   ├── appointments.js
│   │   └── reports.js
│   ├── .env
│   ├── server.js
│   └── package.json
├── frontend/
│   ├── src/
│   │   ├── components/
│   │   ├── context/
│   │   │   └── AuthContext.jsx
│   │   ├── pages/
│   │   │   ├── Login.jsx
│   │   │   ├── Dashboard.jsx
│   │   │   ├── Patients.jsx
│   │   │   ├── Doctors.jsx
│   │   │   ├── Appointments.jsx
│   │   │   └── Reports.jsx
│   │   ├── services/
│   │   │   └── api.js
│   │   ├── App.jsx
│   │   ├── main.jsx
│   │   └── index.css
│   ├── index.html
│   ├── package.json
│   └── vite.config.js
├── SPEC.md
├── TODO.md
└── README.md
```

## License

MIT
