Skip to content

Commit

Permalink
Fix failing test cases and UI
Browse files Browse the repository at this point in the history
  • Loading branch information
cmHuang777 committed Oct 31, 2023
1 parent aa267b6 commit 62a7392
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 153 deletions.
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Messages {
public static final String MESSAGE_PERSON_NOT_FOUND = "Person with specified nric cannot be found!";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";
"Multiple values specified for the following single-valued field(s): ";

/**
* Returns an error message indicating the duplicate prefixes.
Expand Down Expand Up @@ -46,6 +46,8 @@ public static String format(Person person) {
.append(person.getAddress())
.append("; Tags: ");
person.getTags().forEach(builder::append);
builder.append("; Appointments: ");
person.getAppointments().forEach(builder::append);
return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class AddAppointmentCommand extends Command {
"This patient already has an appointment at this timing";
public static final String MESSAGE_DUPLICATE_APPOINTMENT_DOCTOR =
"This doctor already has an appointment at this timing";
public static final String MESSAGE_SAME_DOCTOR_AND_PATIENT =
"You entered the same IC for both doctors and patients!";


private final Appointment toAdd;
Expand All @@ -53,13 +55,6 @@ public AddAppointmentCommand(Appointment appointment) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

Check warning on line 57 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L57

Added line #L57 was not covered by tests
// Ic patientIc = toAdd.getPatient();
// Ic doctorIc = toAdd.getDoctor();
//
// // check that patient and doctor exists in the model
// if (!model.hasPatientIc(patientIc)) {
//
// }

Patient chosenPatient = findPatient(model);
Doctor chosenDoctor = findDoctor(model);

Check warning on line 60 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L59-L60

Added lines #L59 - L60 were not covered by tests
Expand All @@ -70,6 +65,12 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_INVALID_DOCTOR);

Check warning on line 65 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L65

Added line #L65 was not covered by tests
}

// check that patient and doctor are not the same person
if (chosenPatient.isSamePerson(chosenDoctor)) {
throw new CommandException(MESSAGE_SAME_DOCTOR_AND_PATIENT);

Check warning on line 70 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L70

Added line #L70 was not covered by tests
}


// check that the patient and doctor do not have appointment scheduled at the same time
if (chosenPatient.hasAppointmentAt(toAdd.getAppointmentTime())) {
throw new CommandException(MESSAGE_DUPLICATE_APPOINTMENT_PATIENT);

Check warning on line 76 in src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java#L76

Added line #L76 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_APPOINTMENT_TIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOCTOR_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PATIENT_IC;
import static seedu.address.model.appointment.Appointment.FORMATTER;

import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;
Expand Down Expand Up @@ -40,7 +41,7 @@ public AddAppointmentCommand parse(String args) throws ParseException {
Ic doctorIc = ParserUtil.parseIc(argMultimap.getValue(PREFIX_DOCTOR_IC).get());

Check warning on line 41 in src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java#L40-L41

Added lines #L40 - L41 were not covered by tests
LocalDateTime dateTime;
try {
dateTime = LocalDateTime.parse(argMultimap.getValue(PREFIX_APPOINTMENT_TIME).get());
dateTime = LocalDateTime.parse(argMultimap.getValue(PREFIX_APPOINTMENT_TIME).get(), FORMATTER);
} catch (DateTimeParseException e) {
throw new ParseException(e.getMessage());
}
Expand Down
28 changes: 2 additions & 26 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;

import java.util.List;
import java.util.Objects;

import javafx.collections.ObservableList;
import seedu.address.commons.util.ToStringBuilder;
Expand Down Expand Up @@ -88,31 +89,6 @@ public boolean hasDoctor(Doctor doctor) {
return doctors.contains(doctor);
}

// /**
// * Returns true if there is a patient with the same ic as {@code patientIc} in the address book.
// */
// public boolean hasPatientIc(Ic patientIc) {
// requireNonNull(patientIc);
// return patients.containsIc(patientIc);
// }

// /**
// * Returns true if there is a doctor with the same ic as {@code doctorIc} in the address book.
// */
// public boolean hasDoctorIc(Ic doctorIc) {
// requireNonNull(doctorIc);
// return doctors.containsIc(doctorIc);
// }

// /**
// * Adds the {@code appointment} to the addressbook.
// *
// * @param appointment the appointment to be added.
// */
// public void addAppointment(Appointment appointment) {
//
// }

/**
* Adds a person to the address book.
* The person must not already exist in the address book.
Expand Down Expand Up @@ -211,6 +187,6 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
return patients.hashCode();
return Objects.hash(patients, doctors);

Check warning on line 190 in src/main/java/seedu/address/model/AddressBook.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/AddressBook.java#L190

Added line #L190 was not covered by tests
}
}
8 changes: 0 additions & 8 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ public interface Model {
*/
void setPerson(Person target, Person editedPerson);

// /**
// * Adds an appointment specified by the {@code appointment} into the model.
// * The patient and doctor in the appointment cannot have another appointment at the same time.
// *
// * @param appointment the appointment to be added.
// */
// public void addApointment(Appointment appointment);

/**
* Returns an unmodifiable view of the filtered person list
*/
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,6 @@ public boolean hasPerson(Person person) {
return false;
}
}
//
// /**
// * Returns true if a patient with the same ic as {@code patientIc} exists in the address book.
// *
// * @param patientIc The ic of patient to check.
// * @return true if there is a patient with patientIc in the address book
// */
// public boolean hasPatientIc(Ic patientIc) {
// requireNonNull(patientIc);
// return addressBook.hasPatientIc(patientIc);
// }
//
// /**
// * Returns true if a doctor with the same ic as {@code doctorIc} exists in the address book.
// *
// * @param doctorIc The ic of doctor to check.
// * @return true if there is a patient with doctorIc in the address book
// */
// public boolean hasDoctorIc(Ic doctorIc) {
// requireNonNull(doctorIc);
// return addressBook.hasDoctorIc(doctorIc);
// }

@Override
public void deletePerson(Person target) {
Expand Down Expand Up @@ -196,13 +174,6 @@ public void setPerson(Person target, Person editedPerson) {
}
}

// @Override
// public void addApointment(Appointment appointment) {
// requireNonNull(appointment);
// updateBackup();
// addressBook.addAppointment(appointment);
// }

/**
* Returns an unmodifiable view of the filtered person list
*/
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/seedu/address/model/appointment/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import static java.util.Objects.requireNonNull;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

import seedu.address.model.person.Ic;

/**
* The {@code Appointment} class represents a scheduled appointment between a doctor and a patient.
* It includes information about the doctor, patient, and the appointment time.
* Doctor and patient ic should not be the same.
*/
public class Appointment {
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private Ic doctorIc;
private Ic patientIc;
private LocalDateTime appointmentTime;
Expand Down Expand Up @@ -101,8 +105,14 @@ public boolean equals(Object other) {
&& this.status.equals(otherAppointment.status);
}

@Override
public int hashCode() {
return Objects.hash(doctorIc, patientIc, appointmentTime, status);
}

@Override
public String toString() {
return "Patient with IC " + patientIc + ", Doctor with IC " + doctorIc + " at " + appointmentTime;
return "Patient with IC " + patientIc + ", Doctor with IC " + doctorIc + " at "
+ appointmentTime.format(FORMATTER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ public boolean contains(Doctor toCheck) {
requireNonNull(toCheck);
return internalList.stream().anyMatch(toCheck::isSamePerson);
}
//
// /**
// * Returns true if the list contains a person with same ic as the given argument.
// */
// public boolean containsIc(Ic toCheck) {
// requireNonNull(toCheck);
// return internalList.stream().anyMatch(toCheck::equals);
// }

/**
* Adds a person to the list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ public boolean contains(Patient toCheck) {
return internalList.stream().anyMatch(toCheck::isSamePerson);
}

// /**
// * Returns true if the list contains a person with same ic as the given argument.
// */
// public boolean containsIc(Ic toCheck) {
// requireNonNull(toCheck);
// return internalList.stream().anyMatch(toCheck::equals);
// }

/**
* Adds a person to the list.
* The person must not already exist in the list.
Expand Down
88 changes: 42 additions & 46 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.model.util;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -28,61 +29,56 @@ public class SampleDataUtil {

public static final Remark EMPTY_REMARK = new Remark("");
public static final Set<Appointment> EMPTY_APPOINTMENTS = new HashSet<>();
public static final Appointment APPOINTMENT_1 = new Appointment(new Ic("S8811111Z"),
new Ic("S1111111Z"), LocalDateTime.parse("2023-10-31T14:00"));
public static final Appointment APPOINTMENT_2 = new Appointment(new Ic("S8811112Z"),
new Ic("S1111111Z"), LocalDateTime.parse("2023-10-31T15:00"));
public static final Appointment APPOINTMENT_3 = new Appointment(new Ic("S8811112Z"),
new Ic("S1111112Z"), LocalDateTime.parse("2023-10-31T16:00"));

// persons should not be used anymore
public static Patient[] getSamplePatients() {
return new Patient[] {
new Patient(new Name("Alex Yeoh"), new Phone("87438807"), new Phone("99272758"),
new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"),
EMPTY_REMARK, new Gender("M"), new Ic("S1111111Z"), new Condition("Unknown"),
new BloodType("O+"), EMPTY_APPOINTMENTS,
getTagSet("friends")),
new Patient(new Name("Bernice Yu"), new Phone("99272758"), new Phone("87438807"),
new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
EMPTY_REMARK, new Gender("F"), new Ic("S1111112Z"), new Condition("Unknown"),
new BloodType("O+"), EMPTY_APPOINTMENTS,
getTagSet("colleagues", "friends")),
new Patient(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Phone("87438807"),
new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
EMPTY_REMARK, new Gender("F"), new Ic("S1111113Z"), new Condition("Unknown"),
new BloodType("O+"), EMPTY_APPOINTMENTS,
getTagSet("neighbours")),
new Patient(new Name("David Li"), new Phone("91031282"), new Phone("87438807"),
new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
EMPTY_REMARK, new Gender("M"), new Ic("S1111114Z"), new Condition("Unknown"),
new BloodType("O+"), EMPTY_APPOINTMENTS,
getTagSet("family")),
new Patient(new Name("Irfan Ibrahim"), new Phone("92492021"), new Phone("87438807"),
new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_REMARK,
new Gender("M"), new Ic("S1111115Z"), new Condition("Unknown"), new BloodType("O+"),
EMPTY_APPOINTMENTS, getTagSet("classmates")),
new Patient(new Name("Roy Balakrishnan"), new Phone("92624417"), new Phone("87438807"),
new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_REMARK,
new Gender("M"), new Ic("S1111116Z"), new Condition("Unknown"), new BloodType("O+"),
EMPTY_APPOINTMENTS, getTagSet("colleagues"))
new Patient(new Name("Alex Yeoh"), new Phone("87438807"), new Phone("99272758"),
new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"),
EMPTY_REMARK, new Gender("M"), new Ic("S1111111Z"), new Condition("Unknown"),
new BloodType("O+"), getAppointmentSet(APPOINTMENT_1, APPOINTMENT_2),

Check warning on line 45 in src/main/java/seedu/address/model/util/SampleDataUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/util/SampleDataUtil.java#L45

Added line #L45 was not covered by tests
getTagSet("friends")),
new Patient(new Name("Bernice Yu"), new Phone("99272758"), new Phone("87438807"),
new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
EMPTY_REMARK, new Gender("F"), new Ic("S1111112Z"), new Condition("Unknown"),
new BloodType("O+"), getAppointmentSet(APPOINTMENT_3),

Check warning on line 50 in src/main/java/seedu/address/model/util/SampleDataUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/util/SampleDataUtil.java#L50

Added line #L50 was not covered by tests
getTagSet("colleagues", "friends")),
new Patient(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Phone("87438807"),
new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
EMPTY_REMARK, new Gender("F"), new Ic("S1111113Z"), new Condition("Unknown"),
new BloodType("O+"), EMPTY_APPOINTMENTS,
getTagSet("neighbours")),
new Patient(new Name("David Li"), new Phone("91031282"), new Phone("87438807"),
new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
EMPTY_REMARK, new Gender("M"), new Ic("S1111114Z"), new Condition("Unknown"),
new BloodType("O+"), EMPTY_APPOINTMENTS,
getTagSet("family")),
new Patient(new Name("Irfan Ibrahim"), new Phone("92492021"), new Phone("87438807"),
new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_REMARK,
new Gender("M"), new Ic("S1111115Z"), new Condition("Unknown"), new BloodType("O+"),
EMPTY_APPOINTMENTS, getTagSet("classmates")),

Check warning on line 65 in src/main/java/seedu/address/model/util/SampleDataUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/util/SampleDataUtil.java#L65

Added line #L65 was not covered by tests
new Patient(new Name("Roy Balakrishnan"), new Phone("92624417"), new Phone("87438807"),
new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_REMARK,
new Gender("M"), new Ic("S1111116Z"), new Condition("Unknown"), new BloodType("O+"),
EMPTY_APPOINTMENTS, getTagSet("colleagues"))

Check warning on line 69 in src/main/java/seedu/address/model/util/SampleDataUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/util/SampleDataUtil.java#L69

Added line #L69 was not covered by tests
};
}

public static Doctor[] getSampleDoctors() {
return new Doctor[] {
new Doctor(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"),
new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_REMARK, new Gender("M"),
new Ic("S1111111Z"), EMPTY_APPOINTMENTS, getTagSet("friends")),
new Doctor(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), EMPTY_REMARK, new Gender("F"),
new Ic("S1111112Z"), EMPTY_APPOINTMENTS, getTagSet("colleagues", "friends")),
new Doctor(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), EMPTY_REMARK, new Gender("F"),
new Ic("S1111113Z"), EMPTY_APPOINTMENTS, getTagSet("neighbours")),
new Doctor(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), EMPTY_REMARK, new Gender("M"),
new Ic("S1111114Z"), EMPTY_APPOINTMENTS, getTagSet("family")),
new Doctor(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_REMARK, new Gender("M"),
new Ic("S1111115Z"), EMPTY_APPOINTMENTS, getTagSet("classmates")),
new Doctor(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_REMARK, new Gender("M"),
new Ic("S1111116Z"), EMPTY_APPOINTMENTS, getTagSet("colleagues"))
new Doctor(new Name("Adam Lim"), new Phone("87438000"), new Email("adamlim@example.com"),
new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_REMARK, new Gender("M"),
new Ic("S8811111Z"), getAppointmentSet(APPOINTMENT_1), getTagSet("GP")),

Check warning on line 77 in src/main/java/seedu/address/model/util/SampleDataUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/util/SampleDataUtil.java#L77

Added line #L77 was not covered by tests
new Doctor(new Name("Bernard Tan"), new Phone("99272000"), new Email("bernardtan@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), EMPTY_REMARK, new Gender("M"),
new Ic("S8811112Z"), getAppointmentSet(APPOINTMENT_2, APPOINTMENT_3),
getTagSet("ENTspecialist"))

Check warning on line 81 in src/main/java/seedu/address/model/util/SampleDataUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/util/SampleDataUtil.java#L80-L81

Added lines #L80 - L81 were not covered by tests
};
}

Expand Down
Loading

0 comments on commit 62a7392

Please sign in to comment.