Skip to content

Commit

Permalink
Merge branch 'editDoctor'
Browse files Browse the repository at this point in the history
  • Loading branch information
tanveersingh10 committed Nov 12, 2023
2 parents 1189e53 + c39dd6b commit 334b671
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.");

Check warning on line 147 in src/main/java/seedu/address/logic/commands/EditCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/EditCommand.java#L146-L147

Added lines #L146 - L147 were not covered by tests
}
}
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.");

Check warning on line 154 in src/main/java/seedu/address/logic/commands/EditCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/EditCommand.java#L153-L154

Added lines #L153 - L154 were not covered by tests
}
if (editPersonDescriptor.getTags().isPresent()
&& !editPersonDescriptor.isValidDoctorTagList(editPersonDescriptor.getTags().get())) {
logger.warning(editPersonDescriptor.getTags().toString());
throw new CommandException("Please enter valid Doctor tags.");

Check warning on line 159 in src/main/java/seedu/address/logic/commands/EditCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/EditCommand.java#L158-L159

Added lines #L158 - L159 were not covered by tests
}
}

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

0 comments on commit 334b671

Please sign in to comment.