-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaffDiagonsisWindowController.java
More file actions
239 lines (189 loc) · 9.31 KB
/
StaffDiagonsisWindowController.java
File metadata and controls
239 lines (189 loc) · 9.31 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
package healthcareLook;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
/*
* The purpose of this window is to allow the staff member to set diagnosis
* of the patients they saw that day.
* this also will create a bill for the patient to pay.
*/
public class StaffDiagonsisWindowController implements Initializable {
@FXML
Label complaintLabel;
@FXML
Label noteLabel;
@FXML
ListView patientView;
@FXML
ListView diagnosisView;
@FXML
Button confirmButton;
Alert dataAlert = new Alert(AlertType.INFORMATION);
Alert confirmAlert = new Alert(AlertType.CONFIRMATION);
Alert warnAlert = new Alert(AlertType.WARNING);
Optional<ButtonType> result;
Connection conn;
Statement sqlState;
Statement sqlState2;
Statement sqlState3;
Statement sqlState5;
PreparedStatement sqlState4;
String staffId, patId;
boolean isInPayment = false;
String patientCheck = "";
int indexSelected;
String cost;
int notUsed;
ArrayList<DiagnosisData> diaData = new ArrayList<DiagnosisData>();
ArrayList<Appointment> appData = new ArrayList<Appointment>();
ArrayList<Appointment> appDatacheck = new ArrayList<Appointment>();
ArrayList<String> patidData = new ArrayList<String>();
ArrayList<String> diadata = new ArrayList<String>();
@Override
public void initialize(URL location, ResourceBundle resources) {
//first we retrieve the id.
staffId = StaffDiagonsisWindow.RetrieveID(staffId);
ObservableList<String> patientList = FXCollections.observableArrayList();
ObservableList<String> diagnosisList = FXCollections.observableArrayList();
try{
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost/healthcare_clinic?autoReconnect=true&useSSL=false","root", "CSC3610" );
sqlState = conn.createStatement();
sqlState2 = conn.createStatement();
sqlState3 = conn.createStatement();
String command = "Select diagnosis, cost from diagnosis_chart ";
String command4 = "Select appointment_date, appointment_time, complaint, patient_id from appointment where requested_doctor = '" + staffId + "' and nurse_visit = 'Y' and doctor_visit is NULL";
String command5 ="Select appointment_date, appointment_time, complaint, patient_id from appointment where requested_doctor is NULL and nurse_visit = 'Y' and doctor_visit is NULL";
// System.out.println("We are before result set" + staffId);
ResultSet row01 = sqlState.executeQuery(command);
// System.out.println("We are after result set");
// gets the diagnosis from the diagnosis table
while(row01.next()){
diagnosisList.add(row01.getString(1));
// System.out.println("loop #1");
diaData.add(new DiagnosisData(row01.getString(1), row01.getString(2)));
// System.out.println(row01.getString(1) + " " + row01.getString(2));
}
ResultSet rows2 = sqlState2.executeQuery(command4);
while(rows2.next()){
patientView.getItems().add(rows2.getString(1) + " - " +rows2.getString(2) + " - " +rows2.getString(4) + " - " +rows2.getString(3));
}
ResultSet rows3 = sqlState3.executeQuery(command5);
while(rows3.next()){
patientView.getItems().add(rows3.getString(1) + " - " +rows3.getString(2) + " - " +rows3.getString(4) + " - " +rows3.getString(3));
}
}
catch(SQLException ex){
System.out.println("SQLException : " +ex.getMessage());
System.out.println("VendorError : " +ex.getErrorCode());
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
diagnosisView.setItems(diagnosisList);
//patientView.setItems(patientList);
diagnosisView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
//This will change the label to the complaint of the id number you have selected.
patientView.setOnMouseClicked(e->{
//This array will store the information from the selected index. I split it so I can retrieve the information I want.
String[] split = null;
indexSelected = patientView.getSelectionModel().getSelectedIndex();
split = patientView.getSelectionModel().getSelectedItem().toString().split(" - ");
//The complaint of the patient is on array index 3
complaintLabel.setText(split[3]);
try{
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost/healthcare_clinic?autoReconnect=true&useSSL=false","root", "CSC3610" );
Statement noteStatement = conn.createStatement();
String noteCommand = "Select height, weight, heart_rate, blood_pressure, medication from doctor_notes where appointment_date = '"+ split[0] + "' and appointment_time = '" + split[1] + "' and patient_id = '" + split[2] + "'";
ResultSet noteResult = noteStatement.executeQuery(noteCommand);
while(noteResult.next()){
noteLabel.setText("Height: " + noteResult.getString(1) + "\tWeight: " + noteResult.getString(2) + "\nHeart_Rate: " + noteResult.getString(3) + "\tBlood_pressure: " + noteResult.getString(4) + "\nMedication: " + noteResult.getString(5));
}
}catch(SQLException ex){
System.out.println("SQLException : " +ex.getMessage());
System.out.println("VendorError : " +ex.getErrorCode());
}
catch(ClassNotFoundException j){
j.printStackTrace();
}
});
//This will ask if the person wishes to add another diagnosis to the patient compliant. If so then it
//keeps the information in the list and add the diagnosis to the payment_bill table otherwise it will
//remove the id number (associated with the complaint) from the list and save to the payment_bill table.
confirmButton.setOnAction(g->{
//The same for changing the label is used here for this confirmation messagebox.
String[] split = null;
split = patientView.getSelectionModel().getSelectedItem().toString().split(" - ");
// System.out.println("Still working?");
confirmAlert.setTitle("Confirmation");
confirmAlert.setHeaderText("Is the following diagnosis correct?");
confirmAlert.setContentText("Complaint: " + split[3] + "\nDiagnosis: " + diagnosisView.getSelectionModel().getSelectedItems().toString());
result = confirmAlert.showAndWait();
//If It was the right diagnosis then it will go below
if(result.get() == ButtonType.OK){
diadata.addAll(diagnosisView.getSelectionModel().getSelectedItems());
try {
//This will select cost from the diagnosis chart this is needed so I can fill the payment_bill database.
String command4;
String command5;
String[] datetimeid = patientView.getSelectionModel().getSelectedItem().toString().split(" - ");
for(int i = 0; i < diadata.size(); i++){
sqlState5 = conn.createStatement();
command5 ="select cost from diagnosis_chart where diagnosis = '" + diadata.get(i) +"'";
ResultSet row5 = sqlState5.executeQuery(command5);
if(row5.next()){
cost = row5.getString(1);
}
//This is where I insert the new bill into the payment_bill table.
command4 = "insert into payment_bill(diagnosis, appointment_date, appointment_time, payment, patient_id, paid) values(?, ?, ?, ?, ?, ?)";
sqlState4 = conn.prepareStatement(command4);
sqlState4.setString(1, diadata.get(i));
sqlState4.setString(2, datetimeid[0]);
sqlState4.setString(3, datetimeid[1]);
sqlState4.setString(4, cost);
sqlState4.setString(5, datetimeid[2]);
sqlState4.setString(6, "N");
notUsed = sqlState4.executeUpdate();
//I make this a for loop because the person may have multiple diagnosis during one doctor visit.
}
//After the for loop I consider the doctor visit complete and update the appointment table tuple.
String command6 = "update appointment set doctor_visit = 'Y' where appointment_date = '" + datetimeid[0] + "' and appointment_time = '" + datetimeid[1] + "' and patient_id = '" + datetimeid[2] +"'";
sqlState5.executeUpdate(command6);
}
catch(SQLException ex){
System.out.println("SQLException : " +ex.getMessage());
System.out.println("VendorError : " +ex.getErrorCode());
}
//Now I delete the patient id from the listview to ensure that the id and complaint is never used again.
//This prevents a person from being charged twice for one diagnosis.
patientView.getItems().remove(patientView.getSelectionModel().getSelectedIndex());
dataAlert.setTitle("Doctor Visit Result");
dataAlert.setHeaderText("The Appointment is now completed and a bill has been processed");
dataAlert.showAndWait();
}
else{
confirmAlert.close();
}
});
}
}