Skip to content

Commit 1783f0d

Browse files
authored
Merge pull request #113 from Alteqa/branch-addtimeappointments
Add time to appointments besides date
2 parents 6d4d38e + 1b4297d commit 1783f0d

29 files changed

+220
-205
lines changed

src/main/java/seedu/address/logic/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static String format(Person person) {
6161
public static String format(Appointment appointment) {
6262
final StringBuilder builder = new StringBuilder();
6363
builder.append("Date: ")
64-
.append(appointment.getAppointmentDate())
64+
.append(appointment.getAppointmentDateTime())
6565
.append("; Doctor: ")
6666
.append(appointment.getDoctorNric())
6767
.append("; Patient: ")

src/main/java/seedu/address/logic/commands/AddAppointmentCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class AddAppointmentCommand extends Command {
2727
+ PREFIX_DOCTORNRIC + "DOCTOR NRIC "
2828
+ PREFIX_PATIENTNRIC + "PATIENT NRIC\n"
2929
+ "Example: " + COMMAND_WORD + " "
30-
+ PREFIX_DATE + "2024-04-09 "
30+
+ PREFIX_DATE + "2024-04-09 10:15 "
3131
+ PREFIX_DOCTORNRIC + "S7777888T "
3232
+ PREFIX_PATIENTNRIC + "T0000111U";
3333

src/main/java/seedu/address/logic/commands/EditAppointmentCommand.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import seedu.address.logic.parser.exceptions.ParseException;
1717
import seedu.address.model.Model;
1818
import seedu.address.model.appointment.Appointment;
19-
import seedu.address.model.appointment.AppointmentDate;
19+
import seedu.address.model.appointment.AppointmentDateTime;
2020
import seedu.address.model.person.Nric;
2121

2222
/**
@@ -85,11 +85,11 @@ private static Appointment createEditedAppointment(
8585

8686
Nric doctorNric = appointmentToEdit.getDoctorNric();
8787
Nric patientNric = appointmentToEdit.getPatientNric();
88-
AppointmentDate updatedDate = editAppointmentDescriptor
89-
.getDate().orElse(appointmentToEdit.getAppointmentDate());
88+
AppointmentDateTime updatedDateTime = editAppointmentDescriptor
89+
.getDate().orElse(appointmentToEdit.getAppointmentDateTime());
9090

9191
try {
92-
return new Appointment(doctorNric, patientNric, updatedDate);
92+
return new Appointment(doctorNric, patientNric, updatedDateTime);
9393
} catch (ParseException e) {
9494
throw new CommandException("Unable to edit appointment due to invalid inputs");
9595
}
@@ -126,7 +126,7 @@ public String toString() {
126126
public static class EditAppointmentDescriptor {
127127
private Nric doctorNric;
128128
private Nric patientNric;
129-
private AppointmentDate apptdate;
129+
private AppointmentDateTime apptdatetime;
130130

131131
public EditAppointmentDescriptor() {}
132132

@@ -135,7 +135,7 @@ public EditAppointmentDescriptor() {}
135135
* A defensive copy of {@code tags} is used internally.
136136
*/
137137
public EditAppointmentDescriptor(EditAppointmentDescriptor toCopy) {
138-
setDate(toCopy.apptdate);
138+
setDateTime(toCopy.apptdatetime);
139139
setDoctorNric(toCopy.doctorNric);
140140
setPatientNric(toCopy.patientNric);
141141
}
@@ -144,15 +144,15 @@ public EditAppointmentDescriptor(EditAppointmentDescriptor toCopy) {
144144
* Returns true if at least one field is edited.
145145
*/
146146
public boolean isAnyFieldEdited() {
147-
return CollectionUtil.isAnyNonNull(apptdate);
147+
return CollectionUtil.isAnyNonNull(apptdatetime);
148148
}
149149

150-
public void setDate(AppointmentDate date) {
151-
this.apptdate = date;
150+
public void setDateTime(AppointmentDateTime dateTime) {
151+
this.apptdatetime = dateTime;
152152
}
153153

154-
public Optional<AppointmentDate> getDate() {
155-
return Optional.ofNullable(apptdate);
154+
public Optional<AppointmentDateTime> getDate() {
155+
return Optional.ofNullable(apptdatetime);
156156
}
157157

158158
public void setDoctorNric(Nric nric) {
@@ -183,15 +183,15 @@ public boolean equals(Object other) {
183183
}
184184

185185
EditAppointmentDescriptor otherEditAppointmentDescriptor = (EditAppointmentDescriptor) other;
186-
return Objects.equals(apptdate, otherEditAppointmentDescriptor.apptdate)
186+
return Objects.equals(apptdatetime, otherEditAppointmentDescriptor.apptdatetime)
187187
&& Objects.equals(doctorNric, otherEditAppointmentDescriptor.doctorNric)
188188
&& Objects.equals(patientNric, otherEditAppointmentDescriptor.patientNric);
189189
}
190190

191191
@Override
192192
public String toString() {
193193
return new ToStringBuilder(this)
194-
.add("apptdate", apptdate)
194+
.add("apptdatetime", apptdatetime)
195195
.toString();
196196
}
197197
}

src/main/java/seedu/address/logic/parser/AddAppointmentCommandParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import seedu.address.logic.commands.AddAppointmentCommand;
1111
import seedu.address.logic.parser.exceptions.ParseException;
1212
import seedu.address.model.appointment.Appointment;
13-
import seedu.address.model.appointment.AppointmentDate;
13+
import seedu.address.model.appointment.AppointmentDateTime;
1414
import seedu.address.model.person.Nric;
1515

1616
/**
@@ -34,12 +34,12 @@ public AddAppointmentCommand parse(String args) throws ParseException {
3434
}
3535

3636
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_DATE, PREFIX_DOCTORNRIC, PREFIX_PATIENTNRIC);
37-
AppointmentDate appointmentDate = ParserUtil.parseAppointmentDate(argMultimap.getValue(PREFIX_DATE).get());
37+
AppointmentDateTime appointmentDateTime =
38+
ParserUtil.parseAppointmentDateTime(argMultimap.getValue(PREFIX_DATE).get());
3839
Nric doctorNric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_DOCTORNRIC).get());
3940
Nric patientNric = ParserUtil.parseNric(argMultimap.getValue(PREFIX_PATIENTNRIC).get());
4041

41-
Appointment appointment = new Appointment(doctorNric, patientNric, appointmentDate);
42-
42+
Appointment appointment = new Appointment(doctorNric, patientNric, appointmentDateTime);
4343
return new AddAppointmentCommand(appointment);
4444
}
4545

src/main/java/seedu/address/logic/parser/AddressBookParser.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public Command parseCommand(String userInput) throws ParseException {
6161

6262
switch (commandWord) {
6363

64-
// case AddCommand.COMMAND_WORD:
65-
// return new AddCommandParser().parse(arguments);
66-
6764
case AddPatientCommand.COMMAND_WORD:
6865
return new AddPatientCommandParser().parse(arguments);
6966

src/main/java/seedu/address/logic/parser/EditAppointmentCommandParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public EditAppointmentCommand parse(String args) throws ParseException {
3838
EditAppointmentDescriptor editAppointmentDescriptor = new EditAppointmentDescriptor();
3939

4040
if (argMultimap.getValue(PREFIX_DATE).isPresent()) {
41-
editAppointmentDescriptor.setDate(ParserUtil.parseAppointmentDate(argMultimap.getValue(PREFIX_DATE).get()));
41+
editAppointmentDescriptor.setDateTime(
42+
ParserUtil.parseAppointmentDateTime(argMultimap.getValue(PREFIX_DATE).get()));
4243
}
4344

4445
if (!editAppointmentDescriptor.isAnyFieldEdited()) {

src/main/java/seedu/address/logic/parser/ParserUtil.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import seedu.address.commons.core.index.Index;
1010
import seedu.address.commons.util.StringUtil;
1111
import seedu.address.logic.parser.exceptions.ParseException;
12-
import seedu.address.model.appointment.AppointmentDate;
12+
import seedu.address.model.appointment.AppointmentDateTime;
1313
import seedu.address.model.person.Address;
1414
import seedu.address.model.person.DoB;
1515
import seedu.address.model.person.Email;
@@ -181,16 +181,16 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
181181

182182
/**
183183
* Parses AppointmentDate from string to return an AppointmentDate object
184-
* @param apptDate String to parse
184+
* @param apptDateTime String to parse
185185
* @return instance of AppointmentDate
186186
* @throws ParseException if string is invalid date
187187
*/
188-
public static AppointmentDate parseAppointmentDate(String apptDate) throws ParseException {
189-
requireNonNull(apptDate);
190-
String trimmedDate = apptDate.trim();
191-
if (!AppointmentDate.isValidDate(trimmedDate)) {
192-
throw new ParseException(AppointmentDate.MESSAGE_CONSTRAINTS);
188+
public static AppointmentDateTime parseAppointmentDateTime(String apptDateTime) throws ParseException {
189+
requireNonNull(apptDateTime);
190+
String trimmedDate = apptDateTime.trim();
191+
if (!AppointmentDateTime.isValidDate(trimmedDate)) {
192+
throw new ParseException(AppointmentDateTime.MESSAGE_CONSTRAINTS);
193193
}
194-
return new AppointmentDate(trimmedDate);
194+
return new AppointmentDateTime(trimmedDate);
195195
}
196196
}

src/main/java/seedu/address/model/appointment/Appointment.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import static seedu.address.commons.util.AppUtil.checkArgument;
44
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
55

6-
import java.time.LocalDate;
6+
import java.time.LocalDateTime;
7+
import java.time.format.DateTimeFormatter;
78

89
import seedu.address.commons.util.ToStringBuilder;
910
import seedu.address.logic.parser.exceptions.ParseException;
@@ -25,7 +26,7 @@ public class Appointment {
2526
private Nric patientNric;
2627

2728
// The date of the appointment
28-
private final AppointmentDate appointmentDate;
29+
private final AppointmentDateTime appointmentDateTime;
2930

3031
// Message to outputs in case constraints are not met
3132

@@ -35,38 +36,38 @@ public class Appointment {
3536
* Constructs a new appointment instance
3637
* @param doctorNric doctor in charge
3738
* @param patientNric patient of the appointment
38-
* @param appointmentDate date of the appointment
39+
* @param appointmentDateTime date of the appointment
3940
*/
4041
public Appointment(
41-
Nric doctorNric, Nric patientNric, AppointmentDate appointmentDate) throws ParseException {
42-
requireAllNonNull(doctorNric, patientNric, appointmentDate);
42+
Nric doctorNric, Nric patientNric, AppointmentDateTime appointmentDateTime) throws ParseException {
43+
requireAllNonNull(doctorNric, patientNric, appointmentDateTime);
4344

4445
try {
45-
checkArgument(isValidAppointment(appointmentDate), MESSAGE_CONSTRAINTS_INVALID_DATE);
46+
checkArgument(isValidAppointment(appointmentDateTime), MESSAGE_CONSTRAINTS_INVALID_DATE);
4647
} catch (IllegalArgumentException e) {
4748
throw new ParseException(e.getMessage());
4849
}
4950

5051
this.doctorNric = doctorNric;
5152
this.patientNric = patientNric;
52-
this.appointmentDate = appointmentDate;
53+
this.appointmentDateTime = appointmentDateTime;
5354
this.appointmentId = new AppointmentId();
5455
}
5556

5657
/**
5758
* Constructs a new appointment instance
5859
* @param doctorNric doctor in charge
5960
* @param patientNric patient of the appointment
60-
* @param appointmentDate date of the appointment
61+
* @param appointmentDateTime date and time of the appointment
6162
* @param appointmentId id of the appointment
6263
*/
63-
public Appointment(Nric doctorNric, Nric patientNric, AppointmentDate appointmentDate,
64+
public Appointment(Nric doctorNric, Nric patientNric, AppointmentDateTime appointmentDateTime,
6465
AppointmentId appointmentId) {
65-
requireAllNonNull(doctorNric, patientNric, appointmentDate);
66-
checkArgument(isValidAppointment(appointmentDate), MESSAGE_CONSTRAINTS_INVALID_DATE);
66+
requireAllNonNull(doctorNric, patientNric, appointmentDateTime);
67+
checkArgument(isValidAppointment(appointmentDateTime), MESSAGE_CONSTRAINTS_INVALID_DATE);
6768
this.doctorNric = doctorNric;
6869
this.patientNric = patientNric;
69-
this.appointmentDate = appointmentDate;
70+
this.appointmentDateTime = appointmentDateTime;
7071
this.appointmentId = appointmentId;
7172
}
7273

@@ -77,9 +78,10 @@ public Appointment(Nric doctorNric, Nric patientNric, AppointmentDate appointmen
7778
* @param appointmentDate Date to check validity of
7879
* @return boolean if appointment is valid or not
7980
*/
80-
public boolean isValidAppointment(AppointmentDate appointmentDate) {
81-
AppointmentDate currentDate = new AppointmentDate(LocalDate.now());
82-
return appointmentDate.compareTo(currentDate) > -1;
81+
public boolean isValidAppointment(AppointmentDateTime appointmentDate) {
82+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
83+
AppointmentDateTime currentDateTime = new AppointmentDateTime(LocalDateTime.now().format(formatter));
84+
return appointmentDate.compareTo(currentDateTime) > -1;
8385
}
8486

8587
/**
@@ -114,8 +116,8 @@ public AppointmentId getAppointmentId() {
114116
* Gets date of the appointment
115117
* @return date of the appointment
116118
*/
117-
public AppointmentDate getAppointmentDate() {
118-
return appointmentDate;
119+
public AppointmentDateTime getAppointmentDateTime() {
120+
return appointmentDateTime;
119121
}
120122

121123
/**
@@ -131,7 +133,7 @@ public boolean isSameAppointment(Appointment appt) {
131133
return appt != null
132134
&& appt.getDoctorNric().equals(this.getDoctorNric())
133135
&& appt.getPatientNric().equals(this.getPatientNric())
134-
&& appt.getAppointmentDate().equals(this.getAppointmentDate());
136+
&& appt.getAppointmentDateTime().equals(this.getAppointmentDateTime());
135137
}
136138

137139
/**
@@ -161,13 +163,13 @@ public boolean equals(Object appt) {
161163
return appt != null
162164
&& appointment.getDoctorNric().equals(this.getDoctorNric())
163165
&& appointment.getPatientNric().equals(this.getPatientNric())
164-
&& appointment.getAppointmentDate().equals(this.getAppointmentDate());
166+
&& appointment.getAppointmentDateTime().equals(this.getAppointmentDateTime());
165167
}
166168

167169
@Override
168170
public String toString() {
169171
return new ToStringBuilder(this)
170-
.add("Date", getAppointmentDate())
172+
.add("Date", getAppointmentDateTime())
171173
.add("Doctor", getDoctorNric())
172174
.add("Patient", getPatientNric())
173175
.add("Id", getAppointmentId())

0 commit comments

Comments
 (0)