diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index a434a38c20d..efdac2bb1b2 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -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; /** @@ -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 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) { @@ -138,6 +151,11 @@ public static class EditPatientDescriptor { private Email email; private Address address; private Set tags; + private Gender gender; + private Birthday birthday; + private IcNumber icNumber; + private AssignedDepartment department; + private Record record; public EditPatientDescriptor() {} @@ -192,6 +210,25 @@ public Optional
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 getRecord() { + return Optional.ofNullable(record); + } + /** * Sets {@code tags} to this object's {@code tags}. * A defensive copy of {@code tags} is used internally. @@ -228,6 +265,38 @@ public boolean equals(Object other) { && Objects.equals(tags, otherEditPatientDescriptor.tags); } + public void setGender(Gender gender) { + this.gender = gender; + } + + public Optional getGender() { + return Optional.ofNullable(gender); + } + + public void setBirthday(Birthday birthday) { + this.birthday = birthday; + } + + public Optional getBirthday() { + return Optional.ofNullable(birthday); + } + + public void setIcNumber(IcNumber icNumber) { + this.icNumber = icNumber; + } + + public Optional getIcNumber() { + return Optional.ofNullable(icNumber); + } + + public void setDepartment(AssignedDepartment department) { + this.department = department; + } + + public Optional getDepartment() { + return Optional.ofNullable(department); + } + @Override public String toString() { return new ToStringBuilder(this) diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 34f4548df73..6ffc43ff248 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -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; @@ -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 */ @@ -32,7 +41,8 @@ public class EditCommandParser implements Parser { 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; @@ -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()); + } + parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPatientDescriptor::setTags); if (!editPatientDescriptor.isAnyFieldEdited()) { diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index d4b34666a2e..7aa074c664c 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -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; @@ -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 @@ -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 tags} into a {@code Set}. */