-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDoctorsOffice.cpp
More file actions
358 lines (325 loc) · 10.8 KB
/
DoctorsOffice.cpp
File metadata and controls
358 lines (325 loc) · 10.8 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
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
#include <iostream>
#include <cstring>
#include <bits/stdc++.h>
#ifdef WIN32
#include <ncurses/ncurses.h>
#else
#include <ncurses.h>
#endif
#include "OfficeOfAcademics.h"
#include "DoctorsOffice.h"
#define AppointmentsPath "Appointments.txt"
#define HealthRecordPath "HealthRecord.txt"
#define SpecialistsRequestsPath "SpecialistsRequests.txt"
#define SpecialistsAvailabilityPath "SpecialistsAvailability.txt"
#define SUCCESSFUL 1
#define STUDENT 1
#define FACULTY 2
#define DOCTOR 1
#define HCSTAFF 2
#define YES 1
#define NO 0
int count1=0;
int DoctorsOffice::loginmode= 0;
int DoctorsOffice::SpecList[7] = {0};
char DoctorsOffice::specname[7][40] = {"Gastroenterologist",
"Gynaecologist",
"Paediatrician",
"ENT_Specialist",
"Dermatologist",
"Orthopaedic_Specialist",
"Ophthalmologist"};
void LOGINSTART();
void DoctorsOffice:: PreLoadStuff()
{
//loading the appointments
FILE *fp = fopen(SpecialistsAvailabilityPath,"r");
for(int i=0;i<7;i++)
{
char buffer[100];
fscanf(fp,"%[^\n]s",buffer);
fgetc(fp);
char specialist[40]; int availability;
sscanf(buffer,"%s %d",specialist, &availability);
SpecList[i] = availability;
}
}
void DoctorsOffice:: login(int mode)
{
char ldap[40], pass[40];
std::cout << "Enter Employee ID: " ;
std::cin >> ldap;
initscr(); // enable ncurses
printw("Enter Password: ");
noecho(); // disable character echoing
getnstr(pass,sizeof(pass));
echo(); // enable character echoing again
// getch(); // Wait for a keypress
endwin(); // disable ncurses
// std::cout << std::endl;
int loginverify= OfficeOfAcademics::VerifyCredentials(ldap, pass);
if(loginverify==SUCCESSFUL)
{
std::cout << ("\n** Login Successful! **\n\n");
DoctorsOffice::loginmode = mode;
DoctorsOffice::DisplayOptions();
}
else
{
std::cout << "\n -- Login Unsuccessful! --\n\n";
std::cout << ("Enter credentials again.\n");
count1++;
if(count1==3)
{
printf("You have entered the wrong credentials three times\n\n");
::LOGINSTART();
}
login(mode);
}
}
void DoctorsOffice:: viewHealthRecord(char ldapinp[])
{
FILE *fp = fopen(HealthRecordPath,"r");
char prev[20];
while(!feof(fp))
{
char buffer[100];
fscanf(fp, "%[^\n]s", buffer);
char ldap[20]; char record[80];
int len1 = strlen(buffer);
buffer[len1] = '\n';
buffer[len1+1] = '\0';
sscanf(buffer, "%s %[^\n]s",ldap, record);
fgetc(fp);
if(strcmp(ldap, prev)==0)
break;
if(strcmp(ldapinp,ldap)==0)
{
std::cout << "Student LDAP ID: " << ldap << "\n" ;
std::cout << "Health Record: " << record << "\n" ;
break;
}
strcpy(prev,ldap);
}
}
void DoctorsOffice::addSpecialistRequest(int spec, int loginmode)
{
// if(loginmode==STUDENT)
// SpecList[spec-1] ++;
// else
// SpecList[spec-1] +=5;
FILE *fp1 = fopen(SpecialistsRequestsPath,"r");
FILE *fp2 = fopen("temp3.txt","w");
char prev[40];
while(!feof(fp1))
{
char buffer[100];
fscanf(fp1,"%[^\n]s",buffer);
fgetc(fp1);
char specialist[40]; int requests;
sscanf(buffer,"%s %d",specialist, &requests);
if(strcmp(specialist,prev)==0)
break;
if(strcmp(specialist,specname[spec-1])==0)
{
if(loginmode==FACULTY)
fprintf(fp2,"%s %d\n",specialist,requests+5);
else fprintf(fp2,"%s %d\n",specialist,requests+1);
}
else
fprintf(fp2,"%s %d\n",specialist, requests);
strcpy(prev,specialist);
}
fclose(fp1);
fclose(fp2);
fp1 = fopen(SpecialistsRequestsPath,"w");
fp2 = fopen("temp3.txt","r");
while(!feof(fp2))
{
fputc(fgetc(fp2),fp1);
}
fclose(fp2);
fclose(fp1);
// fp2 = fopen("temp3.txt","w");
// //remove("temp3.txt");
// fclose(fp2);
}
void DoctorsOffice::viewSpecialistRequest()
{
std::cout << "Requests for specialists are as follows: \n";
FILE *fp = fopen(SpecialistsRequestsPath,"r");
while(!feof(fp))
{
fputc(fgetc(fp),stdout);
}
fclose(fp);
}
void DoctorsOffice::addToAppointments(char ldapinp[], char appt[])
{
//std::cout << ldapinp <<" " << appt << "\n";
FILE *fp = fopen(AppointmentsPath,"a");
fprintf(fp,"%s %s\n",ldapinp, appt);
fclose(fp);
}
void DoctorsOffice:: ShowAppointments()
{
FILE *fp = fopen(AppointmentsPath,"r");
std::cout << "\nAppointments are: \n";
while(!(feof(fp)))
{
fputc(fgetc(fp),stdout);
}
std::cout << "\n";
}
int* DoctorsOffice::getSpecList()
{
return SpecList;
}
void DoctorsOffice::updateHealthRecord(char ldapinp[], char details[])
{
FILE *fp2 = fopen(HealthRecordPath,"r");
FILE *fp1 = fopen("temp1.txt","w");
char prev[20];
while(!feof(fp2))
{
char buffer[100];
fscanf(fp2,"%[^\n]s",buffer);
fgetc(fp2);
char ldap[20]; char record[80];
sscanf(buffer, "%s %[^\0]s", ldap, record);
if(strcmp(ldap,prev)==0)
break;
fprintf(fp1,"%s",buffer);
if(strcmp(ldapinp, ldap)==0)
fprintf(fp1," %s", details);
fprintf(fp1,"\n");
strcpy(prev,ldap);
}
fclose(fp1);
fclose(fp2);
fp1 = fopen(HealthRecordPath,"w");
fp2 = fopen("temp1.txt","r");
while(!feof(fp2))
{
fputc(fgetc(fp2),fp1);
}
fclose(fp1);
fclose(fp2);
}
void DoctorsOffice:: DisplayOptions()
{
if(loginmode==DOCTOR) //logging in as Doctor
{
int repeat = YES;
do
{
int incorrectChoice = NO;
std::cout << "\nEnter your choice (The corresponding number): ";
std::cout << " 1: View health Record\n";
std::cout << " 2: Send Medical Leave Record\n";
std::cout << " 3: Show Apointments\n";
std::cout << "Your choice - ";
int choice;
std::cin >> choice;
switch(choice)
{
case 1:
{
char ldap[25];
std::cout << "Enter LDAP of the patient \n";
std::cin >> ldap;
DoctorsOffice::viewHealthRecord(ldap);
break;
}
case 2:
{
char roll[15];
char leaves[60];
std::cout << "Enter roll number of the student\n";
scanf("%s",roll);
std::cout<< "Enter the leaves granted\n";
fflush(stdin);
scanf("%[^\n]s",leaves);
OfficeOfAcademics::UpdateMedicalLeaveRecord(roll,leaves);
break;
}
case 3:
{
DoctorsOffice::ShowAppointments();
break;
}
default :
{
std::cout << " -- Please enter valid choice! --\n";
incorrectChoice = YES;
}
}
if(incorrectChoice==YES)
repeat = YES;
else
{
std::cout << "Would you like to perform more operations as Doctor? (Yes/No): ";
std::string response;
std::cin >> response;
std::transform(response.begin(), response.end(), response.begin(), ::tolower);
if(response.std::string::compare("yes")==0)
repeat = YES;
else
repeat = NO;
}
}while(repeat == YES);
}
if(loginmode==HCSTAFF) //logging in as Staff
{
int repeat = YES;
do
{
int incorrectChoice = NO;
std::cout << "\nEnter your choice (The corresponding number): ";
std::cout << " 1: Update Health Record\n";
std::cout << " 2: View Specialist request\n";
std::cout << "Your choice - ";
int choice;
std::cin >> choice;
switch(choice)
{
case 1:
{
char ldap[15];
char details[100];
std::cout << "Enter LDAP of the Patient\n";
std::cin >> ldap;
fflush(stdin);
std::cout<<"Enter the details that are to be updated\n";
fgetc(stdin);
scanf("%[^\n]s", details);
DoctorsOffice::updateHealthRecord(ldap,details);
break;
}
case 2:
{
DoctorsOffice::viewSpecialistRequest();
break;
}
default:
{
std::cout << "Please enter a valid option!\n";
incorrectChoice = YES;
}
}
if(incorrectChoice==YES)
repeat = YES;
else
{
std::cout << "\nWould you like to perform more operations as HC Staff? (Yes/No): ";
std::string response;
std::cin >> response;
std::transform(response.begin(), response.end(), response.begin(), ::tolower);
if(response.std::string::compare("yes")==0)
repeat = YES;
else
repeat = NO;
}
}while(repeat == YES);
}
}