A Spring Boot-based Patient Management System designed to efficiently manage patient records and related healthcare information.
The application follows a standard layered architecture with clear separation of concerns:
graph TD
A[Frontend] -->|HTTP POST/GET| B[Controller]
B <-->|DTOs| C[Service]
C <-->|Domain Models| D[Repository]
D <-->|Queries| E[(Database)]
- Java 21 or higher
- Maven 3.6.3 or higher
- PostgreSQL or H2 Database
-
Clone the repository:
git clone https://github.com/yourusername/patient-management.git cd patient-management -
Configure the database:
- Create a new PostgreSQL database
- Update
application.propertieswith your database credentials
-
Build the application:
./mvnw clean install
-
Run the application:
./mvnw spring-boot:run
Once the application is running, you can access:
- Swagger UI: http://localhost:4000/swagger-ui/index.html
- H2 Console (if using H2 in-memory DB): http://localhost:4000/h2-console
-
Controller Layer (
PatientController)- Handles HTTP requests/responses and maps endpoints to service methods.
- Performs input validation using
@Valid.
-
Service Layer (
PatientService)- Contains core business logic and data validation.
- Interacts with the repository and throws custom exceptions for business rule violations.
-
Repository Layer (
PatientRepository)- Extends
JpaRepositoryfor CRUD operations and provides database access methods.
- Extends
-
Exception Handling (
GlobalExceptionHandler)- Uses
@ControllerAdviceto handle exceptions globally, including validation and custom business exceptions.
- Uses
-
Data Transfer Objects (DTOs)
PatientRequestDTO: For receiving patient data.PatientResponseDTO: For sending patient data.
- Endpoint:
POST /patients - Request Body:
PatientRequestDTO - Flow:
- Validates the request.
- Checks if the email already exists and throws
EmailAlreadyExistsExceptionif it does. - Saves the new patient to the database.
- Returns the created patient as a
PatientResponseDTO.
- Endpoint:
GET /patients - Response: A list of
PatientResponseDTO. - Flow:
- Retrieves all patients from the database.
- Maps the entities to DTOs and returns the list.
MethodArgumentNotValidException: Triggered on request validation failure. Returns400 Bad Requestwith field-level errors.EmailAlreadyExistsException: Triggered when creating a patient with a duplicate email. Returns400 Bad Request.
src/main/java/com/company/patientservice/
├── config/ # Configuration classes
├── controller/ # REST controllers
├── dto/ # Data Transfer Objects
├── model/ # Domain models/entities
├── repository/ # Data access layer
├── service/ # Business logic
└── PatientServiceApplication.java # Application entry point
- Build the project:
./mvnw clean install - Run tests:
./mvnw test - Run with custom profile:
./mvnw spring-boot:run -Dspring.profiles.active=dev
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Spring Boot Team
- Open Source Community