-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
457 lines (355 loc) · 12.2 KB
/
Copy pathcode.c
File metadata and controls
457 lines (355 loc) · 12.2 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
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
#include <stdio.h>
#include <stdlib.h>
#include "Std_types.h"
//patient list
typedef struct patientNode{
uint32_t ID;
char name[50];
uint16_t age;
char gender ;
struct patientNode * nextPatientPtr;
}patient;
//reservations list
typedef struct slotsNode{
uint32_t ID ;
float slot;
struct slotsNode* nextSlotPtr;
}reservation;
//protoTypes
void WelcomeMsgs (void);
void mainMenu(void);
void separateLine (void);
void adminMode (void);
void userMode (void);
void copy (char * arr, char * newArr);
void defaultSlots (void);
void NewSlot(float slotValue, reservation** temp);
//declaration
uint16_t mode,U_mode,A_mode;
//initialization
patient* headPTR = NULL;
reservation *slotsHeadPTR = NULL;
int main (void){
defaultSlots();
WelcomeMsgs();
mainMenu();
return 0;
}
void WelcomeMsgs (void){
printf("\n\n\t\t\t\t\t##############################################################################################\n\n\n");
printf("\t\t\t\t\t\t\t\t\tWELCOME TO CLINIC MANAGEMENT SYSTEM\n\n\n");
printf("\t\t\t\t\t##############################################################################################\n");
}
void mainMenu(void){
printf("\n\n###############################################################################\n");
printf("################################ MAIN MENU #################################");
printf("\n###############################################################################\n\n");
printf("-> For Admin mode press '1'\n");
printf("-> For User mode press '2'\n");
printf("-> To exist press '3'\n\n");
separateLine ();
do {
printf("The chosen mode is: ");
scanf("%hu",&mode);
//ADMIN MODE
if (mode == 1){
adminMode();
break;
}
//USER MODE
else if (mode == 2){
userMode();
break;
}
//EXIT
else if (mode == 3) break;
//unvalid option
else printf("\nPlease, Enter a valid option: \n");
} while (1);
}
void adminMode (void){
int pass,count = 0;
printf("To enter admin mode please enter the password \n");
do {
printf("Password: ");
scanf("%d",&pass);
if (pass == 1234){
printf("CORRECT PASSWORD!");
printf("\n\n###############################################################################\n");
printf("########################### WELCOME TO ADMIN MODE ###########################");
printf("\n###############################################################################\n\n");
do {
printf("-> To add new patient press '1'\n");
printf("-> To edit patient record press '2'\n");
printf("-> To reserve with a doctor press '3'\n");
printf("-> To delete a reservation press '4'\n");
printf("-> To return to main menu press '5'\n\n");
separateLine();
printf("Your choice: ");
scanf("%hu",&A_mode);
//add new patient
if (A_mode == 1){
uint16_t id;
char Name[50];
uint16_t Age;
char Gender ;
printf("Please enter the following data: \n");
printf("Patient's ID: ");
scanf("%hu",&id);
printf("Patient's name: ");
scanf("%s",Name);
printf("Patient's age: ");
scanf("%hu",&Age);
printf("For female press 'F' for male press 'M' \n");
printf("Patient gender: ");
scanf(" %c",&Gender);
patient* createdPatientNode =(patient*)calloc(1,sizeof(patient));
if (createdPatientNode != NULL){
createdPatientNode -> ID = id;
copy(Name , createdPatientNode -> name);
createdPatientNode -> age = Age;
createdPatientNode -> gender = Gender;
}
patient* temp = headPTR;
if (headPTR == NULL){
headPTR = createdPatientNode;
printf("New patient added successfully!\n");
}
else
{
uint16_t flag = 1;
while (temp -> nextPatientPtr != NULL){
if(temp -> ID == id){
printf("\nID already exist\nCan't add new patient");
flag =0;
break;
}
temp = temp -> nextPatientPtr;
}
if (flag == 1){
temp -> nextPatientPtr = createdPatientNode;
printf("New patient added successfully!\n");
}
}
separateLine();
}
//edit patient record
else if (A_mode == 2){
uint16_t tempID;
patient* temp = headPTR;
printf("enter patient ID: ");
scanf("%hu",&tempID);
while (temp -> ID != tempID)
{
if (temp -> nextPatientPtr == NULL){
printf("ID NOT FOUND \n\n"); break;
separateLine();
}
temp = temp -> nextPatientPtr;
}
if (temp -> ID == tempID){
printf("\nEnter the new data: \n\n");
uint16_t id;
char Name[50];
uint16_t Age;
char Gender ;
printf("Please enter the following data: \n");
printf("Patient's ID: ");
scanf("%hu",&id);
printf("Patient's name: ");
scanf("%s",Name);
printf("Patient's age: ");
scanf("%hu",&Age);
printf("For female press 'F' for male press 'M' \n");
printf("Patient gender: ");
scanf(" %c",&Gender);
temp -> ID = id;
copy(Name , temp -> name);
temp -> age = Age;
temp -> gender = Gender;
printf("Data updates successfully\n\n");
separateLine();
}
}
//reserve with a doctor
else if (A_mode == 3){
float desiredSlot;uint16_t id; uint16_t flag =1;uint16_t askPatientID =1;
printf ("Todays available reservation slots are: \n");
reservation* temp = slotsHeadPTR;
while (temp -> nextSlotPtr != NULL){
if (temp -> ID == 0){
printf("%.2f pm \n", temp -> slot);
}
temp = temp -> nextSlotPtr;
}
if (temp -> ID == 0){printf("%.2f pm \n\n", temp -> slot);}
printf("enter the desired slot: ");
scanf("%f",&desiredSlot);
temp = slotsHeadPTR;
while(temp -> slot != desiredSlot){
if (temp -> nextSlotPtr == NULL){
printf("The slot you choose is unavailable \n\n");
separateLine(); askPatientID =0; break;
}
temp = temp -> nextSlotPtr;
}
if (askPatientID == 1){
printf("Enter patient ID: ");
scanf("%hu",&id);
patient* patientTemp = headPTR;
reservation* SlotTemp = slotsHeadPTR;
while (patientTemp -> ID != id)
{
if (patientTemp -> nextPatientPtr == NULL){
printf("ID NOT FOUND \nFailed to reserve a slot\n\n"); flag = 0;
separateLine(); break;
}
patientTemp = patientTemp -> nextPatientPtr;
}
while(SlotTemp -> nextSlotPtr != NULL ){
if(SlotTemp -> ID == id){
printf("This ID is already reserved\n"); flag =0;
separateLine(); break;
}
SlotTemp = SlotTemp -> nextSlotPtr;
}
if (flag == 1){
temp -> ID = id;
printf("Slot reserved successfully!\n\n");
separateLine();
}
}
}
//delete reservation
else if (A_mode == 4){
uint16_t tempID; reservation *temp = slotsHeadPTR; uint16_t flag=1;
printf("Patient ID: ");
scanf("%hu",&tempID);
while (temp -> ID != tempID)
{
if (temp -> nextSlotPtr == NULL){
printf("ID NOT FOUND \n\n");
separateLine(); flag =0; break;
}
temp = temp -> nextSlotPtr;
}
if(flag ==1){
temp -> ID = 0;
printf("Reservation deleted successfully \n\n");
separateLine();
}
}
//return to main menu
else if (A_mode == 5){
mainMenu();
break;
}
else printf("Please, enter a valid option\n");
}// sec do while
while (1);
break;
} //if
else {
printf("WRONG PASSWORD\n");
count++;
}
} // main do while
while (count != 3);
if (count == 3) printf("Try again later");
}//admin mode
void userMode (void){
printf("\n\n###############################################################################\n");
printf("########################### WELCOME TO USER MODE ############################");
printf("\n###############################################################################\n\n");
do {
printf("-> To view patient record press '1'\n");
printf("-> To view today's reservations press '2'\n");
printf("-> To return to main menu press '3'\n\n");
separateLine();
printf("Your choice: ");
scanf("%hu",&U_mode);
//view patient record
if (U_mode == 1){
uint16_t tempID ;
patient* temp = headPTR;
if (temp == NULL){
printf("No patients added yet\n\n");
separateLine();
}
else
{
printf("enter patient ID: ");
scanf("%hu",&tempID);
while (temp -> ID != tempID)
{
if (temp -> nextPatientPtr == NULL){
printf("ID NOT FOUND \n\n"); break;
separateLine();
}
temp = temp -> nextPatientPtr;
}
if (temp -> ID == tempID){
printf("\nPatient record: \n\n");
printf("ID: %hu\n",temp -> ID);
printf("Name: %s\n",temp -> name);
printf("Age: %hu\n",temp -> age);
printf("Gender: %c\n",temp -> gender);
separateLine();
}
}
}
//view today's reservation
else if (U_mode == 2){
reservation*temp = slotsHeadPTR;
printf("\nTodays reservations: \n");
while (temp -> nextSlotPtr != NULL){
if (temp -> ID != 0){
printf("Patient with ID: %hu has appointment at %.2f pm \n",temp -> ID ,temp -> slot);
}
temp = temp -> nextSlotPtr;
}
if (temp -> ID != 0){printf("Patient with ID: %hu has appointment at %.2f pm \n",temp -> ID ,temp -> slot);}
printf("\n");
separateLine();
}
//return to main menu
else if (U_mode == 3){
mainMenu();
break;
}
else printf("Please, enter a valid option\n");
}while (1);
}
void separateLine (void){
printf("############################################################################################\n\n");
}
void copy (char * arr, char * newArr){
while (*arr != '\0'){
*newArr = *arr;
arr++; newArr++;
}
}
void defaultSlots (void){
NewSlot(2.00, &slotsHeadPTR); // slot 2 from 2.30 pm to 3.00 pm
NewSlot(2.30, &slotsHeadPTR); // slot 2 from 2.30 pm to 3.00 pm
NewSlot(3.00, &slotsHeadPTR); // slot 3 from 3.00 pm to 3.30 pm
NewSlot(4.00, &slotsHeadPTR); // slot 4 from 4.00 pm to 4.30 pm
NewSlot(4.30, &slotsHeadPTR); // slot 4 from 4.30 pm to 5.00 pm
}
void NewSlot(float slotValue, reservation**slotsHeadPTR){
reservation * createdSlot = NULL;
createdSlot = (reservation*)calloc(1,sizeof(reservation));
if (createdSlot != NULL){
createdSlot -> slot = slotValue;
}
reservation* temp = *slotsHeadPTR;
if (*slotsHeadPTR == NULL){
*slotsHeadPTR = createdSlot;
}
else {
while (temp -> nextSlotPtr != NULL){
temp = temp -> nextSlotPtr;
}
temp -> nextSlotPtr = createdSlot;
}
}