From db2d3a33913f52a2ff93c1e30e6f4f6a0d3044d0 Mon Sep 17 00:00:00 2001 From: nniiggeell Date: Tue, 12 Oct 2021 18:31:05 +0800 Subject: [PATCH 1/8] Add MedicalHistory command --- .../commands/student/EditStudentCommand.java | 15 +++++++---- .../logic/parser/AddressBookParser.java | 5 ++++ .../seedu/address/logic/parser/CliSyntax.java | 1 + .../logic/parser/StudentCommandParser.java | 5 ++-- .../student/AddStudentCommandParser.java | 5 ++-- .../seedu/address/model/person/Student.java | 25 ++++++++++++++++--- .../address/model/util/SampleDataUtil.java | 18 ++++++++----- .../address/storage/JsonAdaptedStudent.java | 22 +++++++++++++--- 8 files changed, 73 insertions(+), 23 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java b/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java index 05f2fc2b97e..69767704217 100644 --- a/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java +++ b/src/main/java/seedu/address/logic/commands/student/EditStudentCommand.java @@ -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"; @@ -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 @@ -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)); } diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index b6c23f2eda2..23eb28685db 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -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. @@ -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); } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 6f07369134a..379932a8f61 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -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/"); } diff --git a/src/main/java/seedu/address/logic/parser/StudentCommandParser.java b/src/main/java/seedu/address/logic/parser/StudentCommandParser.java index 0e75d356a54..33e50d57123 100644 --- a/src/main/java/seedu/address/logic/parser/StudentCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/StudentCommandParser.java @@ -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; @@ -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); } diff --git a/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java b/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java index d06a388ee81..a403fe76bea 100644 --- a/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/student/AddStudentCommandParser.java @@ -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; @@ -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); } diff --git a/src/main/java/seedu/address/model/person/Student.java b/src/main/java/seedu/address/model/person/Student.java index 908b0d5c436..8912e611b16 100644 --- a/src/main/java/seedu/address/model/person/Student.java +++ b/src/main/java/seedu/address/model/person/Student.java @@ -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} @@ -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 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; } /** @@ -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() { @@ -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. @@ -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()); } } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 4f6206d00cc..b786c081d34 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -11,6 +11,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.Person; import seedu.address.model.person.Phone; @@ -22,27 +23,32 @@ */ public class SampleDataUtil { public static Student[] getSamplePersons() { + MedicalHistory emptyMedicalHistory = new MedicalHistory(""); return new Student[] { new Student(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), new Involvement("Math class"), - getTagSet("friends"), new Phone("91934131"), new FormClass("1E1"), new Gender("M")), + getTagSet("friends"), new Phone("91934131"), new FormClass("1E1"), new Gender("M"), + emptyMedicalHistory), new Student(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new Involvement("Badminton CCA"), getTagSet("colleagues", "friends"), new Phone("95614132"), new FormClass("1E4"), - new Gender("F")), + new Gender("F"), emptyMedicalHistory), new Student(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new Involvement("Bio class"), - getTagSet("neighbours"), new Phone("90234134"), new FormClass("3Bio5"), new Gender("F")), + getTagSet("neighbours"), new Phone("90234134"), new FormClass("3Bio5"), new Gender("F"), + emptyMedicalHistory), new Student(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new Involvement("Math class"), - getTagSet("family"), new Phone("81934910"), new FormClass("2Science2"), new Gender("M")), + getTagSet("family"), new Phone("81934910"), new FormClass("2Science2"), new Gender("M"), + emptyMedicalHistory), new Student(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), new Involvement("Math class"), getTagSet("classmates"), new Phone("94893113"), new FormClass("Sec 3 Pure Geography"), - new Gender("N")), + new Gender("N"), emptyMedicalHistory), new Student(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), new Involvement("Math class"), - getTagSet("colleagues"), new Phone("91919301"), new FormClass("3 NORMAL 2"), new Gender("N")) + getTagSet("colleagues"), new Phone("91919301"), new FormClass("3 NORMAL 2"), new Gender("N"), + emptyMedicalHistory) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedStudent.java b/src/main/java/seedu/address/storage/JsonAdaptedStudent.java index de7c213fdc6..69e1b6c9a1e 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedStudent.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedStudent.java @@ -14,6 +14,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; @@ -30,6 +31,7 @@ class JsonAdaptedStudent extends JsonAdaptedPerson { private final String emergencyContact; private final String formClass; private final String gender; + private final String medicalHistory; /** * Constructs a {@code JsonAdaptedPerson} with the given student details. @@ -41,16 +43,18 @@ public JsonAdaptedStudent(@JsonProperty("name") String name, @JsonProperty("phon @JsonProperty("tagged") List tagged, @JsonProperty("emergencyContact") String emergencyContact, @JsonProperty("formClass") String formClass, - @JsonProperty("gender") String gender) { + @JsonProperty("gender") String gender, + @JsonProperty("medicalHistory") String medicalHistory) { super(name, phone, email, involvement, tagged); this.address = address; this.emergencyContact = emergencyContact; this.formClass = formClass; this.gender = gender; + this.medicalHistory = medicalHistory; } /** - * Converts a given {@code Person} into this class for Jackson use. + * Converts a given {@code Student} into this class for Jackson use. */ public JsonAdaptedStudent(Student source) { super(source); @@ -58,6 +62,7 @@ public JsonAdaptedStudent(Student source) { this.emergencyContact = source.getEmergencyContact().value; this.formClass = source.getFormClass().formClass; this.gender = source.getGender().gender; + this.medicalHistory = source.getMedicalHistory().value; } /** @@ -128,6 +133,8 @@ public Student toModelType() throws IllegalValueException { if (!FormClass.isValidFormClass(formClass)) { throw new IllegalValueException(FormClass.MESSAGE_CONSTRAINTS); } + final FormClass modelFormClass = new FormClass(formClass); + if (gender == null) { throw new IllegalValueException(String.format( MISSING_FIELD_MESSAGE_FORMAT, Gender.class.getSimpleName())); @@ -135,8 +142,15 @@ public Student toModelType() throws IllegalValueException { if (!Gender.isValidGender(gender)) { throw new IllegalValueException(Gender.MESSAGE_CONSTRAINTS); } - final FormClass modelFormClass = new FormClass(formClass); + final Gender modelGender = new Gender(gender); + + if (medicalHistory == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + MedicalHistory.class.getSimpleName())); + } + final MedicalHistory modelMedicalHistory = new MedicalHistory(medicalHistory); + return new Student(modelName, modelPhone, modelEmail, modelAddress, modelInvolvement, - modelTags, modelEmergencyContact, modelFormClass, new Gender(gender)); + modelTags, modelEmergencyContact, modelFormClass, modelGender, modelMedicalHistory); } } From df13301687ef1a57d29edff69eab39e0013827e5 Mon Sep 17 00:00:00 2001 From: nniiggeell Date: Tue, 12 Oct 2021 18:31:19 +0800 Subject: [PATCH 2/8] Add medical history label --- src/main/java/seedu/address/ui/StudentCard.java | 3 +++ src/main/resources/view/PersonListCard.fxml | 1 + 2 files changed, 4 insertions(+) diff --git a/src/main/java/seedu/address/ui/StudentCard.java b/src/main/java/seedu/address/ui/StudentCard.java index fa4017789c9..207271ff20d 100644 --- a/src/main/java/seedu/address/ui/StudentCard.java +++ b/src/main/java/seedu/address/ui/StudentCard.java @@ -48,6 +48,8 @@ public class StudentCard extends UiPart { private Label formClass; @FXML private Label gender; + @FXML + private Label medicalHistory; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -62,6 +64,7 @@ public StudentCard(Student student, int displayedIndex) { email.setText(student.getEmail().value); formClass.setText(student.getFormClass().formClass); gender.setText(student.getGender().gender); + medicalHistory.setText(student.getMedicalHistory().value); involvement.setText(student.getInvolvement().involvement); student.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index b0064e289d2..1bb66d0ad14 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -32,6 +32,7 @@