From 41fe5a1841281601024f2899418e2977ac749a19 Mon Sep 17 00:00:00 2001 From: Joshen Lim <77193243+joshenx@users.noreply.github.com> Date: Wed, 27 Oct 2021 22:48:25 +0800 Subject: [PATCH 1/4] Implement Auto-Archive feature and Sort Command --- .../logic/commands/AddAppointmentCommand.java | 4 +- .../commands/ArchiveAppointmentCommand.java | 4 +- .../commands/DeleteAppointmentCommand.java | 2 +- .../commands/SortAppointmentsCommand.java | 42 +++++++++++++++++++ .../DeletePrescriptionCommand.java | 2 +- .../ListPrescriptionsCommand.java | 2 +- .../docit/logic/parser/AddressBookParser.java | 12 +++--- .../logic/parser/AppointmentBookParser.java | 3 ++ .../seedu/docit/model/AppointmentBook.java | 5 ++- src/main/java/seedu/docit/model/Model.java | 5 +++ .../java/seedu/docit/model/ModelManager.java | 6 +++ .../docit/model/appointment/Appointment.java | 20 +++++++-- .../appointment/UniqueAppointmentList.java | 7 ++++ .../seedu/docit/model/patient/Patient.java | 7 +++- .../java/seedu/docit/ui/AppointmentCard.java | 6 ++- .../resources/view/AppointmentListCard.fxml | 1 + src/main/resources/view/LightTheme.css | 7 ++++ 17 files changed, 115 insertions(+), 20 deletions(-) create mode 100644 src/main/java/seedu/docit/logic/commands/SortAppointmentsCommand.java diff --git a/src/main/java/seedu/docit/logic/commands/AddAppointmentCommand.java b/src/main/java/seedu/docit/logic/commands/AddAppointmentCommand.java index 04e9ce556f4..58492dbe6b4 100644 --- a/src/main/java/seedu/docit/logic/commands/AddAppointmentCommand.java +++ b/src/main/java/seedu/docit/logic/commands/AddAppointmentCommand.java @@ -21,10 +21,10 @@ public class AddAppointmentCommand extends AppointmentCommand { public static final String COMMAND_WORD = "add"; public static final String MESSAGE_USAGE = - "appt " + COMMAND_WORD + ": Adds an appointment to the appointment book. " + "apmt " + COMMAND_WORD + ": Adds an appointment to the appointment book. " + "Parameters: " + CliSyntax.PREFIX_INDEX + "INDEX " + CliSyntax.PREFIX_DATETIME + "DATETIME \n" - + "Example: appt " + COMMAND_WORD + " " + CliSyntax.PREFIX_INDEX + "1 " + + "Example: apmt " + COMMAND_WORD + " " + CliSyntax.PREFIX_INDEX + "1 " + CliSyntax.PREFIX_DATETIME + "2021-12-31 1600"; public static final String MESSAGE_SUCCESS = "New appointment added: %1$s"; diff --git a/src/main/java/seedu/docit/logic/commands/ArchiveAppointmentCommand.java b/src/main/java/seedu/docit/logic/commands/ArchiveAppointmentCommand.java index a6d5ceaf9e3..f093116ab11 100644 --- a/src/main/java/seedu/docit/logic/commands/ArchiveAppointmentCommand.java +++ b/src/main/java/seedu/docit/logic/commands/ArchiveAppointmentCommand.java @@ -17,9 +17,9 @@ public class ArchiveAppointmentCommand extends AppointmentCommand { public static final String COMMAND_WORD = "archive"; - public static final String MESSAGE_USAGE = "appt " + COMMAND_WORD + public static final String MESSAGE_USAGE = "apmt " + COMMAND_WORD + ": Archives the appointment identified by the index number used in the displayed appointment list.\n" - + "Parameters: INDEX (must be a positive integer)\n" + "Example: appt " + COMMAND_WORD + " 1"; + + "Parameters: INDEX (must be a positive integer)\n" + "Example: apmt " + COMMAND_WORD + " 1"; public static final String MESSAGE_ARCHIVE_APPOINTMENT_SUCCESS = "Archived Appointment: %1$s"; diff --git a/src/main/java/seedu/docit/logic/commands/DeleteAppointmentCommand.java b/src/main/java/seedu/docit/logic/commands/DeleteAppointmentCommand.java index 7dfc0a10ccd..a2a0b49fd1d 100644 --- a/src/main/java/seedu/docit/logic/commands/DeleteAppointmentCommand.java +++ b/src/main/java/seedu/docit/logic/commands/DeleteAppointmentCommand.java @@ -19,7 +19,7 @@ public class DeleteAppointmentCommand extends AppointmentCommand { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the appointment identified by the index number used in the displayed appointment list.\n" - + "Parameters: INDEX (must be a positive integer)\n" + "Example: appt " + COMMAND_WORD + " 1"; + + "Parameters: INDEX (must be a positive integer)\n" + "Example: apmt " + COMMAND_WORD + " 1"; public static final String MESSAGE_DELETE_APPOINTMENT_SUCCESS = "Deleted Appointment: %1$s"; diff --git a/src/main/java/seedu/docit/logic/commands/SortAppointmentsCommand.java b/src/main/java/seedu/docit/logic/commands/SortAppointmentsCommand.java new file mode 100644 index 00000000000..bfd1a1930cd --- /dev/null +++ b/src/main/java/seedu/docit/logic/commands/SortAppointmentsCommand.java @@ -0,0 +1,42 @@ +package seedu.docit.logic.commands; + +import static java.util.Objects.requireNonNull; + +import java.util.List; +import seedu.docit.commons.core.Messages; +import seedu.docit.commons.core.index.Index; +import seedu.docit.logic.commands.exceptions.CommandException; +import seedu.docit.model.Model; +import seedu.docit.model.appointment.Appointment; + +/** + * Archives an appointment identified using it's displayed index from the appointment book. + */ +public class SortAppointmentsCommand extends AppointmentCommand { + + public static final String COMMAND_WORD = "sort"; + + public static final String MESSAGE_USAGE = "apmt " + COMMAND_WORD + + ": Sorts appointments based on their urgency and name.\n" + + "Parameters: [parameter to sort by..]\n" + "Example: apmt " + COMMAND_WORD + ""; // TODO + + public static final String MESSAGE_SORT_APPOINTMENT_SUCCESS = "Sorted Appointments based on " + + "default settings."; + + public SortAppointmentsCommand() { + + } + + @Override public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredAppointmentList(); + + model.sortAppointments(); + return new CommandResult(String.format(MESSAGE_SORT_APPOINTMENT_SUCCESS)); + } + + @Override public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof SortAppointmentsCommand); + } +} diff --git a/src/main/java/seedu/docit/logic/commands/prescription/DeletePrescriptionCommand.java b/src/main/java/seedu/docit/logic/commands/prescription/DeletePrescriptionCommand.java index 256f4b82aed..d6a32f41b66 100644 --- a/src/main/java/seedu/docit/logic/commands/prescription/DeletePrescriptionCommand.java +++ b/src/main/java/seedu/docit/logic/commands/prescription/DeletePrescriptionCommand.java @@ -25,7 +25,7 @@ public class DeletePrescriptionCommand extends AppointmentCommand { + "Parameters: \n" + CliSyntax.PREFIX_INDEX + "ID OF APPOINTMENT \n" + CliSyntax.PREFIX_NAME + "MEDICINE \n" - + "Example: appt " + COMMAND_WORD + " " + + "Example: apmt " + COMMAND_WORD + " " + CliSyntax.PREFIX_INDEX + "1 " + CliSyntax.PREFIX_NAME + "Penicillin "; diff --git a/src/main/java/seedu/docit/logic/commands/prescription/ListPrescriptionsCommand.java b/src/main/java/seedu/docit/logic/commands/prescription/ListPrescriptionsCommand.java index 806088031db..c163ef654d5 100644 --- a/src/main/java/seedu/docit/logic/commands/prescription/ListPrescriptionsCommand.java +++ b/src/main/java/seedu/docit/logic/commands/prescription/ListPrescriptionsCommand.java @@ -22,7 +22,7 @@ public class ListPrescriptionsCommand extends AppointmentCommand { + COMMAND_WORD + ": List all prescriptions of an appointment " + "Parameters: \n" + CliSyntax.PREFIX_INDEX + "ID OF APPOINTMENT \n" - + "Example: appt " + COMMAND_WORD + " " + + "Example: apmt " + COMMAND_WORD + " " + CliSyntax.PREFIX_INDEX + "1 "; public static final String MESSAGE_SUCCESS = "Listed all prescriptions of appointment"; diff --git a/src/main/java/seedu/docit/logic/parser/AddressBookParser.java b/src/main/java/seedu/docit/logic/parser/AddressBookParser.java index 8c47f68d1a7..1d26df5183f 100644 --- a/src/main/java/seedu/docit/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/docit/logic/parser/AddressBookParser.java @@ -24,7 +24,7 @@ public class AddressBookParser { private static final Pattern APPT_COMMAND_FORMAT = Pattern.compile("(apmt) (?\\S+)(?.*)"); private final PatientBookParser patientParser = new PatientBookParser(); - private final AppointmentBookParser apptParser = new AppointmentBookParser(); + private final AppointmentBookParser apmtParser = new AppointmentBookParser(); private final BasicAddressBookParser basicParser = new BasicAddressBookParser(); /** @@ -38,7 +38,7 @@ public Command parseCommand(String userInput) throws ParseException { // Patient Command Matching final Matcher patientMatcher = PTNT_COMMAND_FORMAT.matcher(userInput.trim()); final Matcher basicMatcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim()); - final Matcher apptMatcher = APPT_COMMAND_FORMAT.matcher(userInput.trim()); + final Matcher apmtMatcher = APPT_COMMAND_FORMAT.matcher(userInput.trim()); // empty inputs if (userInput.equals("")) { @@ -50,11 +50,11 @@ public Command parseCommand(String userInput) throws ParseException { final String commandWord = basicMatcher.group("commandWord"); final String arguments = basicMatcher.group("arguments"); // ignore any arguments return basicParser.parseBasicCommand(commandWord); - } else if (apptMatcher.matches()) { + } else if (apmtMatcher.matches()) { // Appointment Command Matching - final String commandWord = apptMatcher.group("commandWord"); - final String arguments = apptMatcher.group("arguments"); - return apptParser.parseAppointmentCommand(commandWord, arguments); + final String commandWord = apmtMatcher.group("commandWord"); + final String arguments = apmtMatcher.group("arguments"); + return apmtParser.parseAppointmentCommand(commandWord, arguments); } else if (patientMatcher.matches()) { // Patient Command Matching final String commandWord = patientMatcher.group("commandWord"); diff --git a/src/main/java/seedu/docit/logic/parser/AppointmentBookParser.java b/src/main/java/seedu/docit/logic/parser/AppointmentBookParser.java index 30193cb70a3..3d208206fd2 100644 --- a/src/main/java/seedu/docit/logic/parser/AppointmentBookParser.java +++ b/src/main/java/seedu/docit/logic/parser/AppointmentBookParser.java @@ -8,6 +8,7 @@ import seedu.docit.logic.commands.DeleteAppointmentCommand; import seedu.docit.logic.commands.EditAppointmentCommand; import seedu.docit.logic.commands.ListAppointmentsCommand; +import seedu.docit.logic.commands.SortAppointmentsCommand; import seedu.docit.logic.commands.prescription.AddPrescriptionCommand; import seedu.docit.logic.commands.prescription.DeletePrescriptionCommand; import seedu.docit.logic.commands.prescription.ListPrescriptionsCommand; @@ -39,6 +40,8 @@ public AppointmentCommand parseAppointmentCommand(String commandWord, String arg return new ArchiveAppointmentCommandParser().parseAppointmentCommand(arguments); case ListAppointmentsCommand.COMMAND_WORD: return new ListAppointmentsCommand(); + case SortAppointmentsCommand.COMMAND_WORD: + return new SortAppointmentsCommand(); case AddPrescriptionCommand.COMMAND_WORD: return new AddPrescriptionCommandParser().parse(arguments); case DeletePrescriptionCommand.COMMAND_WORD: diff --git a/src/main/java/seedu/docit/model/AppointmentBook.java b/src/main/java/seedu/docit/model/AppointmentBook.java index f7705f0bae2..395726ed7a8 100644 --- a/src/main/java/seedu/docit/model/AppointmentBook.java +++ b/src/main/java/seedu/docit/model/AppointmentBook.java @@ -87,6 +87,10 @@ public void setAppointment(Appointment target, Appointment editedAppointment) { appointments.setAppointment(target, editedAppointment); } + public void sortAppointments() { + appointments.sort(); + } + /** * Updates appointments in the list with {@code target} when there are changes to the patient's details. * The appointment identity of {@code editedAppointment} must not be the same as another @@ -153,5 +157,4 @@ public void removeAppointment(Appointment key) { @Override public int hashCode() { return appointments.hashCode(); } - } diff --git a/src/main/java/seedu/docit/model/Model.java b/src/main/java/seedu/docit/model/Model.java index b632d082618..3cb49721bf9 100644 --- a/src/main/java/seedu/docit/model/Model.java +++ b/src/main/java/seedu/docit/model/Model.java @@ -153,6 +153,11 @@ public interface Model { */ void setAppointment(Appointment target, Appointment editedAppointment); + /** + * Sorts appointments in order of whether its today, followed by dateTime, and patient name. + */ + void sortAppointments(); + String getAppointments(); String getArchivedAppointments(); diff --git a/src/main/java/seedu/docit/model/ModelManager.java b/src/main/java/seedu/docit/model/ModelManager.java index 02b14899557..68f86812301 100644 --- a/src/main/java/seedu/docit/model/ModelManager.java +++ b/src/main/java/seedu/docit/model/ModelManager.java @@ -213,6 +213,12 @@ public void setAppointment(Appointment target, Appointment editedAppointment) { appointmentBook.setAppointment(target, editedAppointment); } + @Override + public void sortAppointments() { + appointmentBook.sortAppointments(); + updateFilteredAppointmentList(PREDICATE_SHOW_ALL_APPOINTMENTS); + } + //=========== ArchivedAppointmentBook ======================================================================= /** diff --git a/src/main/java/seedu/docit/model/appointment/Appointment.java b/src/main/java/seedu/docit/model/appointment/Appointment.java index a03bd1f6c98..746754b36d6 100644 --- a/src/main/java/seedu/docit/model/appointment/Appointment.java +++ b/src/main/java/seedu/docit/model/appointment/Appointment.java @@ -2,8 +2,10 @@ import static seedu.docit.commons.util.CollectionUtil.requireAllNonNull; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Comparator; import java.util.Objects; import java.util.function.Predicate; @@ -19,7 +21,7 @@ * Represents an Appointment in the appointment book. Guarantees: details are present and not null, field values are * validated, immutable. */ -public class Appointment { +public class Appointment implements Comparable { public static final DateTimeFormatter UI_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("d MMM yyyy HHmm"); public static final DateTimeFormatter UI_DATE_FORMATTER = DateTimeFormatter.ofPattern("d MMM yyyy"); @@ -93,6 +95,14 @@ public String getInputFormattedDatetimeString() { return getDatetime().format(INPUT_DATE_TIME_FORMATTER); } + public boolean containsPrescription(Prescription p) { + return prescriptions.contains(p); + } + + public boolean isToday() { + return getDatetime().toLocalDate().equals(LocalDate.now()); + } + /** * Returns true if both appointments have the same name and datetime. This defines a weaker notion of equality * between two appointments. @@ -145,7 +155,11 @@ public String toString() { + getPrescriptions() + "\n"; } - public boolean containsPrescription(Prescription p) { - return prescriptions.contains(p); + @Override + public int compareTo(Appointment o) { + return Comparator.comparing(Appointment::isToday).reversed() + .thenComparing(Appointment::getDatetime) + .thenComparing(Appointment::getPatient) + .compare(this, o); } } diff --git a/src/main/java/seedu/docit/model/appointment/UniqueAppointmentList.java b/src/main/java/seedu/docit/model/appointment/UniqueAppointmentList.java index ed69382e3da..af0428e50a3 100644 --- a/src/main/java/seedu/docit/model/appointment/UniqueAppointmentList.java +++ b/src/main/java/seedu/docit/model/appointment/UniqueAppointmentList.java @@ -96,6 +96,13 @@ public void setAppointments(List appointments) { internalList.setAll(appointments); } + /** + * Sorts the contents of this list. + */ + public void sort() { + internalList.sort(Appointment::compareTo); + } + /** * Returns the backing list as an unmodifiable {@code ObservableList}. */ diff --git a/src/main/java/seedu/docit/model/patient/Patient.java b/src/main/java/seedu/docit/model/patient/Patient.java index bd1d1201e1a..43ad2a58e1c 100644 --- a/src/main/java/seedu/docit/model/patient/Patient.java +++ b/src/main/java/seedu/docit/model/patient/Patient.java @@ -14,7 +14,7 @@ * Represents a Patient in the address book. * Guarantees: details are present and not null, field values are validated, immutable. */ -public class Patient { +public class Patient implements Comparable { // Identity fields private final Name name; @@ -170,4 +170,9 @@ public String toString() { return builder.toString(); } + + @Override + public int compareTo(Patient o) { + return this.name.fullName.compareTo(o.name.fullName); + } } diff --git a/src/main/java/seedu/docit/ui/AppointmentCard.java b/src/main/java/seedu/docit/ui/AppointmentCard.java index 8aaacf875f0..213738e5613 100644 --- a/src/main/java/seedu/docit/ui/AppointmentCard.java +++ b/src/main/java/seedu/docit/ui/AppointmentCard.java @@ -1,5 +1,6 @@ package seedu.docit.ui; +import java.time.LocalDate; import java.util.Comparator; import javafx.fxml.FXML; @@ -42,11 +43,11 @@ public class AppointmentCard extends UiPart { @FXML private Label time; @FXML - private Label prescription; - @FXML private FlowPane tags; @FXML private FlowPane prescriptions; + @FXML + private Label isToday; /** * Creates a {@code AppointmentCode} with the given {@code Appointment} and index to display. @@ -66,6 +67,7 @@ public AppointmentCard(Appointment appointment, int displayedIndex) { appointment.getPrescriptionList().stream() .sorted(Comparator.comparing(presctn -> presctn.getMedicine())) .forEach(presctn -> prescriptions.getChildren().add(new Label(presctn.toUiFormat()))); + isToday.setVisible(appointment.isToday()); } @Override diff --git a/src/main/resources/view/AppointmentListCard.fxml b/src/main/resources/view/AppointmentListCard.fxml index 426f88e1fcd..f44ce7ab38d 100644 --- a/src/main/resources/view/AppointmentListCard.fxml +++ b/src/main/resources/view/AppointmentListCard.fxml @@ -56,6 +56,7 @@ +