-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatient.java
More file actions
175 lines (135 loc) · 5.2 KB
/
Copy pathPatient.java
File metadata and controls
175 lines (135 loc) · 5.2 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
import java.util.ArrayList;
public class Patient extends User{
private String Gender;
private String Age;
private String Assigned_doctor;
ArrayList<Appointment>MyAppointments;
public Patient(String ID, String name, String password, String username, String phonenumber) {
super(ID, name, password, username, phonenumber);
}
public Patient(){
this.MyAppointments = new ArrayList<>();
}
public Patient(String id,String name,String Age,String Gender,String phonenumber,String Assigned_doctor,String password,String username) {
super(id, name, password, username, phonenumber);
this.Age = Age;
this.Gender = Gender;
this.Assigned_doctor=Assigned_doctor;
this.MyAppointments = new ArrayList<>();
}
public void setGender(String Gender) {
this.Gender = Gender;
}
public void setAge(String Age) {
this.Age = Age;
}
public void setAssigned_doctor(String Assigned_doctor) {
this.Assigned_doctor = Assigned_doctor;
}
public String getGender() {
return Gender;
}
public String getAge() {
return Age;
}
public ArrayList<Appointment> getPatientAppointments() {
return MyAppointments;
}
public String getAssigned_doctor() {
if (Assigned_doctor==null){
return "You have not assigned your doctor yet.";
}
else
return Assigned_doctor;
}
public void getList_of_Appointments() {
if (MyAppointments.isEmpty()) {
System.out.println("You have not reserved any appointments.");
} else {
System.out.println("Your Appointments:");
for (Appointment app : MyAppointments) {
System.out.println("- Date: " + app.getDate() + " | Time: " + app.getTime() + " | Status: " + app.getStatus()); }
}
}
@Override
public void displayinfo(){
System.out.println("Name: "+getName());
System.out.println("Username: "+getUsername());
System.out.println("Age: "+getAge());
System.out.println("Gender: "+getGender());
System.out.println("Phone number: "+getPhonenumber());
System.out.println("ID: "+getID());
System.out.println("Assigned Doctor: " +getAssigned_doctor());
}
public String Book_Appointment(String date, String time, Admin admin) {
if (this.getAssigned_doctor() == null || this.getAssigned_doctor().equals("You have not assigned your doctor yet.")) {
return "You must be assigned to a doctor first!";
}
Doctor targetDoctor = null;
for (Doctor d : admin.Doctors) {
if (d.getName().equalsIgnoreCase(this.getAssigned_doctor())) {
targetDoctor = d;
break;
}
}
if (targetDoctor == null) {
return "Error: Assigned doctor not found in the system!";
}
boolean available =
admin.checkDoctorAvailability(
targetDoctor.getID(),
date,
time
);
if(!available){
return "Doctor already has appointment at this time!";
}
Appointment newAppointment =
new Appointment(
this.getID(),
targetDoctor.getID(),
"APP" + (admin.Appointments.size() + 1),
date,
time,
"Confirmed"
);
newAppointment.patientID = this.getID();
newAppointment.doctorID = targetDoctor.getID();
newAppointment.status = "Confirmed";
newAppointment.appointmentID = "APP" + (admin.Appointments.size() + 1);
targetDoctor.MyAppointments.add(newAppointment);
this.MyAppointments.add(newAppointment);
admin.createappointment(newAppointment, targetDoctor, this);
System.out.println("Appointment booked and shared with your Doctor and Admin.");
return "Appointment booked successfully with Dr. " + targetDoctor.getName();
}
public void bookAppointment(Appointment newApp, Admin admin, Doctor doctor) {
if (newApp != null && admin != null && doctor != null) {
this.MyAppointments.add(newApp);
doctor.getMyAppointments().add(newApp);
admin.getAppointments().add(newApp);
System.out.println("Appointment booked and shared successfully.");
}
}
public String Cancel_Appointment(String date, String time, Admin admin) {
Appointment appointmentToCancel = null;
for (Appointment app : MyAppointments) {
if (app.getDate().equals(date) && app.getTime().equals(time)) {
appointmentToCancel = app;
break;
}
}
if (appointmentToCancel != null) {
MyAppointments.remove(appointmentToCancel);
admin.Appointments.remove(appointmentToCancel);
for (Doctor d : admin.Doctors) {
if (d.getID().equals(appointmentToCancel.getDoctorID())) {
d.MyAppointments.remove(appointmentToCancel);
break;
}
}
return "Appointment on " + date + " at " + time + " cancelled successfully.";
}
return "There is no Appointment with this date or time!!";
}
}