-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClinicSystem.java
145 lines (133 loc) · 5.38 KB
/
ClinicSystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package clinic;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class ClinicSystem implements TextFileManipulation {
protected ArrayList<String> appointmentList = new ArrayList<String>();
DateOfAppointment appointment = new DateOfAppointment();
private String[] account;
private boolean check = true;
public String[] logIn(String username, String password) throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
this.account = null;
readLines(this, userPath(), getMethodObject("clinic.ClinicSystem", "authentication"), username, password, null,
null, null, null);
return account;
}
public void authentication(String readLine, String username, String password, String keyword3, String keyword4,
String keyword5, String keyword6) throws ParseException {
String[] token = readLine.split(",");
if (username.equals(token[2]) && password.equals(token[3])) {
this.account = token;
}
}
public String setAppointmentDate(String doctor, String patient)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
SecurityException, ClassNotFoundException, ParseException {
do {
check = true;
do {
appointment.setYear();
appointment.setMonth();
appointment.setDay();
appointment.setTime();
} while (!appointment.isValidDateTime());
checkAvailability(doctor, patient);
} while (!check);
System.out.println("Completed");
return appointment.getInputtedDate() + "," + appointment.getTime();
}
public void checkAvailability(String doctor, String patient)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
SecurityException, ClassNotFoundException {
readLines(this, appointmentPath(), getMethodObject("clinic.ClinicSystem", "checkAppointments"), doctor, patient,
null, null, null, null);
}
public void checkAppointments(String readLine, String doctor, String patient, String keyword3, String keyword4,
String keyword5, String keyword6) {
String[] token = readLine.split(",");
if (token[0].equals(doctor) && token[1].equals(patient) && token[2].equals(appointment.getInputtedDate())
&& token[3].equals(appointment.getTime())) {
System.out.println("This is the same appointment");
this.check = false;
} else if (token[0].equals(doctor) && token[2].equals(appointment.getInputtedDate())
&& token[3].equals(appointment.getTime())) {
System.out.println("The doctor unavailable at this time");
this.check = false;
} else if (token[1].equals(patient) && token[2].equals(appointment.getInputtedDate())
&& token[3].equals(appointment.getTime())) {
System.out.println("The patient unavailable at this time");
this.check = false;
}
}
public void getAppointmentList(String readLine, String keyword1, String keyword2, String keyword3, String keyword4,
String keyword5, String keyword6) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH.mm");
String[] date = readLine.split(",");
String tempDate = date[2] + " " + date[3];
Date date1 = sdf.parse(tempDate);
Date date2 = sdf.parse(appointment.getCurrentDate() + " " + appointment.getCurrentTime());
if (date1.after(date2)) {
appointmentList.add(readLine);
}
}
public boolean compareDates(String date) {
SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
long diff = 0;
long temp = 0;
try {
Date date1 = myFormat.parse(appointment.getCurrentDate());
Date date2 = myFormat.parse(date);
diff = date2.getTime() - date1.getTime();
temp = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
} catch (ParseException e) {
e.printStackTrace();
}
if (temp <= 7 && temp >= 0) {
return true;
}
return false;
}
public void sortAllAppointment() throws NoSuchMethodException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException {
readLines(this, appointmentPath(), getMethodObject("clinic.ClinicSystem", "getAppointmentList"), null, null,
null, null, null, null);
File newFile = new File(tempFilePath());
newFile.createNewFile();
sortAppointments(appointmentList);
for (int i = 0; i < appointmentList.size(); i++) {
writeLines(tempFilePath(), appointmentList.get(i));
}
File oldFile = new File(appointmentPath());
oldFile.delete();
newFile.renameTo(oldFile);
appointmentList.clear();
}
public void sortAppointments(ArrayList<String> sort) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH.mm");
for (int outer = 0; outer < sort.size(); outer++) {
for (int inner = outer + 1; inner < sort.size(); inner++) {
String[] token1 = sort.get(inner).split(",");
String[] token2 = sort.get(outer).split(",");
String temp = token1[2] + " " + token1[3];
String temp2 = token2[2] + " " + token2[3];
Date date1 = sdf.parse(temp);
Date date2 = sdf.parse(temp2);
if (date1.before(date2)) {
String tempVar = sort.get(inner);
sort.remove(inner);
sort.add(outer, tempVar);
}
}
}
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}