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.
- Java 21
- Spring Boot 4.0.5
- Spring Web MVC
- Spring Data JPA
- PostgreSQL 17
- Lombok
- Maven
- Docker Compose
src/main/java/com/rahul/practice/hospitalManagement
|-- dto
| `-- BloodGroupCountResponseEntity.java
|-- entity
| |-- Patient.java
| `-- type
| `-- BloodGroupType.java
|-- repository
| `-- PatientRepository.java
|-- service
| `-- PatientService.java
`-- HospitalManagementApplication.java
- 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
The Patient entity currently contains:
idnamebirthDateemailgenderbloodGroupcreatedAtupdatedAt
Database constraints configured on the entity:
- Unique constraint on
name + birthDate - Unique constraint on
email - Index on
birthDate
Supported blood groups:
A_POSITIVEA_NEGATIVEB_POSITIVEB_NEGATIVEAB_POSITIVEAB_NEGATIVEO_POSITIVEO_NEGATIVE
Make sure the following are installed:
- Java 21
- Maven 3.9+ or use the included Maven wrapper
- Docker and Docker Compose
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=alwaysNotes:
- The schema is recreated on every application startup because
spring.jpa.hibernate.ddl-auto=createis enabled. - Seed data is inserted automatically from
data.sql.
Run the database with Docker Compose:
docker compose up -dThis starts a PostgreSQL 17 container with:
- Database:
hospitalManagement - Username:
postgres - Password:
postgres - Port:
5432
The Docker Compose file is available at docker-compose.yaml.
Using the Maven wrapper:
./mvnw spring-boot:runOr with Maven installed globally:
mvn spring-boot:runThe application entry point is HospitalManagementApplication.java.
./mvnw testOn 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
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)
PatientService.java contains a transactional example showing how entity state changes are handled inside a transaction.
Tests are available under src/test/java and currently focus on:
- Spring context loading
- Repository access
- Transaction and pagination behavior
Relevant test files:
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.