This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
183 lines (151 loc) · 5.69 KB
/
main.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
#include <iostream>
#include <string>
// include our defined headers
#include "patients/Patient.h"
#include "doctors/Doctor.h"
#include "appointments/Appointment.h"
using namespace std;
void menu() {
// initializing linked lists we'll be using
PatientLinkedList patientLinkedList;
DoctorLinkedList doctorLinkedList;
AppointmentLinkedList appointmentLinkedList;
int choice;
do {
cout << "\nMenu:\n";
cout << "1. Register a Patient\n";
cout << "2. Register a Doctor\n";
cout << "3. Register an appointment\n";
cout << "4. Display Patients\n";
cout << "5. Display Doctors\n";
cout << "6. Display Appointments\n";
cout << "7. Exit \n";
// Get user's choice
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1: {
int id;
string name;
string dob;
string gender;
cout << "\n\n" << "PATIENT REGISTRATION";
cout << "\n--------------------\n\n";
// request data and validate them
ask_for_patient_id:
cout << "ID: ";
cin >> id;
// Check if patient with given id already exist
if (patientLinkedList.doesPatientExistById(id)) {
cout << "\nPatient with this id already exist";
cout << "\nTry different Id";
goto ask_for_patient_id;
}
cout << "\nNAME: ";
cin >> name;
cout << "\nDoB: ";
cin >> dob;
cout << "\nGENDER: ";
cin >> gender;
// create a patient with provided data
Patient patient(id, name, dob, gender);
// save patient to patient linkedlist
patientLinkedList.addPatient(patient);
break;
}
case 2: {
int id;
string name;
string specialization;
cout << "\n\n" << "DOCTOR REGISTRATION";
cout << "\n-------------------\n\n";
// request data
ask_for_doctor_id:
cout << "ID: ";
cin >> id;
// Check if patient with given id already exist
if (doctorLinkedList.doesDoctorExistById(id)) {
cout << "\nDoctor with this id already exist";
cout << "\nTry different Id";
goto ask_for_doctor_id;
}
cout << "\nNAME: ";
cin >> name;
cout << "\nSPECIALIZATION: ";
cin >> specialization;
// create a doctor with provided data
Doctor doctor(id, name, specialization);
// save doctor to doctor linkedlist
doctorLinkedList.addDoctor(doctor);
break;
}
case 3: {
int id;
int patient_id;
int doctor_id;
string date;
cout << "\n\n" << "APPOINTMENT REGISTRATION";
cout << "\n------------------------\n\n";
// request data and validate them
ask_for_appointment_id:
cout << "ID: ";
cin >> id;
if (appointmentLinkedList.doesAppointmentExistById(id)) {
cout << "\nAppointment with this id already exist";
cout << "\nTry different Id";
goto ask_for_appointment_id;
}
ask_for_patient_id_app:
cout << "\nP_ID: ";
cin >> patient_id;
if (!patientLinkedList.doesPatientExistById(patient_id)) {
cout << "\nPatient with provided id doesn't exist";
cout << "\nTry different Id";
goto ask_for_patient_id_app;
}
ask_for_doctor_id_app:
cout << "\nD_ID: ";
cin >> doctor_id;
if (!doctorLinkedList.doesDoctorExistById(doctor_id)) {
cout << "\nDoctor with provided id doesn't exist";
cout << "\nTry different Id";
goto ask_for_doctor_id_app;
}
cout << "\nDATE: ";
cin >> date;
// create an appointment with provided data
Appointment appointment(id, patient_id, doctor_id, date);
// save an appointment to appointment linkedlist
appointmentLinkedList.addAppointment(appointment);
break;
}
case 4: {
patientLinkedList.displayPatients();
break;
}
case 5: {
doctorLinkedList.displayDoctors();
break;
}
case 6: {
appointmentLinkedList.displayAppointments();
break;
}
case 7: {
cout << "\nSaving session data & Exiting....";
const string filename = R"(C:\Users\User\Documents\dsa-logs\data.csv)";
patientLinkedList.saveToCSV(filename);
doctorLinkedList.saveToCSV(filename);
appointmentLinkedList.saveToCSV(filename);
cout << "\nDone, bye!";
break;
}
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 7);
}
int main() {
menu();
return 0;
}