Skip to content

IsraaXx/Hospital-System-Backend

Repository files navigation

๐Ÿฅ Hospital Management System (Spring Boot)

๐Ÿ“Œ Overview

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.


๐Ÿ‘ฅ Roles

  • 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.

โœจ Features

  • ๐Ÿ”‘ 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

๐Ÿ›  Tech Stack

  • 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

๐Ÿ“‚ Project Structure

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

โš™๏ธ Setup & Installation

โœ… Prerequisites

  • Java 17+
  • Maven 3+
  • MySQL 8+
  • IDE (IntelliJ IDEA, Eclipse, or VS Code)
  • Docker & Docker Compose (optional for containerization)

1๏ธโƒฃ Clone the project

git clone https://github.com/IsraaXx/Hospital-System-Backend.git
cd Hospital-System-Backend

2๏ธโƒฃ Configure Database

src/main/resources/application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/Hospital_System
spring.datasource.username= USERNAME
spring.datasource.password= PASSWORD

3๏ธโƒฃ Build & Run

mvn clean install
mvn spring-boot:run

๐Ÿ“Œ API Endpoints

๐Ÿ”‘ Authentication

  • POST /auth/register → Register new user
  • POST /auth/login → Login & receive JWT

๐Ÿ‘จ‍โš•๏ธ Doctor

  • GET /doctors/{doctorId}/patients → View all doctor patients
  • POST /doctor/prescriptions → Assign prescription
  • POST /doctors/appointments/follow-up → Add follow up notes
  • GET /doctors/{doctorId}/patients/{patientId}/history → View patient history with that doctor

๐Ÿง‘‍๐Ÿค‍๐Ÿง‘ Patient

  • POST /patient/doctors/schedules → get Available Doctor Schedules
  • POST /patient/medicines → get Available Medicines

๐Ÿ’Š Pharmacy

  • POST /pharmacy/pharmacy{Id}/medicines → Add medicine
  • GET /pharmacy/pharmacy{Id}/medicines → List medicines
  • GET /pharmacy/pharmacy{Id}/medicines/medicine{Id} → get medicine by id
  • Put /pharmacy/pharmacy{Id}/medicines/medicine{Id} → update medicine by id
  • Patch /pharmacy/pharmacy{Id}/medicines/medicine{Id}/stock → update medicine stock by id
  • Delete /pharmacy/pharmacy{Id}/medicines/medicine{Id} → delete medicine by id

๐Ÿ’ฌ Messaging

  • POST /messages → Send message (doctor ↔ patient only)
  • GET /messages/conversation?userAId=1&userBId=2 → Get conversation

๐Ÿ“… Appointments

  • POST /appointments → Book a new appointment
  • GET /appointments?doctorId={doctorId}&start={startDateTime}&end={endDateTime}→ List a doctor’s appointments in a given time window
  • PATCH /appointments/{appointmentId}/cancel → Cancel an existing appointment

๐Ÿงช Testing

Run all unit & integration tests:

mvn test
  • Uses JUnit 5 + Mockito
  • In-memory H2 database for fast testing

๐Ÿณ Docker & Deployment

Build Docker Image

docker build -t hospital-system .

Run with Docker Compose

docker-compose up --build

๐Ÿ“Š ERD

Hospital ERD

About

Graduation training project at Banque Misr. Our team developed a backend Hospital Management System using Spring Boot, with secure role-based access, doctor & patient management, pharmacy & medicine modules, appointment scheduling, and prescription handling. The system also includes extensive unit/integration tests, Docker support, and logging.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors