Skip to content

Commit

Permalink
Merge pull request #63 from erv-teo/branch-remarks
Browse files Browse the repository at this point in the history
Add remark feature
  • Loading branch information
iamtr authored Apr 2, 2024
2 parents 937f541 + 063f62a commit bc449a8
Show file tree
Hide file tree
Showing 30 changed files with 607 additions and 64 deletions.
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public static String format(Person person) {
.append(person.getWard())
.append("\n Admitted: ")
.append(person.getAdmissionDate())
.append("\n Remarks: ")
.append(person.getRemark())
.append("\n Tags: ");
person.getTags().forEach(builder::append);
return builder.toString();
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WARD;

Expand All @@ -21,20 +22,22 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. \n"
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_IC + "IC "
+ PREFIX_DOB + "DOB "
+ PREFIX_ADMISSION_DATE + "ADMISSION DATE "
+ PREFIX_WARD + "WARD NUMBER "
+ PREFIX_ADMISSION_DATE + "ADMISSION_DATE "
+ PREFIX_WARD + "WARD_NUMBER "
+ "[" + PREFIX_REMARK + "REMARK] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_IC + "S0123456A "
+ PREFIX_DOB + "1/1/2000 "
+ PREFIX_ADMISSION_DATE + "15/03/2024 "
+ PREFIX_WARD + "3 "
+ PREFIX_REMARK + "Prevent bed sores. "
+ PREFIX_TAG + "FallRisk";

public static final String MESSAGE_SUCCESS = "New patient added: %1$s";
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WARD;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
Expand All @@ -29,6 +30,7 @@
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Remark;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

Expand All @@ -49,6 +51,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_WARD + "WARD] "
+ "[" + PREFIX_ADMISSION_DATE + "ADMISSION DATE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_REMARK + "REMARK]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_IC + "T1234567Q "
+ PREFIX_DOB + "12/08/1999";
Expand Down Expand Up @@ -115,8 +118,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
AdmissionDate updatedAdmissionDate =
editPersonDescriptor.getAdmissionDate().orElse(personToEdit.getAdmissionDate());
Ward updatedWard = editPersonDescriptor.getWard().orElse(personToEdit.getWard());
Remark updatedRemark = editPersonDescriptor.getRemark().orElse(personToEdit.getRemark());

return new Person(updatedName, updatedTags, updatedDob, updatedIc, updatedAdmissionDate, updatedWard);
return new Person(updatedName, updatedTags, updatedDob, updatedIc, updatedAdmissionDate,
updatedWard, updatedRemark);
}

@Override
Expand Down Expand Up @@ -154,7 +159,7 @@ public static class EditPersonDescriptor {
private Dob dob;
private AdmissionDate admissionDate;
private Ward ward;

private Remark remark;
public EditPersonDescriptor() {}

/**
Expand All @@ -168,6 +173,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setIc(toCopy.ic);
setAdmissionDate(toCopy.admissionDate);
setWard(toCopy.ward);
setRemark(toCopy.remark);
}

/**
Expand Down Expand Up @@ -225,6 +231,12 @@ public void setWard(Ward ward) {
public Optional<Ward> getWard() {
return Optional.ofNullable(ward);
}
public void setRemark(Remark remark) {
this.remark = remark;
}
public Optional<Remark> getRemark() {
return Optional.ofNullable(remark);
}
@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -242,19 +254,21 @@ public boolean equals(Object other) {
&& Objects.equals(ic, otherEditPersonDescriptor.ic)
&& Objects.equals(dob, otherEditPersonDescriptor.dob)
&& Objects.equals(admissionDate, otherEditPersonDescriptor.admissionDate)
&& Objects.equals(ward, otherEditPersonDescriptor.ward);
&& Objects.equals(ward, otherEditPersonDescriptor.ward)
&& Objects.equals(remark, otherEditPersonDescriptor.remark);

}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("name", name)
.add("tags", tags)
.add("ic", ic)
.add("dob", dob)
.add("ic", ic)
.add("tags", tags)
.add("admissionDate", admissionDate)
.add("ward", ward)
.add("remark", remark)
.toString();
}
}
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/seedu/address/logic/commands/RemarkCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package seedu.address.logic.commands;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.List;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.person.Remark;



/**
* Changes the remark of an existing person in the address book.
*/
public class RemarkCommand extends Command {
public static final String COMMAND_WORD = "remark";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Edits the remark of the person identified "
+ "by the index number used in the last person listing. "
+ "Existing remark will be overwritten by the input.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "r\\[REMARK]\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ "r\\Likes to swim.";

public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s";
public static final String MESSAGE_ADD_REMARK_SUCCESS = "Added remark to Patient: %1$s";
public static final String MESSAGE_DELETE_REMARK_SUCCESS = "Removed remark from Patient: %1$s";

private final Index index;
private final Remark remark;

/**
* @param index of the person in the filtered person list to edit the remark
* @param remark of the person to be updated to
*/
public RemarkCommand(Index index, Remark remark) {
requireAllNonNull(index, remark);

this.index = index;
this.remark = remark;
}

@Override
public CommandResult execute(Model model) throws CommandException {
List<Person> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = new Person(
personToEdit.getName(), personToEdit.getTags(), personToEdit.getDob(),
personToEdit.getIc(), personToEdit.getAdmissionDate(), personToEdit.getWard(),
remark);

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

return new CommandResult(generateSuccessMessage(editedPerson));
}

/**
* Generates a command execution success message based on whether
* the remark is added to or removed from
* {@code personToEdit}.
*/
private String generateSuccessMessage(Person personToEdit) {
String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS;
return String.format(message, Messages.format(personToEdit));
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof RemarkCommand)) {
return false;
}

RemarkCommand e = (RemarkCommand) other;
return index.equals(e.index)
&& remark.equals(e.remark);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WARD;

Expand All @@ -21,6 +22,7 @@
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Remark;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

Expand All @@ -37,7 +39,7 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TAG,
PREFIX_DOB, PREFIX_IC, PREFIX_ADMISSION_DATE, PREFIX_WARD);
PREFIX_DOB, PREFIX_IC, PREFIX_ADMISSION_DATE, PREFIX_WARD, PREFIX_REMARK);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME,
PREFIX_DOB, PREFIX_IC, PREFIX_ADMISSION_DATE, PREFIX_WARD)
Expand All @@ -53,6 +55,8 @@ public AddCommand parse(String args) throws ParseException {
AdmissionDate admissionDate =
ParserUtil.parseAdmissionDate(argMultimap.getValue(PREFIX_ADMISSION_DATE).orElse(null));
Ward ward = ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).orElse(null));
Remark remark = ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).orElse(null));


DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate dobDate = LocalDate.parse(dob.value, formatter);
Expand All @@ -61,7 +65,7 @@ public AddCommand parse(String args) throws ParseException {
throw new ParseException(MESSAGE_DOB_LATER_THAN_ADMISSION);
}

Person person = new Person(name, tagList, dob, ic, admissionDate, ward);
Person person = new Person(name, tagList, dob, ic, admissionDate, ward, remark);

return new AddCommand(person);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -76,6 +77,8 @@ public Command parseCommand(String userInput) throws ParseException {

case HelpCommand.COMMAND_WORD:
return new HelpCommand();
case RemarkCommand.COMMAND_WORD:
return new RemarkCommandParser().parse(arguments);

default:
logger.finer("This user input caused a ParseException: " + userInput);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class CliSyntax {
public static final Prefix PREFIX_WARD = new Prefix("w\\");
public static final Prefix PREFIX_IC = new Prefix("ic\\");
public static final Prefix PREFIX_ADMISSION_DATE = new Prefix("ad\\");
public static final Prefix PREFIX_REMARK = new Prefix("r\\");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WARD;

Expand Down Expand Up @@ -34,7 +35,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DOB, PREFIX_WARD, PREFIX_IC,
PREFIX_ADMISSION_DATE, PREFIX_TAG);
PREFIX_ADMISSION_DATE, PREFIX_TAG, PREFIX_REMARK);

Index index;

Expand Down Expand Up @@ -67,6 +68,10 @@ public EditCommand parse(String args) throws ParseException {
editPersonDescriptor.setWard(ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).get()));
}

if (argMultimap.getValue(PREFIX_REMARK).isPresent()) {
editPersonDescriptor.setRemark(ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get()));
}

if (!editPersonDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.model.person.Dob;
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Remark;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -152,4 +153,17 @@ public static Ward parseWard(String ward) throws ParseException {
return new Ward(trimmedWard);
}

/**
* Parses a {@code String remark} into a {@code Remark}.
* Leading and trailing whitespaces will be trimmed.
*/
public static Remark parseRemark(String remark) throws ParseException {
if (remark == null) {
return new Remark("");
} else {
String trimmedRemark = remark.trim();
return new Remark(trimmedRemark);
}
}

}
45 changes: 45 additions & 0 deletions src/main/java/seedu/address/logic/parser/RemarkCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Remark;



/**
* Parses input arguments and creates a new RemarkCommand object
*/
public class RemarkCommandParser implements Parser<RemarkCommand> {

/**
* Parses the given {@code String} of arguments in the context of the RemarkCommand
* and returns an RemarkCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
@Override
public RemarkCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args,
PREFIX_REMARK);

Index index;
try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
RemarkCommand.MESSAGE_USAGE), ive);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_REMARK);

Remark remark = new Remark(argMultimap.getValue(PREFIX_REMARK).orElse(""));

return new RemarkCommand(index, remark);
}
}
Loading

0 comments on commit bc449a8

Please sign in to comment.