-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatient.java
More file actions
418 lines (331 loc) · 15.2 KB
/
Patient.java
File metadata and controls
418 lines (331 loc) · 15.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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package teamprojectsavecare;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.sql.ResultSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author seanr
*/
public class Patient extends HospitalUser {
private String patientID;
private String pharmacyID;
private String patientAddress;
private String patientEircode;
private String patientPhoneNumber;
private String patientNationality;
private String patientRace;
private String patientDateOfBirth;
private String patientMaritalStatus;
private String patientSex;
private String patientEmergencyNumber;
private String patientNumber;
private String patientBloodType;
private String patientSmoker;
private String patientWeeklyActivity;
private String patientOccupation;
private String patientHospitalId;
private String patientSurgeryId;
public Patient(String patientID, String pharmacyID, String patientAddress, String patientEircode, String patientPhoneNumber, String patientNationality, String patientRace, String patientDateOfBirth, String patientMaritalStatus, String patientSex, String patientEmergencyNumber, String patientNumber, String patientBloodType, String patientSmoker, String patientWeeklyActivity, String patientOccupation, String patientHospitalId, String patientSurgeryId, String hospitalID, String surgeryID, String UserId, String userFirstName, String userLastName, String userPPSNumber, String userEmail, String userPassword, String userType) {
super(hospitalID, surgeryID, UserId, userFirstName, userLastName, userPPSNumber, userEmail, userPassword, userType);
this.patientID = patientID;
this.pharmacyID = pharmacyID;
this.patientAddress = patientAddress;
this.patientEircode = patientEircode;
this.patientPhoneNumber = patientPhoneNumber;
this.patientNationality = patientNationality;
this.patientRace = patientRace;
this.patientDateOfBirth = patientDateOfBirth;
this.patientMaritalStatus = patientMaritalStatus;
this.patientSex = patientSex;
this.patientEmergencyNumber = patientEmergencyNumber;
this.patientNumber = patientNumber;
this.patientBloodType = patientBloodType;
this.patientSmoker = patientSmoker;
this.patientWeeklyActivity = patientWeeklyActivity;
this.patientOccupation = patientOccupation;
this.patientHospitalId = patientHospitalId;
this.patientSurgeryId = patientSurgeryId;
}
public Patient() {
}
public String getPatientID() {
return patientID;
}
public void setPatientID(String patientID) {
this.patientID = patientID;
}
public String getPharmacyID() {
return pharmacyID;
}
public void setPharmacyID(String pharmacyID) {
this.pharmacyID = pharmacyID;
}
public String getPatientAddress() {
return patientAddress;
}
public void setPatientAddress(String patientAddress) {
this.patientAddress = patientAddress;
}
public String getPatientEircode() {
return patientEircode;
}
public void setPatientEircode(String patientEircode) {
this.patientEircode = patientEircode;
}
public String getPatientPhoneNumber() {
return patientPhoneNumber;
}
public void setPatientPhoneNumber(String patientPhoneNumber) {
this.patientPhoneNumber = patientPhoneNumber;
}
public String getPatientNationality() {
return patientNationality;
}
public void setPatientNationality(String patientNationality) {
this.patientNationality = patientNationality;
}
public String getPatientRace() {
return patientRace;
}
public void setPatientRace(String patientRace) {
this.patientRace = patientRace;
}
public String getPatientDateOfBirth() {
return patientDateOfBirth;
}
public void setPatientDateOfBirth(String patientDateOfBirth) {
this.patientDateOfBirth = patientDateOfBirth;
}
public String getPatientMaritalStatus() {
return patientMaritalStatus;
}
public void setPatientMaritalStatus(String patientMaritalStatus) {
this.patientMaritalStatus = patientMaritalStatus;
}
public String getPatientSex() {
return patientSex;
}
public void setPatientSex(String patientSex) {
this.patientSex = patientSex;
}
public String getPatientEmergencyNumber() {
return patientEmergencyNumber;
}
public void setPatientEmergencyNumber(String patientemergencyNumber) {
this.patientEmergencyNumber = patientemergencyNumber;
}
public String getPatientHospitalId() {
return patientHospitalId;
}
public void setPatientHospitalId(String patientHospitalId) {
this.patientHospitalId = patientHospitalId;
}
public String getPatientSurgeryId() {
return patientSurgeryId;
}
public void setPatientSurgeryId(String patientSurgeryId) {
this.patientSurgeryId = patientSurgeryId;
}
public String getPatientNumber() {
return patientNumber;
}
public void setPatientNumber(String patientNumber) {
this.patientNumber = patientNumber;
}
public String getPatientBloodType() {
return patientBloodType;
}
public void setPatientBloodType(String patientBloodType) {
this.patientBloodType = patientBloodType;
}
public String getPatientSmoker() {
return patientSmoker;
}
public void setPatientSmoker(String patientSmoker) {
this.patientSmoker = patientSmoker;
}
public String getPatientWeeklyActivity() {
return patientWeeklyActivity;
}
public void setPatientWeeklyActivity(String patientWeeklyActivity) {
this.patientWeeklyActivity = patientWeeklyActivity;
}
public String getPatientOccupation() {
return patientOccupation;
}
public void setPatientOccupation(String patientOccupation) {
this.patientOccupation = patientOccupation;
}
@Override
public String toString() {
return super.toString() + "Patient{" + "patientID=" + patientID + ", pharmacyID=" + pharmacyID + ", patientAddress=" + patientAddress + ", patientEircode=" + patientEircode + ", patientPhoneNumber=" + patientPhoneNumber + ", patientNationality=" + patientNationality + ", patientRace=" + patientRace + ", patientDateOfBirth=" + patientDateOfBirth + ", patientMaritalStatus=" + patientMaritalStatus + ", patientSex=" + patientSex + ", patientEmergencyNumber=" + patientEmergencyNumber + ", patientNumber=" + patientNumber + ", patientBloodType=" + patientBloodType + ", patientSmoker=" + patientSmoker + ", patientWeeklyActivity=" + patientWeeklyActivity + ", patientOccupation=" + patientOccupation + ", patientHospitalId=" + patientHospitalId + ", patientSurgeryId=" + patientSurgeryId + '}';
}
//This method is used to update a patients personal and lyfestyle information.
//the table column to be udated and the field to be updated are sent into the and injected into the sql query.
//We found this idea useful instead of seprerate queries.
public void changeData(String updateContent, String updateField) {
try {
Statement statement = myConn.createStatement();
statement.execute("Update Patient"
+ " SET Patient" + updateField + "='" + updateContent + "'"
+ " WHERE " + "" + "PatientEmail='" + userEmail + "';");
//after the database is updated then the object variable must be updateed.
setPatientVariable(updateField, updateContent);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e); //error from try
}//end try catch
}
//this method updates the patient objects field
public void setPatientVariable(String updateField, String updateContent) {
if (updateField.matches("Password")) {
userPassword = updateContent;
}
if (updateField.matches("Sex")) {
patientSex = updateContent;
}
if (updateField.matches("Address")) {
patientAddress = updateContent;
}
if (updateField.matches("PhoneNumber")) {
patientPhoneNumber = updateContent;
}
if (updateField.matches("MaritalStatus")) {
patientMaritalStatus = updateContent;
}
}
//This methd validates that the mariatal status inserted matches of of the if statement parameters
public boolean validateMaritalStatus(String maritalStatus) {
if (maritalStatus.equals("Single") || maritalStatus.equals("Married") || maritalStatus.equals("Seperated") || maritalStatus.equals("Divorced")) {
return true;
}
return false;
}
//This method generates a qr code from the patients email and returns it from the method
public ImageIcon generateQR() {
try {
//The link to this code is below
//https://www.geeksforgeeks.org/how-to-generate-and-read-qr-code-with-java-using-zxing-library/
// The file path string represents a file path the qrcode will be stored
String filepath = "qr.png";
//the charset string represents the character encoding for the qr code encoding
String charset = "UTF-8";
//Map stores hints for the QR code generation process
//We are unsure of how this occurs but it was a nessesarry step for the qrcode generation to occur
Map<EncodeHintType, ErrorCorrectionLevel> hintMap = new HashMap<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
//The bitmatrix is a zxing class that represents a matrix of bits which represents the qrcode
BitMatrix matrix = new MultiFormatWriter().encode(
new String(userEmail.getBytes(charset), charset),
BarcodeFormat.QR_CODE, 500, 500, hintMap);
// this method is used to store the qrcode in the specified format and stores it in the file location
MatrixToImageWriter.writeToFile(matrix, filepath.substring(filepath.lastIndexOf('.') + 1), new File(filepath));
//The ImageIcon is used to load the qr code into
//the icn is then returned from the method
ImageIcon icon = new ImageIcon("qr.png");
return icon;
} catch (Exception e) {
System.out.println(e);
}
return null;
}
public String returnPatientFullName() {
return getUserFirstName() + " " + getUserLastName();
}
public Patient connectToDisplay(Patient patient) {
try {
// here sakila is database name, root is username and password.... password is
// set as a variable above.Patient p = new Patient();
Statement stmt = myConn.createStatement();
ResultSet rs = stmt.executeQuery(
"select * from Patient where PatientEmail='"
+ patient.getUserEmail() + "';");
// while loop to iterate through all records of customer table and display them
// in the text field
while (rs.next()) {
patient.setPatientID(rs.getString(1));
patient.setPatientHospitalId(rs.getString(2));
patient.setPharmacyID(rs.getString(3));
patient.setPatientSurgeryId(rs.getString(4));
patient.setUserPPSNumber(rs.getString(5));
patient.setUserFirstName(rs.getString(6));
patient.setUserLastName(rs.getString(7));
patient.setUserEmail(rs.getString(8));
patient.setUserPassword(rs.getString(9));
patient.setPatientAddress(rs.getString(10));
patient.setPatientEircode(rs.getString(11));
patient.setPatientPhoneNumber(rs.getString(12));
patient.setPatientNationality(rs.getString(13));
patient.setPatientRace(rs.getString(14));
patient.setPatientDateOfBirth(rs.getString(15));
patient.setPatientMaritalStatus(rs.getString(16));
patient.setPatientSex(rs.getString(17));
patient.setPatientEmergencyNumber(rs.getString(18));
patient.setPatientNumber(rs.getString(19));
patient.setPatientBloodType(rs.getString(20));
patient.setPatientSmoker(rs.getString(21));
patient.setPatientWeeklyActivity(rs.getString(22));
patient.setPatientOccupation(rs.getString(23));
System.out.println(rs.getString(15));
}
return patient;
} catch (SQLException ex) {
System.out.println(ex);
} catch (Exception ex) {
System.out.println(ex);
}
return patient;
}
public boolean validateEmergencyNumber(String emergencyNumber) {
if (!emergencyNumber.matches("^(?:\\+353|0)8[35679]\\d{7}$")) {
return false;
}
return true;
}
public boolean validateBloodType(String bloodType) {
String[] validBloodTypes = {"A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"};
for (String validType : validBloodTypes) {
if (bloodType.equalsIgnoreCase(validType)) {
return true;
}
}
return false;
}
public boolean validateSmoke(String Smoker) {
String regex = "^(?i)(never|(current|former)\\s+\\d+\\s*.*)$";
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(Smoker);
return matcher.matches();
}
public boolean validateWeeklyActivity(String weeklyActivity) {
String regex = "^(?i)(sedentary|light|moderate|vigorous)\\s?\\d+.*$";
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(weeklyActivity);
return matcher.matches();
}
public boolean validateOccupation(String occupation) {
if (!occupation.matches("^[a-zA-Z\\s]+$")) {
return false;
}
return true;
}
}