I am developing a spring boot MVC REST API for mobile application ,The system is a patient booking in the clinic, I am looking for the best solution to the problem of displaying the available times of the doctor.

problem definition : the system shall allow the user to choose ,clinic , doctor and the specific date(year/month/day) from the calendar and the system shall show the available times for the chooses date , the appointment duration is 30 min and from 7 am to 6 pm .

more clarification : 
The system is consist of many clinics and doctors belong to these clinics , Each doctor has fixed hours for which the user can book. These hours are divided into the dates of each half-hour appointment. Users can not book at the same doctor at the same time . 

example : 
Patient Joey booked an appointment at Doctor x , at 21-may-2018 3:30 ,
another patient jack has opened the application to book an appointment he chooses doctor x and he chooses the same date as joey (21-may-2018) the system shall show times available from 7 am to 6 pm (7 :00 , 7:30 , 8:00 , 8:30 ......)exclude 3:30 . 

Solutions tried : 
1) make a job in the data base that fill the available times every year and mark the time with flag.
2) when the client ask for the available times the system iterate over the all appointments for the doctor and find these times.
3) make a static list with times and dates and when the user ask for the available times iterate over the appointments and remove the times belong to an appointment from the list . 
4) make a database calendar.
5) let the user of the admin page fill the times manually from the admin page. 
i tried all these possible solutions but i did not find them very efficient i am looking for a better solution . 

code sample : 
 controller section:

```
 @RequestMapping(method = RequestMethod.GET , value = "/availabletimes")
public ResponseEntity<ResponseUtil> getAvailableTimes(@RequestParam String date){

    try {
        return new ResponseEntity<ResponseUtil> (new ResponseUtil(200, Constants.SUCCESS_STATUS, "Cancelled", service.getAvailableTimes(date)),HttpStatus.OK);
    }catch (BackendException e) {
        return new ResponseEntity<ResponseUtil> (new ResponseUtil(403, Constants.FAILED_STATUS, e.getMessage(), null),HttpStatus.FORBIDDEN);
    }

}

```

Service implementation : 

```
@Override
public List<String> getAvailableTimes(String date) {
    List<String> availableTimes = findAvailableTimes(date);

    if(availableTimes == null || availableTimes.isEmpty())
        throw new BackendException("No times available for the given date");

    return availableTimes;
}

private List<String> findAvailableTimes(String date){

    //TODO write the logic for findding the available times 
    return null;
}

```

Repository : 

```
 public interface AppointmentRepo extends IRepository<Appointment, Long> {

List<Appointment> findByCustomer(Customer customer);

     }

```

entity : 

```
@Entity
public class Appointment extends BaseEntity {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private Date appoitmentDate;

// Relations
@ManyToOne(fetch = FetchType.LAZY)
private Doctor doctor;
@ManyToOne(fetch = FetchType.LAZY)
private Clinic clinic;
@ManyToOne(fetch = FetchType.LAZY)
private Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
private Follower follower;
@ManyToOne(fetch = FetchType.LAZY)
private AppointmentStatus appointmentStatus;
@OneToOne(fetch = FetchType.LAZY)
private Report report;

// Setters and Getters
public Doctor getDoctor() {
    return doctor;
}

public void setDoctor(Doctor doctor) {
    this.doctor = doctor;
}

public Clinic getClinic() {
    return clinic;
}

public void setClinic(Clinic clinic) {
    this.clinic = clinic;
}

public Customer getCustomer() {
    return customer;
}

public void setCustomer(Customer customer) {
    this.customer = customer;
}

public Follower getFollower() {
    return follower;
}

public void setFollower(Follower follower) {
    this.follower = follower;
}

public Date getAppoitmentDate() {
    return appoitmentDate;
}

public void setAppoitmentDate(Date appoitmentDate) {
    this.appoitmentDate = appoitmentDate;
}

public AppointmentStatus getAppointmentStatus() {
    return appointmentStatus;
}

public void setAppointmentStatus(AppointmentStatus appointmentStatus) {
    this.appointmentStatus = appointmentStatus;
}

public Report getReport() {
    return report;
}

public void setReport(Report report) {
    this.report = report;
}

}

```