From 71963e1c00d262dd2b92544d81c635d438edf342 Mon Sep 17 00:00:00 2001 From: Ong JunZheng <46806333+kaboomzxc@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:45:16 +0800 Subject: [PATCH] Revert "Implement "find" command" --- src/src/main/java/BookBob/Main.java | 21 ----- src/src/main/java/BookBob/entity/Patient.java | 94 ------------------- .../BookBob/entity/PatientAttributeCheck.java | 6 -- src/src/main/java/BookBob/entity/Records.java | 29 ------ src/src/main/java/BookBob/functions/CRUD.java | 31 ------ .../BookBob/functions/CommandHandler.java | 44 --------- src/src/main/java/BookBob/functions/Find.java | 62 ------------ .../BookBob/functions/SaveAndRetrieve.java | 84 ----------------- src/src/test/java/BookBob/DukeTest.java | 12 --- 9 files changed, 383 deletions(-) delete mode 100644 src/src/main/java/BookBob/Main.java delete mode 100644 src/src/main/java/BookBob/entity/Patient.java delete mode 100644 src/src/main/java/BookBob/entity/PatientAttributeCheck.java delete mode 100644 src/src/main/java/BookBob/entity/Records.java delete mode 100644 src/src/main/java/BookBob/functions/CRUD.java delete mode 100644 src/src/main/java/BookBob/functions/CommandHandler.java delete mode 100644 src/src/main/java/BookBob/functions/Find.java delete mode 100644 src/src/main/java/BookBob/functions/SaveAndRetrieve.java delete mode 100644 src/src/test/java/BookBob/DukeTest.java diff --git a/src/src/main/java/BookBob/Main.java b/src/src/main/java/BookBob/Main.java deleted file mode 100644 index 664da117ee..0000000000 --- a/src/src/main/java/BookBob/Main.java +++ /dev/null @@ -1,21 +0,0 @@ -package BookBob; - -import java.util.Scanner; - -public class Main { - /** - * Main entry-point for the java.duke.Duke application. - */ - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); - - Scanner in = new Scanner(System.in); - System.out.println("Hello " + in.nextLine()); - } -} diff --git a/src/src/main/java/BookBob/entity/Patient.java b/src/src/main/java/BookBob/entity/Patient.java deleted file mode 100644 index 10cd6a634e..0000000000 --- a/src/src/main/java/BookBob/entity/Patient.java +++ /dev/null @@ -1,94 +0,0 @@ -package BookBob.entity; - -import java.util.ArrayList; -import java.util.List; - -public class Patient { - private String name; - private String nric; - private String dateOfBirth; - private String phoneNumber; - private String homeAddress; - private String diagnosis; - private List medication; - - // default constructor only takes in name and NRIC - public Patient(String name, String nric) { - this.name = name; - this.nric = nric; - this.dateOfBirth = ""; - this.phoneNumber = ""; - this.homeAddress = ""; - this.diagnosis = ""; - this.medication = new ArrayList<>(); - } - - // constructor used in retrieving data - public Patient(String name, String nric, String dateOfBirth, String phoneNumber, String homeAddress, - String diagnosis, ArrayList medications) { - this.name = name; - this.nric = nric; - this.dateOfBirth = dateOfBirth; - this.phoneNumber = phoneNumber; - this.homeAddress = homeAddress; - this.diagnosis = diagnosis; - this.medication = medications; - } - - // getters and setters - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNric() { - return nric; - } - - public void setNric(String nric) { - this.nric = nric; - } - - public String getDateOfBirth() { - return dateOfBirth; - } - - public void setDateOfBirth(String dateOfBirth) { - this.dateOfBirth = dateOfBirth; - } - - public String getPhoneNumber() { - return phoneNumber; - } - - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } - - public String getHomeAddress() { - return homeAddress; - } - - public void setHomeAddress(String homeAddress) { - this.homeAddress = homeAddress; - } - - public String getDiagnosis() { - return diagnosis; - } - - public void setDiagnosis(String diagnosis) { - this.diagnosis = diagnosis; - } - - public List getMedication() { - return medication; - } - - public void setMedication(ArrayList medication) { - this.medication = medication; - } -} diff --git a/src/src/main/java/BookBob/entity/PatientAttributeCheck.java b/src/src/main/java/BookBob/entity/PatientAttributeCheck.java deleted file mode 100644 index 066cdebf87..0000000000 --- a/src/src/main/java/BookBob/entity/PatientAttributeCheck.java +++ /dev/null @@ -1,6 +0,0 @@ -package BookBob.entity; - -@FunctionalInterface -public interface PatientAttributeCheck { - boolean test(Patient patient, String keyword); -} diff --git a/src/src/main/java/BookBob/entity/Records.java b/src/src/main/java/BookBob/entity/Records.java deleted file mode 100644 index 0a268e8afa..0000000000 --- a/src/src/main/java/BookBob/entity/Records.java +++ /dev/null @@ -1,29 +0,0 @@ -package BookBob.entity; - -import java.util.ArrayList; -import java.util.List; - -public class Records { - private List patients; - - // default constructor: empty - public Records() { - this.patients = new ArrayList<>(); - } - - // add a patient to records - public void addPatient(Patient patient) { - List patients = this.getPatients(); - patients.add(patient); - this.setPatients(patients); - } - - // setter and getters - public List getPatients() { - return patients; - } - - public void setPatients(List patients) { - this.patients = patients; - } -} diff --git a/src/src/main/java/BookBob/functions/CRUD.java b/src/src/main/java/BookBob/functions/CRUD.java deleted file mode 100644 index b943878ae1..0000000000 --- a/src/src/main/java/BookBob/functions/CRUD.java +++ /dev/null @@ -1,31 +0,0 @@ -package BookBob.functions; - -import BookBob.entity.Patient; -import BookBob.entity.Records; -import java.util.List; - -public class CRUD { - public void delete(String NRIC, Records records) { - List patients = records.getPatients(); - int initialPatientSize = patients.size(); - - if (initialPatientSize == 0) { - System.out.println("There are no patients in the record currently."); - return; - } - - for (int i = 0; i < patients.size(); i++) { - Patient currentPatient = patients.get(i); - String patientNRIC = currentPatient.getNric(); - if (patientNRIC.equals(NRIC)) { - patients.remove(i); - System.out.println("Patient " + currentPatient.getName() + ", " + patientNRIC + ", has been deleted."); - break; - } - } - - if (patients.size() == initialPatientSize) { - System.out.println("Patient " + NRIC + " not found"); - } - } -} diff --git a/src/src/main/java/BookBob/functions/CommandHandler.java b/src/src/main/java/BookBob/functions/CommandHandler.java deleted file mode 100644 index 9d095f2dbe..0000000000 --- a/src/src/main/java/BookBob/functions/CommandHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package BookBob.functions; - -public class CommandHandler { - - // Prints output for help command - public void help() { - System.out.println("+-----------+---------------------------------------+---------------------------------+\n" + - "| Action | Format | Example |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| Help | help | help |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| Add | add n/NAME ic/NRIC [p/PHONE_NUMBER] | add n/James Ho ic/S9534567A |\n" + - "| | [d/DIAGNOSIS] [m/MEDICATION] | p/91234567 d/Asthma m/Albuterol |\n" + - "| | [ha/HOME_ADDRESS] [dob/DATE_OF_BIRTH] | ha/NUS-PGPR dob/13121995 |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| List | list | list |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| Find | find NAME [KEYWORDS] OR | find NRIC S1234 |\n" + - "| | find NRIC [KEYWORDS] OR | |\n" + - "| | find PHONE_NUMBER [KEYWORDS] OR | |\n" + - "| | find DIAGNOSIS [KEYWORDS] OR | |\n" + - "| | find MEDICATION [KEYWORDS] OR | |\n" + - "| | find HOME_ADDRESS [KEYWORDS] OR | |\n" + - "| | find DATE_OF_BIRTH [KEYWORDS] | |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| Delete | delete NRIC | delete S9534567A |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| Save | save(automatic) | save |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| Retrieve/ | retrieve or import | retrieve |\n" + - "| Import | (automatic) | |\n" + - "+-----------+---------------------------------------+---------------------------------+\n" + - "| Exit | exit | exit |\n" + - "+-----------+---------------------------------------+---------------------------------+\n"); - } - - // Takes in an input string and determines whether to exit the program - public void exit(String input) { - if(input.equalsIgnoreCase("exit")) { - System.exit(0); - } - } - -} diff --git a/src/src/main/java/BookBob/functions/Find.java b/src/src/main/java/BookBob/functions/Find.java deleted file mode 100644 index a073397424..0000000000 --- a/src/src/main/java/BookBob/functions/Find.java +++ /dev/null @@ -1,62 +0,0 @@ -package BookBob.functions; - -import BookBob.entity.Patient; -import BookBob.entity.PatientAttributeCheck; -import BookBob.entity.Records; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; - -public class Find { - public List findPatientsByAttribute(Records records, String[] keywords, - PatientAttributeCheck attributeCheck) { - List findList = new ArrayList<>(); - - for (Patient p : records.getPatients()) { - for (String keyword : keywords) { - if (attributeCheck.test(p, keyword)) { - findList.add(p); - break; // To avoid adding the same patient multiple times - } - } - } - - return findList; - } - - public List findPatientsByName(Records records, String[] keywords) { - return findPatientsByAttribute(records, keywords, (p, keyword) -> p.getName().contains(keyword)); - } - - public List findPatientsByNric(Records records, String[] keywords) { - return findPatientsByAttribute(records, keywords, (p, keyword) -> p.getNric().contains(keyword)); - } - - public List findPatientsByDateOfBirth(Records records, String[] keywords) { - return findPatientsByAttribute(records, keywords, (p, keyword) -> { - DateTimeFormatter dateInputFormatter = DateTimeFormatter.ofPattern("ddMMyyyy"); - - LocalDate searchDate = LocalDate.parse(keyword, dateInputFormatter); - LocalDate patientDateOfBirth = LocalDate.parse(p.getDateOfBirth(), dateInputFormatter); - return patientDateOfBirth.equals(searchDate); - }); - } - - public List findPatientsByPhoneNumber(Records records, String[] keywords) { - return findPatientsByAttribute(records, keywords, (p, keyword) -> p.getPhoneNumber().contains(keyword)); - } - - public List findPatientsByHomeAddress(Records records, String[] keywords) { - return findPatientsByAttribute(records, keywords, (p, keyword) -> p.getHomeAddress().contains(keyword)); - } - - public List findPatientsByDiagnosis(Records records, String[] keywords) { - return findPatientsByAttribute(records, keywords, (p, keyword) -> p.getDiagnosis().contains(keyword)); - } - - public List findPatientsByMedication(Records records, String[] keywords) { - return findPatientsByAttribute(records,keywords, (p, keyword) -> p.getMedication().contains(keyword)); - } -} diff --git a/src/src/main/java/BookBob/functions/SaveAndRetrieve.java b/src/src/main/java/BookBob/functions/SaveAndRetrieve.java deleted file mode 100644 index 5e4246de0c..0000000000 --- a/src/src/main/java/BookBob/functions/SaveAndRetrieve.java +++ /dev/null @@ -1,84 +0,0 @@ -package BookBob.functions; - -import BookBob.entity.Patient; -import BookBob.entity.Records; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class SaveAndRetrieve { - - public static void initFile(Records records){ - try { - File file = new File("bookbob_data.txt"); - if(file.createNewFile()) { - } - else { - retrieveData(records); - } - } - catch(Exception e){ - System.out.println("An error occured"); - e.printStackTrace(); - } - } - - private static String convertPatientToOutputText(Patient patient) { - String output = ""; - output += "Name: " + patient.getName() + " | " + "NRIC: " + patient.getNric() + " | " + "Phone Number: " + patient.getPhoneNumber() + " | " - + "Date_Of_Birth: " + patient.getDateOfBirth() + " | " + "Home Address: " + patient.getHomeAddress() + " | " + "Diagnosis: " + patient.getDiagnosis() + " | " - + "Medication: "; - List medications = patient.getMedication(); - for(int i = 0; i < medications.size(); i++) { - output += medications.get(i) + ";"; - } - return output; - } - - public static void autosave(Records records) throws IOException { - List patients = records.getPatients(); - FileWriter fw = new FileWriter("bookbob_data.txt"); - for(int i = 0; i < patients.size(); i++) { - Patient currPatient = patients.get(i); - String toWrite = convertPatientToOutputText(currPatient); - - //for test - System.out.println(toWrite); - - fw.write(toWrite + "\n"); - } - fw.close(); - } - - public static void retrieveData(Records records){ - try { - File file = new File("bookbob_data.txt"); - Scanner reader = new Scanner(file); - while (reader.hasNextLine()) { - String line = reader.nextLine(); - String[] data = line.split("\\|"); - String name = data[0].trim(); - String NRIC = data[1].trim(); - String phoneNumber = data[2].trim(); - String dateOfBirth = data[3].trim(); - String homeAddress = data[4].trim(); - String diagnosis = data[5].trim(); - ArrayList medications = new ArrayList<>(); - String[] rawMedications = data[6].trim().split(";"); - for(int i = 0; i < rawMedications.length; i++) { - medications.add(rawMedications[i].trim()); - } - Patient patient = new Patient(name, NRIC, phoneNumber, dateOfBirth, homeAddress, diagnosis, medications); - records.addPatient(patient); - } - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/src/src/test/java/BookBob/DukeTest.java b/src/src/test/java/BookBob/DukeTest.java deleted file mode 100644 index bf1704be32..0000000000 --- a/src/src/test/java/BookBob/DukeTest.java +++ /dev/null @@ -1,12 +0,0 @@ -package BookBob; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -class DukeTest { - @Test - public void sampleTest() { - assertTrue(true); - } -}