We will redesign the patient scheduling system making better use of interfaces, using classes and interfaces from the Java Collections Framework, and assigning patient ids to all patients, and doctor ids to all doctors.

a) Create a new base package, as edu.miami.cis324.hw3.XXXX, where XXXX is your username without the dot, i.e., j.does package should be edu.miami.cis324.hw3.jdoe.

b) Use the SchedulePatientsCollectionsTest class provided in this assignment as the main class in your Java application (i.e., the class that will contain the main method). Note that the class has a call run() method: all work should be done inside this method.

Note also that the SchedulePatientsCollectionsTest class contains two two--dimensional String arrays. These will be used to initialize your data.

c) Define a Patient interface. This interface must define methods to access (but not modify):

  • Patient id
  • last name
  • first name
  • SSN
  • date of birth (as a java.util.Date object)
  • age

d) Create an enum called MedicalSpecialty listing medical specialties, similar to Assignment #1. Include GENERAL_MEDICINE, PEDIATRICS, and ONCOLOGY as members of this enumeration.

e) Inside the MedicalSpecialty enum, define a method called getFromString that takes a String parameter and returns a MedicalSpecialty with the same name as the String parameter. Hint: use the toString() method from the MedicalSpecialty enum to perform your checks.

f) Define a Doctor interface. At a minimum, this interface must define methods to access (but not modify):

  • Doctor id
  • last name
  • first name
  • specialty (use the enum defined in step e)).

g) Create a PatientImpl class as implementation of the Patient interface. Note that this implementation class must NOT define modifier methods (setters): it is to be an immutable class. It must define a constructor that takes as arguments the full name, SSN, and date of birth.

a. The full name is given as in the patientArray array. Note that getters are needed for last name and first name separately.

b. The date of birth argument must be passed in as a java.util.Date.

c. Override the equals method for this class in order to say that two objects are the same if they have the same id, last name, first name, SSN, and date of birth. Do not forget to override hashCode.

h) Create a DoctorImpl class as implementation of the Doctor interface. Note that this implementation class must NOT define modifier methods (setters): it is to be an immutable class. It must define a constructor that takes as arguments the full name, SSN, date of birth, and specialty.

a. The full name is given as in the doctorArray array. Note that getters are needed for last name and first name separately.

b. The date of birth argument must be passed in as a java.util.Date.

c. The specialty should be converted from the String representation to a MedicalSpecialty object using the method you defined in the MedicalSpecialty enum.

d. Override the equals method for this class in order to say that two objects are the same if they have the same id, last name, first name, SSN, date of birth, and specialty. Do not forget to override hashCode.

i) Create a generic Visit interface, where the generic type parameter V represents a visitor and generic type parameter T represents a host. Define methods in the interface to:

a. Get the visitor

b. Get the host

c. Get the date of the visit.

j) Create a generic VisitImpl class, implementing all the methods of the Visit interface, and additionally providing a constructor that initializes the visitor, the host, and the date of the visit.

a. Override the equals method for this class in order to say that two objects are the same if they have the same visitor, the same host, and the same date. Do not forget to override hashCode.

k) In the run() method in class SchedulePatientsCollectionsTest:

a. Create a Collection of Patient objects and a collection of Doctor objects, and fill these sets with the data provided in the patientArray and doctorArray arrays, respectively.

i. You must use the Java Collections Framework to define the collections. Choose whether lists or sets are a better implementation, and justify your selection with a comment next to where the collections are created.

ii. Be sure to use the Patient and Doctor interfaces and not the implementation classes to define the objects.

iii. When filling the Patient objects, insert an integer identifier field called patientId for all patients (remember, doctors can also be patients), and provide an integer value to each patient starting at 1.

iv. Filling the Doctor objects, insert an integer identifier field called doctorId for all doctors, and provide an integer value to each doctor starting at1.

b. Create a collection of Visit objects relating Patient objects to Doctor objects, using the following table of data:

Patient Doctor Date
John Lennon John Smith 11 Nov 2014
John Lennon John Smith 11 Nov 2014
Ringo Starr Jane Doe 14 Nov 2014
Jane Doe John Smith 11 Nov 2014
Paul McCartney Mary Jones 09 Nov 2014
George Harrison Beth Garcia 09 Nov 2014
Beth Garcia John Smith 13 Nov 2014
George Harrison Jane Doe 13 Nov 2014

c. Then, use this collection of visits to print all upcoming visits by doctor, with the doctors ordered by last name and the visits ordered by date, only for doctors with the specialty of GENERAL_MEDICINE, to the console output, in the following format (note that the doctors name and specialty should only be listed once, and then all upcoming visits for the doctor):

Doctor: John Smith
Specialty: GENERAL_MEDICINE
Upcoming visits:
Visit date: 2014/11/11
First name: George
Last name: Harrison
SSN: 567-39-9282
Age: 58

i. Sort the collection of Doctor objects created in step a as a multi--step comparison, first by last name, then by first name, then by date of birth, and then by SSN (Implement Comparable< T> on the Doctor class.)

ii. Sort the collection of Visit< Patient, Doctor> objects by date, using an external Comparator< T> implementation. Note: do not use Comparable on the Visit class, as a comparison based solely on date would not be consistent with equals.

iii. Iterate through the sorted Doctor object collection.

iv. For each doctor, look up all visits corresponding to the doctor within the collection of Visit< Patient, Doctor> objects.

d. Write out a line separator using System.out.println(----------------------------------------); Then, list all upcoming visits by patient, only for patients that actually have an upcoming visit, to the console output, in the following format (note that the patient name should only be listed once, and then all the visits for each patient):

Patient Name: Harrison, George
SSN: 567-39-9282
Age: 58
Upcoming visits:
Visit date: 11 November 2014
Doctor: John Smith
Specialty: GENERAL_MEDICINE

Leave a blank line between visits.

e. Create a collection of Visit< Integer,Integer> objects, with the same data as before, but this time relating patient ids to doctor ids (instead of using the whole patient and doctor objects).

f. Create a patientIdMap object that maps the integer patientIds to the patient objects.

g. Create a doctorIdMap object that maps the integer doctorIds to the doctor objects.

h. Write out a line separator using System.out.println(------------------------------------------);

i. Print all upcoming visits to the console output ordered by visit date. The listing must be done with the Visit< Integer,Integer> object that relates patient Ids to doctor Ids. The patientIdMap and doctorIdMap maps should be used to look up the patient and doctor based on their Id. The ordering must be performed using the Collections.sort method, using an external comparator to arrange the visits by dates. (Visits on the same date can be printed in any order).

Visit date: November 11, 2014
Doctor: John Smith
Specialty: GENERAL_MEDICINE
Days until visit: #number of days (such as 35)
Patient:
First name: George
Last name: Harrison
email: george@something.com
SSN: 567-39-9282
Age: 58

Extra credit (+10 points):

1. Implement the listings of visits by doctor and visits by patient using Maps that relate a patient or a doctor to a collection of visits. Then, instead of iterating over the collection of Visit objects multiple times, iterate once to fill your maps and then use the maps to create the listings by iterating over the map entries.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.