From f5389da74c372fc41739c49c37846e056547366a Mon Sep 17 00:00:00 2001 From: alfaloo Date: Thu, 4 Apr 2024 22:20:04 +0800 Subject: [PATCH 1/2] Fix cascading edit nric --- .../address/logic/commands/EditCommand.java | 26 +++++++++++++++++++ .../seedu/address/model/ModelManager.java | 1 - .../model/appointment/Appointment.java | 12 +++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 6c118a89fe0..65340ff08f1 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -6,8 +6,10 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_APPOINTMENTS; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -18,6 +20,9 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.AppointmentContainsDoctorPredicate; +import seedu.address.model.appointment.AppointmentContainsPatientPredicate; import seedu.address.model.person.DoB; import seedu.address.model.person.Doctor; import seedu.address.model.person.Name; @@ -86,6 +91,27 @@ public CommandResult execute(Model model) throws CommandException { model.setPerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + + AppointmentContainsDoctorPredicate predicateDoctor = new AppointmentContainsDoctorPredicate(Arrays.asList(personToEdit.getNric().nric)); + model.updateFilteredAppointmentList(predicateDoctor); + + for (Appointment appt : model.getFilteredAppointmentList()) { + if (appt.getDoctorNric().equals(personToEdit.getNric())) { + appt.setDoctorNric(editedPerson.getNric()); + } + } + + AppointmentContainsPatientPredicate predicatePatient = new AppointmentContainsPatientPredicate(Arrays.asList(personToEdit.getNric().nric)); + model.updateFilteredAppointmentList(predicatePatient); + + for (Appointment appt : model.getFilteredAppointmentList()) { + if (appt.getPatientNric().equals(personToEdit.getNric())) { + appt.setPatientNric(editedPerson.getNric()); + } + } + + model.updateFilteredAppointmentList(PREDICATE_SHOW_ALL_APPOINTMENTS); + return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index c04a138c957..7888c47cd8c 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -202,5 +202,4 @@ public boolean isValidAppointment(Appointment appointment) throws PersonNotFound return false; } - } diff --git a/src/main/java/seedu/address/model/appointment/Appointment.java b/src/main/java/seedu/address/model/appointment/Appointment.java index 680d8d2ebe8..9c2e9e19918 100644 --- a/src/main/java/seedu/address/model/appointment/Appointment.java +++ b/src/main/java/seedu/address/model/appointment/Appointment.java @@ -19,10 +19,10 @@ public class Appointment { "Appointment should be made with a date today onwards"; // The doctor in charge of the appointment - private final Nric doctorNric; + private Nric doctorNric; // The patient benefiting from the appointment - private final Nric patientNric; + private Nric patientNric; // The date of the appointment private final AppointmentDate appointmentDate; @@ -90,6 +90,10 @@ public Nric getDoctorNric() { return doctorNric; } + public void setDoctorNric(Nric nric) { + this.doctorNric = nric; + } + /** * Gets patient of the appointment * @return patient of the appointment @@ -98,6 +102,10 @@ public Nric getPatientNric() { return patientNric; } + public void setPatientNric(Nric nric) { + this.patientNric = nric; + } + public AppointmentId getAppointmentId() { return this.appointmentId; } From f3efcd83c8f96fc97ef687461ab353c7a5092aa6 Mon Sep 17 00:00:00 2001 From: alfaloo Date: Thu, 4 Apr 2024 22:24:01 +0800 Subject: [PATCH 2/2] Fix checkstyle --- src/main/java/seedu/address/logic/commands/EditCommand.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 65340ff08f1..4673548a227 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -92,7 +92,8 @@ public CommandResult execute(Model model) throws CommandException { model.setPerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - AppointmentContainsDoctorPredicate predicateDoctor = new AppointmentContainsDoctorPredicate(Arrays.asList(personToEdit.getNric().nric)); + AppointmentContainsDoctorPredicate predicateDoctor = + new AppointmentContainsDoctorPredicate(Arrays.asList(personToEdit.getNric().nric)); model.updateFilteredAppointmentList(predicateDoctor); for (Appointment appt : model.getFilteredAppointmentList()) { @@ -101,7 +102,8 @@ public CommandResult execute(Model model) throws CommandException { } } - AppointmentContainsPatientPredicate predicatePatient = new AppointmentContainsPatientPredicate(Arrays.asList(personToEdit.getNric().nric)); + AppointmentContainsPatientPredicate predicatePatient = + new AppointmentContainsPatientPredicate(Arrays.asList(personToEdit.getNric().nric)); model.updateFilteredAppointmentList(predicatePatient); for (Appointment appt : model.getFilteredAppointmentList()) {