On this page:
3.1 Initialization and Connecting Clients
3.2 Appointment Protocol
3.3 Handoff
3.4 Delivery
8.9

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:

  1. Providing clients the means to schedule appointments;

  2. Enforcing appointment reservation timeouts; and

  3. 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:

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:

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.

Functions for querying the availability of appointments with certain characteristics:
  • 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.

Functions for choosing from the provided choices:
  • 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.

Functions for finalizing and booking:
  • 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.

And, finally, functions for querying the state of the process or ending it:
  • 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 an Appointment

  

  An AppointmentEx is a four-element tuple

    {VetInfoEx, Nat, DayEx, Time}

  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] }

  

  A DayEx is one of

   - :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:

Data.

  An AppointmentTimeout is a tuple

    {:appointment_timeout, AppointmentEx}

  describing the appointment in question.

3.3 Handoff

As in milestone 5 (Handoff), the shelter should coordinate with the clinic in the event that a client wishes to adopt an unvaccinated pet. To achieve this purpose, we will modify the signature of the STBU.Interface.PetViewer.try_adopt function. It should now yield one of three possible results:
  • :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 Elixir, Mix) with the behavior described above, and succesfully build (i.e. with mix compile).