-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHospital_Database.java
More file actions
983 lines (664 loc) · 34.2 KB
/
Hospital_Database.java
File metadata and controls
983 lines (664 loc) · 34.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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
package hospital_database;
import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.*;
public class Hospital_Database extends JFrame implements ActionListener {
String docname;
appointmentframe af = new appointmentframe();
PatientFrame pf = new PatientFrame();
DoctorFrame df = new DoctorFrame();
doc_enter de;
JButton book = new JButton("BOOK AN APPOINTMENT");
JButton palog = new JButton(" PATIENT LOGIN ");
JButton doclog = new JButton(" DOCTOR LOGIN ");
Hospital_Database(){
JPanel f = new JPanel();
JPanel p1 = new JPanel();
p1.setBackground(Color.WHITE);
p1.setBounds(200, 200, 100, 400);
book.addActionListener(this);
book.setBounds(200, 200, 100, 50);
palog.addActionListener(this);
palog.setBounds(200, 280, 100, 50);
doclog.addActionListener(this);
doclog.setBounds(200, 360, 100, 50);
ImageIcon background=new ImageIcon("D:\\bk.jpeg"); //Change the location of Image
Image img=background.getImage();
Image temp=img.getScaledInstance(500,600,Image.SCALE_SMOOTH);
background=new ImageIcon(temp);
JLabel back=new JLabel(background);
back.setLayout(null);
back.setBounds(0,0,500,600);
f.add(back);
p1.add(book);
p1.add(palog);
p1.add(doclog);
this.add(back);
this.add(p1);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand() == "BOOK AN APPOINTMENT"){
af.setSize(400,300);
af.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
af.setLocationRelativeTo(null);
af.setVisible(true);
}
else if(e.getActionCommand() == " PATIENT LOGIN "){
pf.setSize(400, 400);
pf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pf.setLocationRelativeTo(null);
pf.setVisible(true);
}
else if(e.getActionCommand() == " DOCTOR LOGIN "){
df.setSize(300, 400);
df.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
df.setLocationRelativeTo(null);
df.setVisible(true);
}
}
public static void main(String[] args) {
Hospital_Database hd = new Hospital_Database();
hd.setSize(500, 600);
hd.setLocationRelativeTo(null);
hd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
hd.setVisible(true);
}
class appointmentframe extends JFrame implements ActionListener {
String[] b = {"MG Road", "Mugalraj Puram" ,"SeethaRam Puram" , "Patamata" };
String[] s = {"Cardiology" ,"ENT Specialist" ,"General Physician","Pediatrician" ,"Psychiatrist" };
JLabel name = new JLabel("Name :");
JTextField namef = new JTextField(20);
JLabel pno = new JLabel("Phone Number :");
JTextField pnof = new JTextField(20);
JLabel city = new JLabel("City :");
JTextField cityf = new JTextField(20);
JLabel branch = new JLabel("Branch :");
JComboBox branchb = new JComboBox(b);
JLabel spec = new JLabel("Specialization :");
JComboBox specb = new JComboBox(s);
JLabel date = new JLabel("Date :");
JTextField datef = new JTextField("yyyy-mm-dd");
JButton ok = new JButton("OK");
appointmentframe(){
JPanel p1 = new JPanel(); // creating a panel to add some components
GroupLayout layout = new GroupLayout(p1); //creating a group layout for the panel
p1.setLayout(layout); //setting the layout
layout.setAutoCreateGaps(true); //make sure to automatically fill gaps
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(name) .addComponent(pno) .addComponent(city)
.addComponent(branch) .addComponent(spec) .addComponent(date) )
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(namef) .addComponent(pnof) .addComponent(cityf)
.addComponent(branchb) .addComponent(specb) .addComponent(datef))
);
layout.setVerticalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(name) .addComponent(namef))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(pno) .addComponent(pnof))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(city) .addComponent(cityf))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(branch) .addComponent(branchb))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(spec) .addComponent(specb))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(date) .addComponent(datef))
);
ok.addActionListener(this);
JPanel p2 = new JPanel();
p2.add(ok);
JPanel p3 = new JPanel();
p3.add(p1);
p3.add(p2);
add(p3);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() == "OK"){
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
Statement st2 = con.createStatement();
Statement st3 = con.createStatement();
Statement st4 = con.createStatement();
String query1,query2,query3,query4;
String na = namef.getText();
BigInteger pho = new BigInteger(pnof.getText());
String cy = cityf.getText();
String da = datef.getText();
String br = branchb.getSelectedItem().toString() ;
String sp = String.valueOf(specb.getSelectedItem());
query2 = "insert into patient_new (p_n_name,pno,city,branch,specialization,appoint_date) values ( '"+na+"', "+ pho +", '" +cy+"', '"+br+"' ,'"+sp+"', '"+da+"' );";
st2.executeUpdate(query2);
query1 = "Select doc_name from doctor where branch =\"" + br +"\"and specialization= \"" + sp+"\";";
ResultSet rs = st1.executeQuery(query1);
String d1 = null ,d2 = null;
int i=0;
while(rs.next()){
if(i==0){
d1 = rs.getString(1);
i=1;
}
else
d2 = rs.getString(1);
}
String ds = JOptionPane.showInputDialog("Select your preffered doctor based on his/her timings. Enter 1 to select \"" +d1+ "\" timings - 9am to 1pm OR Enter 2 to select \""+d2+"\" timings - 5pm to 9pm" );
int dsi = Integer.parseInt(ds);
if(dsi ==1 ){
query3 = "Update patient_new SET ref_doc = \"" +d1+"\"where pno = "+ pho +";";
st3.executeUpdate(query3);
JOptionPane.showMessageDialog(null, "Your appointment with \"" + d1+ "\" is succesful :)) " );
af.setVisible(false);
}
else{
query3 = "Update patient_new SET ref_doc = \"" +d2+"\"where pno = "+ pho +";";
st3.executeUpdate(query3);
JOptionPane.showMessageDialog(null, "Your appointment with \"" + d2+ "\" is succesful :)) " );
af.setVisible(false);
}
rs.close();
st1.close();
st2.close();
st3.close();
con.close();
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
}
}
}
class PatientFrame extends JFrame implements ActionListener{
JLabel pname = new JLabel("Name :");
JTextField pnamef = new JTextField("Enter your name",20);
JLabel ppno = new JLabel("Phone Number :");
JTextField ppnof = new JTextField("Enter your phoneno.",20);
JButton plogin = new JButton("Login");
PatientFrame(){
plogin.addActionListener(this);
pname.setBackground(Color.white);
ImageIcon background=new ImageIcon("D:\\patient.jpg"); //Change the location of image
Image img=background.getImage();
Image temp=img.getScaledInstance(400,400,Image.SCALE_SMOOTH);
background=new ImageIcon(temp);
JLabel back=new JLabel(background);
back.setLayout(null);
back.setBounds(0,0,400,400);
JPanel p1 = new JPanel(); // creating a panel to add some components
GroupLayout layout = new GroupLayout(p1); //creating a group layout for the panel
p1.setLayout(layout); //setting the layout
layout.setAutoCreateGaps(true); //make sure to automatically fill gaps
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(pname) .addComponent(ppno))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(pnamef) .addComponent(ppnof))
);
layout.setVerticalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(pname) .addComponent(pnamef))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(ppno) .addComponent(ppnof))
);
JPanel p2 = new JPanel();
p2.add(plogin);
JPanel p3 = new JPanel();
p3.add(p1);
p3.add(p2);
this.add(back);
this.add(p3);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()== "Login"){
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
String query1;
BigInteger p = new BigInteger(ppnof.getText());
String pn = pnamef.getText();
query1 = "Select p_o_name from patient_old where pno = " + p + ";";
ResultSet rs = st1.executeQuery(query1);
System.out.println(pn);
if(rs.next()){
System.out.println(rs.getString(1));
if(rs.getString(1).equals(pn) ){
patientrecords pr = new patientrecords(pn,p);
pr.setSize(1000,800);
pr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pr.setVisible(true);
System.out.println("a");
}
}
else{
JOptionPane.showMessageDialog(null, "Enter Valid data");
}
rs.close();
st1.close();
con.close();
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
}
}
}
class patientrecords extends JFrame {
JLabel[] pr1,pr2,pr3,pr4,pr5,pr6,pr7,pr8;
JLabel pname1 = new JLabel("Patient Name");
JLabel pno1 = new JLabel("Contact Number");
JLabel medi = new JLabel("Medication");
JLabel ph = new JLabel("Previous Records");
JLabel sign = new JLabel("Signs and Symptoms");
JLabel dn = new JLabel("Doctor Name");
JLabel rdate = new JLabel("Record Date");
JLabel comp = new JLabel("Compliant");
int n;
int flag =0;
String query3;
patientrecords(String s , BigInteger pnum){
JLabel wel = new JLabel("WELCOME "+ s );
wel.setBounds(300, 10, 200, 50);
this.add(wel);
JLabel buf = new JLabel(";");
pname1.setBounds(5, 70,80 , 30);
this.add(pname1);
pno1.setBounds(95, 70, 120, 30);
this.add(pno1);
medi.setBounds(225, 70, 100, 30);
this.add(medi);
ph.setBounds(335, 70, 120, 30);
this.add(ph);
sign.setBounds(465, 70, 120, 30);
this.add(sign);
dn.setBounds(595, 70, 80, 30);
this.add(dn);
rdate.setBounds(695, 70, 120, 30);
this.add(rdate);
comp.setBounds(815, 70, 120, 30);
this.add(comp);
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
Statement st2 = con.createStatement();
Statement st3 = con.createStatement();
String query1,query2;
query2 = "Select * from patient_records where pname =\"" + s +"\" and pno = " + pnum + " ;" ;
query1 = "Select count(*) from patient_records where pname =\"" + s +"\" and pno = " + pnum + " ;" ;
System.out.println(docname);
ResultSet rs1 = st1.executeQuery(query1);
ResultSet rs2 = st2.executeQuery(query2);
if(rs1.next())
n = rs1.getInt(1);
System.out.println(n);
int y1 = 110;
pr1 = new JLabel[n];
pr2 = new JLabel[n];
pr3 = new JLabel[n];
pr4 = new JLabel[n];
pr5 = new JLabel[n];
pr6 = new JLabel[n];
pr7 = new JLabel[n];
pr8 = new JLabel[n];
int i=0;
while(rs2.next()){
pr1[i] = new JLabel(rs2.getString(1));
pr1[i].setBounds(5, y1, 80, 30);
this.add(pr1[i]);
pr2[i] = new JLabel(rs2.getString(2));
pr2[i].setBounds(95, y1, 120, 30);
this.add(pr2[i]);
pr3[i] = new JLabel(rs2.getString(3));
pr3[i].setBounds(225, y1, 100, 30);
this.add(pr3[i]);
pr4[i] = new JLabel(rs2.getString(4));
pr4[i].setBounds(335, y1, 120, 30);
this.add(pr4[i]);
pr5[i] = new JLabel(rs2.getString(5));
pr5[i].setBounds(465, y1, 120, 30);
this.add(pr5[i]);
pr6[i] = new JLabel(rs2.getString(6));
pr6[i].setBounds(595, y1, 80, 30);
this.add(pr6[i]);
pr7[i] = new JLabel(rs2.getString(7));
pr7[i].setBounds(695, y1, 120, 30);
this.add(pr7[i]);
pr8[i] = new JLabel(rs2.getString(8));
pr8[i].setBounds(815, y1, 120, 30);
this.add(pr8[i]);
i++;
y1=y1+40;
}
this.add(buf);
rs1.close();
rs2.close();
st1.close();
st2.close();
st3.close();
con.close();
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
}
}
class DoctorFrame extends JFrame implements ActionListener{
JLabel did = new JLabel("ID :");
JTextField didf = new JTextField("Enter your ID",20);
JButton dlogin = new JButton("Login");
DoctorFrame(){
dlogin.addActionListener(this);
ImageIcon background=new ImageIcon("D:\\Doctor.jpg");
Image img=background.getImage();
Image temp=img.getScaledInstance(300,400,Image.SCALE_SMOOTH);
background=new ImageIcon(temp);
JLabel back=new JLabel(background);
back.setLayout(null);
back.setBounds(0,0,300,400);
JPanel p1 = new JPanel(); // creating a panel to add some components
GroupLayout layout = new GroupLayout(p1); //creating a group layout for the panel
p1.setLayout(layout); //setting the layout
layout.setAutoCreateGaps(true); //make sure to automatically fill gaps
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(did) )
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(didf) )
);
layout.setVerticalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(did) .addComponent(didf))
);
JPanel p2 = new JPanel();
p2.add(dlogin);
JPanel p3 = new JPanel();
p3.add(p1);
p3.add(p2);
this.add(back);
add(p3);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()== "Login"){
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
String query1;
int id = Integer.parseInt(didf.getText());
query1 = "Select doc_name from doctor where id = " + id + ";";
ResultSet rs = st1.executeQuery(query1);
if(rs.next()==true){
docname = rs.getString(1);
docsel ds = new docsel();
ds.setSize(500,600);
ds.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ds.setLocationRelativeTo(null);
ds.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "Please enter correct id");
}
rs.close();
st1.close();
con.close();
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
}
}
}
class docsel extends JFrame implements ActionListener{
JButton[] but , butc ;
JLabel[] pna,pdat;
JLabel pname1 = new JLabel("Patient Name");
JLabel buf = new JLabel(";");
int n;
int flag =0;
String query3;
JPanel p1 = new JPanel();
docsel(){
p1.setLayout(null);
pname1.setSize(100, 15);
pname1.setLocation(20 ,05 );
p1.add(pname1);
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
Statement st2 = con.createStatement();
Statement st3 = con.createStatement();
String query1,query2,query3;
query3 = "Select appoint_date from patient_new where ref_doc =\"" + docname +"\"; ";
query2 = "Select p_n_name from patient_new where ref_doc =\"" + docname +"\";" ;
query1 = "Select count(*) from patient_new where ref_doc =\"" + docname +"\";";
System.out.println(docname);
ResultSet rs1 = st1.executeQuery(query1);
ResultSet rs2 = st2.executeQuery(query2);
ResultSet rs3 = st3.executeQuery(query3);
if(rs1.next())
n = rs1.getInt(1);
System.out.println(n);
if(n==0){
JLabel na = new JLabel("NO APPOINTMENTS");
na.setBounds(150, 100, 120, 30);
this.add(na);
}
JLabel we =new JLabel("Welcome DR. "+docname);
we.setBounds(120, 10, 200, 30);
this.add(we);
JLabel nae = new JLabel("NAME");
nae.setBounds(10, 50, 90, 30);
this.add(nae);
JLabel tr = new JLabel("TREATMENT");
tr.setBounds(120, 50, 120, 30);
this.add(tr);
JLabel da = new JLabel("DATE");
da.setBounds(300, 50, 120, 30);
this.add(da);
int y1 = 100;
JPanel p1 = new JPanel();
but = new JButton[n];
butc = new JButton[n];
pna = new JLabel[n];
pdat = new JLabel[n];
int i=0;
while(rs2.next()){
if( rs3.next())
{
pdat[i] = new JLabel(rs3.getString(1));
System.out.println(rs3.getString(1));
pdat[i].setBounds(300, y1, 120, 30);
this.add(pdat[i]);
}
String pname = rs2.getString(1);
but[i] = new JButton("OK");
but[i].setBounds(120, y1, 60, 30);
but[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e ){
enter(pname);
de = new doc_enter(pname);
de.setSize(500,500);
de.setLocationRelativeTo(null);
de.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
de.setVisible(true);
}
});
this.add(but[i]);
butc[i] = new JButton("cancel");
butc[i].setBounds(200, y1, 80, 30);
butc[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e ){
System.out.println("a");
flag = delete(5,pname);
if(flag==1){
JOptionPane.showMessageDialog(null, "Successfully deleted");
}
}
});
this.add(butc[i]);
pna[i] = new JLabel(rs2.getString(1));
System.out.println(rs2.getString(1));
pna[i].setBounds(10, y1, 90, 30);
this.add(pna[i]);
i++;
y1=y1+30;
}
this.add(buf);
rs1.close();
rs2.close();
st1.close();
st2.close();
st3.close();
con.close();
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
}
public int delete(int f,String s){
int j=0;
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
String query = "Delete from patient_new where p_n_name =\""+s+"\";";
st1.executeUpdate(query);
j =1;
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
return j;
}
public void enter(String s){
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
Statement st2 = con.createStatement();
Statement st3 = con.createStatement();
String query2 = "Delete from patient_new where p_n_name =\""+s+"\";";
String query = "insert into patient_old select * from patient_new where p_n_name =\""+s+"\";";
String query3 = "Select p_o_name from patient_old where p_o_name =\""+s+"\"; ";
ResultSet rs = st3.executeQuery(query3);
rs.next();
st1.executeUpdate(query);
st2.executeUpdate(query2);
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
}
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class doc_enter extends JFrame implements ActionListener{
JLabel med = new JLabel("Medication :");
JTextField medf = new JTextField();
JLabel p_his = new JLabel("Previous Medical History :");
JTextField p_hisf = new JTextField();
JLabel ss = new JLabel("Signs and Symptoms :");
JTextField ssf = new JTextField();
JLabel com = new JLabel("Compliant :");
JTextField comf = new JTextField();
JLabel dat = new JLabel("Date");
JTextField datf = new JTextField("yyyy-mm-dd");
JButton ok1 = new JButton("OK");
String patient;
doc_enter(String p){
patient = p;
JPanel p1 = new JPanel(); // creating a panel to add some components
GroupLayout layout = new GroupLayout(p1); //creating a group layout for the panel
p1.setLayout(layout); //setting the layout
layout.setAutoCreateGaps(true); //make sure to automatically fill gaps
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(med) .addComponent(p_his) .addComponent(ss)
.addComponent(com) .addComponent(dat) )
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(medf) .addComponent(p_hisf) .addComponent(ssf)
.addComponent(comf) .addComponent(datf) )
);
layout.setVerticalGroup( // grouping the components horizontally
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(med) .addComponent(medf))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(p_his) .addComponent(p_hisf))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(ss) .addComponent(ssf))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(com) .addComponent(comf))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(dat) .addComponent(datf))
);
ok1.addActionListener(this);
JPanel p2 = new JPanel();
p2.add(ok1);
JPanel p3 = new JPanel();
p3.add(p1);
p3.add(p2);
add(p3);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand() == "OK"){
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hos_database", "root" , "pratap");
Statement st1 = con.createStatement();
Statement st2 = con.createStatement();
String query2,query1;
query1 = "Select pno from patient_old where p_o_name = \"" +patient+"\"and ref_doc =\""+ docname+"\" ;";
ResultSet rs = st1.executeQuery(query1);
rs.next();
BigDecimal pno = rs.getBigDecimal(1);
String me = medf.getText();
String ph = p_hisf.getText();
String s = ssf.getText();
String d = datf.getText();
String c = comf.getText();
query2 = "insert into patient_records values ( '"+patient+"', " +pno + ", '"+ me +"', '" +ph+"', '"+s+"' , '"+docname+"' , '"+d+"' ,'"+c+"' );";
st2.executeUpdate(query2);
JOptionPane.showMessageDialog(null, "Entered Successfully");
de.setVisible(false);
st2.close();
con.close();
}
catch(Exception ex){
System.out.println("Enter Valid data" + ex);
}
}
}
}
}