Skip to content

Commit

Permalink
Merge pull request #79 from CraveToCode/branch-nokUpdates-v1.2-c2c
Browse files Browse the repository at this point in the history
Update `Nok` implementation and add `deleteNok` Command
  • Loading branch information
tsy24 authored Oct 13, 2021
2 parents a10d85d + c7f4809 commit 3c116c1
Show file tree
Hide file tree
Showing 29 changed files with 618 additions and 214 deletions.
29 changes: 22 additions & 7 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,22 @@ Format: `viewElderly`

Adds an elderly to NurseyBook.

Format: `addElderly en/ELDERLY_NAME p/PHONE_NUMBER a/AGE g/GENDER r/ROOMNO [t/TAG]…​`
Format: `addElderly en/ELDERLY_NAME a/AGE g/GENDER r/ROOMNO [t/TAG]…​ [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]`

:bulb: **Tip:**
A elderly can have any number of tags (including 0)

Examples:
* `addElderly en/Khong Guan p/91234567 a/80 g/M r/201`
* `addElderly en/John p/92345678 a/77 g/M r/420 t/diabetes`
* `addElderly en/Khong Guan a/80 g/M r/201 nn/Gong Kuan rs/Brother p/91234567 e/[email protected] addr/London Street 11`
* `addElderly en/John a/77 g/M r/420 t/diabetes`
* `addElderly en/John a/77 g/M r/420 t/diabetes nn/Timothy rs/Son`


### Edit an elderly's details: `editElderly`

Edit the details of a specific elderly.

Format: `editElderly INDEX [en/ELDERLY_NAME] [p/PHONE_NUMBER] [a/AGE] [g/GENDER] [r/ROOMNO] [t/TAG]…​`
Format: `editElderly INDEX [en/ELDERLY_NAME] [a/AGE] [g/GENDER] [r/ROOMNO] [t/TAG]…​ [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]`

* Any number of tags is acceptable (including 0).

Expand All @@ -105,7 +106,7 @@ Format: `viewDetails en/ELDERLY_NAME`

Deletes an elderly from NurseyBook.

Format: `deleteElderly INDEX`
Format: `deleteElderly INDEX`

* Deletes the elderly at the specified `INDEX`.
* The index refers to the index number shown in the displayed elderly list.
Expand All @@ -114,6 +115,19 @@ Format: `deleteElderly INDEX`
Examples:
* `viewElderly` followed by `delete 2` deletes the 2nd elderly in NurseyBook.

### Deleting an elderly's NoK details : `deleteNok`

Deletes an elderly's Next-of-Kin details from NurseyBook.

Format: `deleteNok INDEX`

* Deletes the NoK details of the elderly at the specified `INDEX`.
* The index refers to the index number shown in the displayed elderly list.
* The index **must be a positive integer** 1, 2, 3, …​

Examples:
* `viewElderly` followed by `deleteNok 2` deletes the NoK details of the 2nd elderly in NurseyBook.

### Add tags to elderly: `addTag`

Add one or more tags to a specific elderly.
Expand Down Expand Up @@ -242,13 +256,14 @@ _Details coming soon ..._

Action | Format, Examples
--------|------------------
**Add Elderly** | `addElderly en/ELDERLY_NAME p/PHONE_NUMBER a/AGE r/ROOMNO g/GENDER [t/TAG]…​` <br> e.g., `addElderly en/Khong Guan p/92345678 a/77 r/420 g/M t/diabetes`
**Add Elderly** | `addElderly en/ELDERLY_NAME a/AGE r/ROOMNO g/GENDER [t/TAG]…​ [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]` <br> e.g., `addElderly en/Khong Guan a/80 g/M r/201 nn/Gong Kuan rs/Brother p/91234567 e/[email protected] addr/London Street 11`
**Clear** | `clear`
**Delete Elderly** | `deleteElderly INDEX`<br> e.g., `deleteElderly 3`
**Delete NoK of Elderly** | `deleteNok INDEX`<br> e.g., `deleteNok 3`
**Add Tag** | `addTag INDEX t/TAG [t/TAG]…​` e.g., `addTag 1 t/diabetes`
**Delete Tag** | `deleteTag INDEX t/TAG [t/TAG]…​`
**Filter** | `filter t/TAG [t/TAG]…​`
**Edit Elderly** | `editElderly INDEX [en/ELDERLY_NAME] [p/PHONE_NUMBER] [a/AGE][r/ROOMNO] [g/GENDER] [t/TAG]…​` <br> e.g., `editElderly en/John p/92345678 a/77 r/420 g/M t/diabetes`
**Edit Elderly** | `editElderly INDEX [en/ELDERLY_NAME] [a/AGE] [g/GENDER] [r/ROOMNO] [t/TAG]…​ [nn/NOK_NAME] [rs/NOK_RELATIONSHIP] [p/NOK_PHONE_NUMBER] [e/NOK_EMAIL] [addr/NOK_ADDRESS]`
**View Elderly Details** | `viewDetails en/ELDERLY_NAME`<br> e.g., `viewDetails en/James`
**Remind** | `remind`
**Add task** | `addTask [en/ELDERLY_NAME] desc/DESCRIPTION date/DATE time/TIME` <br> e.g., `addTask en/John desc/check insulin level date/2021-09-25 time/10.00am`
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class AddCommand extends Command {
+ PREFIX_GENDER + "GENDER "
+ PREFIX_ROOM_NUM + "ROOM_NUMBER "
+ "[" + PREFIX_NOK_NAME + "NOK_NAME] "
+ "[" + PREFIX_RELATIONSHIP + "RELATIONSHIP] "
+ "[" + PREFIX_PHONE + "NOK_PHONE] "
+ "[" + PREFIX_RELATIONSHIP + "NOK_RELATIONSHIP] "
+ "[" + PREFIX_PHONE + "NOK_PHONE_NUMBER] "
+ "[" + PREFIX_EMAIL + "NOK_EMAIL] "
+ "[" + PREFIX_ADDRESS + "NOK_ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]...\n"
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteNokCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ELDERLIES;

import java.util.List;

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

/**
* Deletes the NoK fields of an elderly identified using it's displayed index from the address book.
*/
public class DeleteNokCommand extends Command {

public static final String COMMAND_WORD = "deleteNok";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the NoK fields of an elderly identified by the index number used in the displayed "
+ "elderly list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_ELDERLY_NOK_SUCCESS = "Deleted NoK of Elderly: %1$s";

private final Index targetIndex;

public DeleteNokCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Elderly> lastShownList = model.getFilteredElderlyList();

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

Elderly elderlyToDeleteNokFrom = lastShownList.get(targetIndex.getZeroBased());
Elderly updatedElderly = new Elderly(
elderlyToDeleteNokFrom.getName(), elderlyToDeleteNokFrom.getAge(),
elderlyToDeleteNokFrom.getGender(), elderlyToDeleteNokFrom.getRoomNumber(), Nok.createDefaultNok(),
elderlyToDeleteNokFrom.getRemark(), elderlyToDeleteNokFrom.getTags());

model.setElderly(elderlyToDeleteNokFrom, updatedElderly);
model.updateFilteredElderlyList(PREDICATE_SHOW_ALL_ELDERLIES);
return new CommandResult(String.format(MESSAGE_DELETE_ELDERLY_NOK_SUCCESS, updatedElderly));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteNokCommand // instanceof handles nulls
&& targetIndex.equals(((DeleteNokCommand) other).targetIndex)); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public AddCommand parse(String args) throws ParseException {
.orElse(""));
Phone nokPhone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).orElse(""));
Email nokEmail = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).orElse(""));
Address nokAddress = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).orElse("NIL"));
Address nokAddress = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).orElse(""));
Remark remark = new Remark(""); // add command does not allow adding remarks straight away
RoomNumber roomNumber = ParserUtil.parseRoomNumber(argMultimap.getValue(PREFIX_ROOM_NUM).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.DeleteNokCommand;
import seedu.address.logic.commands.DeleteTagCommand;
import seedu.address.logic.commands.DeleteTaskCommand;
import seedu.address.logic.commands.DoneTaskCommand;
Expand Down Expand Up @@ -69,6 +70,9 @@ private Command createCommand(String commandWord, String arguments) throws Parse
case DeleteCommand.COMMAND_WORD:
return new DeleteCommandParser().parse(arguments);

case DeleteNokCommand.COMMAND_WORD:
return new DeleteNokCommandParser().parse(arguments);

case DeleteTaskCommand.COMMAND_WORD:
return new DeleteTaskCommandParser().parse(arguments);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.DeleteNokCommand;
import seedu.address.logic.parser.exceptions.ParseException;

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

/**
* Parses the given {@code String} of arguments in the context of the DeleteNokCommand
* and returns a DeleteNokCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public DeleteNokCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new DeleteNokCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteNokCommand.MESSAGE_USAGE), pe);
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Address {
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[^\\s].*";
public static final String VALIDATION_REGEX = "^$|[^\\s].*";

public final String value;

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/model/person/Elderly.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ public String toString() {
.append("; Age: ")
.append(getAge())
.append("; Gender: ")
.append(getAge())
.append(getGender())
.append("; RoomNumber: ")
.append(getRoomNumber())
.append("; Nok: ")
.append(getNok().getName())
.append(getNok().toString())
.append("; Remark: ")
.append(getRemark());

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/seedu/address/model/person/Nok.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Nok extends Person {
//Default values
private static final String defaultNameField = "NIL";
private static final String defaultNonNameField = "";

//Identity fields
private final Relationship relationship;
private final Phone phone;
Expand Down Expand Up @@ -49,6 +53,17 @@ public Address getAddress() {
return address;
}

/**
* Creates and returns a Nok with all fields set to default values. Equivalent to not specifying any fields in Nok.
*
* @return Nok with all fields set to default values.
*/
public static Nok createDefaultNok() {
Nok blankNok = new Nok(new Name(defaultNameField), new Relationship(defaultNonNameField),
new Phone(defaultNonNameField), new Email(defaultNonNameField), new Address(defaultNonNameField));
return blankNok;
}

/**
* Returns true if both NoKs have the same name.
* This defines a weaker notion of equality between two NoKs.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/person/Relationship.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
* Guarantees: immutable; is always valid
*/
public class Relationship {
public static final String MESSAGE_CONSTRAINTS = "Relationships can take any values";
public static final String MESSAGE_CONSTRAINTS = "Relationships cannot contain numbers, or can be left blank.";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
* Relationship does not accept numerical characters.
*/
public static final String VALIDATION_REGEX = "^$|[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "^$|[^\\s\\d][^\\s\\d]*";

public final String value;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/ElderlyListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
<Label fx:id="age" styleClass="cell_small_label" text="\$age" />
<Label fx:id="gender" styleClass="cell_small_label" text="\$gender" />
<Label fx:id="roomNumber" styleClass="cell_small_label" text="\$roomNumber" />
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark" />
<Label fx:id="nokName" styleClass="cell_small_label" text="\$nokName" />
<Label fx:id="relationship" styleClass="cell_small_label" text="\$relationship" />
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="address" styleClass="cell_small_label" text="\$address" />
<Label fx:id="remark" styleClass="cell_small_label" text="\$remark" />
</VBox>
</GridPane>
</HBox>
13 changes: 8 additions & 5 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ELDERLY_DISPLAYED_INDEX;
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.AGE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.GENDER_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NOK_ADDRESS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NOK_EMAIL_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NOK_NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NOK_PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NOK_RELATIONSHIP_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.ROOM_NUMBER_DESC_AMY;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalElderlies.AMY;
Expand Down Expand Up @@ -82,8 +84,9 @@ public void execute_storageThrowsIoException_throwsCommandException() {
logic = new LogicManager(model, storage);

// Execute add command
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY + AGE_DESC_AMY + GENDER_DESC_AMY
+ ROOM_NUMBER_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY;
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + AGE_DESC_AMY + GENDER_DESC_AMY
+ ROOM_NUMBER_DESC_AMY + NOK_NAME_DESC_AMY + NOK_RELATIONSHIP_DESC_AMY + NOK_PHONE_DESC_AMY
+ NOK_EMAIL_DESC_AMY + NOK_ADDRESS_DESC_AMY;
Elderly expectedElderly = new ElderlyBuilder(AMY).withTags().build();
ModelManager expectedModel = new ModelManager();
expectedModel.addElderly(expectedElderly);
Expand Down
Loading

0 comments on commit 3c116c1

Please sign in to comment.