Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tanveersingh10 committed Nov 2, 2023
2 parents a6573bf + ca0d87c commit ae4b669
Show file tree
Hide file tree
Showing 30 changed files with 731 additions and 254 deletions.
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;

Expand Down Expand Up @@ -40,6 +41,7 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of doctors */
ObservableList<Doctor> getFilteredDoctorList();

ObservableList<Appointment> getFilteredAppointmentList();
/**
* Returns the user prefs' address book file path.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;
import seedu.address.storage.Storage;
Expand Down Expand Up @@ -81,6 +82,11 @@ public ObservableList<Doctor> getFilteredDoctorList() {
return model.getFilteredDoctorList();
}

@Override
public ObservableList<Appointment> getFilteredAppointmentList() {
return model.getFilteredAppointmentList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
70 changes: 59 additions & 11 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@

import javafx.collections.ObservableList;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;
import seedu.address.model.person.UniquePersonList;
import seedu.address.model.person.UniqueAppointmentList;
import seedu.address.model.person.UniqueDoctorList;
import seedu.address.model.person.UniquePatientList;

/**
* Wraps all data at the address-book level
* Duplicates are not allowed (by .isSamePerson comparison)
*/
public class AddressBook implements ReadOnlyAddressBook {
private final UniquePersonList<Doctor> doctors;
private final UniquePersonList<Patient> patients;
private final UniqueDoctorList doctors;
private final UniquePatientList patients;
private final UniqueAppointmentList appointments;

/*
* The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication
Expand All @@ -27,8 +31,9 @@ public class AddressBook implements ReadOnlyAddressBook {
* among constructors.
*/
{
doctors = new UniquePersonList();
patients = new UniquePersonList();
doctors = new UniqueDoctorList();
patients = new UniquePatientList();
appointments = new UniqueAppointmentList();
}

public AddressBook() {
Expand All @@ -49,15 +54,23 @@ public AddressBook(ReadOnlyAddressBook toBeCopied) {
* {@code patients} must not contain duplicate patients.
*/
public void setPatients(List<Patient> patients) {
this.patients.setPersons(patients);
this.patients.setObjects(patients);
}

/**
* Replaces the contents of the doctors list with {@code doctors}.
* {@code doctors} must not contain duplicate persons.
*/
public void setDoctors(List<Doctor> doctors) {
this.doctors.setPersons(doctors);
this.doctors.setObjects(doctors);
}

/**
* Replaces the contents of the appointments list with {@code appointments}.
* {@code appointments} must not contain duplicate appointments.
*/
public void setAppointments(List<Appointment> appointments) {
this.appointments.setObjects(appointments);
}

/**
Expand All @@ -67,6 +80,7 @@ public void resetData(ReadOnlyAddressBook newData) {
requireNonNull(newData);
setDoctors(newData.getDoctorList());
setPatients(newData.getPatientList());
setAppointments(newData.getAppointmentList());
}

//// person-level operations
Expand All @@ -88,6 +102,14 @@ public boolean hasDoctor(Doctor doctor) {
return doctors.contains(doctor);
}

/**
* Returns true if a appointment with the same details as {@code appointment} exists in the address book.
*/
public boolean hasAppointment(Appointment appointment) {
requireNonNull(appointment);
return appointments.contains(appointment);
}

/**
* Adds a person to the address book.
* The person must not already exist in the address book.
Expand All @@ -106,6 +128,10 @@ public void addDoctor(Doctor d) {
doctors.add(d);
}

public void addAppointment(Appointment a) {
appointments.add(a);
}

/**
* Replaces the given person {@code target} in the list with {@code editedPerson}.
* Replaces the given patients {@code target} in the list with {@code editedPerson}.
Expand All @@ -115,7 +141,7 @@ public void addDoctor(Doctor d) {
public void setPatient(Patient target, Patient editedPerson) {
requireNonNull(editedPerson);

patients.setPerson(target, editedPerson);
patients.setObject(target, editedPerson);
}

/**
Expand All @@ -126,7 +152,13 @@ public void setPatient(Patient target, Patient editedPerson) {
public void setDoctor(Doctor target, Doctor editedDoctor) {
requireNonNull(editedDoctor);

doctors.setPerson(target, editedDoctor);
doctors.setObject(target, editedDoctor);
}

public void setAppointment(Appointment target, Appointment editedAppointment) {
requireNonNull(editedAppointment);

appointments.setObject(target, editedAppointment);
}

/**
Expand All @@ -149,13 +181,24 @@ public void removeDoctor(Doctor key) {
}
}

/**
* Removes {@code key} from this {@code AddressBook}.
* {@code key} must exist in the address book.
*/
public void removeAppointment(Appointment key) {
if (appointments.contains(key)) {
appointments.remove(key);
}
}

//// util methods

@Override
public String toString() { //not sure how to modify this
return new ToStringBuilder(this)
.add("patients", patients)
.add("doctors", doctors)
.add("appointments", appointments)
.toString();
}

Expand All @@ -167,6 +210,10 @@ public ObservableList<Doctor> getDoctorList() {
return doctors.asUnmodifiableObservableList();
}

public ObservableList<Appointment> getAppointmentList() {
return appointments.asUnmodifiableObservableList();
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -180,10 +227,11 @@ public boolean equals(Object other) {

AddressBook otherAddressBook = (AddressBook) other;
return patients.equals(otherAddressBook.patients)
&& doctors.equals((otherAddressBook.doctors));
&& doctors.equals((otherAddressBook.doctors))
&& appointments.equals((otherAddressBook.appointments));
}
@Override
public int hashCode() {
return Objects.hash(patients, doctors);
return Objects.hash(patients, doctors, appointments);
}
}
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;
import seedu.address.model.person.Person;
Expand All @@ -20,6 +21,8 @@ public interface Model {
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
Predicate<Doctor> PREDICATE_SHOW_ALL_DOCTORS = unused -> true;

Predicate<Appointment> PREDICATE_SHOW_ALL_APPOINTMENTS = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
*/
Expand Down Expand Up @@ -84,6 +87,10 @@ public interface Model {
*/
void setPerson(Person target, Person editedPerson);

void addAppointment(Appointment appointment);

void setAppointment(Appointment target, Appointment editedAppointment);

/**
* Returns an unmodifiable view of the filtered person list
*/
Expand All @@ -99,6 +106,8 @@ public interface Model {
*/
ObservableList<Doctor> getFilteredDoctorList();

ObservableList<Appointment> getFilteredAppointmentList();

/**
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
*
Expand All @@ -109,4 +118,6 @@ public interface Model {
void undo() throws CommandException;

void redo() throws CommandException;

void updateFilteredAppointmentList(Predicate<Appointment> predicate);
}
26 changes: 26 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;
import seedu.address.model.person.Person;
Expand All @@ -31,6 +32,7 @@ public class ModelManager implements Model {
private final UserPrefs userPrefs;
private final FilteredList<Doctor> filteredDoctors;
private final FilteredList<Patient> filteredPatients;
private final FilteredList<Appointment> filteredAppointments;

/**
* Initializes a ModelManager with the given addressBook and userPrefs.
Expand All @@ -45,6 +47,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs
this.redoList = new ArrayList<>();
filteredDoctors = new FilteredList<>(this.addressBook.getDoctorList());
filteredPatients = new FilteredList<>(this.addressBook.getPatientList());
filteredAppointments = new FilteredList<>(this.addressBook.getAppointmentList());
}

public ModelManager() {
Expand Down Expand Up @@ -162,6 +165,13 @@ public void addPerson(Person person) {
updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
}

@Override
public void addAppointment(Appointment appointment) {
updateBackup();
addressBook.addAppointment(appointment);
updateFilteredAppointmentList(PREDICATE_SHOW_ALL_APPOINTMENTS);
}

@Override
public void setPerson(Person target, Person editedPerson) {
requireAllNonNull(target, editedPerson);
Expand All @@ -174,6 +184,12 @@ public void setPerson(Person target, Person editedPerson) {
}
}

@Override
public void setAppointment(Appointment target, Appointment editedAppointment) {
updateBackup();
addressBook.setAppointment(target, editedAppointment);
}

/**
* Returns an unmodifiable view of the filtered person list
*/
Expand Down Expand Up @@ -201,12 +217,22 @@ public ObservableList<Doctor> getFilteredDoctorList() {
return filteredDoctors;
}

@Override
public ObservableList<Appointment> getFilteredAppointmentList() {
return filteredAppointments;
}

@Override
public void updateFilteredPersonList(Predicate<Person> predicate) {
requireNonNull(predicate);
filteredPatients.setPredicate(predicate);
filteredDoctors.setPredicate(predicate);
}
@Override
public void updateFilteredAppointmentList(Predicate<Appointment> predicate) {
requireNonNull(predicate);
filteredAppointments.setPredicate(predicate);
}

@Override
public boolean equals(Object other) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model;

import javafx.collections.ObservableList;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;

Expand All @@ -14,4 +15,5 @@ public interface ReadOnlyAddressBook {
*/
ObservableList<Doctor> getDoctorList();
ObservableList<Patient> getPatientList();
ObservableList<Appointment> getAppointmentList();
}
Loading

0 comments on commit ae4b669

Please sign in to comment.