# King Faisal Hospital Rwanda — HMS

Online Hospital Appointment and Medical Report Management System.

**Stack:** React.js · Node.js + Express.js · MySQL

## Features

| Module | Receptionist | Doctor |
|--------|:------------:|:------:|
| Register / Login / Logout | ✓ | ✓ |
| Patient CRUD | ✓ | — |
| Appointment management | ✓ | View |
| Medical reports | — | ✓ |
| Date-filtered reports | ✓ | ✓ |

## Project Structure

```
HMSR/
├── backend/          # Express REST API
│   ├── database/     # schema.sql, seed.js
│   ├── routes/
│   └── server.js
└── frontend/         # React SPA
    └── src/pages/
```

## Prerequisites

- Node.js 18+
- MySQL 8+

## Setup

### 1. Database

```bash
mysql -u root -p < backend/database/schema.sql
```

### 2. Backend

```bash
cd backend
copy .env.example .env
```

Edit `.env` with your MySQL password and a JWT secret:

```
DB_PASSWORD=your_mysql_password
JWT_SECRET=change_this_secret_key
```

```bash
npm install
npm run seed
npm start
```

API runs at **http://localhost:5000**

### 3. Frontend

```bash
cd frontend
npm install
npm start
```

App runs at **http://localhost:3000**

## Demo Accounts

| Role | Email | Password |
|------|-------|----------|
| Receptionist | reception@kfh.rw | receptionist123 |
| Doctor | doctor1@kfh.rw | doctor123 |
| Doctor | doctor2@kfh.rw | doctor123 |

## API Endpoints

| Method | Endpoint | Access |
|--------|----------|--------|
| POST | `/api/auth/register` | Public |
| POST | `/api/auth/login` | Public |
| GET | `/api/auth/doctors` | Auth |
| GET/POST/PUT/DELETE | `/api/patients` | Receptionist |
| GET/POST/PUT/PATCH/DELETE | `/api/appointments` | Role-based |
| GET/POST | `/api/medical-reports` | Doctor (POST) |
| GET | `/api/reports/summary?start_date=&end_date=` | Auth |

## Database Tables (ERD)

```mermaid
erDiagram
    users ||--o{ appointments : "doctor_id"
    patients ||--o{ appointments : "patient_id"
    appointments ||--o| medical_reports : "appointment_id"
    users ||--o{ medical_reports : "doctor_id"
    patients ||--o{ medical_reports : "patient_id"

    users {
        int id PK
        string full_name
        string email
        string password
        enum role
    }
    patients {
        int id PK
        string full_name
        enum gender
        date date_of_birth
        string phone_number
        text address
    }
    appointments {
        int id PK
        int patient_id FK
        int doctor_id FK
        date appointment_date
        time appointment_time
        enum status
    }
    medical_reports {
        int id PK
        int appointment_id FK
        int patient_id FK
        int doctor_id FK
        text diagnosis
        text prescription
        date report_date
    }
```

- **users** — receptionists and doctors
- **patients** — patient records
- **appointments** — links patient + doctor, date, time, status
- **medical_reports** — diagnosis, prescription, one per appointment

## License

Academic project — King Faisal Hospital Rwanda scenario.
