From 750aff65f973f2451ad9a9caf3c545893b97b5d4 Mon Sep 17 00:00:00 2001 From: michaelmoss Date: Thu, 19 Feb 2026 15:47:31 -0500 Subject: [PATCH 1/5] ibitial patient class --- .../org/codedifferently/MichaelPatient.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/org/codedifferently/MichaelPatient.java diff --git a/src/main/java/org/codedifferently/MichaelPatient.java b/src/main/java/org/codedifferently/MichaelPatient.java new file mode 100644 index 0000000..5e0d85b --- /dev/null +++ b/src/main/java/org/codedifferently/MichaelPatient.java @@ -0,0 +1,27 @@ +package org.codedifferently; + +public class MichaelPatient { + + private String name; + private String ID; + private boolean isCheckedIn; + + MichaelPatient(String Name, String ID, boolean isCheckedIn) { + this.name=Name; + this.ID=ID; + this.isCheckedIn=false; + + + } + + public void setName(String name) { + this.name=name; + + } + + public void setID(String ID) { + this.ID=ID; + + } + +} From 62855f9c836b4b33948ef127950f1620e3a655b0 Mon Sep 17 00:00:00 2001 From: michaelmoss Date: Thu, 19 Feb 2026 16:01:27 -0500 Subject: [PATCH 2/5] initial patient --- src/main/java/org/codedifferently/MichaelPatient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/MichaelPatient.java b/src/main/java/org/codedifferently/MichaelPatient.java index 5e0d85b..3d26b1a 100644 --- a/src/main/java/org/codedifferently/MichaelPatient.java +++ b/src/main/java/org/codedifferently/MichaelPatient.java @@ -23,5 +23,5 @@ public void setID(String ID) { this.ID=ID; } - +// } From ad99b0a46ddd86832703b2471ae3109791534ab8 Mon Sep 17 00:00:00 2001 From: michaelmoss Date: Thu, 19 Feb 2026 16:02:32 -0500 Subject: [PATCH 3/5] initial commit --- src/main/java/org/codedifferently/MichaelPatient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/codedifferently/MichaelPatient.java b/src/main/java/org/codedifferently/MichaelPatient.java index 3d26b1a..de0556c 100644 --- a/src/main/java/org/codedifferently/MichaelPatient.java +++ b/src/main/java/org/codedifferently/MichaelPatient.java @@ -24,4 +24,5 @@ public void setID(String ID) { } // + // } From ea2d56f1ba4a0ba26bf1d1ba83b1797185541346 Mon Sep 17 00:00:00 2001 From: Lnguyen135 Date: Sun, 22 Feb 2026 15:09:15 -0500 Subject: [PATCH 4/5] initial commit --- .../org/codedifferently/LanAppointment.java | 37 ++++ .../org/codedifferently/LanClinicApp.java | 92 +++++++++ .../org/codedifferently/LanClinicSystem.java | 194 ++++++++++++++++++ .../java/org/codedifferently/LanPatient.java | 45 ++++ .../org/codedifferently/MichaelPatient.java | 6 +- 5 files changed, 371 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/codedifferently/LanAppointment.java create mode 100644 src/main/java/org/codedifferently/LanClinicApp.java create mode 100644 src/main/java/org/codedifferently/LanClinicSystem.java create mode 100644 src/main/java/org/codedifferently/LanPatient.java diff --git a/src/main/java/org/codedifferently/LanAppointment.java b/src/main/java/org/codedifferently/LanAppointment.java new file mode 100644 index 0000000..656e55f --- /dev/null +++ b/src/main/java/org/codedifferently/LanAppointment.java @@ -0,0 +1,37 @@ +package org.codedifferently; + +import java.time.LocalDateTime; + +public class LanAppointment { + private String patientID; + private LocalDateTime time; + private boolean isCompleted; + + public LanAppointment(String patientID, LocalDateTime time) { + this.patientID = patientID; + this.time = time; + this.isCompleted = false; + } + + public String getPatientID() { + return patientID; + } + + public LocalDateTime getTime() { + return time; + } + + public boolean isCompleted() { + return isCompleted; + } + + public void complete() { + this.isCompleted = true; + } + + @Override + public String toString() { + return "Appointment for Patient ID: " + patientID + " at " + time + " | Completed: " + isCompleted; + } +} + diff --git a/src/main/java/org/codedifferently/LanClinicApp.java b/src/main/java/org/codedifferently/LanClinicApp.java new file mode 100644 index 0000000..cda1f0b --- /dev/null +++ b/src/main/java/org/codedifferently/LanClinicApp.java @@ -0,0 +1,92 @@ +package org.codedifferently; + +import java.util.Scanner; + +public class LanClinicApp { + public static void main(String[] args) { + + LanClinicSystem clinic = new LanClinicSystem(); + Scanner sc = new Scanner(System.in); + + boolean running = true; + + while (running) { + System.out.println("\n=== Community Clinic System ==="); + 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 Patient"); + System.out.println("5. Schedule Appointment"); + System.out.println("6. Cancel Appointment"); + System.out.println("7. View Schedule"); + System.out.println("8. Daily Summary Report"); + System.out.println("9. Exit"); + System.out.print("Select option: "); + + String choice = sc.nextLine(); + + switch (choice) { + case "1": + System.out.print("Enter patient name: "); + String name = sc.nextLine(); + clinic.addPatient(name); + break; + + case "2": + clinic.viewAllPatients(); + break; + + case "3": + System.out.print("Enter patient ID or name: "); + String checkInID = sc.nextLine(); + clinic.checkInPatient(checkInID); + break; + + case "4": + System.out.print("Enter patient ID or name to search: "); + String searchID = sc.nextLine(); + LanPatient patient = clinic.searchPatient(searchID); + if (patient != null) { + System.out.println(patient); + } else { + System.out.println("Patient not found."); + } + break; + + case "5": + System.out.print("Enter patient ID: "); + String pid = sc.nextLine(); + if (clinic.searchPatient(pid) != null) { + clinic.scheduleAppointment(pid); + } else { + System.out.println("Patient not found. Please add the patient first."); + } + break; + + case "6": + System.out.print("Enter patient ID: "); + String cancelID = sc.nextLine(); + clinic.cancelAppointment(cancelID); + break; + + case "7": + clinic.viewSchedule(); + break; + + case "8": + clinic.dailySummary(); + break; + + case "9": + running = false; + System.out.println("Exiting system..."); + break; + + default: + System.out.println("Invalid option, try again."); + } + } + + sc.close(); + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/LanClinicSystem.java b/src/main/java/org/codedifferently/LanClinicSystem.java new file mode 100644 index 0000000..74539bd --- /dev/null +++ b/src/main/java/org/codedifferently/LanClinicSystem.java @@ -0,0 +1,194 @@ +package org.codedifferently; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Scanner; + +public class LanClinicSystem { + private ArrayList patients; + private ArrayList appointments; + + public LanClinicSystem() { + patients = new ArrayList<>(); + appointments = new ArrayList<>(); + } + + // ----------------- PATIENT METHODS ----------------- + + public void addPatient(String name) { + LanPatient patient = new LanPatient(name); + patients.add(patient); + System.out.println("Patient added successfully. ID: " + patient.getID()); + } + + public void viewAllPatients() { + if (patients.isEmpty()) { + System.out.println("No patients in system."); + return; + } + for (LanPatient p : patients) { + System.out.println(p); + } + } + + public LanPatient searchPatient(String idOrName) { + for (LanPatient p : patients) { + if (p.getID().equalsIgnoreCase(idOrName) || p.getName().equalsIgnoreCase(idOrName)) { + return p; + } + } + return null; + } + + public void checkInPatient(String idOrName) { + LanPatient p = searchPatient(idOrName); + if (p != null) { + if (!p.isCheckedIn()) { + p.checkIn(); + System.out.println("Patient " + p.getName() + " checked in successfully."); + } else { + System.out.println("Patient is already checked in."); + } + } else { + System.out.println("Patient not found."); + } + } + + // ----------------- APPOINTMENT METHODS ----------------- + + public void scheduleAppointment(String patientID) { + Scanner sc = new Scanner(System.in); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + + LocalDate today = LocalDate.now(); + LocalDate maxDate = today.plusDays(7); + + System.out.println("Schedule an appointment for Patient ID: " + patientID); + System.out.println("Appointments can only be scheduled within the next 7 days."); + + LocalDate chosenDate = null; + while (true) { + try { + System.out.print("Enter appointment date (yyyy-MM-dd): "); + String dateInput = sc.nextLine(); + chosenDate = LocalDate.parse(dateInput, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + + if (chosenDate.isBefore(today) || chosenDate.isAfter(maxDate)) { + System.out.println("Date must be within the next 7 days!"); + } else { + break; + } + } catch (Exception e) { + System.out.println("Invalid date format."); + } + } + + ArrayList slots = new ArrayList<>(); + LocalTime start = LocalTime.of(9, 0); + LocalTime end = LocalTime.of(17, 0); + while (!start.isAfter(end.minusMinutes(30))) { + slots.add(LocalDateTime.of(chosenDate, start)); + start = start.plusMinutes(30); + } + + ArrayList availableSlots = new ArrayList<>(); + for (LocalDateTime slot : slots) { + boolean taken = false; + for (LanAppointment a : appointments) { + if (a.getTime().equals(slot)) { + taken = true; + break; + } + } + if (!taken) availableSlots.add(slot); + } + + if (availableSlots.isEmpty()) { + System.out.println("No available slots on this day. Choose another day."); + return; + } + + System.out.println("Available time slots:"); + int idx = 1; + for (LocalDateTime slot : availableSlots) { + System.out.println(idx + ". " + slot.format(formatter)); + idx++; + } + + int slotChoice = -1; + while (true) { + try { + System.out.print("Select a slot number: "); + slotChoice = Integer.parseInt(sc.nextLine()); + if (slotChoice < 1 || slotChoice > availableSlots.size()) { + System.out.println("Invalid choice. Try again."); + } else { + break; + } + } catch (Exception e) { + System.out.println("Enter a valid number."); + } + } + + LanAppointment appointment = new LanAppointment(patientID, availableSlots.get(slotChoice - 1)); + appointments.add(appointment); + System.out.println("Appointment scheduled for " + availableSlots.get(slotChoice - 1).format(formatter)); + } + + public void cancelAppointment(String patientID) { + Scanner sc = new Scanner(System.in); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + + System.out.print("Enter appointment date/time to cancel (yyyy-MM-dd HH:mm): "); + String input = sc.nextLine(); + try { + LocalDateTime time = LocalDateTime.parse(input, formatter); + LanAppointment toRemove = null; + for (LanAppointment a : appointments) { + if (a.getPatientID().equalsIgnoreCase(patientID) && a.getTime().equals(time)) { + toRemove = a; + break; + } + } + if (toRemove != null) { + appointments.remove(toRemove); + System.out.println("Appointment cancelled successfully."); + } else { + System.out.println("Appointment not found."); + } + } catch (Exception e) { + System.out.println("Invalid date/time format."); + } + } + + public void viewSchedule() { + if (appointments.isEmpty()) { + System.out.println("No appointments scheduled."); + return; + } + System.out.println("=== All Appointments ==="); + for (LanAppointment a : appointments) { + System.out.println(a); + } + } + + public void dailySummary() { + System.out.println("=== Daily Summary ==="); + System.out.println("Total Patients: " + patients.size()); + int checkedIn = 0; + for (LanPatient p : patients) { + if (p.isCheckedIn()) checkedIn++; + } + System.out.println("Checked-in Patients: " + checkedIn); + System.out.println("Appointments Today: " + appointments.size()); + int completed = 0; + for (LanAppointment a : appointments) { + if (a.isCompleted()) completed++; + } + System.out.println("Completed Appointments: " + completed); + } +} + diff --git a/src/main/java/org/codedifferently/LanPatient.java b/src/main/java/org/codedifferently/LanPatient.java new file mode 100644 index 0000000..3cf96bb --- /dev/null +++ b/src/main/java/org/codedifferently/LanPatient.java @@ -0,0 +1,45 @@ +package org.codedifferently; + +import java.util.UUID; + +public class LanPatient { + private String name; + private String ID; + private boolean isCheckedIn; + + public LanPatient(String name) { + this.name = name; + this.ID = generateID(name); + this.isCheckedIn = false; + } + + private String generateID(String name) { + return name.substring(0, 1).toUpperCase() + UUID.randomUUID().toString().substring(0, 5); + } + + public String getName() { + return name; + } + + public String getID() { + return ID; + } + + public boolean isCheckedIn() { + return isCheckedIn; + } + + public void checkIn() { + this.isCheckedIn = true; + } + + public void checkOut() { + this.isCheckedIn = false; + } + + @Override + public String toString() { + return "Patient ID: " + ID + ", Name: " + name + ", Checked-in: " + isCheckedIn; + } +} + diff --git a/src/main/java/org/codedifferently/MichaelPatient.java b/src/main/java/org/codedifferently/MichaelPatient.java index de0556c..6cc3f3d 100644 --- a/src/main/java/org/codedifferently/MichaelPatient.java +++ b/src/main/java/org/codedifferently/MichaelPatient.java @@ -1,6 +1,6 @@ package org.codedifferently; -public class MichaelPatient { +public class MichaelPatient { private String name; private String ID; @@ -23,6 +23,6 @@ public void setID(String ID) { this.ID=ID; } -// - // + + } From 11f662505958f8063b31a4b8ba332081a1c2f72d Mon Sep 17 00:00:00 2001 From: Lnguyen135 Date: Tue, 24 Feb 2026 23:30:13 -0500 Subject: [PATCH 5/5] try to push again --- .../org/codedifferently/LanAppointment.java | 27 +- .../org/codedifferently/LanClinicApp.java | 91 +++--- .../org/codedifferently/LanClinicSystem.java | 296 +++++++++++------- .../java/org/codedifferently/LanPatient.java | 34 +- 4 files changed, 258 insertions(+), 190 deletions(-) diff --git a/src/main/java/org/codedifferently/LanAppointment.java b/src/main/java/org/codedifferently/LanAppointment.java index 656e55f..438ea0e 100644 --- a/src/main/java/org/codedifferently/LanAppointment.java +++ b/src/main/java/org/codedifferently/LanAppointment.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; public class LanAppointment { + private String patientID; private LocalDateTime time; private boolean isCompleted; @@ -13,25 +14,15 @@ public LanAppointment(String patientID, LocalDateTime time) { this.isCompleted = false; } - public String getPatientID() { - return patientID; - } - - public LocalDateTime getTime() { - return time; - } - - public boolean isCompleted() { - return isCompleted; - } + public String getPatientID() { return patientID; } + public LocalDateTime getTime() { return time; } + public boolean isCompleted() { return isCompleted; } - public void complete() { - this.isCompleted = true; - } + public void complete() { isCompleted = true; } - @Override public String toString() { - return "Appointment for Patient ID: " + patientID + " at " + time + " | Completed: " + isCompleted; + return "PatientID: " + patientID + + " | Time: " + time + + " | Completed: " + isCompleted; } -} - +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/LanClinicApp.java b/src/main/java/org/codedifferently/LanClinicApp.java index cda1f0b..e1c7239 100644 --- a/src/main/java/org/codedifferently/LanClinicApp.java +++ b/src/main/java/org/codedifferently/LanClinicApp.java @@ -1,35 +1,45 @@ package org.codedifferently; import java.util.Scanner; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; public class LanClinicApp { + public static void main(String[] args) { LanClinicSystem clinic = new LanClinicSystem(); Scanner sc = new Scanner(System.in); + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + boolean running = true; while (running) { - System.out.println("\n=== Community Clinic System ==="); - 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 Patient"); - System.out.println("5. Schedule Appointment"); - System.out.println("6. Cancel Appointment"); - System.out.println("7. View Schedule"); - System.out.println("8. Daily Summary Report"); - System.out.println("9. Exit"); - System.out.print("Select option: "); + System.out.println("\n=== CLINIC MENU ==="); + System.out.println("1 Add Patient"); + System.out.println("2 View Patients"); + System.out.println("3 Check In Patient"); + System.out.println("4 Search Patient"); + System.out.println("5 Schedule Appointment"); + System.out.println("6 Cancel Appointment"); + System.out.println("7 View Schedule"); + System.out.println("8 Daily Report"); + System.out.println("9 Exit"); + System.out.println("10 Complete Appointment"); + + + System.out.print("Choice: "); + System.out.println("===========================================1"); String choice = sc.nextLine(); - switch (choice) { + switch(choice) { + case "1": - System.out.print("Enter patient name: "); - String name = sc.nextLine(); - clinic.addPatient(name); + System.out.print("Name: "); + clinic.addPatient(sc.nextLine()); break; case "2": @@ -37,36 +47,26 @@ public static void main(String[] args) { break; case "3": - System.out.print("Enter patient ID or name: "); - String checkInID = sc.nextLine(); - clinic.checkInPatient(checkInID); + System.out.print("ID or Name: "); + clinic.checkInPatient(sc.nextLine()); break; case "4": - System.out.print("Enter patient ID or name to search: "); - String searchID = sc.nextLine(); - LanPatient patient = clinic.searchPatient(searchID); - if (patient != null) { - System.out.println(patient); - } else { - System.out.println("Patient not found."); - } + System.out.println("================================"); + System.out.print("ID or Name: "); + System.out.println(clinic.searchPatient(sc.nextLine())); break; case "5": - System.out.print("Enter patient ID: "); - String pid = sc.nextLine(); - if (clinic.searchPatient(pid) != null) { - clinic.scheduleAppointment(pid); - } else { - System.out.println("Patient not found. Please add the patient first."); - } + System.out.println("================================"); + System.out.print("Patient ID: "); + clinic.scheduleAppointment(sc.nextLine()); break; case "6": - System.out.print("Enter patient ID: "); - String cancelID = sc.nextLine(); - clinic.cancelAppointment(cancelID); + System.out.println("================================="); + System.out.print("Patient ID: "); + clinic.cancelAppointment(sc.nextLine()); break; case "7": @@ -79,11 +79,24 @@ public static void main(String[] args) { case "9": running = false; - System.out.println("Exiting system..."); break; - default: - System.out.println("Invalid option, try again."); + case "10": + try { + System.out.println("============================="); + System.out.print("Patient ID: "); + String id = sc.nextLine(); + + System.out.print("DateTime yyyy-MM-dd HH:mm: "); + LocalDateTime time = + LocalDateTime.parse(sc.nextLine(), formatter); + + clinic.completeAppointment(id, time); + + } catch(Exception e) { + System.out.println("Invalid format."); + } + break; } } diff --git a/src/main/java/org/codedifferently/LanClinicSystem.java b/src/main/java/org/codedifferently/LanClinicSystem.java index 74539bd..20ab15c 100644 --- a/src/main/java/org/codedifferently/LanClinicSystem.java +++ b/src/main/java/org/codedifferently/LanClinicSystem.java @@ -1,32 +1,32 @@ package org.codedifferently; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; +import java.time.*; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Scanner; +import java.util.*; public class LanClinicSystem { + private ArrayList patients; private ArrayList appointments; + private HashMap> waitlistMap; public LanClinicSystem() { patients = new ArrayList<>(); appointments = new ArrayList<>(); + waitlistMap = new HashMap<>(); } - // ----------------- PATIENT METHODS ----------------- + // ---------------- PATIENT ---------------- public void addPatient(String name) { - LanPatient patient = new LanPatient(name); - patients.add(patient); - System.out.println("Patient added successfully. ID: " + patient.getID()); + LanPatient p = new LanPatient(name); + patients.add(p); + System.out.println("Patient added. ID: " + p.getID()); } public void viewAllPatients() { if (patients.isEmpty()) { - System.out.println("No patients in system."); + System.out.println("No patients."); return; } for (LanPatient p : patients) { @@ -34,161 +34,237 @@ public void viewAllPatients() { } } - public LanPatient searchPatient(String idOrName) { + public LanPatient searchPatient(String input) { for (LanPatient p : patients) { - if (p.getID().equalsIgnoreCase(idOrName) || p.getName().equalsIgnoreCase(idOrName)) { + if (p.getID().equalsIgnoreCase(input) + || p.getName().equalsIgnoreCase(input)) { return p; } } return null; } - public void checkInPatient(String idOrName) { - LanPatient p = searchPatient(idOrName); - if (p != null) { - if (!p.isCheckedIn()) { - p.checkIn(); - System.out.println("Patient " + p.getName() + " checked in successfully."); - } else { - System.out.println("Patient is already checked in."); - } - } else { + public void checkInPatient(String input) { + LanPatient p = searchPatient(input); + if (p == null) { System.out.println("Patient not found."); + return; + } + + if (p.isCheckedIn()) { + System.out.println("Already checked in."); + } else { + p.checkIn(); + System.out.println("Checked in."); } } - // ----------------- APPOINTMENT METHODS ----------------- + // ---------------- VALIDATION ---------------- + + private boolean isSlotAvailable(LocalDateTime time) { + for (LanAppointment a : appointments) { + if (a.getTime().equals(time)) return false; + } + return true; + } + + private boolean hasAppointmentSameDay(String patientID, LocalDate date) { + for (LanAppointment a : appointments) { + if (a.getPatientID().equals(patientID) + && a.getTime().toLocalDate().equals(date)) { + return true; + } + } + return false; + } + + // ---------------- SCHEDULE ---------------- public void scheduleAppointment(String patientID) { + Scanner sc = new Scanner(System.in); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); - LocalDate today = LocalDate.now(); - LocalDate maxDate = today.plusDays(7); + try { - System.out.println("Schedule an appointment for Patient ID: " + patientID); - System.out.println("Appointments can only be scheduled within the next 7 days."); + LocalDate today = LocalDate.now(); + LocalDate maxDate = today.plusDays(7); - LocalDate chosenDate = null; - while (true) { - try { - System.out.print("Enter appointment date (yyyy-MM-dd): "); - String dateInput = sc.nextLine(); - chosenDate = LocalDate.parse(dateInput, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + System.out.print("Enter date (yyyy-MM-dd): "); + LocalDate date = LocalDate.parse(sc.nextLine()); - if (chosenDate.isBefore(today) || chosenDate.isAfter(maxDate)) { - System.out.println("Date must be within the next 7 days!"); - } else { - break; - } - } catch (Exception e) { - System.out.println("Invalid date format."); + if (date.isBefore(today) || date.isAfter(maxDate)) { + System.out.println("Must be within 7 days."); + return; } - } - ArrayList slots = new ArrayList<>(); - LocalTime start = LocalTime.of(9, 0); - LocalTime end = LocalTime.of(17, 0); - while (!start.isAfter(end.minusMinutes(30))) { - slots.add(LocalDateTime.of(chosenDate, start)); - start = start.plusMinutes(30); - } + if (hasAppointmentSameDay(patientID, date)) { + System.out.println("Already has appointment that day."); + return; + } - ArrayList availableSlots = new ArrayList<>(); - for (LocalDateTime slot : slots) { - boolean taken = false; - for (LanAppointment a : appointments) { - if (a.getTime().equals(slot)) { - taken = true; - break; + ArrayList slots = new ArrayList<>(); + LocalTime start = LocalTime.of(9,0); + LocalTime end = LocalTime.of(17,0); + + while (!start.isAfter(end.minusMinutes(30))) { + slots.add(LocalDateTime.of(date, start)); + start = start.plusMinutes(30); + } + + System.out.println("\n--- Time Slots ---"); + for (int i=0;i slots.size()) return; - int slotChoice = -1; - while (true) { - try { - System.out.print("Select a slot number: "); - slotChoice = Integer.parseInt(sc.nextLine()); - if (slotChoice < 1 || slotChoice > availableSlots.size()) { - System.out.println("Invalid choice. Try again."); - } else { - break; + LocalDateTime chosen = slots.get(choice-1); + + if (isSlotAvailable(chosen)) { + + appointments.add(new LanAppointment(patientID, chosen)); + System.out.println("Appointment scheduled."); + + } else { + + System.out.print("Join waitlist? (Y/N): "); + String ans = sc.nextLine(); + + if (ans.equalsIgnoreCase("Y")) { + waitlistMap.putIfAbsent(chosen, new LinkedList<>()); + waitlistMap.get(chosen).add(patientID); + System.out.println("Added to waitlist."); } - } catch (Exception e) { - System.out.println("Enter a valid number."); } - } - LanAppointment appointment = new LanAppointment(patientID, availableSlots.get(slotChoice - 1)); - appointments.add(appointment); - System.out.println("Appointment scheduled for " + availableSlots.get(slotChoice - 1).format(formatter)); + } catch (Exception e) { + System.out.println("Invalid input."); + } } + // ---------------- CANCEL ---------------- + public void cancelAppointment(String patientID) { + Scanner sc = new Scanner(System.in); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); - System.out.print("Enter appointment date/time to cancel (yyyy-MM-dd HH:mm): "); - String input = sc.nextLine(); try { - LocalDateTime time = LocalDateTime.parse(input, formatter); - LanAppointment toRemove = null; + + System.out.print("Enter date/time: "); + LocalDateTime time = + LocalDateTime.parse(sc.nextLine(), formatter); + + LanAppointment remove = null; + for (LanAppointment a : appointments) { - if (a.getPatientID().equalsIgnoreCase(patientID) && a.getTime().equals(time)) { - toRemove = a; + if (a.getPatientID().equals(patientID) + && a.getTime().equals(time)) { + remove = a; break; } } - if (toRemove != null) { - appointments.remove(toRemove); - System.out.println("Appointment cancelled successfully."); - } else { - System.out.println("Appointment not found."); + + if (remove == null) { + System.out.println("Not found."); + return; } + + appointments.remove(remove); + System.out.println("Cancelled."); + + // WAITLIST AUTO FILL + if (waitlistMap.containsKey(time)) { + + Queue queue = waitlistMap.get(time); + + if (!queue.isEmpty()) { + + String next = queue.poll(); + appointments.add(new LanAppointment(next, time)); + + System.out.println("Waitlist patient auto-booked."); + + if (queue.isEmpty()) { + waitlistMap.remove(time); + } + } + } + } catch (Exception e) { - System.out.println("Invalid date/time format."); + System.out.println("Invalid format."); + } + } + + // ---------------- COMPLETE ---------------- + + public void completeAppointment(String patientID, LocalDateTime time) { + + for (LanAppointment a : appointments) { + + if (a.getPatientID().equals(patientID) + && a.getTime().equals(time)) { + + LanPatient p = searchPatient(patientID); + + if (!p.isCheckedIn()) { + System.out.println("Patient must check in first."); + return; + } + + a.complete(); + p.checkOut(); + System.out.println("Appointment completed."); + return; + } } + + System.out.println("Appointment not found."); } + // ---------------- VIEW ---------------- + public void viewSchedule() { + if (appointments.isEmpty()) { - System.out.println("No appointments scheduled."); + System.out.println("No appointments."); return; } - System.out.println("=== All Appointments ==="); + + appointments.sort(Comparator.comparing(LanAppointment::getTime)); + for (LanAppointment a : appointments) { System.out.println(a); } } public void dailySummary() { - System.out.println("=== Daily Summary ==="); - System.out.println("Total Patients: " + patients.size()); - int checkedIn = 0; - for (LanPatient p : patients) { - if (p.isCheckedIn()) checkedIn++; - } - System.out.println("Checked-in Patients: " + checkedIn); - System.out.println("Appointments Today: " + appointments.size()); + + LocalDate today = LocalDate.now(); + + int total = 0; int completed = 0; + for (LanAppointment a : appointments) { - if (a.isCompleted()) completed++; + if (a.getTime().toLocalDate().equals(today)) { + total++; + if (a.isCompleted()) completed++; + } } - System.out.println("Completed Appointments: " + completed); - } -} + System.out.println("Appointments Today: " + total); + System.out.println("Completed Today: " + completed); + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/LanPatient.java b/src/main/java/org/codedifferently/LanPatient.java index 3cf96bb..f37f0cd 100644 --- a/src/main/java/org/codedifferently/LanPatient.java +++ b/src/main/java/org/codedifferently/LanPatient.java @@ -3,6 +3,7 @@ import java.util.UUID; public class LanPatient { + private String name; private String ID; private boolean isCheckedIn; @@ -14,32 +15,19 @@ public LanPatient(String name) { } private String generateID(String name) { - return name.substring(0, 1).toUpperCase() + UUID.randomUUID().toString().substring(0, 5); - } - - public String getName() { - return name; + return name.substring(0,1).toUpperCase() + + UUID.randomUUID().toString().substring(0,5); } - public String getID() { - return ID; - } + public String getName() { return name; } + public String getID() { return ID; } + public boolean isCheckedIn() { return isCheckedIn; } - public boolean isCheckedIn() { - return isCheckedIn; - } + public void checkIn() { isCheckedIn = true; } + public void checkOut() { isCheckedIn = false; } - public void checkIn() { - this.isCheckedIn = true; - } - - public void checkOut() { - this.isCheckedIn = false; - } - - @Override public String toString() { - return "Patient ID: " + ID + ", Name: " + name + ", Checked-in: " + isCheckedIn; + return "ID: " + ID + " | Name: " + name + + " | Checked In: " + isCheckedIn; } -} - +} \ No newline at end of file