-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatientPaymentWindowController.java
More file actions
320 lines (256 loc) · 9.72 KB
/
PatientPaymentWindowController.java
File metadata and controls
320 lines (256 loc) · 9.72 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
package healthcareLook;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.RadioButton;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
//Should appear if the person has a bill to pay.
public class PatientPaymentWindowController implements Initializable{
@FXML
Button submit;
@FXML
Button quit;
@FXML
RadioButton cash;
@FXML
RadioButton credit;
@FXML
ListView list;
@FXML
Label paymentTotal;
@FXML
TextField cardNumber;
@FXML
TextField cardName;
@FXML
TextField cvvcode;
@FXML
ComboBox month;
@FXML
ComboBox year;
@FXML
ComboBox cardType;
@FXML
Button cardSubmit;
@FXML
ImageView creditError;
Tooltip tip;
Connection conn;
Statement sqlState;
ResultSet rows;
Statement sqlState2;
ResultSet rows2;
Statement sqlState3;
ResultSet rows3;
Statement sqlState4;
ResultSet rows4;
ArrayList<String> appDate = new ArrayList<String>();
ArrayList<String> appTime = new ArrayList<String>();
ArrayList<String> appDia = new ArrayList<String>();
ArrayList<String> appPay = new ArrayList<String>();
ArrayList<String> listSelected = new ArrayList<String>();
@FXML
ToggleGroup toggle = new ToggleGroup();
Alert warnAlert = new Alert(AlertType.WARNING);
Alert dataAlert = new Alert(AlertType.INFORMATION);
String stringApp, stringTime, stringDia, stringPay, patID;
int convertor;
int totalAmount;
int listcount = 0;
int intPay;
int monthtest;
int yeartest;
boolean nextlist = false;
boolean isdone = true;
boolean isPaidFor;
Calendar cal = Calendar.getInstance();
//cash.setToggleGroup(toggle);
//credit.setToggleGroup(toggle);
@Override
public void initialize(URL location, ResourceBundle resources) {
//I set the toggle group for the radio buttons as well as retrieve the patient id.
// System.out.println("Beginning of payment window");
patID = PatientPaymentWindow.getID();
//I open a connection to the database.
try{
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost/healthcare_clinic?autoReconnect=true&useSSL=false","root", "CSC3610" );
sqlState = conn.createStatement();
// System.out.println(patID);
String command = "Select diagnosis, appointment_date, appointment_time, payment from payment_bill where patient_id = '" + patID + "' AND paid = 'N'";
// System.out.println("payment window inside!");
rows = sqlState.executeQuery(command);
// System.out.println("Please work!");
//while data was found
while(rows.next()){
//I wish to add the data into arraylists for each section.
// System.out.println("inside row loop!");
appDate.add(rows.getString(2));
appTime.add(rows.getString(3));
appDia.add(rows.getString(1));
appPay.add(rows.getString(4));
listcount++;
}
//I insert all of the dates and times into the Listview.
for(int i = 0; i < appDate.size();i++){
/* System.out.println(appDate);
System.out.println(appTime);
System.out.println(appDia);
System.out.println(appPay); */
list.getItems().add(appDate.get(i) + " @ " + appTime.get(i));
// System.out.println(list.getItems());
}
}
catch(SQLException ex){
System.out.println("SQLException : " +ex.getMessage());
System.out.println("VendorError : " +ex.getErrorCode());
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
//I set listview to mutliple selection mode
list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
/*
* WORK ON LATER IF YOU CAN.
*/
//When the listview is selected.
list.setOnMouseClicked(a->{
tip.install(list, new Tooltip("When the total selected goes from 2 to 1, please make sure you reselect "
+ "the one you want."));
listSelected.clear();
//Make a arraylist that will add the selected indices.
listSelected.addAll(list.getSelectionModel().getSelectedIndices());
// System.out.println(listSelected + "Before the if statement");
if(listSelected.size() == 1){
listSelected.clear();
listSelected.add(Integer.toString(list.getSelectionModel().getSelectedIndex()));
}
paymentTotal.setText("");
stringDia = "";
intPay =0;
// System.out.println(listSelected);
//This for loop is to add up the diagnosis that were selected as well
//as the costs of them all together.
for(int h=0; h< listSelected.size(); h++){
convertor = Integer.parseInt(String.valueOf((listSelected.get(h))));
try{
stringDia += appDia.get(convertor) + ", ";
intPay += Integer.parseInt(appPay.get(convertor));
}
catch(ArrayIndexOutOfBoundsException ax){
// System.out.println(convertor);
}
}
stringDia += "Cost: $" + intPay +".00";
paymentTotal.setText(stringDia);
});
//This checks of there was any items selected or not and throws a warning if there was none.
submit.setOnAction(b ->{
// System.out.println("Button pressed!");
if(list.getSelectionModel().getSelectedItems().isEmpty()){
warnAlert.setTitle("Error");
warnAlert.setHeaderText("There was a problem!");
warnAlert.setContentText("Please have one item in the list selected.\n If list is empty then please press skip button.");
warnAlert.showAndWait();
}
//If cash was selected the database will change saying you paid it.
else{
if(cash.isSelected()){
// System.out.println("cash selected pressed!");
//Change the data in the database to paid
String command;
for(int h=0; h< listSelected.size(); h++){
convertor = Integer.parseInt(String.valueOf((listSelected.get(h))));
try{
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost/healthcare_clinic?autoReconnect=true&useSSL=false","root", "CSC3610" );
sqlState = conn.createStatement();
command = "update payment_bill set paid = 'Y' where appointment_date = '" +appDate.get(convertor) +"' AND appointment_time = '" +appTime.get(convertor)+ "' AND diagnosis = '" +appDia.get(convertor)+"' AND patient_id = '" +patID+"'";
sqlState.executeUpdate(command);
//Auto update the list after the payment is done.
if(list.getSelectionModel().getSelectedIndices().size() == 1){
list.getItems().remove(list.getSelectionModel().getSelectedIndex());
}
else{
list.getItems().removeAll(list.getSelectionModel().getSelectedIndices());
}
dataAlert.setTitle("Successfully Paid");
dataAlert.setHeaderText("The transaction was successful.");
dataAlert.setContentText("Thank you for paying your bill.");
dataAlert.showAndWait();
}
catch(SQLException ex){
System.out.println("SQLException : " +ex.getMessage());
System.out.println("VendorError : " +ex.getErrorCode());
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
//else it will open a credit card input window and take your credit card information
else{
// System.out.println("CREDIT CARD SELECTED!!");
//This goes to the credit card window but will return a boolean if the person does enter the information or not.
isPaidFor = CreditCardWindow.start();
String command;
if(isPaidFor){
try{
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost/healthcare_clinic?autoReconnect=true&useSSL=false","root", "CSC3610" );
sqlState = conn.createStatement();
//This updates the bill table to 'Y' for the paid attribute.
command = "update payment_bill set paid = 'Y' where appointment_date = '" +appDate.get(convertor) +"' AND appointment_time = '" +appTime.get(convertor)+ "' AND diagnosis = '" +appDia.get(convertor)+"' AND patient_id = '" +patID+"'";
sqlState.executeUpdate(command);
//Auto update the list after the payment is done.
if(list.getSelectionModel().getSelectedIndices().size() == 1){
list.getItems().remove(list.getSelectionModel().getSelectedIndex());
}
else{
list.getItems().removeAll(list.getSelectionModel().getSelectedIndices());
}
dataAlert.setTitle("Successfully Paid");
dataAlert.setHeaderText("The transaction was successful.");
dataAlert.setContentText("Thank you for paying your bill.");
dataAlert.showAndWait();
}
catch(SQLException ex){
System.out.println("SQLException : " +ex.getMessage());
System.out.println("VendorError : " +ex.getErrorCode());
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
}
});
quit.setOnAction(o->{
//Takes the user to the main menu window
PatientPaymentWindow.stageClose();
});
}
}