Skip to content

Commit

Permalink
Merge pull request #55 from nniiggeell/medical-status
Browse files Browse the repository at this point in the history
Medical History
  • Loading branch information
yongchuann authored Oct 12, 2021
2 parents 24603dc + ece95cf commit 7505065
Show file tree
Hide file tree
Showing 25 changed files with 590 additions and 67 deletions.
15 changes: 15 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
import seedu.address.model.Model;
import seedu.address.model.person.FormClass;
import seedu.address.model.person.Gender;
import seedu.address.model.person.MedicalHistory;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Student;

/**
* Edits the fields of an existing student in the New Address Book.
*/
public class EditStudentCommand extends EditCommand {

public static final String COMMAND_WORD = "editStudent";
Expand Down Expand Up @@ -72,7 +76,8 @@ private static Student createdEditedStudent(Student studentToEdit, EditStudentDe
editStudentDescriptor.getEmergencyContact().orElse(studentToEdit.getEmergencyContact());
FormClass updatedFormClass = editStudentDescriptor.getFormClass().orElse(studentToEdit.getFormClass());
Gender updatedGender = editStudentDescriptor.getGender().orElse(studentToEdit.getGender());
return new Student(person, updatedEmergencyContact, updatedFormClass, updatedGender);
MedicalHistory updatedMedicalHistory = studentToEdit.getMedicalHistory(); //edit command does not edit medical
return new Student(person, updatedEmergencyContact, updatedFormClass, updatedGender, updatedMedicalHistory);
}

@Override
Expand All @@ -84,14 +89,14 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Student personToEdit = (Student) lastShownList.get(index.getZeroBased());
Student editedStudent = createdEditedStudent(personToEdit, editStudentDescriptor);
Student studentToEdit = (Student) lastShownList.get(index.getZeroBased());
Student editedStudent = createdEditedStudent(studentToEdit, editStudentDescriptor);

if (!personToEdit.isSamePerson(editedStudent) && model.hasPerson(editedStudent)) {
if (!studentToEdit.isSamePerson(editedStudent) && model.hasPerson(editedStudent)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.setPerson(personToEdit, editedStudent);
model.setPerson(studentToEdit, editedStudent);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedStudent));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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);
}

Student studentToEdit = (Student) lastShownList.get(index.getZeroBased());
Student editedStudent = new Student(studentToEdit.getName(), studentToEdit.getPhone(), studentToEdit.getEmail(),
studentToEdit.getAddress(), studentToEdit.getInvolvement(), studentToEdit.getTags(),
studentToEdit.getEmergencyContact(), studentToEdit.getFormClass(), studentToEdit.getGender(),
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.student.AddStudentCommand;
import seedu.address.logic.commands.student.EditStudentCommand;
import seedu.address.logic.commands.student.MedicalHistoryCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.logic.parser.student.AddStudentCommandParser;
import seedu.address.logic.parser.student.EditStudentCommandParser;
import seedu.address.logic.parser.student.MedicalHistoryCommandParser;

/**
* Parses user input.
Expand Down Expand Up @@ -78,6 +80,9 @@ public Command parseCommand(String userInput) throws ParseException {
case FilterCommand.COMMAND_WORD:
return new FilterCommandParser().parse(arguments);

case MedicalHistoryCommand.COMMAND_WORD:
return new MedicalHistoryCommandParser().parse(arguments);

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public class CliSyntax {
public static final Prefix PREFIX_FORM_CLASS = new Prefix("f/");
public static final Prefix PREFIX_GENDER = new Prefix("g/");
public static final Prefix PREFIX_COPY_FIELD = new Prefix("c/");
public static final Prefix PREFIX_MEDICAL_HISTORY = new Prefix("m/");
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.model.person.FormClass;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Involvement;
import seedu.address.model.person.MedicalHistory;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Student;
Expand Down Expand Up @@ -66,9 +67,9 @@ public StudentCommand parse(String args) throws ParseException {
Phone emergencyContact = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_EMERGENCY_CONTACT).get());
FormClass formClass = ParserUtil.parseFormClass(argMultimap.getValue(PREFIX_FORM_CLASS).get());
Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get());

MedicalHistory medicalHistory = new MedicalHistory(""); //adding student does not allow adding medical
Student student = new Student(name, phone, email, address, involvement, tagList, emergencyContact, formClass,
gender);
gender, medicalHistory);

return new StudentCommand(student);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import seedu.address.model.person.FormClass;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Involvement;
import seedu.address.model.person.MedicalHistory;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Student;
Expand Down Expand Up @@ -67,9 +68,9 @@ public AddStudentCommand parse(String args) throws ParseException {
Phone emergencyContact = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_EMERGENCY_CONTACT).get());
FormClass formClass = ParserUtil.parseFormClass(argMultimap.getValue(PREFIX_FORM_CLASS).get());
Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get());

MedicalHistory medicalHistory = new MedicalHistory(""); //add command does not allow medical
Student student = new Student(name, phone, email, address, involvement, tagList, emergencyContact, formClass,
gender);
gender, medicalHistory);

return new AddStudentCommand(student);
}
Expand Down
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));
}
}
38 changes: 38 additions & 0 deletions src/main/java/seedu/address/model/person/MedicalHistory.java
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();
}
}
25 changes: 21 additions & 4 deletions src/main/java/seedu/address/model/person/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Student extends Person {
private Phone emergencyContact;
private FormClass formClass;
private Gender gender;
private MedicalHistory medicalHistory;

/**
* Constructor for {@code Student}
Expand All @@ -25,14 +26,15 @@ public class Student extends Person {
* @param emergencyContact Emergency contact of student
* @param formClass Form Class of Student
* @param gender Gender of student
* @param medicalHistory Medical History of student
*/

public Student(Name name, Phone phone, Email email, Address address, Involvement involvement, Set<Tag> tags,
Phone emergencyContact, FormClass formClass, Gender gender) {
Phone emergencyContact, FormClass formClass, Gender gender, MedicalHistory medicalHistory) {
super(name, phone, email, address, involvement, tags);
this.emergencyContact = emergencyContact;
this.formClass = formClass;
this.gender = gender;
this.medicalHistory = medicalHistory;
}

/**
Expand All @@ -42,14 +44,17 @@ public Student(Name name, Phone phone, Email email, Address address, Involvement
* @param emergencyContact Emergency contact of student
* @param formClass Form Class of Student
* @param gender Gender of student
* @param medicalHistory Medical History of student
*/

public Student(Person person, Phone emergencyContact, FormClass formClass, Gender gender) {
public Student(Person person, Phone emergencyContact, FormClass formClass, Gender gender,
MedicalHistory medicalHistory) {
super(person.getName(), person.getPhone(), person.getEmail(), person.getAddress(), person.getInvolvement(),
person.getTags());
this.emergencyContact = emergencyContact;
this.formClass = formClass;
this.gender = gender;
this.medicalHistory = medicalHistory;
}

public Phone getEmergencyContact() {
Expand All @@ -64,6 +69,10 @@ public Gender getGender() {
return this.gender;
}

public MedicalHistory getMedicalHistory() {
return this.medicalHistory;
}

/**
* Returns true if both person are students, and have the same identity and data fields.
* This defines a stronger notion of equality between two students.
Expand All @@ -86,6 +95,14 @@ public boolean equals(Object other) {

@Override
public String toString() {
return super.toString() + "; " + String.format("Emergency contact: %s", getEmergencyContact());
return super.toString()
+ "; "
+ String.format("Emergency contact: %s", getEmergencyContact())
+ "; "
+ String.format("Form class: %s", getFormClass())
+ "; "
+ String.format("Gender: %s", getGender())
+ "; "
+ String.format("Medical History: %s", getMedicalHistory());
}
}
Loading

0 comments on commit 7505065

Please sign in to comment.