-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInsert_Patient_Menu_Panel.java
More file actions
executable file
·241 lines (183 loc) · 6.33 KB
/
Insert_Patient_Menu_Panel.java
File metadata and controls
executable file
·241 lines (183 loc) · 6.33 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*****************************************************************************************************
* A menu displayed to the user to insert a new patient into the database.
*****************************************************************************************************/
public class Insert_Patient_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 ssn_field, first_name_field, last_name_field, m_initial_field, dob_field, age_field, location_field;
// fields that might need to be drop down - dob, gender, location
/* String to get input data from fields */
private String input;
private JComboBox gender_selection;
/*********************************************************************************
* Main constructor used for setting up the Insert_Patient_Menu_Panel.
*********************************************************************************/
public Insert_Patient_Menu_Panel(Hospital_Frame frame)
{
this.main_frame = frame;
setLayout(new GridLayout(10, 2));
//setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
initializeTextFields();
initializeComboBoxes();
add(new Centered_Text_Panel("Enter information of patient to be added: "));
add(new JLabel(""));
add(new Centered_Text_Panel(" SSN:"));
add(ssn_field);
add(new Centered_Text_Panel(" First Name:"));
add(first_name_field);
add(new Centered_Text_Panel(" Middle Initial:"));
add(m_initial_field);
add(new Centered_Text_Panel(" Last Name:"));
add(last_name_field);
add(new Centered_Text_Panel(" Date of Birth:"));
add(dob_field);
add(new Centered_Text_Panel(" Age:"));
add(age_field);
add(new Centered_Text_Panel(" Gender:"));
add(gender_selection);
add(new Centered_Text_Panel(" Location:"));
add(location_field);
add(new Main_Menu_Button(main_frame));
add(new Submit_Button());
}
/*********************************************************************************
* Initializes the text fields for Insert_Patient_Menu_Panel.
*********************************************************************************/
private void initializeTextFields()
{
ssn_field = new JTextField(6);
first_name_field = new JTextField(6);
m_initial_field = new JTextField(1);
last_name_field = new JTextField(6);
dob_field = new JTextField(6);
age_field = new JTextField(2);
location_field = new JTextField(6);
}
/*********************************************************************************
* Initializes the combo boxes for Insert_Patient_Menu_Panel.
*********************************************************************************/
private void initializeComboBoxes()
{
gender_selection = new JComboBox(new String[]{"M", "F"});
}
/******************************************************************************
* Submit button for Insert_Patient_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 patient into the database
Patient.insert(input);
JOptionPane.showMessageDialog(null, "Submitted");
}
});
}
/******************************************************************
* 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 = ssn_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "SSN input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get first name from field
try
{
input += first_name_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "First name input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get Middle initial from field
try
{
input += m_initial_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Middle initial input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get last name from field
try
{
input += last_name_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Last name input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get dob from field
try
{
input += dob_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "DOB input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get age from field
try
{
input += age_field.getText() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Age input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get gender selection from field
try
{
input += gender_selection.getSelectedItem().toString() + "\t";
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Gender input could not be read", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// get gender selection from field
try
{
input += location_field.getText();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(new JPanel(), "Location 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 patient menu class