Skip to content

Commit

Permalink
Modify AddAppointmentCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
tanveersingh10 committed Nov 1, 2023
1 parent 335e950 commit a6573bf
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,35 @@ public AddAppointmentCommand(Appointment appointment) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

Patient chosenPatient = findPatient(model);
Doctor chosenDoctor = findDoctor(model);
checkPatientAndDoctor(chosenPatient, chosenDoctor);
checkValidAppointment(chosenPatient, chosenDoctor, toAdd);
chosenPatient.addAppointment(toAdd);
chosenDoctor.addAppointment(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));

Check warning on line 64 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L60-L64

Added lines #L60 - L64 were not covered by tests
}

private void checkValidAppointment(Patient chosenPatient, Doctor chosenDoctor, Appointment toAdd)
throws CommandException {
if (chosenPatient.hasAppointmentAt(toAdd.getAppointmentTime())) {
throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT_PATIENT);

Check warning on line 70 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L70

Added line #L70 was not covered by tests
}
if (chosenDoctor.hasAppointmentAt(toAdd.getAppointmentTime())) {
throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT_DOCTOR);

Check warning on line 73 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L73

Added line #L73 was not covered by tests
}
}

Check warning on line 75 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L75

Added line #L75 was not covered by tests
private void checkPatientAndDoctor(Patient chosenPatient, Doctor chosenDoctor) throws CommandException {
if (chosenPatient == null) {
throw new CommandException(MESSAGE_INVALID_PATIENT);
}
if (chosenDoctor == null) {
throw new CommandException(MESSAGE_INVALID_DOCTOR);
}

// check that patient and doctor are not the same person
if (chosenPatient.isSamePerson(chosenDoctor)) {
throw new CommandException(MESSAGE_SAME_DOCTOR_AND_PATIENT);
}


// check that the patient and doctor do not have appointment scheduled at the same time
if (chosenPatient.hasAppointmentAt(toAdd.getAppointmentTime())) {
throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT_PATIENT);
}
if (chosenDoctor.hasAppointmentAt(toAdd.getAppointmentTime())) {
throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT_DOCTOR);
}
// add appointment to the specified doctor's appointment set
// add appointment to the specified patient's appointment set
chosenPatient.addAppointment(toAdd);
chosenDoctor.addAppointment(toAdd);

return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

private Patient findPatient(Model model) {
Expand Down

0 comments on commit a6573bf

Please sign in to comment.