- Timestamp:
- 05/23/26 14:21:13 (4 months ago)
- Branches:
- master
- Children:
- 7e4a5fd
- Parents:
- 0e894d2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
backend/src/main/java/medora/service/AppointmentService.java
r0e894d2 ra95bd1b 2 2 3 3 import medora.models.domain.Appointment; 4 import medora.models.domain.Patient; 4 5 import medora.models.domain.Doctors; 5 import medora.models.domain.Patient;6 6 import medora.models.enums.AppointmentStatus; 7 7 import medora.repository.AppointmentRepository; 8 import medora.repository.PatientRepository; 8 9 import medora.repository.DoctorRepository; 9 import medora.repository.PatientRepository; 10 10 11 import org.slf4j.Logger; 11 12 import org.slf4j.LoggerFactory; 13 12 14 import org.springframework.stereotype.Service; 13 15 import org.springframework.transaction.annotation.Transactional; … … 79 81 LocalDateTime.of(appointmentDate, appointmentTime); 80 82 81 83 // Future validation 82 84 if (!appointmentDateTime.isAfter(LocalDateTime.now())) { 83 85 throw new RuntimeException( … … 86 88 } 87 89 90 // Doctor slot validation 88 91 boolean doctorBusy = 89 92 appointmentRepository … … 99 102 } 100 103 104 // Duplicate patient validation 101 105 boolean duplicateAppointment = 102 106 appointmentRepository … … 204 208 } 205 209 206 207 210 @Transactional(readOnly = true) 208 211 public Optional<Appointment> getAppointmentById(Long appointmentId) { … … 217 220 } 218 221 219 /** 220 * Get appointments for patient 221 */ 222 222 223 @Transactional(readOnly = true) 223 224 public List<Appointment> getAppointmentsForPatient(Long patientId) { … … 297 298 return appointmentRepository.findAll(); 298 299 } 300 301 302 public LocalTime findNextAvailableSlot(Long doctorId, LocalDate appointmentDate) { 303 LocalTime[] timeSlots = { 304 LocalTime.of(9, 0), 305 LocalTime.of(10, 0), 306 LocalTime.of(11, 0), 307 LocalTime.of(13, 0), 308 LocalTime.of(14, 0), 309 LocalTime.of(15, 0), 310 LocalTime.of(16, 0) 311 }; 312 313 for (LocalTime timeSlot : timeSlots) { 314 boolean isBooked = appointmentRepository 315 .existsByDoctorDoctorIdAndAppointmentDateAndAppointmentTimeAndStatusNot( 316 doctorId, 317 appointmentDate, 318 timeSlot, 319 AppointmentStatus.CANCELLED 320 ); 321 if (!isBooked) { 322 return timeSlot; 323 } 324 } 325 return null; 326 } 299 327 }
Note:
See TracChangeset
for help on using the changeset viewer.
