From 875da8d17ae03a182248ae0f7618b87ba8c79e3a Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 11:27:22 +0800 Subject: [PATCH 01/13] Add Appointment-specific prefixes to CliSyntax --- src/main/java/seedu/address/logic/parser/CliSyntax.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 4fe02557436..610fd382684 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -27,4 +27,9 @@ public class CliSyntax { //specific to doctor public static final Prefix PREFIX_PATIENTS = new Prefix("pts/"); + + //specific to appointment + public static final Prefix PREFIX_PATIENT_IC = new Prefix("pic/"); + public static final Prefix PREFIX_DOCTOR_IC = new Prefix("dic/"); + public static final Prefix PREFIX_APPOINTMENT_TIME = new Prefix("time/"); } From 767a88ba6d0d0ff4d6cb0cf8635c1a4cb56bbb7e Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 11:52:40 +0800 Subject: [PATCH 02/13] Resolve Bug in AddDoctorCommandParser --- .../java/seedu/address/logic/parser/AddDoctorCommandParser.java | 2 +- src/main/java/seedu/address/model/person/Doctor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/AddDoctorCommandParser.java b/src/main/java/seedu/address/logic/parser/AddDoctorCommandParser.java index c175cceb586..94a2234fbb5 100644 --- a/src/main/java/seedu/address/logic/parser/AddDoctorCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddDoctorCommandParser.java @@ -40,7 +40,7 @@ public class AddDoctorCommandParser implements Parser { public AddDoctorCommand parse(String userInput) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(userInput, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, - PREFIX_TAG, PREFIX_REMARK); + PREFIX_GENDER, PREFIX_NRIC, PREFIX_TAG, PREFIX_REMARK); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, PREFIX_NRIC) diff --git a/src/main/java/seedu/address/model/person/Doctor.java b/src/main/java/seedu/address/model/person/Doctor.java index 91df0c83ea8..306ffb781a5 100644 --- a/src/main/java/seedu/address/model/person/Doctor.java +++ b/src/main/java/seedu/address/model/person/Doctor.java @@ -68,7 +68,7 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof Person)) { + if (!(other instanceof Doctor)) { return false; } From c05ca96365ce2d4ae4fab53a3881d4d0760e43a9 Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 12:20:29 +0800 Subject: [PATCH 03/13] Modify AppointmentTest --- .../logic/commands/CommandTestUtil.java | 11 +- .../address/model/person/AppointmentTest.java | 111 ++++++------------ 2 files changed, 44 insertions(+), 78 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 7a0c6c3d33e..ff384c2ff11 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -15,6 +15,8 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.testutil.Assert.assertThrows; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -38,7 +40,6 @@ public class CommandTestUtil { public static final String VALID_NAME_DEREK = "Derek Shepherd"; public static final String VALID_PHONE_AMY = "91234567"; public static final String VALID_PHONE_BOB = "81234567"; - public static final String VALID_PHONE_CHERYL = "92874563"; public static final String VALID_PHONE_DEREK = "97463128"; public static final String VALID_EMERGENCY_CONTACT_AMY = "81234567"; @@ -69,6 +70,14 @@ public class CommandTestUtil { public static final String VALID_BLOODTYPE_BOB = "A+"; public static final String VALID_BLOODTYPE_AMY = "A+"; public static final String VALID_CONDITION_AMY = "Diabetes"; + + public static final String VALID_DATE_1_DESC = "2022-02-14 13:30:00"; + + public static final String VALID_DATE_2_DESC = "2022-02-28 13:30:00"; + + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + public static final LocalDateTime VALID_DATE_1 = LocalDateTime.parse(VALID_DATE_1_DESC, formatter); + public static final LocalDateTime VALID_DATE_2 = LocalDateTime.parse(VALID_DATE_2_DESC, formatter); public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY; public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB; public static final String NAME_DESC_CHERYL = " " + PREFIX_NAME + VALID_NAME_CHERYL; diff --git a/src/test/java/seedu/address/model/person/AppointmentTest.java b/src/test/java/seedu/address/model/person/AppointmentTest.java index 6e2eb89ec45..6bc492d611d 100644 --- a/src/test/java/seedu/address/model/person/AppointmentTest.java +++ b/src/test/java/seedu/address/model/person/AppointmentTest.java @@ -3,15 +3,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DATE_1; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DATE_2; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalDoctor.CHERYL; import static seedu.address.testutil.TypicalDoctor.DEREK; import static seedu.address.testutil.TypicalPatient.AMY; import static seedu.address.testutil.TypicalPatient.BOB; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - import org.junit.jupiter.api.Test; public class AppointmentTest { @@ -21,135 +20,93 @@ public void constructor_null_throwsNullPointerException() { } @Test - public void constructor_invalidDoctor_throwsIllegalArgumentException() { - Doctor invalidDoctor = null; - Patient validPatient = AMY; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime validAppointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - assertThrows(NullPointerException.class, () -> new Appointment(invalidDoctor, validPatient, - validAppointmentTime)); + public void constructor_nullDoctor_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Appointment(null, AMY, + VALID_DATE_1)); } @Test - public void constructor_invalidPatient_throwsIllegalArgumentException() { - Doctor validDoctor = DEREK; - Patient invalidPatient = null; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime validAppointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - assertThrows(NullPointerException.class, () -> new Appointment(validDoctor, invalidPatient, - validAppointmentTime)); + public void constructor_nullPatient_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Appointment(DEREK, null, + VALID_DATE_1)); } @Test - public void constructor_invalidAppointmentTime_throwsIllegalArgumentException() { - Doctor validDoctor = DEREK; - Patient validPatient = AMY; - LocalDateTime invalidAppointmentTime = null; - assertThrows(NullPointerException.class, () -> new Appointment(validDoctor, validPatient, - invalidAppointmentTime)); + public void constructor_nullAppointmentTime_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Appointment(DEREK, AMY, null)); } @Test - public void secondConstructor_invalidDoctor_throwsIllegalArgumentException() { - Doctor invalidDoctor = null; - Patient validPatient = AMY; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime validAppointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - assertThrows(NullPointerException.class, () -> new Appointment(invalidDoctor, validPatient, - validAppointmentTime, "Follow-Up")); + public void secondConstructor_nullDoctor_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Appointment(null, AMY, + VALID_DATE_1, "Follow-Up")); } @Test - public void secondConstructorr_invalidPatient_throwsIllegalArgumentException() { - Doctor validDoctor = DEREK; - Patient invalidPatient = null; - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime validAppointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - assertThrows(NullPointerException.class, () -> new Appointment(validDoctor, invalidPatient, - validAppointmentTime, "Follow-Up")); + public void secondConstructorr_nullPatient_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Appointment(DEREK, null, + VALID_DATE_1, "Follow-Up")); } @Test - public void secondConstructor_invalidAppointmentTime_throwsIllegalArgumentException() { - Doctor validDoctor = DEREK; - Patient validPatient = AMY; - LocalDateTime invalidAppointmentTime = null; - assertThrows(NullPointerException.class, () -> new Appointment(validDoctor, validPatient, - invalidAppointmentTime, "Follow-Up")); + public void secondConstructor_nullAppointmentTime_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Appointment(DEREK, AMY, + null, "Follow-Up")); } @Test - public void constructor_nullStatus() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - assertThrows(NullPointerException.class, () -> new Appointment(DEREK, AMY, appointmentTime, null)); + public void constructor_nullStatus() { // should this throw a nullPointerException? + assertThrows(NullPointerException.class, () -> new Appointment(DEREK, AMY, VALID_DATE_1, null)); } @Test public void testGetDoctor() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); assertEquals(newAppointment.getDoctor(), DEREK); } @Test public void testGetPatient() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); assertEquals(newAppointment.getPatient(), AMY); } @Test public void testGetAppointmentTime() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); - assertEquals(newAppointment.getAppointmentTime(), appointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); + assertEquals(newAppointment.getAppointmentTime(), VALID_DATE_1); } @Test public void testChangeDoctor() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); newAppointment.changeDoctor(CHERYL); assertEquals(newAppointment.getDoctor(), CHERYL); } @Test public void testChangePatient() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); newAppointment.changePatient(BOB); assertEquals(newAppointment.getPatient(), BOB); } @Test public void testSetAppointmentTime() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - LocalDateTime newAppointmentTime = LocalDateTime.parse("2022-02-14 14:30:00", formatter); - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); - newAppointment.setAppointmentTime(newAppointmentTime); - assertEquals(newAppointment.getAppointmentTime(), newAppointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); + newAppointment.setAppointmentTime(VALID_DATE_2); + assertEquals(newAppointment.getAppointmentTime(), VALID_DATE_2); } @Test public void testChangeStatus() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); String newStatus = "Completed"; - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); newAppointment.changeStatus(newStatus); assertEquals(newAppointment.getStatus(), newStatus); } @Test public void equals() { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime appointmentTime = LocalDateTime.parse("2022-02-14 13:30:00", formatter); - Appointment newAppointment = new Appointment(DEREK, AMY, appointmentTime); + Appointment newAppointment = new Appointment(DEREK, AMY, VALID_DATE_1); // same values -> returns true - assertTrue(newAppointment.equals(new Appointment(DEREK, AMY, appointmentTime))); + assertTrue(newAppointment.equals(new Appointment(DEREK, AMY, VALID_DATE_1))); // same object -> returns true assertTrue(newAppointment.equals(newAppointment)); @@ -161,6 +118,6 @@ public void equals() { assertFalse(newAppointment.equals(5.0f)); // different values -> returns false - assertFalse(newAppointment.equals(new Appointment(CHERYL, AMY, appointmentTime))); + assertFalse(newAppointment.equals(new Appointment(CHERYL, AMY, VALID_DATE_1))); } } From b8dfa110db9cd99e33cadae4285e59250d7e6e41 Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 12:35:30 +0800 Subject: [PATCH 04/13] Update JsonAdaptedDoctor --- .../address/storage/JsonAdaptedDoctor.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java index 604e56b5008..df80ebe0f2d 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java @@ -16,6 +16,7 @@ import seedu.address.model.person.Gender; import seedu.address.model.person.Ic; import seedu.address.model.person.Name; +import seedu.address.model.person.Patient; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.person.Remark; @@ -37,6 +38,7 @@ public class JsonAdaptedDoctor { private final String gender; private final String ic; private final List tags = new ArrayList<>(); + private final List patients = new ArrayList<>(); /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -45,7 +47,8 @@ public class JsonAdaptedDoctor { public JsonAdaptedDoctor(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("remark") String remark, @JsonProperty("gender") String gender, - @JsonProperty("nric") String ic, @JsonProperty("tags") List tags) { + @JsonProperty("nric") String ic, @JsonProperty("tags") List patients, + @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; this.email = email; @@ -53,6 +56,9 @@ public JsonAdaptedDoctor(@JsonProperty("name") String name, @JsonProperty("phone this.remark = remark; this.gender = gender; this.ic = ic; + if (patients != null) { + this.patients.addAll(patients); + } if (tags != null) { this.tags.addAll(tags); } @@ -61,7 +67,7 @@ public JsonAdaptedDoctor(@JsonProperty("name") String name, @JsonProperty("phone /** * Converts a given {@code Person} into this class for Jackson use. */ - public JsonAdaptedDoctor(Person source) { + public JsonAdaptedDoctor(Doctor source) { name = source.getName().fullName; phone = source.getPhone().value; email = source.getEmail().value; @@ -69,6 +75,9 @@ public JsonAdaptedDoctor(Person source) { remark = source.getRemark().value; gender = source.getGender().value; ic = source.getIc().value; + patients.addAll(source.getPatients().stream() + .map(JsonAdaptedPatient::new) + .collect(Collectors.toList())); tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -139,7 +148,16 @@ public Doctor toModelType() throws IllegalValueException { final Ic modelIc = new Ic(ic); final Set modelTags = new HashSet<>(doctorTags); - return new Doctor(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelGender, modelIc, + + final List listOfPatients = new ArrayList<>(); + for (JsonAdaptedPatient patient : patients) { + listOfPatients.add(patient.toModelType()); + } + Doctor modelDoctor = new Doctor(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelGender, modelIc, modelTags); + for (Patient patient : listOfPatients) { + modelDoctor.addPatient(patient); + } + return modelDoctor; } -} +} \ No newline at end of file From 597247fcebf3db68c8fd50f2a78947c645197aff Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 13:47:31 +0800 Subject: [PATCH 05/13] Add Appointment Attribute to Doctor --- .../seedu/address/model/person/Doctor.java | 18 +++++++++--------- .../address/storage/JsonAdaptedDoctor.java | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Doctor.java b/src/main/java/seedu/address/model/person/Doctor.java index 306ffb781a5..2ec5dc1a10a 100644 --- a/src/main/java/seedu/address/model/person/Doctor.java +++ b/src/main/java/seedu/address/model/person/Doctor.java @@ -12,7 +12,7 @@ * Guarantees: details are present and not null, field values are validated, immutable. */ public class Doctor extends Person { - private ArrayList patients = new ArrayList(); + private ArrayList appointments = new ArrayList(); /** * Every field must be present and not null. @@ -27,17 +27,17 @@ public Doctor(Name name, Phone phone, Email email, Address address, Remark remar * * @return An ArrayList containing the patients currently registered in the facility. */ - public ArrayList getPatients() { - return patients; + public ArrayList getAppointments() { + return appointments; } /** * Adds a new patient to the medical facility's list of patients. * - * @param patient The Patient object representing the individual to be added. + * @param appointment The Patient object representing the individual to be added. */ - public void addPatient(Patient patient) { - this.patients.add(patient); + public void addAppointment(Appointment appointment) { + this.appointments.add(appointment); } /** @@ -80,13 +80,13 @@ public boolean equals(Object other) { && gender.equals(otherDoctor.gender) && ic.equals(otherDoctor.ic) && tags.equals(otherDoctor.tags) - && patients.equals(otherDoctor.patients); + && appointments.equals(otherDoctor.appointments); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, gender, ic, tags, patients); + return Objects.hash(name, phone, email, address, gender, ic, tags, appointments); } @Override @@ -99,7 +99,7 @@ public String toString() { .add("remark", remark) .add("gender", gender) .add("nric", ic) - .add("patients", patients) + .add("appointments", appointments) .add("tags", tags) .toString(); } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java index df80ebe0f2d..fcbf17ad2c7 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java @@ -17,7 +17,6 @@ import seedu.address.model.person.Ic; import seedu.address.model.person.Name; import seedu.address.model.person.Patient; -import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.person.Remark; import seedu.address.model.tag.Tag; From 1bff024983f4680ee7b8cc071e7c37bffd35adeb Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 13:48:51 +0800 Subject: [PATCH 06/13] Add Appointment Attribute to Patient --- .../seedu/address/model/person/Doctor.java | 2 +- .../seedu/address/model/person/Patient.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Doctor.java b/src/main/java/seedu/address/model/person/Doctor.java index 2ec5dc1a10a..7e415145fb7 100644 --- a/src/main/java/seedu/address/model/person/Doctor.java +++ b/src/main/java/seedu/address/model/person/Doctor.java @@ -12,7 +12,7 @@ * Guarantees: details are present and not null, field values are validated, immutable. */ public class Doctor extends Person { - private ArrayList appointments = new ArrayList(); + private final ArrayList appointments = new ArrayList(); /** * Every field must be present and not null. diff --git a/src/main/java/seedu/address/model/person/Patient.java b/src/main/java/seedu/address/model/person/Patient.java index ba5c430a89c..98bb1403195 100644 --- a/src/main/java/seedu/address/model/person/Patient.java +++ b/src/main/java/seedu/address/model/person/Patient.java @@ -2,6 +2,7 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.util.ArrayList; import java.util.Objects; import java.util.Set; @@ -17,8 +18,8 @@ public class Patient extends Person { // Patient specific fields private final Condition condition; private final BloodType bloodType; - //private final Doctor doctor; to be implemented after Doctor class created - private Phone emergencyContact; + private final ArrayList appointments = new ArrayList(); + private final Phone emergencyContact; /** * Every field must be present and not null. @@ -44,6 +45,24 @@ public Phone getEmergencyContact() { return emergencyContact; } + /** + * Retrieves the list of patients stored in this medical facility. + * + * @return An ArrayList containing the patients currently registered in the facility. + */ + public ArrayList getAppointments() { + return appointments; + } + + /** + * Adds a new patient to the medical facility's list of patients. + * + * @param appointment The Patient object representing the individual to be added. + */ + public void addAppointment(Appointment appointment) { + this.appointments.add(appointment); + } + /** * Returns true if person is a doctor. */ From 239196c95554924957b2ceee69cb11d2f4041b37 Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 14:32:59 +0800 Subject: [PATCH 07/13] Create JsonAdaptedAppointment --- .../storage/JsonAdaptedAppointment.java | 77 +++++++++++++++++++ .../address/storage/JsonAdaptedDoctor.java | 27 +++---- 2 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedAppointment.java diff --git a/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java b/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java new file mode 100644 index 00000000000..f6ab6fab951 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedAppointment.java @@ -0,0 +1,77 @@ +package seedu.address.storage; + +import static seedu.address.storage.JsonAdaptedPatient.MISSING_FIELD_MESSAGE_FORMAT; + +import java.time.LocalDateTime; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.person.Appointment; +import seedu.address.model.person.Doctor; +import seedu.address.model.person.Name; +import seedu.address.model.person.Patient; +import seedu.address.model.tag.Tag; + +/** + * Jackson-friendly version of {@link Tag}. + */ +class JsonAdaptedAppointment { + + private final Doctor doctor; + private final Patient patient; + private final LocalDateTime appointmentTime; + private final String status; + + /** + * Constructs a {@code JsonAdaptedTag} with the given {@code tagName}. + */ + @JsonCreator + public JsonAdaptedAppointment(@JsonProperty("doctor") Doctor doctor, @JsonProperty("patient") Patient patient, + @JsonProperty("appointmentTime") LocalDateTime appointmentTime, + @JsonProperty("status") String status) { + this.doctor = doctor; + this.patient = patient; + this.appointmentTime = appointmentTime; + this.status = status; + } + + /** + * Converts a given {@code Tag} into this class for Jackson use. + */ + public JsonAdaptedAppointment(Appointment source) { + doctor = source.getDoctor(); + patient = source.getPatient(); + appointmentTime = source.getAppointmentTime(); + status = source.getStatus(); + } + + public String checkStatus() throws IllegalValueException { + if (status == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); + } + return status; + } + + public LocalDateTime checkAppointmentTime() throws IllegalValueException { + if (appointmentTime == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); + } + return appointmentTime; + } + + /** + * Converts this Jackson-friendly adapted tag object into the model's {@code Tag} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted tag. + */ + public Appointment toModelType() throws IllegalValueException { + final Doctor modelDoctor = new JsonAdaptedDoctor(doctor).toModelType(); + final Patient modelPatient = new JsonAdaptedPatient(patient).toModelType(); + final LocalDateTime modelAppointmentTime = checkAppointmentTime(); + final String modelStatus = checkStatus(); + return new Appointment(modelDoctor, modelPatient, modelAppointmentTime, modelStatus); + } +} + diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java index fcbf17ad2c7..027b21555b5 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java @@ -11,12 +11,12 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.person.Address; +import seedu.address.model.person.Appointment; import seedu.address.model.person.Doctor; import seedu.address.model.person.Email; import seedu.address.model.person.Gender; import seedu.address.model.person.Ic; import seedu.address.model.person.Name; -import seedu.address.model.person.Patient; import seedu.address.model.person.Phone; import seedu.address.model.person.Remark; import seedu.address.model.tag.Tag; @@ -37,7 +37,7 @@ public class JsonAdaptedDoctor { private final String gender; private final String ic; private final List tags = new ArrayList<>(); - private final List patients = new ArrayList<>(); + private final List appointments = new ArrayList<>(); /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -46,7 +46,8 @@ public class JsonAdaptedDoctor { public JsonAdaptedDoctor(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("remark") String remark, @JsonProperty("gender") String gender, - @JsonProperty("nric") String ic, @JsonProperty("tags") List patients, + @JsonProperty("nric") String ic, + @JsonProperty("tags") List appointments, @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; @@ -55,8 +56,8 @@ public JsonAdaptedDoctor(@JsonProperty("name") String name, @JsonProperty("phone this.remark = remark; this.gender = gender; this.ic = ic; - if (patients != null) { - this.patients.addAll(patients); + if (appointments != null) { + this.appointments.addAll(appointments); } if (tags != null) { this.tags.addAll(tags); @@ -74,8 +75,8 @@ public JsonAdaptedDoctor(Doctor source) { remark = source.getRemark().value; gender = source.getGender().value; ic = source.getIc().value; - patients.addAll(source.getPatients().stream() - .map(JsonAdaptedPatient::new) + appointments.addAll(source.getAppointments().stream() + .map(JsonAdaptedAppointment::new) .collect(Collectors.toList())); tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) @@ -148,15 +149,15 @@ public Doctor toModelType() throws IllegalValueException { final Set modelTags = new HashSet<>(doctorTags); - final List listOfPatients = new ArrayList<>(); - for (JsonAdaptedPatient patient : patients) { - listOfPatients.add(patient.toModelType()); + final List listOfAppointments = new ArrayList<>(); + for (JsonAdaptedAppointment appointment : appointments) { + listOfAppointments.add(appointment.toModelType()); } Doctor modelDoctor = new Doctor(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelGender, modelIc, modelTags); - for (Patient patient : listOfPatients) { - modelDoctor.addPatient(patient); + for (Appointment appointment : listOfAppointments) { + modelDoctor.addAppointment(appointment); } return modelDoctor; } -} \ No newline at end of file +} From 4361bc6151d4fa50339532000023cc02ec94f197 Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 14:43:19 +0800 Subject: [PATCH 08/13] Complete Implementation of JsonAdapted Classes --- .../address/storage/JsonAdaptedDoctor.java | 111 ++---------------- .../address/storage/JsonAdaptedPatient.java | 23 +++- 2 files changed, 31 insertions(+), 103 deletions(-) diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java index 027b21555b5..eb76bba5272 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedDoctor.java @@ -1,41 +1,24 @@ package seedu.address.storage; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.Address; import seedu.address.model.person.Appointment; import seedu.address.model.person.Doctor; -import seedu.address.model.person.Email; -import seedu.address.model.person.Gender; -import seedu.address.model.person.Ic; -import seedu.address.model.person.Name; -import seedu.address.model.person.Phone; -import seedu.address.model.person.Remark; -import seedu.address.model.tag.Tag; +import seedu.address.model.person.Person; /** * Jackson-friendly version of {@link Doctor}. */ -public class JsonAdaptedDoctor { +public class JsonAdaptedDoctor extends JsonAdaptedPerson { - public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!"; - - private final String name; - private final String phone; - private final String email; - private final String address; - private final String remark; - private final String gender; - private final String ic; + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Doctor's %s field is missing!"; private final List tags = new ArrayList<>(); private final List appointments = new ArrayList<>(); @@ -47,40 +30,22 @@ public JsonAdaptedDoctor(@JsonProperty("name") String name, @JsonProperty("phone @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("remark") String remark, @JsonProperty("gender") String gender, @JsonProperty("nric") String ic, - @JsonProperty("tags") List appointments, + @JsonProperty("appointments") List appointments, @JsonProperty("tags") List tags) { - this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - this.remark = remark; - this.gender = gender; - this.ic = ic; + super(name, phone, email, address, remark, gender, ic, tags); if (appointments != null) { this.appointments.addAll(appointments); } - if (tags != null) { - this.tags.addAll(tags); - } } /** * Converts a given {@code Person} into this class for Jackson use. */ public JsonAdaptedDoctor(Doctor source) { - name = source.getName().fullName; - phone = source.getPhone().value; - email = source.getEmail().value; - address = source.getAddress().value; - remark = source.getRemark().value; - gender = source.getGender().value; - ic = source.getIc().value; + super(source); appointments.addAll(source.getAppointments().stream() .map(JsonAdaptedAppointment::new) .collect(Collectors.toList())); - tags.addAll(source.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList())); } /** @@ -89,72 +54,14 @@ public JsonAdaptedDoctor(Doctor source) { * @throws IllegalValueException if there were any data constraints violated in the adapted person. */ public Doctor toModelType() throws IllegalValueException { - final List doctorTags = new ArrayList<>(); - for (JsonAdaptedTag tag : tags) { - doctorTags.add(tag.toModelType()); - } - - if (name == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); - } - if (!Name.isValidName(name)) { - throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); - } - final Name modelName = new Name(name); - - if (phone == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); - } - if (!Phone.isValidPhone(phone)) { - throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); - } - final Phone modelPhone = new Phone(phone); - - if (email == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); - } - if (!Email.isValidEmail(email)) { - throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); - } - final Email modelEmail = new Email(email); - - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); - } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); - } - final Address modelAddress = new Address(address); - - if (remark == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName())); - } - final Remark modelRemark = new Remark(remark); - - if (gender == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Gender.class.getSimpleName())); - } - if (!Gender.isValidGender(gender)) { - throw new IllegalValueException(Gender.MESSAGE_CONSTRAINTS); - } - final Gender modelGender = new Gender(gender); - - if (ic == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Ic.class.getSimpleName())); - } - if (!Ic.isValidIc(ic)) { - throw new IllegalValueException(Ic.MESSAGE_CONSTRAINTS); - } - final Ic modelIc = new Ic(ic); - - final Set modelTags = new HashSet<>(doctorTags); + Person p = super.toModelType(); final List listOfAppointments = new ArrayList<>(); for (JsonAdaptedAppointment appointment : appointments) { listOfAppointments.add(appointment.toModelType()); } - Doctor modelDoctor = new Doctor(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelGender, modelIc, - modelTags); + Doctor modelDoctor = new Doctor(p.getName(), p.getPhone(), p.getEmail(), p.getAddress(), p.getRemark(), + p.getGender(), p.getIc(), p.getTags()); for (Appointment appointment : listOfAppointments) { modelDoctor.addAppointment(appointment); } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPatient.java b/src/main/java/seedu/address/storage/JsonAdaptedPatient.java index 54ed5a4b70a..e9e0d96c526 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPatient.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPatient.java @@ -1,11 +1,14 @@ package seedu.address.storage; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.person.Appointment; import seedu.address.model.person.BloodType; import seedu.address.model.person.Condition; import seedu.address.model.person.Patient; @@ -22,6 +25,7 @@ class JsonAdaptedPatient extends JsonAdaptedPerson { private final String emergencyContact; private final String condition; private final String bloodType; + private final List appointments = new ArrayList<>(); /** * Constructs a {@code JsonAdaptedPatient} with the given person details. @@ -31,9 +35,13 @@ public JsonAdaptedPatient(@JsonProperty("name") String name, @JsonProperty("phon @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("remark") String remark, @JsonProperty("gender") String gender, @JsonProperty("ic") String ic, @JsonProperty("tags") List tags, + @JsonProperty("appointments") List appointments, @JsonProperty("condition") String condition, @JsonProperty("bloodType") String bloodType, @JsonProperty("emergencyContact") String emergencyContact) { super(name, phone, email, address, remark, gender, ic, tags); + if (appointments != null) { + this.appointments.addAll(appointments); + } this.condition = condition; this.bloodType = bloodType; this.emergencyContact = emergencyContact; @@ -45,6 +53,9 @@ public JsonAdaptedPatient(@JsonProperty("name") String name, @JsonProperty("phon public JsonAdaptedPatient(Patient source) { super(source); + appointments.addAll(source.getAppointments().stream() + .map(JsonAdaptedAppointment::new) + .collect(Collectors.toList())); this.emergencyContact = source.getEmergencyContact().value; this.bloodType = source.getBloodType().value; this.condition = source.getCondition().value; @@ -57,12 +68,22 @@ public JsonAdaptedPatient(Patient source) { */ public Patient toModelType() throws IllegalValueException { Person p = super.toModelType(); + + final List listOfAppointments = new ArrayList<>(); + for (JsonAdaptedAppointment appointment : appointments) { + listOfAppointments.add(appointment.toModelType()); + } final Phone modelEmergencyContact = checkEmergencyContact(); final Condition modelCondition = checkCondition(); final BloodType modelBloodType = checkBloodType(); - return new Patient(p.getName(), p.getPhone(), modelEmergencyContact, p.getEmail(), p.getAddress(), + Patient modelPatient = new Patient(p.getName(), p.getPhone(), modelEmergencyContact, p.getEmail(), p.getAddress(), p.getRemark(), p.getGender(), p.getIc(), modelCondition, modelBloodType, p.getTags()); + + for (Appointment appointment : listOfAppointments) { + modelPatient.addAppointment(appointment); + } + return modelPatient; } /** From a22cd65e7fc422edf101a468adbcd0aa34d880a8 Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 14:54:28 +0800 Subject: [PATCH 09/13] Add Appointment to PersonCard Classes --- src/main/java/seedu/address/ui/DoctorCard.java | 7 +++++++ src/main/java/seedu/address/ui/PatientCard.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/seedu/address/ui/DoctorCard.java b/src/main/java/seedu/address/ui/DoctorCard.java index f876a7e479f..dd9e6db019b 100644 --- a/src/main/java/seedu/address/ui/DoctorCard.java +++ b/src/main/java/seedu/address/ui/DoctorCard.java @@ -7,6 +7,7 @@ import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; +import seedu.address.model.person.Appointment; import seedu.address.model.person.Doctor; @@ -41,6 +42,8 @@ public class DoctorCard extends UiPart { @FXML private FlowPane tags; @FXML + private FlowPane appointments; + @FXML private Label remark; @FXML private Label gender; @@ -64,5 +67,9 @@ public DoctorCard(Doctor doctor, int displayedIndex) { doctor.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + doctor.getAppointments().stream() + .sorted(Comparator.comparing(Appointment::getAppointmentTime)) + .forEach(appointment -> appointments.getChildren() + .add(new Label(appointment.getAppointmentTime().toString()))); } } diff --git a/src/main/java/seedu/address/ui/PatientCard.java b/src/main/java/seedu/address/ui/PatientCard.java index d23ffc80afc..d59e04fcd61 100644 --- a/src/main/java/seedu/address/ui/PatientCard.java +++ b/src/main/java/seedu/address/ui/PatientCard.java @@ -7,6 +7,7 @@ import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; +import seedu.address.model.person.Appointment; import seedu.address.model.person.Patient; /** @@ -41,6 +42,8 @@ public class PatientCard extends UiPart { @FXML private FlowPane tags; @FXML + private FlowPane appointments; + @FXML private Label remark; @FXML private Label gender; @@ -70,6 +73,10 @@ public PatientCard(Patient person, int displayedIndex) { person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + person.getAppointments().stream() + .sorted(Comparator.comparing(Appointment::getAppointmentTime)) + .forEach(appointment -> appointments.getChildren() + .add(new Label(appointment.getAppointmentTime().toString()))); condition.setText("Condition: " + person.getCondition().value); bloodType.setText("Blood Type: " + person.getBloodType().value); From d05c2273fc5e09beec1ba9cb6ed7c88c77249650 Mon Sep 17 00:00:00 2001 From: Mohammed-Faizzzz <110959467+Mohammed-Faizzzz@users.noreply.github.com> Date: Sat, 28 Oct 2023 15:21:08 +0800 Subject: [PATCH 10/13] Modify fxml Files to include Appointment --- src/main/resources/view/DoctorListCard.fxml | 1 + src/main/resources/view/PatientListCard.fxml | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/resources/view/DoctorListCard.fxml b/src/main/resources/view/DoctorListCard.fxml index 0f988d18a13..0c266fc059f 100644 --- a/src/main/resources/view/DoctorListCard.fxml +++ b/src/main/resources/view/DoctorListCard.fxml @@ -28,6 +28,7 @@