Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-T14-2#104 from AaronJT1/branch-fi…
Browse files Browse the repository at this point in the history
…xing-patient-dependency

Update AddCommandParser to integrate ParserUtil
  • Loading branch information
RiyaMehta2211 committed Oct 17, 2023
2 parents 839b570 + 5b575f6 commit f85622f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 74 deletions.
67 changes: 28 additions & 39 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand All @@ -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) {
Expand Down Expand Up @@ -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<Tag> 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);
}


Expand All @@ -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();
}

/**
Expand All @@ -149,15 +142,16 @@ public static class EditPatientDescriptor {
private Name name;
private Phone phone;
private Email email;
private Address address;
private Set<Tag> tags;
private Gender gender;
private Birthday birthday;
private IcNumber icNumber;
private Birthday birthday;
private Address address;
private Set<Tag> tags;
private AssignedDepartment department;
private Record record;

public EditPatientDescriptor() {}
public EditPatientDescriptor() {
}

/**
* Copy constructor.
Expand Down Expand Up @@ -225,6 +219,7 @@ public void setTreatmentPlan(String treatmentPlan) {
public void setDiagnosis(String diagnosis) {
record.setDiagnosis(diagnosis);
}

public Optional<Record> getRecord() {
return Optional.ofNullable(record);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -299,13 +293,8 @@ public Optional<AssignedDepartment> 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();
}
}
}
11 changes: 10 additions & 1 deletion src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import seedu.address.model.tag.Tag;



/**
* Parses input arguments and creates a new EditCommand object
*/
Expand All @@ -36,13 +35,13 @@ public class EditCommandParser implements Parser<EditCommand> {
/**
* 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;

Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/patient/Birthday.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand Down
34 changes: 9 additions & 25 deletions src/main/java/seedu/address/model/patient/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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
Expand All @@ -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();
}

}
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/model/patient/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit f85622f

Please sign in to comment.