Skip to content

Commit

Permalink
Merge pull request #208 from laney0808/update-parsers
Browse files Browse the repository at this point in the history
Update documentation and parsers
  • Loading branch information
jovantanyk authored Apr 10, 2024
2 parents 8e1bcdb + de5b5b0 commit ad55575
Show file tree
Hide file tree
Showing 29 changed files with 337 additions and 107 deletions.
43 changes: 24 additions & 19 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ Creates a patient profile in ImmuniMate.

Format: `create ic/<NRIC> n/<Patient_Name> hp/<Phone_Number> a/<Address> dob/<Date_of_birth> s/<Sex> st/<Status> [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/[email protected] 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/[email protected] 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.
Expand All @@ -106,6 +110,7 @@ Format: `update <NRIC> <Field>/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/[email protected]` Updates the phone number and email address of the corresponding patient to be `91234567` and `[email protected]` respectively.
Expand Down Expand Up @@ -201,7 +206,7 @@ Format: `addvisit ic/<NRIC> dov/<Date_of_Visit> sym/<Symptoms> d/<Diagnosis> 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.
Expand Down Expand Up @@ -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 |
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public DeleteCommand(Nric targetNric) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

ObservableList<Person> persons = model.getFilteredPersonList();
if (!model.hasPerson(Person.createPersonWithNric(targetNric))) {
throw new CommandException(Messages.MESSAGE_PERSON_NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -51,7 +49,6 @@ public DeleteInfoCommand(Nric targetNric, boolean[] fieldsToDelete) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

ObservableList<Person> persons = model.getFilteredPersonList();
if (!model.hasPerson(Person.createPersonWithNric(targetNric))) {
throw new CommandException(Messages.MESSAGE_PERSON_NOT_FOUND);
Expand Down Expand Up @@ -98,7 +95,6 @@ private boolean fieldsToDeleteEquals(boolean[] otherFieldsToDelete) {
}
return true;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/address/model/person/Allergies.java
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/seedu/address/model/person/Condition.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/seedu/address/model/person/Country.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/seedu/address/model/person/DateOfAdmission.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -20,14 +23,23 @@ 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);
}

/**
* 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;
}

/**
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/seedu/address/model/person/DateOfBirth.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
}
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/model/person/Diagnosis.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit ad55575

Please sign in to comment.