-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
361 lines (338 loc) · 15.4 KB
/
Copy pathmain.java
File metadata and controls
361 lines (338 loc) · 15.4 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import java.util.List;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Admin admin = new Admin("admin", "admin123", "AD101", "System Admin", "0123456789");
List<Doctor> loadedDoctors = FileManager.loadDoctors("doctors.txt");
for (Doctor d : loadedDoctors) {
admin.Doctors.add(d);
HospitalSystem.countdoctor();
}
List<Patient> loadedPatients = FileManager.LoadPatients("patients.txt");
for (Patient p : loadedPatients) {
admin.patients.add(p);
HospitalSystem.countpatient();
}
List<Appointment> loadedAppointments = FileManager.LoadAppointments("appointments.txt");
for (Appointment a : loadedAppointments) {
admin.Appointments.add(a);
HospitalSystem.countAppointment();
}
int mainChoice;
do {
System.out.println("\n==** Hospital Management System **==");
System.out.println("[1] Login as Admin");
System.out.println("[2] Login as Doctor");
System.out.println("[3] Login as Patient");
System.out.println("[4] Exit System");
System.out.print("Choose any option from 1-4: ");
mainChoice = input.nextInt();
input.nextLine();
switch (mainChoice) {
case 1:
System.out.print("Enter Admin Username: ");
String admU = input.nextLine();
System.out.print("Enter Admin Password: ");
String admP = input.nextLine();
if (admin.getUsername().equals(admU) && admin.getPassword().equals(admP)) {
adminMenu(admin, input);
} else {
System.out.println("Invalid Admin Username or Password!");
}
break;
case 2:
if (admin.Doctors.isEmpty()) {
System.out.println("No doctors in the system. Contact Admin.");
} else {
System.out.print("Enter Doctor Username: ");
String docU = input.nextLine();
System.out.print("Enter Password: ");
String docP = input.nextLine();
Doctor currentDoc = null;
for (Doctor d : admin.Doctors) {
if (d.getUsername().equals(docU) && d.getPassword().equals(docP)) {
currentDoc = d;
break;
}
}
if (currentDoc != null) {
doctorMenu(currentDoc, input);
} else {
System.out.println("Invalid Username or Password!");
}
}
break;
case 3:
if (admin.patients.isEmpty()) {
System.out.println("No patients registered yet!");
} else {
System.out.print("Enter Username: ");
String patU = input.nextLine();
System.out.print("Enter Password: ");
String patP = input.nextLine();
Patient currentPat = null;
for (Patient p : admin.patients) {
if (p.getUsername().equals(patU) && p.getPassword().equals(patP)) {
currentPat = p;
break;
}
}
if (currentPat != null) {
patientMenu(currentPat, input, admin);
} else {
System.out.println("Invalid Username or Password!");
}
}
break;
case 4:
FileManager.saveDoctors("doctors.txt", admin.Doctors);
FileManager.savePatients("patients.txt", admin.patients);
FileManager.saveAppointments("appointments.txt", admin.Appointments);
System.out.println("Data saved. Goodbye!!");
break;
default:
System.out.println("Invalid Choice!");
}
} while (mainChoice != 4);
}
public static void adminMenu(Admin a, Scanner input) {
int choice;
do {
System.out.println("\n--- Admin Page ---");
System.out.println("1. Add Doctor");
System.out.println("2. Register Patient");
System.out.println("3. Assign Patient to Doctor");
System.out.println("4. Create Appointment");
System.out.println("5. View All Doctors");
System.out.println("6. View All Patients");
System.out.println("7. View All Appointments");
System.out.println("8. Search Patient by ID");
System.out.println("9. Search Doctor by ID");
System.out.println("10. Generate Reports");
System.out.println("11. Save Data");
System.out.println("12. Logout");
System.out.print("Choice: ");
choice = input.nextInt();
input.nextLine();
switch (choice) {
case 1: {
Doctor D = new Doctor();
System.out.println("Add a name of Doctor:");
D.setName(input.nextLine());
System.out.println("Enter username:");
D.setUsername(input.nextLine());
System.out.println("Enter password:");
D.setPassword(input.nextLine());
System.out.println("Enter ID:");
D.setID(input.nextLine());
System.out.println("Enter department:");
D.setDepartment(input.nextLine());
System.out.println("Enter Specialization:");
D.setSpecialization(input.nextLine());
System.out.println("Enter phone number:");
D.setPhonenumber(input.nextLine());
a.adddoctor(D);
break;
}
case 2: {
Patient P = new Patient();
System.out.println("Enter name:");
P.setName(input.nextLine());
System.out.println("Enter username:");
P.setUsername(input.nextLine());
System.out.println("Enter password:");
P.setPassword(input.nextLine());
System.out.println("Enter ID:");
P.setID(input.nextLine());
System.out.println("Enter Age:");
P.setAge(input.nextLine());
System.out.println("Enter Gender:");
P.setGender(input.nextLine());
System.out.println("Enter phone number:");
P.setPhonenumber(input.nextLine());
System.out.println("Enter Assigned Doctor name:");
P.setAssigned_doctor(input.nextLine());
a.addpatient(P);
break;
}
case 3: {
System.out.print("Enter Patient ID: ");
String pID = input.nextLine();
System.out.print("Enter Doctor ID: ");
String dID = input.nextLine();
Patient foundPatient = null;
Doctor foundDoctor = null;
for (Patient p : a.patients) {
if (p.getID().equals(pID)) { foundPatient = p; break; }
}
for (Doctor d : a.Doctors) {
if (d.getID().equals(dID)) { foundDoctor = d; break; }
}
if (foundPatient != null && foundDoctor != null) {
foundPatient.setAssigned_doctor(foundDoctor.getName());
a.assignpatient(foundPatient, foundDoctor);
} else {
System.out.println("Error: Patient or Doctor ID not found!");
}
break;
}
case 4: {
System.out.print("Enter ID of Doctor: ");
String docId = input.nextLine();
System.out.print("Enter ID of Patient: ");
String patId = input.nextLine();
System.out.print("Enter Appointment ID: ");
String appID = input.nextLine();
System.out.print("Enter Date (YYYY-MM-DD): ");
String date = input.nextLine();
System.out.print("Enter Time (HH:MM): ");
String time = input.nextLine();
boolean available = a.checkDoctorAvailability(docId, date, time);
if (!available) {
System.out.println("Doctor already has an appointment at this time.");
break;
}
Doctor targetDoctor = null;
for (Doctor d : a.Doctors) {
if (d.getID().equals(docId)) { targetDoctor = d; break; }
}
Patient targetPatient = null;
for (Patient p : a.patients) {
if (p.getID().equals(patId)) { targetPatient = p; break; }
}
if (targetDoctor != null && targetPatient != null) {
Appointment appointment = new Appointment(appID, patId, docId, date, time, "Confirmed");
a.createappointment(appointment, targetDoctor, targetPatient);
System.out.println("Appointment created successfully!");
} else {
System.out.println("Error: Doctor ID or Patient ID not found.");
}
break;
}
case 5:
a.displayinfoDoctors();
break;
case 6:
a.displayinfopatients();
break;
case 7:
a.displayappointment();
break;
case 8: {
System.out.println("Enter ID of Patient:");
a.searchpatientbyID(input.nextLine());
break;
}
case 9: {
System.out.println("Enter ID of Doctor:");
a.searchDoctorbyID(input.nextLine());
break;
}
case 10:
a.reports();
break;
case 11:
FileManager.saveDoctors("doctors.txt", a.Doctors);
FileManager.savePatients("patients.txt", a.patients);
FileManager.saveAppointments("appointments.txt", a.Appointments);
System.out.println("Data saved successfully.");
break;
case 12:
System.out.println("Logging out Admin...");
break;
default:
System.out.println("Invalid Choice!");
}
} while (choice != 12);
}
public static void doctorMenu(Doctor dr, Scanner input) {
int choice;
do {
System.out.println("\n----- Doctor Menu (" + dr.getName() + ") -----");
System.out.println("1. View My Profile");
System.out.println("2. View Assigned Patients");
System.out.println("3. View My Appointments");
System.out.println("4. Update Appointment Status");
System.out.println("5. Logout");
System.out.print("Enter your choice: ");
choice = input.nextInt();
input.nextLine();
switch (choice) {
case 1:
dr.displayinfo();
break;
case 2:
dr.viewAssignedPatients();
break;
case 3:
dr.viewMyAppointments();
break;
case 4:
System.out.print("Enter Appointment ID: ");
String id = input.nextLine();
System.out.println("Status: 1. Confirmed 2. Completed 3. Cancelled");
System.out.print("Enter number: ");
int num = input.nextInt();
input.nextLine();
String newstatus = "";
if (num == 1) newstatus = "Confirmed";
else if (num == 2) newstatus = "Completed";
else if (num == 3) newstatus = "Cancelled";
else System.out.println("Invalid Choice!");
if (!newstatus.equals("")) dr.updateAppointmentStatus(id, newstatus);
break;
case 5:
System.out.println("Logging out...");
break;
default:
System.out.println("Invalid Choice!");
}
} while (choice != 5);
}
public static void patientMenu(Patient patient, Scanner input, Admin admin) {
int choice;
do {
System.out.println("\n--- Patient Menu (" + patient.getName() + ") ---");
System.out.println("[1] View My Profile");
System.out.println("[2] View Assigned Doctor");
System.out.println("[3] View My Appointments");
System.out.println("[4] Book an Appointment");
System.out.println("[5] Cancel an Appointment");
System.out.println("[6] Logout");
System.out.print("Enter choice: ");
choice = input.nextInt();
input.nextLine();
switch (choice) {
case 1:
patient.displayinfo();
break;
case 2:
System.out.println("Your Assigned Doctor is Dr. " + patient.getAssigned_doctor());
break;
case 3:
patient.getList_of_Appointments();
break;
case 4:
System.out.print("Enter Date (YYYY-MM-DD): ");
String date = input.nextLine();
System.out.print("Enter Time (HH:MM): ");
String time = input.nextLine();
System.out.println(patient.Book_Appointment(date, time, admin));
break;
case 5:
System.out.print("Enter the date of Appointment to cancel: ");
String canceldate = input.nextLine();
System.out.print("Enter Time: ");
String canceltime = input.nextLine();
System.out.println(patient.Cancel_Appointment(canceldate, canceltime, admin));
break;
case 6:
System.out.println("Logging out...");
break;
default:
System.out.println("Invalid Choice!");
}
} while (choice != 6);
}
}