-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHospitalSystem.java
More file actions
192 lines (163 loc) · 6.21 KB
/
Copy pathHospitalSystem.java
File metadata and controls
192 lines (163 loc) · 6.21 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
import java.util.ArrayList;
public class HospitalSystem {
private final ArrayList<Doctor> doctors;
private final ArrayList<Patient> patients;
private final ArrayList<Appointment> appointments;
public HospitalSystem() {
doctors = new ArrayList<>();
patients = new ArrayList<>();
appointments = new ArrayList<>();
}
public void addDoctor(Doctor doctor) {
doctors.add(doctor);
}
public void addPatient(Patient patient) {
patients.add(patient);
}
public void addAvailableSlot(String appointmentId, String doctorId, String date, String timeSlot) {
Appointment appointment = new Appointment(appointmentId, doctorId, date, timeSlot);
appointments.add(appointment);
}
public Doctor getDoctorById(String doctorId) {
for (Doctor doctor : doctors) {
if (doctor.getId().equals(doctorId)) {
return doctor;
}
}
return null;
}
public Patient getPatientById(String patientId) {
for (Patient patient : patients) {
if (patient.getId().equals(patientId)) {
return patient;
}
}
return null;
}
private Appointment findAppointmentById(String appointmentId) {
for (Appointment appointment : appointments) {
if (appointment.getAppointmentId().equals(appointmentId)) {
return appointment;
}
}
return null;
}
public boolean bookAppointment(String patientId, String appointmentId) {
Patient patient = getPatientById(patientId);
Appointment appointment = findAppointmentById(appointmentId);
if (patient == null) {
System.out.println("Patient not found with ID: " + patientId);
return false;
}
if (appointment == null) {
System.out.println("Appointment not found with ID: " + appointmentId);
return false;
}
if (appointment.book(patientId)) {
System.out.println("Appointment booked successfully for " + patient.getName());
return true;
}
return false;
}
public boolean cancelAppointment(String appointmentId) {
Appointment appointment = findAppointmentById(appointmentId);
if (appointment == null) {
System.out.println("Appointment not found with ID: " + appointmentId);
return false;
}
if (appointment.cancel()) {
System.out.println("Appointment cancelled successfully!");
return true;
}
return false;
}
public boolean editDoctor(String doctorId, String name, String phoneNumber, String email, int age, String specialization, String licenseNumber, double consultationFee) {
Doctor doctor = getDoctorById(doctorId);
if (doctor == null) {
System.out.println("Doctor not found with ID: " + doctorId);
return false;
}
doctor.setName(name);
doctor.setPhoneNumber(phoneNumber);
doctor.setEmail(email);
doctor.setAge(age);
doctor.setSpecialization(specialization);
doctor.setLicenseNumber(licenseNumber);
doctor.setConsultationFee(consultationFee);
System.out.println("Doctor updated successfully");
return true;
}
public boolean editPatient(String patientId, String name, String phoneNumber, String email, int age, String medicalHistoryId, String bloodType, String allergies) {
Patient patient = getPatientById(patientId);
if (patient == null) {
System.out.println("Patient not found with ID: " + patientId);
return false;
}
patient.setName(name);
patient.setPhoneNumber(phoneNumber);
patient.setEmail(email);
patient.setAge(age);
patient.setMedicalHistoryId(medicalHistoryId);
patient.setBloodType(bloodType);
patient.setAllergies(allergies);
System.out.println("Patient updated successfully");
return true;
}
public ArrayList<Appointment> getBookedAppointmentsByDoctor(String doctorId) {
ArrayList<Appointment> booked = new ArrayList<>();
for (Appointment appointment : appointments) {
if (appointment.getDoctor().equals(doctorId) && appointment.isBooked()) {
booked.add(appointment);
}
}
return booked;
}
public ArrayList<Appointment> getAvailableAppointmentsByDoctor(String doctorId) {
ArrayList<Appointment> available = new ArrayList<>();
for (Appointment appointment : appointments) {
if (appointment.getDoctor().equals(doctorId) && !appointment.isBooked()) {
available.add(appointment);
}
}
return available;
}
public void displayAllDoctors() {
if (doctors.isEmpty()) {
System.out.println("No doctors available.");
return;
}
System.out.println("All Doctors : ");
for (Doctor doctor : doctors) {
System.out.println(doctor);
}
}
public void displayAllPatients() {
if (patients.isEmpty()) {
System.out.println("No patients registered.");
return;
}
System.out.println("All Patients : ");
for (Patient patient : patients) {
System.out.println(patient);
}
}
public void displayAllAppointments() {
if (appointments.isEmpty()) {
System.out.println("No appointments available.");
return;
}
System.out.println(" All Appointments: ");
for (Appointment appointment : appointments) {
System.out.println(appointment);
}
}
public int getTotalAppointments() {
return appointments.size();
}
public int getTotalDoctors() {
return doctors.size();
}
public int getTotalPatients() {
return patients.size();
}
}