-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatient.java
More file actions
215 lines (174 loc) · 7.33 KB
/
Patient.java
File metadata and controls
215 lines (174 loc) · 7.33 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
import java.sql.*;
import java.util.*;
public class Patient {
public static Scanner scan = new Scanner(System.in);
public static Connection con;
public static int patientMenu(Connection conIn){
con = conIn;
int exit =0 ;
while(exit < 1){
System.out.println("\n\n*********************************");
System.out.print("Patient Menu:\nselect one of the following" +
"\n1: Add Patient\n" +
"2: Get Patient Info\n" +
"9: return home page \n" +
"*********************************\n\n" +
"Enter: ");
Scanner scan = new Scanner(System.in);
int menu = scan.nextInt();
switch (menu) {
case 1: {
Patient.newPatient(con);
break;
}
case 2: {
Patient.getPatient(con);
break;
}
case 3: {
break;
}
case 4: {
break;
}
case 5: {
break;
}
case 9: {
exit = 1;
return 1;
}
}
} //emd while
return 0;
}
/* ========================================================================
* newPatient()
* adds to patient to patient table
* table auto increments pid and assigns it to new patient
* @param Connection
* ========================================================================*/
public static void newPatient(Connection con){
System.out.println("\n*********************************");
System.out.println("New Patient Entry: ");
System.out.println("*********************************");
try{
String tablename = "patient";
Scanner scan = new Scanner(System.in);
System.out.print("\nEnter Patient's \nFirst Name: ");
String fName = scan.next();
System.out.print("Last Name: ");
String lName = scan.next();
System.out.print("SSN: ");
String ssn = scan.next();
System.out.print("Emergency Contact Number: ");
String eContact = scan.next();
System.out.print("Policy Number: ");
String policyNum = scan.next();
PreparedStatement insert = con.prepareStatement("INSERT INTO " + tablename +
" (first,last,ssn,eContact,insurance) VALUES" +
" ( '" +fName +"'," +
"'" + lName +"'," +
"" + ssn +"," +
"" + eContact +"," +
"'" + policyNum +"');");
insert.executeUpdate();
insert.close();
}
catch(Exception e){
System.out.println("Error");
}
} // END NEW PATIENT
/* ========================================================================
* getPatient()
* allows you to search the unique indexes of the patient table.
* search patient by pid or ssn
* prints all patient info.
* @param Connection
* =======================================================================*/
public static void getPatient(Connection con) {
System.out.println("\n*********************************");
System.out.println("Search For Existing Patients");
System.out.println("*********************************\n");
String tableName = "patient";
try{
//list all unique idtenifiers in the patient table.
List<String> columns = TableMethods.getUniqueColumns(tableName,con);
System.out.println("How would you like to search?\n");
int i = 1;
for(String x : columns){
System.out.println("Select " + i + ": to search by " + x);
i++;
}
System.out.println("Enter all to display all");
System.out.print("\n\nENTER: ");
String columnNameS = scan.next();
if(columnNameS.equalsIgnoreCase("all")){ //will list every body
getAll(con);
}
else{
int columnNameI = Integer.parseInt(columnNameS)-1;
System.out.print("Enter in Patient's " + columns.get(columnNameI).toUpperCase() + ": ");
String search = scan.next();
Statement stmt =con.createStatement();
String query = "SELECT *" +
" FROM " + tableName +
" WHERE " + columns.get(columnNameI) + " = " + search + ";";
ResultSet rs = stmt.executeQuery(query);
//you should know what types of data that is being return.
//make in the future we can un hard code this.
i = 0;
while(rs.next()){
System.out.println("\n\n***********************************");
int pid = rs.getInt("pid");
String first = rs.getString("first");
String last = rs.getString("last");
String ssn = rs.getString("ssn");
String eContact = rs.getString("eContact");
String insurance = rs.getString("insurance");
//Display values
System.out.println("PID: " + pid);
System.out.println("First: " + first);
System.out.println("Last: " + last);
System.out.println("SSN: " + ssn);
System.out.println("Emergency Contact Number: " + eContact);
System.out.println("Policy Number: " + insurance);
System.out.println("***********************************\n\n");
++i;
}
if(i == 0){
System.out.println("\n\nUnable to find patient\n\n");
}
} //end else
} catch(Exception e){
System.out.println("Patient Not Found");
}
} //end get patient
/* ===============================================================
* Prints off all patients in the system
* ==============================================================*/
public static void getAll(Connection con) throws SQLException{
String[][] arr = TableMethods.selectAll("patient",con);
ArrayList<String> cNames = TableMethods.getAllColumnNames("patient",con);
int rows = arr.length;
int columns = arr[0].length;
System.out.println("*******************************");
System.out.println("All Patient Records");
for(int i = 0; i < rows ; i++){
System.out.print("\n");
for(int c = 0 ; c < columns ; c++) {
System.out.print(arr[i][c]);
System.out.print(", ");
}
}
} // end getALL
/*
* return column name types
*/
public static void columns(Connection con) throws SQLException{
String[] a = TableMethods.getColumnTypeNames("patient",con);
for(int i = 0; i < a.length ; i++){
System.out.println("" + a[i]);
}
}
}