From 16a6ec59ba8a85b6b6e7e6cfcbfc5e7a0ece11f0 Mon Sep 17 00:00:00 2001 From: Hovan Tan Fang Hao Date: Fri, 19 Oct 2018 15:28:25 +0800 Subject: [PATCH 01/68] Incomplete attempt at adding MedHistoryDescriptor to Set Main problem found at: AddHistCommand.java (Line 81) --- .../logic/commands/AddHistCommand.java | 139 ++++++++++++++++-- .../logic/parser/AddHistCommandParser.java | 40 +++-- 2 files changed, 142 insertions(+), 37 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddHistCommand.java b/src/main/java/seedu/address/logic/commands/AddHistCommand.java index 68c17a6196bb..ace540abfc0f 100644 --- a/src/main/java/seedu/address/logic/commands/AddHistCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddHistCommand.java @@ -6,17 +6,32 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_HISTORY_DATE; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; +import seedu.address.commons.util.CollectionUtil; import seedu.address.logic.CommandHistory; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.medhistory.Allergy; +import seedu.address.model.medhistory.MedHistDate; import seedu.address.model.medhistory.MedHistory; +import seedu.address.model.medhistory.PrevCountry; +import seedu.address.model.medicalreport.MedicalReport; +import seedu.address.model.person.Address; +import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.Nric; import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; +import seedu.address.model.tag.Tag; +import seedu.address.model.timetable.Appt; /** * Adds/Edits medical history of a patient in the Health Book. @@ -34,17 +49,19 @@ public class AddHistCommand extends Command { + PREFIX_HISTORY_COUNTRY + " Kuwait "; public static final String MESSAGE_ADD_MEDHISTORY_SUCCESS = "Added medical history to Person: %1$s"; + public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; public static final String MESSAGE_DELETE_MEDHISTORY_SUCCESS = "Removed medical history from Person: %1$s"; private final Index index; - private final MedHistory medHistory; + private final MedHistoryDescriptor medHistoryDescriptor; + //private final MedHistory medHistory; /** * @param index of the patient in the filtered patient list to add medical history * @param medHistory of the person to be updated to */ - public AddHistCommand(Index index, MedHistory medHistory) { - requireAllNonNull(index, medHistory); + public AddHistCommand(Index index, MedHistoryDescriptor medHistoryDescriptor) { + requireAllNonNull(index, medHistoryDescriptor); this.index = index; - this.medHistory = medHistory; + this.medHistoryDescriptor = new MedHistoryDescriptor(medHistoryDescriptor); } @Override @@ -61,22 +78,34 @@ public CommandResult execute(Model model, CommandHistory history) throws Command newMedHistories.add(medHistory); } // adds the new history from command - newMedHistories.add(medHistory); - Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), - personToEdit.getAddress(), personToEdit.getMedicalReports(), newMedHistories, personToEdit.getAppts(), - personToEdit.getNric(), personToEdit.getDateOfBirth(), personToEdit.getTags()); - model.updatePerson(personToEdit, editedPerson); + newMedHistories.add(medHistoryDescriptor); + Person editedPerson = createEditedPerson(personToEdit, medHistoryDescriptor); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); model.commitAddressBook(); - return new CommandResult(generateSuccessMessage(editedPerson)); + return new CommandResult(String.format(MESSAGE_ADD_MEDHISTORY_SUCCESS, editedPerson)); } /** - * Generates a command execution success message based on whether the medical history is added to or removed from - * {@code personToEdit}. + * Creates and returns a {@code Person} with the details of {@code personToEdit} + * edited with {@code editPersonDescriptor}. */ - private String generateSuccessMessage(Person personToEdit) { - return String.format(MESSAGE_ADD_MEDHISTORY_SUCCESS, personToEdit); + private static Person createEditedPerson(Person personToEdit, MedHistoryDescriptor medHistoryDescriptor) { + assert personToEdit != null; + + Name name = personToEdit.getName(); + Phone phone = personToEdit.getPhone(); + Email email = personToEdit.getEmail(); + Address address = personToEdit.getAddress(); + Set appts = personToEdit.getAppts(); + Set medicalReports = personToEdit.getMedicalReports(); + Set medHistory = personToEdit.getMedHistory(); + Set tags = personToEdit.getTags(); + + Nric nric = personToEdit.getNric(); + DateOfBirth dateOfBirth = personToEdit.getDateOfBirth(); + + return new Person(name, phone, email, address, medicalReports, medHistory, appts, + nric, dateOfBirth, tags); } @Override @@ -92,6 +121,86 @@ public boolean equals(Object other) { // state check AddHistCommand e = (AddHistCommand) other; return index.equals(e.index) - && medHistory.equals(e.medHistory); + && medHistoryDescriptor.equals(e.medHistoryDescriptor); + } + + /** + * Stores the details to edit the person with. Each non-empty field value will replace the + * corresponding field value of the person. + */ + public static class MedHistoryDescriptor { + private MedHistDate medHistDate; + private Allergy allergy; + private PrevCountry prevCountry; + + public MedHistoryDescriptor() {} + + /*public MedHistoryDescriptor(MedHistDate medHistDate, Allergy allergy, PrevCountry prevCountry) { + requireAllNonNull(medHistDate, allergy, prevCountry); + this.medHistDate = medHistDate; + this.allergy = allergy; + this.prevCountry = prevCountry; + }*/ + + /** + * Copy constructor. + * A defensive copy of {@code tags} is used internally. + */ + public MedHistoryDescriptor(MedHistoryDescriptor toCopy) { + setMedHistDate(toCopy.medHistDate); + setAllergy(toCopy.allergy); + setPrevCountry(toCopy.prevCountry); + } + + /** + * Returns true if at least one field is edited. + */ + public boolean isAnyFieldEdited() { + return CollectionUtil.isAnyNonNull(medHistDate, allergy, prevCountry); + } + + public void setMedHistDate(MedHistDate medHistDate) { + this.medHistDate = medHistDate; + } + + public Optional getMedHistDate() { + return Optional.ofNullable(medHistDate); + } + + public void setAllergy(Allergy allergy) { + this.allergy = allergy; + } + + public Optional getAllergy() { + return Optional.ofNullable(allergy); + } + + public void setPrevCountry(PrevCountry prevCountry) { + this.prevCountry = prevCountry; + } + + public Optional getPrevCountry() { + return Optional.ofNullable(prevCountry); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof MedHistoryDescriptor)) { + return false; + } + + // state check + MedHistoryDescriptor e = (MedHistoryDescriptor) other; + + return getMedHistDate().equals(e.getMedHistDate()) + && getAllergy().equals(e.getAllergy()) + && getPrevCountry().equals(e.getPrevCountry()); + } } } diff --git a/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java b/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java index 5c80a6f8f9c6..7c9ebed25d2b 100644 --- a/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java @@ -6,16 +6,11 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_HISTORY_COUNTRY; import static seedu.address.logic.parser.CliSyntax.PREFIX_HISTORY_DATE; -import java.util.stream.Stream; - import seedu.address.commons.core.index.Index; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.logic.commands.AddHistCommand; +import seedu.address.logic.commands.AddHistCommand.MedHistoryDescriptor; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.medhistory.Allergy; -import seedu.address.model.medhistory.MedHistDate; -import seedu.address.model.medhistory.MedHistory; -import seedu.address.model.medhistory.PrevCountry; /** @@ -34,11 +29,6 @@ public AddHistCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_HISTORY_DATE, PREFIX_HISTORY_ALLERGY, PREFIX_HISTORY_COUNTRY); - if (!arePrefixesPresent(argMultimap, PREFIX_HISTORY_DATE, PREFIX_HISTORY_ALLERGY, - PREFIX_HISTORY_COUNTRY)) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddHistCommand.MESSAGE_USAGE)); - } - Index index; try { @@ -47,17 +37,23 @@ public AddHistCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddHistCommand.MESSAGE_USAGE), ive); } - Allergy allergy = ParserUtil.parseAllergy(argMultimap.getValue(PREFIX_HISTORY_ALLERGY).get()); - PrevCountry prevCountry = ParserUtil.parsePrevCountry(argMultimap.getValue(PREFIX_HISTORY_COUNTRY).get()); - MedHistDate medHistDate = ParserUtil.parseMedHistDate(argMultimap.getValue(PREFIX_HISTORY_DATE).get()); - return new AddHistCommand(index, new MedHistory (medHistDate, allergy, prevCountry)); - } + MedHistoryDescriptor medHistoryDescriptor = new MedHistoryDescriptor(); + if (argMultimap.getValue(PREFIX_HISTORY_DATE).isPresent()) { + medHistoryDescriptor.setMedHistDate(ParserUtil + .parseMedHistDate(argMultimap.getValue(PREFIX_HISTORY_DATE).get())); + } + if (argMultimap.getValue(PREFIX_HISTORY_ALLERGY).isPresent()) { + medHistoryDescriptor.setAllergy(ParserUtil + .parseAllergy(argMultimap.getValue(PREFIX_HISTORY_ALLERGY).get())); + } + if (argMultimap.getValue(PREFIX_HISTORY_COUNTRY).isPresent()) { + medHistoryDescriptor.setPrevCountry(ParserUtil + .parsePrevCountry(argMultimap.getValue(PREFIX_HISTORY_COUNTRY).get())); + } + if (!medHistoryDescriptor.isAnyFieldEdited()) { + throw new ParseException(AddHistCommand.MESSAGE_NOT_EDITED); + } - /** - * Returns true if none of the prefixes contains empty {@code Optional} values in the given - * {@code ArgumentMultimap}. - */ - private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { - return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + return new AddHistCommand(index, medHistoryDescriptor); } } From e8832b6b062bcc5e9f2784d9f455c57c12a72949 Mon Sep 17 00:00:00 2001 From: Hovan Tan Fang Hao Date: Fri, 19 Oct 2018 16:53:03 +0800 Subject: [PATCH 02/68] Moved MedHistoryDescriptor to MedHistory.java Application is able to run but MedHistory is not properly shown on PersonCard --- .../logic/commands/AddHistCommand.java | 100 ++---------------- .../logic/parser/AddHistCommandParser.java | 14 +-- .../address/model/medhistory/MedHistory.java | 78 +++++++++----- 3 files changed, 70 insertions(+), 122 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddHistCommand.java b/src/main/java/seedu/address/logic/commands/AddHistCommand.java index ace540abfc0f..c3f4fdbef1a3 100644 --- a/src/main/java/seedu/address/logic/commands/AddHistCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddHistCommand.java @@ -52,16 +52,16 @@ public class AddHistCommand extends Command { public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; public static final String MESSAGE_DELETE_MEDHISTORY_SUCCESS = "Removed medical history from Person: %1$s"; private final Index index; - private final MedHistoryDescriptor medHistoryDescriptor; + private final MedHistory medHistory; //private final MedHistory medHistory; /** * @param index of the patient in the filtered patient list to add medical history * @param medHistory of the person to be updated to */ - public AddHistCommand(Index index, MedHistoryDescriptor medHistoryDescriptor) { - requireAllNonNull(index, medHistoryDescriptor); + public AddHistCommand(Index index, MedHistory medHistory) { + requireAllNonNull(index, medHistory); this.index = index; - this.medHistoryDescriptor = new MedHistoryDescriptor(medHistoryDescriptor); + this.medHistory = new MedHistory(medHistory); } @Override @@ -78,8 +78,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command newMedHistories.add(medHistory); } // adds the new history from command - newMedHistories.add(medHistoryDescriptor); - Person editedPerson = createEditedPerson(personToEdit, medHistoryDescriptor); + newMedHistories.add(medHistory); + Person editedPerson = createEditedPerson(personToEdit, medHistory); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); model.commitAddressBook(); return new CommandResult(String.format(MESSAGE_ADD_MEDHISTORY_SUCCESS, editedPerson)); @@ -89,7 +89,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command * Creates and returns a {@code Person} with the details of {@code personToEdit} * edited with {@code editPersonDescriptor}. */ - private static Person createEditedPerson(Person personToEdit, MedHistoryDescriptor medHistoryDescriptor) { + private static Person createEditedPerson(Person personToEdit, MedHistory medHistory) { assert personToEdit != null; Name name = personToEdit.getName(); @@ -98,13 +98,13 @@ private static Person createEditedPerson(Person personToEdit, MedHistoryDescript Address address = personToEdit.getAddress(); Set appts = personToEdit.getAppts(); Set medicalReports = personToEdit.getMedicalReports(); - Set medHistory = personToEdit.getMedHistory(); + Set medHistories = personToEdit.getMedHistory(); Set tags = personToEdit.getTags(); Nric nric = personToEdit.getNric(); DateOfBirth dateOfBirth = personToEdit.getDateOfBirth(); - return new Person(name, phone, email, address, medicalReports, medHistory, appts, + return new Person(name, phone, email, address, medicalReports, medHistories, appts, nric, dateOfBirth, tags); } @@ -121,86 +121,6 @@ public boolean equals(Object other) { // state check AddHistCommand e = (AddHistCommand) other; return index.equals(e.index) - && medHistoryDescriptor.equals(e.medHistoryDescriptor); - } - - /** - * Stores the details to edit the person with. Each non-empty field value will replace the - * corresponding field value of the person. - */ - public static class MedHistoryDescriptor { - private MedHistDate medHistDate; - private Allergy allergy; - private PrevCountry prevCountry; - - public MedHistoryDescriptor() {} - - /*public MedHistoryDescriptor(MedHistDate medHistDate, Allergy allergy, PrevCountry prevCountry) { - requireAllNonNull(medHistDate, allergy, prevCountry); - this.medHistDate = medHistDate; - this.allergy = allergy; - this.prevCountry = prevCountry; - }*/ - - /** - * Copy constructor. - * A defensive copy of {@code tags} is used internally. - */ - public MedHistoryDescriptor(MedHistoryDescriptor toCopy) { - setMedHistDate(toCopy.medHistDate); - setAllergy(toCopy.allergy); - setPrevCountry(toCopy.prevCountry); - } - - /** - * Returns true if at least one field is edited. - */ - public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(medHistDate, allergy, prevCountry); - } - - public void setMedHistDate(MedHistDate medHistDate) { - this.medHistDate = medHistDate; - } - - public Optional getMedHistDate() { - return Optional.ofNullable(medHistDate); - } - - public void setAllergy(Allergy allergy) { - this.allergy = allergy; - } - - public Optional getAllergy() { - return Optional.ofNullable(allergy); - } - - public void setPrevCountry(PrevCountry prevCountry) { - this.prevCountry = prevCountry; - } - - public Optional getPrevCountry() { - return Optional.ofNullable(prevCountry); - } - - @Override - public boolean equals(Object other) { - // short circuit if same object - if (other == this) { - return true; - } - - // instanceof handles nulls - if (!(other instanceof MedHistoryDescriptor)) { - return false; - } - - // state check - MedHistoryDescriptor e = (MedHistoryDescriptor) other; - - return getMedHistDate().equals(e.getMedHistDate()) - && getAllergy().equals(e.getAllergy()) - && getPrevCountry().equals(e.getPrevCountry()); - } + && medHistory.equals(e.medHistory); } } diff --git a/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java b/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java index 7c9ebed25d2b..874e00e09357 100644 --- a/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddHistCommandParser.java @@ -9,7 +9,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.logic.commands.AddHistCommand; -import seedu.address.logic.commands.AddHistCommand.MedHistoryDescriptor; +import seedu.address.model.medhistory.MedHistory; import seedu.address.logic.parser.exceptions.ParseException; @@ -37,23 +37,23 @@ public AddHistCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddHistCommand.MESSAGE_USAGE), ive); } - MedHistoryDescriptor medHistoryDescriptor = new MedHistoryDescriptor(); + MedHistory medHistory = new MedHistory(); if (argMultimap.getValue(PREFIX_HISTORY_DATE).isPresent()) { - medHistoryDescriptor.setMedHistDate(ParserUtil + medHistory.setMedHistDate(ParserUtil .parseMedHistDate(argMultimap.getValue(PREFIX_HISTORY_DATE).get())); } if (argMultimap.getValue(PREFIX_HISTORY_ALLERGY).isPresent()) { - medHistoryDescriptor.setAllergy(ParserUtil + medHistory.setAllergy(ParserUtil .parseAllergy(argMultimap.getValue(PREFIX_HISTORY_ALLERGY).get())); } if (argMultimap.getValue(PREFIX_HISTORY_COUNTRY).isPresent()) { - medHistoryDescriptor.setPrevCountry(ParserUtil + medHistory.setPrevCountry(ParserUtil .parsePrevCountry(argMultimap.getValue(PREFIX_HISTORY_COUNTRY).get())); } - if (!medHistoryDescriptor.isAnyFieldEdited()) { + if (!medHistory.isAnyFieldEdited()) { throw new ParseException(AddHistCommand.MESSAGE_NOT_EDITED); } - return new AddHistCommand(index, medHistoryDescriptor); + return new AddHistCommand(index, medHistory); } } diff --git a/src/main/java/seedu/address/model/medhistory/MedHistory.java b/src/main/java/seedu/address/model/medhistory/MedHistory.java index 9ee4ac8fda10..09b1a5016ba5 100644 --- a/src/main/java/seedu/address/model/medhistory/MedHistory.java +++ b/src/main/java/seedu/address/model/medhistory/MedHistory.java @@ -3,18 +3,22 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.util.Objects; +import java.util.Optional; + +import seedu.address.commons.util.CollectionUtil; /** * Model of medical history of a patient. * Guarantees: details are present and not null, field values are validated, immutable. */ + public class MedHistory { + private MedHistDate medHistDate; + private Allergy allergy; + private PrevCountry prevCountry; - // Data fields - private final MedHistDate medHistDate; - private final Allergy allergy; - private final PrevCountry prevCountry; + public MedHistory() {} public MedHistory(MedHistDate medHistDate, Allergy allergy, PrevCountry prevCountry) { requireAllNonNull(medHistDate, allergy, prevCountry); @@ -23,40 +27,64 @@ public MedHistory(MedHistDate medHistDate, Allergy allergy, PrevCountry prevCoun this.prevCountry = prevCountry; } - public MedHistDate getMedHistDate() { - return medHistDate; + /** + * Copy constructor. + * A defensive copy of {@code tags} is used internally. + */ + public MedHistory(MedHistory toCopy) { + setMedHistDate(toCopy.medHistDate); + setAllergy(toCopy.allergy); + setPrevCountry(toCopy.prevCountry); + } + + /** + * Returns true if at least one field is edited. + */ + public boolean isAnyFieldEdited() { + return CollectionUtil.isAnyNonNull(medHistDate, allergy, prevCountry); + } + + public void setMedHistDate(MedHistDate medHistDate) { + this.medHistDate = medHistDate; + } + + public Optional getMedHistDate() { + return Optional.ofNullable(medHistDate); + } + + public void setAllergy(Allergy allergy) { + this.allergy = allergy; + } + + public Optional getAllergy() { + return Optional.ofNullable(allergy); } - public Allergy getAllergy() { - return allergy; + + public void setPrevCountry(PrevCountry prevCountry) { + this.prevCountry = prevCountry; } - public PrevCountry getPrevCountry() { - return prevCountry; + + public Optional getPrevCountry() { + return Optional.ofNullable(prevCountry); } @Override public boolean equals(Object other) { + // short circuit if same object if (other == this) { return true; } + // instanceof handles nulls if (!(other instanceof MedHistory)) { return false; } - MedHistory otherPerson = (MedHistory) other; - return otherPerson.getMedHistDate().equals(getMedHistDate()) - && otherPerson.getAllergy().equals(getAllergy()) - && otherPerson.getPrevCountry().equals(getPrevCountry()); - } + // state check + MedHistory e = (MedHistory) other; - @Override - public int hashCode() { - // use this method for custom fields hashing instead of implementing your own - return Objects.hash(medHistDate, allergy, prevCountry); - } - - @Override - public String toString() { - return medHistDate.toString() + " \n" + allergy.toString() + " \n" + prevCountry.toString(); + return getMedHistDate().equals(e.getMedHistDate()) + && getAllergy().equals(e.getAllergy()) + && getPrevCountry().equals(e.getPrevCountry()); } -} +} \ No newline at end of file From 12ccad4ebdb002cec0a2eb19b19b641d1498d3af Mon Sep 17 00:00:00 2001 From: Hovan Tan Fang Hao Date: Fri, 19 Oct 2018 16:56:30 +0800 Subject: [PATCH 03/68] Added hashCode and toString methods in MedHistory.java --- .../seedu/address/model/medhistory/MedHistory.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/seedu/address/model/medhistory/MedHistory.java b/src/main/java/seedu/address/model/medhistory/MedHistory.java index 09b1a5016ba5..314f5b156161 100644 --- a/src/main/java/seedu/address/model/medhistory/MedHistory.java +++ b/src/main/java/seedu/address/model/medhistory/MedHistory.java @@ -87,4 +87,15 @@ public boolean equals(Object other) { && getAllergy().equals(e.getAllergy()) && getPrevCountry().equals(e.getPrevCountry()); } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(medHistDate, allergy, prevCountry); + } + + @Override + public String toString() { + return medHistDate.toString() + " \n" + allergy.toString() + " \n" + prevCountry.toString(); + } } \ No newline at end of file From 8f5f740eaedab281ed156b6164be53c57d2a67cc Mon Sep 17 00:00:00 2001 From: xhxh96 Date: Sat, 20 Oct 2018 12:56:38 +0800 Subject: [PATCH 04/68] Added Gender, Height, Weight and Refactor BloodType, DateOfBirth and Nric --- .../logic/commands/AddInfoCommand.java | 4 +- .../address/logic/commands/EditCommand.java | 4 +- .../logic/parser/AddCommandParser.java | 4 +- .../logic/parser/AddressBookParser.java | 2 +- .../address/logic/parser/ParserUtil.java | 4 +- .../seedu/address/model/person/Person.java | 5 +++ .../model/person/{ => addinfo}/BloodType.java | 2 +- .../person/{ => addinfo}/DateOfBirth.java | 3 +- .../address/model/person/addinfo/Gender.java | 36 +++++++++++++++ .../address/model/person/addinfo/Height.java | 45 +++++++++++++++++++ .../model/person/{ => addinfo}/Nric.java | 3 +- .../address/model/person/addinfo/Weight.java | 45 +++++++++++++++++++ .../address/model/util/SampleDataUtil.java | 4 +- .../address/storage/XmlAdaptedPerson.java | 4 +- .../address/logic/parser/ParserUtilTest.java | 2 +- .../address/model/person/DateOfBirthTest.java | 1 + .../seedu/address/model/person/NricTest.java | 2 + .../AddInfoPersonDescriptorBuilder.java | 4 +- .../seedu/address/testutil/PersonBuilder.java | 4 +- 19 files changed, 156 insertions(+), 22 deletions(-) rename src/main/java/seedu/address/model/person/{ => addinfo}/BloodType.java (96%) rename src/main/java/seedu/address/model/person/{ => addinfo}/DateOfBirth.java (92%) create mode 100644 src/main/java/seedu/address/model/person/addinfo/Gender.java create mode 100644 src/main/java/seedu/address/model/person/addinfo/Height.java rename src/main/java/seedu/address/model/person/{ => addinfo}/Nric.java (96%) create mode 100644 src/main/java/seedu/address/model/person/addinfo/Weight.java diff --git a/src/main/java/seedu/address/logic/commands/AddInfoCommand.java b/src/main/java/seedu/address/logic/commands/AddInfoCommand.java index 6ac973713ba6..ab4b8527a360 100644 --- a/src/main/java/seedu/address/logic/commands/AddInfoCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddInfoCommand.java @@ -16,10 +16,10 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; import seedu.address.model.person.Address; -import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 3d00a3b942c9..3f18edff323a 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -23,10 +23,10 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; import seedu.address.model.person.Address; -import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index a22738f6c46d..816ce6756bde 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -16,10 +16,10 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; import seedu.address.model.person.Address; -import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 0199978df851..c9964f56220d 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -51,8 +51,8 @@ public Command parseCommand(String userInput) throws ParseException { final String commandWord = matcher.group("commandWord"); final String arguments = matcher.group("arguments"); - switch (commandWord) { + switch (commandWord) { case AddCommand.COMMAND_WORD: return new AddCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 214e6674e06d..46fcf70e4dd4 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -18,10 +18,10 @@ import seedu.address.model.medicalreport.ReportDate; import seedu.address.model.medicalreport.Title; import seedu.address.model.person.Address; -import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.ApptDateTime; diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 1eb0af0be5fc..fe1225926232 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -9,6 +9,8 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; +import seedu.address.model.person.addinfo.DateOfBirth; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.Appt; @@ -33,6 +35,9 @@ public class Person { // Additional information fields private final Nric nric; private final DateOfBirth dateOfBirth; + //private final Height height; + //private final Weight weight; + //private final Gender gender; /** * Every field must be present and not null. diff --git a/src/main/java/seedu/address/model/person/BloodType.java b/src/main/java/seedu/address/model/person/addinfo/BloodType.java similarity index 96% rename from src/main/java/seedu/address/model/person/BloodType.java rename to src/main/java/seedu/address/model/person/addinfo/BloodType.java index 096ad2115586..70dea0712197 100644 --- a/src/main/java/seedu/address/model/person/BloodType.java +++ b/src/main/java/seedu/address/model/person/addinfo/BloodType.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.person.addinfo; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; diff --git a/src/main/java/seedu/address/model/person/DateOfBirth.java b/src/main/java/seedu/address/model/person/addinfo/DateOfBirth.java similarity index 92% rename from src/main/java/seedu/address/model/person/DateOfBirth.java rename to src/main/java/seedu/address/model/person/addinfo/DateOfBirth.java index 9807680fd783..c3d0875bb32e 100644 --- a/src/main/java/seedu/address/model/person/DateOfBirth.java +++ b/src/main/java/seedu/address/model/person/addinfo/DateOfBirth.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.person.addinfo; import static java.util.Objects.requireNonNull; @@ -23,6 +23,7 @@ public class DateOfBirth { * @param value a valid date * @throws ParseException if date format is invalid */ + //TODO: (DateOfBirth) to be an Optional type to support null values public DateOfBirth(String value) { requireNonNull(value); this.value = LocalDate.parse(value, dateTimeFormatter); diff --git a/src/main/java/seedu/address/model/person/addinfo/Gender.java b/src/main/java/seedu/address/model/person/addinfo/Gender.java new file mode 100644 index 000000000000..55c033f7a943 --- /dev/null +++ b/src/main/java/seedu/address/model/person/addinfo/Gender.java @@ -0,0 +1,36 @@ +package seedu.address.model.person.addinfo; + +import static java.util.Objects.requireNonNull; + +public class Gender { + public static final String GENDER_VALIDATION_REGEX = "[MF]"; + public static final String MESSAGE_GENDER_CONSTRAINTS = "Gender input can only be either M or F."; + + public final String value; + + public Gender(String gender) { + requireNonNull(gender); + gender.toUpperCase(); + value = gender; + } + + public static boolean isValidGender(String test) { + return test.matches(GENDER_VALIDATION_REGEX); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this + || (other instanceof Gender && value.equals(((Gender) other).value)); + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/person/addinfo/Height.java b/src/main/java/seedu/address/model/person/addinfo/Height.java new file mode 100644 index 000000000000..3ae153afda68 --- /dev/null +++ b/src/main/java/seedu/address/model/person/addinfo/Height.java @@ -0,0 +1,45 @@ +package seedu.address.model.person.addinfo; + +import static java.util.Objects.requireNonNull; + +public class Height { + public static final String HEIGHT_VALIDATION_REGEX = "[\\d]"; + public static final String MESSAGE_HEIGHT_CONSTRAINTS = "Height should be numeric input only."; + + public final String value; + + /** + * Constructs an {@code Height}. + * + * @param height A valid height. + */ + public Height(String height) { + requireNonNull(height); + value = height; + } + + /** + * + * Returns if a given string is a valid Height + */ + public static boolean isValidHeight(String test) { + return test.matches(HEIGHT_VALIDATION_REGEX); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this + || (other instanceof Height + && value.equals(((Height) other).value)); + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/person/Nric.java b/src/main/java/seedu/address/model/person/addinfo/Nric.java similarity index 96% rename from src/main/java/seedu/address/model/person/Nric.java rename to src/main/java/seedu/address/model/person/addinfo/Nric.java index 763832dfb543..57ad59d171f5 100644 --- a/src/main/java/seedu/address/model/person/Nric.java +++ b/src/main/java/seedu/address/model/person/addinfo/Nric.java @@ -1,4 +1,4 @@ -package seedu.address.model.person; +package seedu.address.model.person.addinfo; import static java.util.Objects.requireNonNull; @@ -47,5 +47,4 @@ public boolean equals(Object other) { public int hashCode() { return value.hashCode(); } - } diff --git a/src/main/java/seedu/address/model/person/addinfo/Weight.java b/src/main/java/seedu/address/model/person/addinfo/Weight.java new file mode 100644 index 000000000000..eca6eb64d7c6 --- /dev/null +++ b/src/main/java/seedu/address/model/person/addinfo/Weight.java @@ -0,0 +1,45 @@ +package seedu.address.model.person.addinfo; + +import static java.util.Objects.requireNonNull; + +public class Weight { + public static final String WEIGHT_VALIDATION_REGEX = "[\\d]"; + public static final String MESSAGE_WEIGHT_CONSTRAINTS = "Weight should be numeric input only."; + + public final String value; + + /** + * Constructs an {@code Height}. + * + * @param weight A valid weight. + */ + public Weight(String weight) { + requireNonNull(weight); + value = weight; + } + + /** + * + * Returns if a given string is a valid Height + */ + public static boolean isValidWeight(String test) { + return test.matches(WEIGHT_VALIDATION_REGEX); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this + || (other instanceof Weight + && value.equals(((Weight) other).value)); + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index a511370663ba..f6e96b964280 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -10,10 +10,10 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; import seedu.address.model.person.Address; -import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java index 975712f80c3f..b398dd65aa0a 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java @@ -13,10 +13,10 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; import seedu.address.model.person.Address; -import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index a2ccc4cfe885..371e98214907 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -18,7 +18,7 @@ import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; import seedu.address.testutil.Assert; diff --git a/src/test/java/seedu/address/model/person/DateOfBirthTest.java b/src/test/java/seedu/address/model/person/DateOfBirthTest.java index bd4ed6d0bf92..7da4bf89936c 100644 --- a/src/test/java/seedu/address/model/person/DateOfBirthTest.java +++ b/src/test/java/seedu/address/model/person/DateOfBirthTest.java @@ -7,6 +7,7 @@ import org.junit.Test; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.testutil.Assert; public class DateOfBirthTest { diff --git a/src/test/java/seedu/address/model/person/NricTest.java b/src/test/java/seedu/address/model/person/NricTest.java index 63eb23193e47..e2d90d45b858 100644 --- a/src/test/java/seedu/address/model/person/NricTest.java +++ b/src/test/java/seedu/address/model/person/NricTest.java @@ -5,6 +5,8 @@ import org.junit.Test; +import seedu.address.model.person.addinfo.Nric; + public class NricTest { @Test diff --git a/src/test/java/seedu/address/testutil/AddInfoPersonDescriptorBuilder.java b/src/test/java/seedu/address/testutil/AddInfoPersonDescriptorBuilder.java index 60767eabab82..0a02656e4019 100644 --- a/src/test/java/seedu/address/testutil/AddInfoPersonDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/AddInfoPersonDescriptorBuilder.java @@ -1,8 +1,8 @@ package seedu.address.testutil; import seedu.address.logic.commands.AddInfoCommand.AddInfoPersonDescriptor; -import seedu.address.model.person.DateOfBirth; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.DateOfBirth; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; /** diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index efa282f82972..a06da3bc0f95 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -6,10 +6,10 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; import seedu.address.model.person.Address; -import seedu.address.model.person.DateOfBirth; +import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; -import seedu.address.model.person.Nric; +import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; From 8b54a8c0157b33f5d13f82caba193240af483747 Mon Sep 17 00:00:00 2001 From: brandonccm1996 Date: Sun, 21 Oct 2018 21:03:56 +0800 Subject: [PATCH 05/68] Added DateTimeUtil for parsing and formatting of LocalDateTime --- .../address/model/util/DateTimeUtil.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/java/seedu/address/model/util/DateTimeUtil.java diff --git a/src/main/java/seedu/address/model/util/DateTimeUtil.java b/src/main/java/seedu/address/model/util/DateTimeUtil.java new file mode 100644 index 000000000000..ddaf93a5ff6d --- /dev/null +++ b/src/main/java/seedu/address/model/util/DateTimeUtil.java @@ -0,0 +1,38 @@ +package seedu.address.model.util; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class DateTimeUtil { + private static final String DATE_PATTERN = "dd-MM-yyyy"; + private static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(DATE_PATTERN); + private static final String DATETIME_PATTERN = "dd-MM-yyyy HH:mm"; + private static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern(DATETIME_PATTERN); + + // convert LocalDate to String + public static String format(LocalDate date) { + if (date == null) { + return null; + } + return DATE_FORMATTER.format(date); + } + + // convert String to LocalDate + public static LocalDate parseDate(String dateString) { + return LocalDate.parse(dateString, DATE_FORMATTER); + } + + // convert LocalDateTime to String + public static String format(LocalDateTime dateTime) { + if (dateTime == null) { + return null; + } + return DATETIME_FORMATTER.format(dateTime); + } + + // convert String to LocalDateTime + public static LocalDateTime parseDateTime(String dateTimeString) { + return LocalDateTime.parse(dateTimeString, DATETIME_FORMATTER); + } +} From 5af75c995594035d56445503f1dfa8f45bb0a1de Mon Sep 17 00:00:00 2001 From: brandonccm1996 Date: Sun, 21 Oct 2018 21:12:28 +0800 Subject: [PATCH 06/68] Rectified checkstyle errors --- .../java/seedu/address/model/util/DateTimeUtil.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/model/util/DateTimeUtil.java b/src/main/java/seedu/address/model/util/DateTimeUtil.java index ddaf93a5ff6d..ffb32e362722 100644 --- a/src/main/java/seedu/address/model/util/DateTimeUtil.java +++ b/src/main/java/seedu/address/model/util/DateTimeUtil.java @@ -4,6 +4,9 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +/** + * Helper functions for LocalDate and LocalDateTime conversion to and from String + */ public class DateTimeUtil { private static final String DATE_PATTERN = "dd-MM-yyyy"; private static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(DATE_PATTERN); @@ -18,11 +21,6 @@ public static String format(LocalDate date) { return DATE_FORMATTER.format(date); } - // convert String to LocalDate - public static LocalDate parseDate(String dateString) { - return LocalDate.parse(dateString, DATE_FORMATTER); - } - // convert LocalDateTime to String public static String format(LocalDateTime dateTime) { if (dateTime == null) { @@ -31,6 +29,11 @@ public static String format(LocalDateTime dateTime) { return DATETIME_FORMATTER.format(dateTime); } + // convert String to LocalDate + public static LocalDate parseDate(String dateString) { + return LocalDate.parse(dateString, DATE_FORMATTER); + } + // convert String to LocalDateTime public static LocalDateTime parseDateTime(String dateTimeString) { return LocalDateTime.parse(dateTimeString, DATETIME_FORMATTER); From 0e1dce1857dff857d833ee6a9f24c7025f135aca Mon Sep 17 00:00:00 2001 From: brandonccm1996 Date: Sun, 21 Oct 2018 21:18:06 +0800 Subject: [PATCH 07/68] Rectified checkstyle errors --- .../seedu/address/model/util/DateTimeUtil.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/model/util/DateTimeUtil.java b/src/main/java/seedu/address/model/util/DateTimeUtil.java index ffb32e362722..d02a98fa9491 100644 --- a/src/main/java/seedu/address/model/util/DateTimeUtil.java +++ b/src/main/java/seedu/address/model/util/DateTimeUtil.java @@ -13,7 +13,9 @@ public class DateTimeUtil { private static final String DATETIME_PATTERN = "dd-MM-yyyy HH:mm"; private static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern(DATETIME_PATTERN); - // convert LocalDate to String + /** + * convert LocalDate to String + */ public static String format(LocalDate date) { if (date == null) { return null; @@ -21,7 +23,9 @@ public static String format(LocalDate date) { return DATE_FORMATTER.format(date); } - // convert LocalDateTime to String + /** + * convert LocalDateTime to String + */ public static String format(LocalDateTime dateTime) { if (dateTime == null) { return null; @@ -29,12 +33,16 @@ public static String format(LocalDateTime dateTime) { return DATETIME_FORMATTER.format(dateTime); } - // convert String to LocalDate + /** + * convert String to LocalDate + */ public static LocalDate parseDate(String dateString) { return LocalDate.parse(dateString, DATE_FORMATTER); } - // convert String to LocalDateTime + /** + * convert String to LocalDateTime + */ public static LocalDateTime parseDateTime(String dateTimeString) { return LocalDateTime.parse(dateTimeString, DATETIME_FORMATTER); } From 8723082ffad212bb2923b0db5a5657e0596f8f3c Mon Sep 17 00:00:00 2001 From: brandonccm1996 Date: Sun, 21 Oct 2018 22:03:47 +0800 Subject: [PATCH 08/68] Changed ApptDateTime value from String to LocalDateTime - Modified all relevant tests as well (all tests now pass) --- .../seedu/address/logic/commands/AddApptCommand.java | 4 ++-- .../seedu/address/model/timetable/ApptDateTime.java | 9 ++++++--- src/test/data/XmlUtilTest/invalidPersonField.xml | 4 ++-- src/test/data/XmlUtilTest/missingPersonField.xml | 4 ++-- src/test/data/XmlUtilTest/validPerson.xml | 4 ++-- .../address/logic/commands/CommandTestUtil.java | 12 ++++++------ src/test/java/seedu/address/testutil/ApptUtil.java | 4 ++-- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddApptCommand.java b/src/main/java/seedu/address/logic/commands/AddApptCommand.java index 1ae76cf7f46d..63db10d67515 100644 --- a/src/main/java/seedu/address/logic/commands/AddApptCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddApptCommand.java @@ -36,8 +36,8 @@ public class AddApptCommand extends Command { + PREFIX_APPT_INFO + "[INFO] " + PREFIX_APPT_DRNAME + "[DOCTOR'S NAME]\n" + "Example: " + COMMAND_WORD + " 1 " - + PREFIX_APPT_START + "16/09/2018 1500 " - + PREFIX_APPT_END + "16/09/2018 1530 " + + PREFIX_APPT_START + "16-09-2018 15:00 " + + PREFIX_APPT_END + "16-09-2018 15:30 " + PREFIX_APPT_VENUE + "Consultation Room 12 " + PREFIX_APPT_INFO + "Diabetes Checkup " + PREFIX_APPT_DRNAME + "Dr Tan"; diff --git a/src/main/java/seedu/address/model/timetable/ApptDateTime.java b/src/main/java/seedu/address/model/timetable/ApptDateTime.java index ce012de584db..82827fb7fbdc 100644 --- a/src/main/java/seedu/address/model/timetable/ApptDateTime.java +++ b/src/main/java/seedu/address/model/timetable/ApptDateTime.java @@ -2,6 +2,9 @@ import static java.util.Objects.requireNonNull; +import java.time.LocalDateTime; +import seedu.address.model.util.DateTimeUtil; + /** * Represents an appt date and time in an appt in the address book. * Guarantees: immutable; is always valid @@ -10,16 +13,16 @@ public class ApptDateTime { public static final String MESSAGE_NAME_CONSTRAINTS = "The full ReportDate and Time should be of the format: " + "DD/MM/YYYY HH:MM."; - public final String value; + public final LocalDateTime value; public ApptDateTime(String apptDateTime) { requireNonNull(apptDateTime); - value = apptDateTime; + value = DateTimeUtil.parseDateTime(apptDateTime); } @Override public String toString() { - return value; + return DateTimeUtil.format(value); } @Override diff --git a/src/test/data/XmlUtilTest/invalidPersonField.xml b/src/test/data/XmlUtilTest/invalidPersonField.xml index 4753e29297cb..e1bdc9e92e99 100644 --- a/src/test/data/XmlUtilTest/invalidPersonField.xml +++ b/src/test/data/XmlUtilTest/invalidPersonField.xml @@ -17,8 +17,8 @@ USA - 01/01/2018 14:00 - 01/01/2018 15:00 + 01-01-2018 14:00 + 01-01-2018 15:00 Consultation Room 1 Diabetes Checkup Dr Tan diff --git a/src/test/data/XmlUtilTest/missingPersonField.xml b/src/test/data/XmlUtilTest/missingPersonField.xml index c257fba53a38..dbb596b53b1e 100644 --- a/src/test/data/XmlUtilTest/missingPersonField.xml +++ b/src/test/data/XmlUtilTest/missingPersonField.xml @@ -16,8 +16,8 @@ USA - 01/01/2018 14:00 - 01/01/2018 15:00 + 01-01-2018 14:00 + 01-01-2018 15:00 Consultation Room 1 Diabetes Checkup Dr Tan diff --git a/src/test/data/XmlUtilTest/validPerson.xml b/src/test/data/XmlUtilTest/validPerson.xml index 0536eba7f94c..e53a06d46032 100644 --- a/src/test/data/XmlUtilTest/validPerson.xml +++ b/src/test/data/XmlUtilTest/validPerson.xml @@ -16,8 +16,8 @@ USA - 01/01/2018 14:00 - 01/01/2018 15:00 + 01-01-2018 14:00 + 01-01-2018 15:00 Consultation Room 1 Diabetes Checkup Dr Tan diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index a8857b3dd384..43c8e2bf9680 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -92,12 +92,12 @@ public class CommandTestUtil { public static final String VALID_INFO3 = "Prescribed XXX medicine, next appointment on 04/04/2018."; // Appt - public static final String VALID_START_APPT1 = "01/01/2018 14:00"; - public static final String VALID_START_APPT2 = "02/02/2018 15:00"; - public static final String VALID_START_APPT3 = "03/03/2018 16:00"; - public static final String VALID_END_APPT1 = "01/01/2018 15:00"; - public static final String VALID_END_APPT2 = "02/02/2018 16:00"; - public static final String VALID_END_APPT3 = "03/03/2018 17:00"; + public static final String VALID_START_APPT1 = "01-01-2018 14:00"; + public static final String VALID_START_APPT2 = "02-02-2018 15:00"; + public static final String VALID_START_APPT3 = "03-03-2018 16:00"; + public static final String VALID_END_APPT1 = "01-01-2018 15:00"; + public static final String VALID_END_APPT2 = "02-02-2018 16:00"; + public static final String VALID_END_APPT3 = "03-03-2018 17:00"; public static final String VALID_VENUE_APPT1 = "Consultation Room 1"; public static final String VALID_VENUE_APPT2 = "Consultation Room 2"; public static final String VALID_VENUE_APPT3 = "Consultation Room 3"; diff --git a/src/test/java/seedu/address/testutil/ApptUtil.java b/src/test/java/seedu/address/testutil/ApptUtil.java index 149f3487cf49..aed6698c6551 100644 --- a/src/test/java/seedu/address/testutil/ApptUtil.java +++ b/src/test/java/seedu/address/testutil/ApptUtil.java @@ -27,8 +27,8 @@ public static String getAddApptCommand(Appt appt) { */ public static String getApptDetails(Appt appt) { StringBuilder sb = new StringBuilder(); - sb.append(PREFIX_APPT_START + appt.getStart().value + " "); - sb.append(PREFIX_APPT_END + appt.getEnd().value + " "); + sb.append(PREFIX_APPT_START + appt.getStart().toString() + " "); + sb.append(PREFIX_APPT_END + appt.getEnd().toString() + " "); sb.append(PREFIX_APPT_VENUE + appt.getVenue().value + " "); sb.append(PREFIX_APPT_INFO + appt.getInfo().value + " "); sb.append(PREFIX_APPT_DRNAME + appt.getDrName().value + " "); From 6b5a892893c972f5571226532fcbafa6ec94be93 Mon Sep 17 00:00:00 2001 From: xhxh96 Date: Sun, 21 Oct 2018 22:57:14 +0800 Subject: [PATCH 09/68] Implemented Height and Weight Attributes - Add/update weight and height attribute via `addinfo` command - UI now displays header text for additional information --- .../logic/commands/AddApptCommand.java | 3 +- .../logic/commands/AddHistCommand.java | 3 +- .../logic/commands/AddInfoCommand.java | 31 +++++++++++++++-- .../commands/AddMedicalReportCommand.java | 3 +- .../address/logic/commands/EditCommand.java | 13 +++++--- .../logic/parser/AddCommandParser.java | 14 ++++++-- .../logic/parser/AddInfoCommandParser.java | 13 +++++++- .../address/logic/parser/ParserUtil.java | 24 ++++++++++++++ .../seedu/address/model/person/Person.java | 19 +++++++++-- .../address/model/person/addinfo/Height.java | 2 +- .../address/model/person/addinfo/Weight.java | 2 +- .../address/model/util/SampleDataUtil.java | 17 ++++++---- .../address/storage/XmlAdaptedPerson.java | 31 ++++++++++++++--- .../java/seedu/address/ui/PersonCard.java | 12 +++++-- src/main/resources/view/PersonListCard.fxml | 2 ++ .../seedu/address/testutil/PersonBuilder.java | 33 +++++++++++++++++-- 16 files changed, 188 insertions(+), 34 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddApptCommand.java b/src/main/java/seedu/address/logic/commands/AddApptCommand.java index 1ae76cf7f46d..83f4bb435c7f 100644 --- a/src/main/java/seedu/address/logic/commands/AddApptCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddApptCommand.java @@ -75,7 +75,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command newAppts.add(appt); Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), personToEdit.getAddress(), personToEdit.getMedicalReports(), personToEdit.getMedHistory(), newAppts, - personToEdit.getNric(), personToEdit.getDateOfBirth(), personToEdit.getTags()); + personToEdit.getNric(), personToEdit.getDateOfBirth(), personToEdit.getHeight(), + personToEdit.getWeight(), personToEdit.getTags()); model.updatePerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); diff --git a/src/main/java/seedu/address/logic/commands/AddHistCommand.java b/src/main/java/seedu/address/logic/commands/AddHistCommand.java index 68c17a6196bb..c86789b822f1 100644 --- a/src/main/java/seedu/address/logic/commands/AddHistCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddHistCommand.java @@ -64,7 +64,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command newMedHistories.add(medHistory); Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), personToEdit.getAddress(), personToEdit.getMedicalReports(), newMedHistories, personToEdit.getAppts(), - personToEdit.getNric(), personToEdit.getDateOfBirth(), personToEdit.getTags()); + personToEdit.getNric(), personToEdit.getDateOfBirth(), personToEdit.getHeight(), + personToEdit.getWeight(), personToEdit.getTags()); model.updatePerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); model.commitAddressBook(); diff --git a/src/main/java/seedu/address/logic/commands/AddInfoCommand.java b/src/main/java/seedu/address/logic/commands/AddInfoCommand.java index ab4b8527a360..4bf3c1a6113c 100644 --- a/src/main/java/seedu/address/logic/commands/AddInfoCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddInfoCommand.java @@ -7,6 +7,8 @@ import java.util.Optional; import java.util.Set; +import javax.swing.text.html.Option; + import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.CollectionUtil; @@ -19,9 +21,11 @@ import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.addinfo.Height; import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.addinfo.Weight; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.Appt; @@ -41,7 +45,6 @@ public class AddInfoCommand extends Command { public static final String MESSAGE_NOT_EDITED = "At least one field to add additional information must be provided"; public static final String MESSAGE_ADD_INFO_SUCCESS = "Added additional info to Person: %1$s"; - public static final String MESSAGE_DELETE_INFO_SUCCESS = "Removed additional info to person: %1$s"; private final Index index; private final AddInfoPersonDescriptor addInfoPersonDescriptor; @@ -96,9 +99,11 @@ private static Person createEditedPerson(Person personToEdit, AddInfoPersonDescr Nric updatedNric = addInfoPersonDescriptor.getNric().orElse(personToEdit.getNric()); DateOfBirth updatedDateOfBirth = addInfoPersonDescriptor.getDateOfBirth().orElse(personToEdit.getDateOfBirth()); + Height updatedHeight = addInfoPersonDescriptor.getHeight().orElse(personToEdit.getHeight()); + Weight updatedWeight = addInfoPersonDescriptor.getWeight().orElse(personToEdit.getWeight()); return new Person(name, phone, email, address, medicalReports, medHistory, appts, - updatedNric, updatedDateOfBirth, tags); + updatedNric, updatedDateOfBirth, updatedHeight, updatedWeight, tags); } @Override @@ -126,16 +131,20 @@ public boolean equals(Object other) { public static class AddInfoPersonDescriptor { private Nric nric; private DateOfBirth dateOfBirth; + private Height height; + private Weight weight; public AddInfoPersonDescriptor() {} public AddInfoPersonDescriptor(AddInfoPersonDescriptor toCopy) { setNric(toCopy.nric); setDateOfBirth(toCopy.dateOfBirth); + setHeight(toCopy.height); + setWeight(toCopy.weight); } public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(nric, dateOfBirth); + return CollectionUtil.isAnyNonNull(nric, dateOfBirth, height, weight); } public void setNric(Nric nric) { @@ -154,6 +163,22 @@ public Optional getDateOfBirth() { return Optional.ofNullable(dateOfBirth); } + public void setHeight(Height height) { + this.height = height; + } + + public Optional getHeight() { + return Optional.ofNullable(height); + } + + public void setWeight(Weight weight) { + this.weight = weight; + } + + public Optional getWeight() { + return Optional.ofNullable(weight); + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/commands/AddMedicalReportCommand.java b/src/main/java/seedu/address/logic/commands/AddMedicalReportCommand.java index 3867282fc6a6..85b5be8fd67a 100644 --- a/src/main/java/seedu/address/logic/commands/AddMedicalReportCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddMedicalReportCommand.java @@ -70,7 +70,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command newReports.add(report); Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), personToEdit.getAddress(), newReports, personToEdit.getMedHistory(), personToEdit.getAppts(), - personToEdit.getNric(), personToEdit.getDateOfBirth(), personToEdit.getTags()); + personToEdit.getNric(), personToEdit.getDateOfBirth(), personToEdit.getHeight(), + personToEdit.getWeight(), personToEdit.getTags()); model.updatePerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 3f18edff323a..bfe0150a607e 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -26,9 +26,11 @@ import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.addinfo.Height; import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.addinfo.Weight; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.Appt; @@ -104,16 +106,19 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); + Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); + + Nric nric = personToEdit.getNric(); + DateOfBirth dateOfBirth = personToEdit.getDateOfBirth(); + Height height = personToEdit.getHeight(); + Weight weight = personToEdit.getWeight(); Set updatedReports = personToEdit.getMedicalReports(); // edit command disallow editing reports Set updatedMedHistory = personToEdit.getMedHistory(); // edit command does not edit MedHistory now Set updatedAppts = personToEdit.getAppts(); // edit command does not allow editing appts - Nric updatedNric = personToEdit.getNric(); - DateOfBirth updatedDateOfBirth = personToEdit.getDateOfBirth(); - Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedReports, - updatedMedHistory, updatedAppts, updatedNric, updatedDateOfBirth, updatedTags); + updatedMedHistory, updatedAppts, nric, dateOfBirth, height, weight, updatedTags); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 816ce6756bde..df4ab6db2b18 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -19,9 +19,11 @@ import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.addinfo.Height; import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.addinfo.Weight; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.Appt; @@ -48,15 +50,21 @@ public AddCommand parse(String args) throws ParseException { Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); + Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Set reports = new HashSet<>(); // add command does not allow adding reports straight away + Set medHistories = new HashSet<>(); + Set appts = new HashSet<>(); // add command does not allow adding appts straight away + Nric nric = new Nric(""); DateOfBirth dateOfBirth = new DateOfBirth("01-01-1970"); - Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Height height = new Height(""); + Weight weight = new Weight(""); - Person person = new Person(name, phone, email, address, reports, medHistories, appts, nric, dateOfBirth, - tagList); + Person person = new Person(name, phone, email, address, reports, medHistories, appts, nric, dateOfBirth, height, + weight, tagList); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/AddInfoCommandParser.java b/src/main/java/seedu/address/logic/parser/AddInfoCommandParser.java index 690af0d3fd69..ecb47f42441c 100644 --- a/src/main/java/seedu/address/logic/parser/AddInfoCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddInfoCommandParser.java @@ -3,7 +3,9 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADD_INFO_DOB; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADD_INFO_HEIGHT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADD_INFO_NRIC; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADD_INFO_WEIGHT; import seedu.address.commons.core.index.Index; import seedu.address.commons.exceptions.IllegalValueException; @@ -23,7 +25,8 @@ public class AddInfoCommandParser implements Parser { */ public AddInfoCommand parse(String args) throws ParseException { requireNonNull(args); - ArgumentMultimap argMultiMap = ArgumentTokenizer.tokenize(args, PREFIX_ADD_INFO_NRIC, PREFIX_ADD_INFO_DOB); + ArgumentMultimap argMultiMap = ArgumentTokenizer.tokenize(args, PREFIX_ADD_INFO_NRIC, PREFIX_ADD_INFO_DOB, + PREFIX_ADD_INFO_HEIGHT, PREFIX_ADD_INFO_WEIGHT); Index index; try { @@ -40,6 +43,14 @@ public AddInfoCommand parse(String args) throws ParseException { addInfoPersonDescriptor.setDateOfBirth(ParserUtil.parseDateOfBirth( argMultiMap.getValue(PREFIX_ADD_INFO_DOB).get())); } + if (argMultiMap.getValue(PREFIX_ADD_INFO_HEIGHT).isPresent()) { + addInfoPersonDescriptor.setHeight(ParserUtil.parseHeight( + argMultiMap.getValue(PREFIX_ADD_INFO_HEIGHT).get())); + } + if (argMultiMap.getValue(PREFIX_ADD_INFO_WEIGHT).isPresent()) { + addInfoPersonDescriptor.setWeight(ParserUtil.parseWeight( + argMultiMap.getValue(PREFIX_ADD_INFO_WEIGHT).get())); + } if (!addInfoPersonDescriptor.isAnyFieldEdited()) { throw new ParseException(AddInfoCommand.MESSAGE_NOT_EDITED); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 46fcf70e4dd4..000e83525b11 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -21,8 +21,10 @@ import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.addinfo.Height; import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Phone; +import seedu.address.model.person.addinfo.Weight; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.ApptDateTime; import seedu.address.model.timetable.ApptDrName; @@ -148,6 +150,28 @@ public static DateOfBirth parseDateOfBirth(String dateOfBirth) throws ParseExcep return new DateOfBirth(trimmedDateOfBirth); } + public static Height parseHeight(String height) throws ParseException { + requireNonNull(height); + String trimmedHeight = height.trim(); + + if (!Height.isValidHeight(trimmedHeight)) { + throw new ParseException(Height.MESSAGE_HEIGHT_CONSTRAINTS); + } + + return new Height(trimmedHeight); + } + + public static Weight parseWeight(String weight) throws ParseException { + requireNonNull(weight); + String trimmedWeight = weight.trim(); + + if (!Weight.isValidWeight(trimmedWeight)) { + throw new ParseException(Weight.MESSAGE_WEIGHT_CONSTRAINTS); + } + + return new Weight(trimmedWeight); + } + /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index fe1225926232..c9a5a1b23fbf 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -10,7 +10,9 @@ import seedu.address.model.medhistory.MedHistory; import seedu.address.model.medicalreport.MedicalReport; import seedu.address.model.person.addinfo.DateOfBirth; +import seedu.address.model.person.addinfo.Height; import seedu.address.model.person.addinfo.Nric; +import seedu.address.model.person.addinfo.Weight; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.Appt; @@ -35,15 +37,16 @@ public class Person { // Additional information fields private final Nric nric; private final DateOfBirth dateOfBirth; - //private final Height height; - //private final Weight weight; + private final Height height; + private final Weight weight; //private final Gender gender; /** * Every field must be present and not null. */ public Person(Name name, Phone phone, Email email, Address address, Set reports, - Set medHistories, Set appts, Nric nric, DateOfBirth dateOfBirth, Set tags) { + Set medHistories, Set appts, Nric nric, DateOfBirth dateOfBirth, Height height, + Weight weight, Set tags) { requireAllNonNull(name, phone, email, address, tags); this.name = name; this.phone = phone; @@ -51,6 +54,8 @@ public Person(Name name, Phone phone, Email email, Address address, Set getAppts() { return Collections.unmodifiableSet(appts); } diff --git a/src/main/java/seedu/address/model/person/addinfo/Height.java b/src/main/java/seedu/address/model/person/addinfo/Height.java index 3ae153afda68..f3e327c6cc0b 100644 --- a/src/main/java/seedu/address/model/person/addinfo/Height.java +++ b/src/main/java/seedu/address/model/person/addinfo/Height.java @@ -3,7 +3,7 @@ import static java.util.Objects.requireNonNull; public class Height { - public static final String HEIGHT_VALIDATION_REGEX = "[\\d]"; + public static final String HEIGHT_VALIDATION_REGEX = "[\\d]+"; public static final String MESSAGE_HEIGHT_CONSTRAINTS = "Height should be numeric input only."; public final String value; diff --git a/src/main/java/seedu/address/model/person/addinfo/Weight.java b/src/main/java/seedu/address/model/person/addinfo/Weight.java index eca6eb64d7c6..dda720dbec6f 100644 --- a/src/main/java/seedu/address/model/person/addinfo/Weight.java +++ b/src/main/java/seedu/address/model/person/addinfo/Weight.java @@ -3,7 +3,7 @@ import static java.util.Objects.requireNonNull; public class Weight { - public static final String WEIGHT_VALIDATION_REGEX = "[\\d]"; + public static final String WEIGHT_VALIDATION_REGEX = "[\\d]+"; public static final String MESSAGE_WEIGHT_CONSTRAINTS = "Weight should be numeric input only."; public final String value; diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index f6e96b964280..9396fe52c22c 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -13,9 +13,11 @@ import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.addinfo.Height; import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.addinfo.Weight; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.Appt; @@ -26,31 +28,34 @@ public class SampleDataUtil { public static final Nric EMPTY_NRIC = new Nric(""); public static final DateOfBirth EMPTY_DATE_OF_BIRTH = new DateOfBirth("01-01-1970"); + public static final Height EMPTY_HEIGHT = new Height(""); + public static final Weight EMPTY_WEIGHT = new Weight(""); public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), getReportSet(), - getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, getTagSet("friends")), + getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, new Height("42"), EMPTY_WEIGHT, + getTagSet("friends")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), getReportSet(), - getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, + getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, EMPTY_HEIGHT, EMPTY_WEIGHT, getTagSet("colleagues", "friends")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), getReportSet(), - getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, + getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, EMPTY_HEIGHT, EMPTY_WEIGHT, getTagSet("neighbours")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), getReportSet(), - getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, + getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, EMPTY_HEIGHT, EMPTY_WEIGHT, getTagSet("family")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), getReportSet(), - getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, + getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, EMPTY_HEIGHT, EMPTY_WEIGHT, getTagSet("classmates")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), getReportSet(), - getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, + getMedHistorySet(), getApptSet(), EMPTY_NRIC, EMPTY_DATE_OF_BIRTH, EMPTY_HEIGHT, EMPTY_WEIGHT, getTagSet("colleagues")) }; } diff --git a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java index b398dd65aa0a..e49611b9fbc7 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java @@ -16,9 +16,11 @@ import seedu.address.model.person.addinfo.DateOfBirth; import seedu.address.model.person.Email; import seedu.address.model.person.Name; +import seedu.address.model.person.addinfo.Height; import seedu.address.model.person.addinfo.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.addinfo.Weight; import seedu.address.model.tag.Tag; import seedu.address.model.timetable.Appt; @@ -36,18 +38,24 @@ public class XmlAdaptedPerson { private String email; @XmlElement(required = true) private String address; + @XmlElement + private List tagged = new ArrayList<>(); + @XmlElement(required = true) private String nric; @XmlElement(required = true) private String dateOfBirth; + @XmlElement(required = true) + private String height; + @XmlElement(required = true) + private String weight; + @XmlElement private List reports = new ArrayList<>(); @XmlElement private List medHistories = new ArrayList<>(); @XmlElement private List appts = new ArrayList<>(); - @XmlElement - private List tagged = new ArrayList<>(); /** * Constructs an XmlAdaptedPerson. @@ -89,12 +97,16 @@ public XmlAdaptedPerson(Person source) { phone = source.getPhone().value; email = source.getEmail().value; address = source.getAddress().value; + tagged = source.getTags().stream().map(XmlAdaptedTag::new).collect(Collectors.toList()); + nric = source.getNric().value; dateOfBirth = source.getDateOfBirth().toString(); + height = source.getHeight().value; + weight = source.getWeight().value; + reports = source.getMedicalReports().stream().map(XmlAdaptedReport::new).collect(Collectors.toList()); medHistories = source.getMedHistory().stream().map(XmlAdaptedMedHistory::new).collect(Collectors.toList()); appts = source.getAppts().stream().map(XmlAdaptedAppt::new).collect(Collectors.toList()); - tagged = source.getTags().stream().map(XmlAdaptedTag::new).collect(Collectors.toList()); } /** @@ -152,6 +164,16 @@ public Person toModelType() throws IllegalValueException { } final DateOfBirth modelDateOfBirth = new DateOfBirth(dateOfBirth); + if (height == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Height.class.getSimpleName())); + } + final Height modelHeight = new Height(height); + + if (weight == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Weight.class.getSimpleName())); + } + final Weight modelWeight = new Weight(weight); + /** * ================================================== * SUBFIELDS IN LIST FORMAT @@ -183,7 +205,8 @@ public Person toModelType() throws IllegalValueException { final Set modelTags = new HashSet<>(personTags); return new Person(modelName, modelPhone, modelEmail, modelAddress, modelReports, - modelMedHistory, modelAppts, modelNric, modelDateOfBirth, modelTags); + modelMedHistory, modelAppts, modelNric, modelDateOfBirth, modelHeight, modelWeight, + modelTags); } @Override diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 37dd85ba3396..7ae1bb2e86ce 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -41,6 +41,10 @@ public class PersonCard extends UiPart { @FXML private Label dateOfBirth; @FXML + private Label height; + @FXML + private Label weight; + @FXML private FlowPane reports; @FXML private FlowPane appts; @@ -57,8 +61,12 @@ public PersonCard(Person person, int displayedIndex) { phone.setText(person.getPhone().value); address.setText(person.getAddress().value); email.setText(person.getEmail().value); - nric.setText(person.getNric().value); - dateOfBirth.setText(person.getDateOfBirth().toString()); + + // TODO: Split the static text from dynamic text in UI + nric.setText("NRIC: " + person.getNric().value); + dateOfBirth.setText("Date Of Birth: " + person.getDateOfBirth().toString()); + height.setText("Height: " + person.getHeight().value); + weight.setText("Weight: " + person.getWeight().value); person.getMedHistory().forEach(medHistory -> medHistories.getChildren().add(new Label(medHistory.toString()))); person.getMedicalReports().forEach(report -> reports.getChildren().add(new Label(report.toString()))); person.getAppts().forEach(appt -> appts.getChildren().add(new Label(appt.toString()))); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index e85f39efdb58..b2144b26a821 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -33,6 +33,8 @@