diff --git a/src/diagram.puml b/src/diagram.puml new file mode 100644 index 0000000..ddfb407 --- /dev/null +++ b/src/diagram.puml @@ -0,0 +1,90 @@ +@startuml + +class Patient { + - patientId : int + - name : String + - species : String + - ownersPhoneNumber : String + - checkedIn : boolean + + + Patient(species : String, name : String, checkedIn : boolean, ownersPhoneNumber : String) + + + getPatientId() : int + + getName() : String + + getSpecies() : String + + getOwnersPhoneNumber() : String + + isCheckedIn() : boolean + + + setName(name : String) : void + + setSpecies(species : String) : void + + setOwnersPhoneNumber(ownersPhoneNumber : String) : void + + setCheckedIn(checkedIn : boolean) : void +} + +class Appointment { + - reason : String + - date : String + - time : String + - completed : boolean + + + Appointment(date : String, time : String, reason : String) + + + getReason() : String + + getDate() : String + + getTime() : String + + isCompleted() : boolean + + + markCompleted() : void +} + +class ClinicSystem { + - patients : ArrayList + - waitingList : ArrayList + - appointments : ArrayList + - dailyTimeSlots : String[] + + + ClinicSystem() + + + addPatient(patient : Patient) : void + + viewAllPatients() : void + + lookUpPatient(name : String, phoneNumber : String) : void + + lookUpPatientById(id : int) : void + + checkInPatient(patient : Patient) : void + + + scheduleAppointment(date : String, time : String, reason : String) : void + + cancelAppointment(date : String, time : String) : void + + viewFullSchedule() : void + + dailySummary(date : String) : void + + + addedToWaitingList(patient : Patient) : void + + viewWaitList() : void +} + +class ClinicApp { + + main(args : String[]) : void +} + +' ========================================= +' RELATIONSHIPS EXPLAINED +' ========================================= + +' One ClinicSystem manages zero or many Patients. +' "1" means one ClinicSystem. +' "0..*" means the system can manage zero or many Patient objects. +' o-- means aggregation (Patients can exist independently of the ClinicSystem). +ClinicSystem "1" o-- "0..*" Patient + + +' One ClinicSystem manages zero or many Appointments. +' "1" means one ClinicSystem. +' "0..*" means the system can manage zero or many Appointment objects. +' o-- means aggregation (Appointments can exist independently of the ClinicSystem). +ClinicSystem "1" o-- "0..*" Appointment + + +' ClinicApp depends on ClinicSystem. +' This means the main application class uses ClinicSystem to run the program. +' --> represents a dependency relationship. +ClinicApp --> ClinicSystem + +@enduml diff --git a/src/main/java/org/codedifferently/BryantClinicApp.java b/src/main/java/org/codedifferently/BryantClinicApp.java new file mode 100644 index 0000000..7484ef3 --- /dev/null +++ b/src/main/java/org/codedifferently/BryantClinicApp.java @@ -0,0 +1,158 @@ +package org.codedifferently; + +import java.util.Scanner; + +public class BryantClinicApp { + + public static void main(String[] args) { + + Scanner input = new Scanner(System.in); //Scanner object called input + BryantClinicSystem clinic = new BryantClinicSystem(); //instance of the BryantClinicSystem class called clinic + int choice; + + do { + displayClinicMenu(); + try { + choice = input.nextInt(); + input.nextLine(); + } catch (Exception e) { + System.out.println("Invalid input. Please enter a number from the menu."); + input.nextLine(); // clear bad input + choice = -1; // force default case + } + + //Actions based on the menu number the user selects + switch (choice) { + case 1: + System.out.print("Enter patient's species: "); + String species = input.nextLine(); + System.out.print("Enter patient's name: "); + String name = input.nextLine(); + System.out.print("Enter owner's phone number(no dashes): "); + String phone = input.nextLine(); + KennyPatient newPatient = new KennyPatient(species, name, false, phone); + clinic.addPatient(newPatient); + break; + + case 2: + clinic.viewAllPatients(); + break; + + case 3: + System.out.print("Enter patient ID to check in: "); + String checkInId = input.nextLine(); + KennyPatient patient = clinic.getPatientById(Integer.parseInt(checkInId)); + if (patient != null) { + clinic.checkInPatient(patient); + clinic.lookUpPatientById(Integer.parseInt(checkInId)); + + } else { + System.out.println("Patient not found."); + System.out.println("---------------------------"); + } + break; + + case 4: + System.out.print("Enter patient ID: "); + String id = input.nextLine(); + clinic.lookUpPatientById(Integer.parseInt(id)); + break; + + case 5: + System.out.print("Enter patient's name: "); + name = input.nextLine(); + System.out.println("Enter the owner's phone number (no dashes): "); + phone = input.nextLine(); + clinic.lookUpPatient(name,phone); + break; + + case 6: + System.out.print("Enter the date of your appointment (MM/DD/YYYY): "); + String date = input.nextLine(); + System.out.print("Enter the time you want to schedule the appointment: "); + String time = input.nextLine().toUpperCase(); + System.out.print("Enter the reason for scheduling this appointment: "); + String reason = input.nextLine(); + System.out.println("Enter the patient's id: "); + String patientID = input.nextLine(); + clinic.scheduleAppointment(Integer.parseInt(patientID), date, time, reason); + break; + + case 7: + System.out.print("Enter the date of your appointment (MM/DD/YYYY): "); + String cancelDate = input.nextLine(); + System.out.print("Enter the time of your appointment: "); + String cancelTime = input.nextLine().toUpperCase(); + clinic.cancelAppointment(cancelDate, cancelTime); + break; + + case 8: + clinic.viewFullSchedule(); + break; + + case 9: + System.out.print("Enter date for summary (MM/DD/YYYY): "); + String summaryDate = input.nextLine(); + + clinic.dailySummary(summaryDate); + break; + + case 10: + clinic.viewWaitList(); + break; + + case 11: + System.out.print("Enter patient's species: "); + species = input.nextLine(); + System.out.print("Enter patient's name: "); + name = input.nextLine(); + System.out.print("Enter owner's phone number(no dashes): "); + phone = input.nextLine(); + KennyPatient newPatient2 = new KennyPatient(species, name, false, phone); + clinic.addedToWaitingList(newPatient2); + break; + + case 12: + System.out.print("Enter appointment date (MM/DD/YYYY): "); + String compDate = input.nextLine(); + + System.out.print("Enter appointment time: "); + String compTime = input.nextLine().toUpperCase(); + + clinic.completeAppointment(compDate, compTime); + break; + + case 0: + System.out.println("Exiting system. Goodbye!"); + break; + + default: + System.out.println("Invalid choice. Please try again."); + } + + } while (choice != 0); + + input.close(); + } + + //helper function to display the menu options + public static void displayClinicMenu(){ + System.out.println("\n**** Welcome to the Community Clinic System! ****"); + System.out.println("Please select an option:"); + System.out.println("1. Add New Patient"); + System.out.println("2. View All Patients"); + System.out.println("3. Check In Patient"); + System.out.println("4. Search Patient by ID"); + System.out.println("5. Search Patient by Name and Phone Number"); + System.out.println("6. Schedule Appointment"); + System.out.println("7. Cancel Appointment"); + System.out.println("8. View Full Schedule"); + System.out.println("9. Daily Summary Report"); + System.out.println("10. View Waitlist"); + System.out.println("11. Add Patient to Waitlist"); + System.out.println("12. Mark an Appointment as Completed"); + System.out.println("0. Exit"); + System.out.println(); + System.out.print("Enter choice: "); + } +}// ends class diff --git a/src/main/java/org/codedifferently/BryantClinicSystem.java b/src/main/java/org/codedifferently/BryantClinicSystem.java new file mode 100644 index 0000000..e4e9838 --- /dev/null +++ b/src/main/java/org/codedifferently/BryantClinicSystem.java @@ -0,0 +1,239 @@ +package org.codedifferently; + +import java.util.ArrayList; + +public class BryantClinicSystem { + //instance variables + private ArrayList patients; + private ArrayList waitingList; + private ArrayList appointments; + private String[] dailyTimeSlots = {"9:00AM", "10:00AM", "11:00AM", "1:00PM", "2:00PM", "3:00PM"}; + + //constructor + public BryantClinicSystem() { + + this.patients = new ArrayList<>(); + this.waitingList = new ArrayList<>(); + this.appointments = new ArrayList<>(); + + // Preloaded patients + KennyPatient p1 = new KennyPatient("Dog", "Buddy", false, "3025551111"); + KennyPatient p2 = new KennyPatient("Cat", "Luna", false, "3025552222"); + patients.add(p1); + patients.add(p2); + + // Preloaded appointments + MesheikAppointment a1 = new MesheikAppointment("12/10/2026", "9:00AM", "Checkup", p1); + MesheikAppointment a2 = new MesheikAppointment("12/10/2026", "10:00AM", "Vaccination", p2); + appointments.add(a1); + appointments.add(a2); + } + + //checks to see if the time is in the time slot array + public boolean isValidTime(String time) { + for (String slot : dailyTimeSlots) { + if (slot.equalsIgnoreCase(time)) { + return true; + } + } + return false; + } + + //adds the appointment to the appointment array + public void scheduleAppointment(int patientId, String date, String time, String reason) { + + // Find the patient first + KennyPatient patient = getPatientById(patientId); + + // checks for bad input + if (date == null || date.isEmpty() || + time == null || time.isEmpty() || + reason == null || reason.isEmpty()){ + System.out.println("Invalid input. All fields are required to schedule an appointment."); + return; + } + + // Validate if time exists in daily schedule + if (!isValidTime(time)) { + System.out.println("Invalid time slot."); + return; + } + + // Prevent double booking + for (MesheikAppointment appointment : appointments) { + if (appointment.getDate().equals(date) && appointment.getTime().equalsIgnoreCase(time)) { + System.out.println("That time slot is already booked on this date."); + return; + } + } + + // If the appointment is valid and not booked, schedule the appointment + MesheikAppointment newAppointment = new MesheikAppointment(date, time, reason, patient); + appointments.add(newAppointment); + System.out.println("Appointment scheduled successfully."); + } + + + //displays all the appointments + public void viewFullSchedule() { + if (appointments.isEmpty()) { + System.out.println("No appointments are scheduled."); + return; + } + + for (MesheikAppointment appointment : appointments) { + System.out.println("Date: " + appointment.getDate()); + System.out.println("Time: " + appointment.getTime()); + System.out.println("Reason: " + appointment.getReason()); + System.out.println("---------------------------"); + } + } + + //removes an appointment from the list of appointments + public void cancelAppointment(String date, String time) { + for (int i = 0; i < appointments.size(); i++) { + MesheikAppointment appointment = appointments.get(i); + if (appointment.getDate().equals(date) && appointment.getTime().equalsIgnoreCase(time)) { + if (appointment.isCompleted()) { + System.out.println("Cannot cancel a completed appointment."); + System.out.println("---------------------------"); + return; + } + appointments.remove(i); + System.out.println("The Appointment was cancelled."); + System.out.println("---------------------------"); + return; + } + } + System.out.println("Appointment not found."); + System.out.println("---------------------------"); + } + + //marks an appointment as complete when the appointment is completed + public void completeAppointment(String date, String time) { + for (MesheikAppointment appointment : appointments) { + if (appointment.getDate().equals(date) && appointment.getTime().equalsIgnoreCase(time)) { + if (appointment.isCompleted()) { + System.out.println("Appointment already completed."); + System.out.println("---------------------------"); + return; + } + appointment.markCompleted(); + System.out.println("Appointment marked as completed."); + System.out.println("---------------------------"); + return; + } + } + + System.out.println("Appointment not found."); + System.out.println("---------------------------"); + } + + + //adds patients to the waiting list + public void addedToWaitingList(KennyPatient patient) { + waitingList.add(patient); + System.out.println(patient.getName() + " has been added to the waitlist."); + System.out.println("---------------------------"); + } + + //displays the waiting list + public void viewWaitList() { + if (waitingList.isEmpty()) { + System.out.println("Waitlist is empty."); + System.out.println("---------------------------"); + return; + } + System.out.println("***** Waiting List *****"); + for (KennyPatient patient : waitingList) { + patient.displayInfo(); + } + System.out.println("---------------------------"); + } + + //adds the patient to the list of patients + public void addPatient(KennyPatient patient){ + patients.add(patient); + System.out.println("Patient added successfully."); + System.out.println("---------------------------"); + } + + //displays all paitents + public void viewAllPatients(){ + for (KennyPatient patient : patients) { + patient.displayInfo(); + } + } + + //searches for a patient by their name and phone number + public void lookUpPatient(String name, String phoneNumber){ + for (KennyPatient patient : patients) { + if (name.equals(patient.getName()) && phoneNumber.equals(patient.getOwnersPhoneNumber())) { + patient.displayInfo(); + return; + } + } + System.out.println("Patient not found."); + System.out.println("---------------------------"); + } + + //searches for a patient by their ID number + public void lookUpPatientById(int id){ + for (KennyPatient patient : patients) { + if (patient.getPatientId() == id) { + patient.displayInfo(); + return; //exits the method early + } + } + System.out.println("Patient not found."); + System.out.println("---------------------------"); + } + + //returns a patient object by the ID the user passes in + public KennyPatient getPatientById(int id) { + for (KennyPatient patient : patients) { + if (patient.getPatientId() == id) { + return patient; + } + } + return null; + } + + + //checks the patient in for their appointment + public void checkInPatient(KennyPatient patient) { + if (patient.isCheckedIn()) { + System.out.println("Patient already checked in."); + System.out.println("---------------------------"); + return; + } + + patient.setCheckedIn(true); + System.out.println("Patient checked in successfully."); + System.out.println("---------------------------"); + } + + //displays the statuses of all the appointments + public void dailySummary(String date) { + int total=0, completed=0, pending=0; + + for (MesheikAppointment appointment : appointments) { + if (appointment.getDate().equals(date)) { + total++; + + if (appointment.isCompleted()) { + completed++; + } else { + pending++; + } + } + } + + System.out.println("***** Daily Summary for " + date + "*****"); + System.out.println("Total Appointments: " + total); + System.out.println("Completed Appointments: " + completed); + System.out.println("Pending Appointments: " + pending); + System.out.println("---------------------------"); + } + +}// ends class diff --git a/src/main/java/org/codedifferently/KennyPatient.java b/src/main/java/org/codedifferently/KennyPatient.java new file mode 100644 index 0000000..befb4b0 --- /dev/null +++ b/src/main/java/org/codedifferently/KennyPatient.java @@ -0,0 +1,77 @@ +package org.codedifferently; + +import java.util.ArrayList; + +public class KennyPatient { + + //instance variables for the patient class + private String species; + + private String name; + + private boolean checkedIn; + + private String ownersPhoneNumber; + + private int patientId; + + private static int idCounter = 1; + + //constructor + public KennyPatient(String species, String name, boolean checkedIn, String ownersPhoneNumber) { + this.species = species; + + this.name = name; + + this.checkedIn = checkedIn; + + this.ownersPhoneNumber = ownersPhoneNumber; + + this.patientId = idCounter++; + } + + //getter methods for the instance variables + public String getSpecies() { + return species; + } + + public String getName() { + return name; + } + + public boolean isCheckedIn() { + return checkedIn; + } + + public int getPatientId() { + return patientId; + } + + public String getOwnersPhoneNumber(){return ownersPhoneNumber;} + + //getter methods for the instance variables + public void setCheckedIn(Boolean checkedIn) { + this.checkedIn = checkedIn; + } + + public void setName(String name) { + this.name = name; + } + + public void setOwnersPhoneNumber(String ownersPhoneNumber){ + this.ownersPhoneNumber = ownersPhoneNumber; + } + + public void setSpecies(String species){ + this.species = species; + } + + //displays the information of a single patient + public void displayInfo() { + System.out.println("Patient ID: " + patientId); + System.out.println("Pet Name: " + name); + System.out.println("Species: " + species); + System.out.println("Owner's Phone Number: " + ownersPhoneNumber); + System.out.println("Checked In: " + checkedIn); + System.out.println("---------------------------"); } +} 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/MesheikAppointment.java b/src/main/java/org/codedifferently/MesheikAppointment.java new file mode 100644 index 0000000..6562b6d --- /dev/null +++ b/src/main/java/org/codedifferently/MesheikAppointment.java @@ -0,0 +1,60 @@ +package org.codedifferently; + +// This class represents one appointment +public class MesheikAppointment { + + //Setting our appointment variables up + private String date; + private String time; + private String reason; + private boolean completed; + private KennyPatient patient; + + + + // Constructor runs when an appointment is created + public MesheikAppointment(String date, String time, String reason ,KennyPatient patient){ + this.date = date; + this.time = time; + this.reason = reason; + this.completed = false; + this.patient = patient; + } + + //Getters: how we get our appointments + public String getDate() { + return date; + } + + public String getTime() { + return time; + } + + public String getReason() { + return reason; + } + + public boolean isCompleted() { + return completed; + } + + + //Setters: How we change or update our appointments + public void setDate(String date) { + this.date = date; + } + + public void setTime(String time) { + this.time = time; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public void markCompleted() { + this.completed = true; + } + + +}//ends class