E3 — Appointments, Take 2
Due Saturday, 6 April 2024, 11:59:59pm.
Purpose The purpose of this milestone is to implement (most of) the clinic side of the STBU center in Elixir.
Programming Task
This milestone calls for implementing three major pieces of the animal shelter functionality:
Providing clients the means to schedule appointments;
Enforcing appointment reservation timeouts; and
Coordinating between the shelter and clinic.
3.1 Initialization and Connecting Clients
Implement the module STBU.Interface.Entry with (at least) the following public functions:
initialize_shelter_and_clinic/2. The function takes two arguments. The first is an io_device from which a JSON Configuration may be read. The second is a natural number specifying the number of milliseconds a client may play with a pet or reserve an appointment slot before incurring a timeout (c.f. Dawdling Clients).
You have the option to register a name for your clinic and shelter process, in which case initialize_shelter/2 may return that name (atom).
The function should return a tuple of two PIDs, the first for communicating with the shelter and the second for the clinic. Clients will use the PIDs as the starting point of their interactions (see below).
A client may use the returned "clinic" PID to either initiate the appointment protocol. For this purpose, implement the module STBU.Interface.Clinic with (at least) the following public functions:
request_appointment/2. The function’s first is the address of the "clinic." The second argument is a PetView representing the intended patient of the appointment. The return value is the PID of an "appointment scheduler" process that the client may then interact with according to the appointment protocol below. The identity (PID) of the "client" is the process calling the function.
3.2 Appointment Protocol
The logical structure of the adoption protocol mirrors that of milestone 4 (Scheduling an Appointment), with some minor alterations to the data to accomodate the new setting. The client-facing interface will be provided by the module STBU.Interface.AppointmentScheduler, in which you will implement (at least) the following public functions.
The first argument to each of the functions in this section is the address of the appointment scheduler process.
available_vets/1. The function returns a list of (distinct) VetInfoEx, representing the same information as in milestone 4.
available_weeks/1. Like available_vets/1, this function should return a list of integers representing available weeks consistent with the client’s current selection.
available_days/1. Like available_vets/1, this function should return a list of DayEx representing available days consistent with the client’s current selection.
available_times/1. Like available_vets/1, this function should return a list of Times representing available times consistent with the client’s current selection.
select_vet/2. The second argument is the VetInfoEx the client wishes to select. The function need not return any particular kind of value.
select_week/2. Like select_vet/2, but taking an integer representing a week as the second argument.
select_day/2. Like select_vet/2, but taking a DayEx as the second argument.
select_time/2. Like select_vet/2, but taking a Time as the second argument.
finalize_details/1. Attempts to reserve an appointment with the selected choices. The function should return :ok if successful and :error otherwise.
book/1. After successfully finalizing an appointment, the client can book their appointment. The function should return :ok if successful and :error otherwise.
current_selection/1. The function should return a tuple similar to an AppointmentEx, with nil in place of each unselected item.
reset/1. The function releases any reserved but un-booked appointment and selected appointment choices. It need not return a value of any particular type.
cancel/1. The function releases any reserved but un-booked appointment and ends the protocol. It need not return a value of any particular type.
|
representing the vet, week, day, and time of an appointment. |
|
A VetInfoEx is a map with (at least) the following keps associated to |
values of the corresponding type: |
%{ :name => String, |
:specialties => [String] } |
|
- :M |
- :Tu |
- :W |
- :Th |
- :F |
- :Sa |
- :Su |
|
A Time is an instance of the %Time{} struct. |
|
Timeouts.
In the event of a client failing to book an appointment after finalizing its details within the specified time limit, they should lose the reservation and receive an AppointmentTimeout message:
{:appointment_timeout, AppointmentEx} |
describing the appointment in question. |
3.3 Handoff
:ok, in the event of the successful adoption of an already-vaccinated pet;
:error, in the event of an unsuccessful adoption; or
{:schedule, pid}, prompting the client to schedule an appointment at the clinic to complete the adoption. The provided PID is the address of an appointment scheduler process that the client may use.
If the client successfully schedules an appointment within the allotted amount of time, they should receive a message of the format {:adopted, PetView}. Otherwise, they should receive a message {:adoption_failed, PetView}.
3.4 Delivery
Your project should include the designated modules under the lib directory
(see —