diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 297aee7f3f5..2bc71375c85 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -43,8 +43,16 @@ public static String format(Patient patient) { .append(patient.getPhone()) .append("; Email: ") .append(patient.getEmail()) + .append("; Gender: ") + .append(patient.getGender()) + .append("; IC Number: ") + .append(patient.getIcNumber()) + .append("; Birthday: ") + .append(patient.getBirthday()) .append("; Address: ") .append(patient.getAddress()) + .append("; Department: ") + .append(patient.getAssignedDepartment()) .append("; Tags: "); patient.getTags().forEach(builder::append); return builder.toString(); diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index d41e67de48e..a8a0d2175d2 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -2,7 +2,10 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_BIRTHDAY; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_IC_NUMBER; 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; @@ -25,12 +28,18 @@ public class AddCommand extends Command { + PREFIX_NAME + "NAME " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + + PREFIX_GENDER + "GENDER " + + PREFIX_IC_NUMBER + "IC_NUMBER " + + PREFIX_BIRTHDAY + "BIRTHDAY " + PREFIX_ADDRESS + "ADDRESS " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + + PREFIX_GENDER + "MALE " + + PREFIX_IC_NUMBER + "S2840182A " + + PREFIX_BIRTHDAY + "02/01/1998 " + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " + PREFIX_TAG + "friends " + PREFIX_TAG + "owesMoney"; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index a434a38c20d..1f1a635a1ab 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -2,7 +2,10 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_BIRTHDAY; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_IC_NUMBER; 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; @@ -22,7 +25,10 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.patient.Address; +import seedu.address.model.patient.Birthday; import seedu.address.model.patient.Email; +import seedu.address.model.patient.Gender; +import seedu.address.model.patient.IcNumber; import seedu.address.model.patient.Name; import seedu.address.model.patient.Patient; import seedu.address.model.patient.Phone; @@ -36,17 +42,18 @@ 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 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] " - + "[" + PREFIX_PHONE + "PHONE] " - + "[" + PREFIX_EMAIL + "EMAIL] " - + "[" + PREFIX_ADDRESS + "ADDRESS] " - + "[" + PREFIX_TAG + "TAG]...\n" - + "Example: " + COMMAND_WORD + " 1 " - + PREFIX_PHONE + "91234567 " - + PREFIX_EMAIL + "johndoe@example.com"; + + "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] " + + "[" + PREFIX_PHONE + "PHONE] " + + "[" + PREFIX_EMAIL + "EMAIL] " + + "[" + PREFIX_GENDER + "GENDER] " + + "[" + PREFIX_IC_NUMBER + "IC_NUMBER] " + + "[" + PREFIX_BIRTHDAY + "BIRTHDAY] " + + "[" + PREFIX_ADDRESS + "ADDRESS] " + + "[" + PREFIX_TAG + "TAG]...\n" + + "Example: " + COMMAND_WORD + " 1 " + PREFIX_PHONE + "91234567 " + PREFIX_EMAIL + "johndoe@example.com"; 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."; @@ -56,7 +63,7 @@ public class EditCommand extends Command { private final EditPatientDescriptor editPatientDescriptor; /** - * @param index of the patient in the filtered patient list to edit + * @param index of the patient in the filtered patient list to edit * @param editPatientDescriptor details to edit the patient with */ public EditCommand(Index index, EditPatientDescriptor editPatientDescriptor) { @@ -98,12 +105,17 @@ private static Patient createEditedPatient(Patient patientToEdit, EditPatientDes Name updatedName = editPatientDescriptor.getName().orElse(patientToEdit.getName()); Phone updatedPhone = editPatientDescriptor.getPhone().orElse(patientToEdit.getPhone()); Email updatedEmail = editPatientDescriptor.getEmail().orElse(patientToEdit.getEmail()); + Gender updatedGender = editPatientDescriptor.getGender().orElse(patientToEdit.getGender()); + IcNumber updatedIcNumber = editPatientDescriptor.getIcNumber().orElse(patientToEdit.getIcNumber()); + Birthday updatedBirthday = editPatientDescriptor.getBirthday().orElse(patientToEdit.getBirthday()); Address updatedAddress = editPatientDescriptor.getAddress().orElse(patientToEdit.getAddress()); Set updatedTags = editPatientDescriptor.getTags().orElse(patientToEdit.getTags()); - return new Patient(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Patient(updatedName, updatedPhone, updatedEmail, updatedGender, updatedIcNumber, updatedBirthday, + updatedAddress, updatedTags); } + @Override public boolean equals(Object other) { if (other == this) { @@ -116,16 +128,14 @@ public boolean equals(Object other) { } EditCommand otherEditCommand = (EditCommand) other; - return index.equals(otherEditCommand.index) - && editPatientDescriptor.equals(otherEditCommand.editPatientDescriptor); + return index.equals(otherEditCommand.index) && editPatientDescriptor.equals( + otherEditCommand.editPatientDescriptor); } @Override public String toString() { - return new ToStringBuilder(this) - .add("index", index) - .add("editPatientDescriptor", editPatientDescriptor) - .toString(); + return new ToStringBuilder(this).add("index", index).add("editPatientDescriptor", editPatientDescriptor) + .toString(); } /** @@ -136,10 +146,14 @@ public static class EditPatientDescriptor { private Name name; private Phone phone; private Email email; + private Gender gender; + private IcNumber icNumber; + private Birthday birthday; private Address address; private Set tags; - public EditPatientDescriptor() {} + public EditPatientDescriptor() { + } /** * Copy constructor. @@ -149,6 +163,9 @@ public EditPatientDescriptor(EditPatientDescriptor toCopy) { setName(toCopy.name); setPhone(toCopy.phone); setEmail(toCopy.email); + setGender(toCopy.gender); + setIcNumber(toCopy.icNumber); + setBirthday(toCopy.birthday); setAddress(toCopy.address); setTags(toCopy.tags); } @@ -157,7 +174,7 @@ public EditPatientDescriptor(EditPatientDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, address, tags); + return CollectionUtil.isAnyNonNull(name, phone, email, gender, icNumber, birthday, address, tags); } public void setName(Name name) { @@ -224,19 +241,48 @@ public boolean equals(Object other) { return Objects.equals(name, otherEditPatientDescriptor.name) && Objects.equals(phone, otherEditPatientDescriptor.phone) && Objects.equals(email, otherEditPatientDescriptor.email) + && Objects.equals(gender, otherEditPatientDescriptor.gender) + && Objects.equals(icNumber, otherEditPatientDescriptor.icNumber) + && Objects.equals(birthday, otherEditPatientDescriptor.birthday) && Objects.equals(address, otherEditPatientDescriptor.address) && Objects.equals(tags, otherEditPatientDescriptor.tags); } + public void setGender(Gender gender) { + this.gender = gender; + } + + public Optional getGender() { + return Optional.ofNullable(gender); + } + + public void setBirthday(Birthday birthday) { + this.birthday = birthday; + } + + public Optional getBirthday() { + return Optional.ofNullable(birthday); + } + + public void setIcNumber(IcNumber icNumber) { + this.icNumber = icNumber; + } + + public Optional getIcNumber() { + return Optional.ofNullable(icNumber); + } + @Override public String toString() { return new ToStringBuilder(this) .add("name", name) .add("phone", phone) .add("email", email) + .add("gender", gender) + .add("icNumber", icNumber) + .add("birthday", birthday) .add("address", address) - .add("tags", tags) - .toString(); + .add("tags", tags).toString(); } } } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 7a58a19bf1c..540148627be 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -3,7 +3,10 @@ import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.Messages.MESSAGE_REQUIRED_COMMAND_NOT_FOUND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_BIRTHDAY; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_IC_NUMBER; 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; @@ -18,7 +21,10 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.patient.Address; +import seedu.address.model.patient.Birthday; import seedu.address.model.patient.Email; +import seedu.address.model.patient.Gender; +import seedu.address.model.patient.IcNumber; import seedu.address.model.patient.Name; import seedu.address.model.patient.Patient; import seedu.address.model.patient.Phone; @@ -30,11 +36,13 @@ public class AddCommandParser implements Parser { public static final Prefix[] RELEVANT_PREFIXES = new Prefix[]{PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, - PREFIX_ADDRESS, PREFIX_TAG}; + PREFIX_GENDER, PREFIX_IC_NUMBER, PREFIX_BIRTHDAY, PREFIX_ADDRESS, PREFIX_TAG}; + public static final Prefix[] RELEVANT_PREFIXES_WITHOUT_TAG = new Prefix[]{PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_GENDER, PREFIX_IC_NUMBER, PREFIX_BIRTHDAY, PREFIX_ADDRESS}; public static final Prefix[] REQUIRED_PREFIXES = new Prefix[]{PREFIX_NAME}; - public static final Prefix[] OPTIONAL_PREFIXES = new Prefix[]{PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, - PREFIX_TAG}; + public static final Prefix[] OPTIONAL_PREFIXES = new Prefix[]{PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, + PREFIX_IC_NUMBER, PREFIX_BIRTHDAY, PREFIX_ADDRESS, PREFIX_TAG}; /** @@ -58,21 +66,50 @@ public static Prefix[] getPrefixesPresent(ArgumentMultimap argMultimap) { } /** - * Takes in a list of prefixes and creates patients with its corresponding values in argMultimap, if - * optional field values are missing, fill it with default instead. + * Create Patient from prefixes present * - * @param argMultimap Argument multimap which contains prefix to value mapping - * @param prefixes List of prefixes present - * @return Patient object + * @param argMultimap Contains mapping of key which is prefix and value which is argument value + * @param prefixes List of prefixes present in argument + * @return Patient with the fields present in user input * @throws ParseException if the user input does not conform the expected format */ public static Patient createPatientFromPrefixes(ArgumentMultimap argMultimap, Prefix[] prefixes) throws ParseException { + // filling the fields with default values Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); - Phone phone = new Phone("12345678"); - Email email = new Email("default_email@gmail.com"); - Address address = new Address("Address not added"); + Phone phone = new Phone(Phone.DEFAULT_PHONE); + Email email = new Email(Email.DEFAULT_EMAIL); + Gender gender = new Gender(Gender.DEFAULT_GENDER); + IcNumber icNumber = new IcNumber(IcNumber.DEFAULT_IC_NUMBER); + Birthday birthday = new Birthday(Birthday.DEFAULT_BIRTHDAY); + Address address = new Address(Address.DEFAULT_ADDRESS); Set tagList = new HashSet<>(); + + // passing to helper function to replace fields with actual values if it exists + return createPatientFromPresentPrefixes(name, phone, email, gender, icNumber, birthday, address, tagList, + argMultimap, prefixes); + } + + /** + * Replaces Patient fields with actual value if it is present in argMultimap + * + * @param name Name of patient + * @param phone Phone number of patient + * @param email Email of patient + * @param gender Gender of Patient + * @param icNumber IcNumber of Patient + * @param birthday Birthday of Patient + * @param address Address of Patient + * @param tags Tags of Patient + * @param argMultimap Contains mapping of key which is prefix and value which is argument value + * @param prefixes List of prefixes present in argument + * @return Patient with the fields present in user input + * @throws ParseException if the user input does not conform the expected format + */ + public static Patient createPatientFromPresentPrefixes(Name name, Phone phone, Email email, Gender gender, + IcNumber icNumber, Birthday birthday, Address address, + Set tags, ArgumentMultimap argMultimap, + Prefix[] prefixes) throws ParseException { for (Prefix p : prefixes) { switch (p.getPrefix()) { case "p/": @@ -85,12 +122,21 @@ public static Patient createPatientFromPrefixes(ArgumentMultimap argMultimap, Pr address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); break; case "t/": - tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + tags = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + break; + case "g/": + gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()); + break; + case "b/": + birthday = ParserUtil.parseBirthday(argMultimap.getValue(PREFIX_BIRTHDAY).get()); + break; + case "i/": + icNumber = ParserUtil.parseIcNumber(argMultimap.getValue(PREFIX_IC_NUMBER).get()); break; default: } } - return new Patient(name, phone, email, address, tagList); + return new Patient(name, phone, email, gender, icNumber, birthday, address, tags); } /** @@ -111,7 +157,7 @@ public AddCommand parse(String args) throws ParseException { throw new ParseException( String.format(MESSAGE_REQUIRED_COMMAND_NOT_FOUND_FORMAT, Arrays.toString(REQUIRED_PREFIXES))); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); + argMultimap.verifyNoDuplicatePrefixesFor(RELEVANT_PREFIXES_WITHOUT_TAG); Prefix[] prefixesPresent = getPrefixesPresent(argMultimap); Patient patient = createPatientFromPrefixes(argMultimap, prefixesPresent); diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 34f4548df73..06968d8b10a 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -3,7 +3,10 @@ import static java.util.Objects.requireNonNull; 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_BIRTHDAY; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_IC_NUMBER; 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; @@ -19,6 +22,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.tag.Tag; + /** * Parses input arguments and creates a new EditCommand object */ @@ -27,12 +31,13 @@ public class EditCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the EditCommand * and returns an EditCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public EditCommand parse(String args) throws ParseException { requireNonNull(args); - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_ADDRESS, PREFIX_TAG, PREFIX_GENDER, PREFIX_BIRTHDAY, PREFIX_IC_NUMBER); Index index; @@ -42,7 +47,8 @@ public EditCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, + PREFIX_IC_NUMBER, PREFIX_BIRTHDAY, PREFIX_ADDRESS); EditPatientDescriptor editPatientDescriptor = new EditPatientDescriptor(); @@ -58,6 +64,16 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { editPatientDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); } + if (argMultimap.getValue(PREFIX_GENDER).isPresent()) { + editPatientDescriptor.setGender(ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get())); + } + if (argMultimap.getValue(PREFIX_BIRTHDAY).isPresent()) { + editPatientDescriptor.setBirthday(ParserUtil.parseBirthday(argMultimap.getValue(PREFIX_BIRTHDAY).get())); + } + if (argMultimap.getValue(PREFIX_IC_NUMBER).isPresent()) { + editPatientDescriptor.setIcNumber(ParserUtil.parseIcNumber(argMultimap.getValue(PREFIX_IC_NUMBER).get())); + } + parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPatientDescriptor::setTags); if (!editPatientDescriptor.isAnyFieldEdited()) { diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index d4b34666a2e..7aa074c664c 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -10,7 +10,11 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.patient.Address; +import seedu.address.model.patient.AssignedDepartment; +import seedu.address.model.patient.Birthday; import seedu.address.model.patient.Email; +import seedu.address.model.patient.Gender; +import seedu.address.model.patient.IcNumber; import seedu.address.model.patient.Name; import seedu.address.model.patient.Phone; import seedu.address.model.tag.Tag; @@ -21,6 +25,8 @@ public class ParserUtil { public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer."; + public static final String MESSAGE_CONSTRAINTS = "Department name is invalid. " + + "Please enter a valid department name."; /** * Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be @@ -110,6 +116,66 @@ public static Tag parseTag(String tag) throws ParseException { return new Tag(trimmedTag); } + /** + * Parses a {@code String gender} into a {@code Gender}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code gender} is invalid. + */ + public static Gender parseGender(String gender) throws ParseException { + requireNonNull(gender); + String trimmedGender = gender.trim(); + if (!Gender.isValidGender(trimmedGender)) { + throw new ParseException(Gender.MESSAGE_CONSTRAINTS); + } + return new Gender(trimmedGender); + } + + /** + * Parses a {@code String birthday} into a {@code Birthday}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code birthday} is invalid. + */ + public static Birthday parseBirthday(String birthday) throws ParseException { + requireNonNull(birthday); + String trimmedBirthday = birthday.trim(); + if (!Birthday.isValidBirthdate(trimmedBirthday)) { + throw new ParseException(Birthday.MESSAGE_CONSTRAINTS); + } + return new Birthday(trimmedBirthday); + } + + /** + * Parses a {@code String icNumber} into a {@code IcNumber}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code icNumber} is invalid. + */ + public static IcNumber parseIcNumber(String icNumber) throws ParseException { + requireNonNull(icNumber); + String trimmedIcNumber = icNumber.trim(); + if (!IcNumber.isValidIC(trimmedIcNumber)) { + throw new ParseException(IcNumber.MESSAGE_CONSTRAINTS); + } + return new IcNumber(trimmedIcNumber); + } + + /** + * Parses a {@code String department} into a {@code Department}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code department} is invalid. + */ + public static AssignedDepartment parseAssignedDepartment(String department) throws ParseException { + requireNonNull(department); + String trimmedDepartment = department.trim(); + if (!AssignedDepartment.isValidDepartment(trimmedDepartment)) { + throw new ParseException(AssignedDepartment.MESSAGE_CONSTRAINTS); + } + return new AssignedDepartment(trimmedDepartment); + } + /** * Parses {@code Collection tags} into a {@code Set}. */ diff --git a/src/main/java/seedu/address/model/patient/Address.java b/src/main/java/seedu/address/model/patient/Address.java index d4b648fe13a..419eaa72cba 100644 --- a/src/main/java/seedu/address/model/patient/Address.java +++ b/src/main/java/seedu/address/model/patient/Address.java @@ -16,6 +16,7 @@ public class Address { * otherwise " " (a blank string) becomes a valid input. */ public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String DEFAULT_ADDRESS = "No address was added"; public final String value; diff --git a/src/main/java/seedu/address/model/patient/Age.java b/src/main/java/seedu/address/model/patient/Age.java index f3b2bad4b61..3c70352dc66 100644 --- a/src/main/java/seedu/address/model/patient/Age.java +++ b/src/main/java/seedu/address/model/patient/Age.java @@ -11,6 +11,7 @@ public class Age { public static final String MESSAGE_CONSTRAINTS = "Age should only contain numbers, and it should not be negative"; public static final String VALIDATION_REGEX = "\\d+"; + public static final String DEFAULT_AGE = "00"; public final String value; /** diff --git a/src/main/java/seedu/address/model/patient/Birthday.java b/src/main/java/seedu/address/model/patient/Birthday.java index d58a25a5668..d1ad2e82850 100644 --- a/src/main/java/seedu/address/model/patient/Birthday.java +++ b/src/main/java/seedu/address/model/patient/Birthday.java @@ -14,9 +14,10 @@ public class Birthday { public static final String MESSAGE_CONSTRAINTS = "Birth dates should only contain numbers in valid dd/MM/yyyy format"; public static final String VALIDATION_REGEX = "\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}"; + public static final String DEFAULT_BIRTHDAY = "01/01/2000"; public final LocalDate value; + public final String strValue; private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - /** * Constructs a {@code Birthday}. * @@ -25,6 +26,7 @@ public class Birthday { public Birthday(String birthdate) { requireNonNull(birthdate); checkArgument(isValidBirthdate(birthdate), MESSAGE_CONSTRAINTS); + strValue = birthdate; value = LocalDate.parse(birthdate, formatter); } diff --git a/src/main/java/seedu/address/model/patient/Email.java b/src/main/java/seedu/address/model/patient/Email.java index 86c6ba0bddd..7bec4e2d014 100644 --- a/src/main/java/seedu/address/model/patient/Email.java +++ b/src/main/java/seedu/address/model/patient/Email.java @@ -9,6 +9,7 @@ */ public class Email { + public static final String DEFAULT_EMAIL = "default_email@gmail.com"; private static final String SPECIAL_CHARACTERS = "+_.-"; public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain " + "and adhere to the following constraints:\n" diff --git a/src/main/java/seedu/address/model/patient/Gender.java b/src/main/java/seedu/address/model/patient/Gender.java index b69595d6a46..15a0a755128 100644 --- a/src/main/java/seedu/address/model/patient/Gender.java +++ b/src/main/java/seedu/address/model/patient/Gender.java @@ -12,7 +12,7 @@ public class Gender { "Gender should only be MALE, FEMALE or OTHER, and it should not be blank"; public static final String VALIDATION_REGEX = "\\p{Alnum}*"; - + public static final String DEFAULT_GENDER = "OTHER"; public final String value; enum Genders { diff --git a/src/main/java/seedu/address/model/patient/IcNumber.java b/src/main/java/seedu/address/model/patient/IcNumber.java index d421cdb92c2..e910c81e8cc 100644 --- a/src/main/java/seedu/address/model/patient/IcNumber.java +++ b/src/main/java/seedu/address/model/patient/IcNumber.java @@ -11,6 +11,7 @@ public class IcNumber { public static final String MESSAGE_CONSTRAINTS = "IC Number should start and end with an alphabet with non negative numbers in between"; public static final String VALIDATION_REGEX = "^[A-Z]\\d{7}[A-Z]$"; + public static final String DEFAULT_IC_NUMBER = "t0000000a"; public final String value; /** diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index d48cc164e92..2b8a38414d2 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -34,7 +34,7 @@ public class Patient { * Every field must be present and not null. */ public Patient(Name name, Phone phone, Email email, Gender gender, IcNumber icNumber, Birthday birthday, - Address address, Set tags, AssignedDepartment assignedDepartment, Record record) { + Address address, Set tags) { requireAllNonNull(name, phone, email, icNumber, birthday, address, tags); this.name = name; this.phone = phone; @@ -44,8 +44,8 @@ public Patient(Name name, Phone phone, Email email, Gender gender, IcNumber icNu this.birthday = birthday; this.address = address; this.tags.addAll(tags); - this.assignedDepartment = assignedDepartment; - this.record = record; + this.assignedDepartment = new AssignedDepartment(); // default Department given + this.record = new Record(); // creates new Record } public Name getName() { @@ -101,8 +101,7 @@ public boolean isSamePatient(Patient otherPatient) { return true; } - return otherPatient != null - && otherPatient.getName().equals(getName()); + return otherPatient != null && otherPatient.getName().equals(getName()); } /** @@ -121,16 +120,10 @@ public boolean equals(Object other) { } Patient otherPatient = (Patient) other; - return name.equals(otherPatient.name) - && phone.equals(otherPatient.phone) - && email.equals(otherPatient.email) - && gender.equals(otherPatient.gender) - && icNumber.equals(otherPatient.icNumber) - && birthday.equals(otherPatient.birthday) - && address.equals(otherPatient.address) - && tags.equals(otherPatient.tags) - && assignedDepartment.equals(otherPatient.assignedDepartment) - && record.equals(otherPatient.record); + return name.equals(otherPatient.name) && phone.equals(otherPatient.phone) && email.equals(otherPatient.email) + && gender.equals(otherPatient.gender) && icNumber.equals(otherPatient.icNumber) && birthday.equals( + otherPatient.birthday) && address.equals(otherPatient.address) && tags.equals(otherPatient.tags) + && assignedDepartment.equals(otherPatient.assignedDepartment) && record.equals(otherPatient.record); } @Override @@ -141,18 +134,9 @@ public int hashCode() { @Override public String toString() { - return new ToStringBuilder(this) - .add("name", name) - .add("phone", phone) - .add("email", email) - .add("gender", gender) - .add("icNumber", icNumber) - .add("birthday", birthday) - .add("address", address) - .add("tags", tags) - .add ("assignedDepartment", assignedDepartment) - .add("record", record) - .toString(); + return new ToStringBuilder(this).add("name", name).add("phone", phone).add("email", email).add("gender", gender) + .add("icNumber", icNumber).add("birthday", birthday).add("address", address).add("tags", tags) + .add("assignedDepartment", assignedDepartment).add("record", record).toString(); } } diff --git a/src/main/java/seedu/address/model/patient/Phone.java b/src/main/java/seedu/address/model/patient/Phone.java index 98cd5422062..654781a27d5 100644 --- a/src/main/java/seedu/address/model/patient/Phone.java +++ b/src/main/java/seedu/address/model/patient/Phone.java @@ -13,6 +13,7 @@ public class Phone { public static final String MESSAGE_CONSTRAINTS = "Phone numbers should only contain numbers, and it should be at least 3 digits long"; public static final String VALIDATION_REGEX = "\\d{3,}"; + public static final String DEFAULT_PHONE = "00000000"; public final String value; /** diff --git a/src/main/java/seedu/address/model/patient/Record.java b/src/main/java/seedu/address/model/patient/Record.java index c307f6f7589..e7c501fda1e 100644 --- a/src/main/java/seedu/address/model/patient/Record.java +++ b/src/main/java/seedu/address/model/patient/Record.java @@ -8,23 +8,40 @@ */ public class Record { + public static final String DEFAULT_INITIAL_OBSERVATIONS = "No initial observations given"; + public static final String DEFAULT_DIAGNOSIS = "No diagnosis given"; + public static final String DEFAULT_TREATMENT_PLAN = "No treatment plan given"; + private final Patient patient; private String initialObservations; private String diagnosis; private String treatmentPlan; /** - * Initializes a Record with the associated patient. - * - * @param patient The patient associated with this record. + * Initializes a Record with the associated patient and initialise the fields with default values */ public Record(Patient patient) { this.patient = patient; + this.initialObservations = DEFAULT_INITIAL_OBSERVATIONS; + this.diagnosis = DEFAULT_DIAGNOSIS; + this.treatmentPlan = DEFAULT_TREATMENT_PLAN; } + /** + * Initializes a Record with a null patient and initialise the fields with default values + */ + public Record() { + this.patient = null; // patient left null, would have to fix when building editing record command + this.initialObservations = DEFAULT_INITIAL_OBSERVATIONS; + this.diagnosis = DEFAULT_DIAGNOSIS; + this.treatmentPlan = DEFAULT_TREATMENT_PLAN; + } + + public Patient getPatient() { return patient; } + public String getInitialObservations() { return initialObservations; } @@ -51,11 +68,7 @@ public void setTreatmentPlan(String treatmentPlan) { @Override public String toString() { - return new ToStringBuilder(this) - .add("patient", patient) - .add("initialObservations", initialObservations) - .add("diagnosis", diagnosis) - .add("treatmentPlan", treatmentPlan) - .toString(); + return new ToStringBuilder(this).add("patient", patient).add("initialObservations", initialObservations) + .add("diagnosis", diagnosis).add("treatmentPlan", treatmentPlan).toString(); } } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 521c5c24c2c..97c757067d5 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -7,7 +7,10 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.patient.Address; +import seedu.address.model.patient.Birthday; import seedu.address.model.patient.Email; +import seedu.address.model.patient.Gender; +import seedu.address.model.patient.IcNumber; import seedu.address.model.patient.Name; import seedu.address.model.patient.Patient; import seedu.address.model.patient.Phone; @@ -18,26 +21,32 @@ */ public class SampleDataUtil { public static Patient[] getSamplePatients() { - return new Patient[] { - new Patient(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends")), - new Patient(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), - new Patient(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), - new Patient(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), - new Patient(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), - new Patient(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues")) - }; + return new Patient[]{ + new Patient(new Name("Alex Yeoh"), new Phone("87438807"), + new Email("alexyeoh@example.com"), new Gender("Male"), new IcNumber("t7654321a"), + new Birthday("05/05/2005"), new Address("Blk 30 Geylang " + "Street " + "29, #06-40"), + getTagSet("friends")), + new Patient(new Name("Bernice Yu"), new Phone("99272758"), + new Email("berniceyu@example.com"), new Gender("Female"), new IcNumber("s1234567b"), + new Birthday("06/06/1990"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), + getTagSet("colleagues", "friends")), + new Patient(new Name("Charlotte Oliveiro"), new Phone("93210283"), + new Email("charlotte@example.com"), new Gender("Other"), new IcNumber("t1357912g"), + new Birthday("12/12/1989"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), + getTagSet("neighbours")), + new Patient(new Name("David Li"), new Phone("91031282"), + new Email("lidavid@example.com"), new Gender("Male"), + new IcNumber("s7654321p"), new Birthday("01/01/2001"), + new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), getTagSet("family")), + new Patient(new Name("Irfan Ibrahim"), new Phone("92492021"), + new Email("irfan@example.com"), new Gender("Male"), + new IcNumber("s0987654e"), new Birthday("10/10/2000"), + new Address("Blk 47 Tampines Street 20, #17-35"), + getTagSet("classmates")), + new Patient(new Name("Roy Balakrishnan"), new Phone("92624417"), + new Email("royb@example.com"), new Gender("Male"), + new IcNumber("t6789031q"), new Birthday("07/11/1976"), + new Address("Blk 45 Aljunied Street 85, #11-31"), getTagSet("colleagues"))}; } public static ReadOnlyAddressBook getSampleAddressBook() { @@ -52,9 +61,7 @@ public static ReadOnlyAddressBook getSampleAddressBook() { * Returns a tag set containing the list of strings given. */ public static Set getTagSet(String... strings) { - return Arrays.stream(strings) - .map(Tag::new) - .collect(Collectors.toSet()); + return Arrays.stream(strings).map(Tag::new).collect(Collectors.toSet()); } } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPatient.java b/src/main/java/seedu/address/storage/JsonAdaptedPatient.java index dfa1eb936a5..8c28b694f91 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPatient.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPatient.java @@ -11,7 +11,10 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.patient.Address; +import seedu.address.model.patient.Birthday; import seedu.address.model.patient.Email; +import seedu.address.model.patient.Gender; +import seedu.address.model.patient.IcNumber; import seedu.address.model.patient.Name; import seedu.address.model.patient.Patient; import seedu.address.model.patient.Phone; @@ -27,6 +30,9 @@ class JsonAdaptedPatient { private final String name; private final String phone; private final String email; + private final String gender; + private final String icNumber; + private final String birthday; private final String address; private final List tags = new ArrayList<>(); @@ -35,11 +41,16 @@ class JsonAdaptedPatient { */ @JsonCreator public JsonAdaptedPatient(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("email") String email, @JsonProperty("gender") String gender, + @JsonProperty("icNumber") String icNumber, @JsonProperty("birthday") String birthday, + @JsonProperty("address") String address, @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; this.email = email; + this.gender = gender; + this.icNumber = icNumber; + this.birthday = birthday; this.address = address; if (tags != null) { this.tags.addAll(tags); @@ -53,10 +64,11 @@ public JsonAdaptedPatient(Patient source) { name = source.getName().fullName; phone = source.getPhone().value; email = source.getEmail().value; + gender = source.getGender().value; + icNumber = source.getIcNumber().value; + birthday = source.getBirthday().strValue; address = source.getAddress().value; - tags.addAll(source.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList())); + tags.addAll(source.getTags().stream().map(JsonAdaptedTag::new).collect(Collectors.toList())); } /** @@ -69,7 +81,6 @@ public Patient toModelType() throws IllegalValueException { for (JsonAdaptedTag tag : tags) { patientTags.add(tag.toModelType()); } - if (name == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); } @@ -94,6 +105,35 @@ public Patient toModelType() throws IllegalValueException { } final Email modelEmail = new Email(email); + + if (gender == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Gender.class.getSimpleName())); + } + if (!Gender.isValidGender(gender)) { + throw new IllegalValueException(Gender.MESSAGE_CONSTRAINTS); + } + final Gender modelGender = new Gender(gender); + + + if (icNumber == null) { + throw new IllegalValueException( + String.format(MISSING_FIELD_MESSAGE_FORMAT, IcNumber.class.getSimpleName())); + } + if (!IcNumber.isValidIC(icNumber)) { + throw new IllegalValueException(IcNumber.MESSAGE_CONSTRAINTS); + } + final IcNumber modelIcNumber = new IcNumber(icNumber); + + + if (birthday == null) { + throw new IllegalValueException( + String.format(MISSING_FIELD_MESSAGE_FORMAT, Birthday.class.getSimpleName())); + } + if (!Birthday.isValidBirthdate(birthday)) { + throw new IllegalValueException(Birthday.MESSAGE_CONSTRAINTS); + } + final Birthday modelBirthday = new Birthday(birthday); + if (address == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); } @@ -103,7 +143,8 @@ public Patient toModelType() throws IllegalValueException { final Address modelAddress = new Address(address); final Set modelTags = new HashSet<>(patientTags); - return new Patient(modelName, modelPhone, modelEmail, modelAddress, modelTags); + return new Patient(modelName, modelPhone, modelEmail, modelGender, modelIcNumber, modelBirthday, modelAddress, + modelTags); } } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPatientTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPatientTest.java index 9ed0978ec70..79c85e39562 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPatientTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPatientTest.java @@ -22,15 +22,20 @@ public class JsonAdaptedPatientTest { private static final String INVALID_PHONE = "+651234"; private static final String INVALID_ADDRESS = " "; private static final String INVALID_EMAIL = "example.com"; + private static final String INVALID_GENDER = "ma1e"; + private static final String INVALID_IC_NUMBER = "ta1234560"; + private static final String INVALID_BIRTHDAY = "2000/20/20"; private static final String INVALID_TAG = "#friend"; private static final String VALID_NAME = BENSON.getName().toString(); private static final String VALID_PHONE = BENSON.getPhone().toString(); private static final String VALID_EMAIL = BENSON.getEmail().toString(); + private static final String VALID_GENDER = BENSON.getGender().toString(); + private static final String VALID_IC_NUMBER = BENSON.getIcNumber().toString(); + private static final String VALID_BIRTHDAY = BENSON.getIcNumber().toString(); private static final String VALID_ADDRESS = BENSON.getAddress().toString(); - private static final List VALID_TAGS = BENSON.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList()); + private static final List VALID_TAGS = BENSON.getTags().stream().map(JsonAdaptedTag::new) + .collect(Collectors.toList()); @Test public void toModelType_validPatientDetails_returnsPatient() throws Exception { @@ -40,60 +45,64 @@ public void toModelType_validPatientDetails_returnsPatient() throws Exception { @Test public void toModelType_invalidName_throwsIllegalValueException() { - JsonAdaptedPatient patient = - new JsonAdaptedPatient(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, VALID_ADDRESS, VALID_TAGS); String expectedMessage = Name.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @Test public void toModelType_nullName_throwsIllegalValueException() { - JsonAdaptedPatient patient = new JsonAdaptedPatient(null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(null, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, VALID_ADDRESS, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @Test public void toModelType_invalidPhone_throwsIllegalValueException() { - JsonAdaptedPatient patient = - new JsonAdaptedPatient(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, VALID_ADDRESS, VALID_TAGS); String expectedMessage = Phone.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @Test public void toModelType_nullPhone_throwsIllegalValueException() { - JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, null, VALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, VALID_ADDRESS, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @Test public void toModelType_invalidEmail_throwsIllegalValueException() { - JsonAdaptedPatient patient = - new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, VALID_ADDRESS, VALID_TAGS); String expectedMessage = Email.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @Test public void toModelType_nullEmail_throwsIllegalValueException() { - JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, null, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, VALID_ADDRESS, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @Test public void toModelType_invalidAddress_throwsIllegalValueException() { - JsonAdaptedPatient patient = - new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, INVALID_ADDRESS, VALID_TAGS); String expectedMessage = Address.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @Test public void toModelType_nullAddress_throwsIllegalValueException() { - JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, VALID_TAGS); + JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, null, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, patient::toModelType); } @@ -102,8 +111,8 @@ public void toModelType_nullAddress_throwsIllegalValueException() { public void toModelType_invalidTags_throwsIllegalValueException() { List invalidTags = new ArrayList<>(VALID_TAGS); invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); - JsonAdaptedPatient patient = - new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, invalidTags); + JsonAdaptedPatient patient = new JsonAdaptedPatient(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_GENDER, + VALID_IC_NUMBER, VALID_BIRTHDAY, VALID_ADDRESS, invalidTags); assertThrows(IllegalValueException.class, patient::toModelType); } diff --git a/src/test/java/seedu/address/testutil/PatientBuilder.java b/src/test/java/seedu/address/testutil/PatientBuilder.java index 9a7330c83b5..d4af378f6bd 100644 --- a/src/test/java/seedu/address/testutil/PatientBuilder.java +++ b/src/test/java/seedu/address/testutil/PatientBuilder.java @@ -4,10 +4,15 @@ import java.util.Set; import seedu.address.model.patient.Address; +import seedu.address.model.patient.AssignedDepartment; +import seedu.address.model.patient.Birthday; import seedu.address.model.patient.Email; +import seedu.address.model.patient.Gender; +import seedu.address.model.patient.IcNumber; import seedu.address.model.patient.Name; import seedu.address.model.patient.Patient; import seedu.address.model.patient.Phone; +import seedu.address.model.patient.Record; import seedu.address.model.tag.Tag; import seedu.address.model.util.SampleDataUtil; @@ -19,13 +24,21 @@ public class PatientBuilder { public static final String DEFAULT_NAME = "Amy Bee"; public static final String DEFAULT_PHONE = "85355255"; public static final String DEFAULT_EMAIL = "amy@gmail.com"; + public static final String DEFAULT_GENDER = "female"; + public static final String DEFAULT_IC_NUMBER = "t1234567j"; + public static final String DEFAULT_BIRTHDAY = "21/01/1994"; public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111"; private Name name; private Phone phone; private Email email; + private Gender gender; + private IcNumber icNumber; + private Birthday birthday; private Address address; private Set tags; + private AssignedDepartment assignedDepartment; + private final Record record; /** * Creates a {@code PatientBuilder} with the default details. @@ -34,8 +47,13 @@ public PatientBuilder() { name = new Name(DEFAULT_NAME); phone = new Phone(DEFAULT_PHONE); email = new Email(DEFAULT_EMAIL); + gender = new Gender(DEFAULT_GENDER); + icNumber = new IcNumber(DEFAULT_IC_NUMBER); + birthday = new Birthday(DEFAULT_BIRTHDAY); address = new Address(DEFAULT_ADDRESS); tags = new HashSet<>(); + assignedDepartment = new AssignedDepartment(); + record = new RecordBuilder(this).build(); } /** @@ -46,7 +64,12 @@ public PatientBuilder(Patient patientToCopy) { phone = patientToCopy.getPhone(); email = patientToCopy.getEmail(); address = patientToCopy.getAddress(); + gender = patientToCopy.getGender(); + icNumber = patientToCopy.getIcNumber(); + birthday = patientToCopy.getBirthday(); tags = new HashSet<>(patientToCopy.getTags()); + assignedDepartment = patientToCopy.getAssignedDepartment(); + record = patientToCopy.getRecord(); } /** @@ -58,13 +81,46 @@ public PatientBuilder withName(String name) { } /** - * Parses the {@code tags} into a {@code Set} and set it to the {@code Patient} that we are building. + * Sets the {@code Phone} of the {@code Patient} that we are building. */ - public PatientBuilder withTags(String ... tags) { - this.tags = SampleDataUtil.getTagSet(tags); + public PatientBuilder withPhone(String phone) { + this.phone = new Phone(phone); + return this; + } + + /** + * Sets the {@code Email} of the {@code Patient} that we are building. + */ + public PatientBuilder withEmail(String email) { + this.email = new Email(email); + return this; + } + + /** + * Sets the {@code Gender} of the {@code Patient} that we are building. + */ + public PatientBuilder withGender(String gender) { + this.gender = new Gender(gender); + return this; + } + + /** + * Sets the {@code IcNumber} of the {@code Patient} that we are building. + */ + public PatientBuilder withIcNumber(String ic) { + this.icNumber = new IcNumber(ic); + return this; + } + + /** + * Sets the {@code Birthday} of the {@code Patient} that we are building. + */ + public PatientBuilder withBirthday(String birthday) { + this.birthday = new Birthday(birthday); return this; } + /** * Sets the {@code Address} of the {@code Patient} that we are building. */ @@ -73,24 +129,25 @@ public PatientBuilder withAddress(String address) { return this; } + /** - * Sets the {@code Phone} of the {@code Patient} that we are building. + * Parses the {@code tags} into a {@code Set} and set it to the {@code Patient} that we are building. */ - public PatientBuilder withPhone(String phone) { - this.phone = new Phone(phone); + public PatientBuilder withTags(String... tags) { + this.tags = SampleDataUtil.getTagSet(tags); return this; } /** - * Sets the {@code Email} of the {@code Patient} that we are building. + * Sets the {@code AssignedDepartment} of the {@code Patient} that we are building. */ - public PatientBuilder withEmail(String email) { - this.email = new Email(email); + public PatientBuilder withAssignedDepartment(String department) { + this.assignedDepartment = new AssignedDepartment(department); return this; } public Patient build() { - return new Patient(name, phone, email, address, tags); + return new Patient(name, phone, email, gender, icNumber, birthday, address, tags); } } diff --git a/src/test/java/seedu/address/testutil/RecordBuilder.java b/src/test/java/seedu/address/testutil/RecordBuilder.java index 1b1f9253e21..6ad0b33b535 100644 --- a/src/test/java/seedu/address/testutil/RecordBuilder.java +++ b/src/test/java/seedu/address/testutil/RecordBuilder.java @@ -18,9 +18,19 @@ public class RecordBuilder { */ public RecordBuilder() { this.patient = new PatientBuilder().build(); // default patient - this.initialObservations = ""; - this.diagnosis = ""; - this.treatmentPlan = ""; + this.initialObservations = Record.DEFAULT_INITIAL_OBSERVATIONS; + this.diagnosis = Record.DEFAULT_DIAGNOSIS; + this.treatmentPlan = Record.DEFAULT_TREATMENT_PLAN; + } + + /** + * Creates a {@code RecordBuilder} with the specified {@code PatientBuilder} and the default details. + */ + public RecordBuilder(PatientBuilder patient) { + this.patient = patient.build(); + this.initialObservations = Record.DEFAULT_INITIAL_OBSERVATIONS; + this.diagnosis = Record.DEFAULT_DIAGNOSIS; + this.treatmentPlan = Record.DEFAULT_TREATMENT_PLAN; } /** diff --git a/src/test/java/seedu/address/testutil/TypicalPatients.java b/src/test/java/seedu/address/testutil/TypicalPatients.java index cb26142db02..f13bb985c78 100644 --- a/src/test/java/seedu/address/testutil/TypicalPatients.java +++ b/src/test/java/seedu/address/testutil/TypicalPatients.java @@ -23,36 +23,99 @@ */ public class TypicalPatients { - public static final Patient ALICE = new PatientBuilder().withName("Alice Pauline") - .withAddress("123, Jurong West Ave 6, #08-111").withEmail("alice@example.com") + public static final Patient ALICE = new PatientBuilder() + .withName("Alice Pauline") + .withAddress("123, Jurong West Ave 6, #08-111") + .withEmail("alice@example.com") + .withGender("female") + .withBirthday("23/09/2000") + .withIcNumber("T0032415E") .withPhone("94351253") .withTags("friends").build(); - public static final Patient BENSON = new PatientBuilder().withName("Benson Meier") + public static final Patient BENSON = new PatientBuilder() + .withName("Benson Meier") .withAddress("311, Clementi Ave 2, #02-25") - .withEmail("johnd@example.com").withPhone("98765432") + .withEmail("johnd@example.com") + .withGender("male") + .withBirthday("17/03/1987") + .withIcNumber("S2091742P") + .withPhone("98765432") .withTags("owesMoney", "friends").build(); - public static final Patient CARL = new PatientBuilder().withName("Carl Kurz").withPhone("95352563") - .withEmail("heinz@example.com").withAddress("wall street").build(); - public static final Patient DANIEL = new PatientBuilder().withName("Daniel Meier").withPhone("87652533") - .withEmail("cornelia@example.com").withAddress("10th street").withTags("friends").build(); - public static final Patient ELLE = new PatientBuilder().withName("Elle Meyer").withPhone("9482224") - .withEmail("werner@example.com").withAddress("michegan ave").build(); - public static final Patient FIONA = new PatientBuilder().withName("Fiona Kunz").withPhone("9482427") - .withEmail("lydia@example.com").withAddress("little tokyo").build(); - public static final Patient GEORGE = new PatientBuilder().withName("George Best").withPhone("9482442") - .withEmail("anna@example.com").withAddress("4th street").build(); + public static final Patient CARL = new PatientBuilder() + .withName("Carl Kurz") + .withPhone("95352563") + .withGender("male") + .withBirthday("08/06/1997") + .withIcNumber("S2780456R") + .withEmail("heinz@example.com") + .withAddress("wall street").build(); + public static final Patient DANIEL = new PatientBuilder() + .withName("Daniel Meier") + .withPhone("87652533") + .withGender("male") + .withBirthday("29/01/2001") + .withIcNumber("T0163826D") + .withEmail("cornelia@example.com") + .withAddress("10th street") + .withTags("friends").build(); + public static final Patient ELLE = new PatientBuilder() + .withName("Elle Meyer") + .withPhone("9482224") + .withGender("female") + .withBirthday("12/11/1995") + .withIcNumber("S1839267A") + .withEmail("werner@example.com") + .withAddress("michegan ave") + .build(); + public static final Patient FIONA = new PatientBuilder() + .withName("Fiona Kunz") + .withPhone("9482427") + .withEmail("lydia@example.com") + .withGender("female") + .withBirthday("29/06/1982") + .withIcNumber("S3729462N") + .withAddress("little tokyo") + .build(); + public static final Patient GEORGE = new PatientBuilder() + .withName("George Best") + .withPhone("9482442") + .withGender("male") + .withBirthday("03/07/1997") + .withIcNumber("S4839258F") + .withEmail("anna@example.com") + .withAddress("4th street").build(); // Manually added - public static final Patient HOON = new PatientBuilder().withName("Hoon Meier").withPhone("8482424") - .withEmail("stefan@example.com").withAddress("little india").build(); - public static final Patient IDA = new PatientBuilder().withName("Ida Mueller").withPhone("8482131") - .withEmail("hans@example.com").withAddress("chicago ave").build(); + public static final Patient HOON = new PatientBuilder() + .withName("Hoon Meier") + .withPhone("8482424") + .withGender("male") + .withBirthday("07/04/2002") + .withIcNumber("T0247382S") + .withEmail("stefan@example.com") + .withAddress("little india").build(); + public static final Patient IDA = new PatientBuilder() + .withName("Ida Mueller") + .withPhone("8482131") + .withGender("female") + .withBirthday("29/04/1984") + .withIcNumber("S5729346L") + .withEmail("hans@example.com") + .withAddress("chicago ave").build(); // Manually added - Patient's details found in {@code CommandTestUtil} - public static final Patient AMY = new PatientBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY) - .withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build(); - public static final Patient BOB = new PatientBuilder().withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB) - .withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) + public static final Patient AMY = new PatientBuilder() + .withName(VALID_NAME_AMY) + .withPhone(VALID_PHONE_AMY) + .withEmail(VALID_EMAIL_AMY) + .withAddress(VALID_ADDRESS_AMY) + .withTags(VALID_TAG_FRIEND).build(); + public static final Patient BOB = new PatientBuilder() + .withName(VALID_NAME_BOB) + .withPhone(VALID_PHONE_BOB) + .withEmail(VALID_EMAIL_BOB) + .withAddress(VALID_ADDRESS_BOB) + .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) .build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER