Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hospital Management

Hospital Management is a Spring Boot project focused on basic patient data management using Spring Data JPA and PostgreSQL. The current codebase models patients, seeds sample records at startup, and demonstrates common repository patterns such as derived queries, JPQL, native SQL, pagination, and update queries.

Tech Stack

  • Java 21
  • Spring Boot 4.0.5
  • Spring Web MVC
  • Spring Data JPA
  • PostgreSQL 17
  • Lombok
  • Maven
  • Docker Compose

Project Structure

src/main/java/com/rahul/practice/hospitalManagement
|-- dto
|   `-- BloodGroupCountResponseEntity.java
|-- entity
|   |-- Patient.java
|   `-- type
|       `-- BloodGroupType.java
|-- repository
|   `-- PatientRepository.java
|-- service
|   `-- PatientService.java
`-- HospitalManagementApplication.java

Current Features

  • Stores patient records in PostgreSQL
  • Auto-creates the schema at startup with Hibernate
  • Loads sample patient data from src/main/resources/data.sql
  • Supports custom repository methods for querying, pagination, aggregation, and updates
  • Finds patients by name
  • Filters by birth date or email
  • Searches by partial name
  • Queries by blood group
  • Queries patients born after a specific date
  • Counts patients grouped by blood group
  • Supports pagination using a native query
  • Updates a patient name using a JPQL update statement

Patient Model

The Patient entity currently contains:

  • id
  • name
  • birthDate
  • email
  • gender
  • bloodGroup
  • createdAt
  • updatedAt

Database constraints configured on the entity:

  • Unique constraint on name + birthDate
  • Unique constraint on email
  • Index on birthDate

Supported blood groups:

  • A_POSITIVE
  • A_NEGATIVE
  • B_POSITIVE
  • B_NEGATIVE
  • AB_POSITIVE
  • AB_NEGATIVE
  • O_POSITIVE
  • O_NEGATIVE

Prerequisites

Make sure the following are installed:

  • Java 21
  • Maven 3.9+ or use the included Maven wrapper
  • Docker and Docker Compose

Configuration

Application properties are defined in src/main/resources/application.properties.

Default database configuration:

spring.datasource.url=jdbc:postgresql://localhost:5432/hospitalManagement
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
spring.jpa.defer-datasource-initialization=true
spring.sql.init.mode=always

Notes:

  • The schema is recreated on every application startup because spring.jpa.hibernate.ddl-auto=create is enabled.
  • Seed data is inserted automatically from data.sql.

Setup and Run

1. Start PostgreSQL

Run the database with Docker Compose:

docker compose up -d

This starts a PostgreSQL 17 container with:

  • Database: hospitalManagement
  • Username: postgres
  • Password: postgres
  • Port: 5432

The Docker Compose file is available at docker-compose.yaml.

2. Run the application

Using the Maven wrapper:

./mvnw spring-boot:run

Or with Maven installed globally:

mvn spring-boot:run

The application entry point is HospitalManagementApplication.java.

3. Run tests

./mvnw test

Seed Data

On startup, the application inserts sample patient records from src/main/resources/data.sql.

Sample records include patients such as:

  • Aarav Sharma
  • Diya Patel
  • Dishant Verma
  • Neha Iyer
  • Kabir Singh

Repository Capabilities

The main persistence logic lives in PatientRepository.java.

Examples of supported operations:

  • findByName(String name)
  • findByBirthDateOrEmail(LocalDate birthDate, String email)
  • findByNameContainingOrderByIdDesc(String query)
  • findByBloodGroup(BloodGroupType bloodGroup)
  • findByBornAfterDate(LocalDate birthDate)
  • countEachBloodGroupType()
  • findAllPatient(Pageable pageable)
  • updateNameWithId(String name, Long id)

Service Layer

PatientService.java contains a transactional example showing how entity state changes are handled inside a transaction.

Testing

Tests are available under src/test/java and currently focus on:

  • Spring context loading
  • Repository access
  • Transaction and pagination behavior

Relevant test files:

Current Scope

This project currently provides the persistence and service foundation for a hospital management system. It does not yet expose REST controllers or a frontend interface, so it is best described as a backend domain and data-access starter project.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages