A comprehensive full-stack hospital management system built with Spring Boot and React, featuring appointment scheduling, patient records, payment processing, and administrative reporting with comprehensive unit testing coverage.
- Project Overview
- Features
- Technical Architecture
- Unit Testing
- Prerequisites
- Installation & Setup
- Running the Application
- API Documentation
- SOLID Principles
- Team Information
MediWay is a modern healthcare management platform that digitizes hospital operations, providing seamless integration between patients, doctors, and administrators. The system ensures secure, efficient healthcare service delivery with real-time appointment management, comprehensive medical records, and integrated payment processing.
Key Capabilities:
- Appointment Management: Intelligent scheduling with concurrency control
- Patient Records: Complete medical history with secure access controls
- Payment Integration: PayPal sandbox integration with receipt generation
- Administrative Dashboard: Real-time analytics and reporting
- Role-Based Security: Multi-level access control for different user types
- Doctor Availability Management: Real-time schedule tracking and updates
- Intelligent Booking: Date/time validation with conflict prevention
- Concurrency Control: Prevents double-booking through optimistic locking
- Status Tracking: SCHEDULED β COMPLETED β CANCELLED workflow
- Real-time Updates: Instant status synchronization across the platform
- Comprehensive Medical Records: CRUD operations for diagnoses and treatments
- Patient Profiles: Emergency contacts, medical history, and personal information
- QR Code Integration: Digital patient identification and quick access
- Secure Access: Role-based permissions for patient data
- PayPal Integration: Sandbox environment for secure transactions
- Receipt Generation: PDF receipts with QR codes and transaction details
- Payment Tracking: PENDING β COMPLETED β FAILED status management
- Appointment Linking: Automatic status updates upon payment completion
- Statistical Reports: Monthly revenue, appointment analytics, and performance metrics
- Export Capabilities: PDF and CSV report generation
- User Management: CRUD operations for doctors and patients
- System Monitoring: Real-time dashboard with key performance indicators
- Spring Boot 3.4.10: Enterprise-grade Java framework
- Java 17: Modern JVM with enhanced performance and security
- Maven: Dependency management and build automation
- MySQL 8.0: Relational database with ACID compliance
- Spring Data JPA: Object-relational mapping with Hibernate
- Database Schema: Normalized design with foreign key relationships
- Spring Security: Comprehensive security framework
- JWT Tokens: Stateless authentication with role-based access control
- BCrypt: Password hashing for secure credential storage
- PayPal REST SDK: Official PayPal API integration
- Dual Mode Support: Production and sandbox environments
- Webhook Handling: Real-time payment status updates
- ZXing: QR code generation and scanning
- iText 7: PDF document generation
- Jackson: JSON processing and serialization
- Mockito: Testing framework for unit and integration tests
- React 18: Modern component-based UI framework
- Vite: Fast build tool with hot module replacement
- Material-UI: Consistent design system components
- React Context: Global state management for user sessions
- Axios: HTTP client for API communication
- React Router: Client-side routing and navigation
- Docker: Multi-stage builds for optimized images
- Docker Compose: Orchestration for multi-service deployments
- Ngrok: Secure tunneling for webhook development
- GitHub Actions: CI/CD pipeline automation
- JaCoCo: Code coverage analysis and reporting
-- Core Entities
Users (id, email, password, role, profile_data)
Doctors (id, user_id, specialization, availability)
Patients (id, user_id, health_id, medical_history)
Appointments (id, patient_id, doctor_id, date_time, status)
Medical_Records (id, patient_id, doctor_id, diagnosis, treatment)
Payments (id, appointment_id, amount, status, paypal_payment_id)
Receipts (id, payment_id, receipt_number, pdf_content)| Component | Coverage | Test Count | Status |
|---|---|---|---|
| Overall | 82% | 472+ | β |
| Controllers | 85% | 230+ | β |
| Services | 88% | 120+ | β |
| Entities | 81% | 65+ | β |
| Repositories | 95% | 35+ | β |
| Security | 90% | 25+ | β |
- @Test: Unit test annotations
- @DisplayName: Descriptive test names
- @BeforeEach/@AfterEach: Test lifecycle management
- Assertions: Comprehensive assertion library
- @Mock: Dependency mocking
- @InjectMocks: Service injection for testing
- when().thenReturn(): Method stubbing
- verify(): Interaction verification
- @SpringBootTest: Integration testing
- @WebMvcTest: Controller testing
- @DataJpaTest: Repository testing
- MockMvc: HTTP endpoint testing
- Valid input scenarios
- Successful operations
- Expected behavior validation
- Invalid input handling
- Error condition management
- Exception scenarios
- Boundary conditions
- Null/empty values
- Concurrency scenarios
cd backend
./mvnw clean testAppointment System:
./mvnw test -Dtest="AppointmentServiceTest,SimpleAppointmentControllerTest"
# 15 service tests + 26 controller tests = 41 testsAdmin & Reports:
./mvnw test -Dtest="AdminServiceTest,AdminControllerTest,SimpleReportsControllerTest,ReportsServiceTest"
# 21 + 10 + 35 + 20 = 86 testsMedical Records:
./mvnw test -Dtest="MedicalRecordServiceTest,MedicalRecordControllerTest,SimpleMedicalRecordControllerTest,SimpleProfileControllerTest,QRCodeServiceTest"
# 20 + 28 + 15 + 30 + 6 = 99 testsPayment System:
./mvnw test -Dtest="SimplePayPalControllerTest,ReceiptControllerTest"
# 29 + 30 = 59 tests./mvnw clean test jacoco:report
# View: backend/target/site/jacoco/index.html@SpringBootTest
class AppointmentServiceTest {
@Mock
private AppointmentRepository appointmentRepository;
@InjectMocks
private AppointmentService appointmentService;
@Test
@DisplayName("Positive: Successfully create appointment with available doctor")
void testCreateAppointment_Success() {
// Given
when(appointmentRepository.save(any())).thenReturn(testAppointment);
// When
Appointment result = appointmentService.createAppointment(request);
// Then
assertNotNull(result);
assertEquals(Appointment.Status.SCHEDULED, result.getStatus());
verify(appointmentRepository).save(any());
}
}@Test
@DisplayName("Edge: Prevent double booking with concurrent requests")
void testCreateAppointment_ConcurrencyControl() {
// Simulates race condition scenario
// Ensures only one appointment is created
}@Test
@DisplayName("Positive: Create PayPal payment successfully")
void testCreatePayment_Success() {
// Tests PayPal SDK integration
// Verifies payment record creation
// Validates approval URL generation
}@Test
@DisplayName("Negative: Access denied for unauthorized user")
void testAccessControl_UnauthorizedAccess() {
// Tests role-based access control
// Verifies proper exception handling
}- Java Development Kit: JDK 17 or higher
- Node.js: Version 18+ with npm
- MySQL: Version 8.0 or higher
- Maven: Version 3.8+ (included wrapper available)
- Git: Version control system
- Ngrok: For PayPal webhook tunneling
- Docker: Optional, for containerized deployment
-
Database Setup
CREATE DATABASE mediwaydb; CREATE USER 'mediway_user'@'localhost' IDENTIFIED BY 'mediway_password'; GRANT ALL PRIVILEGES ON mediwaydb.* TO 'mediway_user'@'localhost'; FLUSH PRIVILEGES;
-
Application Properties
# Database spring.datasource.url=jdbc:mysql://localhost:3306/mediwaydb spring.datasource.username=mediway_user spring.datasource.password=mediway_password # JPA spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true # Server server.port=8080 # PayPal (Sandbox) paypal.mode=sandbox paypal.client.id=YOUR_SANDBOX_CLIENT_ID paypal.client.secret=YOUR_SANDBOX_CLIENT_SECRET paypal.use-simulated-checkout=true
-
Database Initialization
cd backend mysql -u mediway_user -p mediwaydb < scripts/complete-setup.sql mysql -u mediway_user -p mediwaydb < scripts/setup_admin_doctor_accounts.sql
-
Environment Setup
cd frontend npm install -
Environment Variables
VITE_API_BASE_URL=http://localhost:8080 VITE_PAYPAL_CLIENT_ID=YOUR_SANDBOX_CLIENT_ID
# Install ngrok and start tunnel
ngrok http 5173
# Update PayPal return URLs in application.properties
paypal.return.url=https://your-ngrok-id.ngrok.io/paypal-success
paypal.cancel.url=https://your-ngrok-id.ngrok.io/paypal-cancelBackend:
cd backend
./mvnw spring-boot:run
# Access: http://localhost:8080Frontend:
cd frontend
npm run dev
# Access: http://localhost:5173Ngrok (for PayPal):
ngrok http 5173
# Public URL: https://your-ngrok-id.ngrok.ioBackend:
cd backend
./mvnw clean package -DskipTests
java -jar target/mediway-1.0.0.jarFrontend:
cd frontend
npm run build
# Serve static files from dist/# Build and run with Docker Compose
docker-compose up --buildPOST /api/auth/register # User registration
POST /api/auth/login # User authentication
POST /api/auth/logout # Session terminationGET /api/appointments # List appointments
POST /api/appointments # Create appointment
GET /api/appointments/{id} # Get appointment details
PUT /api/appointments/{id} # Update appointment
DELETE /api/appointments/{id} # Cancel appointment
GET /api/appointments/doctor/{id} # Doctor's appointmentsGET /api/medical-records/patient/{id} # Patient records
POST /api/medical-records # Create record
PUT /api/medical-records/{id} # Update record
DELETE /api/medical-records/{id} # Delete recordPOST /paypal/create # Initiate payment
POST /paypal/execute # Complete payment
POST /paypal/execute-token # Token-based execution
GET /paypal/my-payments # User payments
GET /paypal/receipts/my-receipts # User receiptsGET /admin/users # User management
GET /admin/doctors # Doctor management
GET /admin/appointments # Appointment oversight
GET /api/reports/dashboard # System analytics
GET /api/reports/monthly-revenue/pdf # Revenue reports{
"success": true,
"data": { ... },
"message": "Operation completed",
"timestamp": "2025-10-25T10:00:00Z"
}Each class has one primary responsibility and reason to change.
Examples:
AppointmentService: Handles only appointment business logicQRCodeService: Manages only QR code generationReportsService: Focuses solely on report generation
Software entities should be open for extension but closed for modification.
Examples:
AppointmentStatusenum extensible without code changes- Payment method interfaces allow new providers
- User roles can be extended via configuration
Subtypes must be substitutable for their base types.
Examples:
- All repository implementations work with
JpaRepositoryinterface - Service implementations interchangeable through dependency injection
- Mock repositories in tests behave identically to real ones
Clients should not be forced to depend on interfaces they don't use.
Examples:
- Separate
CrudOperationsandReportGeneratorinterfaces - Focused repository interfaces per entity
- Service-specific interfaces instead of monolithic contracts
High-level modules should not depend on low-level modules.
Examples:
- Controllers depend on service interfaces, not implementations
- Services depend on repository abstractions
- Dependency injection enables loose coupling
Course: Web Engineering (WE20)
Year: Year 3, Semester 1
Institution: University of Colombo School of Computing
Repository: https://github.com/Y3S1-WE20/MediWay
Member 1 - Appointment Scheduling
- Appointment booking system with concurrency control
- Real-time availability management
- Status tracking and validation
Member 2 - Admin & Reporting
- User and doctor management
- Statistical dashboard and analytics
- PDF/CSV report generation
Member 3 - Medical Records
- Patient profile management
- Medical history tracking
- QR code integration
Member 4 - Payment Processing
- PayPal integration and sandbox testing
- Receipt generation and management
- Transaction status tracking
- Total Test Cases: 472+
- Code Coverage: 82% branch coverage
- API Endpoints: 35+ REST endpoints
- Database Tables: 12 core entities
- User Roles: Admin, Doctor, Patient
- Payment Methods: PayPal (Sandbox + Production)
Database Connection:
# Verify MySQL service
mysql --version
mysql -u root -p -e "SHOW DATABASES;"Port Conflicts:
# Windows
netstat -ano | findstr :8080
taskkill /PID <PID> /F
# Linux/Mac
lsof -ti:8080 | xargs kill -9Build Issues:
# Clear Maven cache
./mvnw dependency:purge-local-repository
./mvnw clean install -ULast Updated: October 25, 2025
Version: 1.0.0
Status: Production Ready