-
Notifications
You must be signed in to change notification settings - Fork 2
/
Admin.java
597 lines (542 loc) · 19.6 KB
/
Admin.java
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
import java.util.*;
import java.sql.*;
public class Admin { //code starts
public static void main(String[] args) throws Exception {
String dburl="jdbc:mysql://localhost:3306/blood_bank_management_system";
String uname="root";
String password="swapan";
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(dburl,uname,password);
Scanner input=new Scanner(System.in);
System.out.println("Welcome to BLOOD BANK MANAGEMENT SYSTEM\n");
String ques1,ques2;
String field;
int enter;
do{ //first do
System.out.println("Are you faculty of the blood bank or a visitor? Press \n1. For Faculty \n2. For visitor");
ques1=input.next();
switch(ques1){
case "1":
do{
System.out.println("Enter whether you are an Administrator or a Receptionist?");
ques2=input.next();
switch(ques2){
case "Administrator":
System.out.println("Which dept do you work in? Internal or External?");
ques2=input.next();
switch(ques2){
case "Internal":
System.out.println("Choose one of the following options (Enter Choice No.): "
+ "\n1.Retrieve Blood bank Data"
+ "\n2. Retrieve Blood Inventory details"
+ "\n3.Manage Patient Requests"
+ "\n4.Manage Donor Applications");
ques2=input.next();
String query="";
switch(ques2){
case "1":
query="select * from Blood_bank, Administrator where blood_bank.blood_bank_id=Administrator.bank_id";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
ResultSetMetaData rsmd=rs.getMetaData();
int c=rsmd.getColumnCount();
int i=c;
while(c!=0){
c--;
System.out.format("%16s",rsmd.getColumnName(i-c));
}
System.out.println();
while(rs.next()){
c=i;
while(c!=0){
c--;
System.out.format("%16s",rs.getString(i-c));
}
System.out.println();
}
break;
case "2":
System.out.println("Enter whether you want to see "
+"\n 'All' blood types"
+"\n 'One' Blood Type"
+"\n 'Misc' for One or more blood types");
ques2=input.next();
switch(ques2){
case "All":
query="select * from Blood_bank bb, Administrator a, Blood b where bb.blood_bank_id=a.bank_id and bb.blood_bank_id=blood.bb_id ";
st = con.createStatement();
rs = st.executeQuery(query);
rsmd=rs.getMetaData();
c=rsmd.getColumnCount();
i=c;
while(c!=0){
c--;
System.out.format("%16s",rsmd.getColumnName(i-c));
}
System.out.println();
while(rs.next()){
c=i;
while(c!=0){
c--;
System.out.format("%16s",rs.getString(i-c));
}
System.out.println();
}
break;
case "One":
System.out.println("Enter Blood type");
String btype;
btype=input.next();
query="select * from blood_bank bb, Administrator a, Blood b where bb.Blood_bank-id=a.bank_id and bb.Blood_bank_id=b.bb_id and Blood_type=?";
do{
System.out.println("Enter Choice No. \n1. All Details \n2.Quantity \n3.Platelet Count\n4.Expiry Date");
ques2=input.next();
switch(ques2){
case "1":
query="select * from blood where blood_type=?";
break;
case "2":
query="select blood_units from blood where blood_type=?"; ////////check
System.out.println(btype + "has units ");
break;
case "3":
query="select Platelet_count from blood where blood_type=?";
System.out.println(btype + "has platelet count");
break;
case "4":
query="select Expiry Date from blood where lood_type=?";
break;
}
PreparedStatement st1 = con.prepareStatement(query);
st1.setString(1,btype);
ResultSet rs1 = st1.executeQuery();
ResultSetMetaData rsmd1=rs1.getMetaData();
int c1=rsmd1.getColumnCount();
int i1=c1;
while(c1!=0){
c1--;
System.out.format("%16s",rsmd1.getColumnName(i1-c1));
}
System.out.println();
while(rs1.next()){
c1=i1;
while(c1!=0){
c1--;
System.out.format("%16s",rs1.getString(i1-c1));
}
System.out.println();
}
System.out.println("\nDo you want to continue viewing information for blood type " + btype + "?(Yes/No)");
ques2=input.next();
}while(ques2.equals("Yes"));
break;
case "Misc":
System.out.println("Enter your query in MYSQL");
String temp=input.nextLine();
query=input.nextLine();
Statement st2 = con.createStatement();
ResultSet rs2 = st2.executeQuery(query);
ResultSetMetaData rsmd2=rs2.getMetaData();
int c2=rsmd2.getColumnCount();
int i2=c2;
while(c2!=0){
c2--;
System.out.format("%16s",rsmd2.getColumnName(i2-c2));
}
System.out.println();
while(rs2.next()){
c2=i2;
while(c2!=0){
c2--;
System.out.format("%16s",rs2.getString(i2-c2));
}
System.out.println();
}
break;
}
System.out.println("\nDo you want to continue viewing Blood Type information?(Yes/No)");
field=input.next();
}
///////////////////////////////
case "3":
System.out.println("Do you want to see "
+ "\n1.'All' Patient Records? "
+ "\n2. Approve Patient Request "
+ "\n3. Misc");
ques2=input.next();
switch(ques2){
do{
case "1":
query="select * from Recipient";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
ResultSetMetaData rsmd=rs.getMetaData();
int c=rsmd.getColumnCount();
int i=c;
while(c!=0){
c--;
System.out.format("%16s",rsmd.getColumnName(i-c));
}
System.out.println();
while(rs.next()){
c=i;
while(c!=0){
c--;
System.out.format("%16s",rs.getString(i-c));
}
System.out.println();
}
break;
case "2":
System.out.println("Enter the id of the patient you want to update requests of");
int id;
enter=input.nextInt();
query="update table Recipient set approved=TRUE where recipient_id=?";
String query2="update table blood set blood_units=blood_units-?";
/////////////////dooooooo
PreparedStatement st1 = con.prepareStatement(query);
st1.setInt(1,id);
ResultSet rs1 = st1.executeQuery();
ResultSetMetaData rsmd1=rs1.getMetaData();
int c1=rsmd1.getColumnCount();
int i1=c1;
while(c1!=0){
c1--;
System.out.format("%16s",rsmd1.getColumnName(i1-c1));
}
System.out.println();
while(rs1.next()){
c1=i1;
while(c1!=0){
c1--;
System.out.format("%16s",rs1.getString(i1-c1));
}
System.out.println();
}
break;
case "3":
System.out.println("Enter your query in MYSQL");
String temp=input.nextLine();
query=input.nextLine();
Statement st2 = con.createStatement();
ResultSet rs2 = st2.executeQuery(query);
ResultSetMetaData rsmd2=rs2.getMetaData();
int c2=rsmd2.getColumnCount();
int i2=c2;
while(c2!=0){
c2--;
System.out.format("%16s",rsmd2.getColumnName(i2-c2));
}
System.out.println();
while(rs2.next()){
c2=i2;
while(c2!=0){
c2--;
System.out.format("%16s",rs2.getString(i2-c2));
}
System.out.println();
}
break;
//some case
case "External":
System.out.println("Choose one of the following options (Enter Choice No.): "
+ "\n1.View Hospital list"
+ "\n2.Manage hospitals Request"
+ "\n3.Manage Blood Donation drive");
ques2=input.next();
switch(ques2){
case "1":
query="select * from Hospital";
st = con.createStatement();
rs = st.executeQuery(query);
rsmd=rs.getMetaData();
c=rsmd.getColumnCount();
i=c;
while(c!=0){
c--;
System.out.format("%16s",rsmd.getColumnName(i-c));
}
System.out.println();
while(rs.next()){
c=i;
while(c!=0){
c--;
System.out.format("%16s",rs.getString(i-c));
}
System.out.println();
}
break;
case "2":
System.out.println("Enter ID of the hospital you want to approve the request of");
enter=input.nextInt();
String query2;
query="update Hospital set status='1' where hospital_id=?";
query2="update Blood set units= blood_units-? where blood_type='unitS_requested";
st = con.createStatement();
rs = st.executeQuery(query);
rsmd=rs.getMetaData();
c=rsmd.getColumnCount();
i=c;
while(c!=0){
c--;
System.out.format("%16s",rsmd.getColumnName(i-c));
}
System.out.println();
while(rs.next()){
c=i;
while(c!=0){
c--;
System.out.format("%16s",rs.getString(i-c));
}
System.out.println();
}
break;
case "3":
System.out.println("Enter 1 to view the list of existing drives "
+ "\n 2 To create an event for blood "
+ "\n 3 To edit existing details");
ques2=input.next();
switch(ques2){
case "1":
query="select * from Blood_donation_drive";
st = con.createStatement();
rs = st.executeQuery(query);
rsmd=rs.getMetaData();
c=rsmd.getColumnCount();
i=c;
while(c!=0){
c--;
System.out.format("%16s",rsmd.getColumnName(i-c));
}
System.out.println();
while(rs.next()){
c=i;
while(c!=0){
c--;
System.out.format("%16s",rs.getString(i-c));
}
System.out.println();
}
break;
case "2":
do{
query2 = "insert into Blood_donation_drive values(?,?,?,?)";
PreparedStatement st4 = con.prepareStatement(query2);
System.out.println("Enter Location");
int temp1;
String temp2;
temp2=input.next();
st4.setString(1, temp2);
System.out.println("Enter Number of Donors registered yet");
temp1=input.nextInt();
st4.setInt(2, temp1);
System.out.println("Enter Date(YYYY-MM-DD) of blood donation drive ");
temp2=input.next();
st4.setString(3, temp2);
System.out.println("Enter Blood_bank_id of your bank");
temp1=input.nextInt();
st4.setInt(4, temp1);
int count2 = st4.executeUpdate();
if(count2==1)
System.out.println("Successful insertion");
System.out.println("\nDo you want to continue creating new drives?(Yes/No)");
field=input.next();
}while(field.equals("Yes"));
break;
case "3":
do{
System.out.println("Enter the id of the drive you want to edit details of ");
int id=input.nextInt();
System.out.println("Enter 1. to edit Location "
+ "\n2. to update registered number of donors"
+ "\n3. to change date");
enter=input.nextInt();
switch(enter){
case 1:
query2="update blood_donation_drive set location=?";
System.out.println("Enter new location");
PreparedStatement st5 = con.prepareStatement(query2);
String temp2=input.next();
st5.setString(1, temp2);
int count2 = st5.executeUpdate();
if(count2==1)
System.out.println("Successful updation");
break;
//////////// while loop lgana hai?
case 2:
query2="update blood_donation_drive set registered_donors=?";
System.out.println("Enter updated number of registered donors");
PreparedStatement st6 = con.prepareStatement(query2);
int temp1=input.nextInt();
st6.setInt(1, temp1);
int count1 = st6.executeUpdate();
if(count1==1)
System.out.println("Successful updation");
break;
case 3:
query=query2="update blood_donation_drive set registered_donors=?";
System.out.println("Enter Changed Date (YYYY-MM-DD)");
st6 = con.prepareStatement(query2);
temp2=input.next();
st6.setString(1, temp2);
count1 = st6.executeUpdate();
if(count1==1)
System.out.println("Successful updation");
break;
}System.out.println("Do you want to continue adding, viewing and deleting donation drives? ");
field=input.next();
}while(field.equals("Yes"));
break;
} // donation drives ka switch case ends ---- break lagana hai?
System.out.println("\nDo you want to continue viewing information?(Yes/No)");
field=input.next();
}while(field.equals("Yes"));
break;
case "Receptionist":
System.out.println("Enter your id");
int id=input.nextInt();
System.out.println("Enter"
+ "\n1. For viewing Patients' List"
+ "\n2. For viewing Donors' List"
+ "\n3. For registering Donors"
+ "\n4. For registering Recipients");
enter=input.nextInt();
do{
switch(enter){
case 1:
query="show view receptionist_donor";
break;
/////////// view wali cheez?
case 2:
query="show view receptionist_recipients";
break;
case 3:
do{
System.out.println("Enter the id of donor you want to register");
enter=input.nextInt();
query="update donor set registered_by=? where donor_id=?";
PreparedStatement st4 = con.prepareStatement(query);
st4.setInt(1, id);
st4.setInt(2, enter);
int count1 = st4.executeUpdate();
if(count1==1)
System.out.println("Successful updation");
System.out.println("Do you want to continuing registering donors?");
field=input.next();
} //// break yahan bhi?
while(field.equals("Yes"));
break;
case 4:
do{
System.out.println("Enter the id of recipient you want to register");
enter=input.nextInt();
query="update recipient set registered_by=? where recipient_id=?";
PreparedStatement st4 = con.prepareStatement(query);
st4.setInt(1, id);
st4.setInt(2, enter);
int count1 = st4.executeUpdate();
if(count1==1)
System.out.println("Successful updation");
System.out.println("Do you want to continuing registering recipients?");
field=input.next();
} //// break yahan bhi?
while(field.equals("Yes"));
break;
}System.out.println("Do you want to continuing working?");
field=input.next();
} while(field.equals("Yes"));
break; // switch for Reception ends here
case "2": // visitor
System.out.println("Enter whether you want to donate or recieive blood"
+"\n press D for Donor "
+"\n press R for Recipient");
ques2=input.next();
switch(ques2){
case "D":
System.out.println("Answer the following questions and submit valid proofs of the same:"+
"\n Q1. Is your weight above 47kg? ");
String a1=input.next();
System.out.println("Q2. Are you HIV positive or negative? Enter P or N");
String a2=input.next();
System.out.println("Q2. Is your blood devoid of hard-drugs/alchohol? ");
String a3=input.next();
if(a1.equals("Yes") && a2.equals("N") && a3.equals("Yes")){
String query1="insert into Visitor values(?,?,?,?)";
PreparedStatement st4 = con.prepareStatement(query1);
System.out.println("Enter Aadhar_id");
int temp1;
String temp2;
temp1=input.nextInt();
st4.setInt(1, temp1);
System.out.println("Enter Name");
temp2=input.next();
st4.setString(2, temp2);
System.out.println("Enter Location");
temp2=input.next();
st4.setString(3, temp2);
System.out.println("Enter Date of Birth(YYYY-MM-DD)");
temp2=input.next();
st4.setString(4, temp2);
int count2 = st4.executeUpdate();
///////////TRIGGGERRRRRRR
String query2="insert into Donor values(?,?)";
PreparedStatement st5 = con.prepareStatement(query2);
System.out.println("Enter Donor_id");
temp1=input.nextInt();
st5.setInt(1, temp1);
System.out.println("Enter Blood type you want to donate");
temp2=input.next();
st5.setString(2, temp2);
count2 += st5.executeUpdate();
if(count2==2)
System.out.println("Successful insertion");
}
else{
System.out.println("Sorry, you can't donate blood");
}
break;
case "R":
String query1="insert into Visitor values(?,?,?,?)";
PreparedStatement st4 = con.prepareStatement(query1);
System.out.println("Enter Aadhar_id");
int temp1;
String temp2;
temp1=input.nextInt();
st4.setInt(1, temp1);
System.out.println("Enter Name");
temp2=input.next();
st4.setString(2, temp2);
System.out.println("Enter Location");
temp2=input.next();
st4.setString(3, temp2);
System.out.println("Enter Date of Birth(YYYY-MM-DD)");
temp2=input.next();
st4.setString(4, temp2);
int count3 = st4.executeUpdate();
String query2="insert into Donor values(?,?,?)";
PreparedStatement st5 = con.prepareStatement(query2);
System.out.println("Enter Recipient_id");
temp1=input.nextInt();
st5.setInt(1, temp1);
System.out.println("Enter Blood type you want to recieve");
temp2=input.next();
st5.setString(2, temp2);
count3 += st5.executeUpdate();
if(count3==2){
System.out.println("Successful insertion");}
else{
System.out.println("Sorry, Please Try again");}
break;
}
}
}
}
}
System.out.println("Do you want to continue working in blood bank management system? Yes or No");
ques1=input.next();
}while(ques1.equals("Yes")); // first do ends
System.out.println("ThankYou!"); //main ka hi part
input.close();
con.close();
} //main ends
} // Code Ends