Skip to content

Commit

Permalink
Merge pull request #51 from Michaeliaaa/refactor-person-to-patient
Browse files Browse the repository at this point in the history
Refactor person to patient
  • Loading branch information
ktaekwon000 authored Sep 26, 2020
2 parents 54ef4f7 + 511b6ec commit 6b920ce
Show file tree
Hide file tree
Showing 85 changed files with 1,322 additions and 1,317 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_INVALID_PATIENT_DISPLAYED_INDEX = "The patient index provided is invalid";
public static final String MESSAGE_PATIENTS_LISTED_OVERVIEW = "%1$d patients listed!";

}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.patient.Patient;

/**
* API of the Logic component
Expand All @@ -30,8 +30,8 @@ public interface Logic {
*/
ReadOnlyAddressBook getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
/** Returns an unmodifiable view of the filtered list of patients */
ObservableList<Patient> getFilteredPatientList();

/**
* Returns the user prefs' address book file path.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.patient.Patient;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -65,8 +65,8 @@ public ReadOnlyAddressBook getAddressBook() {
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
public ObservableList<Patient> getFilteredPatientList() {
return model.getFilteredPatientList();
}

@Override
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.patient.Patient;

/**
* Adds a person to the address book.
* Adds a patient to the address book.
*/
public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a patient to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
Expand All @@ -33,28 +33,28 @@ public class AddCommand extends Command {
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
public static final String MESSAGE_SUCCESS = "New patient added: %1$s";
public static final String MESSAGE_DUPLICATE_PATIENT = "This patient already exists in the address book";

private final Person toAdd;
private final Patient toAdd;

/**
* Creates an AddCommand to add the specified {@code Person}
* Creates an AddCommand to add the specified {@code Patient}
*/
public AddCommand(Person person) {
requireNonNull(person);
toAdd = person;
public AddCommand(Patient patient) {
requireNonNull(patient);
toAdd = patient;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
if (model.hasPatient(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PATIENT);
}

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

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.patient.Patient;

/**
* Deletes a person identified using it's displayed index from the address book.
* Deletes a patient identified using it's displayed index from the address book.
*/
public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the displayed person list.\n"
+ ": Deletes the patient identified by the index number used in the displayed patient list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_PATIENT_SUCCESS = "Deleted Patient: %1$s";

private final Index targetIndex;

Expand All @@ -33,15 +33,15 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
List<Patient> lastShownList = model.getFilteredPatientList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
throw new CommandException(Messages.MESSAGE_INVALID_PATIENT_DISPLAYED_INDEX);
}

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
Patient patientToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePatient(patientToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PATIENT_SUCCESS, patientToDelete));
}

@Override
Expand Down
88 changes: 44 additions & 44 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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] "
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

import seedu.address.commons.core.Messages;
import seedu.address.model.Model;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.patient.NameContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Finds and lists all patients in address book whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class FindCommand extends Command {

public static final String COMMAND_WORD = "find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all patients whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";
Expand All @@ -28,9 +28,9 @@ public FindCommand(NameContainsKeywordsPredicate predicate) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
model.updateFilteredPatientList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
String.format(Messages.MESSAGE_PATIENTS_LISTED_OVERVIEW, model.getFilteredPatientList().size()));
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
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);
}
}
Loading

0 comments on commit 6b920ce

Please sign in to comment.