-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdatePatientInfo.java
More file actions
175 lines (129 loc) · 4.52 KB
/
UpdatePatientInfo.java
File metadata and controls
175 lines (129 loc) · 4.52 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
package bootathonfinal;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import com.mysql.jdbc.Connection;
public class UpdatePatientInfo {
static int Checkup_id;
String [] tablets=new String[100];
int i =0;
UpdatePatientInfo(int Checkup_id){
this.Checkup_id=Checkup_id;
JFrame frame = ObjectFile.getFrame("Update patient info");
JLabel dis = new JLabel("Enter the diseases");
dis.setBounds(380, 100, 200, 30);
dis.setFont(new Font("Times New Roman", Font.BOLD,20));
frame.add(dis);
JTextField diseases = new JTextField();
diseases.setBounds(540, 100, 200, 40);
frame.add(diseases);
JLabel dru = new JLabel("Enter the drug");
dru.setBounds(380, 200, 200, 30);
dru.setFont(new Font("Times New Roman", Font.BOLD,20));
frame.add(dru);
try {
Connection con = (Connection) ObjectFile.getjdbc();
String query = "Select * from Tablet";
Statement stmt =con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next()) {
tablets[i++] = rs.getString("Tablet_name");
}
System.out.println(tablets);
con.close();
}catch(Exception e) {
System.out.println("The error found"+e);
}
JComboBox tablet = new JComboBox(tablets);
tablet.setBounds(540, 200, 200, 40);
Border border = new LineBorder(Color.BLACK, 0, false);
tablet.setBorder(border);
tablet.setBackground(Color.WHITE);
frame.add(tablet);
JLabel dose = new JLabel("Enter the dosage");
dose.setBounds(380, 300, 200, 30);
dose.setFont(new Font("Times New Roman", Font.BOLD,20));
frame.add(dose);
JTextField dosage = new JTextField();
dosage.setBounds(540, 300, 200, 40);
frame.add(dosage);
JButton addnewdiseases = ObjectFile.getButton("Add ");
addnewdiseases.setBounds(760, 100, 100, 30);
//addnewdiseases.setBackground(Color.WHITE);
frame.add(addnewdiseases);
JButton addnewdrug = ObjectFile.getButton("Add");
addnewdrug.setBounds(760, 200, 100, 30);
frame.add(addnewdrug);
JButton Update = ObjectFile.getButton("Update patient info");
Update.setBounds(460, 370, 300, 40);
frame.add(Update);
JPanel panel = ObjectFile.getpanel();
frame.add(panel);
addnewdiseases.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
diseases.setText("");
}
});
Update.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String diseases_info = diseases.getText().toLowerCase();
String drug_info = (String) tablet.getItemAt(tablet.getSelectedIndex());
String dosage_info = dosage.getText();
if(diseases.getText().isEmpty()!=true && drug_info.isEmpty()!=true&& dosage.getText().isEmpty()!=true ) {
int temp=0;
Connection con=(Connection) ObjectFile.getjdbc();
try {
Statement st=con.createStatement();
String Query="Select Tablet_id from Tablet where Tablet_name='"+drug_info+"'";
ResultSet rs=st.executeQuery(Query);
while(rs.next())
{
temp=rs.getInt("Tablet_id");
break;
}
con.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
update_patient(diseases_info,temp,dosage_info);
}
else {
JOptionPane.showMessageDialog(frame,"Please include all the fields");
}
}});
addnewdrug.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dosage.setText("");
}
});
}
public static void update_patient(String diseases , int drug , String dosage) {
Connection con=(Connection) ObjectFile.getjdbc();
String query="insert into Prescription (Checkup_id,Tablet_id,Disease,Dosage)values('"+Checkup_id+"',"+drug+",'"+diseases+"','"+dosage+"')";
try {
Statement st=con.createStatement();
int d=st.executeUpdate(query);
if(d==1)
{
System.out.println("Successfully done!");
JOptionPane.showMessageDialog(null,"Succesfully updated");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}