diff --git a/docs/AboutUs.md b/docs/AboutUs.md new file mode 100644 index 000000000..0f072953e --- /dev/null +++ b/docs/AboutUs.md @@ -0,0 +1,9 @@ +# About us + +Display | Name | Github Profile | Portfolio +--------|:----:|:--------------:|:---------: +![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) diff --git a/docs/ByeCommand.png b/docs/ByeCommand.png new file mode 100644 index 000000000..fa90843be Binary files /dev/null and b/docs/ByeCommand.png differ diff --git a/docs/ByeCommand.puml b/docs/ByeCommand.puml new file mode 100644 index 000000000..8429c889b --- /dev/null +++ b/docs/ByeCommand.puml @@ -0,0 +1,13 @@ +@startuml +'https://plantuml.com/sequence-diagram + + +User -> ":Duke": bye +":Duke" -> ":parser": getCommand() +":parser" --> ":Duke": fullCommand +":Duke" -> ":Ui": sayGoodbye() +":Ui" --> ":Duke": Goodbye message +":Duke" --> User: Goodbye message + + +@enduml \ No newline at end of file diff --git a/docs/ClassDiagram.puml b/docs/ClassDiagram.puml new file mode 100644 index 000000000..b101c5c19 --- /dev/null +++ b/docs/ClassDiagram.puml @@ -0,0 +1,40 @@ +@startuml +'https://plantuml.com/class-diagram + +abstract class AbstractList +abstract AbstractCollection +interface List +interface Collection + +List <|-- AbstractList +Collection <|-- AbstractCollection + +Collection <|- List +AbstractCollection <|- AbstractList +AbstractList <|-- ArrayList + +class DoctorList { +doctors: ArrayList +size: Integer +DoctorList() +getDoctor(index: Integer): Person +addDoctor(doctor: Doctor) +deleteDoctor(index: Integer) +toString(): String +} + +class Person { + +} + +class Doctor { + +} + +enum TimeUnit { +DAYS +HOURS +MINUTES +} + +@enduml \ No newline at end of file diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md new file mode 100644 index 000000000..f7adbc951 --- /dev/null +++ b/docs/DeveloperGuide.md @@ -0,0 +1,47 @@ +# Developer Guide + +## Acknowledgements + +{list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the original source as well} + +## Design & implementation + +{Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.} + +### Exit program +Step 1: User type "bye" as input to exit the program. Duke will call Parser#getCommand() +to return the user command received. + +Step 2: After checking the user command is "bye", Duke will +call Ui#sayGoodbye to print Goodbye message + +The following sequence diagram shows how the exit operation works: +![](ByeCommand.png) + +## Product scope +### Target user profile +Hospital admin staff + +### Value proposition +IHospital is a desktop application meant for staff in hospitals. Its main purpose is to manage patients, +doctors, nurses, appointments and operation rooms data, and it’s optimised for use via a Command Line Interface (CLI). +If you can type fast, this application allows you to access relevant hospital information faster than traditional GUI applications. + +## User Stories + +|Version| As a ... | I want to ... | So that I can ...| +|--------|----------|---------------|------------------| +|v1.0|new user|see usage instructions|refer to them when I forget how to use the application| +|v2.0|user|find a to-do item by name|locate a to-do without having to go through the entire list| + +## Non-Functional Requirements + +{Give non-functional requirements} + +## Glossary + +* *glossary item* - Definition + +## Instructions for manual testing + +{Give instructions on how to do a manual product testing e.g., how to load sample data to be used for testing} diff --git a/docs/README.md b/docs/README.md index 8077118eb..c85cbae1f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,8 @@ -# User Guide +# IHospital -## Features +{Give product intro here} -### Feature-ABC - -Description of the feature. - -### Feature-XYZ - -Description of the feature. - -## Usage - -### `Keyword` - Describe action - -Describe the action and its outcome. - -Example of usage: - -`keyword (optional arguments)` - -Expected outcome: - -Description of the outcome. - -``` -expected output -``` +Useful links: +* [User Guide](UserGuide.md) +* [Developer Guide](DeveloperGuide.md) +* [About Us](AboutUs.md) diff --git a/docs/UserGuide.md b/docs/UserGuide.md new file mode 100644 index 000000000..abd9fbe89 --- /dev/null +++ b/docs/UserGuide.md @@ -0,0 +1,42 @@ +# User Guide + +## Introduction + +{Give a product intro} + +## Quick Start + +{Give steps to get started quickly} + +1. Ensure that you have Java 11 or above installed. +1. Down the latest version of `Duke` from [here](http://link.to/duke). + +## Features + +{Give detailed description of each feature} + +### Adding a todo: `todo` +Adds a new item to the list of todo items. + +Format: `todo n/TODO_NAME d/DEADLINE` + +* The `DEADLINE` can be in a natural language format. +* The `TODO_NAME` cannot contain punctuation. + +Example of usage: + +`todo n/Write the rest of the User Guide d/next week` + +`todo n/Refactor the User Guide to remove passive voice d/13/04/2020` + +## FAQ + +**Q**: How do I transfer my data to another computer? + +**A**: {your answer here} + +## Command Summary + +{Give a 'cheat sheet' of commands here} + +* Add todo `todo n/TODO_NAME d/DEADLINE` diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java new file mode 100644 index 000000000..5616b78ff --- /dev/null +++ b/src/main/java/seedu/duke/Duke.java @@ -0,0 +1,36 @@ +package seedu.duke; + +import tp.DoctorList; +import tp.Parser; +import tp.PatientList; +import tp.Ui; +import tp.AppointmentList; +import tp.Storage; +import tp.IHospitalException; +import tp.Command; +import tp.person.Patient; + +import java.util.Scanner; + +public class Duke { + /** + * Main entry-point for the java.duke.Duke application. + */ + private static final Ui ui = new Ui(); + private static final Parser parser = new Parser(); + private static PatientList patientList = new PatientList(); + private static DoctorList doctorList = new DoctorList(); + private static AppointmentList appointmentList = new AppointmentList(); + private static Storage storage = new Storage(); + + public static void main(String[] args) throws IHospitalException { + ui.sayHello(); + String fullCommand = parser.getCommand(); + while (!fullCommand.equals("bye")) { + Command command = parser.parse(fullCommand); + command.execute(doctorList, patientList, appointmentList, ui, storage); + fullCommand = parser.getCommand(); + } + ui.sayGoodbye(); + } +} diff --git a/src/main/java/tp/AddAppointmentCommand.java b/src/main/java/tp/AddAppointmentCommand.java new file mode 100644 index 000000000..a99d6759e --- /dev/null +++ b/src/main/java/tp/AddAppointmentCommand.java @@ -0,0 +1,31 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +import java.time.LocalDateTime; + +public class AddAppointmentCommand extends Command { + protected int doctorIndex; + protected int patientIndex; + protected LocalDateTime time; + + public AddAppointmentCommand() { + + } + + public AddAppointmentCommand(int doctorIndex, int patientIndex, String time) { + this.doctorIndex = doctorIndex; + this.patientIndex = patientIndex; + this.time = LocalDateTime.parse(time); + } + + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + Doctor doctor = (Doctor) doctorList.getDoctor(doctorIndex); + Patient patient = (Patient) patientList.getPatient(patientIndex); + appointmentList.addAppointment(doctor, patient, time); + } +} diff --git a/src/main/java/tp/AddDoctorCommand.java b/src/main/java/tp/AddDoctorCommand.java new file mode 100644 index 000000000..bdabf877d --- /dev/null +++ b/src/main/java/tp/AddDoctorCommand.java @@ -0,0 +1,29 @@ +package tp; + +import tp.person.Doctor; + +public class AddDoctorCommand extends Command { + protected String id; + protected String name; + protected String phoneNumber; + protected String email; + protected boolean isOnDuty; + + public AddDoctorCommand() { + } + + public AddDoctorCommand(String id, String name, String phoneNumber, String email, boolean isOnDuty) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + this.isOnDuty = isOnDuty; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + Doctor doctor = new Doctor(id, name, phoneNumber, email); + doctorList.addDoctor(doctor); + } +} diff --git a/src/main/java/tp/AddPatientCommand.java b/src/main/java/tp/AddPatientCommand.java new file mode 100644 index 000000000..fa3f20d62 --- /dev/null +++ b/src/main/java/tp/AddPatientCommand.java @@ -0,0 +1,28 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +public class AddPatientCommand extends Command { + protected String id; + protected String name; + protected String phoneNumber; + protected String email; + + public AddPatientCommand() { + } + + public AddPatientCommand(String id, String name, String phoneNumber, String email) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + Patient patient = new Patient(id, name, phoneNumber, email); + patientList.addPatient(patient); + } +} diff --git a/src/main/java/tp/Appointment.java b/src/main/java/tp/Appointment.java new file mode 100644 index 000000000..05f72429b --- /dev/null +++ b/src/main/java/tp/Appointment.java @@ -0,0 +1,24 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +import java.time.LocalDateTime; + +public class Appointment { + protected Doctor doctor; + protected Patient patient; + protected LocalDateTime time; + + public Appointment(Doctor doctor, Patient patient, LocalDateTime time) { + this.doctor = doctor; + this.patient = patient; + this.time = time; + } + + @Override + public String toString() { + return "Doctor: " + doctor.getName() + " || Patient: " + + patient.getName() + " || Appointment time: " + time; + } +} diff --git a/src/main/java/tp/AppointmentList.java b/src/main/java/tp/AppointmentList.java new file mode 100644 index 000000000..6d82ff937 --- /dev/null +++ b/src/main/java/tp/AppointmentList.java @@ -0,0 +1,64 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Patient; + +import java.time.LocalDateTime; +import java.util.ArrayList; + +public class AppointmentList { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + protected ArrayList appointments = new ArrayList<>(); + protected int countAppointment; + + public AppointmentList() { + countAppointment = 0; + } + + public Appointment getAppointment(int index) { + return appointments.get(index - 1); + } + + /** + * Adds an appointment to appointment list. + * + * @param doctor Doctor assigned for this appointment. + * @param patient Patient coming for this appointment. + * @param time The time reserved. + */ + public void addAppointment(Doctor doctor, Patient patient, LocalDateTime time) { + appointments.add(new Appointment(doctor, patient, time)); + countAppointment++; + System.out.println(boundary + "Noted. I've added this appointment:"); + System.out.println(appointments.get(countAppointment - 1)); + System.out.print("Now you have " + countAppointment + + " appointments recorded in the system." + System.lineSeparator() + boundary); + } + + /** + * Deletes an appointment from the list. + * + * @param index Index of the appointment to be deleted. + */ + public void deleteAppointment(int index) { + System.out.println(boundary + "Noted. I've removed this appointment:"); + System.out.println(appointments.get(index - 1)); + System.out.print("Now you have " + (countAppointment - 1) + + " appointments recorded in the system." + System.lineSeparator() + boundary); + appointments.remove(index - 1); + countAppointment -= 1; + } + + @Override + public String toString() { + String toPrint = boundary + "Here are the existing appointments:" + System.lineSeparator(); + for (int i = 1; i <= countAppointment; i++) { + toPrint += (i + ". " + getAppointment(i)); + } + toPrint += ("Now you have " + countAppointment + + " appointments recorded in the system." + System.lineSeparator() + + boundary + System.lineSeparator()); + return toPrint; + } +} \ No newline at end of file diff --git a/src/main/java/tp/Command.java b/src/main/java/tp/Command.java new file mode 100644 index 000000000..a57a18b08 --- /dev/null +++ b/src/main/java/tp/Command.java @@ -0,0 +1,11 @@ +package tp; + +public abstract class Command { + + public boolean isExit() { + return false; + } + + public abstract void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException; +} diff --git a/src/main/java/tp/DeleteAppointmentCommand.java b/src/main/java/tp/DeleteAppointmentCommand.java new file mode 100644 index 000000000..e7f600a26 --- /dev/null +++ b/src/main/java/tp/DeleteAppointmentCommand.java @@ -0,0 +1,19 @@ +package tp; + +public class DeleteAppointmentCommand extends Command { + int index; + + public DeleteAppointmentCommand(){ + + } + + public DeleteAppointmentCommand(int index) { + this.index = index; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + appointmentList.deleteAppointment(index); + } +} diff --git a/src/main/java/tp/DeleteDoctorCommand.java b/src/main/java/tp/DeleteDoctorCommand.java new file mode 100644 index 000000000..053de908e --- /dev/null +++ b/src/main/java/tp/DeleteDoctorCommand.java @@ -0,0 +1,15 @@ +package tp; + +public class DeleteDoctorCommand extends Command { + private final int index; + + public DeleteDoctorCommand(int index) { + this.index = index; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + doctorList.deleteDoctor(index); + } +} diff --git a/src/main/java/tp/DeletePatientCommand.java b/src/main/java/tp/DeletePatientCommand.java new file mode 100644 index 000000000..9d6131922 --- /dev/null +++ b/src/main/java/tp/DeletePatientCommand.java @@ -0,0 +1,15 @@ +package tp; + +public class DeletePatientCommand extends Command { + private final int index; + + public DeletePatientCommand(int index) { + this.index = index; + } + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + patientList.deletePatient(index); + } +} diff --git a/src/main/java/tp/DoctorList.java b/src/main/java/tp/DoctorList.java new file mode 100644 index 000000000..867beffd1 --- /dev/null +++ b/src/main/java/tp/DoctorList.java @@ -0,0 +1,51 @@ +package tp; + +import tp.person.Doctor; +import tp.person.Person; + +import javax.print.Doc; +import java.util.ArrayList; + +public class DoctorList { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + protected ArrayList doctors = new ArrayList<>(); + protected int size = 0; + + public DoctorList() { + size = 0; + } + + public Person getDoctor(int index) { + return doctors.get(index - 1); + } + + public void addDoctor(Doctor doctor) { + doctors.add(doctor); + size++; + System.out.println(boundary + "Noted. I've added this doctor:"); + System.out.println(doctors.get(size - 1)); + System.out.print("Now you have " + size + + " doctors recorded in the system." + System.lineSeparator() + boundary); + } + + public void deleteDoctor(int index) { + System.out.println(boundary + "Noted. I've removed this doctor:"); + System.out.println(doctors.get(index - 1)); + System.out.print("Now you have " + (size - 1) + + " doctors in the system." + System.lineSeparator() + boundary); + doctors.remove(index - 1); + size -= 1; + } + + @Override + public String toString() { + String toPrint = boundary + "Here are the doctors in this hospital:" + System.lineSeparator(); + for (int i = 1; i <= size; i++) { + toPrint += (i + ". " + getDoctor(i)); + } + toPrint += ("You have " + size + " doctors recorded in the system." + + System.lineSeparator() + boundary + System.lineSeparator()); + return toPrint; + } +} \ No newline at end of file diff --git a/src/main/java/tp/ExitCommand.java b/src/main/java/tp/ExitCommand.java new file mode 100644 index 000000000..7440eea6e --- /dev/null +++ b/src/main/java/tp/ExitCommand.java @@ -0,0 +1,14 @@ +package tp; + +public class ExitCommand extends Command { + public ExitCommand() { + + } + + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + return; + } +} \ No newline at end of file diff --git a/src/main/java/tp/IHospitalException.java b/src/main/java/tp/IHospitalException.java new file mode 100644 index 000000000..5aa0e8b08 --- /dev/null +++ b/src/main/java/tp/IHospitalException.java @@ -0,0 +1,13 @@ +package tp; + +public class IHospitalException extends Throwable { + public IHospitalException(String s) { + super(s); + } + + @Override + public String toString() { + return super.getMessage(); + } + +} diff --git a/src/main/java/tp/ListAppointmentListCommand.java b/src/main/java/tp/ListAppointmentListCommand.java new file mode 100644 index 000000000..4961b79dd --- /dev/null +++ b/src/main/java/tp/ListAppointmentListCommand.java @@ -0,0 +1,10 @@ +package tp; + +public class ListAppointmentListCommand extends Command { + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + System.out.print(appointmentList); + } +} diff --git a/src/main/java/tp/ListDoctorListCommand.java b/src/main/java/tp/ListDoctorListCommand.java new file mode 100644 index 000000000..13d8eb0a1 --- /dev/null +++ b/src/main/java/tp/ListDoctorListCommand.java @@ -0,0 +1,10 @@ +package tp; + +public class ListDoctorListCommand extends Command { + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + System.out.print(doctorList); + } +} diff --git a/src/main/java/tp/ListPatientListCommand.java b/src/main/java/tp/ListPatientListCommand.java new file mode 100644 index 000000000..4f221d24b --- /dev/null +++ b/src/main/java/tp/ListPatientListCommand.java @@ -0,0 +1,10 @@ +package tp; + +public class ListPatientListCommand extends Command { + + @Override + public void execute(DoctorList doctorList, PatientList patientList, + AppointmentList appointmentList, Ui ui, Storage storage) throws IHospitalException { + System.out.print(patientList); + } +} diff --git a/src/main/java/tp/Parser.java b/src/main/java/tp/Parser.java new file mode 100644 index 000000000..e52df641c --- /dev/null +++ b/src/main/java/tp/Parser.java @@ -0,0 +1,102 @@ +package tp; + +import java.util.Scanner; + +public class Parser { + + public Parser() { + + } + + public static String getCommand() { + String command; + Scanner in = new Scanner(System.in); + command = in.nextLine(); + return command; + } + + public Command parse(String fullCommand) throws IHospitalException { + if (fullCommand.contains("add doctor")) { + String id; + String dummy = fullCommand.trim(); + try { + int idIndex = dummy.indexOf("/id") + 4; + int nameIndex = dummy.indexOf("/n"); + id = dummy.substring(idIndex, nameIndex); + nameIndex += 3; + int phoneNumberIndex = dummy.indexOf("/ph"); + String name = dummy.substring(nameIndex, phoneNumberIndex); + phoneNumberIndex += 4; + int emailIndex = dummy.indexOf("/e"); + String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); + emailIndex += 3; + String email = dummy.substring(emailIndex); + return new AddDoctorCommand(id, name, phoneNumber, email, false); + } catch (Exception e) { + System.out.println("The input format of the doctor information is wrong."); + } + + } else if (fullCommand.contains("add patient")) { + String id; + String dummy = fullCommand.trim(); + try { + int idIndex = dummy.indexOf("/id") + 4; + int nameIndex = dummy.indexOf("/n"); + id = dummy.substring(idIndex, nameIndex); + nameIndex += 3; + int phoneNumberIndex = dummy.indexOf("/ph"); + String name = dummy.substring(nameIndex, phoneNumberIndex); + phoneNumberIndex += 4; + int emailIndex = dummy.indexOf("/e"); + String phoneNumber = dummy.substring(phoneNumberIndex, emailIndex); + emailIndex += 3; + String email = dummy.substring(emailIndex); + return new AddPatientCommand(id, name, phoneNumber, email); + } catch (Exception e) { + System.out.println("The input format of the patient information is wrong."); + } + + } else if (fullCommand.contains("add appointment")) { + String time; + String dummy = fullCommand.trim(); + try { + int timeIndex = dummy.indexOf("/t"); + int doctorIndex = dummy.indexOf("/d"); + time = dummy.substring(timeIndex, doctorIndex); + int patientIndex = dummy.indexOf("/p"); + String s = dummy.substring(doctorIndex, patientIndex); + + doctorIndex = Integer.parseInt(s); + patientIndex += 3; + s = dummy.substring(patientIndex); + patientIndex = Integer.parseInt(s); + return new AddAppointmentCommand(doctorIndex, patientIndex, time); + } catch (Exception e) { + System.out.println("The input format of the appointment information is wrong."); + } + } else if (fullCommand.contains("delete doctor")) { + String dummy = fullCommand.trim(); + int index = Integer.parseInt(dummy.substring(dummy.length() - 1)); + return new DeleteDoctorCommand(index); + } else if (fullCommand.contains("delete patient")) { + String dummy = fullCommand.trim(); + int index = Integer.parseInt(dummy.substring(dummy.length() - 1)); + return new DeletePatientCommand(index); + } else if (fullCommand.contains("delete appointment")) { + String dummy = fullCommand.trim(); + int index = Integer.parseInt(dummy.substring(dummy.length() - 1)); + return new DeleteAppointmentCommand(index); + } else if (fullCommand.contains("list doctor")) { + return new ListDoctorListCommand(); + } else if (fullCommand.contains("list appointment")) { + return new ListAppointmentListCommand(); + } else if (fullCommand.contains("list patient")) { + return new ListPatientListCommand(); + } else + throw new IHospitalException("Invalid command given"); + + return null; + } +} + + diff --git a/src/main/java/tp/PatientList.java b/src/main/java/tp/PatientList.java new file mode 100644 index 000000000..4d7950bfd --- /dev/null +++ b/src/main/java/tp/PatientList.java @@ -0,0 +1,56 @@ +package tp; + +import tp.person.Patient; +import tp.person.Person; + +import java.util.ArrayList; + +public class PatientList { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + protected ArrayList patients = new ArrayList<>(); + protected int countPatient; + + public PatientList() { + countPatient = 0; + } + + public Person getPatient(int index) { + return patients.get(index - 1); + } + + public void addPatient(Patient patient) { + patients.add(patient); + countPatient++; + + System.out.println(boundary + "Noted. I've added this patient:"); + System.out.println(patients.get(countPatient - 1)); + System.out.print("Now you have " + countPatient + + " patients recorded in the system." + System.lineSeparator() + boundary); + } + + /** + * Deletes a patient from the list. + * + * @param index Index of the patient to be deleted. + */ + public void deletePatient(int index) { + System.out.println(boundary + "Noted. I've removed this patient:"); + System.out.println(patients.get(index - 1)); + System.out.print("Now you have " + (countPatient - 1) + + " patients recorded in the system." + System.lineSeparator() + boundary); + patients.remove(index - 1); + countPatient -= 1; + } + + @Override + public String toString() { + String toPrint = boundary + "Here are the patients recorded:" + System.lineSeparator(); + for (int i = 1; i <= countPatient; i++) { + toPrint += (i + ". " + getPatient(i) + System.lineSeparator()); + } + toPrint += ("You have " + countPatient + " patients recorded in the system." + + System.lineSeparator() + boundary + System.lineSeparator()); + return toPrint; + } +} diff --git a/src/main/java/tp/Storage.java b/src/main/java/tp/Storage.java new file mode 100644 index 000000000..78516042d --- /dev/null +++ b/src/main/java/tp/Storage.java @@ -0,0 +1,5 @@ +package tp; + +public class Storage { + +} \ No newline at end of file diff --git a/src/main/java/tp/Ui.java b/src/main/java/tp/Ui.java new file mode 100644 index 000000000..6a5cd67aa --- /dev/null +++ b/src/main/java/tp/Ui.java @@ -0,0 +1,32 @@ +package tp; + +import java.util.Scanner; + +public class Ui { + public static String boundary = "____________________________________________________________" + + System.lineSeparator(); + + // Prints welcome message. + public void sayHello() { + System.out.print(boundary); + System.out.println("Hello! This is IHospital."); + System.out.print("What can I do for you?" + System.lineSeparator() + boundary); + } + + // Prints goodbye message. + public void sayGoodbye() { + System.out.print(boundary + "Bye. Hope to see you again soon!" + System.lineSeparator() + boundary); + } + + public void printDoctorPage(DoctorList doctors) { + System.out.print(boundary); + System.out.println("Welcome to Doctor Page."); + System.out.print(doctors); + } + + public void printPatientPage(PatientList patients) { + System.out.print(boundary); + System.out.println("Welcome to Patient Page."); + System.out.print(patients); + } +} diff --git a/src/main/java/tp/person/Doctor.java b/src/main/java/tp/person/Doctor.java new file mode 100644 index 000000000..152b8c954 --- /dev/null +++ b/src/main/java/tp/person/Doctor.java @@ -0,0 +1,24 @@ +package tp.person; + +public class Doctor extends Person { + protected boolean isOnDuty; + + public Doctor(String id, String name, String phoneNumber, String email) { + super(id, name, phoneNumber, email); + isOnDuty = false; + } + + public void markOnDuty() { + isOnDuty = true; + } + + public void markOnLeave() { + isOnDuty = false; + } + + @Override + public String toString() { + return "* DOCTOR " + super.toString(); + } + +} diff --git a/src/main/java/tp/person/Patient.java b/src/main/java/tp/person/Patient.java new file mode 100644 index 000000000..e0975185f --- /dev/null +++ b/src/main/java/tp/person/Patient.java @@ -0,0 +1,12 @@ +package tp.person; + +public class Patient extends Person { + public Patient(String id, String name, String phoneNumber, String email) { + super(id, name, phoneNumber, email); + } + + @Override + public String toString() { + return "* PATIENT " + super.toString(); + } +} diff --git a/src/main/java/tp/person/Person.java b/src/main/java/tp/person/Person.java new file mode 100644 index 000000000..2099ae12c --- /dev/null +++ b/src/main/java/tp/person/Person.java @@ -0,0 +1,55 @@ +package tp.person; + +public class Person { + protected String id; + protected String name; + protected String phoneNumber; + protected String email; + + public Person(String id, String name, String phoneNumber, String email) { + this.id = id; + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + } + + public void setPerson(String name, String phoneNumber, String email) { + this.name = name; + this.phoneNumber = phoneNumber; + this.email = email; + } + + public void editName(String name) { + this.name = name; + } + + public void editPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public void editEmail(String email) { + this.email = email; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public String getEmail() { + return email; + } + + @Override + public String toString() { + return "[" + id + "] || Name: " + name + + " || Contact No.: " + phoneNumber + " || Email: " + email; + } +} diff --git a/src/test/tp/person/DoctorTest.java b/src/test/tp/person/DoctorTest.java new file mode 100644 index 000000000..ec3f31de7 --- /dev/null +++ b/src/test/tp/person/DoctorTest.java @@ -0,0 +1,15 @@ +package tp.person; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class DoctorTest { + private final Doctor doctor = new Doctor("1234", "john", + "12341234", "3600@gmail.com"); + @Test + void testToString() { + assertEquals("* DOCTOR " + "[1234] || Name: john " + + "|| Contact No.: 12341234 || Email: 3600@gmail.com", doctor.toString()); + } +} \ No newline at end of file diff --git a/src/test/tp/person/PatientTest.java b/src/test/tp/person/PatientTest.java new file mode 100644 index 000000000..542e0cdb9 --- /dev/null +++ b/src/test/tp/person/PatientTest.java @@ -0,0 +1,16 @@ +package tp.person; + +import org.junit.jupiter.api.Test; +import tp.PatientList; + +import static org.junit.jupiter.api.Assertions.*; + +class PatientTest { + private final Patient patient = new Patient("1234", "john", + "12341234", "3600@gmail.com"); + @Test + void testToString() { + assertEquals("* PATIENT " + "[1234] || Name: john " + + "|| Contact No.: 12341234 || Email: 3600@gmail.com", patient.toString()); + } +} \ No newline at end of file diff --git a/src/test/tp/person/PersonTest.java b/src/test/tp/person/PersonTest.java new file mode 100644 index 000000000..a4a059548 --- /dev/null +++ b/src/test/tp/person/PersonTest.java @@ -0,0 +1,36 @@ +package tp.person; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PersonTest { + private final Person person = new Person("1234", "john", + "12341234", "3600@gmail.com"); + + @Test + void getId() { + assertEquals("1234", person.getId()); + } + + @Test + void getName() { + assertEquals("john", person.getName()); + } + + @Test + void getPhoneNumber() { + assertEquals("12341234", person.getPhoneNumber()); + } + + @Test + void getEmail() { + assertEquals("3600@gmail.com", person.getEmail()); + } + + @Test + void testToString() { + assertEquals("[1234] || Name: john " + + "|| Contact No.: 12341234 || Email: 3600@gmail.com", person.toString()); + } +} \ No newline at end of file