Skip to content

Commit

Permalink
Merge pull request #225 from tanveersingh10/master
Browse files Browse the repository at this point in the history
Fix bug to prevent /ec when editing doctor
  • Loading branch information
kohkaijie committed Nov 12, 2023
2 parents 6ffae7b + 334b671 commit ec3d7ef
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,40 @@ private Person getPersonToEdit(Model model) throws CommandException {
private Person getEditedPerson(Model model, Person personToEdit) throws CommandException {
Person editedPerson;
if (personToEdit instanceof Patient) {
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidPatientTagList(editPersonDescriptor.getTags().get())) {
logger.warning("Invalid tag for patient");
throw new CommandException("Please enter a valid patient tag.");
}
editedPerson = createEditedPatient((Patient) personToEdit, editPersonDescriptor);
Patient patientToEdit = (Patient) personToEdit;
validatePatient();
editedPerson = createEditedPatient(patientToEdit, editPersonDescriptor);
} else {
assert personToEdit.isDoctor();
if (editPersonDescriptor.getCondition().isPresent() || editPersonDescriptor.getBloodType().isPresent()) {
logger.warning("Error thrown - tried to edit condition / bloodtype of doctor");
throw new CommandException("Doctors cannot have Condition or BloodType fields.");
}
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidDoctorTagList(editPersonDescriptor.getTags().get())) {
logger.warning(editPersonDescriptor.getTags().toString());
throw new CommandException("Please enter valid Doctor tags.");
}
editedPerson = createEditedDoctor((Doctor) personToEdit, editPersonDescriptor);
Doctor doctorToEdit = (Doctor) personToEdit;
validateDoctor();
editedPerson = createEditedDoctor(doctorToEdit, editPersonDescriptor);
}
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
logger.warning("Edited Person and orignal person are the same");
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
return editedPerson;
}
private void validatePatient() throws CommandException {
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidPatientTagList(editPersonDescriptor.getTags().get())) {
logger.warning("Invalid tag for patient");
throw new CommandException("Please enter a valid patient tag.");
}
}
private void validateDoctor() throws CommandException {
if (editPersonDescriptor.getCondition().isPresent() || editPersonDescriptor.getBloodType().isPresent()
|| editPersonDescriptor.getEmergencyContact().isPresent()) {
logger.warning("Error thrown - tried to edit condition/blood type/emergency contact of doctor");
throw new CommandException("Doctors cannot have Condition, BloodType or Emergency Contact fields.");
}
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidDoctorTagList(editPersonDescriptor.getTags().get())) {
logger.warning(editPersonDescriptor.getTags().toString());
throw new CommandException("Please enter valid Doctor tags.");
}
}

/**
* Creates and returns a {@code Person} with the details of {@code personToEdit}
Expand Down

0 comments on commit ec3d7ef

Please sign in to comment.