-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedicalApp.java
More file actions
611 lines (486 loc) · 22.6 KB
/
Copy pathMedicalApp.java
File metadata and controls
611 lines (486 loc) · 22.6 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
import javax.swing.*;
import java.awt.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;
public class MedicalApp {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new LoginFrame());
}
}
class LoginFrame extends JFrame {
private static final String DOCTOR_USERNAME = "doc";
private static final String DOCTOR_PASSWORD = "1";
private static final String SECRETARY_USERNAME = "sec";
private static final String SECRETARY_PASSWORD = "2";
private List<Patient> patients = new ArrayList<>();
@SuppressWarnings("unused")
public LoginFrame() {
super("تسجيل الدخول - نظام إدارة العيادة");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(5, 1, 10, 10));
JLabel label = new JLabel("اختر نوع المستخدم:", JLabel.CENTER);
JButton patientButton = new JButton("مريض");
JButton doctorButton = new JButton("طبيب");
JButton secretaryButton = new JButton("سكرتير");
patientButton.addActionListener(e -> new PatientLoginFrame(patients));
doctorButton.addActionListener(e -> doctorLogin());
secretaryButton.addActionListener(e -> secretaryLogin());
panel.add(label);
panel.add(patientButton);
panel.add(doctorButton);
panel.add(secretaryButton);
add(panel);
setVisible(true);
}
private void doctorLogin() {
String username = JOptionPane.showInputDialog(this, "اسم المستخدم:");
String password = JOptionPane.showInputDialog(this, "كلمة المرور:");
if (DOCTOR_USERNAME.equals(username) && DOCTOR_PASSWORD.equals(password)) {
new DoctorFrame(patients);
dispose();
} else {
JOptionPane.showMessageDialog(this, "اسم المستخدم أو كلمة المرور غير صحيحة.");
}
}
private void secretaryLogin() {
String username = JOptionPane.showInputDialog(this, "اسم المستخدم:");
String password = JOptionPane.showInputDialog(this, "كلمة المرور:");
if (SECRETARY_USERNAME.equals(username) && SECRETARY_PASSWORD.equals(password)) {
new SecretaryFrame(patients);
dispose();
} else {
JOptionPane.showMessageDialog(this, "اسم المستخدم أو كلمة المرور غير صحيحة.");
}
}
}
class Appointment {
private boolean requested;
private String status;
private String date;
private String medicalFile;
private String rejectionReason;
private String prescription;
public Appointment() {
this.requested = false;
this.status = "لم يتم تحديد الموعد";
this.date = "";
this.medicalFile = "";
this.prescription = "";
}
public boolean isRequested() {
return requested;
}
public void requestAppointment() {
this.requested = true;
this.status = "طلب موعد";
}
public String getStatus() {
return status;
}
public void setDate(String date) {
this.date = date;
this.status = "تم قبول الموعد";
}
public void rejectAppointment() {
this.status = "تم رفض الموعد";
}
public void sendMedicalFile(String file) {
this.medicalFile = file;
}
public String getDate() {
return date;
}
public String getMedicalFile() {
return medicalFile;
}
public String getRejectionReason() {
return rejectionReason;
}
public void sendPrescription(String prescription) {
this.prescription = prescription;
}
public String getPrescription() {
return prescription;
}
public void setStatus(String status) {
this.status = status;
}
}
class DoctorFrame extends JFrame {
private List<Patient> patients;
public DoctorFrame(List<Patient> patients) {
super("واجهة الطبيب");
this.patients = patients;
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(4, 1, 10, 10));
JButton viewAppointmentsButton = new JButton("عرض المواعيد القادمة");
JButton manageAppointmentsButton = new JButton("تعديل موعد");
JButton viewMedicalFilesButton = new JButton("عرض الملفات الطبية");
JButton sendPrescriptionButton = new JButton("إرسال وصفة طبية");
JButton backButton = new JButton("العودة");
viewMedicalFilesButton.addActionListener(_ -> viewMedicalFiles());
sendPrescriptionButton.addActionListener(_ -> sendPrescription());
viewAppointmentsButton.addActionListener(_ -> JOptionPane.showMessageDialog(this, "عرض المواعيد القادمة."));
manageAppointmentsButton.addActionListener(_ -> manageAppointments());
backButton.addActionListener(_ -> {
new LoginFrame();
dispose();
});
panel.add(viewAppointmentsButton);
panel.add(manageAppointmentsButton);
panel.add(viewMedicalFilesButton);
panel.add(sendPrescriptionButton);
panel.add(backButton);
add(panel);
setVisible(true);
}
private void viewMedicalFiles() {
StringBuilder filesInfo = new StringBuilder();
for (Patient patient : patients) {
Appointment appointment = patient.getAppointment();
if (!appointment.getMedicalFile().isEmpty()) {
filesInfo.append("المريض: ").append(patient.getFirstName()).append(" ").append(patient.getLastName())
.append("\nالملف الطبي: ").append(appointment.getMedicalFile()).append("\n\n");
}
}
if (filesInfo.length() == 0) {
JOptionPane.showMessageDialog(this, "لا توجد ملفات طبية لتحميلها.");
} else {
JOptionPane.showMessageDialog(this, filesInfo.toString(), "الملفات الطبية", JOptionPane.INFORMATION_MESSAGE);
}
}
private void sendPrescription() {
String patientName = JOptionPane.showInputDialog(this, "أدخل اسم المريض لإرسال وصفة طبية:");
for (Patient patient : patients) {
if (patient.getFirstName().equalsIgnoreCase(patientName)) {
String prescription = JOptionPane.showInputDialog(this, "أدخل نص الوصفة الطبية:");
if (prescription != null && !prescription.trim().isEmpty()) {
patient.getAppointment().sendPrescription(prescription);
JOptionPane.showMessageDialog(this, "تم إرسال الوصفة الطبية بنجاح للمريض: " + patient.getFirstName());
} else {
JOptionPane.showMessageDialog(this, "لم يتم إدخال وصفة طبية.");
}
return;
}
}
JOptionPane.showMessageDialog(this, "لم يتم العثور على المريض.");
}
private void manageAppointments() {
List<String> patientNames = new ArrayList<>();
for (Patient patient : patients) {
if (patient.getAppointment() != null && patient.getAppointment().getStatus().equals("تم قبول الموعد")) {
patientNames.add(patient.getFirstName() + " " + patient.getLastName());
}
}
if (patientNames.isEmpty()) {
JOptionPane.showMessageDialog(this, "لا توجد مواعيد لتعديلها.");
return;
}
String selectedPatientName = (String) JOptionPane.showInputDialog(
this,
"اختر المريض لتعديل موعده:",
"تعديل الموعد",
JOptionPane.QUESTION_MESSAGE,
null,
patientNames.toArray(),
null
);
if (selectedPatientName == null) {
return;
}
for (Patient patient : patients) {
String fullName = patient.getFirstName() + " " + patient.getLastName();
if (fullName.equals(selectedPatientName)) {
String newDate = JOptionPane.showInputDialog(this, "أدخل التاريخ الجديد (اليوم/الشهر/السنة):");
if (newDate != null && isValidDate(newDate)) {
patient.getAppointment().setDate(newDate);
patient.getAppointment().setStatus("تم قبول الموعد");
JOptionPane.showMessageDialog(this, "تم تعديل موعد المريض: " + fullName + " إلى التاريخ: " + newDate);
} else {
JOptionPane.showMessageDialog(this, "التاريخ المدخل غير صحيح أو غير صالح.");
}
return;
}
}
}
private boolean isValidDate(String date) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy");
LocalDate enteredDate = LocalDate.parse(date, formatter);
LocalDate currentDate = LocalDate.now();
return enteredDate.isAfter(currentDate);
} catch (DateTimeParseException e) {
return false;
}
}
}
class Patient {
private String firstName;
private String lastName;
private String username;
private String password;
private Appointment appointment;
public Patient(String firstName, String lastName, String username, String password) {
this.firstName = firstName;
this.lastName = lastName;
this.username = username;
this.password = password;
this.appointment = new Appointment();
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public Appointment getAppointment() {
return appointment;
}
}
class PatientFrame extends JFrame {
private Patient patient;
public PatientFrame(Patient patient) {
super("واجهة المريض");
this.patient = patient;
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JLabel duaLabel = new JLabel("اللهم اشف مرضانا ومرضى المسلمين", SwingConstants.CENTER);
duaLabel.setFont(new Font("Arial", Font.BOLD, 16));
duaLabel.setForeground(Color.BLUE);
JPanel panel = new JPanel(new GridLayout(4, 1, 10, 10));
JButton requestAppointmentButton = new JButton("طلب موعد");
JButton checkStatusButton = new JButton("معرفة حالة الطلب");
JButton uploadMedicalFileButton = new JButton("تحميل الملف الطبي");
JButton backButton = new JButton("العودة");
requestAppointmentButton.addActionListener(_ -> requestAppointment());
checkStatusButton.addActionListener(_ -> checkAppointmentStatus());
uploadMedicalFileButton.addActionListener(_ -> uploadMedicalFile());
backButton.addActionListener(_ -> {
new LoginFrame();
dispose();
});
panel.add(requestAppointmentButton);
panel.add(checkStatusButton);
panel.add(uploadMedicalFileButton);
panel.add(backButton);
add(duaLabel, BorderLayout.NORTH);
add(panel, BorderLayout.CENTER);
setVisible(true);
}
private void uploadMedicalFile() {
String filePath = JOptionPane.showInputDialog(this, "أدخل مسار الملف الطبي:");
if (filePath != null && !filePath.trim().isEmpty()) {
patient.getAppointment().sendMedicalFile(filePath);
JOptionPane.showMessageDialog(this, "تم تحميل الملف الطبي بنجاح.");
} else {
JOptionPane.showMessageDialog(this, "لم يتم تحميل الملف الطبي.");
}
}
private void requestAppointment() {
Appointment appointment = patient.getAppointment();
if (appointment.isRequested()) {
JOptionPane.showMessageDialog(this, "لقد طلبت بالفعل موعدًا. يرجى الانتظار لمعالجة طلبك.");
} else {
appointment.requestAppointment();
JOptionPane.showMessageDialog(this, "تم إرسال طلب الموعد. يرجى الانتظار لمعالجة الطلب.");
}
}
private void checkAppointmentStatus() {
Appointment appointment = patient.getAppointment();
if (!appointment.isRequested()) {
JOptionPane.showMessageDialog(this, "لم يتم تقديم طلب موعد بعد.");
return;
}
String status = appointment.getStatus();
if (status.equals("تم قبول الموعد")) {
JOptionPane.showMessageDialog(this, "تم قبول الموعد. التاريخ: " + appointment.getDate());
String prescription = appointment.getPrescription();
if (!prescription.isEmpty()) {
JOptionPane.showMessageDialog(this, "الوصفة الطبية: " + prescription);
}
} else if (status.equals("تم رفض الموعد")) {
JOptionPane.showMessageDialog(this, "تم رفض الموعد. السبب: " + appointment.getRejectionReason());
} else {
JOptionPane.showMessageDialog(this, "طلب الموعد قيد المعالجة.");
}
}
}
class PatientLoginFrame extends JFrame {
private List<Patient> patients;
@SuppressWarnings("unused")
public PatientLoginFrame(List<Patient> patients) {
super("تسجيل الدخول - المريض");
this.patients = patients;
setSize(400, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(3, 1, 10, 10));
JButton loginButton = new JButton("تسجيل الدخول");
JButton registerButton = new JButton("فتح حساب جديد");
loginButton.addActionListener(e -> login());
registerButton.addActionListener(e -> new PatientRegisterFrame(patients));
panel.add(new JLabel("مرحبًا بالمريض! اختر الإجراء:", JLabel.CENTER));
panel.add(loginButton);
panel.add(registerButton);
add(panel);
setVisible(true);
}
private void login() {
String username = JOptionPane.showInputDialog(this, "اسم المستخدم:");
String password = JOptionPane.showInputDialog(this, "كلمة المرور:");
for (Patient patient : patients) {
if (patient.getUsername().equals(username) && patient.getPassword().equals(password)) {
JOptionPane.showMessageDialog(this, "مرحبًا " + patient.getFirstName() + "!");
new PatientFrame(patient);
dispose();
return;
}
}
JOptionPane.showMessageDialog(this, "اسم المستخدم أو كلمة المرور غير صحيحة.");
}
}
class PatientRegisterFrame extends JFrame {
@SuppressWarnings("unused")
private List<Patient> patients;
@SuppressWarnings("unused")
public PatientRegisterFrame(List<Patient> patients) {
super("فتح حساب جديد - المريض");
this.patients = patients;
setSize(400, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(5, 2, 10, 10));
JTextField firstNameField = new JTextField();
JTextField lastNameField = new JTextField();
JTextField usernameField = new JTextField();
JPasswordField passwordField = new JPasswordField();
JButton registerButton = new JButton("تسجيل");
registerButton.addActionListener(e -> {
String firstName = firstNameField.getText();
String lastName = lastNameField.getText();
String username = usernameField.getText();
String password = new String(passwordField.getPassword());
if (firstName.isEmpty() || lastName.isEmpty() || username.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(this, "يرجى ملء جميع الحقول.");
} else {
patients.add(new Patient(firstName, lastName, username, password));
JOptionPane.showMessageDialog(this, "تم تسجيل الحساب بنجاح!");
dispose();
}
});
panel.add(new JLabel("الاسم:"));
panel.add(firstNameField);
panel.add(new JLabel("اللقب:"));
panel.add(lastNameField);
panel.add(new JLabel("اسم المستخدم:"));
panel.add(usernameField);
panel.add(new JLabel("كلمة المرور:"));
panel.add(passwordField);
panel.add(new JLabel());
panel.add(registerButton);
add(panel);
setVisible(true);
}
}
class SecretaryFrame extends JFrame {
private List<Patient> patients;
public SecretaryFrame(List<Patient> patients) {
super("واجهة السكرتير");
this.patients = patients;
setSize(500, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JPanel panel = new JPanel(new GridLayout(3, 1, 10, 10));
JButton showRequestsButton = new JButton("عرض طلبات المواعيد");
JButton showAcceptedButton = new JButton("عرض المواعيد المقبولة");
JButton backButton = new JButton("العودة");
showRequestsButton.addActionListener(_ -> showAppointmentRequests());
showAcceptedButton.addActionListener(_ -> showAcceptedAppointments());
backButton.addActionListener(_ -> {
new LoginFrame();
dispose();
});
panel.add(showRequestsButton);
panel.add(showAcceptedButton);
panel.add(backButton);
add(panel);
setVisible(true);
}
private void showAppointmentRequests() {
String[] options = {"قبول", "رفض", "تخطي"};
for (Patient patient : patients) {
Appointment appointment = patient.getAppointment();
if (appointment.isRequested() && appointment.getStatus().equals("طلب موعد")) {
String action = (String) JOptionPane.showInputDialog(
this,
"طلب موعد من المريض: " + patient.getFirstName() + " " + patient.getLastName(),
"إدارة طلب الموعد",
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]
);
if (action == null || action.equals("تخطي")) {
continue;
}
if (action.equals("قبول")) {
String date = JOptionPane.showInputDialog(this, "أدخل تاريخ الموعد (اليوم/الشهر/السنة):");
if (isValidDate(date)) {
appointment.setDate(date);
JOptionPane.showMessageDialog(this, "تم قبول الموعد للمريض: " + patient.getFirstName());
} else {
JOptionPane.showMessageDialog(this, "التاريخ غير صحيح أو غير صالح.");
}
} else if (action.equals("رفض")) {
String reason = JOptionPane.showInputDialog(this, "أدخل سبب الرفض:");
if (reason != null && !reason.trim().isEmpty()) {
appointment.rejectAppointment();
JOptionPane.showMessageDialog(this, "تم رفض الموعد للمريض: " + patient.getFirstName() + " بسبب: " + reason);
} else {
JOptionPane.showMessageDialog(this, "لم يتم إدخال سبب الرفض.");
}
}
}
}
JOptionPane.showMessageDialog(this, "تم الانتهاء من مراجعة طلبات المواعيد.");
}
private boolean isValidDate(String date) {
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy");
LocalDate enteredDate = LocalDate.parse(date, formatter);
LocalDate currentDate = LocalDate.now();
return enteredDate.isAfter(currentDate);
} catch (DateTimeParseException e) {
return false;
}
}
private void showAcceptedAppointments() {
StringBuilder acceptedAppointments = new StringBuilder();
for (Patient patient : patients) {
Appointment appointment = patient.getAppointment();
if (appointment.getStatus().equals("تم قبول الموعد")) {
acceptedAppointments.append("المريض: ").append(patient.getFirstName()).append(" ").append(patient.getLastName())
.append("\nتاريخ الموعد: ").append(appointment.getDate()).append("\n\n");
}
}
if (acceptedAppointments.length() == 0) {
JOptionPane.showMessageDialog(this, "لا توجد مواعيد مقبولة حاليًا.");
} else {
JOptionPane.showMessageDialog(this, acceptedAppointments.toString(), "المواعيد المقبولة", JOptionPane.INFORMATION_MESSAGE);
}
}
}