-
Notifications
You must be signed in to change notification settings - Fork 1
/
Austin4.cpp
428 lines (379 loc) · 12.2 KB
/
Austin4.cpp
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
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
class Patient{
protected:
int pId, age;
string name, symptoms;
public:
Patient(int pId):pId(pId){};
Patient(int pId, string name, int age, string symptoms) : pId(pId), age(age), name(name), symptoms(symptoms) {};
int getId() { return pId; }
string getName() { return name; }
int getAge() { return age; }
string getSymp() { return symptoms; }
};
class Doctor{
protected:
int dId;
string name, specialization;
public:
Doctor(int dId) : dId(dId){};
Doctor(int dId, string name, string specialization) : dId(dId), name(name), specialization(specialization) {};
int getId() { return dId; }
string getName() { return name; }
string getSpecialization() { return specialization; }
};
class Appointment : protected Patient, protected Doctor{
int aId, date, time;
vector<Patient> &patients;
vector<Doctor> &doctors;
public:
Appointment(int aId, int dId, int pId, int date, int time, vector<Patient> &patients, vector<Doctor> &doctors) : aId(aId), date(date), time(time), patients(patients), doctors(doctors), Doctor(dId), Patient(pId){};
int getId() { return aId; }
int getpId() { return pId; }
int getdId() { return dId; }
int getDate() { return date; }
int getTime() { return time; }
string getPatientName(){
for (auto &itr : patients){
if (pId == itr.getId()){
return itr.getName();
}
}
return "unknown";
}
string getDoctorName(){
for (auto &itr : doctors){
if (dId == itr.getId()){
return itr.getName();
}
}
return "unknown";
}
};
class Bill{
int bId, amount, pId;
string status;
vector<Patient> &patients;
public:
Bill(int bId, int pId, int amount, string status, vector<Patient> &patients) : bId(bId), pId(pId), amount(amount), status(status), patients(patients) {};
int getId() { return bId; }
int getpId() { return pId; }
int getAmount() { return amount; }
string getStatus() { return status; }
string getName(){
for (auto &itr : patients)
{
if (pId == itr.getId())
{
return itr.getName();
}
}
return "unknown";
}
};
class Prescription{
int dId, pId, prId;
string prescription;
public:
Prescription(int prId, int dId, int pId, std::string prescription) : prId(prId), dId(dId), pId(pId), prescription(prescription) {};
int getId() { return prId; }
int getDoctorId() { return dId; }
int getPatientId() { return pId; }
string getPrescription() { return prescription; }
};
bool checkDoctorId(vector<Doctor> &doctors, int id){
bool check = false;
for (auto &doctor : doctors){
if (id == doctor.getId()){
check = true;
break;
}
}
return check;
};
bool checkPatientId(vector<Patient> &patients, int id){
bool check = false;
for (auto &patient : patients){
if (id == patient.getId()){
check = true;
break;
}
}
return check;
};
class Management{
public:
void viewPatients(vector<Patient> &patients){
cout<<"Patients Lists:\n";
cout<<setw(5)<<"pID"<<setw(15)<<"Name"<<setw(5)<<"Age"<<" "<<"Symptoms"<<endl;
for (auto &patient : patients){
cout<<patient.getId()<<setw(12)<<patient.getName()<<setw(7)<<patient.getAge()<<setw(10)<<patient.getSymp()<<endl;
}
}
void viewDoctors(vector<Doctor> &doctors)
{
cout<<"Doctors List:\n";
cout<<"dID"<<" "<<setw(8)<<"Name"<<" "<<setw(18)<<"Specialization"<<endl;
for (auto &doctor : doctors){
cout<<doctor.getId()<<setw(10)<<doctor.getName()<<setw(10)<<doctor.getSpecialization()<<" ";
cout<<endl;
}
}
void viewBill(vector<Bill> &bills){
cout<<"Bill List:\n";
cout<<"bID"<<setw(5)<<"pID"<<setw(10)<<"Name"<<setw(15)<<"Amount"<<setw(10)<<"Status"<<endl;
for (auto &itr : bills)
{
cout<<itr.getId()<<setw(5)<<itr.getpId()<<setw(15)<<itr.getName()<<setw(9)<<itr.getAmount()<<setw(12)<<itr.getStatus()<<endl;
}
}
void viewAppointment(vector<Appointment> &appointments){
cout<<"Appointment List:\n";
cout<<"aID"<<setw(5)<<"pID"<<setw(18)<<"Patient_Name"<<setw(7)<<"dID"<<setw(15)<<"DoctorName"<<setw(8)<<"Date"<<setw(11)<<"Time "<<endl;
for (auto &appointment : appointments)
{
cout<<appointment.getId()<<setw(5)<<appointment.getpId()<<setw(15)<<appointment.getPatientName()<<setw(10)<<appointment.getdId()<<setw(10)<<appointment.getDoctorName()<<setw(13)<<appointment.getDate()<<setw(10)<<appointment.getTime()<<endl;
};
};
int addPatient(vector<Patient> &patients){
static int pId = 1;
int age;
string name, symptoms;
cout<<"Enter the Patient Name : ";
cin.ignore();
getline(cin, name);
cout<<"Enter the age : ";
cin >> age;
cout<<"What are your symptoms ?\n";
cin.ignore();
getline(cin, symptoms);
for (auto &patient : patients){
if (pId == patient.getId()){
pId += 1;
patients.emplace_back(pId, name, age, symptoms);
cout<<"Patient is added successfully!\n";
return 0;
}
}
patients.emplace_back(pId, name, age, symptoms);
cout<<"Patient is added successfully!\n";
return 0;
}
int addDoctors(vector<Doctor> &doctors){
static int dId = 1;
string name, specialization;
cout<<"Enter the Doctor Name : ";
cin.ignore();
getline(cin, name);
cout<<"What are your Specialization ?\n";
cin.ignore();
getline(cin, specialization);
for (auto &doctor : doctors){
if (dId == doctor.getId()){
dId += 1;
doctors.emplace_back(dId, name, specialization);
cout<<"Doctor is added successfully!\n";
return 0;
}
}
doctors.emplace_back(dId, name, specialization);
cout<<"Doctor is added successfully!\n";
return 0;
}
int addBill(vector<Bill> &bills, vector<Patient> &patients){
static int bId = 1;
int amount;
string status;
int pId;
cout<<"Enter the patient's id : ";
cin >> pId;
cout<<"enter the amount value : \n";
cin >> amount;
cout<<"Enter the status : \n";
cin.ignore();
getline(cin, status);
bool patientFound = false;
for (auto &itr : patients){
if (pId == itr.getId()){
patientFound = true;
break;
}
}
if (patientFound){
bId += 1;
bills.emplace_back(bId, pId, amount, status, patients);
cout<<"Bill is added successfully!\n";
}
else{
cout<<"No patient found with this ID!\n";
}
return 0;
}
void addAppointment(vector<Appointment> &appointments, vector<Patient> &patients, vector<Doctor> &doctors){
static int aId = 1;
int pId, dId, date, time;
cout<<"Enter Patient ID : ";
cin >> pId;
cout<<"Enter Doctor ID : ";
cin >> dId;
cout<<"Enter Date : ";
cin >> date;
cout<<"Enter Time : ";
cin >> time;
//If any Id out of dId and pId not exists, then we write the statement of being Id invalid.
if (!checkDoctorId(doctors, dId)){
cout<<"Doctor Id is invalid. Please check again!";
return;
}
else if (!checkPatientId(patients, pId)){
cout<<"Patient Id is invalid. Please check again!";
return;
}
appointments.emplace_back(aId++, dId, pId, date, time, patients, doctors);
cout<<"Appointment is added successfully!\n";
return;
}
void viewPrescriptions(vector<Patient> &patients, vector<Doctor> &doctors, vector<Prescription> &prescriptions){
if (prescriptions.size() == 0){
cout<<"No prescriptions are available!"<<endl;
return;
}
cout<<"Prescriptions List : \n";
cout<<setw(4)<<"prescriptionId"<<setw(15)<<"Doctor Name"<<setw(15)<<"Patient Name\n";
for (auto &prescription : prescriptions){
// For finding the Doctor and Patient Name
string docName = "null", patName = "null";
for (auto &doctor : doctors){
int docId = doctor.getId();
if (prescription.getDoctorId() == docId){
docName = doctor.getName();
}
}
for (auto &patient : patients){
int patId = patient.getId();
if (prescription.getPatientId() == patId){
patName = patient.getName();
}
}
// Printing each prescriptions
cout<<setw(4)<<prescription.getId()<<setw(15)<<docName<<setw(15)<<patName<<" - Prescription --> "<<prescription.getPrescription()<<endl;
}
}
void addPrescription(vector<Patient> &patients, vector<Doctor> &doctors, vector<Prescription> &prescriptions){
static int prId = 1;
int dId, pId;
// int prId, dId, pId;
string prescription;
cout<<"Enter the Doctor Id : ";
cin >> dId;
cout<<"Enter the Patient Id : ";
cin >> pId;
cout<<"Enter the Prescription : ";
cin.ignore();
getline(cin, prescription);
// If any Id out of dId and pId not exists, then we write the statement of being Id invalid.
if (!checkDoctorId(doctors, dId)){
cout<<"Doctor Id is invalid. Please check again!";
return;
}
else if (!checkPatientId(patients, pId)){
cout<<"Patient Id is invalid. Please check again!";
return;
}
prescriptions.emplace_back(prId++, dId, pId, prescription);
cout<<"Prescription is added successfully!\n";
return;
}
};
int main(){
vector<Patient> patients = {{1,"Ambani",36,"Weight loss"}};
vector<Doctor> doctors = {{1,"Mukesh", "MBBS"}};
vector<Bill> bills = {{1,1,200,"Paid",patients}};
vector<Appointment> appointment;
vector<Prescription> prescriptions;
Management system;
int choice;
do{
cout<<"--------------------"<<endl;
cout<<"1. View Patients\n";
cout<<"2. Add Patients\n";
cout<<"--------------------"<<endl;
cout<<"3. View Doctors\n";
cout<<"4. Add Doctors\n";
cout<<"--------------------"<<endl;
cout<<"5. View Bill\n";
cout<<"6. Add Bill\n";
cout<<"--------------------"<<endl;
cout<<"7. View Appointment\n";
cout<<"8. Add Appointment\n";
cout<<"--------------------"<<endl;
cout<<"9. View Prescription\n";
cout<<"10. Add Prescription\n";
cout<<"--------------------"<<endl;
cout<<"11. Exit\n";
cout<<"--------------------"<<endl;
cout<<"Enter your choice : ";
cin >> choice;
if (cin.fail())
{
cout<<"Invalid input. Please enter a number between 1 and 11.\n";
cin.clear(); // Clear the invalid input
cin.ignore(INT8_MAX, '\n'); // It ignore the invalid input in the cin
continue; // Restart the loop
}
switch (choice){
case 1:
system.viewPatients(patients);
cout<<"===============================================================\n";
break;
case 2:
system.addPatient(patients);
cout<<"===============================================================\n";
break;
case 3:
system.viewDoctors(doctors);
cout<<"===============================================================\n";
break;
case 4:
system.addDoctors(doctors);
cout<<"===============================================================\n";
break;
case 5:
system.viewBill(bills);
cout<<"===============================================================\n";
break;
case 6:
system.addBill(bills, patients);
cout<<"===============================================================\n";
break;
case 7:
system.viewAppointment(appointment);
cout<<"===============================================================\n";
break;
case 8:
system.addAppointment(appointment, patients, doctors);
cout<<"===============================================================\n";
break;
case 9:
system.viewPrescriptions(patients, doctors, prescriptions);
cout<<"===============================================================\n";
break;
case 10:
system.addPrescription(patients, doctors, prescriptions);
cout<<"===============================================================\n";
break;
case 11:
cout<<"-------------- Thank You for the visit --------------";
break;
default:
cout<<"Invalid Number\n";
cout<<"---------TRY AGAIN---------\n";
cout<<"===============================================================\n";
}
} while (choice != 11);
return 0;
}