forked from nus-cs2103-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Michaeliaaa/refactor-person-to-patient
Refactor person to patient
- Loading branch information
Showing
85 changed files
with
1,322 additions
and
1,317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
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_PERSONS; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
|
@@ -19,22 +19,22 @@ | |
import seedu.address.commons.util.CollectionUtil; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.patient.Address; | ||
import seedu.address.model.patient.Email; | ||
import seedu.address.model.patient.Name; | ||
import seedu.address.model.patient.Patient; | ||
import seedu.address.model.patient.Phone; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Edits the details of an existing person in the address book. | ||
* Edits the details of an existing patient in the address book. | ||
*/ | ||
public class EditCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "edit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the patient identified " | ||
+ "by the index number used in the displayed patient list. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_NAME + "NAME] " | ||
|
@@ -46,60 +46,60 @@ public class EditCommand extends Command { | |
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
|
||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
public static final String MESSAGE_EDIT_PATIENT_SUCCESS = "Edited Patient: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; | ||
public static final String MESSAGE_DUPLICATE_PATIENT = "This patient already exists in the address book."; | ||
|
||
private final Index index; | ||
private final EditPersonDescriptor editPersonDescriptor; | ||
private final EditPatientDescriptor editPatientDescriptor; | ||
|
||
/** | ||
* @param index of the person in the filtered person list to edit | ||
* @param editPersonDescriptor details to edit the person with | ||
* @param index of the patient in the filtered patient list to edit | ||
* @param editPatientDescriptor details to edit the patient with | ||
*/ | ||
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { | ||
public EditCommand(Index index, EditPatientDescriptor editPatientDescriptor) { | ||
requireNonNull(index); | ||
requireNonNull(editPersonDescriptor); | ||
requireNonNull(editPatientDescriptor); | ||
|
||
this.index = index; | ||
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor); | ||
this.editPatientDescriptor = new EditPatientDescriptor(editPatientDescriptor); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
List<Patient> lastShownList = model.getFilteredPatientList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
throw new CommandException(Messages.MESSAGE_INVALID_PATIENT_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); | ||
Patient patientToEdit = lastShownList.get(index.getZeroBased()); | ||
Patient editedPatient = createEditedPatient(patientToEdit, editPatientDescriptor); | ||
|
||
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
if (!patientToEdit.isSamePatient(editedPatient) && model.hasPatient(editedPatient)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PATIENT); | ||
} | ||
|
||
model.setPerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson)); | ||
model.setPatient(patientToEdit, editedPatient); | ||
model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PATIENT_SUCCESS, editedPatient)); | ||
} | ||
|
||
/** | ||
* Creates and returns a {@code Person} with the details of {@code personToEdit} | ||
* edited with {@code editPersonDescriptor}. | ||
* Creates and returns a {@code Patient} with the details of {@code patientToEdit} | ||
* edited with {@code editPatientDescriptor}. | ||
*/ | ||
private static Person createEditedPerson(Person personToEdit, EditPersonDescriptor editPersonDescriptor) { | ||
assert personToEdit != null; | ||
private static Patient createEditedPatient(Patient patientToEdit, EditPatientDescriptor editPatientDescriptor) { | ||
assert patientToEdit != null; | ||
|
||
Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); | ||
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); | ||
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); | ||
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); | ||
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); | ||
Name updatedName = editPatientDescriptor.getName().orElse(patientToEdit.getName()); | ||
Phone updatedPhone = editPatientDescriptor.getPhone().orElse(patientToEdit.getPhone()); | ||
Email updatedEmail = editPatientDescriptor.getEmail().orElse(patientToEdit.getEmail()); | ||
Address updatedAddress = editPatientDescriptor.getAddress().orElse(patientToEdit.getAddress()); | ||
Set<Tag> updatedTags = editPatientDescriptor.getTags().orElse(patientToEdit.getTags()); | ||
|
||
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); | ||
return new Patient(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); | ||
} | ||
|
||
@Override | ||
|
@@ -117,27 +117,27 @@ public boolean equals(Object other) { | |
// state check | ||
EditCommand e = (EditCommand) other; | ||
return index.equals(e.index) | ||
&& editPersonDescriptor.equals(e.editPersonDescriptor); | ||
&& editPatientDescriptor.equals(e.editPatientDescriptor); | ||
} | ||
|
||
/** | ||
* Stores the details to edit the person with. Each non-empty field value will replace the | ||
* corresponding field value of the person. | ||
* Stores the details to edit the patient with. Each non-empty field value will replace the | ||
* corresponding field value of the patient. | ||
*/ | ||
public static class EditPersonDescriptor { | ||
public static class EditPatientDescriptor { | ||
private Name name; | ||
private Phone phone; | ||
private Email email; | ||
private Address address; | ||
private Set<Tag> tags; | ||
|
||
public EditPersonDescriptor() {} | ||
public EditPatientDescriptor() {} | ||
|
||
/** | ||
* Copy constructor. | ||
* A defensive copy of {@code tags} is used internally. | ||
*/ | ||
public EditPersonDescriptor(EditPersonDescriptor toCopy) { | ||
public EditPatientDescriptor(EditPatientDescriptor toCopy) { | ||
setName(toCopy.name); | ||
setPhone(toCopy.phone); | ||
setEmail(toCopy.email); | ||
|
@@ -209,12 +209,12 @@ public boolean equals(Object other) { | |
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EditPersonDescriptor)) { | ||
if (!(other instanceof EditPatientDescriptor)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
EditPersonDescriptor e = (EditPersonDescriptor) other; | ||
EditPatientDescriptor e = (EditPatientDescriptor) other; | ||
|
||
return getName().equals(e.getName()) | ||
&& getPhone().equals(e.getPhone()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS; | ||
|
||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Lists all persons in the address book to the user. | ||
* Lists all patients in the address book to the user. | ||
*/ | ||
public class ListCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "list"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all persons"; | ||
public static final String MESSAGE_SUCCESS = "Listed all patients"; | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
Oops, something went wrong.