Skip to content

Commit

Permalink
Merge pull request #95 from CS2113-AY1819S1-T12-2/v1.3
Browse files Browse the repository at this point in the history
mid V1.3
  • Loading branch information
brandonccm1996 authored Oct 24, 2018
2 parents 570fa12 + 54db364 commit 3845184
Show file tree
Hide file tree
Showing 90 changed files with 1,324 additions and 394 deletions.
61 changes: 56 additions & 5 deletions src/main/java/seedu/address/logic/commands/AddApptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_APPT_VENUE;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.HashSet;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
Expand All @@ -19,7 +20,9 @@
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.timetable.Appt;
import seedu.address.model.timetable.ApptComparator;

//@@author brandonccm1996
/**
* Adds an appointment to a person's timetable.
*/
Expand All @@ -36,13 +39,15 @@ 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";

public static final String MESSAGE_ADD_APPT_SUCCESS = "Added appt to Person: %1$s";
public static final String MESSAGE_APPT_CLASH = "The appt you are adding clashes with the timing of another appt";
public static final String MESSAGE_INVALID_TIME = "The end time of an appt must be after the start time";
public static final String MESSAGE_DELETE_APPT_SUCCESS = "Removed appt from Person: %1$s";

private final Index index;
Expand All @@ -68,14 +73,26 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

Person personToEdit = lastShownList.get(index.getZeroBased());
Set<Appt> oldAppts = personToEdit.getAppts();
Set<Appt> newAppts = new HashSet<>();

if (hasInvalidTiming(appt)) {
throw new CommandException(MESSAGE_INVALID_TIME);
}

for (Appt oldAppt : oldAppts) {
if (hasApptClash(oldAppt, appt)) {
throw new CommandException(MESSAGE_APPT_CLASH);
}
}

Set<Appt> newAppts = new TreeSet<>(new ApptComparator());
for (Appt appt : oldAppts) {
newAppts.add(appt);
}
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);
Expand All @@ -92,6 +109,40 @@ private String generateSuccessMessage(Person personToEdit) {
return String.format(MESSAGE_ADD_APPT_SUCCESS, personToEdit);
}

/**
* Checks if an appt has end time before or equal to start time
*/
private boolean hasInvalidTiming(Appt appt) {
LocalDateTime start = appt.getStart().value;
LocalDateTime end = appt.getEnd().value;

if (!end.isAfter(start)) {
return true;
}
return false;
}

/**
* Checks if appt1 and appt2 have timings which clash
*/
private boolean hasApptClash(Appt appt1, Appt appt2) {
LocalDateTime start1 = appt1.getStart().value;
LocalDateTime end1 = appt1.getEnd().value;
LocalDateTime start2 = appt2.getStart().value;
LocalDateTime end2 = appt2.getEnd().value;

// Example:
// if appt1 is from 1600-1700, appt2 cannot start between 1600-1759, and cannot end between 1601-1800
// if appt2 is from 1600-1700, appt1 cannot start between 1600-1759, and cannot end between 1601-1800
if (((start1.isEqual(start2) || start1.isAfter(start2)) && start1.isBefore(end2))
|| ((start2.isEqual(start1) || start2.isAfter(start1)) && start2.isBefore(end1))
|| (end1.isAfter(start2) && (end1.isBefore(end2) || end1.isEqual(end2)))
|| (end2.isAfter(start1) && (end2.isBefore(end1) || end2.isEqual(end1)))) {
return true;
}
return false;
}

@Override
public boolean equals(Object other) {
// short circuit if same object
Expand Down
45 changes: 36 additions & 9 deletions src/main/java/seedu/address/logic/commands/AddHistCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.medhistory.MedHistory;
import seedu.address.model.medicalreport.MedicalReport;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
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;

/**
* Adds/Edits medical history of a patient in the Health Book.
Expand All @@ -34,6 +45,7 @@ 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;
Expand All @@ -44,7 +56,7 @@ public class AddHistCommand extends Command {
public AddHistCommand(Index index, MedHistory medHistory) {
requireAllNonNull(index, medHistory);
this.index = index;
this.medHistory = medHistory;
this.medHistory = new MedHistory(medHistory);
}

@Override
Expand All @@ -62,21 +74,36 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}
// 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());
Person editedPerson = createEditedPerson(personToEdit, newMedHistories);
model.updatePerson(personToEdit, editedPerson);
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, Set <MedHistory> newMedHistories) {
assert personToEdit != null;

Name name = personToEdit.getName();
Phone phone = personToEdit.getPhone();
Email email = personToEdit.getEmail();
Address address = personToEdit.getAddress();
Set<Appt> appts = personToEdit.getAppts();
Set<MedicalReport> medicalReports = personToEdit.getMedicalReports();
Set<MedHistory> medHistories = newMedHistories;
Set<Tag> tags = personToEdit.getTags();

Nric nric = personToEdit.getNric();
DateOfBirth dateOfBirth = personToEdit.getDateOfBirth();
Height height = personToEdit.getHeight();
Weight weight = personToEdit.getWeight();

return new Person(name, phone, email, address, medicalReports, medHistories, appts,
nric, dateOfBirth, height, weight, tags);
}

@Override
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/seedu/address/logic/commands/AddInfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
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.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.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;

Expand All @@ -41,7 +43,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;
Expand Down Expand Up @@ -96,9 +97,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
Expand Down Expand Up @@ -126,16 +129,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) {
Expand All @@ -154,6 +161,22 @@ public Optional<DateOfBirth> getDateOfBirth() {
return Optional.ofNullable(dateOfBirth);
}

public void setHeight(Height height) {
this.height = height;
}

public Optional<Height> getHeight() {
return Optional.ofNullable(height);
}

public void setWeight(Weight weight) {
this.weight = weight;
}

public Optional<Weight> getWeight() {
return Optional.ofNullable(weight);
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.model.medicalreport.MedicalReport;
import seedu.address.model.person.Person;

//@@author chewkahmeng
/**
* Adds a medical report to a person.
*/
Expand All @@ -33,8 +34,8 @@ public class AddMedicalReportCommand extends Command {
+ PREFIX_INFORMATION + "[INFORMATION]\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_TITLE + "Asthma "
+ PREFIX_DATE + "01/01/2018 "
+ PREFIX_INFORMATION + "prescribed XXX medicine, next appointment on 02/02/2018. ";
+ PREFIX_DATE + "01-01-2018 "
+ PREFIX_INFORMATION + "prescribed XXX medicine, next appointment on 02-02-2018. ";

public static final String MESSAGE_ADD_REPORT_SUCCESS = "Added medical report to Person: %1$s";

Expand Down Expand Up @@ -70,7 +71,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);
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
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.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.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;

Expand Down Expand Up @@ -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<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

Nric nric = personToEdit.getNric();
DateOfBirth dateOfBirth = personToEdit.getDateOfBirth();
Height height = personToEdit.getHeight();
Weight weight = personToEdit.getWeight();

Set<MedicalReport> updatedReports = personToEdit.getMedicalReports(); // edit command disallow editing reports
Set<MedHistory> updatedMedHistory = personToEdit.getMedHistory(); // edit command does not edit MedHistory now
Set<Appt> updatedAppts = personToEdit.getAppts(); // edit command does not allow editing appts
Nric updatedNric = personToEdit.getNric();
DateOfBirth updatedDateOfBirth = personToEdit.getDateOfBirth();
Set<Tag> 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
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public class FindCommand extends Command {

public static final String COMMAND_WORD = "find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose PREFIX contain any "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose prefix contain any "
+ "of the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: PREFIX KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " n/ " + " alice" + " or " + "p/ " + "91234567.";
+ "Parameters: PREFIX/ KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " n/ " + "aliCe Bernard" + "\t" + COMMAND_WORD + " p/ " + "91234567\n"
+ "Personal prefixes:\t n/ (Name)\t p/ (Phone)\t e/ (Email)\t\t\t a/ (Address)\t\t t/ (tag)\t ic/ (NRIC)\n"
+ "Medical prefixes:\t i/ (MedInfo)\t hsa/ (Allergy)\t hsb/ (BloodType)\t hsc/ (LastCountry)";

private final Predicate<Person> predicate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import seedu.address.model.timetable.ApptInfo;
import seedu.address.model.timetable.ApptVenue;

//@@author brandonccm1996
/**
* Parses input arguments and creates a new {@code AddApptCommand} object
*/
Expand Down
Loading

0 comments on commit 3845184

Please sign in to comment.