Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S2#55 from wynonaK/appointmentSto…
Browse files Browse the repository at this point in the history
…rage

Allowing for appointments to be stored
  • Loading branch information
Aquarinte authored Mar 23, 2018
2 parents 4968d70 + 3cb626e commit 89c2125
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public AddressBookChangedEvent(ReadOnlyAddressBook data) {
public String toString() {
return "number of persons " + data.getPersonList().size()
+ ", number of tags " + data.getTagList().size()
+ ", number of appointments " + data.getAppointmentList().size()
+ ", number of pet patients " + data.getPetPatientList().size()
+ ", number of pet patient tags " + data.getPetPatientTagList().size();
}
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public void setTags(Set<Tag> tags) {
this.tags.setTags(tags);
}

public void setAppointments(List<Appointment> appointments) throws DuplicateAppointmentException {
this.appointments.setAppointments(appointments);
}

public void setPetPatients(List<PetPatient> petPatients) throws DuplicatePetPatientException {
this.petPatients.setPetPatients(petPatients);
}
Expand All @@ -95,6 +99,15 @@ public void resetData(ReadOnlyAddressBook newData) {
throw new AssertionError("AddressBooks should not have duplicate persons");
}

List<Appointment> syncedAppointmentList = newData.getAppointmentList().stream()
.map(this::syncWithAppointmentMasterTagList)
.collect(Collectors.toList());
try {
setAppointments(syncedAppointmentList);
} catch (DuplicateAppointmentException dae) {
throw new AssertionError("AddressBook should not have appointments on the same slot");
}

setPetPatientTags(new HashSet<>(newData.getPetPatientTagList()));
List<PetPatient> syncedPetPatientList = newData.getPetPatientList().stream()
.map(this::syncWithMasterTagList)
Expand Down Expand Up @@ -329,6 +342,7 @@ public void removeTag(Tag tag) {
public String toString() {
return persons.asObservableList().size() + " persons, "
+ tags.asObservableList().size() + " tags, "
+ appointments.asObservableList().size() + " appointments"
+ petPatients.asObservableList().size() + " pet patients, "
+ petPatientTags.asObservableList().size() + " pet patient tags";
// TODO: refine later
Expand All @@ -344,6 +358,11 @@ public ObservableList<Tag> getTagList() {
return tags.asObservableList();
}

@Override
public ObservableList<Appointment> getAppointmentList() {
return appointments.asObservableList();
}

@Override
public ObservableList<PetPatient> getPetPatientList() {
return petPatients.asObservableList();
Expand All @@ -360,13 +379,14 @@ public boolean equals(Object other) {
|| (other instanceof AddressBook // instanceof handles nulls
&& this.persons.equals(((AddressBook) other).persons)
&& this.tags.equalsOrderInsensitive(((AddressBook) other).tags))
&& this.appointments.equals(((AddressBook) other).appointments)
&& this.petPatients.equals(((AddressBook) other).petPatients)
&& this.petPatientTags.equalsOrderInsensitive(((AddressBook) other).petPatientTags);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(persons, tags, petPatients, petPatientTags);
return Objects.hash(persons, tags, appointments, petPatients, petPatientTags);
}
}
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
Predicate<Appointment> PREDICATE_SHOW_ALL_APPOINTMENTS = unused -> true;
Predicate<PetPatient> PREDICATE_SHOW_ALL_PET_PATIENTS = unused -> true;

/** Clears existing backing model and replaces with the provided new data. */
Expand Down Expand Up @@ -57,6 +58,14 @@ void updatePerson(Person target, Person editedPerson)
*/
void updateFilteredPersonList(Predicate<Person> predicate);

/** Returns an unmodifiable view of the filtered appointment list */
ObservableList<Appointment> getFilteredAppointmentList();
/**
* Updates the filter of the filtered appointment list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredAppointmentList(Predicate<Appointment> predicate);

void updateFilteredPetPatientList(Predicate<PetPatient> predicate);

void addPetPatient(PetPatient petPatient) throws DuplicatePetPatientException;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ModelManager extends ComponentManager implements Model {

private final AddressBook addressBook;
private final FilteredList<Person> filteredPersons;
private final FilteredList<Appointment> filteredAppointments;
private final FilteredList<PetPatient> filteredPetPatients;

/**
Expand All @@ -43,6 +44,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, UserPrefs userPrefs) {

this.addressBook = new AddressBook(addressBook);
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
filteredAppointments = new FilteredList<>(this.addressBook.getAppointmentList());
filteredPetPatients = new FilteredList<>(this.addressBook.getPetPatientList());
}

Expand Down Expand Up @@ -98,6 +100,8 @@ public void updatePerson(Person target, Person editedPerson)
@Override
public synchronized void addAppointment(Appointment appointment) throws DuplicateAppointmentException {
addressBook.addAppointment(appointment);
updateFilteredAppointmentList(PREDICATE_SHOW_ALL_APPOINTMENTS);
indicateAddressBookChanged();
}

@Override
Expand All @@ -122,6 +126,23 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
filteredPersons.setPredicate(predicate);
}

//=========== Filtered Appointment List Accessors =============================================================

/**
* Returns an unmodifiable view of the list of {@code Appointment} backed by the internal list of
* {@code addressBook}
*/
@Override
public ObservableList<Appointment> getFilteredAppointmentList() {
return FXCollections.unmodifiableObservableList(filteredAppointments);
}

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

@Override
public void updateFilteredPetPatientList(Predicate<PetPatient> predicate) {
requireNonNull(predicate);
Expand All @@ -144,6 +165,7 @@ public boolean equals(Object obj) {
ModelManager other = (ModelManager) obj;
return addressBook.equals(other.addressBook)
&& filteredPersons.equals(other.filteredPersons)
&& filteredAppointments.equals(other.filteredAppointments)
&& filteredPetPatients.equals(other.filteredPetPatients);
}

Expand Down
10 changes: 10 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.Person;
import seedu.address.model.petpatient.PetPatient;
import seedu.address.model.tag.Tag;
Expand All @@ -23,12 +24,21 @@ public interface ReadOnlyAddressBook {
ObservableList<Tag> getTagList();

/**
* Returns an unmodifiable view of the appointments list.
* This list will not contain any duplicate tags.
*/
ObservableList<Appointment> getAppointmentList();

/**
* Returns an unmodifiable view of the pet patient list.
* This list will not contain any duplicate pet patients.
*/
ObservableList<PetPatient> getPetPatientList();

/**
* Returns an unmodifiable view of the pet patient tags list.
* This list will not contain any duplicate pet patient tags.
*/
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/address/model/appointment/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Objects;
import java.util.Set;

import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.petpatient.PetPatient;
import seedu.address.model.tag.Tag;
Expand All @@ -18,8 +19,9 @@
* Guarantees: details are present and not null, field values are validated.
*/
public class Appointment {
private final Person owner; //owner of the appointment
private final PetPatient pet;
private Person owner = null; //owner of the appointment
private Name ownerName = null;
private PetPatient pet = null;
private Remark remark; //remarks
private LocalDateTime localDateTime; //date of appointment

Expand All @@ -38,10 +40,23 @@ public Appointment(Person owner, PetPatient pet, Remark remark, LocalDateTime lo
this.type = new UniqueTagList(type);
}

public Appointment(Name owner, Remark remark, LocalDateTime localDateTime, Set<Tag> type) {
requireAllNonNull(owner, remark, localDateTime, type);
this.ownerName = owner;
this.remark = remark;
this.localDateTime = localDateTime;
// protect internal tags from changes in the arg list
this.type = new UniqueTagList(type);
}

public Person getOwner() {
return owner;
}

public Name getOwnerName() {
return ownerName;
}

public PetPatient getPetPatient() {
return pet;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package seedu.address.model.appointment;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Iterator;
import java.util.List;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.address.model.appointment.exceptions.AppointmentNotFoundException;
import seedu.address.model.appointment.exceptions.DuplicateAppointmentException;

/**
Expand Down Expand Up @@ -40,6 +43,42 @@ public void add(Appointment toAdd) throws DuplicateAppointmentException {
internalList.add(toAdd);
}

/**
* Replaces the appointment {@code target} in the list with {@code editedAppointment}.
*
* @throws DuplicateAppointmentException if the replacement is equivalent to
* another existing appointment in the list.
* @throws AppointmentNotFoundException if {@code target} could not be found in the list.
*/
public void setAppointment(Appointment target, Appointment editedAppointment)
throws DuplicateAppointmentException, AppointmentNotFoundException {
requireNonNull(editedAppointment);

int index = internalList.indexOf(target);
if (index == -1) {
throw new AppointmentNotFoundException();
}

if (!target.equals(editedAppointment) && internalList.contains(editedAppointment)) {
throw new DuplicateAppointmentException();
}

internalList.set(index, editedAppointment);
}

public void setAppointments(UniqueAppointmentList replacement) {
this.internalList.setAll(replacement.internalList);
}

public void setAppointments(List<Appointment> appointments) throws DuplicateAppointmentException {
requireAllNonNull(appointments);
final UniqueAppointmentList replacement = new UniqueAppointmentList();
for (final Appointment appointment : appointments) {
replacement.add(appointment);
}
setAppointments(replacement);
}

/**
* Returns the backing list as an unmodifiable {@code ObservableList}.
*/
Expand Down
Loading

0 comments on commit 89c2125

Please sign in to comment.