-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInsert_Record_Menu_Panel.java
More file actions
194 lines (145 loc) · 5.29 KB
/
Insert_Record_Menu_Panel.java
File metadata and controls
194 lines (145 loc) · 5.29 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*****************************************************************************************************
* A menu displayed to the user to insert a new Record into the database.
*****************************************************************************************************/
public class Insert_Record_Menu_Panel extends JPanel
{
/* Pointer to the main java window to access its get() methods for other panels */
private Hospital_Frame main_frame;
/* Text fields for the user to enter intput data */
private JTextField patient_ssn_field, admittance_date_field, primary_doctor_field,
patient_diagnosis_field, status_field;
/* String to get input data from fields */
private String input;
private JComboBox gender_selection;
/*********************************************************************************
* Main constructor used for setting up the Insert_Record_Menu_Panel.
*********************************************************************************/
public Insert_Record_Menu_Panel(Hospital_Frame frame)
{
this.main_frame = frame;
setLayout(new GridLayout(7, 2));
//setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
initializeTextFields();
initializeComboBoxes();
add(new Centered_Text_Panel("Enter information of Record to be added: "));
add(new JLabel(""));
add(new Centered_Text_Panel(" Patient SSN:"));
add(patient_ssn_field);
add(new Centered_Text_Panel(" Admittance Date:"));
add(admittance_date_field);
add(new Centered_Text_Panel(" Primary Doctor:"));
add(primary_doctor_field);
add(new Centered_Text_Panel(" Patient Diagnosis:"));
add(patient_diagnosis_field);
add(new Centered_Text_Panel(" Status:"));
add(status_field);
add(new Main_Menu_Button(main_frame));
add(new Submit_Button());
}
/*********************************************************************************
* Initializes the text fields for Insert_Record_Menu_Panel.
*********************************************************************************/
private void initializeTextFields()
{
patient_ssn_field = new JTextField(6);
primary_doctor_field = new JTextField(1);
admittance_date_field = new JTextField(6);
patient_diagnosis_field = new JTextField(6);
status_field = new JTextField(2);
}
/*********************************************************************************
* Initializes the combo boxes for Insert_Record_Menu_Panel.
*********************************************************************************/
private void initializeComboBoxes()
{
gender_selection = new JComboBox(new String[]{"M", "F"});
}
/******************************************************************************
* Submit button for Insert_Record_Menu_Panel class.
******************************************************************************/
private class Submit_Button extends JButton
{
/******************************************************************
* Main constructor for Submit_Button
******************************************************************/
public Submit_Button()
{
super("Submit");
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// get input from ssn field into ssn string variable
loadText();
// insert the Record into the database
String success = Patient.insertRecord(input);
JOptionPane.showMessageDialog(null, success);
}
});
}
/******************************************************************
* Load input from ssn field into corresponding string variable.
*
* If load is successful, true is returned, otherwise false
* is returned.
******************************************************************/
private boolean loadText()
{
// get ssn from field
try
{
input = patient_ssn_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "SSN input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get admittance_date_field from field
try
{
input += admittance_date_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "admittance_date_field input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get Primary Doctor from field
try
{
input += primary_doctor_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Primary Doctor input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get patient_diagnosis_field from field
try
{
input += patient_diagnosis_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "patient_diagnosis_field input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get status_field from field
try
{
input += status_field.getText();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "status_field input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// if this point is reached age and ssn were successfully retrieved
return true;
}
} // end Submit_Button class
} // end Record menu class