Ignore:
Timestamp:
05/23/26 14:21:13 (4 months ago)
Author:
MBK <marija.karapandzova@…>
Branches:
master
Children:
7e4a5fd
Parents:
0e894d2
Message:

Add functionalities for total sum in billing and generate pdf invoice for a bill

File:
1 edited

Legend:

Unmodified
Added
Removed
  • backend/src/main/java/medora/service/AppointmentService.java

    r0e894d2 ra95bd1b  
    22
    33import medora.models.domain.Appointment;
     4import medora.models.domain.Patient;
    45import medora.models.domain.Doctors;
    5 import medora.models.domain.Patient;
    66import medora.models.enums.AppointmentStatus;
    77import medora.repository.AppointmentRepository;
     8import medora.repository.PatientRepository;
    89import medora.repository.DoctorRepository;
    9 import medora.repository.PatientRepository;
     10
    1011import org.slf4j.Logger;
    1112import org.slf4j.LoggerFactory;
     13
    1214import org.springframework.stereotype.Service;
    1315import org.springframework.transaction.annotation.Transactional;
     
    7981                LocalDateTime.of(appointmentDate, appointmentTime);
    8082
    81 
     83        // Future validation
    8284        if (!appointmentDateTime.isAfter(LocalDateTime.now())) {
    8385            throw new RuntimeException(
     
    8688        }
    8789
     90        // Doctor slot validation
    8891        boolean doctorBusy =
    8992                appointmentRepository
     
    99102        }
    100103
     104        // Duplicate patient validation
    101105        boolean duplicateAppointment =
    102106                appointmentRepository
     
    204208    }
    205209
    206 
    207210    @Transactional(readOnly = true)
    208211    public Optional<Appointment> getAppointmentById(Long appointmentId) {
     
    217220    }
    218221
    219     /**
    220      * Get appointments for patient
    221      */
     222
    222223    @Transactional(readOnly = true)
    223224    public List<Appointment> getAppointmentsForPatient(Long patientId) {
     
    297298        return appointmentRepository.findAll();
    298299    }
     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    }
    299327}
Note: See TracChangeset for help on using the changeset viewer.