Repository navigation
Expand file tree
/
Copy pathInvoiceTreatmentController.java
More file actions
74 lines (59 loc) · 2.46 KB
/
Copy pathInvoiceTreatmentController.java
File metadata and controls
74 lines (59 loc) · 2.46 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
package controller;
import entity.Insurance;
import java.sql.*;
public class InsuranceController {
private static InsuranceController instance;
private InsuranceController() {}
public static InsuranceController getInstance() {
if (instance == null)
instance = new InsuranceController();
return instance;
}
public Insurance getInsuranceByPatientID(int patientID) {
String sql = "SELECT * FROM TblInsuranceDetails WHERE patientID = ?";
try (Connection conn = DataBaseManager.connect();
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, patientID);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return new Insurance(
rs.getInt("insuranceID"),
rs.getString("providerName"),
rs.getString("PolicyNumber"),
rs.getInt("patientID")
);
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return new Insurance(0, "Unknown", "", patientID);
}
public String getDetails(int patientID) {
return getInsuranceDetailsByPatientID(patientID);
}
public String getProviderByPatient(int patientID) {
return getInsuranceByPatientID(patientID).getProviderName();
}
public String getInsuranceDetailsByPatientID(int patientID) {
String result = "Provider: Unknown\nPolicy: Not Assigned";
String sql = "SELECT providerName, PolicyNumber FROM TblInsuranceDetails WHERE patientID = ?";
try (Connection conn = DataBaseManager.getConnection();
PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, patientID);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
String provider = rs.getString("providerName");
String policy = rs.getString("PolicyNumber");
result = String.format(
"Provider: %s\nPolicy: %s",
(provider != null && !provider.isEmpty()) ? provider : "Unknown",
(policy != null && !policy.isEmpty()) ? policy : "Not Assigned"
);
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}