The Hospital Management System is a secure RESTful backend built with Spring Boot to manage hospital operations including patients, doctors, pharmacies, and administrators.
It implements role-based access control, secure messaging (doctor–patient only), and CRUD features for hospital workflows.
- Admin → Manage all accounts (doctor, patient, pharmacy).
- Doctor → Manage patients, assign prescriptions, message patients.
- Patient → Register, book appointments, message doctor, buy medicines.
- Pharmacy → Manage medicine inventory.
- 🔑 JWT-based authentication & authorization
- 📅 Appointment booking & management
- 💊 Prescription and medicine management
- 💬 Secure doctor–patient messaging (non real-time)
- 🧾 Medicine orders & pharmacy stock control
- ⚙️ Role-based access restrictions
- Backend: Spring Boot (Web, JPA, Security, Validation, Lombok)
- Database: MySQL (H2 for tests)
- Auth: Spring Security + JWT
- Build: Maven
- Testing: JUnit 5 + Mockito
- Deployment: Docker & Docker Compose
Hospital-System/
│── ERD/ # ERD diagram
│── logs/ # Application logs
│── src/
│ ├── main/
│ │ ├── java/com/example/Hospital_System/
│ │ │ ├── config/ # SecurityConfig (Spring Security configuration)
│ │ │ ├── controller/ # REST Controllers
│ │ │ ├── dto/ # Data Transfer Objects
│ │ │ ├── exception/ # Custom exceptions
│ │ │ ├── mapper/ # Entity <-> DTO mappers
│ │ │ ├── model/ # JPA Entities
│ │ │ ├── repository/ # Spring Data JPA Repositories
│ │ │ ├── response/ # Response wrappers (e.g., ErrorResponse)
│ │ │ ├── security/ # JWT filters, utils
│ │ │ ├── service/ # Business logic services
│ │ │ └── HospitalSystemApplication.java
│ │ └── resources/ # application.properties & configs
│ └── test/ # Unit & Integration tests
│── Dockerfile # Docker image config
│── docker-compose.yml # Multi-service setup
│── pom.xml # Maven dependencies
- Java 17+
- Maven 3+
- MySQL 8+
- IDE (IntelliJ IDEA, Eclipse, or VS Code)
- Docker & Docker Compose (optional for containerization)
git clone https://github.com/IsraaXx/Hospital-System-Backend.git
cd Hospital-System-Backendsrc/main/resources/application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/Hospital_System
spring.datasource.username= USERNAME
spring.datasource.password= PASSWORD
mvn clean install
mvn spring-boot:runPOST /auth/register→ Register new userPOST /auth/login→ Login & receive JWT
GET /doctors/{doctorId}/patients→ View all doctor patientsPOST /doctor/prescriptions→ Assign prescriptionPOST /doctors/appointments/follow-up→ Add follow up notesGET /doctors/{doctorId}/patients/{patientId}/history→ View patient history with that doctor
POST /patient/doctors/schedules→ get Available Doctor SchedulesPOST /patient/medicines→ get Available Medicines
POST /pharmacy/pharmacy{Id}/medicines→ Add medicineGET /pharmacy/pharmacy{Id}/medicines→ List medicinesGET /pharmacy/pharmacy{Id}/medicines/medicine{Id}→ get medicine by idPut /pharmacy/pharmacy{Id}/medicines/medicine{Id}→ update medicine by idPatch /pharmacy/pharmacy{Id}/medicines/medicine{Id}/stock→ update medicine stock by idDelete /pharmacy/pharmacy{Id}/medicines/medicine{Id}→ delete medicine by id
POST /messages→ Send message (doctor ↔ patient only)GET /messages/conversation?userAId=1&userBId=2→ Get conversation
POST /appointments→ Book a new appointmentGET /appointments?doctorId={doctorId}&start={startDateTime}&end={endDateTime}→ List a doctor’s appointments in a given time windowPATCH /appointments/{appointmentId}/cancel→ Cancel an existing appointment
Run all unit & integration tests:
mvn test- Uses JUnit 5 + Mockito
- In-memory H2 database for fast testing
docker build -t hospital-system .docker-compose up --build