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

Prevent editing IC & UG for find-appt #149

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
22 changes: 20 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: User Guide

MediLink Contacts(MLC) is a **desktop app for managing patients and doctors details, optimized for use via a Command
Line Interface** (CLI) while still having the benefits of a Graphical User Interface (GUI). If you can type fast, MLC
can get your patients management tasks done faster than traditional GUI apps.
cang get your patients management tasks done faster than traditional GUI apps.

### Table of Contents

Expand Down Expand Up @@ -145,7 +145,7 @@ Format: `new-appt pic/IC dic/IC time/yyyy-MM-dd HH:mm:ss`
**:information_source: Take Note:**<br>

- All fields are Required.
- EMAIL must follow the specified format (ie. `yyyy-MM-dd HH:mm:ss`).
- TIME must follow the specified format (ie. `yyyy-MM-dd HH:mm:ss`).
- PATIENT must contain the valid IC of a Patient in the Database.
- DOCTOR must contain the valid IC of a Doctor in the Database.

Expand All @@ -155,6 +155,24 @@ Examples:

* `new-appt pic/T0123456H dic/S9851586G time/2023-10-30T13:00:00`

### Finding an Appointment : `find-appt`

Finds all appointments that involve a specific patient/doctor.

Format: `find-appt IC`

<div markdown="block" class="alert alert-info">
**:information_source: Take Note:**<br>

- All fields are Required.
- IC must contain the valid IC of a Patient or Doctor in the Database.

</div>

Examples:

* `find-appt T0123456H`

### Listing all persons : `list`

Shows a list of all persons in the MediLink Contacts.
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMERGENCY_CONTACT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -62,7 +61,6 @@ public class EditCommand extends Command {
+ "[" + PREFIX_GENDER + "GENDER] "
+ "[" + PREFIX_CONDITION + "CONDITION] "
+ "[" + PREFIX_BLOODTYPE + "BLOOD TYPE] "
+ "[" + PREFIX_NRIC + "NRIC] "
+ "[" + PREFIX_EMERGENCY_CONTACT + "EMAIL] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " T0123456H "
Expand All @@ -73,6 +71,7 @@ public class EditCommand extends Command {
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
public static final String MESSAGE_DOESNT_EXIST = "This person hasn't been saved";
public static final String MESSAGE_IC_CHANGED = "You can't change a person's IC";
private static final Logger logger = LogsCenter.getLogger(EditCommand.class.getName());
private final Ic nric;
private final EditPersonDescriptor editPersonDescriptor;
Expand All @@ -92,6 +91,10 @@ public EditCommand(Ic nric, EditPersonDescriptor editPersonDescriptor) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
if (editPersonDescriptor.getIc().isPresent() && !(editPersonDescriptor.getIc().get().equals(nric))) {
throw new CommandException(MESSAGE_IC_CHANGED);
}

// combine doctor list and patient list
Person personToEdit = getPersonToEdit(model);
Person editedPerson = getEditedPerson(model, personToEdit);
Expand Down Expand Up @@ -152,7 +155,7 @@ private static Doctor createEditedDoctor(Doctor personToEdit, EditPersonDescript
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Remark updatedRemarks = editPersonDescriptor.getRemark().orElse(personToEdit.getRemark());
Gender updatedGender = editPersonDescriptor.getGender().orElse(personToEdit.getGender());
Ic updatedIc = editPersonDescriptor.getIc().orElse(personToEdit.getIc());
Ic updatedIc = personToEdit.getIc(); // since you can't modify ic
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Set<Appointment> updatedAppointments =
editPersonDescriptor.getAppointments().orElse(personToEdit.getAppointments());
Expand All @@ -175,7 +178,7 @@ private static Patient createEditedPatient(Patient personToEdit, EditPersonDescr
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Remark updatedRemarks = editPersonDescriptor.getRemark().orElse(personToEdit.getRemark());
Gender updatedGender = editPersonDescriptor.getGender().orElse(personToEdit.getGender());
Ic updatedIc = editPersonDescriptor.getIc().orElse(personToEdit.getIc());
Ic updatedIc = personToEdit.getIc(); // since you can't modify ic
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Set<Appointment> updatedAppointments =
editPersonDescriptor.getAppointments().orElse(personToEdit.getAppointments());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FindAppointmentCommand extends Command {
private final Predicate<Appointment> predicate;
/**
* Finds and lists all persons in address book whose attributes match the predicate.
* Keyword matching is case insensitive.
* Keyword matching is case-insensitive.
*/
public FindAppointmentCommand(Predicate<Appointment> predicate) {
requireNonNull(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* Parses input arguments and creates a new EditCommand object
*/
public class EditCommandParser implements Parser<EditCommand> {
public static final String CANNOT_CHANGE_IC_MESSAGE = "You cannot modify a person's IC";
private static final Logger logger = LogsCenter.getLogger(EditCommand.class);
/**
* Parses the given {@code String} of arguments in the context of the EditCommand
Expand Down Expand Up @@ -58,6 +59,9 @@ public EditCommand parse(String args) throws ParseException {

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

if (argMultimap.getValue(PREFIX_NRIC).isPresent()) {
editPersonDescriptor.setIc(ParserUtil.parseIc(argMultimap.getValue(PREFIX_NRIC).get()));
}
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
}
Expand All @@ -73,9 +77,6 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_GENDER).isPresent()) {
editPersonDescriptor.setGender(ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()));
}
if (argMultimap.getValue(PREFIX_NRIC).isPresent()) {
editPersonDescriptor.setIc(ParserUtil.parseIc(argMultimap.getValue(PREFIX_NRIC).get()));
}
if (argMultimap.getValue(PREFIX_CONDITION).isPresent()) {
editPersonDescriptor.setCondition(ParserUtil.parseCondition(argMultimap.getValue(PREFIX_CONDITION).get()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,22 @@ public class CommandTestUtil {
DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withBloodType(VALID_BLOODTYPE_AMY).withCondition(VALID_CONDITION_AMY)
.withGender(VALID_GENDER_FEMALE).withIc(VALID_NRIC_AMY)
.withGender(VALID_GENDER_FEMALE)
.withTags(VALID_TAG_FRIEND).withBloodType(VALID_BLOODTYPE_AMY)
.build();

DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB)
.withGender(VALID_GENDER_MALE).withIc(VALID_NRIC_BOB)
.withGender(VALID_GENDER_MALE)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();

DESC_CHERYL = new EditPersonDescriptorBuilder().withName(VALID_NAME_CHERYL)
.withPhone(VALID_PHONE_CHERYL).withEmail(VALID_EMAIL_CHERYL).withAddress(VALID_ADDRESS_CHERYL)
.withGender(VALID_GENDER_FEMALE).withIc(VALID_NRIC_CHERYL).build();
.withGender(VALID_GENDER_FEMALE).build();

DESC_DEREK = new EditPersonDescriptorBuilder().withName(VALID_NAME_DEREK)
.withPhone(VALID_PHONE_DEREK).withEmail(VALID_EMAIL_DEREK).withAddress(VALID_ADDRESS_DEREK)
.withGender(VALID_GENDER_MALE).withIc(VALID_NRIC_DEREK).build();
.withGender(VALID_GENDER_MALE).build();
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class EditCommandTest {

@Test
public void execute_patientAllFieldsSpecifiedUnfilteredList_success() {
Person editedPatient = new PatientBuilder().build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPatient).build();
Ic nricOfFirstPatient = model.getFilteredPatientList().get(0).getIc();
Person editedPatient = new PatientBuilder(nricOfFirstPatient).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(nricOfFirstPatient, editedPatient).build();
EditCommand editCommand = new EditCommand(nricOfFirstPatient, descriptor);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPatient));
Expand All @@ -56,9 +56,9 @@ public void execute_patientAllFieldsSpecifiedUnfilteredList_success() {

@Test
public void execute_doctorAllFieldsSpecifiedUnfilteredList_success() {
Doctor editedDoctor = new DoctorBuilder().build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedDoctor).build();
Ic nricOfFirstDoctor = model.getFilteredDoctorList().get(0).getIc();
Doctor editedDoctor = new DoctorBuilder(nricOfFirstDoctor).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(nricOfFirstDoctor, editedDoctor).build();
EditCommand editCommand = new EditCommand(nricOfFirstDoctor, descriptor);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedDoctor));
Expand Down Expand Up @@ -127,11 +127,10 @@ public void execute_duplicatePersonUnfilteredList_failure() {
Ic nricOfFirstPerson = model.getFilteredPatientList().get(0).getIc();
Person firstPerson = model.getFilteredPatientList().stream().filter(p ->
p.getIc().equals(nricOfFirstPerson)).findFirst().orElse(null);
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstPerson).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(nricOfFirstPerson, firstPerson).build();
Ic nricOfSecondPerson = model.getFilteredPatientList().get(1).getIc();
EditCommand editCommand = new EditCommand(nricOfSecondPerson, descriptor);

assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON);
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_IC_CHANGED);
}

@Test
Expand All @@ -142,9 +141,9 @@ public void execute_duplicatePersonFilteredList_failure() {
Patient patientInList = model.getAddressBook().getPatientList().get(INDEX_SECOND_PERSON.getZeroBased());
Ic nricOfFirstPerson = model.getFilteredPatientList().get(INDEX_FIRST_PERSON.getZeroBased()).getIc();
EditCommand editCommand = new EditCommand(nricOfFirstPerson,
new EditPersonDescriptorBuilder(patientInList).build());
new EditPersonDescriptorBuilder(patientInList.getIc(), patientInList).build());

assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON);
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_IC_CHANGED);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void parseCommand_deleteAppointment() throws Exception {
@Test
public void parseCommand_edit() throws Exception {
Patient person = new PatientBuilder().build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(person).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(person.getIc(), person).build();
EditCommand command = (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " "
+ person.getIc() + " " + PersonUtil.getEditPersonDescriptorDetails(descriptor));
assertEquals(new EditCommand(person.getIc(), descriptor), command);
Expand Down
15 changes: 14 additions & 1 deletion src/test/java/seedu/address/testutil/DoctorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,20 @@ public DoctorBuilder(Doctor doctorToCopy) {
tags = new HashSet<>(doctorToCopy.getTags());
appointments = new HashSet<>(doctorToCopy.getAppointments());
}

/**
* Initializes the PersonBuilder with an nric.
*/
public DoctorBuilder(Ic nric) {
name = new Name(DEFAULT_NAME);
phone = new Phone(DEFAULT_PHONE);
email = new Email(DEFAULT_EMAIL);
address = new Address(DEFAULT_ADDRESS);
remark = new Remark(DEFAULT_REMARK);
gender = new Gender(DEFAULT_GENDER);
ic = nric;
tags = new HashSet<>();
appointments = new HashSet<>();
}
/**
* Sets the {@code Name} of the {@code Person} that we are building.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public EditPersonDescriptorBuilder(EditPersonDescriptor descriptor) {
/**
* Returns an {@code EditPersonDescriptor} with fields containing {@code person}'s details
*/
public EditPersonDescriptorBuilder(Person person) {
public EditPersonDescriptorBuilder(Ic nric, Person person) {
descriptor = new EditPersonDescriptor();
descriptor.setIc(nric);
descriptor.setName(person.getName());
descriptor.setPhone(person.getPhone());
descriptor.setEmail(person.getEmail());
descriptor.setAddress(person.getAddress());
descriptor.setGender(person.getGender());
descriptor.setIc(person.getIc());
descriptor.setTags(person.getTags());
descriptor.setRemark(person.getRemark());
if (person.isPatient()) {
Expand Down Expand Up @@ -104,13 +104,6 @@ public EditPersonDescriptorBuilder withRemark(String remark) {
return this;
}

/**
* Sets the {@code Ic} of the {@code EditPersonDescriptor} that we are building.
*/
public EditPersonDescriptorBuilder withIc(String ic) {
descriptor.setIc(new Ic(ic));
return this;
}

/**
* Sets the {@code BloodType} of the {@code EditPersonDescriptor} that we are building.
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/seedu/address/testutil/PatientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ public PatientBuilder() {
tags = new HashSet<>();
appointments = new HashSet<>();
}
/**
* Initializes the PatientBuilder with an nric,
*/
public PatientBuilder(Ic nric) {
name = new Name(DEFAULT_NAME);
phone = new Phone(DEFAULT_PHONE);
emergencyContact = new Phone(DEFAULT_EMERGENCY_CONTACT);
email = new Email(DEFAULT_EMAIL);
address = new Address(DEFAULT_ADDRESS);
remark = new Remark(DEFAULT_REMARK);
gender = new Gender(DEFAULT_GENDER);
ic = nric;
condition = new Condition(DEFAULT_CONDITION);
bloodType = new BloodType(DEFAULT_BLOODTYPE);
tags = new HashSet<>();
appointments = new HashSet<>();
}

/**
* Initializes the PatientBuilder with the data of {@code patientToCopy}.
Expand Down
Loading