diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index efdac2bb1b2..d8595735a98 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -41,17 +41,12 @@ public class EditCommand extends Command { public static final String COMMAND_WORD = "edit"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the patient identified " - + "by the index number used in the displayed patient list. " - + "Existing values will be overwritten by the input values.\n" - + "Parameters: INDEX (must be a positive integer) " - + "[" + PREFIX_NAME + "NAME] " - + "[" + PREFIX_PHONE + "PHONE] " - + "[" + PREFIX_EMAIL + "EMAIL] " - + "[" + PREFIX_ADDRESS + "ADDRESS] " - + "[" + PREFIX_TAG + "TAG]...\n" - + "Example: " + COMMAND_WORD + " 1 " - + PREFIX_PHONE + "91234567 " - + PREFIX_EMAIL + "johndoe@example.com"; + + "by the index number used in the displayed patient list. " + + "Existing values will be overwritten by the input values.\n" + + "Parameters: INDEX (must be a positive integer) " + "[" + PREFIX_NAME + "NAME] " + "[" + PREFIX_PHONE + + "PHONE] " + "[" + PREFIX_EMAIL + "EMAIL] " + "[" + PREFIX_ADDRESS + "ADDRESS] " + "[" + PREFIX_TAG + + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_PHONE + "91234567 " + PREFIX_EMAIL + + "johndoe@example.com"; public static final String MESSAGE_EDIT_PATIENT_SUCCESS = "Edited Patient: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; @@ -61,7 +56,7 @@ public class EditCommand extends Command { private final EditPatientDescriptor editPatientDescriptor; /** - * @param index of the patient in the filtered patient list to edit + * @param index of the patient in the filtered patient list to edit * @param editPatientDescriptor details to edit the patient with */ public EditCommand(Index index, EditPatientDescriptor editPatientDescriptor) { @@ -107,13 +102,13 @@ private static Patient createEditedPatient(Patient patientToEdit, EditPatientDes 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()); +// AssignedDepartment updatedDepartment = editPatientDescriptor.getDepartment() +// .orElse(patientToEdit.getAssignedDepartment()); Set updatedTags = editPatientDescriptor.getTags().orElse(patientToEdit.getTags()); - Record updatedRecord = editPatientDescriptor.getRecord().orElse(patientToEdit.getRecord()); +// Record updatedRecord = editPatientDescriptor.getRecord().orElse(patientToEdit.getRecord()); - return new Patient(updatedName, updatedPhone, updatedEmail, updatedGender, updatedIcNumber, - updatedBirthday, updatedAddress, updatedTags, updatedDepartment, updatedRecord); + return new Patient(updatedName, updatedPhone, updatedEmail, updatedGender, updatedIcNumber, updatedBirthday, + updatedAddress, updatedTags); } @@ -129,16 +124,14 @@ public boolean equals(Object other) { } EditCommand otherEditCommand = (EditCommand) other; - return index.equals(otherEditCommand.index) - && editPatientDescriptor.equals(otherEditCommand.editPatientDescriptor); + return index.equals(otherEditCommand.index) && editPatientDescriptor.equals( + otherEditCommand.editPatientDescriptor); } @Override public String toString() { - return new ToStringBuilder(this) - .add("index", index) - .add("editPatientDescriptor", editPatientDescriptor) - .toString(); + return new ToStringBuilder(this).add("index", index).add("editPatientDescriptor", editPatientDescriptor) + .toString(); } /** @@ -149,15 +142,16 @@ public static class EditPatientDescriptor { private Name name; private Phone phone; private Email email; - private Address address; - private Set tags; private Gender gender; - private Birthday birthday; private IcNumber icNumber; + private Birthday birthday; + private Address address; + private Set tags; private AssignedDepartment department; private Record record; - public EditPatientDescriptor() {} + public EditPatientDescriptor() { + } /** * Copy constructor. @@ -225,6 +219,7 @@ public void setTreatmentPlan(String treatmentPlan) { public void setDiagnosis(String diagnosis) { record.setDiagnosis(diagnosis); } + public Optional getRecord() { return Optional.ofNullable(record); } @@ -258,11 +253,10 @@ public boolean equals(Object other) { } EditPatientDescriptor otherEditPatientDescriptor = (EditPatientDescriptor) other; - return Objects.equals(name, otherEditPatientDescriptor.name) - && Objects.equals(phone, otherEditPatientDescriptor.phone) - && Objects.equals(email, otherEditPatientDescriptor.email) - && Objects.equals(address, otherEditPatientDescriptor.address) - && Objects.equals(tags, otherEditPatientDescriptor.tags); + return Objects.equals(name, otherEditPatientDescriptor.name) && Objects.equals(phone, + otherEditPatientDescriptor.phone) && Objects.equals(email, otherEditPatientDescriptor.email) + && Objects.equals(address, otherEditPatientDescriptor.address) && Objects.equals(tags, + otherEditPatientDescriptor.tags); } public void setGender(Gender gender) { @@ -299,13 +293,8 @@ public Optional getDepartment() { @Override public String toString() { - return new ToStringBuilder(this) - .add("name", name) - .add("phone", phone) - .add("email", email) - .add("address", address) - .add("tags", tags) - .toString(); + return new ToStringBuilder(this).add("name", name).add("phone", phone).add("email", email) + .add("address", address).add("tags", tags).toString(); } } } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 46cc17e3d13..c3ffec4057f 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -104,12 +104,21 @@ public static Patient createPatientFromPresentPrefixes(Name name, Phone phone, E case "e/": email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); break; - case "g/": + case "a/": address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); break; case "t/": tags = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); break; + case "g/": + gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()); + break; + case "b/": + birthday = ParserUtil.parseBirthday(argMultimap.getValue(PREFIX_BIRTHDAY).get()); + break; + case "i/": + icNumber = ParserUtil.parseIcNumber(argMultimap.getValue(PREFIX_IC_NUMBER).get()); + break; default: } } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 6ffc43ff248..e212ea952d9 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -27,7 +27,6 @@ import seedu.address.model.tag.Tag; - /** * Parses input arguments and creates a new EditCommand object */ @@ -36,13 +35,13 @@ public class EditCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the EditCommand * and returns an EditCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public EditCommand parse(String args) throws ParseException { requireNonNull(args); - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG, - PREFIX_GENDER, PREFIX_BIRTHDAY, PREFIX_IC_NUMBER, PREFIX_DEPARTMENT); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_ADDRESS, PREFIX_TAG, PREFIX_GENDER, PREFIX_BIRTHDAY, PREFIX_IC_NUMBER, PREFIX_DEPARTMENT); Index index; @@ -78,8 +77,8 @@ public EditCommand parse(String args) throws ParseException { 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())); + editPatientDescriptor.setDepartment( + ParserUtil.parseAssignedDepartment(argMultimap.getValue(PREFIX_DEPARTMENT).get())); } if (argMultimap.getValue(PREFIX_INITIAL_OBSERVATION).isPresent()) { editPatientDescriptor.setInitialObservation(argMultimap.getValue(PREFIX_INITIAL_OBSERVATION).get()); diff --git a/src/main/java/seedu/address/model/patient/Birthday.java b/src/main/java/seedu/address/model/patient/Birthday.java index a9be9002a7f..05f65503e40 100644 --- a/src/main/java/seedu/address/model/patient/Birthday.java +++ b/src/main/java/seedu/address/model/patient/Birthday.java @@ -17,7 +17,7 @@ public class Birthday { public final LocalDate value; public final String strValue; private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - public static String DEFAULT_BIRTHDAY = "00/00/0000"; + public static String DEFAULT_BIRTHDAY = "01/01/2000"; /** * Constructs a {@code Birthday}. * diff --git a/src/main/java/seedu/address/model/patient/Patient.java b/src/main/java/seedu/address/model/patient/Patient.java index 3ef2d924e23..2b8a38414d2 100644 --- a/src/main/java/seedu/address/model/patient/Patient.java +++ b/src/main/java/seedu/address/model/patient/Patient.java @@ -45,7 +45,7 @@ public Patient(Name name, Phone phone, Email email, Gender gender, IcNumber icNu this.address = address; this.tags.addAll(tags); this.assignedDepartment = new AssignedDepartment(); // default Department given - this.record = new Record(this); // creates new Record + this.record = new Record(); // creates new Record } public Name getName() { @@ -101,8 +101,7 @@ public boolean isSamePatient(Patient otherPatient) { return true; } - return otherPatient != null - && otherPatient.getName().equals(getName()); + return otherPatient != null && otherPatient.getName().equals(getName()); } /** @@ -121,16 +120,10 @@ public boolean equals(Object other) { } Patient otherPatient = (Patient) other; - return name.equals(otherPatient.name) - && phone.equals(otherPatient.phone) - && email.equals(otherPatient.email) - && gender.equals(otherPatient.gender) - && icNumber.equals(otherPatient.icNumber) - && birthday.equals(otherPatient.birthday) - && address.equals(otherPatient.address) - && tags.equals(otherPatient.tags) - && assignedDepartment.equals(otherPatient.assignedDepartment) - && record.equals(otherPatient.record); + return name.equals(otherPatient.name) && phone.equals(otherPatient.phone) && email.equals(otherPatient.email) + && gender.equals(otherPatient.gender) && icNumber.equals(otherPatient.icNumber) && birthday.equals( + otherPatient.birthday) && address.equals(otherPatient.address) && tags.equals(otherPatient.tags) + && assignedDepartment.equals(otherPatient.assignedDepartment) && record.equals(otherPatient.record); } @Override @@ -141,18 +134,9 @@ public int hashCode() { @Override public String toString() { - return new ToStringBuilder(this) - .add("name", name) - .add("phone", phone) - .add("email", email) - .add("gender", gender) - .add("icNumber", icNumber) - .add("birthday", birthday) - .add("address", address) - .add("tags", tags) - .add ("assignedDepartment", assignedDepartment) - .add("record", record) - .toString(); + return new ToStringBuilder(this).add("name", name).add("phone", phone).add("email", email).add("gender", gender) + .add("icNumber", icNumber).add("birthday", birthday).add("address", address).add("tags", tags) + .add("assignedDepartment", assignedDepartment).add("record", record).toString(); } } diff --git a/src/main/java/seedu/address/model/patient/Record.java b/src/main/java/seedu/address/model/patient/Record.java index 02b80b71aad..6867496d360 100644 --- a/src/main/java/seedu/address/model/patient/Record.java +++ b/src/main/java/seedu/address/model/patient/Record.java @@ -19,8 +19,6 @@ public class Record { /** * Initializes a Record with the associated patient and initialise the fields with default values - * - * @param patient The patient associated with this record. */ public Record(Patient patient) { this.patient = patient; @@ -29,6 +27,14 @@ public Record(Patient patient) { this.treatmentPlan = DEFAULT_TREATMENT_PLAN; } + public Record() { + this.patient = null; // patient left null, would have to fix when building editing record command + this.initialObservations = DEFAULT_INITIAL_OBSERVATIONS; + this.diagnosis = DEFAULT_DIAGNOSIS; + this.treatmentPlan = DEFAULT_TREATMENT_PLAN; + } + + public Patient getPatient() { return patient; }