-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hospital_Management.c
206 lines (152 loc) · 4.4 KB
/
Hospital_Management.c
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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct patient{
int id;
char patientName[50];
char patientAddress[50];
char disease[50];
char date[12];
}p;
struct doctor{
int id;
char name[50];
char address[50];
char specialize[50];
char date[12];
}d;
FILE *fp;
int main(){
int ch;
while(1){
system("cls");
printf("<== Hospital Management System ==>\n");
printf("1.Admit Patient\n");
printf("2.Patient List\n");
printf("3.Discharge Patient\n");
printf("4.Add Doctor\n");
printf("5.Doctors List\n");
printf("0.Exit\n\n");
printf("Enter your choice: ");
scanf("%d", &ch);
switch(ch){
case 0:
exit(0);
case 1:
admitPatient();
break;
case 2:
patientList();
break;
case 3:
dischargePatient();
break;
case 4:
addDoctor();
break;
case 5:
doctorList();
break;
default:
printf("Invalid Choice...\n\n");
}
printf("\n\nPress Any Key To Continue...");
getch();
}
return 0;
}
void admitPatient(){
char myDate[12];
time_t t = time(NULL);
struct tm tm = *localtime(&t);
sprintf(myDate, "%02d/%02d/%d", tm.tm_mday, tm.tm_mon+1, tm.tm_year + 1900);
strcpy(p.date, myDate);
fp = fopen("patient.txt", "ab");
printf("Enter Patient id: ");
scanf("%d", &p.id);
printf("Enter Patient name: ");
fflush(stdin);
gets(p.patientName);
printf("Enter Patient Address: ");
fflush(stdin);
gets(p.patientAddress);
printf("Enter Patient Disease: ");
fflush(stdin);
gets(p.disease);
printf("\nPatient Added Successfully");
fwrite(&p, sizeof(p), 1, fp);
fclose(fp);
}
void patientList(){
system("cls");
printf("<== Patient List ==>\n\n");
printf("%-10s %-30s %-30s %-20s %s\n", "Id", "Patient Name", "Address", "Disease", "Date");
printf("----------------------------------------------------------------------------------------------------------\n");
fp = fopen("patient.txt", "rb");
while(fread(&p, sizeof(p), 1, fp) == 1){
printf("%-10d %-30s %-30s %-20s %s\n", p.id, p.patientName, p.patientAddress, p.disease, p.date);
}
fclose(fp);
}
void dischargePatient(){
int id, f=0;
system("cls");
printf("<== Discharge Patient ==>\n\n");
printf("Enter Patient id to discharge: ");
scanf("%d", &id);
FILE *ft;
fp = fopen("patient.txt", "rb");
ft = fopen("temp.txt", "wb");
while(fread(&p, sizeof(p), 1, fp) == 1){
if(id == p.id){
f=1;
}else{
fwrite(&p, sizeof(p), 1, ft);
}
}
if(f==1){
printf("\n\nPatient Discharged Successfully.");
}else{
printf("\n\nRecord Not Found !");
}
fclose(fp);
fclose(ft);
remove("patient.txt");
rename("temp.txt", "patient.txt");
}
void addDoctor(){
char myDate[12];
time_t t = time(NULL);
struct tm tm = *localtime(&t);
sprintf(myDate, "%02d/%02d/%d", tm.tm_mday, tm.tm_mon+1, tm.tm_year + 1900);
strcpy(d.date, myDate);
int f=0;
system("cls");
printf("<== Add Doctor ==>\n\n");
fp = fopen("doctor.txt", "ab");
printf("Enter Doctor id: ");
scanf("%d", &d.id);
printf("Enter Doctor Name: ");
fflush(stdin);
gets(d.name);
printf("Enter Doctor Address: ");
fflush(stdin);
gets(d.address);
printf("Doctor Specialize in: ");
fflush(stdin);
gets(d.specialize);
printf("Doctor Added Successfully\n\n");
fwrite(&d, sizeof(d), 1, fp);
fclose(fp);
}
void doctorList(){
system("cls");
printf("<== Doctor List ==>\n\n");
printf("%-10s %-30s %-30s %-30s %s\n", "id", "Name", "Address", "Specialize","Date");
printf("-------------------------------------------------------------------------------------------------------------------\n");
fp = fopen("doctor.txt", "rb");
while(fread(&d, sizeof(d), 1, fp) == 1){
printf("%-10d %-30s %-30s %-30s %s\n", d.id, d.name, d.address, d.specialize, d.date);
}
fclose(fp);
}