Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EditCommand.java, EditCommandParser.java, and ParserUtil.java #103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.patient.Address;
import seedu.address.model.patient.AssignedDepartment;
import seedu.address.model.patient.Birthday;
import seedu.address.model.patient.Email;
import seedu.address.model.patient.Gender;
import seedu.address.model.patient.IcNumber;
import seedu.address.model.patient.Name;
import seedu.address.model.patient.Patient;
import seedu.address.model.patient.Phone;
import seedu.address.model.patient.Record;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -98,12 +103,20 @@ private static Patient createEditedPatient(Patient patientToEdit, EditPatientDes
Name updatedName = editPatientDescriptor.getName().orElse(patientToEdit.getName());
Phone updatedPhone = editPatientDescriptor.getPhone().orElse(patientToEdit.getPhone());
Email updatedEmail = editPatientDescriptor.getEmail().orElse(patientToEdit.getEmail());
Gender updatedGender = editPatientDescriptor.getGender().orElse(patientToEdit.getGender());
IcNumber updatedIcNumber = editPatientDescriptor.getIcNumber().orElse(patientToEdit.getIcNumber());
Birthday updatedBirthday = editPatientDescriptor.getBirthday().orElse(patientToEdit.getBirthday());
Address updatedAddress = editPatientDescriptor.getAddress().orElse(patientToEdit.getAddress());
AssignedDepartment updatedDepartment = editPatientDescriptor.getDepartment().orElse(
patientToEdit.getAssignedDepartment());
Set<Tag> updatedTags = editPatientDescriptor.getTags().orElse(patientToEdit.getTags());
Record updatedRecord = editPatientDescriptor.getRecord().orElse(patientToEdit.getRecord());

return new Patient(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Patient(updatedName, updatedPhone, updatedEmail, updatedGender, updatedIcNumber,
updatedBirthday, updatedAddress, updatedTags, updatedDepartment, updatedRecord);
}


@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down Expand Up @@ -138,6 +151,11 @@ public static class EditPatientDescriptor {
private Email email;
private Address address;
private Set<Tag> tags;
private Gender gender;
private Birthday birthday;
private IcNumber icNumber;
private AssignedDepartment department;
private Record record;

public EditPatientDescriptor() {}

Expand Down Expand Up @@ -192,6 +210,25 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setRecord(Record record) {
this.record = record;
}

public void setInitialObservation(String initialObservation) {
record.setInitialObservations(initialObservation);
}

public void setTreatmentPlan(String treatmentPlan) {
record.setTreatmentPlan(treatmentPlan);
}

public void setDiagnosis(String diagnosis) {
record.setDiagnosis(diagnosis);
}
public Optional<Record> getRecord() {
return Optional.ofNullable(record);
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
Expand Down Expand Up @@ -228,6 +265,38 @@ public boolean equals(Object other) {
&& Objects.equals(tags, otherEditPatientDescriptor.tags);
}

public void setGender(Gender gender) {
this.gender = gender;
}

public Optional<Gender> getGender() {
return Optional.ofNullable(gender);
}

public void setBirthday(Birthday birthday) {
this.birthday = birthday;
}

public Optional<Birthday> getBirthday() {
return Optional.ofNullable(birthday);
}

public void setIcNumber(IcNumber icNumber) {
this.icNumber = icNumber;
}

public Optional<IcNumber> getIcNumber() {
return Optional.ofNullable(icNumber);
}

public void setDepartment(AssignedDepartment department) {
this.department = department;
}

public Optional<AssignedDepartment> getDepartment() {
return Optional.ofNullable(department);
}

@Override
public String toString() {
return new ToStringBuilder(this)
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIRTHDAY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DIAGNOSIS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC_NUMBER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_INITIAL_OBSERVATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TREATMENT_PLAN;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -19,6 +26,8 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.tag.Tag;



/**
* Parses input arguments and creates a new EditCommand object
*/
Expand All @@ -32,7 +41,8 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG,
PREFIX_GENDER, PREFIX_BIRTHDAY, PREFIX_IC_NUMBER, PREFIX_DEPARTMENT);

Index index;

Expand All @@ -58,6 +68,29 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) {
editPatientDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()));
}
if (argMultimap.getValue(PREFIX_GENDER).isPresent()) {
editPatientDescriptor.setGender(ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()));
}
if (argMultimap.getValue(PREFIX_BIRTHDAY).isPresent()) {
editPatientDescriptor.setBirthday(ParserUtil.parseBirthday(argMultimap.getValue(PREFIX_BIRTHDAY).get()));
}
if (argMultimap.getValue(PREFIX_IC_NUMBER).isPresent()) {
editPatientDescriptor.setIcNumber(ParserUtil.parseIcNumber(argMultimap.getValue(PREFIX_IC_NUMBER).get()));
}
if (argMultimap.getValue(PREFIX_DEPARTMENT).isPresent()) {
editPatientDescriptor.setDepartment(ParserUtil.parseAssignedDepartment(
argMultimap.getValue(PREFIX_DEPARTMENT).get()));
}
if (argMultimap.getValue(PREFIX_INITIAL_OBSERVATION).isPresent()) {
editPatientDescriptor.setInitialObservation(argMultimap.getValue(PREFIX_INITIAL_OBSERVATION).get());
}
if (argMultimap.getValue(PREFIX_DIAGNOSIS).isPresent()) {
editPatientDescriptor.setDiagnosis(argMultimap.getValue(PREFIX_DIAGNOSIS).get());
}
if (argMultimap.getValue(PREFIX_TREATMENT_PLAN).isPresent()) {
editPatientDescriptor.setTreatmentPlan(argMultimap.getValue(PREFIX_TREATMENT_PLAN).get());
}

Comment on lines +71 to +93

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you have implemented the same checks as previous attributes. Good job!

parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPatientDescriptor::setTags);

if (!editPatientDescriptor.isAnyFieldEdited()) {
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you have implemented Riya's task for this week. Would be good to discuss with her about this!!

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.patient.Address;
import seedu.address.model.patient.AssignedDepartment;
import seedu.address.model.patient.Birthday;
import seedu.address.model.patient.Email;
import seedu.address.model.patient.Gender;
import seedu.address.model.patient.IcNumber;
import seedu.address.model.patient.Name;
import seedu.address.model.patient.Phone;
import seedu.address.model.tag.Tag;
Expand All @@ -21,6 +25,8 @@
public class ParserUtil {

public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer.";
public static final String MESSAGE_CONSTRAINTS = "Department name is invalid. "
+ "Please enter a valid department name.";

/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
Expand Down Expand Up @@ -110,6 +116,66 @@ public static Tag parseTag(String tag) throws ParseException {
return new Tag(trimmedTag);
}

/**
* Parses a {@code String gender} into a {@code Gender}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code gender} is invalid.
*/
public static Gender parseGender(String gender) throws ParseException {
requireNonNull(gender);
String trimmedGender = gender.trim();
if (!Gender.isValidGender(trimmedGender)) {
throw new ParseException(Gender.MESSAGE_CONSTRAINTS);
}
return new Gender(trimmedGender);
}

/**
* Parses a {@code String birthday} into a {@code Birthday}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code birthday} is invalid.
*/
public static Birthday parseBirthday(String birthday) throws ParseException {
requireNonNull(birthday);
String trimmedBirthday = birthday.trim();
if (!Birthday.isValidBirthdate(trimmedBirthday)) {
throw new ParseException(Birthday.MESSAGE_CONSTRAINTS);
}
return new Birthday(trimmedBirthday);
}

/**
* Parses a {@code String icNumber} into a {@code IcNumber}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code icNumber} is invalid.
*/
public static IcNumber parseIcNumber(String icNumber) throws ParseException {
requireNonNull(icNumber);
String trimmedIcNumber = icNumber.trim();
if (!IcNumber.isValidIC(trimmedIcNumber)) {
throw new ParseException(IcNumber.MESSAGE_CONSTRAINTS);
}
return new IcNumber(trimmedIcNumber);
}

/**
* Parses a {@code String department} into a {@code Department}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code department} is invalid.
*/
public static AssignedDepartment parseAssignedDepartment(String department) throws ParseException {
requireNonNull(department);
String trimmedDepartment = department.trim();
if (!AssignedDepartment.isValidDepartment(trimmedDepartment)) {
throw new ParseException(AssignedDepartment.MESSAGE_CONSTRAINTS);
}
return new AssignedDepartment(trimmedDepartment);
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>}.
*/
Expand Down
Loading