From d2f1a2563e904d937389a054a67e7fa71b1ddd1d Mon Sep 17 00:00:00 2001 From: choowengyan Date: Thu, 4 Apr 2024 15:48:57 +0800 Subject: [PATCH 1/5] Disallow duplicate for name, pid, and preferred name field for EditCommand --- src/main/java/seedu/address/logic/parser/EditCommandParser.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index d64f0cce858..525877a99b0 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -40,6 +40,8 @@ public EditCommand parse(String args) throws ParseException { ArgumentTokenizer.tokenize(args, PREFIX_PID, PREFIX_NAME, PREFIX_PREFERRED_NAME, PREFIX_FOOD_PREFERENCE, PREFIX_FAMILY_CONDITION, PREFIX_HOBBY, PREFIX_TAG); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_PID, PREFIX_NAME, PREFIX_PREFERRED_NAME); + Index index; try { From e42997999e1551adaf0660d1f0b7c323d08bf2dc Mon Sep 17 00:00:00 2001 From: choowengyan Date: Thu, 4 Apr 2024 16:26:02 +0800 Subject: [PATCH 2/5] Adds logging --- .../java/seedu/address/logic/commands/AddCommand.java | 10 ++++++++++ .../java/seedu/address/logic/commands/EditCommand.java | 10 ++++++++++ .../seedu/address/logic/parser/AddCommandParser.java | 9 +++++++++ .../seedu/address/logic/parser/EditCommandParser.java | 8 ++++++++ 4 files changed, 37 insertions(+) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 6b94a6e95d4..35614067e0f 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -9,6 +9,10 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PREFERRED_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import java.util.logging.Level; +import java.util.logging.Logger; + +import seedu.address.commons.core.LogsCenter; import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; @@ -44,6 +48,8 @@ public class AddCommand extends Command { public static final String MESSAGE_DUPLICATE_PATIENT = "This patient already exists in the address book"; + private static final Logger logger = LogsCenter.getLogger(AddCommand.class); + private final Patient toAdd; /** @@ -56,13 +62,17 @@ public AddCommand(Patient patient) { @Override public CommandResult execute(Model model) throws CommandException { + logger.log(Level.INFO, "Attempting to execute AddCommand."); requireNonNull(model); if (model.hasPatient(toAdd)) { throw new CommandException(MESSAGE_DUPLICATE_PATIENT); } + logger.log(Level.INFO, "Patient is a new entry."); model.addPatient(toAdd); + logger.log(Level.INFO, "Patient details successfully added."); + return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd.getName(), toAdd.getPatientHospitalId())); } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index a76e77f92a3..5b490098f44 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -12,7 +12,10 @@ import java.util.List; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import seedu.address.commons.core.LogsCenter; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; @@ -54,6 +57,7 @@ public class EditCommand extends Command { public static final String MESSAGE_EDIT_PATIENT_SUCCESS = "Edited Patient: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; public static final String MESSAGE_DUPLICATE_PATIENT = "This patient already exists in the address book."; + private static final Logger logger = LogsCenter.getLogger(EditCommand.class); private final Index index; private final EditPatientDescriptor editPatientDescriptor; @@ -63,6 +67,7 @@ public class EditCommand extends Command { * @param editPatientDescriptor details to edit the patient with */ public EditCommand(Index index, EditPatientDescriptor editPatientDescriptor) { + logger.log(Level.INFO, "Attempting to execute EditCommand."); requireNonNull(index); requireNonNull(editPatientDescriptor); @@ -76,8 +81,10 @@ public CommandResult execute(Model model) throws CommandException { List lastShownList = model.getFilteredPatientList(); if (index.getZeroBased() >= lastShownList.size()) { + logger.log(Level.WARNING, "Invalid patient index for EditCommand: " + index.getOneBased()); throw new CommandException(Messages.MESSAGE_INVALID_PATIENT_DISPLAYED_INDEX); } + logger.log(Level.INFO, "Target index is valid."); Patient patientToEdit = lastShownList.get(index.getZeroBased()); Patient editedPatient = createEditedPatient(patientToEdit, editPatientDescriptor); @@ -85,9 +92,11 @@ public CommandResult execute(Model model) throws CommandException { if (!patientToEdit.isSamePatient(editedPatient) && model.hasPatient(editedPatient)) { throw new CommandException(MESSAGE_DUPLICATE_PATIENT); } + logger.log(Level.INFO, "Target patient to edit is valid."); model.setPatient(patientToEdit, editedPatient); model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); + logger.log(Level.INFO, "Patient details successfully updated."); return new CommandResult(String.format(MESSAGE_EDIT_PATIENT_SUCCESS, Messages.format(editedPatient))); } @@ -112,6 +121,7 @@ static Patient createEditedPatient(Patient patientToEdit, EditPatientDescriptor Set updatedEvents = editPatientDescriptor.getEvents() .orElse(patientToEdit.getEvents()); + logger.log(Level.INFO, "Attempting to update the information on the patient with the updated fields"); return new Patient(originalPatientHospitalId, updatedName, updatedPreferredName, updatedFoodPreferences, updatedFamilyConditions, updatedHobbies, updatedTags, updatedEvents); } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index f49dccdc6b1..adc9717ce25 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -10,8 +10,11 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Stream; +import seedu.address.commons.core.LogsCenter; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.patient.FamilyCondition; @@ -27,6 +30,7 @@ * Parses input arguments and creates a new AddCommand object */ public class AddCommandParser implements Parser { + private static final Logger logger = LogsCenter.getLogger(AddCommandParser.class); /** * Parses the given {@code String} of arguments in the context of the AddCommand @@ -34,14 +38,18 @@ public class AddCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public AddCommand parse(String args) throws ParseException { + logger.info("Received arguments: " + args + " for AddCommand; Attempting to parse.."); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PID, PREFIX_NAME, PREFIX_PREFERRED_NAME, PREFIX_FOOD_PREFERENCE, PREFIX_FAMILY_CONDITION, PREFIX_HOBBY, PREFIX_TAG); if (!arePrefixesPresent(argMultimap, PREFIX_PID, PREFIX_NAME, PREFIX_PREFERRED_NAME, PREFIX_FOOD_PREFERENCE, PREFIX_FAMILY_CONDITION, PREFIX_HOBBY) || !argMultimap.getPreamble().isEmpty()) { + logger.log(Level.WARNING, "Required prefix(s) not found in AddCommand"); throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } + logger.info("All prefixes required are present."); argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_PID, PREFIX_NAME, PREFIX_PREFERRED_NAME); @@ -58,6 +66,7 @@ public AddCommand parse(String args) throws ParseException { Patient patient = new Patient(patientHospitalId, name, preferredName, foodPreferenceList, familyConditionList, hobbyList, tagList); + logger.info("All arguments received are valid"); return new AddCommand(patient); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 525877a99b0..6b6ed7e2b6c 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -14,7 +14,10 @@ import java.util.Collections; import java.util.Optional; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import seedu.address.commons.core.LogsCenter; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.parser.exceptions.ParseException; @@ -28,6 +31,7 @@ * Parses input arguments and creates a new EditCommand object */ public class EditCommandParser implements Parser { + private static final Logger logger = LogsCenter.getLogger(EditCommandParser.class); /** * Parses the given {@code String} of arguments in the context of the EditCommand @@ -35,7 +39,9 @@ public class EditCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public EditCommand parse(String args) throws ParseException { + logger.log(Level.INFO, "Received arguments: " + args + " for EditCommand; Attempting to parse.."); requireNonNull(args); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PID, PREFIX_NAME, PREFIX_PREFERRED_NAME, PREFIX_FOOD_PREFERENCE, PREFIX_FAMILY_CONDITION, PREFIX_HOBBY, PREFIX_TAG); @@ -49,6 +55,7 @@ public EditCommand parse(String args) throws ParseException { } catch (ParseException pe) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); } + logger.log(Level.INFO, "Patient Index is valid."); EditPatientDescriptor editPatientDescriptor = new EditPatientDescriptor(); @@ -78,6 +85,7 @@ public EditCommand parse(String args) throws ParseException { throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); } + logger.log(Level.INFO, "All arguments are valid."); return new EditCommand(index, editPatientDescriptor); } From fc8e1fccf68caf6545b117ea0beb23c293de3b74 Mon Sep 17 00:00:00 2001 From: choowengyan Date: Thu, 4 Apr 2024 20:44:44 +0800 Subject: [PATCH 3/5] Update UserGuide.md for duplicate prefixes details --- docs/UserGuide.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 920518c9cec..202a52e3f80 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -92,10 +92,15 @@ Format: `add id/PATIENT_HOSPITAL_ID n/NAME p/PREFERRED_NAME f/FOOD_PREFERENCE+ c **Tip:** -* A patient can have any number of tags (including 0) -* A patient can have more than 1 `f/FOOD_PREFERENCE`, `c/FAMILY_CONDITION` and `h/HOBBY` -* Parameters can be in any order -* All command keywords, that is `‘add’`, `‘id/’`, `‘n/’`, `‘p/’`, `‘f/’`, `‘c/’` and `‘h/’` are case-sensitive (to standardise keyword arguments) +* The `add` command accepts parameters which consists of: + * `patientHospitalId` integer, + * `name`, `preferredName` String with only alphabets character, + * `foodPreference`, `familyCondition`, `hobby` String and all kinds of characters, + * `tag` which are alphanumeric. +* A patient can have any number of tags (including 0). +* A patient can have more than 1 `f/FOOD_PREFERENCE`, `c/FAMILY_CONDITION` and `h/HOBBY`. +* Parameters can be in any order. +* All command keywords, that is `‘add’`, `‘id/’`, `‘n/’`, `‘p/’`, `‘f/’`, `‘c/’` and `‘h/’` are case-sensitive (to standardise keyword arguments). @@ -128,7 +133,12 @@ Format: `edit INDEX [id/PATIENT_HOSPITAL_ID] [n/NAME] [p/PREFERRED_NAME] [f/FOOD * Edits the patient at the specified `INDEX`. The index refers to the index number shown in the displayed patient list. The index **must be a positive integer** 1, 2, 3, …​ * At least one of the optional fields must be provided. * Existing values will be updated to the input values. -* Editing a patient can have repeated fields for `f/FOOD_PREFERENCE`, `c/FAMILY_CONDITION` and `h/HOBBY` +* * The `edit` command accepts parameters which consists of: + * `patientHospitalId` integer, + * `name`, `preferredName` String with only alphabets character, + * `foodPreference`, `familyCondition`, `hobby` String and all kinds of characters + * `tag` which are alphanumeric. +* Editing a patient can have repeated fields for `f/FOOD_PREFERENCE`, `c/FAMILY_CONDITION`, `h/HOBBY` and `t/TAG`. * When editing tags, the existing tags of the patient will be removed i.e adding of tags is not cumulative. * You can remove all the patient’s tags by typing `t/` without specifying any tags after it. From 8f092bbd87565f8e8f6bee4e04f540b1af1318cd Mon Sep 17 00:00:00 2001 From: choowengyan Date: Thu, 4 Apr 2024 20:45:14 +0800 Subject: [PATCH 4/5] Adds more EditCommandParser test cases --- .../logic/parser/EditCommandParserTest.java | 83 ++++++++++++++++++- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 51856497696..a09ea2d5a1d 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -4,7 +4,9 @@ import static seedu.address.logic.commands.CommandTestUtil.FAMILY_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.FAMILY_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.FOOD_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.FOOD_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.HOBBY_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.HOBBY_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.ID_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.ID_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.INVALID_FAMILY_DESC; @@ -15,18 +17,25 @@ import static seedu.address.logic.commands.CommandTestUtil.INVALID_PREFERRED_NAME_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.PREFERRED_NAME_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.PREFERRED_NAME_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_DEPRESSION; import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_DIABETES; import static seedu.address.logic.commands.CommandTestUtil.VALID_FAMILY_CONDITION_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_FAMILY_CONDITION_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_FOOD_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_FOOD_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_HOBBY_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_HOBBY_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_ID_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_PREFERRED_NAME_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_DEPRESSION; import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_DIABETES; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PID; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PREFERRED_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; @@ -37,6 +46,7 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.EditCommand; import seedu.address.model.patient.EditPatientDescriptor; import seedu.address.model.patient.FamilyCondition; @@ -53,7 +63,7 @@ public class EditCommandParserTest { private static final String TAG_EMPTY = " " + PREFIX_TAG; private static final String MESSAGE_INVALID_FORMAT = - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE); + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE); private EditCommandParser parser = new EditCommandParser(); @@ -108,14 +118,14 @@ public void parse_invalidValue_failure() { // multiple invalid values, but only the first invalid value is captured assertParseFailure(parser, "1" + INVALID_ID_DESC + INVALID_NAME_DESC + INVALID_PREFERRED_NAME_DESC - + VALID_FOOD_AMY + VALID_FAMILY_CONDITION_AMY + VALID_HOBBY_AMY, PatientHospitalId.MESSAGE_CONSTRAINTS); + + VALID_FOOD_AMY + VALID_FAMILY_CONDITION_AMY + VALID_HOBBY_AMY, PatientHospitalId.MESSAGE_CONSTRAINTS); } @Test public void parse_allFieldsSpecified_success() { Index targetIndex = INDEX_SECOND_PATIENT; String userInput = targetIndex.getOneBased() + ID_DESC_AMY + NAME_DESC_AMY + TAG_DESC_DEPRESSION - + PREFERRED_NAME_DESC_AMY + FOOD_DESC_AMY + FAMILY_DESC_AMY + HOBBY_DESC_AMY + TAG_DESC_DIABETES; + + PREFERRED_NAME_DESC_AMY + FOOD_DESC_AMY + FAMILY_DESC_AMY + HOBBY_DESC_AMY + TAG_DESC_DIABETES; EditPatientDescriptor descriptor = new EditPatientDescriptorBuilder() .withPatientHospitalId(VALID_ID_AMY).withName(VALID_NAME_AMY).withPreferredName(VALID_PREFERRED_NAME_AMY) @@ -145,7 +155,7 @@ public void parse_oneFieldSpecified_success() { Index targetIndex = INDEX_THIRD_PATIENT; String userInput = targetIndex.getOneBased() + NAME_DESC_AMY; EditPatientDescriptor descriptor = - new EditPatientDescriptorBuilder().withName(VALID_NAME_AMY).build(); + new EditPatientDescriptorBuilder().withName(VALID_NAME_AMY).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -200,6 +210,71 @@ public void parse_multipleRepeatedFields_failure() { userInput = targetIndex.getOneBased() + INVALID_ID_DESC + INVALID_ID_DESC; } + @Test + public void parse_repeatedNonTagValue_failure() { + String validExpectedPatientString = ID_DESC_BOB + NAME_DESC_BOB + PREFERRED_NAME_DESC_BOB + FOOD_DESC_BOB + + FAMILY_DESC_BOB + HOBBY_DESC_BOB + TAG_DESC_DIABETES; + + // multiple patient hospital ID + assertParseFailure(parser, ID_DESC_AMY + validExpectedPatientString, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PID)); + + // multiple names + assertParseFailure(parser, NAME_DESC_AMY + validExpectedPatientString, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME)); + + // multiple preferred names + assertParseFailure(parser, PREFERRED_NAME_DESC_AMY + validExpectedPatientString, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PREFERRED_NAME)); + } + + @Test + public void parse_duplicatePrefixes_success() { + // Duplicate food preference input + String userInput = "1 " + FOOD_DESC_AMY + FOOD_DESC_BOB; + EditPatientDescriptor descriptor = new EditPatientDescriptorBuilder() + .withFoodPreferences(VALID_FOOD_AMY, VALID_FOOD_BOB) + .build(); + EditCommand expectedCommand = new EditCommand(INDEX_FIRST_PATIENT, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // Duplicate family condition input + userInput = "1 " + FAMILY_DESC_AMY + FAMILY_DESC_BOB; + descriptor = new EditPatientDescriptorBuilder() + .withFamilyConditions(VALID_FAMILY_CONDITION_AMY, VALID_FAMILY_CONDITION_BOB) + .build(); + expectedCommand = new EditCommand(INDEX_FIRST_PATIENT, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + + // Duplicate hobby input + userInput = "1 " + HOBBY_DESC_AMY + HOBBY_DESC_BOB; + descriptor = new EditPatientDescriptorBuilder() + .withHobbies(VALID_HOBBY_AMY, VALID_HOBBY_BOB) + .build(); + expectedCommand = new EditCommand(INDEX_FIRST_PATIENT, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_duplicatePrefixes_failure() { + // Duplicate patient hospital ID + String userInput = "1 " + ID_DESC_AMY + ID_DESC_BOB; + assertParseFailure(parser, userInput, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PID)); + + // Duplicate names + userInput = "1 " + NAME_DESC_AMY + NAME_DESC_BOB; + assertParseFailure(parser, userInput, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME)); + + // Duplicate preferred names + userInput = "1 " + PREFERRED_NAME_DESC_AMY + PREFERRED_NAME_DESC_BOB; + assertParseFailure(parser, userInput, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PREFERRED_NAME)); + } + + + @Test public void parse_resetTags_success() { Index targetIndex = INDEX_THIRD_PATIENT; From b58197d183a38689fc0e118d2870f93e5c766673 Mon Sep 17 00:00:00 2001 From: choowengyan Date: Thu, 4 Apr 2024 21:37:10 +0800 Subject: [PATCH 5/5] Adds activity diagram and updates UG for AddCommand and EditCommand --- docs/DeveloperGuide.md | 6 +++++ docs/diagrams/AddActivityDiagram.puml | 37 ++++++++++++++++++++++++++ docs/diagrams/EditActivityDiagram.puml | 35 ++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 docs/diagrams/AddActivityDiagram.puml create mode 100644 docs/diagrams/EditActivityDiagram.puml diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index c725acbd0db..ab3b698a4c6 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -188,6 +188,9 @@ The `AddCommand` class is responsible for adding new patient's information in th * `tag` field is optional in the AddCommand and can be added later on using the `AddTagsCommand`. * If any of the fields are repeated during the adding of patient or missing fields, error message will be thrown. +The activity diagram below outlines the steps involved when a user initiates a Add command. + + #### Example Usage Scenario Given below is an example usage scenario and how the group creation mechanism behaves at each step. @@ -484,6 +487,9 @@ The `EditCommand` class is responsible for editing current patient's information * Fields such as `foodPreference`, `familyCondition`, `hobby` and `tag` can be repeated for multiple inputs. * If the fields for `patientHospitalId`, `name` and `preferredName` are repeated during the editing of patient, error message will be thrown. +The activity diagram below outlines the steps involved when a user initiates a Edit command. + + #### Example Usage Scenario Given below is an example usage scenario and how the group creation mechanism behaves at each step. diff --git a/docs/diagrams/AddActivityDiagram.puml b/docs/diagrams/AddActivityDiagram.puml new file mode 100644 index 00000000000..f6d82b6777d --- /dev/null +++ b/docs/diagrams/AddActivityDiagram.puml @@ -0,0 +1,37 @@ +@startuml + +start +:User wants to add a patient; +:User runs the "add" command with id/PATIENT_HOSPITAL_ID n/NAME p/PREFERRED_NAME f/FOOD_PREFERENCE c/FAMILY_CONDITION h/HOBBY; +if () then ([Required prefixes present]) + if () then ([Valid command format]) + :PatientSync checks if the input format for the respective prefix is valid; + if () then ([Valid input format]) + :PatientSync creates Patient object; + if () then ([Valid Patient Hospital ID]) + :PatientSync adds patient to model; + :PatientSync generates success message; + :PatientSync returns success message to output; + else ([else]) + :PatientSync throws command exception; + :PatientSync generates error message; + :PatientSync returns error message; + endif + else ([else]) + :PatientSync throws parse exception; + :PatientSync generates error message; + :PatientSync returns error message; + endif + else ([else]) + :PatientSync throws parse exception; + :PatientSync generates error message; + :PatientSync returns error message; + endif +else ([else]) + :PatientSync throws parse exception; + :PatientSync generates error message; + :PatientSync returns error message; +endif +:PatientSync displays output message on GUI; +stop +@enduml diff --git a/docs/diagrams/EditActivityDiagram.puml b/docs/diagrams/EditActivityDiagram.puml new file mode 100644 index 00000000000..577652e57a6 --- /dev/null +++ b/docs/diagrams/EditActivityDiagram.puml @@ -0,0 +1,35 @@ +@startuml +start +:User wants to edit information (eg. hobby) of a patient; +:User runs the "edit" command with patient index, details of fields (eg. hobby with command h/Reading h/Singing); +if () then ([else]) + :PatientSync throws an error; + :PatientSync adds error message to output; +else ([Valid command format]) + :PatientSync checks if the patient index is valid; + if () then ([else]) + :PatientSync throws an error; + :PatientSync adds error message to output; + else ([Valid patient index]) + :PatientSync checks if the prefix(s) is valid; + if () then ([else]) + :PatientSync throws an error; + :PatientSync adds error message to output; + else ([Valid prefix]) + :PatientSync checks if the input format for the respective prefix is valid; + if () then ([else]) + :PatientSync throws an error; + :PatientSync adds error message to output; + else ([Valid input format]) + :PatientSync generates the information to be edited; + :PatientSync edits the specified event; + :PatientSync updates the set of events for the patient; + :PatientSync updates the displayed patient list; + :PatientSync adds success message to output; + endif + endif + endif +endif +:PatientSync displays output message on GUI; +stop +@enduml