Skip to content

Commit

Permalink
Modify records to fit with appointments
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren159 committed Oct 20, 2023
1 parent 227e6f8 commit 291d956
Show file tree
Hide file tree
Showing 44 changed files with 211 additions and 174 deletions.
33 changes: 24 additions & 9 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,17 +18,15 @@ 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.
*/
public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePrefixes) {
assert duplicatePrefixes.length > 0;

Set<String> duplicateFields =
Stream.of(duplicatePrefixes).map(Prefix::toString).collect(Collectors.toSet());
Set<String> duplicateFields = Stream.of(duplicatePrefixes).map(Prefix::toString).collect(Collectors.toSet());

return MESSAGE_DUPLICATE_FIELDS + String.join(" ", duplicateFields);
}
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)));
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/seedu/address/logic/commands/AddRecordCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;


/**
Expand Down Expand Up @@ -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<Allergy> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -56,7 +57,7 @@ public AddCommand parse(String args) throws ParseException {
Set<Allergy> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
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;
import seedu.address.model.person.Email;
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.
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package seedu.address.model.person.appointment;
package seedu.address.model.appointment;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Objects;

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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/address/model/record/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public int hashCode() {

@Override
public String toString() {
return "[" + condition + "]";
return condition;
}


}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/record/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -74,6 +64,4 @@ public int hashCode() {
public String toString() {
return dateTime.format(FORMATTER);
}


}
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -31,22 +31,22 @@ public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Email("[email protected]"), 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("[email protected]"), 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("[email protected]"), 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("[email protected]"), 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("[email protected]"), 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("[email protected]"), new Phone("92624417"),
new Gender("M"), new Age(24), new BloodType("B+"),
getAllergySet("Grass"), false, new UniqueAppointmentList()),
getAllergySet("Grass"), new UniqueRecordList(), new UniqueAppointmentList(), false),
};
}

Expand Down
Loading

0 comments on commit 291d956

Please sign in to comment.