diff --git a/docs/UserGuide.md b/docs/UserGuide.md index efdbeb4c86c..d53cc4f858c 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -78,10 +78,14 @@ Creates a patient profile in ImmuniMate. Format: `create ic/ n/ hp/ a/
dob/ s/ st/ [e/Email] [c/Country_of_Nationality] [doa/Date_of_Admission] [bt/Blood type] [al/Allergies] [con/Condition] [sym/Symptom] [d/diagnosis]` +* All mandatory fields must be provided. +* The unique identifier for each patient is the NRIC. The new NRIC must not already exist in the system. + Examples: * `create ic/S1234567A n/John Doe hp/98765432 a/311, Clementi Ave 2, #02-25 dob/1990-01-01 s/M st/PENDING` -* `create ic/S0123456A n/Jane Doe hp/87654321 a/311, Clementi Ave 2, #02-25 dob/01-01-1990 s/F st/PENDING e/janed@example.com bt/A+` +* `create ic/S0123456A n/Jane Doe hp/87654321 a/311, Clementi Ave 2, #02-25 dob/1990-01-01 s/F st/PENDING e/janed@example.com bt/A+` +For specification of each field, refer to the [Field summary](#field-summary) at the end of this User Guide. ### Listing all patients : `list` Shows a list of all patients in ImmuniMate. @@ -106,6 +110,7 @@ Format: `update /CONTENT` * Updates the patient of corresponding NRIC. * At least one of the fields must be provided. * Existing values will be updated to the input values. +* NRIC cannot be updated, while all other values can be updated. Examples: * `update S1234567A hp/91234567 e/jd123@example.com` Updates the phone number and email address of the corresponding patient to be `91234567` and `jd123@example.com` respectively. @@ -201,7 +206,7 @@ Format: `addvisit ic/ dov/ sym/ d/ st/ Examples: * `addvisit ic/S1234567A dov/2024-01-01 sym/Cough d/Covid st/UNWELL` adds a visit to history of patient uniquely identified by NRIC S1234567A. During this visit on 2024-01-01, the patient had cough and was diagnosed with Covid. * `addvisit ic/S0123456A dov/2024-02-02 sym/Fever,Rashes d/Dengue st/PENDING` adds a visit to history of patient uniquely identified by NRIC S0123456A. During this visit on 2024-02-02, the patient had fever and rashes, and was diagnosed with Dengue. - +Date of visit: `yyyy-MM-dd` format. ### Check patient history : `check` Checks all visits in patient history. @@ -295,20 +300,20 @@ Furthermore, certain edits can cause ImmuniMate to behave in unexpected ways (e. ## Field summary -| Field | Prefix | -|----------------------------|--------| -| **Name** | `n/` | -| **NRIC** | `ic/` | -| **Phone Number** | `hp/` | -| **Address** | `a/` | -| **Date of birth** | `dob/` | -| **Sex** | `s/` | -| **Status** | `st/` | -| **Email** | `e/` | -| **Country of nationality** | `c/` | -| **Date of admission** | `doa/` | -| **Blood type** | `bt/` | -| **Allergies** | `al/` | -| **Condition** | `con/` | -| **Symptom** | `sym/` | -| **Diagnosis** | `d/` | +| Field | Prefix | Format | Mandatory | +|----------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------|-----------| +| **Name** | `n/` | Any string containing only alphabets and spaces. | Yes | +| **NRIC** | `ic/` | 9 characters. First character can be any of S, T, followed by 7 digits, and the last character is an alphabet. Only upper-case allowed. | Yes | +| **Phone Number** | `hp/` | 8 digits. | Yes | +| **Address** | `a/` | Any text. Blank or empty text is not accepted. | Yes | +| **Date of birth** | `dob/` | `yyyy-MM-dd` format. | Yes | +| **Sex** | `s/` | `M` or `F` | Yes | +| **Status** | `st/` | `PENDING`, `UNWELL`or `HEALTHY` | Yes | +| **Email** | `e/` | Any valid email address of the form `local-part@domain`. | No | +| **Country of nationality** | `c/` | Any text. Blank or empty text is not accepted. | No | +| **Date of admission** | `doa/` | `yyyy-MM-dd` format. | No | +| **Blood type** | `bt/` | `A+`, `A-`, `B+`, `B-`, `AB+`, `AB-`, `O+`, `O-` | No | +| **Allergies** | `al/` | Any text. Blank or empty text is not accepted. | No | +| **Condition** | `con/` | Any text. Blank or empty text is not accepted. | No | +| **Symptom** | `sym/` | Any text. Blank or empty text is not accepted. | No | +| **Diagnosis** | `d/` | Any text. Blank or empty text is not accepted. | No | diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index d716c951b47..94e1a579430 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -47,6 +47,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE logger.info("----------------[USER COMMAND][" + commandText + "]"); CommandResult commandResult; + model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS); Command command = immuniMateParser.parseCommand(commandText); commandResult = command.execute(model); diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index f010b3f4e15..27ac3834f66 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -34,7 +34,6 @@ public DeleteCommand(Nric targetNric) { @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ObservableList persons = model.getFilteredPersonList(); if (!model.hasPerson(Person.createPersonWithNric(targetNric))) { throw new CommandException(Messages.MESSAGE_PERSON_NOT_FOUND); diff --git a/src/main/java/seedu/address/logic/commands/DeleteInfoCommand.java b/src/main/java/seedu/address/logic/commands/DeleteInfoCommand.java index 2b6a262a2e9..f27e5d1156d 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteInfoCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteInfoCommand.java @@ -33,12 +33,10 @@ public enum Fields { } public static final String MESSAGE_DELETE_PERSON_INFORMATION_SUCCESS = "Deleted Patient info: %1$s"; public static final int NUM_FIELDS = 8; + private final Nric targetNric; //{email, allergies, bloodtype, date of admission, country, condition, symptom, diagnosis} private boolean[] fieldsToDelete = new boolean[NUM_FIELDS]; - - - //TODO test cases /** * Creates a DeleteInfoCommand to delete the specified {@code Person}'s information */ @@ -51,7 +49,6 @@ public DeleteInfoCommand(Nric targetNric, boolean[] fieldsToDelete) { @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ObservableList persons = model.getFilteredPersonList(); if (!model.hasPerson(Person.createPersonWithNric(targetNric))) { throw new CommandException(Messages.MESSAGE_PERSON_NOT_FOUND); @@ -98,7 +95,6 @@ private boolean fieldsToDeleteEquals(boolean[] otherFieldsToDelete) { } return true; } - @Override public boolean equals(Object other) { if (other == this) { @@ -114,8 +110,6 @@ public boolean equals(Object other) { return targetNric.equals(otherDeleteCommand.targetNric) && fieldsToDeleteEquals(otherDeleteCommand.fieldsToDelete); } - - //TODO test cases @Override public String toString() { StringBuilder fields = new StringBuilder(); diff --git a/src/main/java/seedu/address/logic/commands/UpdateCommand.java b/src/main/java/seedu/address/logic/commands/UpdateCommand.java index 3f8dfeea11e..502033a6fe1 100644 --- a/src/main/java/seedu/address/logic/commands/UpdateCommand.java +++ b/src/main/java/seedu/address/logic/commands/UpdateCommand.java @@ -82,7 +82,7 @@ public class UpdateCommand extends Command { public static final String MESSAGE_UPDATE_PERSON_SUCCESS = "Updated Person ->\n%1$s"; public static final String MESSAGE_NOT_UPDATED = "At least one field to update must be provided."; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; - + public static final String MESSAGE_NRIC_NOT_UPDATED = "NRIC cannot be updated."; private final Nric nric; private final UpdatePersonDescriptor updatePersonDescriptor; diff --git a/src/main/java/seedu/address/logic/parser/DeleteInfoCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteInfoCommandParser.java index c126ec7b740..a6a4693c777 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteInfoCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteInfoCommandParser.java @@ -83,9 +83,11 @@ public DeleteInfoCommand parse(String args) throws ParseException { PREFIX_BLOODTYPE, PREFIX_DATEOFADMISSION, PREFIX_COUNTRY, PREFIX_CONDITION, PREFIX_SYMPTOM, PREFIX_DIAGNOSIS}; for (int i = 0; i < optionalPrefixes.length; i++) { + //prefix is not mentioned if (argMultimap.getValue(optionalPrefixes[i]).isEmpty()) { continue; } + //prefix is mentioned but value is not empty if (!argMultimap.getValue(optionalPrefixes[i]).get().isEmpty()) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteInfoCommand.MESSAGE_USAGE)); diff --git a/src/main/java/seedu/address/logic/parser/UpdateCommandParser.java b/src/main/java/seedu/address/logic/parser/UpdateCommandParser.java index f134eaefc20..ca165fd005a 100644 --- a/src/main/java/seedu/address/logic/parser/UpdateCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/UpdateCommandParser.java @@ -63,6 +63,10 @@ public UpdateCommand parse(String args) throws ParseException { UpdatePersonDescriptor updatePersonDescriptor = new UpdatePersonDescriptor(); updatePersonDescriptor.setNric(nric); + //Un-updatable field + if (argMultimap.getValue(PREFIX_NRIC).isPresent()) { + throw new ParseException(UpdateCommand.MESSAGE_NRIC_NOT_UPDATED); + } // Mandatory fields if (argMultimap.getValue(PREFIX_NAME).isPresent()) { diff --git a/src/main/java/seedu/address/model/person/Allergies.java b/src/main/java/seedu/address/model/person/Allergies.java index e298312214b..54045dadb8f 100644 --- a/src/main/java/seedu/address/model/person/Allergies.java +++ b/src/main/java/seedu/address/model/person/Allergies.java @@ -1,17 +1,32 @@ package seedu.address.model.person; +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + /** * Represents a Person's allergies in the address book. * Guarantees: immutable; */ public class Allergies { + //making string non-empty because empty input is already represented by null, + //and if allowed, can cause storage problems + public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String MESSAGE_CONSTRAINTS = "Allergies can take any values, and it should not be blank"; private final String allergies; - + /** + * Constructs an {@code Allergies}. + * + * @param allergies A valid allergies. + */ public Allergies(String allergies) { + requireNonNull(allergies); + checkArgument(isValidAllergies(allergies), MESSAGE_CONSTRAINTS); this.allergies = allergies; } - + public static boolean isValidAllergies(String test) { + return test.matches(VALIDATION_REGEX); + } public String getAllergies() { return allergies; } diff --git a/src/main/java/seedu/address/model/person/Condition.java b/src/main/java/seedu/address/model/person/Condition.java index 8093e9bf15c..7b299b0306d 100644 --- a/src/main/java/seedu/address/model/person/Condition.java +++ b/src/main/java/seedu/address/model/person/Condition.java @@ -1,16 +1,35 @@ package seedu.address.model.person; +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + /** * Represents a Person's condition in the address book. * Guarantees: immutable; */ public class Condition { + public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String MESSAGE_CONSTRAINTS = "Conditions can take any values, and it should not be blank"; private final String condition; + /** + * Constructs an {@code Condition}. + * + * @param condition A valid condition. + */ public Condition(String condition) { + requireNonNull(condition); + checkArgument(isValidCondition(condition), MESSAGE_CONSTRAINTS); this.condition = condition; } + /** + * Returns true if a given string is a valid condition. + */ + public static boolean isValidCondition(String test) { + return test.matches(VALIDATION_REGEX); + } + public String getCondition() { return condition; diff --git a/src/main/java/seedu/address/model/person/Country.java b/src/main/java/seedu/address/model/person/Country.java index 59619c9a735..e2a06dfc3b3 100644 --- a/src/main/java/seedu/address/model/person/Country.java +++ b/src/main/java/seedu/address/model/person/Country.java @@ -1,17 +1,36 @@ package seedu.address.model.person; +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + /** * Represents a Person's condition in the address book. * Guarantees: immutable; */ public class Country { + //making string non-empty because empty input is already represented by null, + //and if allowed, can cause storage problems + public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String MESSAGE_CONSTRAINTS = "Countries can take any values, and it should not be blank." + + " It is case insensitive."; private final String country; - //Todo: map input country to a standard country name + + /** + * Constructs an {@code Country}. + * + * @param country A valid country. + */ public Country(String country) { + requireNonNull(country); + checkArgument(isValidCountry(country), MESSAGE_CONSTRAINTS); this.country = country; } + public static boolean isValidCountry(String test) { + return test.matches(VALIDATION_REGEX); + } + /** * Returns given placeholder string if value field is not initialised * @param alt diff --git a/src/main/java/seedu/address/model/person/DateOfAdmission.java b/src/main/java/seedu/address/model/person/DateOfAdmission.java index 27d4cd5adff..0ba0bc32cc4 100644 --- a/src/main/java/seedu/address/model/person/DateOfAdmission.java +++ b/src/main/java/seedu/address/model/person/DateOfAdmission.java @@ -1,16 +1,19 @@ package seedu.address.model.person; +import static java.util.Objects.requireNonNull; + import java.time.LocalDate; + /** * Represents a Person's date of admission in the address book. * Guarantees: immutable; */ public class DateOfAdmission { + //Changed validity check for date format to disallow invalid dates, as not doing so results in parser errors public static final String MESSAGE_CONSTRAINTS = - "Date of admission should be in the format of YYYY-MM-DD, and it should not be blank."; - - public static final String VALIDATION_REGEX = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"; + "Date of admission should be in the format of YYYY-MM-DD. It should be a valid date," + + " and it should not be blank."; private final LocalDate dateOfAdmission; @@ -20,6 +23,10 @@ public class DateOfAdmission { * @param dateOfAdmission A valid date of admission. */ public DateOfAdmission(String dateOfAdmission) { + requireNonNull(dateOfAdmission); + if (!isValidDateOfAdmission(dateOfAdmission)) { + throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); + } this.dateOfAdmission = LocalDate.parse(dateOfAdmission); } @@ -27,7 +34,12 @@ public DateOfAdmission(String dateOfAdmission) { * Returns true if a given string is a valid date of admission. */ public static boolean isValidDateOfAdmission(String test) { - return test.matches(VALIDATION_REGEX); + try { + LocalDate.parse(test); + } catch (Exception e) { + return false; + } + return true; } /** diff --git a/src/main/java/seedu/address/model/person/DateOfBirth.java b/src/main/java/seedu/address/model/person/DateOfBirth.java index f3da0992063..89b7cd922d7 100644 --- a/src/main/java/seedu/address/model/person/DateOfBirth.java +++ b/src/main/java/seedu/address/model/person/DateOfBirth.java @@ -1,16 +1,19 @@ package seedu.address.model.person; +import static java.util.Objects.requireNonNull; + import java.time.LocalDate; + /** * Represents a Person's date of admission in the address book. * Guarantees: immutable; */ public class DateOfBirth { + //Changed validity check for date format to disallow invalid dates, as not doing so results in parser error public static final String MESSAGE_CONSTRAINTS = - "Date of birth should be in the format of YYYY-MM-DD, and it should not be blank."; - - public static final String VALIDATION_REGEX = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])"; + "Date of birth should be in the format of YYYY-MM-DD. It should be a valid date," + + " and it should not be blank."; private final LocalDate dateOfBirth; @@ -20,6 +23,7 @@ public class DateOfBirth { * @param dateOfBirth A valid date of birth. */ public DateOfBirth(String dateOfBirth) { + requireNonNull(dateOfBirth); if (!isValidDateOfBirth(dateOfBirth)) { throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); } @@ -30,7 +34,12 @@ public DateOfBirth(String dateOfBirth) { * Returns true if a given string is a valid date of birth. */ public static boolean isValidDateOfBirth(String test) { - return test.matches(VALIDATION_REGEX); + try { + LocalDate.parse(test); + } catch (Exception e) { + return false; + } + return true; } @Override diff --git a/src/main/java/seedu/address/model/person/Diagnosis.java b/src/main/java/seedu/address/model/person/Diagnosis.java index f103fe7206a..b2d5ab1d314 100644 --- a/src/main/java/seedu/address/model/person/Diagnosis.java +++ b/src/main/java/seedu/address/model/person/Diagnosis.java @@ -1,16 +1,33 @@ package seedu.address.model.person; +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + /** * Represents a Person's diagnosis in the address book. * Guarantees: immutable; */ public class Diagnosis { + //making string non-empty because empty input is already represented by null, + //and if allowed, can cause storage problems + public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String MESSAGE_CONSTRAINTS = "Diagnosis can take any values, and it should not be blank"; private final String diagnosis; + /** + * Constructs a {@code Diagnosis}. + * + * @param diagnosis A valid diagnosis. + */ public Diagnosis(String diagnosis) { + requireNonNull(diagnosis); + checkArgument(isValidDiagnosis(diagnosis), MESSAGE_CONSTRAINTS); this.diagnosis = diagnosis; } + public static boolean isValidDiagnosis(String test) { + return test.matches(VALIDATION_REGEX); + } public String getDiagnosis() { return diagnosis; diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/person/Email.java index 3fb7c7986e9..fe85fb260e4 100644 --- a/src/main/java/seedu/address/model/person/Email.java +++ b/src/main/java/seedu/address/model/person/Email.java @@ -20,7 +20,7 @@ public class Email { + "The domain name must:\n" + " - end with a domain label at least 2 characters long\n" + " - have each domain label start and end with alphanumeric characters\n" - + " - have each domain label consist of alphanumeric characters, separated only by hyphens, if any."; + + " - have each domain label consist of alphanumeric characters, separated only by hyphens, if any."; // alphanumeric and special characters private static final String ALPHANUMERIC_NO_UNDERSCORE = "[^\\W_]+"; // alphanumeric characters except underscore private static final String LOCAL_PART_REGEX = "^" + ALPHANUMERIC_NO_UNDERSCORE + "([" + SPECIAL_CHARACTERS + "]" diff --git a/src/main/java/seedu/address/model/person/Nric.java b/src/main/java/seedu/address/model/person/Nric.java index 79a3460b5e8..dde1598cf85 100644 --- a/src/main/java/seedu/address/model/person/Nric.java +++ b/src/main/java/seedu/address/model/person/Nric.java @@ -30,7 +30,8 @@ public class Nric { public Nric(String nric) { requireNonNull(nric); checkArgument(isValidNric(nric), MESSAGE_CONSTRAINTS); - this.nric = nric; + //TODO: is this a bug? + this.nric = nric.toUpperCase(); } /** diff --git a/src/main/java/seedu/address/model/person/Symptom.java b/src/main/java/seedu/address/model/person/Symptom.java index aaaad4e9ad3..d194edf73bd 100644 --- a/src/main/java/seedu/address/model/person/Symptom.java +++ b/src/main/java/seedu/address/model/person/Symptom.java @@ -1,15 +1,32 @@ package seedu.address.model.person; +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + /** * Represents a Person's symptom in the address book. * Guarantees: immutable; */ public class Symptom { + //making string non-empty because empty input is already represented by null, + //and if allowed, can cause storage problems + public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String MESSAGE_CONSTRAINTS = "Symptom can take any values, and it should not be blank"; private final String symptom; + /** + * Constructs a {@code Symptom}. + * + * @param symptom A valid symptom. + */ public Symptom(String symptom) { + requireNonNull(symptom); + checkArgument(isValidSymptom(symptom), MESSAGE_CONSTRAINTS); this.symptom = symptom; } + public static boolean isValidSymptom(String test) { + return test.matches(VALIDATION_REGEX); + } public String getSymptom() { return symptom; diff --git a/src/main/java/seedu/address/model/visit/DateOfVisit.java b/src/main/java/seedu/address/model/visit/DateOfVisit.java index 26762565d52..a024720f28f 100644 --- a/src/main/java/seedu/address/model/visit/DateOfVisit.java +++ b/src/main/java/seedu/address/model/visit/DateOfVisit.java @@ -1,5 +1,7 @@ package seedu.address.model.visit; +import static java.util.Objects.requireNonNull; + import java.time.LocalDate; /** @@ -7,10 +9,10 @@ * Guarantees: immutable; */ public class DateOfVisit { + //Changed validity check for date format to disallow invalid dates, as not doing so results in parser error public static final String MESSAGE_CONSTRAINTS = - "Date of Visit should be in the format of YYYY-MM-DD, and it should not be blank."; - - public static final String VALIDATION_REGEX = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])"; + "Date of visit should be in the format of YYYY-MM-DD. It should be a valid date," + + " and it should not be blank."; private final LocalDate dateOfVisit; @@ -20,6 +22,7 @@ public class DateOfVisit { * @param dateOfBirth A valid date of birth. */ public DateOfVisit(String dateOfBirth) { + requireNonNull(dateOfBirth); if (!isValidDateOfVisit(dateOfBirth)) { throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); } @@ -30,7 +33,12 @@ public DateOfVisit(String dateOfBirth) { * Returns true if a given string is a valid date of birth. */ public static boolean isValidDateOfVisit(String test) { - return test.matches(VALIDATION_REGEX); + try { + LocalDate.parse(test); + } catch (Exception e) { + return false; + } + return true; } @Override diff --git a/src/test/java/seedu/address/logic/commands/CheckCommandTest.java b/src/test/java/seedu/address/logic/commands/CheckCommandTest.java index 8ebb847c862..6ff8b53ae49 100644 --- a/src/test/java/seedu/address/logic/commands/CheckCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/CheckCommandTest.java @@ -75,5 +75,4 @@ void testToString() { String expected = CheckCommand.class.getCanonicalName() + "{nric=" + ALICE.getNric() + "}"; assertEquals(expected, checkCommand.toString()); } - } diff --git a/src/test/java/seedu/address/logic/commands/DeleteInfoCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteInfoCommandTest.java index 23f974fdc2e..d1b62a69ecf 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteInfoCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteInfoCommandTest.java @@ -1,9 +1,13 @@ package seedu.address.logic.commands; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.NON_EXISTENT_NRIC; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NRIC_AMI; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -21,6 +25,13 @@ public class DeleteInfoCommandTest { private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + @Test + public void constructor_emptyInput_throwsException() { + Nric targetNric = new Nric(VALID_NRIC_AMI); + boolean[] fieldsToDelete = {true, true, true, true, true, true, true, true}; //too many fields + assertThrows(NullPointerException.class, () -> new DeleteInfoCommand(targetNric, null)); + assertThrows(NullPointerException.class, () -> new DeleteInfoCommand(null, fieldsToDelete)); + } @Test public void execute_deleteInfo_success() { Person personToDeleteInfo = new PersonBuilder(ALICE).withNric("T0278967B").build(); @@ -45,7 +56,6 @@ public void execute_deleteInfo_success() { assertEquals(expectedPerson, personToDeleteInfo); } - @Test public void execute_invalidNric_throwsCommandException() { Nric targetNric = new Nric(NON_EXISTENT_NRIC); @@ -54,4 +64,41 @@ public void execute_invalidNric_throwsCommandException() { assertCommandFailure(deleteInfoCommand, model, Messages.MESSAGE_PERSON_NOT_FOUND); } + + @Test + public void equals_equalInput_true() { + Nric targetNric = new Nric(VALID_NRIC_AMI); + boolean[] fieldsToDelete = {true, true, true, true, true, true, true, true}; + DeleteInfoCommand deleteInfoCommand = new DeleteInfoCommand(targetNric, fieldsToDelete); + DeleteInfoCommand deleteInfoCommandCopy = new DeleteInfoCommand(targetNric, fieldsToDelete); + + assertTrue(deleteInfoCommand.equals(deleteInfoCommandCopy)); //equivalent objects + assertTrue(deleteInfoCommand.equals(deleteInfoCommand)); //same objects + } + + @Test + public void equals_unequalInput_false() { + Nric targetNric = new Nric(VALID_NRIC_AMI); + boolean[] fieldsToDelete = {true, true, true, true, true, true, true, true}; + boolean[] otherFieldsToDelete = {true, true, true, true, true, true, true, false}; + DeleteInfoCommand deleteInfoCommand = new DeleteInfoCommand(targetNric, fieldsToDelete); + DeleteInfoCommand otherDeleteInfoCommand = new DeleteInfoCommand(targetNric, otherFieldsToDelete); + + assertFalse(deleteInfoCommand.equals(otherDeleteInfoCommand)); //other values + assertFalse(deleteInfoCommand.equals(null)); //null + assertFalse(deleteInfoCommand.equals(new CreateCommand(ALICE))); //different class + assertFalse(deleteInfoCommand.equals(new DeleteInfoCommand(new Nric("T0123456A"), fieldsToDelete))); + //different NRIC + } + + @Test + public void toStringTest() { + Nric targetNric = new Nric(VALID_NRIC_AMI); + boolean[] fieldsToDelete = {true, true, true, true, true, true, true, true}; + DeleteInfoCommand deleteInfoCommand = new DeleteInfoCommand(targetNric, fieldsToDelete); + String expected = DeleteInfoCommand.class.getCanonicalName() + "{targetNric=" + VALID_NRIC_AMI + + ", fieldsToDelete=" + "EMAIL,ALLERGIES,BLOODTYPE,DATEOFADMISSION," + + "COUNTRY,CONDITION,SYMPTOM,DIAGNOSIS,}"; + assertEquals(expected, deleteInfoCommand.toString()); + } } diff --git a/src/test/java/seedu/address/model/person/AddressTest.java b/src/test/java/seedu/address/model/person/AddressTest.java index 314885eca26..3fb6efcb2d9 100644 --- a/src/test/java/seedu/address/model/person/AddressTest.java +++ b/src/test/java/seedu/address/model/person/AddressTest.java @@ -20,14 +20,15 @@ public void constructor_invalidAddress_throwsIllegalArgumentException() { } @Test - public void isValidAddress() { + public void isValidAddress_invalidAddress_returnsFalse() { // null address assertThrows(NullPointerException.class, () -> Address.isValidAddress(null)); - // invalid addresses assertFalse(Address.isValidAddress("")); // empty string assertFalse(Address.isValidAddress(" ")); // spaces only - + } + @Test + public void isValidAddress_validAddress_returnsTrue() { // valid addresses assertTrue(Address.isValidAddress("Blk 456, Den Road, #01-355")); assertTrue(Address.isValidAddress("-")); // one character diff --git a/src/test/java/seedu/address/model/person/AllergiesTest.java b/src/test/java/seedu/address/model/person/AllergiesTest.java index 974a579360d..8a0008bfb24 100644 --- a/src/test/java/seedu/address/model/person/AllergiesTest.java +++ b/src/test/java/seedu/address/model/person/AllergiesTest.java @@ -2,12 +2,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; public class AllergiesTest { - - /* commented as Allergies can be null, and doesn't have regex @Test public void constructor_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new Allergies(null)); @@ -15,10 +14,25 @@ public void constructor_null_throwsNullPointerException() { @Test public void constructor_invalidAllergies_throwsIllegalArgumentException() { - String invalidAllergies = ""; - assertThrows(IllegalArgumentException.class, () -> new Allergies(invalidAllergies)); + assertThrows(IllegalArgumentException.class, () -> new Allergies("")); + assertThrows(IllegalArgumentException.class, () -> new Allergies(" ")); + } + + @Test + public void isValidAddress_invalidAllergies_returnsFalse() { + // null address + assertThrows(NullPointerException.class, () -> Allergies.isValidAllergies(null)); + // invalid addresses + assertFalse(Allergies.isValidAllergies("")); // empty string + assertFalse(Allergies.isValidAllergies(" ")); // spaces only + } + @Test + public void isValidAllergies_validAllergies_returnsTrue() { + // valid addresses + assertTrue(Allergies.isValidAllergies("peanut")); + assertTrue(Allergies.isValidAllergies("-")); // one character + assertTrue(Allergies.isValidAllergies("Pollen, Cat hair, Dog hair, Dust mites, Mold, Cockroach droppings")); } - */ @Test public void equals() { diff --git a/src/test/java/seedu/address/model/person/ConditionTest.java b/src/test/java/seedu/address/model/person/ConditionTest.java index d373765a694..b45e15853e9 100644 --- a/src/test/java/seedu/address/model/person/ConditionTest.java +++ b/src/test/java/seedu/address/model/person/ConditionTest.java @@ -2,23 +2,39 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; public class ConditionTest { - /* commented as Condition can be null, and doesn't have regex @Test public void constructor_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new Condition(null)); } @Test - public void constructor_invalidAddress_throwsIllegalArgumentException() { - String invalidCondition = ""; - assertThrows(IllegalArgumentException.class, () -> new Condition(invalidCondition)); + public void constructor_invalidCondition_throwsIllegalArgumentException() { + String invalidAddress = ""; + assertThrows(IllegalArgumentException.class, () -> new Condition("")); + assertThrows(IllegalArgumentException.class, () -> new Condition(" ")); + } + + @Test + public void isValidCondition_invalidCondition_returnsFalse() { + // null address + assertThrows(NullPointerException.class, () -> Condition.isValidCondition(null)); + // invalid addresses + assertFalse(Condition.isValidCondition("")); // empty string + assertFalse(Condition.isValidCondition(" ")); // spaces only + } + @Test + public void isValidAddress_validAddress_returnsTrue() { + // valid addresses + assertTrue(Condition.isValidCondition("Covid-19")); + assertTrue(Condition.isValidCondition("-")); // one character + assertTrue(Condition.isValidCondition("akdjfadncalakfoaiejfkndcldkckadjlckadlckaldkfjclkadjcfkj")); } - */ @Test public void equals() { diff --git a/src/test/java/seedu/address/model/person/CountryTest.java b/src/test/java/seedu/address/model/person/CountryTest.java index f40ea68b13e..bc7f271aa40 100644 --- a/src/test/java/seedu/address/model/person/CountryTest.java +++ b/src/test/java/seedu/address/model/person/CountryTest.java @@ -1,24 +1,40 @@ package seedu.address.model.person; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class CountryTest { - /* commented as Allergies can be null, and doesn't have regex @Test public void constructor_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new Country(null)); } @Test - public void constructor_invalidAddress_throwsIllegalArgumentException() { - String invalidCountry = ""; - assertThrows(IllegalArgumentException.class, () -> new Condition(invalidCountry)); + public void constructor_invalidCountry_throwsIllegalArgumentException() { + assertThrows(IllegalArgumentException.class, () -> new Country("")); + assertThrows(IllegalArgumentException.class, () -> new Country(" ")); + } + + @Test + public void isValidCountry_invalidCountry_returnsFalse() { + // null address + assertThrows(NullPointerException.class, () -> Country.isValidCountry(null)); + // invalid addresses + assertFalse(Country.isValidCountry("")); // empty string + assertFalse(Country.isValidCountry(" ")); // spaces only + } + + @Test + public void isValidCountry_validCountry_returnsTrue() { + // valid addresses + assertTrue(Country.isValidCountry("Singapore")); + assertTrue(Country.isValidCountry("-")); // one character + assertTrue(Country.isValidCountry("United States of America")); // long country } - */ @Test public void equals() { diff --git a/src/test/java/seedu/address/model/person/DateOfAdmissionTest.java b/src/test/java/seedu/address/model/person/DateOfAdmissionTest.java index 4098240cb14..d7196a755ea 100644 --- a/src/test/java/seedu/address/model/person/DateOfAdmissionTest.java +++ b/src/test/java/seedu/address/model/person/DateOfAdmissionTest.java @@ -2,30 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; public class DateOfAdmissionTest { - - /* commented as DateOfAdmission can be null, and doesn't have regex - @Test - public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new DateOfAdmission(null)); - } - @Test - public void constructor_invalidAddress_throwsIllegalArgumentException() { - String invalidDate = ""; - assertThrows(IllegalArgumentException.class, () -> new DateOfAdmission(invalidDate)); - } - */ - - @Test - public void isValidAddress() { - // null address - assertThrows(NullPointerException.class, () -> DateOfAdmission.isValidDateOfAdmission(null)); - + public void isValidDateOfAdmission() { // invalid addresses assertFalse(DateOfAdmission.isValidDateOfAdmission("")); // empty string assertFalse(DateOfAdmission.isValidDateOfAdmission(" ")); // spaces only diff --git a/src/test/java/seedu/address/model/person/DateOfBirthTest.java b/src/test/java/seedu/address/model/person/DateOfBirthTest.java index a948596a20c..c34d3a88b1b 100644 --- a/src/test/java/seedu/address/model/person/DateOfBirthTest.java +++ b/src/test/java/seedu/address/model/person/DateOfBirthTest.java @@ -20,10 +20,7 @@ public void constructor_invalidAddress_throwsIllegalArgumentException() { } @Test - public void isValidAddress() { - // null address - assertThrows(NullPointerException.class, () -> DateOfAdmission.isValidDateOfAdmission(null)); - + public void isValidDateOfBirth() { // invalid addresses assertFalse(DateOfAdmission.isValidDateOfAdmission("")); // empty string assertFalse(DateOfAdmission.isValidDateOfAdmission(" ")); // spaces only diff --git a/src/test/java/seedu/address/model/person/DiagnosisTest.java b/src/test/java/seedu/address/model/person/DiagnosisTest.java index de000fd74e2..5c349d2c371 100644 --- a/src/test/java/seedu/address/model/person/DiagnosisTest.java +++ b/src/test/java/seedu/address/model/person/DiagnosisTest.java @@ -2,23 +2,36 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; public class DiagnosisTest { - - /* commented as DateOfAdmission can be null, and doesn't have regex @Test public void constructor_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new Diagnosis(null)); } @Test - public void constructor_invalidAddress_throwsIllegalArgumentException() { - String invalidDiagnosis = ""; - assertThrows(IllegalArgumentException.class, () -> new Diagnosis(invalidDiagnosis)); + public void constructor_invalidSymptom_throwsIllegalArgumentException() { + assertThrows(IllegalArgumentException.class, () -> new Diagnosis("")); + assertThrows(IllegalArgumentException.class, () -> new Diagnosis(" ")); + } + @Test + public void isValidDiagnosis_invalidDiagnosis_returnsFalse() { + // null diagnosis + assertThrows(NullPointerException.class, () -> Diagnosis.isValidDiagnosis(null)); + // invalid diagnoses + assertFalse(Diagnosis.isValidDiagnosis("")); // empty string + assertFalse(Diagnosis.isValidDiagnosis(" ")); // spaces only + } + @Test + public void isValidDiagnosis_validDiagnosis_returnsTrue() { + // valid diagnoses + assertTrue(Diagnosis.isValidDiagnosis("Valid Diagnosis")); + assertTrue(Diagnosis.isValidDiagnosis("-")); // one character + assertTrue(Diagnosis.isValidDiagnosis("Longggggggggggg Didagnosis")); // long diagnosis } - */ @Test public void equals() { diff --git a/src/test/java/seedu/address/model/person/NricTest.java b/src/test/java/seedu/address/model/person/NricTest.java index 38a3ac56701..6bf20553e62 100644 --- a/src/test/java/seedu/address/model/person/NricTest.java +++ b/src/test/java/seedu/address/model/person/NricTest.java @@ -14,28 +14,39 @@ public void constructor_null_throwsNullPointerException() { } @Test - public void constructor_invalidAddress_throwsIllegalArgumentException() { + public void constructor_invalidNric_throwsIllegalArgumentException() { String invalidNric = ""; assertThrows(IllegalArgumentException.class, () -> new Nric(invalidNric)); } @Test - public void isValidAddress() { + public void isValidNric_null_throwNullPointerException() { // null address assertThrows(NullPointerException.class, () -> Nric.isValidNric(null)); + } + @Test + public void isValidNric_invalidNric_returnFalse() { // invalid addresses assertFalse(Nric.isValidNric("")); // empty string assertFalse(Nric.isValidNric(" ")); // spaces only assertFalse(Nric.isValidNric("0312345")); // numbers only - assertFalse(Nric.isValidNric("S0312345")); // without first letter - assertFalse(Nric.isValidNric("0312345A")); // without last letter + assertFalse(Nric.isValidNric("S0312345")); // without last letter + assertFalse(Nric.isValidNric("0312345A")); // without first letter assertFalse(Nric.isValidNric("T03123425A")); // too many numbers assertFalse(Nric.isValidNric("T031234A")); // too few numbers - assertFalse(Nric.isValidNric("D03123452S")); // invalid first number - + assertFalse(Nric.isValidNric("D0312345S")); // invalid first number + } + @Test + public void isValidNric_validNric_returnTrue() { // valid addresses assertTrue(Nric.isValidNric("T0912345A")); + assertTrue(Nric.isValidNric("S0412345G")); + } + @Test + public void toString_upperCaseNric_returnUpperCase() { + Nric nric = new Nric("T0412345G"); + assertTrue(nric.toString().equals("T0412345G")); } @Test diff --git a/src/test/java/seedu/address/model/person/SymptomTest.java b/src/test/java/seedu/address/model/person/SymptomTest.java index 89830c694f9..e2bca1229f7 100644 --- a/src/test/java/seedu/address/model/person/SymptomTest.java +++ b/src/test/java/seedu/address/model/person/SymptomTest.java @@ -2,23 +2,36 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; public class SymptomTest { - - /* commented as DateOfAdmission can be null, and doesn't have regex @Test public void constructor_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new Symptom(null)); } @Test - public void constructor_invalidAddress_throwsIllegalArgumentException() { - String invalidSymptom = ""; - assertThrows(IllegalArgumentException.class, () -> new Sex(invalidSymptom)); + public void constructor_invalidSymptom_throwsIllegalArgumentException() { + assertThrows(IllegalArgumentException.class, () -> new Symptom("")); + assertThrows(IllegalArgumentException.class, () -> new Symptom(" ")); + } + @Test + public void isValidSymptom_invalidSymptom_returnsFalse() { + // null symptom + assertThrows(NullPointerException.class, () -> Symptom.isValidSymptom(null)); + // invalid symptoms + assertFalse(Symptom.isValidSymptom("")); // empty string + assertFalse(Symptom.isValidSymptom(" ")); // spaces only + } + @Test + public void isValidSymptom_validSymptom_returnsTrue() { + // valid symptoms + assertTrue(Symptom.isValidSymptom("Valid Symptom")); + assertTrue(Symptom.isValidSymptom("-")); // one character + assertTrue(Symptom.isValidSymptom("Longggggggggggg Symptom")); // long symptom } - */ @Test public void equals() { diff --git a/src/test/java/seedu/address/testutil/PersonUtil.java b/src/test/java/seedu/address/testutil/PersonUtil.java index c82581f3cd6..cca2e91c122 100644 --- a/src/test/java/seedu/address/testutil/PersonUtil.java +++ b/src/test/java/seedu/address/testutil/PersonUtil.java @@ -57,7 +57,6 @@ public static String getPersonDetails(Person person) { */ public static String getEditPersonDescriptorDetails(UpdatePersonDescriptor descriptor) { StringBuilder sb = new StringBuilder(); - sb.append(PREFIX_NRIC).append(descriptor.getNric()).append(" "); assert descriptor.getName().isPresent() && descriptor.getPhone().isPresent() && descriptor.getAddress().isPresent() && descriptor.getDateOfBirth().isPresent() && descriptor.getSex().isPresent() && descriptor.getStatus().isPresent();