diff --git a/src/main/java/org/codedifferently/LanAppointment.java b/src/main/java/org/codedifferently/LanAppointment.java new file mode 100644 index 0000000..438ea0e --- /dev/null +++ b/src/main/java/org/codedifferently/LanAppointment.java @@ -0,0 +1,28 @@ +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() { isCompleted = true; } + + public String toString() { + 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 new file mode 100644 index 0000000..e1c7239 --- /dev/null +++ b/src/main/java/org/codedifferently/LanClinicApp.java @@ -0,0 +1,105 @@ +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=== 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) { + + case "1": + System.out.print("Name: "); + clinic.addPatient(sc.nextLine()); + break; + + case "2": + clinic.viewAllPatients(); + break; + + case "3": + System.out.print("ID or Name: "); + clinic.checkInPatient(sc.nextLine()); + break; + + case "4": + System.out.println("================================"); + System.out.print("ID or Name: "); + System.out.println(clinic.searchPatient(sc.nextLine())); + break; + + case "5": + System.out.println("================================"); + System.out.print("Patient ID: "); + clinic.scheduleAppointment(sc.nextLine()); + break; + + case "6": + System.out.println("================================="); + System.out.print("Patient ID: "); + clinic.cancelAppointment(sc.nextLine()); + break; + + case "7": + clinic.viewSchedule(); + break; + + case "8": + clinic.dailySummary(); + break; + + case "9": + running = false; + break; + + 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; + } + } + + 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..20ab15c --- /dev/null +++ b/src/main/java/org/codedifferently/LanClinicSystem.java @@ -0,0 +1,270 @@ +package org.codedifferently; + +import java.time.*; +import java.time.format.DateTimeFormatter; +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 ---------------- + + public void addPatient(String name) { + 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."); + return; + } + for (LanPatient p : patients) { + System.out.println(p); + } + } + + public LanPatient searchPatient(String input) { + for (LanPatient p : patients) { + if (p.getID().equalsIgnoreCase(input) + || p.getName().equalsIgnoreCase(input)) { + return p; + } + } + return null; + } + + 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."); + } + } + + // ---------------- 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"); + + try { + + LocalDate today = LocalDate.now(); + LocalDate maxDate = today.plusDays(7); + + System.out.print("Enter date (yyyy-MM-dd): "); + LocalDate date = LocalDate.parse(sc.nextLine()); + + if (date.isBefore(today) || date.isAfter(maxDate)) { + System.out.println("Must be within 7 days."); + return; + } + + if (hasAppointmentSameDay(patientID, date)) { + System.out.println("Already has appointment that day."); + 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(date, start)); + start = start.plusMinutes(30); + } + + System.out.println("\n--- Time Slots ---"); + for (int i=0;i slots.size()) return; + + 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("Invalid input."); + } + } + + // ---------------- CANCEL ---------------- + + public void cancelAppointment(String patientID) { + + Scanner sc = new Scanner(System.in); + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + + try { + + System.out.print("Enter date/time: "); + LocalDateTime time = + LocalDateTime.parse(sc.nextLine(), formatter); + + LanAppointment remove = null; + + for (LanAppointment a : appointments) { + if (a.getPatientID().equals(patientID) + && a.getTime().equals(time)) { + remove = a; + break; + } + } + + 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 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."); + return; + } + + appointments.sort(Comparator.comparing(LanAppointment::getTime)); + + for (LanAppointment a : appointments) { + System.out.println(a); + } + } + + public void dailySummary() { + + LocalDate today = LocalDate.now(); + + int total = 0; + int completed = 0; + + for (LanAppointment a : appointments) { + if (a.getTime().toLocalDate().equals(today)) { + total++; + if (a.isCompleted()) 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 new file mode 100644 index 0000000..f37f0cd --- /dev/null +++ b/src/main/java/org/codedifferently/LanPatient.java @@ -0,0 +1,33 @@ +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() { isCheckedIn = true; } + public void checkOut() { isCheckedIn = false; } + + public String toString() { + return "ID: " + ID + " | Name: " + name + + " | Checked In: " + isCheckedIn; + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/MichaelPatient.java b/src/main/java/org/codedifferently/MichaelPatient.java new file mode 100644 index 0000000..6cc3f3d --- /dev/null +++ b/src/main/java/org/codedifferently/MichaelPatient.java @@ -0,0 +1,28 @@ +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; + + } + + +}