Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2103T-T15-1#130 from alfaloo/debug
Browse files Browse the repository at this point in the history
Fix cascading edit nric
  • Loading branch information
Kappaccinoh authored Apr 4, 2024
2 parents 1ab6334 + f3efcd8 commit 6d4d38e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -86,6 +91,29 @@ 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)));
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,4 @@ public boolean isValidAppointment(Appointment appointment) throws PersonNotFound

return false;
}

}
12 changes: 10 additions & 2 deletions src/main/java/seedu/address/model/appointment/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -98,6 +102,10 @@ public Nric getPatientNric() {
return patientNric;
}

public void setPatientNric(Nric nric) {
this.patientNric = nric;
}

public AppointmentId getAppointmentId() {
return this.appointmentId;
}
Expand Down

0 comments on commit 6d4d38e

Please sign in to comment.