Skip to content

Commit

Permalink
Merge branch 'master' into add-teacher-features
Browse files Browse the repository at this point in the history
  • Loading branch information
g4ryy committed Oct 12, 2021
2 parents 9f633bb + 7505065 commit 6134b6e
Show file tree
Hide file tree
Showing 28 changed files with 608 additions and 60 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 @@ -18,10 +18,14 @@
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.FormClass;
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 TARGET = "student";
public static final String COMMAND_WORD = "editStudent";
Expand Down Expand Up @@ -60,7 +64,8 @@ private static Student createdEditedStudent(Student studentToEdit, EditStudentDe
editStudentDescriptor.getEmergencyContact().orElse(studentToEdit.getEmergencyContact());
FormClass updatedFormClass = editStudentDescriptor.getFormClass().orElse(studentToEdit.getFormClass());
Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress());
return new Student(person, updatedEmergencyContact, updatedFormClass, updatedAddress);
MedicalHistory updatedMedicalHistory = studentToEdit.getMedicalHistory(); //edit command does not edit medical
return new Student(person, updatedEmergencyContact, updatedFormClass, updatedAddress, updatedMedicalHistory);
}

@Override
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
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.commands.teacher.AddTeacherCommand;
import seedu.address.logic.commands.teacher.EditTeacherCommand;
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;
import seedu.address.logic.parser.teacher.AddTeacherCommandParser;
import seedu.address.logic.parser.teacher.EditTeacherCommandParser;

Expand Down Expand Up @@ -88,6 +90,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 @@ -17,4 +17,5 @@ public class CliSyntax {
public static final Prefix PREFIX_GENDER = new Prefix("g/");
public static final Prefix PREFIX_OFFICE_TABLE = new Prefix("o/");
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 @@ -67,10 +67,8 @@ 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());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Student student = new Student(name, phone, email, gender, involvement, address, emergencyContact, formClass,
tagList);

return new AddStudentCommand(student);
}
}
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public AddTeacherCommand parse(String args) throws ParseException {
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Teacher teacher = new Teacher(name, phone, email, gender, involvement, tableNumber, tagList);

return new AddTeacherCommand(teacher);
}
}
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();
}
}
48 changes: 36 additions & 12 deletions src/main/java/seedu/address/model/person/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
*/
public class Student extends Person {

private final Phone emergencyContact;
private final FormClass formClass;
private final Address address;
private Phone emergencyContact;
private FormClass formClass;
private Address address;
private MedicalHistory medicalHistory;

/**
* Constructor for {@code Student}
* Constructor for {@code Student} with every fields present
* @param name Name of student
* @param phone Phone number of student
* @param email Email of 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 tags Tags associated to student
* @param medicalHistory Medical History of student
*/

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

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

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

/**
* Constructor for {@code Student} without medical history
*
*/
public Student(Name name, Phone phone, Email email, Gender gender, Involvement involvement, Address address,
Phone emergencyContact, FormClass formClass, Set<Tag> tags) {
this(name, phone, email, gender, involvement, address,
emergencyContact, formClass, tags, new MedicalHistory(""));
}

public Phone getEmergencyContact() {
Expand All @@ -64,6 +78,10 @@ public Address getAddress() {
return this.address;
}

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 @@ -82,13 +100,19 @@ public boolean equals(Object other) {
return super.equals(otherStudent)
&& this.getEmergencyContact().equals(otherStudent.getEmergencyContact())
&& this.getFormClass().equals(otherStudent.getFormClass())
&& this.getAddress().equals(otherStudent.getAddress());
&& this.getAddress().equals(otherStudent.getAddress())
&& this.getMedicalHistory().equals(otherStudent.getMedicalHistory());
}

@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("Address: %s", getAddress());
+ "; "
+ String.format("Address: %s", getAddress())
+ "; "
+ String.format("Medical History: %s", getMedicalHistory());
}
}
Loading

0 comments on commit 6134b6e

Please sign in to comment.