Skip to content

Commit

Permalink
Merge pull request #30 from iamtr/branch-add-classes-for-person
Browse files Browse the repository at this point in the history
Add IC, DOB, Ward and AdmissionDate for Person class
  • Loading branch information
iamtr authored Mar 18, 2024
2 parents b4dfc39 + 4990695 commit 57f76d1
Show file tree
Hide file tree
Showing 20 changed files with 747 additions and 228 deletions.
58 changes: 54 additions & 4 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.AdmissionDate;
import seedu.address.model.person.Dob;
import seedu.address.model.person.Email;
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -100,8 +104,14 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
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);
Ic updatedIc = editPersonDescriptor.getIc().orElse(personToEdit.getIc());
Dob updatedDob = editPersonDescriptor.getDob().orElse(personToEdit.getDob());
AdmissionDate updatedAdmissionDate =
editPersonDescriptor.getAdmissionDate().orElse(personToEdit.getAdmissionDate());
Ward updatedWard = editPersonDescriptor.getWard().orElse(personToEdit.getWard());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
updatedTags, updatedDob, updatedIc, updatedAdmissionDate, updatedWard);
}

@Override
Expand Down Expand Up @@ -138,6 +148,10 @@ public static class EditPersonDescriptor {
private Email email;
private Address address;
private Set<Tag> tags;
private Ic ic;
private Dob dob;
private AdmissionDate admissionDate;
private Ward ward;

public EditPersonDescriptor() {}

Expand All @@ -151,6 +165,10 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
setDob(toCopy.dob);
setIc(toCopy.ic);
setAdmissionDate(toCopy.admissionDate);
setWard(toCopy.ward);
}

/**
Expand Down Expand Up @@ -208,7 +226,30 @@ public void setTags(Set<Tag> tags) {
public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

public void setIc(Ic ic) {
this.ic = ic;
}
public Optional<Ic> getIc() {
return Optional.ofNullable(ic);
}
public void setDob(Dob dob) {
this.dob = dob;
}
public Optional<Dob> getDob() {
return Optional.ofNullable(dob);
}
public void setAdmissionDate(AdmissionDate admissionDate) {
this.admissionDate = admissionDate;
}
public Optional<AdmissionDate> getAdmissionDate() {
return Optional.ofNullable(admissionDate);
}
public void setWard(Ward ward) {
this.ward = ward;
}
public Optional<Ward> getWard() {
return Optional.ofNullable(ward);
}
@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -225,7 +266,12 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
&& Objects.equals(tags, otherEditPersonDescriptor.tags)
&& Objects.equals(ic, otherEditPersonDescriptor.ic)
&& Objects.equals(dob, otherEditPersonDescriptor.dob)
&& Objects.equals(admissionDate, otherEditPersonDescriptor.admissionDate)
&& Objects.equals(ward, otherEditPersonDescriptor.ward);

}

@Override
Expand All @@ -236,6 +282,10 @@ public String toString() {
.add("email", email)
.add("address", address)
.add("tags", tags)
.add("ic", ic)
.add("dob", dob)
.add("admissionDate", admissionDate)
.add("ward", ward)
.toString();
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADMISSION_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
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.logic.parser.CliSyntax.PREFIX_WARD;

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.person.Address;
import seedu.address.model.person.AdmissionDate;
import seedu.address.model.person.Dob;
import seedu.address.model.person.Email;
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -31,9 +39,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_DOB, PREFIX_IC, PREFIX_ADMISSION_DATE, PREFIX_WARD);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_DOB, PREFIX_IC, PREFIX_ADMISSION_DATE, PREFIX_WARD)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
Expand All @@ -44,8 +54,14 @@ 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));
Dob dob = ParserUtil.parseDob(argMultimap.getValue(PREFIX_DOB).orElse(null));
Ic ic = ParserUtil.parseIc(argMultimap.getValue(PREFIX_IC).orElse(null));
AdmissionDate admissionDate =
ParserUtil.parseAdmissionDate(argMultimap.getValue(PREFIX_ADMISSION_DATE).orElse(null));
Ward ward = ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).orElse(null));

Person person = new Person(name, phone, email, address, tagList);

Person person = new Person(name, phone, email, address, tagList, dob, ic, admissionDate, ward);

return new AddCommand(person);
}
Expand Down
65 changes: 65 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,9 +10,13 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.AdmissionDate;
import seedu.address.model.person.Dob;
import seedu.address.model.person.Email;
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -121,4 +125,65 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
}
return tagSet;
}

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

/**
* Parses a {@code String ic} into a {@code Ic}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code ic} is invalid.
*/
public static Ic parseIc(String ic) throws ParseException {
requireNonNull(ic);
// Todo: Error handling
String trimmedIc = ic.trim();
if (!Ic.isValidIc(trimmedIc)) {
throw new ParseException(Ic.MESSAGE_CONSTRAINTS);
}
return new Ic(trimmedIc);
}

/**
* Parses a {@code String admissionDate} into a {@code AdmissionDate}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code admissionDate} is invalid.
*/
public static AdmissionDate parseAdmissionDate(String admissionDate) throws ParseException {
requireNonNull(admissionDate);
String trimmedAdmissionDate = admissionDate.trim();
if (!AdmissionDate.isValidAdmissionDate(admissionDate.trim())) {
throw new ParseException(AdmissionDate.MESSAGE_CONSTRAINTS);
}
return new AdmissionDate(trimmedAdmissionDate);
}

/**
* Parses a {@code String ward} into a {@code Ward}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code ward} is invalid.
*/
public static Ward parseWard(String ward) throws ParseException {
requireNonNull(ward);
String trimmedWard = ward.trim();
// For now we assume all strings are valid wards.
// We can change this to be better in the future.
return new Ward(trimmedWard);
}

}
53 changes: 53 additions & 0 deletions src/main/java/seedu/address/model/person/AdmissionDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a patient's admission date in the address book.
*/
public class AdmissionDate {
public static final String MESSAGE_CONSTRAINTS =
"Admission dates can take any date, and it should be in DD/MM/YYYY";
public static final String VALIDATION_REGEX = "^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/[0-9]{4}$";

public final String value;

/**
* Constructs a {@code AdmissionDate}.
*
* @param value A valid admission date.
*/
public AdmissionDate(String value) {
requireNonNull(value);
checkArgument(isValidAdmissionDate(value), MESSAGE_CONSTRAINTS);
this.value = value;
}
public static boolean isValidAdmissionDate(String admissionDate) {
return admissionDate.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return value.toString();
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof AdmissionDate)) {
return false;
}

AdmissionDate otherAdmissionDate = (AdmissionDate) other;
return value.equals(otherAdmissionDate.value);
}

@Override
public int hashCode() {
return value.hashCode();
}
}
56 changes: 56 additions & 0 deletions src/main/java/seedu/address/model/person/Dob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a patient's date of birth in the address book.
*/
public class Dob {
public static final String MESSAGE_CONSTRAINTS = "Dates of birth takes in a date";
public static final String VALIDATION_REGEX = "^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/[0-9]{4}$";

public final String value;

/**
* Constructs a {@code Dob}.
*
* @param value A valid date of birth.
*/
public Dob(String value) {
requireNonNull(value);
checkArgument(isValidDob(value), MESSAGE_CONSTRAINTS);
this.value = value;
}

public static boolean isValidDob(String dob) {
return dob.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

if (!(other instanceof Dob)) {
return false;
}

Dob otherDob = (Dob) other;
return value.equals(otherDob.value);
}

@Override
public int hashCode() {
return value.hashCode();
}

// Todo: isValidDob

}
Loading

0 comments on commit 57f76d1

Please sign in to comment.