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 project from team repo #5

Merged
merged 19 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
20b0781
Update Patient constructor arguments
AaronJT1 Oct 16, 2023
6d01c19
Update Record.java to initialise with default values
AaronJT1 Oct 16, 2023
a47d6c3
Update PatientBuilder.java to cater to new Patient class
AaronJT1 Oct 16, 2023
8a6510d
Update each Patient attribute to have default value
AaronJT1 Oct 16, 2023
9df51a2
Update AddCommandParser.java to use new Patient class
AaronJT1 Oct 16, 2023
b6e2c2e
Update SampleDataUtil.java to use new Patient class
AaronJT1 Oct 16, 2023
d63a1c3
Update JsonAdaptedPatient.java to use new Patient class
AaronJT1 Oct 16, 2023
3dd88ff
Update JsonAdaptedPatientTest.java to include new Patient attributes
AaronJT1 Oct 16, 2023
17c2e69
Update patient attributes to have more intuitive default values
AaronJT1 Oct 16, 2023
b127dd9
Update EditCommand.java, EditCommandParser.java, and ParserUtil.java.
longnguyentan Oct 16, 2023
294222e
Merge pull request #102 from AaronJT1/branch-update-patient-fields
wujy28 Oct 17, 2023
839b570
Merge pull request #103 from longnguyentan/branch-EditCommand
AaronJT1 Oct 17, 2023
5b575f6
Update AddCommandParser to integrate ParserUtil
AaronJT1 Oct 17, 2023
f85622f
Merge pull request #104 from AaronJT1/branch-fixing-patient-dependency
RiyaMehta2211 Oct 17, 2023
8233415
Fix inconsistencies in EditCommand and EditCommandParser
wujy28 Oct 17, 2023
5363de7
Fix StackOverflow bug involving PatientBuilder and RecordBuilder
wujy28 Oct 17, 2023
9e0710c
Add new attributes to some console messages
wujy28 Oct 17, 2023
fe15562
Fix CheckStyle Issues
wujy28 Oct 17, 2023
1da5292
Merge pull request #108 from wujy28/branch-Edit-Command
longnguyentan Oct 18, 2023
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
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ public static String format(Patient patient) {
.append(patient.getPhone())
.append("; Email: ")
.append(patient.getEmail())
.append("; Gender: ")
.append(patient.getGender())
.append("; IC Number: ")
.append(patient.getIcNumber())
.append("; Birthday: ")
.append(patient.getBirthday())
.append("; Address: ")
.append(patient.getAddress())
.append("; Department: ")
.append(patient.getAssignedDepartment())
.append("; Tags: ");
patient.getTags().forEach(builder::append);
return builder.toString();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static java.util.Objects.requireNonNull;
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_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_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -25,12 +28,18 @@ public class AddCommand extends Command {
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_GENDER + "GENDER "
+ PREFIX_IC_NUMBER + "IC_NUMBER "
+ PREFIX_BIRTHDAY + "BIRTHDAY "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_GENDER + "MALE "
+ PREFIX_IC_NUMBER + "S2840182A "
+ PREFIX_BIRTHDAY + "02/01/1998 "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
Expand Down
92 changes: 69 additions & 23 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static java.util.Objects.requireNonNull;
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_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_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -22,7 +25,10 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.patient.Address;
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;
Expand All @@ -36,17 +42,18 @@ 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_GENDER + "GENDER] "
+ "[" + PREFIX_IC_NUMBER + "IC_NUMBER] "
+ "[" + PREFIX_BIRTHDAY + "BIRTHDAY] "
+ "[" + 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 @@ -56,7 +63,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 @@ -98,12 +105,17 @@ 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());
Set<Tag> updatedTags = editPatientDescriptor.getTags().orElse(patientToEdit.getTags());

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


@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -116,16 +128,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 @@ -136,10 +146,14 @@ public static class EditPatientDescriptor {
private Name name;
private Phone phone;
private Email email;
private Gender gender;
private IcNumber icNumber;
private Birthday birthday;
private Address address;
private Set<Tag> tags;

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

/**
* Copy constructor.
Expand All @@ -149,6 +163,9 @@ public EditPatientDescriptor(EditPatientDescriptor toCopy) {
setName(toCopy.name);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setGender(toCopy.gender);
setIcNumber(toCopy.icNumber);
setBirthday(toCopy.birthday);
setAddress(toCopy.address);
setTags(toCopy.tags);
}
Expand All @@ -157,7 +174,7 @@ public EditPatientDescriptor(EditPatientDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, gender, icNumber, birthday, address, tags);
}

public void setName(Name name) {
Expand Down Expand Up @@ -224,19 +241,48 @@ public boolean equals(Object other) {
return Objects.equals(name, otherEditPatientDescriptor.name)
&& Objects.equals(phone, otherEditPatientDescriptor.phone)
&& Objects.equals(email, otherEditPatientDescriptor.email)
&& Objects.equals(gender, otherEditPatientDescriptor.gender)
&& Objects.equals(icNumber, otherEditPatientDescriptor.icNumber)
&& Objects.equals(birthday, otherEditPatientDescriptor.birthday)
&& Objects.equals(address, otherEditPatientDescriptor.address)
&& 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);
}

@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)
.toString();
.add("tags", tags).toString();
}
}
}
74 changes: 60 additions & 14 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_REQUIRED_COMMAND_NOT_FOUND_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_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_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -18,7 +21,10 @@
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.patient.Address;
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;
Expand All @@ -30,11 +36,13 @@
public class AddCommandParser implements Parser<AddCommand> {

public static final Prefix[] RELEVANT_PREFIXES = new Prefix[]{PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_TAG};
PREFIX_GENDER, PREFIX_IC_NUMBER, PREFIX_BIRTHDAY, PREFIX_ADDRESS, PREFIX_TAG};
public static final Prefix[] RELEVANT_PREFIXES_WITHOUT_TAG = new Prefix[]{PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_GENDER, PREFIX_IC_NUMBER, PREFIX_BIRTHDAY, PREFIX_ADDRESS};
public static final Prefix[] REQUIRED_PREFIXES = new Prefix[]{PREFIX_NAME};

public static final Prefix[] OPTIONAL_PREFIXES = new Prefix[]{PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_TAG};
public static final Prefix[] OPTIONAL_PREFIXES = new Prefix[]{PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER,
PREFIX_IC_NUMBER, PREFIX_BIRTHDAY, PREFIX_ADDRESS, PREFIX_TAG};


/**
Expand All @@ -58,21 +66,50 @@ public static Prefix[] getPrefixesPresent(ArgumentMultimap argMultimap) {
}

/**
* Takes in a list of prefixes and creates patients with its corresponding values in argMultimap, if
* optional field values are missing, fill it with default instead.
* Create Patient from prefixes present
*
* @param argMultimap Argument multimap which contains prefix to value mapping
* @param prefixes List of prefixes present
* @return Patient object
* @param argMultimap Contains mapping of key which is prefix and value which is argument value
* @param prefixes List of prefixes present in argument
* @return Patient with the fields present in user input
* @throws ParseException if the user input does not conform the expected format
*/
public static Patient createPatientFromPrefixes(ArgumentMultimap argMultimap, Prefix[] prefixes)
throws ParseException {
// filling the fields with default values
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = new Phone("12345678");
Email email = new Email("default_email@gmail.com");
Address address = new Address("Address not added");
Phone phone = new Phone(Phone.DEFAULT_PHONE);
Email email = new Email(Email.DEFAULT_EMAIL);
Gender gender = new Gender(Gender.DEFAULT_GENDER);
IcNumber icNumber = new IcNumber(IcNumber.DEFAULT_IC_NUMBER);
Birthday birthday = new Birthday(Birthday.DEFAULT_BIRTHDAY);
Address address = new Address(Address.DEFAULT_ADDRESS);
Set<Tag> tagList = new HashSet<>();

// passing to helper function to replace fields with actual values if it exists
return createPatientFromPresentPrefixes(name, phone, email, gender, icNumber, birthday, address, tagList,
argMultimap, prefixes);
}

/**
* Replaces Patient fields with actual value if it is present in argMultimap
*
* @param name Name of patient
* @param phone Phone number of patient
* @param email Email of patient
* @param gender Gender of Patient
* @param icNumber IcNumber of Patient
* @param birthday Birthday of Patient
* @param address Address of Patient
* @param tags Tags of Patient
* @param argMultimap Contains mapping of key which is prefix and value which is argument value
* @param prefixes List of prefixes present in argument
* @return Patient with the fields present in user input
* @throws ParseException if the user input does not conform the expected format
*/
public static Patient createPatientFromPresentPrefixes(Name name, Phone phone, Email email, Gender gender,
IcNumber icNumber, Birthday birthday, Address address,
Set<Tag> tags, ArgumentMultimap argMultimap,
Prefix[] prefixes) throws ParseException {
for (Prefix p : prefixes) {
switch (p.getPrefix()) {
case "p/":
Expand All @@ -85,12 +122,21 @@ public static Patient createPatientFromPrefixes(ArgumentMultimap argMultimap, Pr
address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
break;
case "t/":
tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
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:
}
}
return new Patient(name, phone, email, address, tagList);
return new Patient(name, phone, email, gender, icNumber, birthday, address, tags);
}

/**
Expand All @@ -111,7 +157,7 @@ public AddCommand parse(String args) throws ParseException {
throw new ParseException(
String.format(MESSAGE_REQUIRED_COMMAND_NOT_FOUND_FORMAT, Arrays.toString(REQUIRED_PREFIXES)));
}
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(RELEVANT_PREFIXES_WITHOUT_TAG);
Prefix[] prefixesPresent = getPrefixesPresent(argMultimap);

Patient patient = createPatientFromPrefixes(argMultimap, prefixesPresent);
Expand Down
Loading
Loading