Skip to content

Commit

Permalink
Merge pull request #122 from Mohammed-Faizzzz/branch-AddAppointment-UI
Browse files Browse the repository at this point in the history
Branch new-appointment UI
  • Loading branch information
Mohammed-Faizzzz committed Oct 29, 2023
2 parents f7ee0c4 + b127780 commit d586698
Show file tree
Hide file tree
Showing 24 changed files with 404 additions and 239 deletions.
33 changes: 23 additions & 10 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Address;
import seedu.address.model.person.BloodType;
import seedu.address.model.person.Condition;
Expand Down Expand Up @@ -212,7 +213,7 @@ public static class EditPersonDescriptor {
private Set<Tag> tags;
private Condition condition;
private BloodType bloodType;
private ArrayList<Patient> patients;
private Set<Appointment> appointments;

public EditPersonDescriptor() {
}
Expand All @@ -233,15 +234,15 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setTags(toCopy.tags);
setBloodType(toCopy.bloodType);
setCondition(toCopy.condition);
setPatients(toCopy.patients);
setAppointments(toCopy.appointments);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, emergencyContact, address,
gender, ic, tags, bloodType, condition, remark, patients);
gender, ic, tags, bloodType, condition, remark, appointments);
}

public void setName(Name name) {
Expand Down Expand Up @@ -275,12 +276,6 @@ public void setEmail(Email email) {
public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}
public void setPatients(ArrayList<Patient> patients) {
this.patients = patients;
}
public Optional<ArrayList<Patient>> getPatients() {
return Optional.ofNullable(patients);
}
public void setAddress(Address address) {
this.address = address;
}
Expand Down Expand Up @@ -347,6 +342,22 @@ public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
*/
public void setAppointments(Set<Appointment> appointments) {
this.appointments = (appointments != null) ? new HashSet<>(appointments) : null;
}
/**
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
*/
public Optional<Set<Appointment>> getAppointments() {
return (appointments != null) ? Optional.of(Collections.unmodifiableSet(appointments)) : Optional.empty();
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -368,7 +379,8 @@ public boolean equals(Object other) {
&& Objects.equals(tags, otherEditPersonDescriptor.tags)
&& Objects.equals(condition, otherEditPersonDescriptor.condition)
&& Objects.equals(bloodType, otherEditPersonDescriptor.bloodType)
&& Objects.equals(remark, otherEditPersonDescriptor.remark);
&& Objects.equals(remark, otherEditPersonDescriptor.remark)
&& Objects.equals(appointments, otherEditPersonDescriptor.appointments);
}

@Override
Expand All @@ -383,6 +395,7 @@ public String toString() {
.add("tags", tags)
.add("condition", condition)
.add("blood type", bloodType)
.add("appointments", appointments)
.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class AddDoctorCommandParser implements Parser<AddDoctorCommand> {
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)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/");
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package seedu.address.model.person;
package seedu.address.model.appointment;

import static java.util.Objects.requireNonNull;

import java.time.LocalDateTime;

import seedu.address.model.person.Doctor;
import seedu.address.model.person.Patient;

/**
* 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.
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/seedu/address/model/person/Doctor.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package seedu.address.model.person;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.tag.Tag;

/**
* Represents a Doctor in the address book.
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Doctor extends Person {
private ArrayList<Patient> patients = new ArrayList<Patient>();
private final Set<Appointment> appointments = new HashSet<>();

/**
* Every field must be present and not null.
Expand All @@ -27,17 +28,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<Patient> getPatients() {
return patients;
public Set<Appointment> 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);
}

/**
Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof Person)) {
if (!(other instanceof Doctor)) {
return false;
}

Expand All @@ -80,13 +81,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
Expand All @@ -99,7 +100,7 @@ public String toString() {
.add("remark", remark)
.add("gender", gender)
.add("nric", ic)
.add("patients", patients)
.add("appointments", appointments)
.add("tags", tags)
.toString();
}
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/seedu/address/model/person/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -17,8 +19,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 Set<Appointment> appointments = new HashSet<>();
private final Phone emergencyContact;

/**
* Every field must be present and not null.
Expand All @@ -44,6 +46,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 Set<Appointment> 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.
*/
Expand Down Expand Up @@ -85,7 +105,8 @@ public boolean equals(Object other) {
&& ic.equals(otherPatient.ic)
&& tags.equals(otherPatient.tags)
&& condition.equals(otherPatient.condition)
&& bloodType.equals(otherPatient.bloodType);
&& bloodType.equals(otherPatient.bloodType)
&& appointments.equals(otherPatient.appointments);
}

@Override
Expand All @@ -107,9 +128,9 @@ public String toString() {
.add("nric", ic)
.add("condition", condition)
.add("bloodType", bloodType)
.add("appointments", appointments)
.add("tags", tags)
.toString();
}

}

9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.person.Address;
import seedu.address.model.person.BloodType;
import seedu.address.model.person.Condition;
Expand Down Expand Up @@ -108,4 +109,12 @@ public static Set<Tag> getTagSet(String... strings) {
.collect(Collectors.toSet());
}

/**
* Returns a tag set containing the list of strings given.
*/
public static Set<Appointment> getAppointmentSet(Appointment... appointments) {
return Arrays.stream(appointments)
.collect(Collectors.toSet());
}

}
77 changes: 77 additions & 0 deletions src/main/java/seedu/address/storage/JsonAdaptedAppointment.java
Original file line number Diff line number Diff line change
@@ -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.appointment.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);
}
}

Loading

0 comments on commit d586698

Please sign in to comment.