Skip to content

Kshitij21092001/Spring_Boot_Hospital_Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hospital Management

A Spring Boot application that models core hospital operations and demonstrates robust persistence-layer design with Spring Data JPA and PostgreSQL. The project manages patients, doctors, departments, appointments, and insurance policies, including their relational mappings and transactional service operations.

Overview

This application provides a foundation for a hospital-management backend. Its current focus is the domain, repository, and service layers; a REST controller layer has not yet been implemented.

Key capabilities include:

  • Patient records with demographic information, blood group, and creation timestamp.
  • Doctor records, specializations, and departmental membership.
  • Department management, including a department head and doctor assignments.
  • Appointment scheduling and reassignment between doctors.
  • One-to-one insurance-policy assignment and removal for patients.
  • Custom patient queries for blood-group reporting, date filtering, search, paging, bulk updates, and appointment retrieval.
  • Database initialization with representative patient, doctor, and appointment data.

Technology Stack

Area Technology
Language Java 17
Framework Spring Boot 3.5.16
Data access Spring Data JPA / Hibernate
Database PostgreSQL
Build tool Maven (Maven Wrapper included)
Boilerplate reduction Lombok
Testing Spring Boot Test / JUnit

Domain Model

Entity Description Main relationships
Patient Stores patient demographic and clinical-reference data. One insurance policy; many appointments.
Insurance Represents a patient's insurance policy. One patient.
Doctor Stores a doctor's name, specialization, and email. Many departments; many appointments.
Department Represents a hospital department. One head doctor; many doctors.
Appointment Records an appointment time and reason. One patient; one doctor.

The Patient entity enforces a unique combination of name and birth date, and uses a string-backed BloodGroupType enum to retain readable blood-group values in the database.

Prerequisites

  • JDK 17 or later
  • PostgreSQL 14 or later
  • A PostgreSQL database named hospitalDB

Configuration

The default development configuration is located in src/main/resources/application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/hospitalDB
spring.datasource.username=postgres
spring.datasource.password=root

Update these values for your local PostgreSQL installation. For shared, staging, or production environments, provide credentials through environment-specific configuration rather than committing them to source control.

The current configuration uses the following development-oriented settings:

spring.jpa.hibernate.ddl-auto=create
spring.sql.init.mode=always

ddl-auto=create recreates the schema each time the application starts. This is appropriate for local development and demonstrations, but it must be replaced with a safe migration strategy before deploying to an environment that contains persistent data.

Getting Started

  1. Create the PostgreSQL database:

    CREATE DATABASE hospitalDB;
  2. Update the datasource settings in src/main/resources/application.properties if your local PostgreSQL username, password, host, or port differs from the defaults.

  3. Start the application from the project root:

    Windows

    mvnw.cmd spring-boot:run

    macOS/Linux

    ./mvnw spring-boot:run

On startup, Hibernate creates the schema and Spring executes src/main/resources/data.sql to load sample patients, doctors, and appointments.

Build and Test

Run the full test suite:

mvnw.cmd test

Build the application artifact:

mvnw.cmd clean package

The packaged application is created under target/ and can be run with:

java -jar target\hospitalManagement-0.0.1-SNAPSHOT.jar

Project Structure

src
├── main
│   ├── java/com/kshitijgaikwad/learnspring/hospitalManagement
│   │   ├── entity/          JPA domain entities and enums
│   │   ├── repository/      Spring Data JPA repositories and custom queries
│   │   ├── service/         Transactional business operations
│   │   ├── dto/             Query response objects
│   │   └── HospitalManagementApplication.java
│   └── resources
│       ├── application.properties
│       └── data.sql         Development seed data
└── test
    └── java/                Application and repository tests

Repository Features

PatientRepository extends JpaRepository and includes derived and JPQL/native queries for common patient workflows:

  • Finding patients by name, birth date, email, date range, or blood group.
  • Returning blood-group counts through BloodGroupCountResponseEntity.
  • Paging patient results with Pageable.
  • Updating a patient's name with a transactional modifying query.
  • Fetching patients with their appointments and associated doctors.

Service Operations

The service layer coordinates entity relationships inside transactions:

  • AppointmentService creates appointments for a selected patient and doctor, and reassigns appointments to another doctor.
  • InsuranceService assigns or removes a patient's insurance policy while maintaining both sides of the one-to-one association.
  • PatientService contains an example of transactional entity retrieval and dirty checking.

Testing

The test suite contains Spring Boot integration tests for application startup, patient persistence, and insurance relationships. Ensure PostgreSQL is running and the datasource configuration is valid before executing the tests.

Current Scope and Next Steps

This repository currently provides the application core and does not include a web API. Typical next steps are:

  1. Add REST controllers and request/response DTOs.
  2. Add input validation and centralized exception handling.
  3. Replace schema recreation with versioned migrations such as Flyway or Liquibase.
  4. Move credentials to environment variables or a secrets manager.
  5. Add authentication, authorization, and API documentation.

License

No license has been specified for this repository. Add a license file before distributing or reusing the project outside its intended context.

About

A Spring Boot application that models core hospital operations and demonstrates robust persistence-layer design with Spring Data JPA and PostgreSQL. The project manages patients, doctors, departments, appointments, and insurance policies, including their relational mappings and transactional service operations.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages