forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-teacher-features
- Loading branch information
Showing
28 changed files
with
608 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,21 @@ Examples: | |
* `teacher n/Lebron p/91234567 e/[email protected] a/George street, block 123, #01-01 i/Math HOD | ||
t/relief` | ||
|
||
### Adding a medical history to a student: `medical` | ||
|
||
Adds a medical history to an existing student in NewAddressBook. | ||
|
||
Format: `medical INDEX m/MEDICAL_HISTORY` | ||
|
||
<div markdown="span" class="alert alert-primary">:bulb: **Tip:** | ||
Edits the student at the specified index. The index must be a positive integer. | ||
To edit an existing medical history, simply use the same command, which will overwrite | ||
the current medical history. | ||
</div> | ||
|
||
Examples: | ||
* `medical 1 m/ADHD` | ||
|
||
### Listing all persons : `list` | ||
|
||
Shows a list of all persons stored in NewAddressBook. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/seedu/address/logic/commands/student/MedicalHistoryCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package seedu.address.logic.commands.student; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.MedicalHistory; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Student; | ||
|
||
/** | ||
* Changes the medical history of an existing student inside the New Address Book. | ||
*/ | ||
public class MedicalHistoryCommand extends Command { | ||
public static final String COMMAND_WORD = "medical"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Edits the medical history of the person identified " | ||
+ "by the index number used in the last person listing. " | ||
+ "Existing medical history will be overwritten by the input.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "m/ [MEDICAL_HISTORY]\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ "m/ ADHD"; | ||
|
||
public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Medical_History: %2$s"; | ||
public static final String MESSAGE_ADD_MEDICAL_HISTORY_SUCCESS = "Added medical history to Person: %1$s"; | ||
public static final String MESSAGE_DELETE_MEDICAL_HISTORY_SUCCESS = "Removed medical history from Person: %1$s"; | ||
|
||
private final Index index; | ||
private final MedicalHistory medicalHistory; | ||
|
||
/** | ||
* @param index of the student in the filtered person list to edit the {@code MedicalHistory} | ||
* @param medicalHistory of the student to be updated to | ||
*/ | ||
public MedicalHistoryCommand(Index index, MedicalHistory medicalHistory) { | ||
requireAllNonNull(index, medicalHistory); | ||
|
||
this.index = index; | ||
this.medicalHistory = medicalHistory; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
if (!(personToEdit instanceof Student)) { | ||
throw new CommandException("You cannot add medical history to a teacher!"); | ||
} | ||
Student studentToEdit = (Student) personToEdit; | ||
Student editedStudent = new Student(studentToEdit, studentToEdit.getEmergencyContact(), | ||
studentToEdit.getFormClass(), studentToEdit.getAddress(), medicalHistory); | ||
|
||
model.setPerson(studentToEdit, editedStudent); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(generateSuccessMessage(editedStudent)); | ||
} | ||
|
||
/** | ||
* Generates a command execution success message based on whether | ||
* the medical history is added to or removed from | ||
* {@code studentToEdit}. | ||
*/ | ||
private String generateSuccessMessage(Student studentToEdit) { | ||
String message = !medicalHistory.value.isEmpty() ? MESSAGE_ADD_MEDICAL_HISTORY_SUCCESS | ||
: MESSAGE_DELETE_MEDICAL_HISTORY_SUCCESS; | ||
return String.format(message, studentToEdit); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MedicalHistoryCommand)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
MedicalHistoryCommand e = (MedicalHistoryCommand) other; | ||
return index.equals(e.index) | ||
&& medicalHistory.equals(e.medicalHistory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/seedu/address/logic/parser/student/MedicalHistoryCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package seedu.address.logic.parser.student; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MEDICAL_HISTORY; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.student.MedicalHistoryCommand; | ||
import seedu.address.logic.parser.ArgumentMultimap; | ||
import seedu.address.logic.parser.ArgumentTokenizer; | ||
import seedu.address.logic.parser.Parser; | ||
import seedu.address.logic.parser.ParserUtil; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.MedicalHistory; | ||
|
||
/** | ||
* Parses input arguments and creates a new {@code MedicalHistoryCommand} object. | ||
*/ | ||
public class MedicalHistoryCommandParser implements Parser<MedicalHistoryCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the MedicalHistoryCommand | ||
* and returns an MedicalHistoryCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public MedicalHistoryCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, | ||
PREFIX_MEDICAL_HISTORY); | ||
|
||
Index index; | ||
try { | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
} catch (IllegalValueException ive) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MedicalHistoryCommand.MESSAGE_USAGE), ive); | ||
} | ||
|
||
String medicalHistory = argMultimap.getValue(PREFIX_MEDICAL_HISTORY).orElse(""); | ||
|
||
return new MedicalHistoryCommand(index, new MedicalHistory(medicalHistory)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/seedu/address/model/person/MedicalHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package seedu.address.model.person; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Represents a Student's medical history in the address book. | ||
* Guarantees: immutable; is always valid | ||
*/ | ||
public class MedicalHistory { | ||
public final String value; | ||
|
||
/** | ||
* Constructs a {@code MedicalHistory}. | ||
* | ||
* @param medicalHistory A medicalHistory. | ||
*/ | ||
public MedicalHistory(String medicalHistory) { | ||
requireNonNull(medicalHistory); | ||
value = medicalHistory; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof MedicalHistory // instanceof handles nulls | ||
&& value.equals(((MedicalHistory) other).value)); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.