From 291d956b551cb0cb118dd8236adbad51fb82a190 Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 20 Oct 2023 21:55:30 +0800 Subject: [PATCH] Modify records to fit with appointments --- .../java/seedu/address/logic/Messages.java | 33 ++++++++--- .../logic/commands/AddAppointmentCommand.java | 6 +- .../logic/commands/AddRecordCommand.java | 14 ++--- .../address/logic/commands/EditCommand.java | 8 ++- .../parser/AddAppointmentCommandParser.java | 4 +- .../logic/parser/AddCommandParser.java | 5 +- .../logic/parser/AddRecordCommandParser.java | 2 +- .../address/logic/parser/ParserUtil.java | 4 +- .../{person => }/appointment/Appointment.java | 3 +- .../appointment/UniqueAppointmentList.java | 6 +- .../AppointmentNotFoundException.java | 2 +- .../DuplicateAppointmentException.java | 2 +- .../seedu/address/model/person/Person.java | 6 +- .../seedu/address/model/record/Condition.java | 4 +- .../seedu/address/model/record/Record.java | 2 +- .../model/{person => }/shared/DateTime.java | 14 +---- .../address/model/util/SampleDataUtil.java | 18 +++--- .../storage/JsonAdaptedAppointment.java | 8 +-- .../address/storage/JsonAdaptedPerson.java | 11 ++-- .../address/storage/JsonAdaptedRecord.java | 10 ++-- .../invalidAndValidPersonAddressBook.json | 20 +++++-- .../invalidPersonAddressBook.json | 10 +++- .../typicalPersonsAddressBook.json | 58 ++++++++++++++----- .../commands/AddAppointmentCommandTest.java | 4 +- .../logic/commands/AddRecordCommandTest.java | 19 +++--- .../logic/commands/CommandTestUtil.java | 4 +- .../logic/commands/EditCommandTest.java | 4 +- .../AddAppointmentCommandParserTest.java | 4 +- .../parser/AddRecordCommandParserTest.java | 2 +- .../logic/parser/AddressBookParserTest.java | 2 +- .../appointment/AppointmentTest.java | 3 +- .../appointment/DateTimeTest.java | 6 +- .../UniqueAppointmentListTest.java | 8 ++- .../address/model/record/DateTimeTest.java | 9 +-- .../address/model/record/RecordTest.java | 4 +- .../storage/JsonAdaptedAppointmentTest.java | 2 +- .../storage/JsonAdaptedRecordTest.java | 5 +- .../address/testutil/AppointmentBuilder.java | 4 +- .../address/testutil/AppointmentUtil.java | 2 +- .../seedu/address/testutil/PersonBuilder.java | 18 +++--- .../seedu/address/testutil/RecordBuilder.java | 4 +- .../address/testutil/TypicalAppointments.java | 4 +- .../address/testutil/TypicalPersons.java | 15 ++--- .../address/testutil/TypicalRecords.java | 12 ++-- 44 files changed, 211 insertions(+), 174 deletions(-) rename src/main/java/seedu/address/model/{person => }/appointment/Appointment.java (95%) rename src/main/java/seedu/address/model/{person => }/appointment/UniqueAppointmentList.java (95%) rename src/main/java/seedu/address/model/{person => }/appointment/exceptions/AppointmentNotFoundException.java (72%) rename src/main/java/seedu/address/model/{person => }/appointment/exceptions/DuplicateAppointmentException.java (85%) rename src/main/java/seedu/address/model/{person => }/shared/DateTime.java (86%) rename src/test/java/seedu/address/model/{person => }/appointment/AppointmentTest.java (96%) rename src/test/java/seedu/address/model/{person => }/appointment/DateTimeTest.java (95%) rename src/test/java/seedu/address/model/{person => }/appointment/UniqueAppointmentListTest.java (94%) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 1c0b8e3b6be..52be7953670 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -5,8 +5,9 @@ import java.util.stream.Stream; import seedu.address.logic.parser.Prefix; +import seedu.address.model.appointment.Appointment; import seedu.address.model.person.Person; -import seedu.address.model.person.appointment.Appointment; +import seedu.address.model.record.Record; /** * Container for user visible messages. @@ -17,8 +18,7 @@ public class Messages { public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid"; public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; - public static final String MESSAGE_DUPLICATE_FIELDS = - "Multiple values specified for the following single-valued field(s): "; + public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the following single-valued field(s): "; /** * Returns an error message indicating the duplicate prefixes. @@ -26,8 +26,7 @@ public class Messages { public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePrefixes) { assert duplicatePrefixes.length > 0; - Set duplicateFields = - Stream.of(duplicatePrefixes).map(Prefix::toString).collect(Collectors.toSet()); + Set duplicateFields = Stream.of(duplicatePrefixes).map(Prefix::toString).collect(Collectors.toSet()); return MESSAGE_DUPLICATE_FIELDS + String.join(" ", duplicateFields); } @@ -58,11 +57,27 @@ public static String format(Person person) { */ public static String format(Appointment appointment, Person person) { final StringBuilder builder = new StringBuilder(); - builder.append(appointment.getName()) + builder.append("Patient: ") + .append(person.getName()) + .append("; Appointment: ") + .append(appointment.getName()) .append("; Date & Time: ") - .append(appointment.getDateTime()) - .append("; Patient: ") - .append(person.getName()); + .append(appointment.getDateTime()); + + return builder.toString(); + } + + /** + * Formats the {@code person} for display to the user. + */ + public static String format(Record record, Person person) { + final StringBuilder builder = new StringBuilder(); + builder.append("Patient: ") + .append(person.getName()) + .append("; Conditions: ") + .append(record.getConditions()) + .append("; Date & Time: ") + .append(record.getDateTime()); return builder.toString(); } } diff --git a/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java b/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java index 4249a1070b0..64635d205c2 100644 --- a/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java @@ -11,9 +11,9 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.UniqueAppointmentList; import seedu.address.model.person.Person; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.UniqueAppointmentList; /** * Adds an appointment to the address book. @@ -67,7 +67,7 @@ public CommandResult execute(Model model) throws CommandException { Person newPerson = new Person(oldPerson.getName(), oldPerson.getEmail(), oldPerson.getPhone(), oldPerson.getGender(), oldPerson.getAge(), oldPerson.getBloodType(), oldPerson.getAllergies(), - oldPerson.isPinned(), newAppointmentList); + oldPerson.getRecords(), newAppointmentList, oldPerson.isPinned()); model.setPerson(oldPerson, newPerson); return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd, newPerson))); diff --git a/src/main/java/seedu/address/logic/commands/AddRecordCommand.java b/src/main/java/seedu/address/logic/commands/AddRecordCommand.java index 89c9c672b6f..9af71fe2762 100644 --- a/src/main/java/seedu/address/logic/commands/AddRecordCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddRecordCommand.java @@ -22,15 +22,15 @@ public class AddRecordCommand extends Command { public static final String COMMAND_WORD = "addrecord"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a patient record to the address book. " - + "Parameters: " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a patient record to the address book.\n" + + "Parameters: INDEX (must be a positive integer) " + PREFIX_DATE + "DATE " + PREFIX_CONDITION + "CONDITION " + "\n" - + "Example: " + COMMAND_WORD + " " - + PREFIX_DATE + "18092023 1800" + + "Example: " + COMMAND_WORD + " 1 " + + PREFIX_DATE + "18-09-2023 1800 " + PREFIX_CONDITION + "Fever"; - public static final String MESSAGE_SUCCESS = "New record added"; + public static final String MESSAGE_SUCCESS = "New record added: %1$s"; private final Record record; @@ -60,11 +60,11 @@ public CommandResult execute(Model model) throws CommandException { Person personWithAddedRecord = new Person(personToAddRecord.getName(), personToAddRecord.getEmail(), personToAddRecord.getPhone(), personToAddRecord.getGender(), personToAddRecord.getAge(), personToAddRecord.getBloodType(), personToAddRecord.getAllergies(), - newRecords, personToAddRecord.isPinned()); + newRecords, personToAddRecord.getAppointments(), personToAddRecord.isPinned()); model.setPerson(personToAddRecord, personWithAddedRecord); - return new CommandResult(MESSAGE_SUCCESS); + return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(record, personWithAddedRecord))); } @Override diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 4a05eee438c..684d4491c97 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -23,6 +23,7 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.appointment.UniqueAppointmentList; import seedu.address.model.person.Age; import seedu.address.model.person.Allergy; import seedu.address.model.person.BloodType; @@ -31,7 +32,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; -import seedu.address.model.person.appointment.UniqueAppointmentList; +import seedu.address.model.record.UniqueRecordList; /** @@ -111,11 +112,12 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Age updatedAge = editPersonDescriptor.getAge().orElse(personToEdit.getAge()); BloodType updatedBloodType = editPersonDescriptor.getBloodType().orElse(personToEdit.getBloodType()); Set updatedAllergies = editPersonDescriptor.getAllergies().orElse(personToEdit.getAllergies()); - Boolean updatedisPinned = personToEdit.isPinned(); + UniqueRecordList updatedRecords = personToEdit.getRecords(); UniqueAppointmentList updatedAppointments = personToEdit.getAppointments(); + Boolean updatedisPinned = personToEdit.isPinned(); return new Person(updatedName, updatedEmail, updatedPhone, updatedGender, - updatedAge, updatedBloodType, updatedAllergies, updatedisPinned, updatedAppointments); + updatedAge, updatedBloodType, updatedAllergies, updatedRecords, updatedAppointments, updatedisPinned); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java b/src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java index 6468601aea2..06ea7c749ab 100644 --- a/src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java @@ -10,9 +10,9 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.AddAppointmentCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.appointment.Appointment; import seedu.address.model.person.Name; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.DateTime; +import seedu.address.model.shared.DateTime; /** * Parses input arguments and creates a new AddAppointmentCommand object diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 736a66da0a5..31f5e3b4663 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -14,6 +14,7 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.appointment.UniqueAppointmentList; import seedu.address.model.person.Age; import seedu.address.model.person.Allergy; import seedu.address.model.person.BloodType; @@ -22,7 +23,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; -import seedu.address.model.person.appointment.UniqueAppointmentList; +import seedu.address.model.record.UniqueRecordList; /** * Parses input arguments and creates a new AddCommand object @@ -56,7 +57,7 @@ public AddCommand parse(String args) throws ParseException { Set allergies = ParserUtil.parseAllergies(argMultimap.getAllValues(PREFIX_ALLERGIES)); Person person = new Person(name, email, phone, gender, age, bloodType, allergies, - false, new UniqueAppointmentList()); + new UniqueRecordList(), new UniqueAppointmentList(), false); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/AddRecordCommandParser.java b/src/main/java/seedu/address/logic/parser/AddRecordCommandParser.java index d517beb82a2..389ae3486c4 100644 --- a/src/main/java/seedu/address/logic/parser/AddRecordCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddRecordCommandParser.java @@ -10,9 +10,9 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.AddRecordCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.shared.DateTime; import seedu.address.model.record.Condition; import seedu.address.model.record.Record; +import seedu.address.model.shared.DateTime; /** * Parses a user input and creates a AddRecordCommand object diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index e8536bb8c4c..df8ee1f7c63 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -11,6 +11,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.shared.DateTime; import seedu.address.model.person.Age; import seedu.address.model.person.Allergy; import seedu.address.model.person.BloodType; @@ -18,7 +19,6 @@ import seedu.address.model.person.Gender; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; -import seedu.address.model.person.appointment.DateTime; import seedu.address.model.record.Condition; /** * Contains utility methods used for parsing strings in the various *Parser classes. @@ -193,7 +193,7 @@ public static Condition parseCondition(String condition) throws ParseException { requireNonNull(condition); String trimmedCondition = condition.trim(); if (!Condition.isValidCondition(trimmedCondition)) { - throw new ParseException(DateTime.MESSAGE_CONSTRAINTS); + throw new ParseException(Condition.MESSAGE_CONSTRAINTS); } return new Condition(trimmedCondition); } diff --git a/src/main/java/seedu/address/model/person/appointment/Appointment.java b/src/main/java/seedu/address/model/appointment/Appointment.java similarity index 95% rename from src/main/java/seedu/address/model/person/appointment/Appointment.java rename to src/main/java/seedu/address/model/appointment/Appointment.java index 2358387deb9..1a201d081c3 100644 --- a/src/main/java/seedu/address/model/person/appointment/Appointment.java +++ b/src/main/java/seedu/address/model/appointment/Appointment.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.appointment; +package seedu.address.model.appointment; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; @@ -6,6 +6,7 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.person.Name; +import seedu.address.model.shared.DateTime; /** * Represents an Appointment in the address book. diff --git a/src/main/java/seedu/address/model/person/appointment/UniqueAppointmentList.java b/src/main/java/seedu/address/model/appointment/UniqueAppointmentList.java similarity index 95% rename from src/main/java/seedu/address/model/person/appointment/UniqueAppointmentList.java rename to src/main/java/seedu/address/model/appointment/UniqueAppointmentList.java index 83ad5fa6144..16f09078353 100644 --- a/src/main/java/seedu/address/model/person/appointment/UniqueAppointmentList.java +++ b/src/main/java/seedu/address/model/appointment/UniqueAppointmentList.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.appointment; +package seedu.address.model.appointment; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; @@ -8,8 +8,8 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import seedu.address.model.person.appointment.exceptions.AppointmentNotFoundException; -import seedu.address.model.person.appointment.exceptions.DuplicateAppointmentException; +import seedu.address.model.appointment.exceptions.AppointmentNotFoundException; +import seedu.address.model.appointment.exceptions.DuplicateAppointmentException; /** * A list of appointments that enforces uniqueness between its elements and does not allow nulls. diff --git a/src/main/java/seedu/address/model/person/appointment/exceptions/AppointmentNotFoundException.java b/src/main/java/seedu/address/model/appointment/exceptions/AppointmentNotFoundException.java similarity index 72% rename from src/main/java/seedu/address/model/person/appointment/exceptions/AppointmentNotFoundException.java rename to src/main/java/seedu/address/model/appointment/exceptions/AppointmentNotFoundException.java index 3a048356ffa..5dc5c48d3d8 100644 --- a/src/main/java/seedu/address/model/person/appointment/exceptions/AppointmentNotFoundException.java +++ b/src/main/java/seedu/address/model/appointment/exceptions/AppointmentNotFoundException.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.appointment.exceptions; +package seedu.address.model.appointment.exceptions; /** * Signals that the operation is unable to find the specified appointment. diff --git a/src/main/java/seedu/address/model/person/appointment/exceptions/DuplicateAppointmentException.java b/src/main/java/seedu/address/model/appointment/exceptions/DuplicateAppointmentException.java similarity index 85% rename from src/main/java/seedu/address/model/person/appointment/exceptions/DuplicateAppointmentException.java rename to src/main/java/seedu/address/model/appointment/exceptions/DuplicateAppointmentException.java index 293054922d5..bbbaa46ea89 100644 --- a/src/main/java/seedu/address/model/person/appointment/exceptions/DuplicateAppointmentException.java +++ b/src/main/java/seedu/address/model/appointment/exceptions/DuplicateAppointmentException.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.appointment.exceptions; +package seedu.address.model.appointment.exceptions; /** * Signals that the operation will result in duplicate Appointments (Appointments are considered diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 8bb91e7e75f..f643ec13fad 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -9,9 +9,9 @@ import java.util.Set; import seedu.address.commons.util.ToStringBuilder; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.UniqueAppointmentList -;import seedu.address.model.record.Record; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.UniqueAppointmentList; +import seedu.address.model.record.Record; import seedu.address.model.record.UniqueRecordList; diff --git a/src/main/java/seedu/address/model/record/Condition.java b/src/main/java/seedu/address/model/record/Condition.java index b213776465e..63d47bb0f33 100644 --- a/src/main/java/seedu/address/model/record/Condition.java +++ b/src/main/java/seedu/address/model/record/Condition.java @@ -54,8 +54,6 @@ public int hashCode() { @Override public String toString() { - return "[" + condition + "]"; + return condition; } - - } diff --git a/src/main/java/seedu/address/model/record/Record.java b/src/main/java/seedu/address/model/record/Record.java index 8515dd1f16c..398adf26b34 100644 --- a/src/main/java/seedu/address/model/record/Record.java +++ b/src/main/java/seedu/address/model/record/Record.java @@ -8,7 +8,7 @@ import java.util.Objects; import seedu.address.commons.util.ToStringBuilder; -import seedu.address.model.person.shared.DateTime; +import seedu.address.model.shared.DateTime; /** * Record of condition of a patient and date and time in which a patient visits the doctor diff --git a/src/main/java/seedu/address/model/person/shared/DateTime.java b/src/main/java/seedu/address/model/shared/DateTime.java similarity index 86% rename from src/main/java/seedu/address/model/person/shared/DateTime.java rename to src/main/java/seedu/address/model/shared/DateTime.java index 8b027771825..9967cacaf87 100644 --- a/src/main/java/seedu/address/model/person/shared/DateTime.java +++ b/src/main/java/seedu/address/model/shared/DateTime.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.shared; +package seedu.address.model.shared; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; @@ -28,16 +28,6 @@ public DateTime(String dateTime) { this.dateTime = LocalDateTime.parse(dateTime, FORMATTER); } - /** - * Constructs a {@code DateTime}. - * - * @param dateTime A valid date and time. - */ - public DateTime(LocalDateTime dateTime) { - requireNonNull(dateTime); - this.dateTime = dateTime; - } - /** * Returns true if a given string is a valid date-time. */ @@ -74,6 +64,4 @@ public int hashCode() { public String toString() { return dateTime.format(FORMATTER); } - - } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 358811621c5..7549c1d226c 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -7,6 +7,9 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.shared.DateTime; +import seedu.address.model.appointment.UniqueAppointmentList; import seedu.address.model.person.Age; import seedu.address.model.person.Allergy; import seedu.address.model.person.BloodType; @@ -15,9 +18,6 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.DateTime; -import seedu.address.model.person.appointment.UniqueAppointmentList; import seedu.address.model.record.Condition; import seedu.address.model.record.Record; import seedu.address.model.record.UniqueRecordList; @@ -31,22 +31,22 @@ public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Email("alexyeoh@example.com"), new Phone("87438807"), new Gender("M"), new Age(12), new BloodType("A+"), getAllergySet("Peanuts"), - true, getAppointmentList(new Appointment(new Name("Eye Exam"), new DateTime("01-01-2001 1200")))), + getRecordList(new Record(new DateTime("01-01-2001 1200"), getConditionList("Fever"))), getAppointmentList(new Appointment(new Name("Eye Exam"), new DateTime("01-01-2001 1200"))), true), new Person(new Name("Bernice Yu"), new Email("berniceyu@example.com"), new Phone("99272758"), new Gender("F"), new Age(31), new BloodType("B+"), getAllergySet("Dust", "Peanuts"), - false, new UniqueAppointmentList()), + new UniqueRecordList(), new UniqueAppointmentList(), false), new Person(new Name("Charlotte Oliveiro"), new Email("charlotte@example.com"), new Phone("93210283"), new Gender("F"), new Age(12), new BloodType("AB+"), getAllergySet("Dust"), - false, new UniqueAppointmentList()), + new UniqueRecordList(), new UniqueAppointmentList(), false), new Person(new Name("David Li"), new Email("lidavid@example.com"), new Phone("91031282"), new Gender("M"), new Age(33), new BloodType("O-"), - getAllergySet("Pollen"), false, new UniqueAppointmentList()), + getAllergySet("Pollen"), new UniqueRecordList(), new UniqueAppointmentList(), false), new Person(new Name("Irfan Ibrahim"), new Email("irfan@example.com"), new Phone("92492021"), new Gender("M"), new Age(21), new BloodType("B-"), - getAllergySet("Fur"), false, new UniqueAppointmentList()), + getAllergySet("Fur"), new UniqueRecordList(), new UniqueAppointmentList(), false), new Person(new Name("Roy Balakrishnan"), new Email("royb@example.com"), new Phone("92624417"), new Gender("M"), new Age(24), new BloodType("B+"), - getAllergySet("Grass"), false, new UniqueAppointmentList()), + getAllergySet("Grass"), new UniqueRecordList(), new UniqueAppointmentList(), false), }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java b/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java index 5fbd2801bf6..c655facb0e9 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java @@ -4,10 +4,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.shared.DateTime; import seedu.address.model.person.Name; import seedu.address.model.person.Person; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.DateTime; /** * Jackson-friendly version of {@link Person}. @@ -43,7 +43,7 @@ public JsonAdaptedAppointment(Appointment source) { */ public Appointment toModelType() throws IllegalValueException { if (name == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Name")); + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); } if (!Name.isValidName(name)) { throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); @@ -51,7 +51,7 @@ public Appointment toModelType() throws IllegalValueException { final Name modelname = new Name(name); if (dateTime == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "DateTime")); + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, DateTime.class.getSimpleName())); } if (!DateTime.isValidDateTime(dateTime)) { throw new IllegalValueException(DateTime.MESSAGE_CONSTRAINTS); diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 80d06a46f53..76726ff2f2f 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -10,6 +10,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.UniqueAppointmentList; import seedu.address.model.person.Age; import seedu.address.model.person.Allergy; import seedu.address.model.person.BloodType; @@ -20,9 +22,6 @@ import seedu.address.model.person.Phone; import seedu.address.model.record.UniqueRecordList; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.UniqueAppointmentList; - /** * Jackson-friendly version of {@link Person}. */ @@ -87,10 +86,10 @@ public JsonAdaptedPerson(Person source) { .stream() .map(JsonAdaptedRecord::new) .collect(Collectors.toList())); - isPinned = source.isPinned(); appointments.addAll(source.getAppointments().asUnmodifiableObservableList().stream() .map(JsonAdaptedAppointment::new) - .collect(Collectors.toList())); + .collect(Collectors.toList())); + isPinned = source.isPinned(); } /** @@ -168,6 +167,6 @@ public Person toModelType() throws IllegalValueException { return new Person(modelName, modelEmail, modelPhone, modelGender, - modelAge, modelBloodType, modelAllergies, modelRecords, isPinned, modelAppointments); + modelAge, modelBloodType, modelAllergies, modelRecords, modelAppointments, isPinned); } } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedRecord.java b/src/main/java/seedu/address/storage/JsonAdaptedRecord.java index 2a0b2b67445..e36e476c7f3 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedRecord.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedRecord.java @@ -1,6 +1,5 @@ package seedu.address.storage; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -9,9 +8,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.shared.DateTime; import seedu.address.model.record.Condition; import seedu.address.model.record.Record; +import seedu.address.model.shared.DateTime; /** * Jackson-friendly version of {@link Record}. @@ -19,7 +18,7 @@ public class JsonAdaptedRecord { public static final String MISSING_FIELD_MESSAGE_FORMAT = "Record's %s field is missing!"; - private final LocalDateTime dateTime; + private final String dateTime; private final List conditions = new ArrayList<>(); @@ -27,7 +26,7 @@ public class JsonAdaptedRecord { * Constructs a {@code JsonAdoptedRecord} with the given record details. */ @JsonCreator - public JsonAdaptedRecord(@JsonProperty("dateTime") LocalDateTime dateTime, + public JsonAdaptedRecord(@JsonProperty("dateTime") String dateTime, @JsonProperty("condition") List conditions) { this.dateTime = dateTime; if (conditions != null) { @@ -39,7 +38,7 @@ public JsonAdaptedRecord(@JsonProperty("dateTime") LocalDateTime dateTime, * Converts a given {@code Record} into this class for Jackson use. */ public JsonAdaptedRecord(Record source) { - this.dateTime = source.getDateTime().dateTime; + this.dateTime = source.getDateTime().toString(); this.conditions.addAll(source.getConditions().stream() .map(JsonAdaptedCondition::new) .collect(Collectors.toList())); @@ -74,6 +73,5 @@ public Record toModelType() throws IllegalValueException { final List modelConditions = new ArrayList<>(conditionsList); return new Record(modelDateTime, modelConditions); - } } diff --git a/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json b/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json index 6dcc05a5488..ff3e4db7b39 100644 --- a/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json +++ b/src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json @@ -8,13 +8,19 @@ "age": "18", "bloodType": "A+", "allergies": ["Peanuts"], - "isPinned": true, + "records": [ + { + "dateTime": "01-01-2001 1200", + "conditions": ["Fever"] + } + ], "appointments": [ { "name": "Eye Examination", "dateTime": "18-09-2023 1800" } - ] + ], + "isPinned": true }, { "name": "Person With Invalid Phone Field", @@ -24,13 +30,19 @@ "age": "18", "bloodType": "A+", "allergies": ["Peanuts"], - "isPinned": true, + "records": [ + { + "dateTime": "01-01-2001 1200", + "conditions": ["Fever"] + } + ], "appointments": [ { "name": "Eye Examination", "dateTime": "18-09-2023 1800" } - ] + ], + "isPinned": true } ] } diff --git a/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json b/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json index a32353a03cd..33af3f2e953 100644 --- a/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json +++ b/src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json @@ -8,13 +8,19 @@ "age": "18", "bloodType": "A+", "allergies": ["Peanuts"], - "isPinned": true, + "records": [ + { + "dateTime": "01-01-2001 1200", + "conditions": ["Fever"] + } + ], "appointments": [ { "name": "Eye Examination", "dateTime": "18-09-2023 1800" } - ] + ], + "isPinned": false } ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index 6a264a4ed6b..04f32845a38 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -9,13 +9,23 @@ "gender": "F", "age": 20, "allergies": ["Chocolate"], - "isPinned": true, + "records": [ + { + "dateTime": "09-09-2023 1800", + "conditions": ["Fever", "Cold"] + }, + { + "dateTime": "23-10-2022 1130", + "conditions": ["Allergic Reaction"] + } + ], "appointments": [ { "name": "Eye Exam", "dateTime": "01-01-2001 1200" } - ] + ], + "isPinned": true }, { "name": "Benson Meier", @@ -25,13 +35,23 @@ "gender": "M", "age": 15, "allergies": ["Pollen", "Soil"], - "isPinned": false, + "records": [ + { + "dateTime": "24-12-2023 1200", + "conditions": ["Headache"] + }, + { + "dateTime": "23-10-2022 1130", + "conditions": ["Allergic Reaction"] + } + ], "appointments": [ { "name": "Vaccination", "dateTime": "11-09-2001 1200" } - ] + ], + "isPinned": false }, { "name": "Carl Kurz", @@ -41,13 +61,19 @@ "gender": "M", "age": 24, "allergies": ["Dogs"], - "isPinned": false, + "records": [ + { + "dateTime": "20-03-2023 1500", + "conditions": ["Stomachache"] + } + ], "appointments": [ { "name": "Colonoscopy", "dateTime": "21-12-2001 1200" } - ] + ], + "isPinned": false }, { "name": "Daniel Meier", @@ -57,8 +83,9 @@ "gender": "M", "age": 26, "allergies": ["Cats"], - "isPinned": false, - "appointments": [] + "records": [], + "appointments": [], + "isPinned": false }, { "name": "Elle Meyer", @@ -68,8 +95,9 @@ "gender": "F", "age": 27, "allergies": ["Light"], - "isPinned": false, - "appointments": [] + "records": [], + "appointments": [], + "isPinned": false }, { "name": "Fiona Kunz", @@ -79,8 +107,9 @@ "gender": "F", "age": 29, "allergies": [], - "isPinned": false, - "appointments": [] + "records": [], + "appointments": [], + "isPinned": false }, { "name": "George Best", @@ -90,8 +119,9 @@ "gender": "M", "age": 30, "allergies": [], - "isPinned": false, - "appointments": [] + "records": [], + "appointments": [], + "isPinned": false } ] } diff --git a/src/test/java/seedu/address/logic/commands/AddAppointmentCommandTest.java b/src/test/java/seedu/address/logic/commands/AddAppointmentCommandTest.java index b183f86e1c0..ace6ab75131 100644 --- a/src/test/java/seedu/address/logic/commands/AddAppointmentCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddAppointmentCommandTest.java @@ -21,9 +21,9 @@ import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.UniqueAppointmentList; import seedu.address.model.person.Person; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.UniqueAppointmentList; import seedu.address.testutil.AppointmentBuilder; import seedu.address.testutil.PersonBuilder; diff --git a/src/test/java/seedu/address/logic/commands/AddRecordCommandTest.java b/src/test/java/seedu/address/logic/commands/AddRecordCommandTest.java index 1fa69e913fc..55309d86844 100644 --- a/src/test/java/seedu/address/logic/commands/AddRecordCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddRecordCommandTest.java @@ -22,7 +22,6 @@ import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; import seedu.address.model.person.Person; -import seedu.address.model.record.Record; import seedu.address.model.record.UniqueRecordList; import seedu.address.testutil.PersonBuilder; @@ -33,15 +32,14 @@ public class AddRecordCommandTest { public void execute_validIndexUnfilteredList_success() { Person personToAddRecord = model.getFilteredPersonList().get(INDEX_THIRD_PERSON.getZeroBased()); UniqueRecordList records = new UniqueRecordList(); - for (Record record : personToAddRecord.getRecords()) { - records.add(record); - } + records.setRecords(personToAddRecord.getRecords()); records.add(FEVER); - Person personWithAddedRecord = new PersonBuilder(personToAddRecord).withRecords(records).buildWithRecord(); + Person personWithAddedRecord = new PersonBuilder(personToAddRecord).withRecords(records).build(); AddRecordCommand addRecordCommand = new AddRecordCommand(INDEX_THIRD_PERSON, FEVER); - String expectedMessage = AddRecordCommand.MESSAGE_SUCCESS; + String expectedMessage = String.format(AddRecordCommand.MESSAGE_SUCCESS, + Messages.format(FEVER, personWithAddedRecord)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(model.getFilteredPersonList().get(2), personWithAddedRecord); @@ -62,15 +60,14 @@ public void execute_validIndexFilteredList_success() { Person personToAddRecord = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); UniqueRecordList records = new UniqueRecordList(); - for (Record record : personToAddRecord.getRecords()) { - records.add(record); - } + records.setRecords(personToAddRecord.getRecords()); records.add(FEVER); - Person personWithAddedRecord = new PersonBuilder(personToAddRecord).withRecords(records).buildWithRecord(); + Person personWithAddedRecord = new PersonBuilder(personToAddRecord).withRecords(records).build(); AddRecordCommand addRecordCommand = new AddRecordCommand(INDEX_FIRST_PERSON, FEVER); - String expectedMessage = AddRecordCommand.MESSAGE_SUCCESS; + String expectedMessage = String.format(AddRecordCommand.MESSAGE_SUCCESS, + Messages.format(FEVER, personWithAddedRecord)); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); showPersonAtIndex(expectedModel, INDEX_FIRST_PERSON); diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 612d606de34..f67c8e5f7e1 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -20,11 +20,11 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.AddressBook; import seedu.address.model.Model; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.shared.DateTime; import seedu.address.model.person.Name; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.DateTime; import seedu.address.testutil.EditPersonDescriptorBuilder; /** diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 5c2524944d1..d730173b07d 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -39,8 +39,8 @@ public class EditCommandTest { @Test public void execute_allFieldsSpecifiedUnfilteredList_success() { Person personToEdit = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); - Person editedPerson = new PersonBuilder().withIsPinned(personToEdit.isPinned()) - .withAppointments(personToEdit.getAppointments()).build(); + Person editedPerson = new PersonBuilder().withRecords(personToEdit.getRecords()) + .withAppointments(personToEdit.getAppointments()).withIsPinned(personToEdit.isPinned()).build(); EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build(); EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor); diff --git a/src/test/java/seedu/address/logic/parser/AddAppointmentCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddAppointmentCommandParserTest.java index 96521e47dfc..7c6c0dbba1c 100644 --- a/src/test/java/seedu/address/logic/parser/AddAppointmentCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddAppointmentCommandParserTest.java @@ -15,9 +15,9 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.AddAppointmentCommand; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.shared.DateTime; import seedu.address.model.person.Name; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.DateTime; public class AddAppointmentCommandParserTest { diff --git a/src/test/java/seedu/address/logic/parser/AddRecordCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddRecordCommandParserTest.java index 10f59b7061a..7da22fc18c3 100644 --- a/src/test/java/seedu/address/logic/parser/AddRecordCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddRecordCommandParserTest.java @@ -15,7 +15,7 @@ public class AddRecordCommandParserTest { @Test public void parse_validArgs_returnsAddRecordCommand() { - assertParseSuccess(parser, "1 d/09102023 1800 c/Fever", + assertParseSuccess(parser, "1 d/09-10-2023 1800 c/Fever", new AddRecordCommand(INDEX_FIRST_PERSON, FEVER)); } @Test diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 8a0b63d9d28..abd90ce3de5 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -26,9 +26,9 @@ import seedu.address.logic.commands.PinCommand; import seedu.address.logic.commands.UnpinCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.appointment.Appointment; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; -import seedu.address.model.person.appointment.Appointment; import seedu.address.testutil.AppointmentBuilder; import seedu.address.testutil.AppointmentUtil; import seedu.address.testutil.EditPersonDescriptorBuilder; diff --git a/src/test/java/seedu/address/model/person/appointment/AppointmentTest.java b/src/test/java/seedu/address/model/appointment/AppointmentTest.java similarity index 96% rename from src/test/java/seedu/address/model/person/appointment/AppointmentTest.java rename to src/test/java/seedu/address/model/appointment/AppointmentTest.java index 0f6e50eff98..0cbef42cb4a 100644 --- a/src/test/java/seedu/address/model/person/appointment/AppointmentTest.java +++ b/src/test/java/seedu/address/model/appointment/AppointmentTest.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.appointment; +package seedu.address.model.appointment; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.model.appointment.Appointment; import seedu.address.testutil.AppointmentBuilder; public class AppointmentTest { diff --git a/src/test/java/seedu/address/model/person/appointment/DateTimeTest.java b/src/test/java/seedu/address/model/appointment/DateTimeTest.java similarity index 95% rename from src/test/java/seedu/address/model/person/appointment/DateTimeTest.java rename to src/test/java/seedu/address/model/appointment/DateTimeTest.java index f8cb56f6f82..ebade63cdeb 100644 --- a/src/test/java/seedu/address/model/person/appointment/DateTimeTest.java +++ b/src/test/java/seedu/address/model/appointment/DateTimeTest.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.appointment; +package seedu.address.model.appointment; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -6,11 +6,13 @@ import org.junit.jupiter.api.Test; +import seedu.address.model.shared.DateTime; + public class DateTimeTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new DateTime(null)); + assertThrows(NullPointerException.class, () -> new DateTime((String)null)); } @Test diff --git a/src/test/java/seedu/address/model/person/appointment/UniqueAppointmentListTest.java b/src/test/java/seedu/address/model/appointment/UniqueAppointmentListTest.java similarity index 94% rename from src/test/java/seedu/address/model/person/appointment/UniqueAppointmentListTest.java rename to src/test/java/seedu/address/model/appointment/UniqueAppointmentListTest.java index 123c1df96e3..35e7fe3ef7f 100644 --- a/src/test/java/seedu/address/model/person/appointment/UniqueAppointmentListTest.java +++ b/src/test/java/seedu/address/model/appointment/UniqueAppointmentListTest.java @@ -1,4 +1,4 @@ -package seedu.address.model.person.appointment; +package seedu.address.model.appointment; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -13,8 +13,10 @@ import org.junit.jupiter.api.Test; -import seedu.address.model.person.appointment.exceptions.AppointmentNotFoundException; -import seedu.address.model.person.appointment.exceptions.DuplicateAppointmentException; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.UniqueAppointmentList; +import seedu.address.model.appointment.exceptions.AppointmentNotFoundException; +import seedu.address.model.appointment.exceptions.DuplicateAppointmentException; public class UniqueAppointmentListTest { diff --git a/src/test/java/seedu/address/model/record/DateTimeTest.java b/src/test/java/seedu/address/model/record/DateTimeTest.java index ef239701a05..9cf8931656b 100644 --- a/src/test/java/seedu/address/model/record/DateTimeTest.java +++ b/src/test/java/seedu/address/model/record/DateTimeTest.java @@ -4,18 +4,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.testutil.Assert.assertThrows; -import java.time.LocalDateTime; - import org.junit.jupiter.api.Test; -import seedu.address.model.person.shared.DateTime; +import seedu.address.model.shared.DateTime; public class DateTimeTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new DateTime((String) null)); - assertThrows(NullPointerException.class, () -> new DateTime((LocalDateTime) null)); + assertThrows(NullPointerException.class, () -> new DateTime(null)); } @Test public void constructor_invalidDateTime_throwsIllegalArgumentException() { @@ -24,7 +21,7 @@ public void constructor_invalidDateTime_throwsIllegalArgumentException() { } @Test public void isValidDateTime_success() { - String validDateTime = "09092023 1800"; + String validDateTime = "09-09-2023 1800"; assertTrue(DateTime.isValidDateTime(validDateTime)); } @Test diff --git a/src/test/java/seedu/address/model/record/RecordTest.java b/src/test/java/seedu/address/model/record/RecordTest.java index 783a2f5520b..ea8317c7ea3 100644 --- a/src/test/java/seedu/address/model/record/RecordTest.java +++ b/src/test/java/seedu/address/model/record/RecordTest.java @@ -8,13 +8,13 @@ import org.junit.jupiter.api.Test; -import seedu.address.model.person.shared.DateTime; +import seedu.address.model.shared.DateTime; public class RecordTest { @Test public void constructor_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new Record(null, null)); - assertThrows(NullPointerException.class, () -> new Record(new DateTime("09102023 1800"), null)); + assertThrows(NullPointerException.class, () -> new Record(new DateTime("09-10-2023 1800"), null)); List validConditions = new ArrayList<>(Arrays.asList(new Condition("Fever"), new Condition("Cold"))); assertThrows(NullPointerException.class, () -> new Record(null, validConditions)); } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedAppointmentTest.java b/src/test/java/seedu/address/storage/JsonAdaptedAppointmentTest.java index ec4b3d1dc19..5a97d18a8ec 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedAppointmentTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedAppointmentTest.java @@ -8,8 +8,8 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.shared.DateTime; import seedu.address.model.person.Name; -import seedu.address.model.person.appointment.DateTime; public class JsonAdaptedAppointmentTest { private static final String INVALID_NAME = "Sl@@p Study"; diff --git a/src/test/java/seedu/address/storage/JsonAdaptedRecordTest.java b/src/test/java/seedu/address/storage/JsonAdaptedRecordTest.java index 3f6baf9fbc2..84ab90ef74a 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedRecordTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedRecordTest.java @@ -5,7 +5,6 @@ import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalRecords.FEVER; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -13,12 +12,12 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.shared.DateTime; import seedu.address.model.record.Condition; +import seedu.address.model.shared.DateTime; public class JsonAdaptedRecordTest { - private static final LocalDateTime VALID_DATETIME = FEVER.getDateTime().dateTime; + private static final String VALID_DATETIME = FEVER.getDateTime().toString(); private static final List VALID_CONDITIONS = FEVER.getConditions() .stream() diff --git a/src/test/java/seedu/address/testutil/AppointmentBuilder.java b/src/test/java/seedu/address/testutil/AppointmentBuilder.java index 2f5898d300f..fe2e32d00af 100644 --- a/src/test/java/seedu/address/testutil/AppointmentBuilder.java +++ b/src/test/java/seedu/address/testutil/AppointmentBuilder.java @@ -1,8 +1,8 @@ package seedu.address.testutil; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.shared.DateTime; import seedu.address.model.person.Name; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.DateTime; /** * A utility class to help with building Appointment objects. diff --git a/src/test/java/seedu/address/testutil/AppointmentUtil.java b/src/test/java/seedu/address/testutil/AppointmentUtil.java index b1d758adfa8..abae5a03d11 100644 --- a/src/test/java/seedu/address/testutil/AppointmentUtil.java +++ b/src/test/java/seedu/address/testutil/AppointmentUtil.java @@ -4,7 +4,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import seedu.address.logic.commands.AddAppointmentCommand; -import seedu.address.model.person.appointment.Appointment; +import seedu.address.model.appointment.Appointment; /** * A utility class for Appointment. */ diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index db59124d707..6a3fa0baebe 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -3,6 +3,8 @@ import java.util.HashSet; import java.util.Set; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.UniqueAppointmentList; import seedu.address.model.person.Age; import seedu.address.model.person.Allergy; import seedu.address.model.person.BloodType; @@ -11,8 +13,6 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.UniqueAppointmentList; import seedu.address.model.record.Record; import seedu.address.model.record.UniqueRecordList; import seedu.address.model.util.SampleDataUtil; @@ -38,8 +38,8 @@ public class PersonBuilder { private BloodType bloodType; private Set allergies; private UniqueRecordList records; - private boolean isPinned; private UniqueAppointmentList appointments; + private boolean isPinned; /** * Creates a {@code PersonBuilder} with the default details. @@ -53,8 +53,8 @@ public PersonBuilder() { bloodType = new BloodType(DEFAULT_BLOODTYPE); allergies = new HashSet<>(); records = new UniqueRecordList(); - isPinned = false; appointments = new UniqueAppointmentList(); + isPinned = false; } /** @@ -70,8 +70,9 @@ public PersonBuilder(Person personToCopy) { allergies = new HashSet<>(personToCopy.getAllergies()); records = new UniqueRecordList(); records.setRecords(personToCopy.getRecords()); + appointments = new UniqueAppointmentList(); + appointments.setAppointments(personToCopy.getAppointments());; isPinned = personToCopy.isPinned(); - appointments = personToCopy.getAppointments(); } /** @@ -171,11 +172,6 @@ public PersonBuilder withAppointments(Appointment ... appointments) { } public Person build() { - return new Person(name, email, phone, gender, age, bloodType, allergies, isPinned); - } - - public Person buildWithRecord() { - return new Person(name, email, phone, gender, age, bloodType, allergies, records, isPinned); + return new Person(name, email, phone, gender, age, bloodType, allergies, records, appointments, isPinned); } - } diff --git a/src/test/java/seedu/address/testutil/RecordBuilder.java b/src/test/java/seedu/address/testutil/RecordBuilder.java index dabcfa7168a..252a764b1e3 100644 --- a/src/test/java/seedu/address/testutil/RecordBuilder.java +++ b/src/test/java/seedu/address/testutil/RecordBuilder.java @@ -3,9 +3,9 @@ import java.util.ArrayList; import java.util.List; -import seedu.address.model.person.shared.DateTime; import seedu.address.model.record.Condition; import seedu.address.model.record.Record; +import seedu.address.model.shared.DateTime; import seedu.address.model.util.SampleDataUtil; /** @@ -22,7 +22,7 @@ public class RecordBuilder { */ public RecordBuilder() { conditions = new ArrayList<>(); - dateTime = new DateTime("09102023 1800"); + dateTime = new DateTime("09-10-2023 1800"); } /** diff --git a/src/test/java/seedu/address/testutil/TypicalAppointments.java b/src/test/java/seedu/address/testutil/TypicalAppointments.java index 459cf947dc7..dfbbc0fcc4f 100644 --- a/src/test/java/seedu/address/testutil/TypicalAppointments.java +++ b/src/test/java/seedu/address/testutil/TypicalAppointments.java @@ -5,8 +5,8 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_SLEEP_STUDY; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_THYROID_CHECK; -import seedu.address.model.person.appointment.Appointment; -import seedu.address.model.person.appointment.UniqueAppointmentList; +import seedu.address.model.appointment.Appointment; +import seedu.address.model.appointment.UniqueAppointmentList; /** * A utility class containing a list of {@code Appointment} objects to be used in tests. */ diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index 3f214027112..5f1d76683d0 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -20,7 +20,6 @@ import static seedu.address.testutil.TypicalRecords.ALLERGIC_REACTION; import static seedu.address.testutil.TypicalRecords.FEVER_AND_COLD; import static seedu.address.testutil.TypicalRecords.HEADACHE; -import static seedu.address.testutil.TypicalRecords.SORE_THROAT_AND_COLD; import static seedu.address.testutil.TypicalRecords.STOMACHACHE; import java.util.ArrayList; @@ -43,14 +42,14 @@ public class TypicalPersons { .withBloodType("AB+") .withAllergies("Chocolate") .withRecords(FEVER_AND_COLD, ALLERGIC_REACTION) - .withAppointments(EYE_EXAM). - .withIsPinned(true)build(); + .withAppointments(EYE_EXAM) + .withIsPinned(true).build(); public static final Person BENSON = new PersonBuilder().withName("Benson Meier") .withEmail("johnd@example.com") .withPhone("98765432") .withGender("M") .withAge(15) - .withBloodType("B-") + .withBloodType("B-") .withAllergies("Pollen", "Soil") .withRecords(HEADACHE, ALLERGIC_REACTION) .withAppointments(VACCINATION) @@ -74,7 +73,6 @@ public class TypicalPersons { .withAge(26) .withBloodType("AB+") .withAllergies("Cats") - .withRecords(SORE_THROAT_AND_COLD) .withIsPinned(false).build(); public static final Person ELLE = new PersonBuilder().withName("Elle Meyer") .withPhone("9482224") @@ -82,16 +80,14 @@ public class TypicalPersons { .withGender("F") .withAge(27) .withBloodType("A-") - .withRecords(HEADACHE) .withAllergies("Light") - withIsPinned(false).build(); + .withIsPinned(false).build(); public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz") .withEmail("lydia@example.com") .withPhone("9482427") .withGender("F") .withAge(29) .withBloodType("B+") - .withRecords(HEADACHE) .withIsPinned(false).build(); public static final Person GEORGE = new PersonBuilder().withName("George Best") .withEmail("anna@example.com") @@ -99,7 +95,6 @@ public class TypicalPersons { .withGender("M") .withAge(30) .withBloodType("O+") - .withRecords(HEADACHE) .withIsPinned(false).build(); // Manually added @@ -128,7 +123,6 @@ public class TypicalPersons { .withAge(VALID_AGE_AMY) .withBloodType(VALID_BLOODTYPE_AMY) .withAllergies(VALID_ALLERGY_DUST) - .withRecords(HEADACHE) .build(); public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB) .withEmail(VALID_EMAIL_BOB) @@ -137,7 +131,6 @@ public class TypicalPersons { .withAge(VALID_AGE_BOB) .withBloodType(VALID_BLOODTYPE_BOB) .withAllergies(VALID_ALLERGY_DUST, VALID_ALLERGY_PEANUTS) - .withRecords(HEADACHE) .build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER diff --git a/src/test/java/seedu/address/testutil/TypicalRecords.java b/src/test/java/seedu/address/testutil/TypicalRecords.java index e5a0f2f8055..35e9c8b9436 100644 --- a/src/test/java/seedu/address/testutil/TypicalRecords.java +++ b/src/test/java/seedu/address/testutil/TypicalRecords.java @@ -7,32 +7,32 @@ */ public class TypicalRecords { public static final Record FEVER = new RecordBuilder() - .withDateTime("09102023 1800") + .withDateTime("09-10-2023 1800") .withConditions("Fever") .build(); public static final Record FEVER_AND_COLD = new RecordBuilder() - .withDateTime("09092023 1800") + .withDateTime("09-09-2023 1800") .withConditions("Fever", "Cold") .build(); public static final Record ALLERGIC_REACTION = new RecordBuilder() - .withDateTime("23102022 1130") + .withDateTime("23-10-2022 1130") .withConditions("Allergic Reaction") .build(); public static final Record HEADACHE = new RecordBuilder() - .withDateTime("24012023 1200") + .withDateTime("24-12-2023 1200") .withConditions("Headache") .build(); public static final Record STOMACHACHE = new RecordBuilder() - .withDateTime("20032023 1500") + .withDateTime("20-03-2023 1500") .withConditions("Stomachache") .build(); public static final Record SORE_THROAT_AND_COLD = new RecordBuilder() - .withDateTime("25042023 1000") + .withDateTime("25-04-2023 1000") .withConditions("Sore throat", "Cold") .build(); }