From 1a9231f70d3616f2d2df08c180a4d7f2d4d454e4 Mon Sep 17 00:00:00 2001 From: S-Aishvarya Date: Thu, 4 Apr 2024 21:11:25 +0800 Subject: [PATCH 1/6] Add list-by-date and list-until-date --- .../logic/commands/ListByApptDateCommand.java | 53 +++++++++++++++++++ .../commands/ListByDateCriteriaCommand.java | 49 +++++++++++++++++ .../address/logic/parser/InputParser.java | 8 +++ .../ListByDateCriteriaCommandParser.java | 33 ++++++++++++ .../patient/ApptDateMatchesPredicate.java | 43 +++++++++++++++ 5 files changed, 186 insertions(+) create mode 100755 src/main/java/seedu/address/logic/commands/ListByApptDateCommand.java create mode 100755 src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java create mode 100755 src/main/java/seedu/address/logic/parser/ListByDateCriteriaCommandParser.java create mode 100755 src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java diff --git a/src/main/java/seedu/address/logic/commands/ListByApptDateCommand.java b/src/main/java/seedu/address/logic/commands/ListByApptDateCommand.java new file mode 100755 index 00000000000..5fd1845a97e --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/ListByApptDateCommand.java @@ -0,0 +1,53 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.PatientList; +import seedu.address.model.patient.Patient; + +/** + * Lists patient by appointment dates + */ +public class ListByApptDateCommand extends Command { + + public static final String COMMAND_WORD = "list-by-date"; + + public static final String MESSAGE_SUCCESS = "Listed all patients by ascending appointment date"; + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); + List sortedList = new ArrayList(); + sortedList.addAll(model.getFilteredPatientList()); + Comparator comparator = (patient1, patient2) -> { + if (null != patient1.getAppointment().appointment && null != patient2.getAppointment().appointment) { + return patient1.getAppointment().appointment.compareTo((patient2.getAppointment().appointment)); + } else if (null != patient1.getAppointment().appointment && null == patient2.getAppointment().appointment) { + return 1; + } else if (null == patient1.getAppointment().appointment && null != patient2.getAppointment().appointment) { + return -1; + } else if (null == patient1.getAppointment().appointment && null == patient2.getAppointment().appointment) { + return 0; + } + return 0; + }; + sortedList.sort(comparator); + + for (Patient patient : sortedList) { + model.setPatientList(new PatientList()); + //model.deletePatient(patient); + } + for (Patient patient : sortedList) { + model.addPatient(patient); + } + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java b/src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java new file mode 100755 index 00000000000..48d7403d023 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java @@ -0,0 +1,49 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE_OF_VISIT; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.PatientList; +import seedu.address.model.patient.ApptDateMatchesPredicate; +import seedu.address.model.patient.Patient; + +/** + * Lists patient by appointment dates on or before given date + */ +public class ListByDateCriteriaCommand extends Command { + + public static final String COMMAND_WORD = "list-until-date"; + + public static final String MESSAGE_SUCCESS = "Listed all patients with appointment date on or before date"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Finds all patients with appointment date on or before date " + + "Parameters: " + + "[" + PREFIX_DATE_OF_VISIT + "DATEOFVISIT] " + + "Example: " + COMMAND_WORD + " " + + PREFIX_DATE_OF_VISIT + "25/2/2024"; + + private final ApptDateMatchesPredicate apptDatePredicate; + + public ListByDateCriteriaCommand(ApptDateMatchesPredicate apptDatePredicate) { + this.apptDatePredicate = apptDatePredicate; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); + List sortedList = new ArrayList(); + model.updateFilteredPatientList(apptDatePredicate); + + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/main/java/seedu/address/logic/parser/InputParser.java b/src/main/java/seedu/address/logic/parser/InputParser.java index 7c3db620a39..183c288711c 100644 --- a/src/main/java/seedu/address/logic/parser/InputParser.java +++ b/src/main/java/seedu/address/logic/parser/InputParser.java @@ -21,6 +21,8 @@ import seedu.address.logic.commands.ForceDeleteAllCommand; import seedu.address.logic.commands.ForceExitCommand; import seedu.address.logic.commands.HelpCommand; +import seedu.address.logic.commands.ListByApptDateCommand; +import seedu.address.logic.commands.ListByDateCriteriaCommand; import seedu.address.logic.commands.ListCommand; import seedu.address.logic.commands.NoCommand; import seedu.address.logic.commands.YesCommand; @@ -133,6 +135,12 @@ public Command parseCommand(String userInput) throws ParseException { case HelpCommand.COMMAND_WORD: return new HelpCommand(); + case ListByApptDateCommand.COMMAND_WORD: + return new ListByApptDateCommand(); + + case ListByDateCriteriaCommand.COMMAND_WORD: + return new ListByDateCriteriaCommandParser().parse(arguments); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/ListByDateCriteriaCommandParser.java b/src/main/java/seedu/address/logic/parser/ListByDateCriteriaCommandParser.java new file mode 100755 index 00000000000..01c235f0a05 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ListByDateCriteriaCommandParser.java @@ -0,0 +1,33 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE_OF_VISIT; + +import java.time.LocalDate; + +import seedu.address.logic.commands.ListByDateCriteriaCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.patient.ApptDateMatchesPredicate; + +/** + * Lists patient by appointment dates parser + */ +public class ListByDateCriteriaCommandParser implements Parser { + + @Override + public ListByDateCriteriaCommand parse(String args) throws ParseException { + + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DATE_OF_VISIT); + + if (!argMultimap.getPreamble().equals("")) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + ListByDateCriteriaCommand.MESSAGE_USAGE)); + } + + LocalDate dateOfVisit = + ParserUtil.parseAppointment(argMultimap.getValue(PREFIX_DATE_OF_VISIT).get()).appointment; + ApptDateMatchesPredicate apptDatePredicate = new ApptDateMatchesPredicate(dateOfVisit); + + return new ListByDateCriteriaCommand(apptDatePredicate); + } +} diff --git a/src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java b/src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java new file mode 100755 index 00000000000..809ce4b2d04 --- /dev/null +++ b/src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java @@ -0,0 +1,43 @@ +package seedu.address.model.patient; + +import java.time.LocalDate; +import java.util.function.Predicate; + +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.patient.Appointment; +public class ApptDateMatchesPredicate implements Predicate { + private final LocalDate apptDate; + + public ApptDateMatchesPredicate(LocalDate apptDate) { + this.apptDate = apptDate; + } + + @Override + public boolean test(Patient patient) { + LocalDate ptApptDate = patient.getAppointment().appointment; + if (ptApptDate == null) { + return false; + } + return ptApptDate.isBefore(this.apptDate) || ptApptDate.isEqual(this.apptDate); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof ApptDateMatchesPredicate)) { + return false; + } + + ApptDateMatchesPredicate otherApptMatchesPredicate = (ApptDateMatchesPredicate) other; + return apptDate.equals(otherApptMatchesPredicate.apptDate); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("appointment", apptDate).toString(); + } +} From 32b5de7f74e30977220ab5f4d33ebf7c27043a20 Mon Sep 17 00:00:00 2001 From: S-Aishvarya Date: Thu, 4 Apr 2024 21:20:04 +0800 Subject: [PATCH 2/6] Add list-by-date and list-until-date --- .../address/logic/commands/ListByDateCriteriaCommand.java | 3 --- .../address/model/patient/ApptDateMatchesPredicate.java | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java b/src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java index 48d7403d023..cb6c2deabba 100755 --- a/src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java @@ -4,14 +4,11 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE_OF_VISIT; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS; -import java.time.LocalDate; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.PatientList; import seedu.address.model.patient.ApptDateMatchesPredicate; import seedu.address.model.patient.Patient; diff --git a/src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java b/src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java index 809ce4b2d04..a2fa1375578 100755 --- a/src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java +++ b/src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java @@ -4,7 +4,10 @@ import java.util.function.Predicate; import seedu.address.commons.util.ToStringBuilder; -import seedu.address.model.patient.Appointment; + +/** + * Predicate for appointment date. + */ public class ApptDateMatchesPredicate implements Predicate { private final LocalDate apptDate; From 5b6316f66c9d583de6562ecda2de43379ce42221 Mon Sep 17 00:00:00 2001 From: S-Aishvarya Date: Thu, 4 Apr 2024 21:38:31 +0800 Subject: [PATCH 3/6] Edit ListCommand and ListAlphabeticalCommand --- .../commands/ListAlphabeticalCommand.java | 41 +++++++++++++++++++ .../address/logic/commands/ListCommand.java | 14 +------ .../address/logic/parser/InputParser.java | 4 ++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/ListAlphabeticalCommand.java diff --git a/src/main/java/seedu/address/logic/commands/ListAlphabeticalCommand.java b/src/main/java/seedu/address/logic/commands/ListAlphabeticalCommand.java new file mode 100644 index 00000000000..e97c10fd817 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/ListAlphabeticalCommand.java @@ -0,0 +1,41 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import seedu.address.model.Model; +import seedu.address.model.patient.Patient; + +/** + * Lists all patients in the patient list alphabetically to the user. + */ +public class ListAlphabeticalCommand extends Command { + + public static final String COMMAND_WORD = "list-a"; + + public static final String MESSAGE_SUCCESS = "Listed all patients in alphabetical order"; + + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); + List sortedList = new ArrayList(); + sortedList.addAll(model.getFilteredPatientList()); + Comparator comparator = (patient1, patient2) -> { + return patient1.getName().fullName.compareTo(patient2.getName().fullName); + }; + sortedList.sort(comparator); + for (Patient patient : sortedList) { + model.deletePatient(patient); + } + for (Patient patient : sortedList) { + model.addPatient(patient); + } + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 24ee25a2ad9..4bc5db6e9a9 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -11,7 +11,7 @@ import seedu.address.model.patient.Patient; /** - * Lists all patients in the patient list to the user. + * Lists all patients in the patient list arbitrarily to the user. */ public class ListCommand extends Command { @@ -24,18 +24,6 @@ public class ListCommand extends Command { public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); - List sortedList = new ArrayList(); - sortedList.addAll(model.getFilteredPatientList()); - Comparator comparator = (patient1, patient2) -> { - return patient1.getName().fullName.compareTo(patient2.getName().fullName); - }; - sortedList.sort(comparator); - for (Patient patient : sortedList) { - model.deletePatient(patient); - } - for (Patient patient : sortedList) { - model.addPatient(patient); - } return new CommandResult(MESSAGE_SUCCESS); } } diff --git a/src/main/java/seedu/address/logic/parser/InputParser.java b/src/main/java/seedu/address/logic/parser/InputParser.java index 183c288711c..e0a483dff4f 100644 --- a/src/main/java/seedu/address/logic/parser/InputParser.java +++ b/src/main/java/seedu/address/logic/parser/InputParser.java @@ -23,6 +23,7 @@ import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListByApptDateCommand; import seedu.address.logic.commands.ListByDateCriteriaCommand; +import seedu.address.logic.commands.ListAlphabeticalCommand; import seedu.address.logic.commands.ListCommand; import seedu.address.logic.commands.NoCommand; import seedu.address.logic.commands.YesCommand; @@ -125,6 +126,9 @@ public Command parseCommand(String userInput) throws ParseException { case ListCommand.COMMAND_WORD: return new ListCommand(); + case ListAlphabeticalCommand.COMMAND_WORD: + return new ListAlphabeticalCommand(); + case ExitCommand.COMMAND_WORD: isPreviousCommandExit = true; return new ExitCommand(); From 8eb64512522cec5a939f0e6b3f6ca6cb1719a29a Mon Sep 17 00:00:00 2001 From: S-Aishvarya Date: Thu, 4 Apr 2024 21:43:38 +0800 Subject: [PATCH 4/6] Edit ListCommand and ListAlphabeticalCommand --- src/main/java/seedu/address/logic/commands/ListCommand.java | 5 ----- src/main/java/seedu/address/logic/parser/InputParser.java | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 4bc5db6e9a9..5f0e91a2c4f 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -3,12 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; - import seedu.address.model.Model; -import seedu.address.model.patient.Patient; /** * Lists all patients in the patient list arbitrarily to the user. diff --git a/src/main/java/seedu/address/logic/parser/InputParser.java b/src/main/java/seedu/address/logic/parser/InputParser.java index e0a483dff4f..fc767f086a6 100644 --- a/src/main/java/seedu/address/logic/parser/InputParser.java +++ b/src/main/java/seedu/address/logic/parser/InputParser.java @@ -22,8 +22,8 @@ import seedu.address.logic.commands.ForceExitCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListByApptDateCommand; -import seedu.address.logic.commands.ListByDateCriteriaCommand; import seedu.address.logic.commands.ListAlphabeticalCommand; +import seedu.address.logic.commands.ListByDateCriteriaCommand; import seedu.address.logic.commands.ListCommand; import seedu.address.logic.commands.NoCommand; import seedu.address.logic.commands.YesCommand; From 4adb6e4288417006e19fef9b50a1e51117a9018e Mon Sep 17 00:00:00 2001 From: S-Aishvarya Date: Thu, 4 Apr 2024 21:48:23 +0800 Subject: [PATCH 5/6] Edit ListCommand and ListAlphabeticalCommand --- src/main/java/seedu/address/logic/parser/InputParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/parser/InputParser.java b/src/main/java/seedu/address/logic/parser/InputParser.java index fc767f086a6..ade7a61d892 100644 --- a/src/main/java/seedu/address/logic/parser/InputParser.java +++ b/src/main/java/seedu/address/logic/parser/InputParser.java @@ -21,8 +21,8 @@ import seedu.address.logic.commands.ForceDeleteAllCommand; import seedu.address.logic.commands.ForceExitCommand; import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.ListByApptDateCommand; import seedu.address.logic.commands.ListAlphabeticalCommand; +import seedu.address.logic.commands.ListByApptDateCommand; import seedu.address.logic.commands.ListByDateCriteriaCommand; import seedu.address.logic.commands.ListCommand; import seedu.address.logic.commands.NoCommand; From 7af01e3ae8ba7f44c433d0779db1fd6ec40a20a2 Mon Sep 17 00:00:00 2001 From: S-Aishvarya Date: Thu, 4 Apr 2024 22:05:58 +0800 Subject: [PATCH 6/6] Update UserGuide with list commands --- docs/UserGuide.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 84b5ae48b9f..3fe455f0162 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -96,6 +96,27 @@ Shows a list of all patients in the address book. Format: `list` +### Listing all patients in alphabetical order : `list-a` + +Shows a list of all patients in the address book in alphabetical order. + +Format: `list-a` + +### Listing all patients in order of appointment date : `list-by-date` + +Shows a list of all patients in the address book in order of appointment. + +Format: `list-by-date` + +### Listing all patients whose appointments fall or on before a certain date : `list-until-date` + +Shows a list of all patients in the address book whose appointments fall on or before the given date. + +Format: `list-until-date d/dd/mm/yyyy` + +Examples: +* `list-until-date d/13/01/2024` Displays all patients with appointments on or before 13 January 2024. + ### Editing a patient : `edit` Edits an existing patient in the address book.