-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWolfHospital.java
More file actions
1147 lines (1094 loc) · 61.5 KB
/
WolfHospital.java
File metadata and controls
1147 lines (1094 loc) · 61.5 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
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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.sql.*;
import java.util.*;
/**
* This class is the main class of the Wolf Hospital system. It allows users to enter, update, and delete
* staff and hospital information, check-in and check-out patients, reserve and release beds,
* and generate reports.
*
* @author Christopher Maynard
* @author Marshall Skelton
* @author Daniel Deans
* @author Caeman Toombs
*/
public class WolfHospital{
private static final String user = "";
private static final String password = "";
private static final String jdbcURL = "jdbc:mariadb://classdb2.csc.ncsu.edu:3306/" + user;
private static Scanner scanner = null;
/**
* Starting point of the project sets up many of the objects needed in the program and
* calls the functions that cause behvaior of the program
*/
public static void main(String[] args){
Connection connection = null;
Statement statement = null;
ResultSet result = null;
try {
Class.forName("org.mariadb.jdbc.Driver");
connection = DriverManager.getConnection(jdbcURL, user, password);
statement = connection.createStatement();
scanner = new Scanner(System.in);
setupTables(statement);
actions(statement, result);
} catch(Throwable oops) {
oops.printStackTrace();
}
if(scanner != null){
scanner.close();
}
close(result);
close(statement);
close(connection);
}
/**
* Closes the connection for the project
*
* @param conn The connection
*/
static void close(Connection conn) {
if(conn != null) {
try { conn.close(); } catch(Throwable whatever) {}
}
}
/**
* Closes the statement object for the project
*
* @param st The statement object
*/
static void close(Statement st) {
if(st != null) {
try { st.close(); } catch(Throwable whatever) {}
}
}
/**
* Closes the result set for the project
*
* @param rs The result set
*/
static void close(ResultSet rs) {
if(rs != null) {
try { rs.close(); } catch(Throwable whatever) {}
}
}
/**
* Sets up the tables in the database as well as the sequences for the database.
*
* @param statement Sends sql statements to the DBMS
* @throws SQLException
*/
private static void setupTables(Statement statement) throws SQLException{
statement.executeUpdate("CREATE TABLE IF NOT EXISTS staff (" +
"id INT AUTO_INCREMENT PRIMARY KEY, " +
"name VARCHAR(128) NOT NULL, " +
"age INT NOT NULL, " +
"gender VARCHAR(128) NOT NULL," +
"job_title VARCHAR(128) NOT NULL, " +
"professional_title VARCHAR(128) NOT NULL, " +
"dept VARCHAR(128) NOT NULL, " +
"contact_info VARCHAR(128) NOT NULL)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS doctor( " +
"staff_id INT PRIMARY KEY, " +
"specialist VARCHAR(128), " +
"CONSTRAINT doctor_fk FOREIGN KEY(staff_id) REFERENCES staff(id) " +
"ON DELETE CASCADE)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS nurse( " +
"staff_id INT PRIMARY KEY, " +
"CONSTRAINT nurse_fk FOREIGN KEY(staff_id) REFERENCES staff(id) " +
"ON DELETE CASCADE)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS operator( " +
"staff_id INT PRIMARY KEY, " +
"CONSTRAINT operator_fk FOREIGN KEY(staff_id) REFERENCES staff(id) " +
"ON DELETE CASCADE)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS patient( " +
"patient_id INT AUTO_INCREMENT PRIMARY KEY, " +
"status VARCHAR(128) NOT NULL, " +
"gender VARCHAR(128) NOT NULL, " +
"ssn INT, " +
"name VARCHAR(128) NOT NULL, " +
"DOB VARCHAR(128) NOT NULL, " +
"age INT NOT NULL, " +
"contact_info VARCHAR(128) NOT NULL)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS medical_record( " +
"record_num INT AUTO_INCREMENT PRIMARY KEY, " +
"res_doctor INT NOT NULL, " +
"diagnosis_details VARCHAR(128), " +
"prescription VARCHAR(128), " +
"CONSTRAINT doctor_medical_fk FOREIGN KEY(res_doctor) REFERENCES doctor(staff_id) " +
"ON DELETE CASCADE )");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS billing_account( " +
"billing_id INT AUTO_INCREMENT PRIMARY KEY, " +
"billing_addr VARCHAR(128) NOT NULL, " +
"payment_info VARCHAR(128) NOT NULL)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS ward( " +
"ward_num INT AUTO_INCREMENT PRIMARY KEY, " +
"charges_per_day INT NOT NULL, " +
"res_nurse INT NOT NULL, " +
"capacity INT NOT NULL, " +
"CONSTRAINT nurse_ward_fk FOREIGN KEY(res_nurse) REFERENCES nurse(staff_id) " +
"ON DELETE CASCADE)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS bed( " +
"bed_num INT AUTO_INCREMENT PRIMARY KEY, " +
"ward_num INT, " +
"patient_id INT, " +
"CONSTRAINT ward_bed_fk FOREIGN KEY(ward_num) REFERENCES ward(ward_num) " +
"ON DELETE CASCADE, " +
"CONSTRAINT patient_bed_fk FOREIGN KEY(patient_id) REFERENCES patient(patient_id) " +
"ON DELETE CASCADE)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS check_in_information( " +
"check_in_id INT AUTO_INCREMENT PRIMARY KEY, " +
"start_date DATE NOT NULL, " +
"end_date DATE, " +
"bed_num INT NOT NULL, " +
"ward_num INT NOT NULL, " +
"CONSTRAINT bed_check_fk FOREIGN KEY(bed_num) REFERENCES bed(bed_num) " +
"ON DELETE CASCADE, " +
"CONSTRAINT ward_check_fk FOREIGN KEY(ward_num) REFERENCES ward(ward_num) " +
"ON DELETE CASCADE)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS test( " +
"test_id INT AUTO_INCREMENT PRIMARY KEY, " +
"record_num INT NOT NULL, " +
"test_name VARCHAR(128) NOT NULL, " +
"specialist INT NOT NULL, " +
"patient_id INT NOT NULL, " +
"test_results VARCHAR(128) NOT NULL, " +
"CONSTRAINT specialist_test_fk FOREIGN KEY(specialist) REFERENCES doctor(staff_id) " +
"ON DELETE CASCADE, " +
"CONSTRAINT record_num_test_fk FOREIGN KEY(record_num) REFERENCES medical_record(record_num) " +
"ON DELETE CASCADE, " +
"CONSTRAINT patient_test_fk FOREIGN KEY(patient_id) REFERENCES patient(patient_id) " +
"ON DELETE CASCADE)");
statement.executeUpdate("CREATE TABLE IF NOT EXISTS office_visit( " +
"visit_num INT AUTO_INCREMENT PRIMARY KEY, " +
"record_num INT, " +
"billing_id INT, " +
"check_in_id INT, " +
"patient_id INT, " +
"CONSTRAINT record_num_ov_fk FOREIGN KEY(record_num) REFERENCES medical_record(record_num) " +
"ON DELETE CASCADE, " +
"CONSTRAINT billing_ov_fk FOREIGN KEY(billing_id) REFERENCES billing_account(billing_id) " +
"ON DELETE CASCADE, " +
"CONSTRAINT check_in_ov_fk FOREIGN KEY(check_in_id) REFERENCES check_in_information(check_in_id) " +
"ON DELETE CASCADE, " +
"CONSTRAINT patient_ov_fk FOREIGN KEY(patient_id) REFERENCES patient(patient_id) " +
"ON DELETE CASCADE)");
}
/**
* This method is responsible for a use's behavior. It will conintue to take requests
* from the operator until they decide to quit out. Users can enter, update, and delete
* staff and hospital information, check-in and check-out patients, reserve and release beds,
* and generate reports.
*
* @param statement Sends sql statements to the DBMS
* @param result Records the result of an SQL statement
*/
private static void actions(Statement statement, ResultSet result) throws SQLException{
System.out.println("Hello and Welcome to the Wolf Hospital System!");
//prompt user for commands
while(true){
System.out.println("Your actions are: \n<Enter> info about patients, staff, and wards." +
"\n<Update> info about patients, staff, and wards."+
"\n<Delete> info about patients, staff, and wards." +
"\n<Check-in> patients." +
"\n<Check-out> patients." +
"\n<Reserve> beds for patients." +
"\n<Release> reservations for beds for patients." +
"\nGenerate <reports>." +
"\n<Quit>.");
String action = scanner.nextLine();
//check commands for next steps
if(action.toLowerCase().equals("quit")){
return;
//entering new data
} else if(action.toLowerCase().equals("enter")){
System.out.println("Choices for entering info: Patient, Doctor, Nurse, Operator, Ward, or Bed.");
String type = scanner.nextLine();
//entering a new patient
if(type.toLowerCase().equals("patient")){
int social;
String status;
String gender;
String name;
String dob;
int age;
String contact;
try {
System.out.println("social security number: ");
social = scanner.nextInt();
scanner.nextLine();
System.out.println("status: ");
status = scanner.nextLine();
System.out.println("Gender");
gender = scanner.nextLine();
System.out.println("Name: ");
name = scanner.nextLine();
System.out.println("Date of Birth: ");
dob = scanner.nextLine();
System.out.println("Age:");
age = scanner.nextInt();
scanner.nextLine();
System.out.println("Contact Info: ");
contact = scanner.nextLine();
} catch (Exception e) {
System.out.println("Invalid input.");
break;
}
try {
statement.executeUpdate("INSERT INTO patient(status, gender, ssn, name, DOB, age, contact_info) VALUES ('" + status + "', '" + gender + "', '" + social + "', '" + name + "', '" + dob + "', '" + age + "', '" + contact + "')");
} catch (SQLException e) {
e.printStackTrace();
}
//entering a new doctor
} else if(type.toLowerCase().equals("doctor")){
String name;
int age;
String gender;
String job;
String professional;
String department;
String contact;
String specialist;
try {
System.out.println("Name: ");
name = scanner.nextLine();
System.out.println("Age: ");
age = scanner.nextInt();
scanner.nextLine();
System.out.println("gender: ");
gender = scanner.nextLine();
System.out.println("Job Title: ");
job = scanner.nextLine();
System.out.println("Professional Title: ");
professional = scanner.nextLine();
System.out.println("Department: ");
department = scanner.nextLine();
System.out.println("Contact Info: ");
contact = scanner.nextLine();
System.out.println("Specialist? (Yes/No): ");
specialist = scanner.nextLine();
} catch (Exception e) {
System.out.println("Invalid Input.");
break;
}
try {
statement.executeUpdate("START TRANSACTION;");
statement.executeUpdate("INSERT INTO staff(name ,age, gender, job_title, professional_title, dept, contact_info) VALUES ('" + name + "', '" + age + "', '"+ gender + "', '" + job + "', '" + professional + "', '" + department + "', '" + contact + "')");
result = statement.executeQuery("SELECT MAX(id) AS max_id FROM staff");
result.next();
int id = result.getInt("max_id");
statement.executeUpdate("INSERT INTO doctor(staff_id, specialist) VALUES ('" + id + "', '" + specialist + "')");
statement.executeUpdate("COMMIT;");
} catch (SQLException e) {
statement.executeUpdate("ROLLBACK;");
e.printStackTrace();
}
//enter a new nurse
} else if(type.toLowerCase().equals("nurse")){
String name;
int age;
String gender;
String job;
String professional;
String department;
String contact;
try {
System.out.println("Name: ");
name = scanner.nextLine();
System.out.println("Age: ");
age = scanner.nextInt();
scanner.nextLine();
System.out.println("gender: ");
gender = scanner.nextLine();
System.out.println("Job Title: ");
job = scanner.nextLine();
System.out.println("Professional Title: ");
professional = scanner.nextLine();
System.out.println("Department: ");
department = scanner.nextLine();
System.out.println("Contact Info: ");
contact = scanner.nextLine();
} catch (Exception e) {
System.out.println("invalid input.");
break;
}
try {
statement.executeUpdate("START TRANSACTION;");
statement.executeUpdate("INSERT INTO staff(name ,age, gender, job_title, professional_title, dept, contact_info) VALUES ('" + name + "', '" + age + "', '"+ gender + "', '" + job + "', '" + professional + "', '" + department + "', '" + contact + "')");
result = statement.executeQuery("SELECT MAX(id) AS max_id FROM staff");
result.next();
int id = result.getInt("max_id");
statement.executeUpdate("INSERT INTO nurse(staff_id) VALUES ( '" + id + "')");
statement.executeUpdate("COMMIT;");
} catch (SQLException e) {
statement.executeUpdate("ROLLBACK;");
e.printStackTrace();
}
//enter a new operator
} else if(type.toLowerCase().equals("operator")){
String name;
int age;
String gender;
String job;
String professional;
String department;
String contact;
try {
System.out.println("Name: ");
name = scanner.nextLine();
System.out.println("Age: ");
age = scanner.nextInt();
scanner.nextLine();
System.out.println("gender: ");
gender = scanner.nextLine();
System.out.println("Job Title: ");
job = scanner.nextLine();
System.out.println("Professional Title: ");
professional = scanner.nextLine();
System.out.println("Department: ");
department = scanner.nextLine();
System.out.println("Contact Info: ");
contact = scanner.nextLine();
} catch (Exception e) {
System.out.println("invalid input.");
break;
}
try {
statement.executeUpdate("INSERT INTO staff(name ,age, gender, job_title, professional_title, dept, contact_info) VALUES ('" + name + "', '" + age + "', '"+ gender + "', '" + job + "', '" + professional + "', '" + department + "', '" + contact + "')");
result = statement.executeQuery("SELECT MAX(id) AS max_id FROM staff");
result.next();
int id = result.getInt("max_id");
statement.executeUpdate("INSERT INTO operator(staff_id) VALUES ('" + id + "')");
} catch (SQLException e) {
e.printStackTrace();
}
//enter a new ward
} else if(type.toLowerCase().equals("ward")){
int charges;
int nurse;
int capacity;
try {
System.out.println("charges per day: ");
charges = scanner.nextInt();
scanner.nextLine();
System.out.println("responsible nurse: ");
nurse = scanner.nextInt();
scanner.nextLine();
System.out.println("capacity: ");
capacity = scanner.nextInt();
scanner.nextLine();
} catch (Exception e) {
System.out.println("Invalid input.");
break;
}
try {
statement.executeUpdate("INSERT INTO ward( charges_per_day, res_nurse, capacity) VALUES ('" + charges + "', '" + nurse + "', '" + capacity + "')");
} catch (SQLException e) {
e.printStackTrace();
}
//enter a new bed
} else if(type.toLowerCase().equals("bed")){
int ward;
int patient;
try {
System.out.println("Ward Numer: ");
ward = scanner.nextInt();
scanner.nextLine();
System.out.println("Patient ID:");
patient = scanner.nextInt();
scanner.nextLine();
} catch (Exception e) {
System.out.println("Invalid Input.");
break;
}
try {
statement.executeUpdate("INSERT INTO bed ( ward_num, patient_id) VALUES ('" + ward + "', '" + patient + "')");
} catch (SQLException e) {
e.printStackTrace();
}
} else {
System.out.println("Not a valid object to enter information about.");
continue;
}
//update option for updating existing information
} else if(action.toLowerCase().equals("update")){
System.out.println("Choices for updating info: Patient, Doctor, Nurse, Operator, Ward, or Bed.");
String type = scanner.nextLine();
//updating the patient information
if(type.toLowerCase().equals("patient")){
System.out.println("Patient ID for update: ");
int id = scanner.nextInt();
scanner.nextLine();
while (true) {
System.out.println("Options for patient update: quit, social, status, gender, name, dob, age, contact");
String option = scanner.nextLine();
if (option.toLowerCase().equals("social")) {
String social = scanner.nextLine();
try {
statement.executeUpdate("UPDATE patient SET ssn=" + social + " WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
}else if (option.toLowerCase().equals("status")) {
String status = scanner.nextLine();
try {
statement.executeUpdate("UPDATE patient SET status=" + status + " WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
}else if (option.toLowerCase().equals("gender")) {
String gender = scanner.nextLine();
try {
statement.executeUpdate("UPDATE patient SET gender=" + gender + " WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
}else if (option.toLowerCase().equals("name")) {
String name = scanner.nextLine();
try {
statement.executeUpdate("UPDATE patient SET name=" + name + " WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
}else if (option.toLowerCase().equals("dob")) {
String dob = scanner.nextLine();
try {
statement.executeUpdate("UPDATE patient SET DOB=" + dob + " WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
}else if (option.toLowerCase().equals("age")) {
int age = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE patient SET age=" + age + " WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
}else if (option.toLowerCase().equals("contact")) {
String contact = scanner.nextLine();
try {
statement.executeUpdate("UPDATE patient SET contact_info=" + contact + " WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
}else if (option.toLowerCase().equals("quit")) {
break;
} else {
System.out.println("Invalid Input. Try again");
}
}
//updating a doctors information
} else if(type.toLowerCase().equals("doctor")){
System.out.println("doctor/staff ID for update: ");
int id = scanner.nextInt();
scanner.nextLine();
while (true) {
System.out.println("Options for doctor/staff update: quit, name, age, job, professional, dept, contact, specialist");
String option = scanner.nextLine();
if (option.toLowerCase().equals("quit")) {
break;
} else if (option.toLowerCase().equals("name")) {
String name = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET name='" + name + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("age")) {
int age = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET age=" + age + " WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
}else if (option.toLowerCase().equals("gender")) {
String gender = scanner.nextLine();
try {
statement.executeUpdate("UPDATE doctor SET gender='" + gender + "' WHERE staff_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
} else if (option.toLowerCase().equals("job")) {
String job = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET job_title='" + job + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("professional")) {
String professional = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET professional_title='" + professional + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("dept")) {
String dept = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET dept='" + dept + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("contact")) {
String contact = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET contact_info='" + contact + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("specialist")) {
String specialist = scanner.nextLine();
try {
statement.executeUpdate("UPDATE doctor SET specialist='" + specialist + "' WHERE staff_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating doctor");
break;
}
} else {
System.out.println("Invalid Input.");
}
}
//updating nurse information
} else if(type.toLowerCase().equals("nurse")){
System.out.println("nurse/staff ID for update: ");
int id = scanner.nextInt();
scanner.nextLine();
while (true) {
System.out.println("Options for nurse/staff update: quit, name, age, job, professional, dept, contact");
String option = scanner.nextLine();
if (option.equals("quit")) {
break;
} else if (option.toLowerCase().equals("name")) {
String name = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET name='" + name + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println(e);
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("age")) {
int age = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET age=" + age + " WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
}else if (option.toLowerCase().equals("gender")) {
String gender = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET gender='" + gender + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
} else if (option.toLowerCase().equals("job")) {
String job = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET job_title='" + job + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("professional")) {
String professional = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET professional_title='" + professional + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("dept")) {
String dept = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET dept='" + dept + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("contact")) {
String contact = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET contact_info='" + contact + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else {
System.out.println("Invalid Input.");
}
}
//updating operator information
} else if(type.toLowerCase().equals("operator")){
System.out.println("Operator/staff ID for update: ");
int id = scanner.nextInt();
scanner.nextLine();
while (true) {
System.out.println("Options for Operator/staff update: quit, name, age, job, professional, dept, contact");
String option = scanner.nextLine();
if (option.toLowerCase().equals("quit")) {
break;
} else if (option.toLowerCase().equals("name")) {
String name = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET name='" + name + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("age")) {
int age = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET age=" + age + " WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
}else if (option.toLowerCase().equals("gender")) {
String gender = scanner.nextLine();
try {
statement.executeUpdate("UPDATE doctor SET gender='" + gender + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating patient");
break;
}
} else if (option.toLowerCase().equals("job")) {
String job = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET job_title='" + job + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("professional")) {
String professional = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET professional_title='" + professional + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("dept")) {
String dept = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET dept=" + dept + " WHERE staff_id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else if (option.toLowerCase().equals("contact")) {
String contact = scanner.nextLine();
try {
statement.executeUpdate("UPDATE staff SET contact_info='" + contact + "' WHERE id=" + id);
} catch (SQLException e) {
System.out.println("Error updating staff");
break;
}
} else {
System.out.println("Invalid Input.");
}
}
//updating ward information
} else if(type.toLowerCase().equals("ward")){
System.out.println("Ward number for update: ");
int ward = scanner.nextInt();
scanner.nextLine();
System.out.println("Options for ward update: quit, charges, responsible, capacity");
String option = scanner.nextLine();
if (option.equals("quit")) {
break;
} else if (option.toLowerCase().equals("charges")) {
int charges = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE ward SET charges_per_day=" + charges + " WHERE ward_num=" + ward);
} catch (SQLException e) {
System.out.println("Error updating ward");
break;
}
} else if (option.toLowerCase().equals("responsible")) {
int responsible = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE ward SET res_nurse=" + responsible + " WHERE ward_num=" + ward);
} catch (SQLException e) {
System.out.println("Error updating ward");
break;
}
} else if (option.toLowerCase().equals("capacity")) {
int capacity = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE ward SET capacity=" + capacity + " WHERE ward_num=" + ward);
} catch (SQLException e) {
System.out.println("Error updating ward");
break;
}
} else {
System.out.println("Invalid Input");
}
//updating bed information
} else if(type.toLowerCase().equals("bed")){
System.out.println("Bed number for update: ");
int bed = scanner.nextInt();
scanner.nextLine();
System.out.println("ward number for bed update:");
int ward = scanner.nextInt();
scanner.nextLine();
System.out.println("Options for bed update: quit, patient");
String option = scanner.nextLine();
if (option.toLowerCase().equals("quit")) {
break;
} else if (option.toLowerCase().equals("patient")) {
int patient = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE bed SET patient_id=" + patient + " WHERE bed_num=" + bed + "AND WHERE ward_num=" + ward);
} catch (SQLException e) {
System.out.println("Error updating ward");
break;
}
} else {
System.out.println("Invalid information for update");
}
} else {
System.out.println("Not a valid object to update information about.");
continue;
}
//delete data from the database
} else if(action.toLowerCase().equals("delete")){
System.out.println("Choices for deleting info: Patient, Doctor, Nurse, Operator, Ward, or Bed.");
String type = scanner.nextLine();
if(type.toLowerCase().equals("patient")){
System.out.println("Patient id for deletion:");
int id = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("DELETE FROM patient WHERE patient_id=" + id);
} catch (SQLException e) {
System.out.println("Error deleting patient.");
}
} else if(type.toLowerCase().equals("doctor")){
System.out.println("doctor id for deletion:");
int id = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("DELETE FROM doctor WHERE staff_id=" + id);
} catch (SQLException e) {
System.out.println("Error deleting doctor.");
}
} else if(type.toLowerCase().equals("nurse")){
System.out.println("nurse id for deletion:");
int id = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("DELETE FROM nurse WHERE staff_id=" + id);
} catch (SQLException e) {
System.out.println("Error deleting nurse.");
}
} else if(type.toLowerCase().equals("operator")){
System.out.println("operator id for deletion:");
int id = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("DELETE FROM operator WHERE operator_id=" + id);
} catch (SQLException e) {
System.out.println("Error deleting operator.");
}
} else if(type.toLowerCase().equals("ward")){
System.out.println("ward num for deletion:");
int id = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("DELETE FROM ward WHERE ward_num=" + id);
} catch (SQLException e) {
System.out.println("Error deleting ward.");
}
} else if(type.toLowerCase().equals("bed")){
System.out.println("bed id for deletion:");
int bedid = scanner.nextInt();
scanner.nextLine();
System.out.println("ward num for deletion of bed");
int wardid = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("DELETE FROM bed WHERE bed_num=" + bedid + "AND WHERE ward_num=" + wardid);
} catch (SQLException e) {
System.out.println("Error deleting bed.");
}
} else {
System.out.println("Not a valid object to delete.");
continue;
}
//check in for an office visit
} else if(action.toLowerCase().equals("check-in")){
System.out.println("Check-in Date (YYYY-MM-DD):");
String startdate = scanner.nextLine();
System.out.println("bed number:");
int bed = scanner.nextInt();
scanner.nextLine();
System.out.println("ward number:");
int ward= scanner.nextInt();
scanner.nextLine();
System.out.println("patient id number:");
int patient= scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("INSERT INTO check_in_information( start_date, end_date, bed_num, ward_num) VALUES ('" + startdate + "', NULL,'" + bed + "','" + ward + "')'");
result = statement.executeQuery("SELECT MAX(id) AS max_id FROM check_in_information");
result.next();
int id = result.getInt("max_id");
statement.executeUpdate("INSERT INTO office_visit(record_num, billing_id, check_in_id, patient_id) VALUES(NULL, NULL, " + id + ", " + patient + ")");
} catch (SQLException e) {
System.out.println("Error creating check_in");
}
//check out for an office visit
} else if(action.toLowerCase().equals("check-out")){
System.out.println("Office Visit ID:");
int id = scanner.nextInt();
scanner.nextLine();
System.out.println("Check-out date (YYYY-MM-DD): ");
String enddate = scanner.nextLine();
System.out.println("Medical Record Info");
System.out.println("Responsible Doctor ID:");
int doctor_id = scanner.nextInt();
scanner.nextLine();
System.out.println("Diagnosis Details:");
String diagnosis_details = scanner.nextLine();
System.out.println("Prescription: ");
String prescription = scanner.nextLine();
System.out.println("Billing Info");
System.out.println("Billing Address:");
String billing_addr = scanner.nextLine();
System.out.println("Payment Info:");
String payment_info = scanner.nextLine();
try {
result = statement.executeQuery("SELECT check_in_id FROM office_visit WHERE visit_num = " + id);
result.next();
int check_in_id = result.getInt("check_in_id");
statement.executeUpdate("UPDATE check_in_information SET end_date=" + enddate + " WHERE check_in_id=" + check_in_id);
statement.executeUpdate("INSERT INTO medical_record( res_doctor, diagnosis_details, prescription) VALUES ('" + doctor_id + "','" + diagnosis_details + "','" + prescription + "')'");
statement.executeUpdate("INSERT INTO billing_account( billing_addr, payment_info) VALUES ('" + billing_addr + "','" + payment_info + "')'");
result = statement.executeQuery("SELECT MAX(id) AS max_id FROM medical_record");
result.next();
int record_num = result.getInt("max_id");
result = statement.executeQuery("SELECT MAX(id) AS max_id FROM billing_account");
result.next();
int billing_id = result.getInt("max_id");
statement.executeUpdate("UPDATE office_visit SET record_num=" + record_num + ", billing_id = " + billing_id + " WHERE visit_num = " + id);
System.out.println("Was a test run? (Yes/No)");
String test = scanner.nextLine();
if(test.toLowerCase().startsWith("y")){
System.out.println("Test Name: ");
String test_name = scanner.nextLine();
System.out.println("Specialist:");
int specialist_id = scanner.nextInt();
scanner.nextLine();
System.out.println("Test Results:");
String test_results = scanner.nextLine();
result = statement.executeQuery("SELECT patient_id FROM office_visit WHERE vist_num = " + id);
result.next();
int patient_id = result.getInt("patient_id");
statement.executeUpdate("INSERT INTO test( record_num, test_name, specialist, patient_id, test_results) VALUES ('" + record_num + "','" + test_name + "','" + specialist_id +"','" + patient_id + "','" + test_results + "')'");
}
} catch (SQLException e) {
System.out.println("Error checking out");
}
//reserving a bed in a ward
} else if(action.toLowerCase().equals("reserve")){
System.out.println("Patient id for reserving bed:");
int patid = scanner.nextInt();
scanner.nextLine();
System.out.println("bed num for reservation:");
int bednum = scanner.nextInt();
scanner.nextLine();
System.out.println("ward num for reservation");
int wardnum = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE bed patient_id=" + patid + "WHERE bed_num =" + bednum + "AND WHERE ward_num=" + wardnum + "AND patient_id=NULL");
} catch (SQLException e) {
System.out.println("Error reserving bed.");
}
//releasing a patient from a ward
} else if(action.toLowerCase().equals("release")){
System.out.println("bed num for release:");
int bednum = scanner.nextInt();
scanner.nextLine();
System.out.println("ward num for release");
int wardnum = scanner.nextInt();
scanner.nextLine();
try {
statement.executeUpdate("UPDATE bed patient_id=NULL WHERE bed_num =" + bednum + "AND WHERE ward_num=" + wardnum);
} catch (SQLException e) {
System.out.println("Error releasing bed.");
}
//reports section
} else if(action.toLowerCase().equals("reports")){
System.out.println("What report? Patient <history>, <ward> status, patients per month<ppm>, ward-usage percentage<wup>, a <doctor>'s patients, <staff> info.");
String type = scanner.nextLine();
//reports the patients history
if(type.toLowerCase().equals("history")){
System.out.println("What is the patient's id?");
int id = scanner.nextInt();
scanner.nextLine();
System.out.println("Beginning Check-in Date (YYYY-MM-DD):");