-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoctor.cs
346 lines (316 loc) · 16.1 KB
/
Doctor.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalManagementConsole
{
internal class Doctor : User
{
private string address, email, phone;
//Doctor constructor
public Doctor(string id, string password, string fullName, string address, string email, string phone, string role) : base(id, password, fullName, role)
{
this.address = address;
this.email = email;
this.phone = phone;
}
//Doctor Details method
public void Details()
{
Console.Clear();
Console.WriteLine("┌──────────────────────────────────────┐");
Console.WriteLine("│ │");
Console.WriteLine("│ DOTNET Hospital Managment System │");
Console.WriteLine("│──────────────────────────────────────│");
Console.WriteLine("│ My Details │");
Console.WriteLine("│ │");
Console.WriteLine("└──────────────────────────────────────┘");
Console.WriteLine();
//additional processing required to format into table as per specifications
string[] labelNames = { "Name", "Email Address", "Phone", "Address" };
Utils.Header(labelNames, "-");
//Display the doctor's details
Console.WriteLine(this);
Console.ReadKey();
Menu();
}
//Method to display the doctor's details
public void ListAssignedPatients()
{
Console.Clear();
Console.WriteLine("┌──────────────────────────────────────┐");
Console.WriteLine("│ │");
Console.WriteLine("│ DOTNET Hospital Managment System │");
Console.WriteLine("│──────────────────────────────────────│");
Console.WriteLine("│ My Patients │");
Console.WriteLine("│ │");
Console.WriteLine("└──────────────────────────────────────┘");
Console.WriteLine();
Console.WriteLine($"Patients assigned to {fullName}");
Console.WriteLine();
//additional processing required to format into table as per specifications
string[] labelNames = { "Name", "Doctor", "Email Address", "Phone", "Address" };
Utils.Header(labelNames, "-");
//Get all patients assigned to this doctor from RegisteredPatients directory
if (File.Exists($"DB\\Doctors\\RegisteredPatients\\{id}.txt"))
{
string[] patients = File.ReadAllLines($"DB\\Doctors\\RegisteredPatients\\{id}.txt");
foreach (string patient in patients)
{
// for each registered patient, read their respective file and display the details
string[] registeredPatient = File.ReadAllLines($"DB\\Patients\\{patient}.txt");
string[] registeredPatientDetails = registeredPatient[0].Split(';');
Patient p = new Patient(registeredPatientDetails[0], registeredPatientDetails[1], registeredPatientDetails[2], registeredPatientDetails[3], registeredPatientDetails[4], registeredPatientDetails[5], "Patient");
Console.WriteLine(p);
}
}
else
{
Console.WriteLine("No patients assigned to you.");
}
Console.ReadKey();
Menu();
}
//Method to display all appointments for the doctor
public void ListAppointments()
{
Console.Clear();
Console.WriteLine("┌──────────────────────────────────────┐");
Console.WriteLine("│ │");
Console.WriteLine("│ DOTNET Hospital Managment System │");
Console.WriteLine("│──────────────────────────────────────│");
Console.WriteLine("│ All Appointments │");
Console.WriteLine("│ │");
Console.WriteLine("└──────────────────────────────────────┘");
Console.WriteLine();
//additional processing required to format into table as per specifications
string[] labelNames = { "Doctor", "Patient", "Description" };
Utils.Header(labelNames, "-");
//Get all appointments for this doctor from Appointments directory
if (File.Exists($"DB\\Appointments\\Doctors\\{id}.txt"))
{
string[] appointments = File.ReadAllLines($"DB\\\\Appointments\\Doctors\\{id}.txt");
foreach (string appointment in appointments)
{
// for each appointment within the doctor's file, display the appointment details
string[] appointmentDetails = appointment.Split('|');
Appointment a = new Appointment(appointmentDetails[0], appointmentDetails[1], appointmentDetails[2]);
Console.WriteLine(a);
}
}
else
{
Console.WriteLine("No appointments for you.");
}
Console.ReadKey();
Menu();
}
//Method to check a particular patient
public void CheckParticularPatient()
{
Console.Clear();
Console.WriteLine("┌──────────────────────────────────────┐");
Console.WriteLine("│ │");
Console.WriteLine("│ DOTNET Hospital Managment System │");
Console.WriteLine("│──────────────────────────────────────│");
Console.WriteLine("│ Check Patient Details │");
Console.WriteLine("│ │");
Console.WriteLine("└──────────────────────────────────────┘");
Console.WriteLine();
Console.Write("Enter the ID of the patient to check: ");
try
{
string patientID = Console.ReadLine() ?? "";
//validate patient ID format
if (!Utils.ValidateInput(patientID, "id"))
{
throw new Exception("Invalid ID format, return to menu by pressing any key");
}
//Check if patient exists in the Patients directory
if (File.Exists($"DB\\Patients\\{patientID}.txt"))
{
string[] patientDetails = File.ReadAllText($"DB\\Patients\\{patientID}.txt").Split(';');
Console.WriteLine();
string[] labelNames = { "Patient", "Doctor", "Email Address", "Phone", "Address" };
Utils.Header(labelNames, "-");
Patient p = new Patient(patientDetails[0], patientDetails[1], patientDetails[2], patientDetails[3], patientDetails[4], patientDetails[5], "Patient");
Console.WriteLine(p);
}
else
{
throw new Exception("Patient not found, return to menu by pressing any key");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.ReadKey();
Menu();
}
}
//Method to list appointments with a particular patient
public void ListAppointmentsWIthPatient()
{
Console.Clear();
Console.WriteLine("┌──────────────────────────────────────┐");
Console.WriteLine("│ │");
Console.WriteLine("│ DOTNET Hospital Managment System │");
Console.WriteLine("│──────────────────────────────────────│");
Console.WriteLine("│ Appointment With │");
Console.WriteLine("│ │");
Console.WriteLine("└──────────────────────────────────────┘");
Console.WriteLine();
Console.Write("Enter the ID of the patient you would like to view appointments for: ");
try
{
string patientID = Console.ReadLine() ?? "";
//validate patient ID format
if (!Utils.ValidateInput(patientID, "id"))
{
throw new Exception("Invalid ID format, return to menu by pressing any key");
}
//check if patient exists and is registered patient of the doctor in patient's registered doctor directory.
if (File.Exists($"DB\\Patients\\{patientID}.txt"))
{
if (File.Exists($"DB\\Patients\\RegisteredDoctors\\{patientID}.txt"))
{
string[] registeredDoctors = File.ReadAllLines($"DB\\Patients\\RegisteredDoctors\\{patientID}.txt");
// if registeredDoctors contains the doctor's id, then the patient is assigned to the doctor.
if (registeredDoctors.Contains(id))
{
Console.WriteLine();
//additional processing required to format into table as per specifications
string[] labelNames = { "Doctor", "Patient", "Description" };
Utils.Header(labelNames, "-");
if (File.Exists($"DB\\Appointments\\Patients\\{patientID}.txt"))
{
string[] appointments = File.ReadAllLines($"DB\\Appointments\\Patients\\{patientID}.txt");
foreach (string appointment in appointments)
{
string[] appointmentDetails = appointment.Split('|');
Appointment a = new Appointment(appointmentDetails[0], appointmentDetails[1], appointmentDetails[2]);
Console.WriteLine(a);
}
}
else
{
Console.WriteLine("No appointments for you.");
}
}
else
{
throw new Exception("Patient not assigned to you, return to menu by pressing any key");
}
}
else
{
throw new Exception("No patients assigned to you, return to menu by pressing any key");
}
}
else
{
throw new Exception("Patient not found, return to menu by pressing any key");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.ReadKey();
Menu();
}
//[TODO] : Appointment search using patient ID
}
//override Menu method from User to display Patient Menu
public override void Menu()
{
Console.Clear();
Console.WriteLine("┌──────────────────────────────────────┐");
Console.WriteLine("│ │");
Console.WriteLine("│ DOTNET Hospital Managment System │");
Console.WriteLine("│──────────────────────────────────────│");
Console.WriteLine("│ Doctor Menu │");
Console.WriteLine("│ │");
Console.WriteLine("└──────────────────────────────────────┘");
Console.WriteLine();
Console.WriteLine($"Welcome to DOTNET Hospital Managment System {fullName}");
Console.WriteLine();
Console.WriteLine("Please choose an option:");
foreach (string option in options)
{
Console.WriteLine(option);
}
try
{
var info = Console.ReadKey(true);
switch (info.Key)
{
//1. List doctor details
case ConsoleKey.D1:
case ConsoleKey.NumPad1:
Details();
break;
//2. List patients
case ConsoleKey.D2:
case ConsoleKey.NumPad2:
ListAssignedPatients();
break;
//3. List appointments
case ConsoleKey.D3:
case ConsoleKey.NumPad3:
ListAppointments();
break;
//4. Check particular patient
case ConsoleKey.D4:
case ConsoleKey.NumPad4:
CheckParticularPatient();
break;
//5. List appointment with patient
case ConsoleKey.D5:
case ConsoleKey.NumPad5:
ListAppointmentsWIthPatient();
break;
//6. Logout
case ConsoleKey.D6:
case ConsoleKey.NumPad6:
Console.Clear();
Program.Main([]);
break;
case ConsoleKey.D7:
case ConsoleKey.NumPad7:
Environment.Exit(0);
break;
default:
throw new Exception($"Invalid option, please choose from 1-{options.Length}");
}
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine(e.Message);
Console.ReadKey();
Menu();
}
Console.ReadKey();
}
public override string ToString()
{
return $"{fullName,-20} | {email,-20} | {phone,-5} | {address,-20}";
}
public string ToSave()
{
return $"{id};{password};{fullName};{address};{email};{phone}";
}
~Doctor()
{
Console.WriteLine("Doctor object destroyed and clearing memory");
GC.Collect();
}
}
}