Skip to content

Commit

Permalink
Merge pull request #82 from qyaner/branch-appointment-id
Browse files Browse the repository at this point in the history
Add appointment id
  • Loading branch information
techjay-c authored Oct 19, 2023
2 parents 8336520 + 1d9207e commit 00df525
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AddAppointmentCommand extends Command {
+ PREFIX_DURATION + "PT1H30M "
+ PREFIX_SERVICE + "Braces";

public static final String MESSAGE_SUCCESS = "New Appointment added: 1$s%";
public static final String MESSAGE_SUCCESS = "New Appointment added: %1$s";

public static final String MESSAGE_CLASHING_APPOINTMENTS = "This Appointment clashes with a current one.";

Expand All @@ -59,6 +59,7 @@ public AddAppointmentCommand(Appointment appointment) {
*/
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
if (model.hasAppointment(toAdd)) {
throw new CommandException(MESSAGE_CLASHING_APPOINTMENTS);
}
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class AddressBook implements ReadOnlyAddressBook {

private long patientId;
private long dentistId;
private long appointmentId;

/*
* The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication
Expand Down Expand Up @@ -83,6 +84,17 @@ public void incrementDentistId() {
dentistId = dentistId + 1;
}

public void setAppointmentId(long id) {
appointmentId = id;
}
@Override
public long getAppointmentId() {
return appointmentId;
}
public void incrementAppointmentId() {
appointmentId = appointmentId + 1;
}

//// list overwrite operations

/**
Expand Down Expand Up @@ -125,6 +137,7 @@ public void resetData(ReadOnlyAddressBook newData) {
setAppointments(newData.getAppointmentList());
setPatientId(newData.getPatientId());
setDentistId(newData.getDentistId());
setAppointmentId(newData.getAppointmentId());
}

//// person-level operations
Expand Down Expand Up @@ -204,8 +217,20 @@ public void addDentist(Dentist dentist) {
}
}

/**
* Adds an appointment to the list of appointments.
* If the appointment has an ID of -1, it assigns a new ID and increments the global appointment ID counter.
*
* @param appointment The appointment to be added.
*/
public void addAppointment(Appointment appointment) {
appointments.add(appointment);
if (appointment.getId() == -1) {
appointment.setId(appointmentId);
appointments.add(appointment);
incrementAppointmentId();
} else {
appointments.add(appointment);
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public interface ReadOnlyAddressBook {
* Returns an integer which represents the next available dentist id
*/
long getDentistId();

/**
* Returns an integer which represents the next available appointment id
*/
long getAppointmentId();

}
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/model/appointments/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Appointment {
private final AppointmentTime appointmentTime;
private final String duration;
private final String treatment;
private long id;

/**
* Constructs an Appointment with the specified details.
Expand All @@ -26,6 +27,26 @@ public Appointment(String dentist, String patient, AppointmentTime appointmentTi
this.appointmentTime = appointmentTime;
this.duration = duration;
this.treatment = treatment;
this.id = -1;
}

/**
* Constructs an Appointment with the specified details.
*
* @param dentist The name of the dentist for the appointment.
* @param patient The name of the patient for the appointment.
* @param appointmentTime The time and date of the appointment.
* @param duration The duration of the appointment.
* @param treatment The treatment provided.
*/
public Appointment(String dentist, String patient, AppointmentTime appointmentTime,
String duration, String treatment, long id) {
this.dentist = dentist;
this.patient = patient;
this.appointmentTime = appointmentTime;
this.duration = duration;
this.treatment = treatment;
this.id = id;
}

public String getDentist() {
Expand All @@ -47,6 +68,14 @@ public AppointmentTime getAppointmentTime() {
public String getTreatment() {
return this.treatment;
}
public void setId(long id) {
this.id = id;
}

public long getId() {
return id;
}


/**
* Checks whether this appointment clashes with another.
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/seedu/address/storage/JsonAdaptedAppointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class JsonAdaptedAppointment {
private final String start;
private final String duration;
private final String treatment;
private final String id;

/**
* Constructs a {@code JsonAdaptedAppointment} with the given appointment details.
Expand All @@ -32,12 +33,13 @@ public class JsonAdaptedAppointment {
@JsonCreator
public JsonAdaptedAppointment(@JsonProperty("dentist") String dentist, @JsonProperty("patient") String patient,
@JsonProperty("start") String start, @JsonProperty("duration") String duration,
@JsonProperty("treatment") String treatment) {
@JsonProperty("treatment") String treatment, @JsonProperty("id") String id) {
this.dentist = dentist;
this.patient = patient;
this.start = start;
this.duration = duration;
this.treatment = treatment;
this.id = id;

}

Expand All @@ -52,6 +54,7 @@ public JsonAdaptedAppointment(Appointment source) {
start = source.getAppointmentTime().startToString();
duration = source.getAppointmentTime().durationToString();
treatment = source.getTreatment();
id = String.valueOf(source.getId());
}

/**
Expand Down Expand Up @@ -81,7 +84,13 @@ public Appointment toModelType() throws IllegalValueException {
throw new IllegalValueException(
String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()));
}
if (id == null) {
throw new IllegalValueException(
"id value does not exist!");
}
long lid = Long.parseLong(id);

final AppointmentTime appointmentTime = new AppointmentTime(start, duration);
return new Appointment(dentist, patient, appointmentTime, duration, treatment);
return new Appointment(dentist, patient, appointmentTime, duration, treatment, lid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class JsonSerializableAddressBook {

private String patientId;
private String dentistId;
private String appointmentId;



Expand All @@ -60,6 +61,7 @@ public JsonSerializableAddressBook(ReadOnlyAddressBook source) {

patientId = String.valueOf(source.getPatientId());
dentistId = String.valueOf(source.getDentistId());
appointmentId = String.valueOf(source.getAppointmentId());
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/ui/AppointmentCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class AppointmentCard extends UiPart<Region> {
private Label date;
@FXML
private Label service;
@FXML
private Label appointmentId;

/**
* Constructs an {@code AppointmentCard} with the given {@code Appointment}.
Expand All @@ -40,5 +42,6 @@ public AppointmentCard(Appointment appointment) {
appointmentTime.setText(appointment.getAppointmentTime().appointmentTimeToString());
date.setText(appointment.getAppointmentTime().dateToString());
service.setText("Treatment: " + appointment.getTreatment());
appointmentId.setText("Appointment ID: " + String.valueOf(appointment.getId()));
}
}
1 change: 1 addition & 0 deletions src/main/resources/view/AppointmentListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<Label fx:id="dentist" styleClass="details-text" text="\$dentist" />
<Label fx:id="patient" styleClass="details-text" text="\$patient" />
<Label fx:id="service" styleClass="details-text" text="\$service" />
<Label fx:id="appointmentId" styleClass="cell_small_label" text="\$appointmentId" />
</VBox>
</GridPane>
</HBox>
4 changes: 4 additions & 0 deletions src/test/java/seedu/address/model/AddressBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public long getDentistId() {
throw new AssertionError("This method should not be called.");
}

@Override
public long getAppointmentId() {
throw new AssertionError("This method should not be called.");
}
@Override
public ObservableList<Dentist> getDentistList() {
return dentists;
Expand Down

0 comments on commit 00df525

Please sign in to comment.