diff --git a/Mechanic Shop/.idea/misc.xml b/Mechanic Shop/.idea/misc.xml new file mode 100644 index 0000000..7b50ef4 --- /dev/null +++ b/Mechanic Shop/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Mechanic Shop/.idea/modules.xml b/Mechanic Shop/.idea/modules.xml new file mode 100644 index 0000000..c8c8ab4 --- /dev/null +++ b/Mechanic Shop/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Mechanic Shop/.idea/workspace.xml b/Mechanic Shop/.idea/workspace.xml new file mode 100644 index 0000000..4e468fb --- /dev/null +++ b/Mechanic Shop/.idea/workspace.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1771806406753 + + + + + + + + file://$PROJECT_DIR$/src/Main.java + 10 + + + + + \ No newline at end of file diff --git a/src/main/java/org/codedifferently/CarAppointment.java b/src/main/java/org/codedifferently/CarAppointment.java new file mode 100644 index 0000000..0edfea9 --- /dev/null +++ b/src/main/java/org/codedifferently/CarAppointment.java @@ -0,0 +1,88 @@ +package org.codedifferently; + +import org.codedifferently.data.TimeSlot; + +import java.sql.Array; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.UUID; + +public class CarAppointment { + + private String appointmentID; + + private static final LocalTime OPEN_TIME = LocalTime.of(7,0); + private static final LocalTime CLOSE_TIME = LocalTime.of(21,0); + private static final LocalTime LAST_APPOINTMENT = LocalTime.of(20,0); + private CarPatient carPatient; + private TimeSlot timeSlot; + private boolean isCompleted; + private String serviceType; + private static int instanceCounter; + { + instanceCounter++; + } + public static int getInstanceCounter() { + return instanceCounter; + } + + public boolean isCompleted() { + return isCompleted; + } + + public boolean isDuringBusinessHours(TimeSlot timeSlot){ + LocalTime startTime = timeSlot.getStart().toLocalTime(); + LocalTime endTime = timeSlot.getEnd().toLocalTime(); + + return startTime.isAfter(OPEN_TIME) && endTime.isBefore(CLOSE_TIME); + } + public CarAppointment(CarPatient carPatient, TimeSlot timeSlot, String serviceType){ + this.carPatient = carPatient; + this.timeSlot = timeSlot; + this.serviceType= serviceType; + appointmentID = UUID.randomUUID().toString().substring(0, 6); + } + + public CarAppointment(CarPatient carPatient, TimeSlot timeSlot){ + if(isDuringBusinessHours(timeSlot)){ + this.carPatient = carPatient; + this.timeSlot = timeSlot; + } else { + System.out.println("Appointment must be between our business hours of 7am-9pm"); + } + } + + public String getAppointmentID() { + return appointmentID; + } + + public void setAppointmentID(String appointmentID) { + this.appointmentID = appointmentID; + } + + public TimeSlot getTimeSlot() { + return timeSlot; + } + + public void setTimeSlot(TimeSlot timeSlot) { + this.timeSlot = timeSlot; + } + + public String getServiceType() { + return serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public CarPatient getCarPatient() { + return carPatient; + } + + public void setCarPatient(CarPatient carPatient) { + this.carPatient = carPatient; + } + +} diff --git a/src/main/java/org/codedifferently/CarClinicApp.java b/src/main/java/org/codedifferently/CarClinicApp.java new file mode 100644 index 0000000..1b23e0b --- /dev/null +++ b/src/main/java/org/codedifferently/CarClinicApp.java @@ -0,0 +1,155 @@ +package org.codedifferently; + +import org.codedifferently.data.TimeSlot; +import org.codedifferently.helpers.InputHandler; +import org.codedifferently.helpers.PatientHandler; + +import java.util.Scanner; + +//TIP To Run code, press or +// click the icon in the gutter. +public class CarClinicApp { + public static void main(String[] args) { + + CarClinicApp carClinicApp = new CarClinicApp(); + CarClinicSystem carClinicSystem = new CarClinicSystem(); + + carClinicApp.handleMainMenu(carClinicSystem); + + } + + void handleMainMenu(CarClinicSystem carClinicSystem) { + + boolean inMainMenu = true; + while(inMainMenu) { + + System.out.println("Welcome to the CWW Auto Repair Shop."); + System.out.println("What would you like to do today?"); + + System.out.println("-------------------------------------"); + System.out.println("1. View Car Patients"); + System.out.println("2. View Car Appointments"); + System.out.println("3. Check Summary Reports"); + System.out.println("4. Exit"); + System.out.println("-------------------------------------"); + + //Call Static Method to handle Integer input + int scanInput = InputHandler.handleIntegerInput(); + + switch (scanInput) { + case 1: + handlePatientMenu(carClinicSystem); + break; + case 2: + handleAppointmentMenu(carClinicSystem); + break; + case 4: + inMainMenu = false; + System.out.println("End of day summary report."); + System.out.println("Number of appointments created: " + CarAppointment.getInstanceCounter()); + System.out.println("Number of customers added to system: " + CarPatient.getInstanceCounter()); + System.out.println("Alright, have a nice day!"); + break; + default: + System.out.println("That's not an option on our menu! Please try again!"); + break; + } + } + } + + void handlePatientMenu(CarClinicSystem carClinicSystem) { + + boolean inPatientMenu = true; + while(inPatientMenu) { + System.out.println("-------------------------------------"); + System.out.println("Patient Viewer"); + System.out.println("We appreciate your patience, Patient!"); + System.out.println("What would you like to do today?"); + System.out.println("-------------------------------------"); + System.out.println("1. Add patient"); + System.out.println("2. View all patients"); + System.out.println("3. Check in patient"); + System.out.println("4. Search for patient"); + System.out.println("5. Exit"); + System.out.println("-------------------------------------"); + + int scanInput = InputHandler.handleIntegerInput(); + + PatientHandler patientHandler = new PatientHandler(); + + switch(scanInput) { + case 1: + patientHandler.promptNewPatient(carClinicSystem); + break; + case 2: + patientHandler.viewAllPatients(carClinicSystem); + break; + case 3: + patientHandler.checkInPatient(carClinicSystem); + break; + case 4: + patientHandler.printSearchedPatient(carClinicSystem); + break; + case 5: + System.out.println("Exiting out of Patient Menu!"); + inPatientMenu = false; + break; + default: + System.out.println("Thats not an option on our menu, please try again."); + } + } + + } + + void handleAppointmentMenu(CarClinicSystem carClinicSystem) { + + boolean inAppointmentMenu = true; + while(inAppointmentMenu) { + System.out.println("-------------------------------------"); + System.out.println("Appointment Viewer"); + System.out.println("You have reached A POINT meant in time."); + System.out.println("What would you like to do today?"); + System.out.println("-------------------------------------"); + System.out.println("1. View Timeslots"); + System.out.println("2. Schedule an appointment"); + System.out.println("3. Cancel an appointment."); + System.out.println("4. Exit"); + System.out.println("-------------------------------------"); + + int scanInput = InputHandler.handleIntegerInput(); + + PatientHandler patientHandler = new PatientHandler(); + + ShopScheduler shopScheduler = new ShopScheduler(); + + switch(scanInput) { + case 1: + shopScheduler.printSchedule(carClinicSystem); + break; + case 2: + CarPatient patient = patientHandler.searchForPatient(carClinicSystem); + if(patient == null) { + System.out.println("Patient was not found!!!"); + //Create new patient if not found. + patient = patientHandler.promptNewPatient(carClinicSystem); + } + TimeSlot timeSlot = shopScheduler.promptTimeSlot(); + String serviceType = shopScheduler.promptServiceType(); + shopScheduler.scheduleAppointment(carClinicSystem, patient, timeSlot, serviceType); + break; + case 3: + System.out.println("Give me the appointment ID that you want to cancel: "); + String appointmentID = InputHandler.handleStringInput(); + shopScheduler.cancelAppointment(carClinicSystem, appointmentID); + break; + case 4: + System.out.println("Exiting out of Patient Menu!"); + inAppointmentMenu = false; + break; + default: + System.out.println("Thats not an option on our menu, please try again."); + } + } + + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/CarClinicSystem.java b/src/main/java/org/codedifferently/CarClinicSystem.java new file mode 100644 index 0000000..da53b20 --- /dev/null +++ b/src/main/java/org/codedifferently/CarClinicSystem.java @@ -0,0 +1,22 @@ +package org.codedifferently; + +import java.util.ArrayList; + +public class CarClinicSystem { + + private ArrayList carAppointments = new ArrayList<>(); + private ArrayList carPatients = new ArrayList<>(); + + private final Waitlist waitlist = new Waitlist(); + + public Waitlist getWaitlist() { + return waitlist; + } + public ArrayList getCarAppointments() { + return carAppointments; + } + + public ArrayList getCarPatients() { + return carPatients; + } +} diff --git a/src/main/java/org/codedifferently/CarPatient.java b/src/main/java/org/codedifferently/CarPatient.java new file mode 100644 index 0000000..29890b1 --- /dev/null +++ b/src/main/java/org/codedifferently/CarPatient.java @@ -0,0 +1,60 @@ +package org.codedifferently; + +import org.codedifferently.data.Car; + +public class CarPatient { + + private String patientID; + private String firstName; + private String lastName; + private String email; + private String phoneNumber; + private boolean checkedIn; + private static int instanceCounter; + { + instanceCounter++; + } + + public static int getInstanceCounter() { + return instanceCounter; + } + + public CarPatient(String patientID, String firstName, String lastName, + String email, String phoneNumber) { + this.patientID = patientID; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.phoneNumber = phoneNumber; + this.checkedIn = false; + //this.patientCar = patientCar; + } + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getEmail() { + + return email; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public String getPatientID() { + return patientID; + } + + public boolean isCheckedIn() { + return checkedIn; + } + + public void setCheckedIn(boolean checkedIn) { + this.checkedIn = checkedIn; + } +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java deleted file mode 100644 index 435139b..0000000 --- a/src/main/java/org/codedifferently/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.codedifferently; - -//TIP To Run code, press or -// click the icon in the gutter. -public class Main { - public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); - - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); - } - } -} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ShopScheduler.java b/src/main/java/org/codedifferently/ShopScheduler.java new file mode 100644 index 0000000..9d59b85 --- /dev/null +++ b/src/main/java/org/codedifferently/ShopScheduler.java @@ -0,0 +1,141 @@ +package org.codedifferently; +import org.codedifferently.data.TimeSlot; +import org.codedifferently.helpers.InputHandler; +import org.codedifferently.WaitlistEntry; +import java.time.LocalDate; +import java.time.LocalDateTime; + +public class ShopScheduler { + + private boolean timeSlotsOverlap(TimeSlot a, TimeSlot b) { + return a.getStart().isBefore(b.getEnd()) && a.getEnd().isAfter(b.getStart()); + } + + public boolean isTimeSlotBooked(CarClinicSystem carClinicSystem, TimeSlot timeSlot) { + for (CarAppointment appt : carClinicSystem.getCarAppointments()) { + if (appt != null && timeSlotsOverlap(appt.getTimeSlot(), timeSlot)) { + return true; + } + } + return false; + } + + + public boolean scheduleAppointment(CarClinicSystem carClinicSystem, CarPatient customer, TimeSlot timeSlot, String serviceType) { + + // Use the serviceType the user typed (not hardcoded) + CarAppointment newAppt = new CarAppointment(customer, timeSlot, serviceType); + + // Prevent scheduling outside business hours + if (!newAppt.isDuringBusinessHours(newAppt.getTimeSlot())) { + System.out.println("Can't schedule outside business hours!"); + return false; + } + + // If slot is already taken, offer waitlist + if (isTimeSlotBooked(carClinicSystem, timeSlot)) { + System.out.println("That time slot is already booked."); + + System.out.println("Would you like to join the waitlist for this time slot?"); + System.out.println("1. Yes"); + System.out.println("2. No"); + + int choice = InputHandler.handleIntegerInput(); + if (choice == 1) { + String entryId = "W" + System.currentTimeMillis(); + WaitlistEntry entry = new WaitlistEntry(entryId, customer, timeSlot, serviceType); + carClinicSystem.getWaitlist().add(entry); + + System.out.println("Added to waitlist! Entry ID: " + entryId); + } else { + System.out.println("Okay, please choose another time slot."); + } + + return false; + } + + // Slot is open, schedule it + carClinicSystem.getCarAppointments().add(newAppt); + System.out.println("Appointment scheduled successfully!"); + return true; + } + + // Cancel appointment by timeSlot + + // Cancel appointment by timeSlot + public void cancelAppointment(CarClinicSystem carClinicSystem, String appointmentID) { + for(int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { + if(carClinicSystem.getCarAppointments().get(i).getAppointmentID().equals(appointmentID)) { + carClinicSystem.getCarAppointments().remove(i); + System.out.println("Appointment canceled."); + }else { + System.out.println("No appointment found."); + } + } + + } + + + + // Print full schedule + public void printSchedule(CarClinicSystem carClinicSystem) { + System.out.println("\n=== CWW Auto Repair Shop Daily Schedule ==="); + System.out.println("---------------------------------------------"); + + if(carClinicSystem.getCarAppointments().size() < 1) { + System.out.println("No appointments currently scheduled!"); + } + else { + for (int i = 0; i < carClinicSystem.getCarAppointments().size(); i++) { + CarAppointment appointment = carClinicSystem.getCarAppointments().get(i); + + if (appointment == null) { + System.out.println((i + 1) + " - AVAILABLE"); + } else { + System.out.println((i + 1) + ". " + "(" + appointment.getAppointmentID() + ") " + + appointment.getCarPatient().getLastName() + ", " + appointment.getCarPatient().getFirstName() + + " (" + appointment.getTimeSlot().getStart() + + " - " + appointment.getTimeSlot().getEnd() + + ") (" + appointment.getServiceType() + ")"); + } + } + + } + System.out.println("-------------------------------"); + System.out.println("WAITLIST APPOINTMENTS"); + System.out.println("-------------------------------"); + + if(carClinicSystem.getWaitlist().getAll().size() < 1) { + System.out.println("No appointments on waitlist!"); + } + else { + for(int i=0; i < carClinicSystem.getWaitlist().getAll().size();i++) { + String firstName = carClinicSystem.getWaitlist().getEntries(i).getPatient().getFirstName(); + String lastName = carClinicSystem.getWaitlist().getEntries(i).getPatient().getLastName(); + String id = carClinicSystem.getWaitlist().getEntries(i).getPatient().getPatientID(); + + System.out.println("First name " + firstName); + System.out.println("Last name " + lastName); + System.out.println("Id" + id); + } + + } + + } + public TimeSlot promptTimeSlot () { + System.out.println("Give me the Start Time: (We're open from 7-21 military time)"); + int startTime = InputHandler.handleIntegerInput(); + System.out.println("Give me the End Time:"); + int endTime = InputHandler.handleIntegerInput(); + LocalDateTime startDateTime = LocalDate.now().atTime(startTime, 0); + LocalDateTime endDateTime = LocalDate.now().atTime(endTime, 0); + return new TimeSlot(startDateTime, endDateTime); + } + + public String promptServiceType () { + System.out.println("What type of Service are you doing today?:"); + return InputHandler.handleStringInput(); + + + } + } diff --git a/src/main/java/org/codedifferently/Waitlist.java b/src/main/java/org/codedifferently/Waitlist.java new file mode 100644 index 0000000..9d5fba0 --- /dev/null +++ b/src/main/java/org/codedifferently/Waitlist.java @@ -0,0 +1,41 @@ +package org.codedifferently; + +import org.codedifferently.data.TimeSlot; + + +import java.util.ArrayList; + +public class Waitlist { + + private final ArrayList entries = new ArrayList<>(); + + public void add(WaitlistEntry entry) { + entries.add(entry); + } + + // Returns and removes the first person waiting for this exact TimeSlot + public WaitlistEntry popNextFor(TimeSlot timeSlot) { + for (int i = 0; i < entries.size(); i++) { + if (entries.get(i).getRequestedTimeSlot().equals(timeSlot)) { + return entries.remove(i); + } + } + return null; + } + + public boolean isEmpty() { + return entries.isEmpty(); + } + + public int size() { + return entries.size(); + } + + public ArrayList getAll() { + return entries; + } + + public WaitlistEntry getEntries(int index) { + return entries.get(index); + } +} diff --git a/src/main/java/org/codedifferently/WaitlistEntry.java b/src/main/java/org/codedifferently/WaitlistEntry.java new file mode 100644 index 0000000..867943a --- /dev/null +++ b/src/main/java/org/codedifferently/WaitlistEntry.java @@ -0,0 +1,44 @@ +package org.codedifferently; + +import org.codedifferently.CarPatient; +import org.codedifferently.data.TimeSlot; + + +public class WaitlistEntry { + private final String entryId; + private final CarPatient patient; + private final TimeSlot requestedTimeSlot; + private final String serviceType; + + public WaitlistEntry(String entryId, CarPatient patient, TimeSlot requestedTimeSlot, String serviceType) { + this.entryId = entryId; + this.patient = patient; + this.requestedTimeSlot = requestedTimeSlot; + this.serviceType = serviceType; + } + + public String getEntryId() { + return entryId; + } + + public CarPatient getPatient() { + return patient; + } + + public TimeSlot getRequestedTimeSlot() { + return requestedTimeSlot; + } + + public String getServiceType() { + return serviceType; + } + + @Override + public String toString() { + return "Entry ID: " + entryId + + " | Patient: " + patient.getLastName() + ", " + patient.getFirstName() + + " | TimeSlot: " + requestedTimeSlot + + " | Service: " + serviceType; + } +} + diff --git a/src/main/java/org/codedifferently/data/Car.java b/src/main/java/org/codedifferently/data/Car.java new file mode 100644 index 0000000..8948b70 --- /dev/null +++ b/src/main/java/org/codedifferently/data/Car.java @@ -0,0 +1,10 @@ +package org.codedifferently.data; + +public class Car { + + private String licensePlate; + private String model; + private int year; + private String color; + private int mileage; +} diff --git a/src/main/java/org/codedifferently/data/TimeSlot.java b/src/main/java/org/codedifferently/data/TimeSlot.java new file mode 100644 index 0000000..589c7d6 --- /dev/null +++ b/src/main/java/org/codedifferently/data/TimeSlot.java @@ -0,0 +1,28 @@ +package org.codedifferently.data; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Duration; + +public class TimeSlot { + private final LocalDateTime start; + private final LocalDateTime end; + + public TimeSlot(LocalDateTime start, LocalDateTime end) { + this.start = start; + this.end = end; + } + + public LocalDateTime getStart() { + return start; + } + + public LocalDateTime getEnd() { + + return end; + } + + public Duration getDuration() { + + return Duration.between(start, end); + } +} diff --git a/src/main/java/org/codedifferently/helpers/InputHandler.java b/src/main/java/org/codedifferently/helpers/InputHandler.java new file mode 100644 index 0000000..b397763 --- /dev/null +++ b/src/main/java/org/codedifferently/helpers/InputHandler.java @@ -0,0 +1,49 @@ +package org.codedifferently.helpers; + +import java.util.Scanner; + +public class InputHandler { + + public static int handleIntegerInput() { + Scanner scan = new Scanner(System.in); + int scanInput = 0; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + scanInput = scan.nextInt(); + validScanInput = true; + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a number instead of a String!"); + scan.next(); + } + } + return scanInput; + } + + public static String handleStringInput() { + Scanner scan = new Scanner(System.in); + String scanInput = ""; + boolean validScanInput = false; + //While loop to make sure user puts in the correct input + while(!validScanInput) { + //Call Scanner methods + try { + //Scanner method to collect input + scanInput = scan.nextLine(); + validScanInput = true; + } + catch (Exception e) { + //If user enters invalid input, the catch block will prevent errors. + System.out.println("Invalid input! Try typing a valid String!"); + scan.next(); + } + } + return scanInput; + } + +} diff --git a/src/main/java/org/codedifferently/helpers/PatientHandler.java b/src/main/java/org/codedifferently/helpers/PatientHandler.java new file mode 100644 index 0000000..02b6f4a --- /dev/null +++ b/src/main/java/org/codedifferently/helpers/PatientHandler.java @@ -0,0 +1,180 @@ +package org.codedifferently.helpers; +import org.codedifferently.CarClinicSystem; +import org.codedifferently.CarPatient; +import org.codedifferently.data.Car; + +import java.util.UUID; + +public class PatientHandler { + + public CarPatient promptNewPatient(CarClinicSystem carClinicSystem) { + + //Prompt user for information. (firstname, lastname, email, phoneNumber) + System.out.println("What is your first name?"); + String firstName = InputHandler.handleStringInput(); + + System.out.println("What is your last name?"); + String lastName = InputHandler.handleStringInput(); + + System.out.println("What's your Email Address?"); + String email = InputHandler.handleStringInput(); + + System.out.println("What's your Phone Number?"); + String phoneNumber = InputHandler.handleStringInput(); + + System.out.println("Awesome, here's your Unique ID, do not share this with ANYONE!"); + String uniqueID = UUID.randomUUID().toString().substring(0, 6); + System.out.println(uniqueID); + + //Make New Car Patient. + CarPatient carPatient = new CarPatient(uniqueID, firstName, lastName, email, phoneNumber); + + //Add new Car Patient to Car Patient Array List. + carClinicSystem.getCarPatients().add(carPatient); + + return carPatient; + } + + public void viewAllPatients(CarClinicSystem carClinicSystem) { + System.out.println("--------------------------------"); + System.out.println("****************************"); + System.out.println("VIEWING ALL PATIENTS"); + + //If no patients, print extra message + if(carClinicSystem.getCarPatients().isEmpty()) { + System.out.println("THERE ARE NO PATIENTS IN THE SYSTEM CURRENTLY"); + } + + //Loop through all car patients, print each of them out. + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //print every field of CarPatient + System.out.print((i+1) + ". ("); + System.out.print(carClinicSystem.getCarPatients().get(i).getPatientID()+ ") "); + System.out.print(carClinicSystem.getCarPatients().get(i).getLastName() + ", "); + System.out.print(carClinicSystem.getCarPatients().get(i).getFirstName() + " | "); + System.out.print(carClinicSystem.getCarPatients().get(i).getEmail() + " | "); + System.out.print(carClinicSystem.getCarPatients().get(i).getPhoneNumber() + " | "); + + String checkedInMsg = (carClinicSystem.getCarPatients().get(i).isCheckedIn() ? "Yes" : " No"); + System.out.print("Checked In: " + checkedInMsg); + System.out.println(); + } + + System.out.println("***************************"); + System.out.println("---------------------------------"); + + System.out.println("Type any key to continue..."); + InputHandler.handleStringInput(); + + } + + + public CarPatient searchForPatient(CarClinicSystem carClinicSystem) { + System.out.println("SEARCHING FOR PATIENT!!"); + System.out.println("Enter the Patients Last Name:"); + + String lastNameInput = InputHandler.handleStringInput(); + CarPatient searchedPatient = null; + + //Loop through all car patients, if theres 1-match. retrieve him + int foundPatientCount = 0; + + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //Keep a counter if we find a match, if we get more than one match. try + //to check for first name now to distinguish the two matches. + if(lastNameInput.equals(carClinicSystem.getCarPatients().get(i).getLastName())) { + searchedPatient = carClinicSystem.getCarPatients().get(i); + foundPatientCount++; + } + } + //If one exact match, return the result! + if(foundPatientCount <= 1) { + return searchedPatient; + } + + //else, we will check first names now + System.out.println("Enter the Patients First Name:"); + searchedPatient = null; + foundPatientCount = 0; + String firstNameInput = InputHandler.handleStringInput(); + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //Keep a counter if we find a match, if we get more than one match. try + //to check for first name now to distinguish the two matches. + if(firstNameInput.equals(carClinicSystem.getCarPatients().get(i).getFirstName())) { + searchedPatient = carClinicSystem.getCarPatients().get(i); + foundPatientCount++; + } + } + + //If one exact match, return the result! + if(foundPatientCount <= 1) { + return searchedPatient; + } + + //Finally, if last name AND first name grants duplicate result, then ask user for their + //unique ID + + System.out.println("Enter the Patients UUID:"); + searchedPatient = null; + foundPatientCount = 0; + String uuIDInput = InputHandler.handleStringInput(); + for(int i = 0; i < carClinicSystem.getCarPatients().size(); i++) { + + //Keep a counter if we find a match, if we get more than one match. try + //to check for first name now to distinguish the two matches. + if(uuIDInput.equals(carClinicSystem.getCarPatients().get(i).getPatientID())) { + searchedPatient = carClinicSystem.getCarPatients().get(i); + foundPatientCount++; + } + } + return searchedPatient; + } + + //Print searched patient, call helper to help with results. this one just prints + //what it finds. + public void printSearchedPatient(CarClinicSystem carClinicSystem) { + + CarPatient searchedPatient = searchForPatient(carClinicSystem); + + if(searchedPatient == null) { + System.out.println("Searched Patient did not exist! Please try again!"); + } + else { + System.out.println("-----------------------------------------"); + System.out.println("Patient FOUND: "); + System.out.println("Name: " + searchedPatient.getFirstName() + + ", " +searchedPatient.getLastName()); + System.out.println("Email: " + searchedPatient.getEmail()); + System.out.println("Phone Number: " + searchedPatient.getPhoneNumber()); + System.out.println("UUID: " + searchedPatient.getPatientID()); + System.out.println("Checked-In: " + (searchedPatient.isCheckedIn() ? "Yes" : "No")); + System.out.println("Type any key to continue..."); + InputHandler.handleStringInput(); + System.out.println("-------------------------------------"); + } + } + + //We use the search functionality to get the patient checked-in. + public void checkInPatient(CarClinicSystem carClinicSystem) { + System.out.println("---------------------------------------"); + System.out.println("Alright, checking in a patient!!"); + System.out.println("But first we need to locate the patient!"); + + CarPatient searchedPatient = searchForPatient(carClinicSystem); + + if(searchedPatient == null) { + System.out.println("Searched Patient did not exist! Please try again!"); + } + else { + System.out.println("Patient " + searchedPatient.getLastName() + + ", " + searchedPatient.getFirstName() + " (" + + searchedPatient.getPatientID() + + ") is now checked in!"); + searchedPatient.setCheckedIn(true); + } + } + +}