COP3804 Summer, 2015 Assignment #2 – Medical Administration

advertisement
COP3804
Summer, 2015
Assignment #2 – Medical Administration System – Phase 2
Last updated 06/12/2015 05:20 pm
For assignment number 2, we are going to enhance our Medical System to read and parse data from an input file.
We are also adding some data validation, exception handling, sorting, as well as, a new utility class called
MedAdminUtility.
To sort the different lists, we are adding a method that implements the bubble sort algorithm. Since we want the
same method to be able to sort an ArrayList of Patients, Doctors, Diagnoses, or Procedures, we will make it a
Generic method.
Below is the list of modifications we are making to the project (feel free to use the solution for phase 1 that I
sent via email).
Person class:
Modification 1: Make the class implement the Comparable<Person> interface.
Modification 2: Provide an implementation for the compareTo method such that it compares the value of the
lastName instance variable of the two objects. If the lastName variable of the calling object is greater, it returns
1, if it’s smaller it returns -1, and if they both have the same value, the method then compares the first name. If
they have the same value for the firstName variable, it returns 0, if the firstName variable of the calling object is
greater, it returns 1, else it returns -1.
Notes:

You may use the compareTo method of the String class.

Include the javadoc comment for the method.
The following is the method signature:
public int compareTo(Person person)
{
// provide implementation
}
Patient class:
Modification 1: In the constructor that has 4 parameters, as well as in the setPatientID method, if the id
parameter is less than or equal to zero, throw an IllegalArgumentException.
Code provided below:
// if the id parameter is negative or equal to 0, throw an exception.
if( id > 0 )
patientID = id;
else
throw new IllegalArgumentException("Patient ID must be a positive
number.");
Modification 2: In the same constructor, as well as in the setDateOfBirth method, if the dob parameter is not a
valid date, throw an IllegalArgumentException. Use the isValidDate method of the MedAdminUtility class. The
message for the exception would be: "The date of birth is not a valid date."
Modification 3: Update the javadoc comments to include the @exception tag for the constructor, the
setPatientID method, and the setDateOfBirth method.
Doctor class:
Modification 1: In the constructor that has 5 parameters, as well as in the setDoctorID method, if the id
parameter is less than or equal to zero, throw an IllegalArgumentException. The message for the exception
would be: "Doctor ID must be a positive number."
Modification 2: In the constructor that has 5 parameters, as well as in the setYearsOfExperience method, if the
years parameter is less than or equal to zero, throw an IllegalArgumentException. The message for the
exception would be: "The number of years of experience must be a positive number."
Modification 3: Update the javadoc comments to include the @exception tag for the constructor, the
setDoctorID method, and the setYearsOfExperience method.
Diagnosis class:
Modification 1: Make the class implement the Comparable<Diagnosis> interface.
Modification 2: Provide an implementation for the compareTo method such that it compares the value of the
code instance variable of the two objects. If the code variable of the calling object is greater, it returns 1, if it’s
smaller it returns -1, and if they both have the same value, the method then compares the description. If they
have the same value for the description variable, it returns 0, if the description variable of the calling object is
greater, it returns 1, else it returns -1.
Notes:

You may use the compareTo method of the String class.

Include the javadoc comment for the method.
The following is the method signature:
public int compareTo(Diagnosis diag)
{
// provide implementation
}
Procedure class:
Modification 1: In the constructor that has 4 parameters, as well as in the setCharge method, if the procCharge
parameter is less than zero, throw an IllegalArgumentException. The message for the exception would be: "The
charge for the procedure must be 0 or a positive number."
Modification 2: Update the javadoc comments to include the @exception tag for both, the constructor and the
setCharge method.
Modification 3: Make the class implement the Comparable<Procedure> interface.
Modification 4: Provide an implementation for the compareTo method such that it compares the value of the
code instance variable of the two objects. If the code variable of the calling object is greater, it returns 1, if it’s
smaller it returns -1, and if they both have the same value, the method then compares the description. If they
have the same value for the description variable, it returns 0, if the description variable of the calling object is
greater, it returns 1, else it returns -1.
Notes:

You may use the compareTo method of the String class.

Include the javadoc comment for the method.
The following is the method signature:
public int compareTo(Procedure proc)
{
// provide implementation
}
MedAdminUtility class:
Add a new class to the project called MedAdminUtility, which is a utility class used as a repository of static
methods that can be used by all the other classes in the project. We will not create objects of this class so we
need no constructors, no instance variables or instance methods. Please see the class members below:
Private Static Variables:
lastAssignedPatientID of type int
lastAssignedDoctorID of type int
Note: You do not need to provide the corresponding getter and setter methods for these variables.
Public Static Methods:
getNextPatientID – This method increments the value stored in the lastAssignedPatientID static variable by one
and returns the new value.
getNextDoctorID – This method increments the value stored in the lastAssignedDoctorID static variable by one
and returns the new value.
findPatient – This method has two parameters, an ArrayList of Patient elements, and a Patient object to search
for in the list. This method returns the element in the list found to be equal to the parameter. Otherwise, it
returns null.
Note: make sure to use the equals method in the Patient class.
The following is the method signature:
public static Patient findPatient(ArrayList<Patient> patientList, Patient
patient)
findDoctor – This method has two parameters, an ArrayList of Doctor elements, and a Doctor object to search
for in the list. This method returns the element in the list found to be equal to the parameter. Otherwise, it
returns null.
Note: make sure to use the equals method in the Doctor class.
findDiagnosis – This method has two parameters, an ArrayList of Diagnosis elements, and a Diagnosis object
to search for in the list. This method returns the element in the list found to be equal to the parameter. Otherwise,
it returns null.
Note: make sure to use the equals method in the Diagnosis class.
findProcedure – This method has two parameters, an ArrayList of Procedure elements, and a Procedure object
to search for in the list. This method returns the element in the list found to be equal to the parameter. Otherwise,
it returns null.
Note: make sure to use the equals method in the Procedure class.
sortArrayList – This method sorts the ArrayList object that gets passed as an argument. It is a generic
method that has a type parameter declaration to specify that the elements of the ArrayList parameter
have to be of a class that implements the Comparable interface.
(see section 17.4 of the textbook)
This method uses the bubble sort algorithm explained in section 16.1. In particular, you may use CodeListing 16-3 of the textbook as a guide, except that you are sorting elements in an ArrayList, not an
array.
public static < E extends Comparable > void sortArrayList
(ArrayList<E> list)
{
int lastPos;
int index;
E temp;
// finish the implementation
}
isValidDate – This method has one parameter of type String to represent a date. It returns true if the parameter
has the format MM/DD/YYYY. It returns false otherwise.
public static boolean isValidDate(String date)
MedAdministration_Phase2 class:
We are adding the functionality to load Patients, Doctors, Diagnoses, and Procedures from a data file.
Note: theClinic is a class variable that was added to this class. The processLineOfData method should add
Patient, Doctor, Diagnosis, and Procedure objects to its listOfDoctors, listOfPatients, listOfDiagnoses, and
listOfProcedures instance variables.
Modification 1: Write a method called processLineOfData that has a String parameter and the return type is
void.
The parameter represents one line of data in the file, which could be data for a Patient, UnderagePatient,
Doctor, Specialist, Diagnosis, or Procedure. See the note below for the expected format for each line.
I’m providing you with an algorithm below:
public static void processLineOfData(String line) throws Exception
{
// Split the line parameter on the comma.
// Get the first field to determine the record type:
// P -> Patient
// U -> UnderagePatient
// D -> Doctor
// S -> Specialist
// G -> Diagnosis
// R -> Procedure
//
//
//
//
//
//
//
//
If the line has Patient data, check if the patient already exists
in the clinic’s listOfPatients variable (use the findPatient
method of the MedAdminUtility class.
If it exists, don’t do anything. If it doesn’t exist, get the next
patient id number (use the getNextPatientID method of the
MedAdminUtility class), update the patientID field of the Patient
object, and add it to the clinic’s listOfPatients variable (use
the addPatient method of Clinic class).
// If the line has UnderagePatient, Doctor, Specialist, Diagnosis, or
// Procedure data, process similarly as the Patient case.
// If the line is none of the above types, throw an
// Exception object with the message “Bad record”.
}
Data Formats in the input data file
The following is the expected format for each type of data in the input file:
Patient
P,first,last,date of birth
UnderagePatient
U,first,last,date of birth,guardian
Doctor
D,first,last,med school,years
Specialist
S,first,last,med school,years,specialty,list of trainings
Diagnosis
G,code,description
Procedure
R,code,description,charge,in patient
Group Member Responsibilities:
Group Member 1



Group Member 2


Modifications to the Person class (implement the Comparable<Person>
interface, add implementation to the compareTo method).
Declare the MedAdminUtility class including variable declarations, write the
findPatient method (include javadoc comments).
In the processLineOfData method of the MedAdministration_Phase2 class, split
the line parameter, and setup an if or switch statement to look at the first
character. Write the code to process the data for a Patient.
Modifications to the Patient class (validate patientID and dateOfBirth).
Modifications to the Procedure class (validate procCharge, implement the
Comparable<Procedure> interface, add implementation to the compareTo
method).


Group Member 3



Group Member 4



In the MedAdminUtility class, write the findDoctor method (include javadoc
comments).
Write the code in the processLineOfData method of the
MedAdministration_Phase2 class to process the data for an UnderagePatient
and Procedure.
Modifications to the Doctor class (validate doctorID and yearsOfExperience).
In the MedAdminUtility class, write the getNextPatientID, getNextDoctorID,
and findProcedure methods (include javadoc comments).
Write the code in the processLineOfData method of the
MedAdministration_Phase2 class, to process the data for a Doctor and
Specialist.
Modifications to the Diagnosis class (implement the Comparable<Diagnosis>
interface, add implementation to the compareTo method).
In the MedAdminUtility class, write the findDiagnosis, sortArrayList, and
isValidDate methods (include javadoc comments).
Write the code in the processLineOfData method of the
MedAdministration_Phase2 class, to process the data for a Diagnosis.
Download