Skip to content

Commit

Permalink
Merge pull request #4 from CS2103-AY1819S2-W17-2/master
Browse files Browse the repository at this point in the history
Update v1.2
  • Loading branch information
JiaHaoLim authored Mar 15, 2019
2 parents 12226f4 + 5e88270 commit 5fbe812
Show file tree
Hide file tree
Showing 41 changed files with 1,032 additions and 279 deletions.
34 changes: 28 additions & 6 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;

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

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

Expand All @@ -22,29 +26,47 @@ public class AddCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_NRIC + "NRIC "
+ PREFIX_YEAR + "DOB "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_NRIC + "S1234567A "
+ PREFIX_YEAR + "30-12-1990 "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ 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_PERSON = "This patient already exists in the dental book";

private final Person toAdd;
private final Patient toAdd;

/**
* Creates an AddCommand to add the specified {@code Patient}
* @param patient the patient to be added.
*/
public AddCommand(Patient patient) {
requireNonNull(patient);
toAdd = patient;
}

/**
* Creates an AddCommand to add the specified {@code Person}
* @param person the person to be added.
*/
public AddCommand(Person person) {
requireNonNull(person);
toAdd = person;
if (person instanceof Patient) {
toAdd = (Patient) person;
} else {
throw new PersonIsNotPatient();
}
}

@Override
Expand All @@ -57,7 +79,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_SUCCESS = "Dental book has been cleared!";


@Override
Expand Down
48 changes: 40 additions & 8 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.patient.DateOfBirth;
import seedu.address.model.patient.Nric;
import seedu.address.model.patient.Patient;
import seedu.address.model.patient.exceptions.PersonIsNotPatient;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -90,7 +94,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson.getName()));
}

/**
Expand All @@ -100,13 +104,21 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
private static Person createEditedPerson(Person personToEdit, EditPersonDescriptor editPersonDescriptor) {
assert personToEdit != 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());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
if (personToEdit instanceof Patient) {
Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
Nric updatedNric = editPersonDescriptor.getNric().orElse(((Patient) personToEdit).getNric());
DateOfBirth updatedDob = editPersonDescriptor.getDateOfBirth().orElse(((Patient) personToEdit)
.getDateOfBirth());
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());

return new Patient(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedNric,
updatedDob);
} else {
throw new PersonIsNotPatient();
}
}

@Override
Expand All @@ -133,6 +145,8 @@ public boolean equals(Object other) {
*/
public static class EditPersonDescriptor {
private Name name;
private Nric nric;
private DateOfBirth dateOfBirth;
private Phone phone;
private Email email;
private Address address;
Expand All @@ -146,6 +160,8 @@ public EditPersonDescriptor() {}
*/
public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setName(toCopy.name);
setNric(toCopy.nric);
setDateOfBirth(toCopy.dateOfBirth);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
Expand All @@ -167,6 +183,22 @@ public Optional<Name> getName() {
return Optional.ofNullable(name);
}

public void setNric(Nric nric) {
this.nric = nric;
}

public Optional<Nric> getNric() {
return Optional.ofNullable(nric);
}

public void setDateOfBirth(DateOfBirth dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}

public Optional<DateOfBirth> getDateOfBirth() {
return Optional.ofNullable(dateOfBirth);
}

public void setPhone(Phone phone) {
this.phone = phone;
}
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;

import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.patient.DateOfBirth;
import seedu.address.model.patient.Nric;
import seedu.address.model.patient.Patient;
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.tag.Tag;

Expand All @@ -31,10 +35,11 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG,
PREFIX_NRIC, PREFIX_YEAR);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_NRIC,
PREFIX_YEAR) || !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

Expand All @@ -43,10 +48,12 @@ public AddCommand parse(String args) throws ParseException {
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Nric nric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).get());
DateOfBirth dateOfBirth = ParserUtil.parseDob(argMultimap.getValue(PREFIX_YEAR).get());

Person person = new Person(name, phone, email, address, tagList);
Patient patient = new Patient(name, phone, email, address, tagList, nric, dateOfBirth);

return new AddCommand(person);
return new AddCommand(patient);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_NRIC = new Prefix("ic/");
public static final Prefix PREFIX_YEAR = new Prefix("dob/");

}
13 changes: 12 additions & 1 deletion src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -30,9 +32,12 @@ public class EditCommandParser implements Parser<EditCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public EditCommand parse(String args) throws ParseException {
System.out.println("Edit command parser parse is run.");

requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG,
PREFIX_NRIC, PREFIX_YEAR);

Index index;

Expand All @@ -46,6 +51,12 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
}
if (argMultimap.getValue(PREFIX_NRIC).isPresent()) {
editPersonDescriptor.setNric(ParserUtil.parseNric(argMultimap.getValue(PREFIX_NRIC).get()));
}
if (argMultimap.getValue(PREFIX_YEAR).isPresent()) {
editPersonDescriptor.setDateOfBirth(ParserUtil.parseDob(argMultimap.getValue(PREFIX_YEAR).get()));
}
if (argMultimap.getValue(PREFIX_PHONE).isPresent()) {
editPersonDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()));
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.patient.DateOfBirth;
import seedu.address.model.patient.Nric;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -96,6 +98,32 @@ public static Email parseEmail(String email) throws ParseException {
return new Email(trimmedEmail);
}

/**
* Parses a {@code String nric} into an {@code Nric}.
* Leading and trailing whitespaces will be trimmed.
*/
public static Nric parseNric(String nric) throws ParseException {
requireNonNull(nric);
String trimmedNric = nric.trim();
if (!Nric.isValidNric(trimmedNric)) {
throw new ParseException(Nric.MESSAGE_CONSTRAINTS);
}
return new Nric(trimmedNric);
}

/**
* Parses a {@code String dob} into an {@code Dob}.
* Leading and trailing whitespaces will be trimmed.
*/
public static DateOfBirth parseDob(String dob) throws ParseException {
requireNonNull(dob);
String trimmedDob = dob.trim();
if (!DateOfBirth.isValidDob(dob)) {
throw new ParseException(DateOfBirth.MESSAGE_CONSTRAINTS);
}
return new DateOfBirth(trimmedDob);
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
Loading

0 comments on commit 5fbe812

Please sign in to comment.