-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaffCreateController.java
More file actions
482 lines (431 loc) · 14.2 KB
/
StaffCreateController.java
File metadata and controls
482 lines (431 loc) · 14.2 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
package healthcareLook;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.ImageView;
/*
* The purpose of this window is to add new employees.
*/
public class StaffCreateController implements Initializable{
@FXML
TextField staffFirstName;
@FXML
TextField staffLastName;
@FXML
TextField staffSsn;
@FXML
TextField staffCity;
@FXML
TextField staffCounty;
@FXML
TextField staffPhone;
@FXML
TextField staffOfficeNumber;
@FXML
TextField staffSpeciality;
@FXML
TextField staffZip;
@FXML
TextField staffAddress;
@FXML
DatePicker staffDob;
@FXML
RadioButton staffMale;
@FXML
RadioButton staffFemale;
@FXML
RadioButton staffOther;
@FXML
Button staffClear;
@FXML
Button staffSave;
Tooltip stafftip;
@FXML
ImageView fWarning;
@FXML
ImageView lWarning;
@FXML
ImageView cityWarning;
@FXML
ImageView countyWarning;
@FXML
ImageView phoneWarning;
@FXML
ImageView officeWarning;
@FXML
ImageView addressWarning;
@FXML
ImageView zipWarning;
@FXML
ImageView dobWarning;
@FXML
ImageView positionWarning;
@FXML
ImageView genderWarning;
@FXML
ImageView ssnWarning;
@FXML
ImageView specialityWarning;
@FXML
ComboBox staffPosition;
boolean isSafeToSave = true;
boolean isDobError = false;
Alert confirmAlert = new Alert(AlertType.CONFIRMATION);
Optional<ButtonType> result;
Alert warnAlert = new Alert(AlertType.WARNING);
Employee newStaff;
RadioButton genderTransfer;
ToggleGroup genderToggle = new ToggleGroup();
String stringFirstName, stringLastName, stringSsn,stringCity,stringCounty,stringPhone,stringOfficeNumber,stringSpeciality,
stringZip,stringAddress,stringDob,stringGender, stringSalary,adminId;
public boolean getNonLetterCount(String s) {
Pattern p = Pattern.compile("[^A-Za-z]");
Matcher m = p.matcher(s);
boolean b = m.find();
return b;
}
//This check is for when I do not want letters or symbols.
public boolean getLetterCount(String s) {
Pattern p = Pattern.compile("[^0-9]");
Matcher m = p.matcher(s);
boolean b = m.find();
return b;
}
//This check is for when I do not want symbols.
public boolean getSymbolCount(String s) {
Pattern p = Pattern.compile("[^A-Za-z0-9]");
Matcher m = p.matcher(s);
boolean b = m.find();
return b;
}
//This is for Address, which can have spaces.
public boolean getAddressCount(String s) {
Pattern p = Pattern.compile("[^A-Za-z0-9 ]");
Matcher m = p.matcher(s);
boolean b = m.find();
return b;
}
/* this check is for making sure
* the data received is just numbers.
* If the person adds a letter it will
* throw a NumberFormatException which returns true
* and if the length of the string is not 9
* the try returns true. If everything is ok
* then the try returns false.
*/
//Change The Names.
public boolean ssnErrorCheck(String test3){
try{
int tester = Integer.parseInt(test3);
if(test3.length() == 9){
return false;
}
else{
return true;
}
}
catch(NumberFormatException ex){
return true;
}
}
/* this check is for numbers with 10+ values like phone
* numbers. Same as ssnErrorCheck.
*/
public boolean phoneErrorCheck(String test4){
try{
long tester = Long.parseLong(test4);
if(test4.length() == 10){
return false;
}
else{
return true;
}
}
catch(NumberFormatException ex){
return true;
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
staffPosition.getItems().addAll("Receptionist", "Nurse", "Doctor","Admin");
staffSave.setOnAction(e ->{
//this boolean is set to true since we would believe the data is OK to send.
isSafeToSave = true;
//the if/else statements check if the data really is ok to send. if there isnt then there will be warnings
//and the boolean will be set to false to prevent the data from saving.
if(staffFirstName.getText().trim().equals("")){
fWarning.setVisible(true);
stafftip.install(fWarning, new Tooltip("Please enter a first name."));
//This is in case the user wants to save the data
//I want to remind them again that the data could be loss so
//I reset the count to zero so it can start at 1 next time they click close
isSafeToSave = false;
}
else if(getNonLetterCount(staffFirstName.getText().trim().toString())){
fWarning.setVisible(true);
stafftip.install(fWarning, new Tooltip("No numbers or symbols."));
isSafeToSave = false;
}
else{
fWarning.setVisible(false);
}
if(staffLastName.getText().trim().equals("")){
lWarning.setVisible(true);
stafftip.install(lWarning, new Tooltip("Please enter a last name."));
//This is in case the user wants to save the data
//I want to remind them again that the data could be loss so
//I reset the count to zero so it can start at 1 next time they click close
isSafeToSave = false;
}
else if(getNonLetterCount(staffLastName.getText().trim().toString())){
lWarning.setVisible(true);
stafftip.install(lWarning, new Tooltip("No numbers or symbols."));
isSafeToSave = false;
}
else{
lWarning.setVisible(false);
}
if(staffSsn.getText().trim().equals("")){
ssnWarning.setVisible(true);
stafftip.install(ssnWarning, new Tooltip("Please enter SSN"));
isSafeToSave = false;
}
else if(getSymbolCount(staffSsn.getText().trim().toString())){
ssnWarning.setVisible(true);
stafftip.install(ssnWarning, new Tooltip("No symbols."));
isSafeToSave = false;
}
else if(ssnErrorCheck(staffSsn.getText().trim().toString())){
if (staffSsn.getText().trim().toString().length() != 9){
ssnWarning.setVisible(true);
stafftip.install(ssnWarning, new Tooltip("Must be 9 numbers(only) long."));
isSafeToSave = false;
}
else{
ssnWarning.setVisible(true);
stafftip.install(ssnWarning, new Tooltip("No letters."));
}
isSafeToSave = false;
}
else{
ssnWarning.setVisible(false);
}
if(staffAddress.getText().trim().equals("")){
addressWarning.setVisible(true);
stafftip.install(addressWarning, new Tooltip("Please enter address."));
isSafeToSave = false;
}
else if(getAddressCount(staffAddress.getText().trim().toString())){
addressWarning.setVisible(true);
stafftip.install(addressWarning, new Tooltip("No symbols."));
isSafeToSave = false;
}
else{
addressWarning.setVisible(false);
}
if(staffCity.getText().trim().equals("")){
cityWarning.setVisible(true);
stafftip.install(cityWarning, new Tooltip("Please enter city."));
isSafeToSave = false;
}
else if(getNonLetterCount(staffCity.getText().toString())){
cityWarning.setVisible(true);
stafftip.install(cityWarning, new Tooltip("No numbers or symbols."));
isSafeToSave = false;
}
else{
cityWarning.setVisible(false);
}
if(staffZip.getText().trim().equals("")){
zipWarning.setVisible(true);
stafftip.install(zipWarning, new Tooltip("Please enter zip code."));
isSafeToSave = false;
}
else if(getSymbolCount(staffZip.getText().toString())){
zipWarning.setVisible(true);
stafftip.install(zipWarning, new Tooltip("No symbols."));
isSafeToSave = false;
}
else{
zipWarning.setVisible(false);
}
if(staffCounty.getText().trim().equals("")){
countyWarning.setVisible(true);
stafftip.install(countyWarning, new Tooltip("Please enter county."));
isSafeToSave = false;
}
else if(getNonLetterCount(staffCounty.getText().toString())){
countyWarning.setVisible(true);
stafftip.install(countyWarning, new Tooltip("No numbers or symbols."));
isSafeToSave = false;
}
else{
countyWarning.setVisible(false);
}
if(staffPhone.getText().trim().equals("")){
phoneWarning.setVisible(true);
stafftip.install(phoneWarning, new Tooltip("Please enter a phone number"));
isSafeToSave = false;
}
else if(getSymbolCount(staffPhone.getText().trim().toString())){
phoneWarning.setVisible(true);
stafftip.install(phoneWarning, new Tooltip("No symbols."));
isSafeToSave = false;
}
else if(phoneErrorCheck(staffPhone.getText().trim().toString())){
phoneWarning.setVisible(true);
if (staffPhone.getText().trim().toString().length() != 10){
stafftip.install(phoneWarning, new Tooltip("10 numbers(only)."));
isSafeToSave = false;
}
else{
phoneWarning.setVisible(true);
stafftip.install(phoneWarning, new Tooltip("No letters."));
}
isSafeToSave = false;
}
else{
phoneWarning.setVisible(false);
}
isDobError=false;
try{
if(staffDob.getValue().equals("")){
}
}
catch(NullPointerException ex){
dobWarning.setVisible(true);
stafftip.install(dobWarning, new Tooltip("Please enter date of birth."));
isSafeToSave = false;
isDobError= true;
}
if(!isDobError){
dobWarning.setVisible(false);
}
if(!(staffMale.isSelected()||staffFemale.isSelected()||staffOther.isSelected())){
genderWarning.setVisible(true);
stafftip.install(genderWarning, new Tooltip("Please pick a gender."));
isSafeToSave = false;
}
else{
genderWarning.setVisible(false);
}
if(staffSpeciality.getText().trim().equals("")){
specialityWarning.setVisible(true);
stafftip.install(specialityWarning, new Tooltip("Please state your speciality."));
isSafeToSave = false;
}
else{
specialityWarning.setVisible(false);
}
if(staffPosition.getSelectionModel().isEmpty()){
positionWarning.setVisible(true);
stafftip.install(positionWarning, new Tooltip("Please state your position."));
isSafeToSave = false;
}
else{
positionWarning.setVisible(false);
}
//if the data was ok to send then they are all converted to strings and a salary is made.
if(isSafeToSave){
stringFirstName = staffFirstName.getText().trim();
stringLastName = staffLastName.getText().trim();
stringSsn = staffSsn.getText().trim();
stringCity = staffCity.getText().trim();
stringCounty = staffCounty.getText().trim();
stringPhone = staffPhone.getText().trim();
stringOfficeNumber = staffOfficeNumber.getText().trim();
stringSpeciality = staffSpeciality.getText().trim();
stringZip = staffZip.getText().trim();
stringAddress = staffAddress.getText().trim();
stringDob = staffDob.getValue().toString().trim();
genderTransfer = (RadioButton)genderToggle.getSelectedToggle();
stringGender = genderTransfer.getText();
stringSalary = Integer.toString((int)((Math.random()*600000)+ 600000));
//this creates a new employee type.
newStaff = new Employee(stringFirstName,stringLastName,stringSsn,stringAddress,stringCity,stringZip,stringCounty,
stringPhone,stringDob,stringGender,staffPosition.getSelectionModel().getSelectedItem().toString(),staffSpeciality.getText().trim(),stringSalary);
//This saves to the database.
boolean isSaved = DatabaseWork.SaveStaff(newStaff);
if(isSaved){
//If it was saved successfully then the id number was made. this displays after we retrieve it and
//is written on the staff members card. For us we would have to write it down or check the database.
String idNumber = DatabaseWork.RetrieveIDStaff(newStaff.getSsn());
confirmAlert.setTitle("Data Successfully Saved!");
confirmAlert.setHeaderText(idNumber);
confirmAlert.setContentText("Please write down and remember your id number.\nDo you wish to create another patient?");
ButtonType yes = new ButtonType("YES");
ButtonType no = new ButtonType("NO");
confirmAlert.getButtonTypes().setAll(yes, no);
result = confirmAlert.showAndWait();
//if there is no more staff to add then we move to the interaction window.
if(result.get() == no){
adminId = HealthStaffCreate.GetAdminId(adminId);
HealthLoginStaff.stageClose();
HealthStaffCreate.stageClose();
confirmAlert.close();
}
else{
//if there is more staff members to add then
//this will clear all the information so you can
//enter another staff member
staffFirstName.clear();
staffLastName.clear();
staffCity.clear();
staffSsn.clear();
staffAddress.clear();
staffZip.clear();
staffCounty.clear();
staffDob.setValue(null);
staffPhone.clear();
staffOfficeNumber.clear();
staffMale.setSelected(false);
staffFemale.setSelected(false);
staffOther.setSelected(false);
staffSpeciality.clear();
staffPosition.getSelectionModel().clearSelection();
confirmAlert.close();
}
}
else{
//IF the data was not saved this will appear.
warnAlert.setTitle("Error in saving data");
warnAlert.setHeaderText("Warning!");
warnAlert.setContentText("If you already have an account with us please log in");
warnAlert.showAndWait();
}
}
staffClear.setOnAction(f ->{
//This button clears all the textfields and date pickers. It also deselects the radio buttons.
staffFirstName.clear();
staffLastName.clear();
staffCity.clear();
staffSsn.clear();
staffAddress.clear();
staffZip.clear();
staffCounty.clear();
staffDob.setValue(null);
staffPhone.clear();
staffOfficeNumber.clear();
staffMale.setSelected(false);
staffFemale.setSelected(false);
staffOther.setSelected(false);
staffSpeciality.clear();
staffPosition.getSelectionModel().clearSelection();
});
});
}
}