On this page:
4.1 Scheduling an Appointment
4.1.1 Calendar Management
4.2 Updated Initialization
4.3 Interfaces
4.4 Testing Task
8.9

4 — Scheduling Veterinary Appointments

Due Monday, 5 February 2024, 11:59:59pm

Delivery Place the product of this week’s milestone into your git repo as follows:

Your project should generate a JAR named Milestone4.jar (see Java, Maven; there is no need to specify a mainClass for this milestone) including the Main and BasicSchedulingClientFactory classes described below. Building the project (such as with mvn package) should put the executable in a folder named target at the top level of your repo.

Purpose

The purpose of this milestone is to implement appointment scheduling for clients at the Husky Animal Lovers Park’s veterinary clinic.

This milestone mimics the behavior the system will need to support clients booking appointments, which may happen simultaenously in person, over the phone, online, etc. When scheduling an appointment, the goal is to find an acceptable vet, day, and time from those available.

4.1 Scheduling an Appointment

The ClinicEntry interface represents the potential interactions between a client and the clinic. Booking an appointment requires finding a suitable day and time for the client’s preferred vet. The client initiates the process by calling the requestAppointment method. The method takes one argument, identifying the pet that this appointment is for.

    ClinicEntry

            Client                                 ClinicEntry

              |                                      |

              |    requestAppointment(AdoptablePet)  |

              |------------------------------------->|

              |           AppointmentScheduler       |

              |<=====================================|

              |                                      |

    

The return value is an instance of the AppointmentScheduler interface. The AppointmentScheduler allows the client to query availability and book the appointment.

Actually booking an appointment entails a combination of several (potential) operations:
  • The client queries the availability of either veterinarians, weeks, days, or times of day.

  • The client can select from the provided choices.

  • If the client has selected a vet, day, and time, they can request to reserve that particular combination while they make a final decision.

  • The client may reset their choices to restart the process.

  • The client may be a tad forgetful, so they may ask for their current selections to be repeated back to them.

  • The client may cancel the process (i.e., hang up the phone).

  • The client may book their reserved choice.

The diagram below depicts a potential interaction between a client and an AppointmentScheduler according to this protocol:

    AppointmentScheduler Protocol

    

            Client                                 AppointmentScheduler

              |                                      |

              |                                      |

              |          availableVets()             |

              |------------------------------------->|

              |            Collection<Vet>           |

              |<=====================================|

              |                                      |

              |                                      |

              |             selectVet(Vet)           |

              |------------------------------------->|

              |               void                   |

              |<=====================================|

              |                                      |

              |                                      |

              |          availableDays()             |

              |------------------------------------->|

              |          Collection<DayOfWeek>       |

              |<=====================================|

              |                                      |

              |                                      |

              |         currentSelection()           |

              |------------------------------------->|

              |         TenativeAppointment          |

              |<=====================================|

              |                                      |

              |                                      |

              |             selectDay(DayOfWeek)     |

              |------------------------------------->|

              |               void                   |

              |<=====================================|

              |                                      |

              |                                      |

              |          availableWeeks()            |

              |------------------------------------->|

              |            Collection<Integer>       |

              |<=====================================|

              |                                      |

              |                                      |

              |             selectWeek(Integer)      |

              |------------------------------------->|

              |               void                   |

              |<=====================================|

              |                                      |

              |                                      |

              |          availableTimes()            |

              |------------------------------------->|

              |          Collection<LocalTime>       |

              |<=====================================|

              |                                      |

              |                                      |

              |          selectTime(LocalTime)       |

              |------------------------------------->|

              |               void                   |

              |<=====================================|

              |                                      |

              |                                      |

              |          finalizeDetails()           |

              |------------------------------------->|

              |                boolean               |

              |<=====================================|

              |                                      |

              |                                      |

              |                book()                |

              |------------------------------------->|

              |             Appointment              |

              |<=====================================|

              |                                      |

              |                                      |

    

Once the client has called selectVet, selectWeek, selectDay, and selectTime, they may reserve that appointment with finalizeDetails. The clinic returns a boolean, indicating whether the client succesfully reserved that particular combination. No other client may book that combination while another client has it reserved. After a successful reservation, the client may call book to make the Appointment.

If the reservation fails, the protocol continues, with the client able to call the query, select, reset, and cancel methods.

Your implementation must account for the following constraints:
  • All queries should reflect the constraints of their current selection. That is, say a client begins by selecting Monday for their appointment. Then, querying for available veterinarians should only return clinicians that have available appointments on a Monday.

  • The client must select a vet, week, day, and time in order to reserve an appointment opening. Moreover, they must reserve an opening before booking the appointment.

  • Once a client has selected a vet, day, and time, no other client should be able to book that appointment slot.

  • One client resetting or canceling the process should allow other clients access to any slots they had reserved.

You may assume that all clients will eventually try to book an appointment or call cancel, call the method in a legal order, and that all selections come from the provided choices.

4.1.1 Calendar Management

The clinic’s operating hours will be 8am to 6pm on weekdays and 9am to 2pm on weekends. Appointments are bookable at every half hour. So, the first and last possible appointment times on a Thursday are 8am and 5:30pm, while on a Sunday they are 9am and 1:30pm.

The center books appointments up to four weeks in advance. That is, appointments may be booked for the current week plus the three following.

For our purposes, we will simply consider any day in the future as a combination of a DayOfWeek as well as a week—represented as an integer offset from the present one. We will use Java’s LocalTime to represent a time on that day.

4.2 Updated Initialization

The ClientEntry interface will now take a Consumer<CenterEntry>; see the attached interfaces. Extend your com.neu.halp.center.Main.initialize method to return an instance of the updated interface.

Extend your com.neu.halp.center.Main class with a method that has the following signature:

    public static ClinicClientEntry initializeClinic(Reader configReader) {

      ...

    }

The interaces archive below has been updated accordingly, including with the ClinicClientEntry

4.3 Interfaces

Place the attached interfaces (updated 2/2/24) in the designated package(s) in your project. Do not modify them.

4.4 Testing Task

To aid in testing, implement (at least one) potential client scheduling behavior. The behavior will be parameterized over preference functions (i.e., sorting) for each aspect of an appointment. For each aspect of the appointment, the client should:
  • Query the availability;

  • Use the provided preference function to select the most desirable (i.e., least) option.

  • If there is no availability (the returned Collection is empty), the Client cancels the process.

The client should begin by querying/selecting a vet, then week, then day, then time. Once they have selected each, they should finalize and then (if successful) book the Appointment. (If finalizing fails, the client cancels the process.)

Implementation Task

Implement the com.neu.halp.test.BasicSchedulingClientFactory class. The class must include the following public methods: }

public BasicSchedulingClientFactory() {

  ...

}

 

public BasicSchedulingClient newClient(AdoptablePet pet,

                                       Function<Collection<Vet>,Collection<Vet>> vetPreference,

                                       Function<Collection<Integer>,Collection<Integer>> weekPreference,

                                       Function<Collection<DayOfWeek>,Collection<DayOfWeek>> dayPreference,

                                       Function<Collection<LocalTime>,Collection<LocalTime>> timePreference) {

  ...

}

Interface

The BasicSchedulingClient interface defines two methods:
  • getFinished, reporting a boolean that returns true if the client is finished running; and

  • getResult, returning an Optional<Appointment> describing either the appointment the client booked, or is empty if they were unable to.