-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTreatment_Menu_Panel.java
More file actions
executable file
·380 lines (256 loc) · 11.1 KB
/
Treatment_Menu_Panel.java
File metadata and controls
executable file
·380 lines (256 loc) · 11.1 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*****************************************************************************************************
* A Treatment menu to display to the user all the options for interacting with the Treatment
* database relation.
*****************************************************************************************************/
public class Treatment_Menu_Panel extends JPanel
{
/* Pointer to the main java window to access its get() methods for other panels */
protected Hospital_Frame hospital_frame;
/* Main screen displayed to the user */
private JPanel current_panel;
/* Panel with 1 BUTTON to return the screen to the MAIN MENU */
private JPanel main_menu_button;
/* String to get input data from fields */
private String input;
/*********************************************************************************
* Main constructor used for setting up the Treatment_Menu_Panel.
*********************************************************************************/
public Treatment_Menu_Panel ( Hospital_Frame frame )
{
this.hospital_frame = frame;
setLayout(new GridLayout(2,1));
add(current_panel = new Treatment_Button_Options());
add(main_menu_button = new Main_Menu_Button(hospital_frame));
}
/*********************************************************************************
* Switches the current main panel to the passed in one
*********************************************************************************/
protected void changeCurrentPanel(JPanel panel)
{
remove(current_panel);
// need to remove and re-add so the button stays on the bottom
remove(main_menu_button);
add(current_panel = panel);
add(main_menu_button = new Main_Menu_Button(hospital_frame));
revalidate();
repaint();
} // end changeCurrentPanel()
/*********************************************************************************
* Panel for displaying options for interacting with database.
*********************************************************************************/
private class Treatment_Button_Options extends JPanel
{
/* Buttons to take user to a panel for interacting with the Treatment relation */
private JButton insert_treatment_button, delete_treatment_button;
/*********************************************************************************
* Main constructor used for setting up the Treatment_Menu_Panel.
*********************************************************************************/
public Treatment_Button_Options ()
{
setLayout(new GridBagLayout());
initializeButtons();
addActionListeners();
add(insert_treatment_button);
add(delete_treatment_button);
}
/*********************************************************************************
* Initializes the buttons for Treatment_Menu_Panel.
*********************************************************************************/
private void initializeButtons()
{
insert_treatment_button = new JButton("Add New Treatment");
delete_treatment_button = new JButton("Delete Existing Treatment");
}
/*********************************************************************************
* Adds the action listeners for Treatment_Button_Options.
*********************************************************************************/
private void addActionListeners()
{
/* Add functionality - Display panel for inserting a new Treatment */
insert_treatment_button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
changeCurrentPanel(new Insert_Treatment_Menu_Panel());
}
});
/* Add functionality - Display panel for deleting an existing Treatment */
delete_treatment_button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
changeCurrentPanel(new Delete_Treatment_Menu_Panel());
}
});
} // end addActionListeners()
} // end Treatment Button Options Class
/*****************************************************************************************************
* A menu displayed to the user to insert a new Treatment into the database.
*****************************************************************************************************/
private class Insert_Treatment_Menu_Panel extends JPanel
{
/* Text fields for the user to enter intput data */
private JTextField patient_ssn_field, doctor_ssn_field, treatment_start_date_field,
treatment_end_date_field, medicaton_field, dosage_field, method_of_delivery_field;
/*********************************************************************************
* Main constructor used for setting up the Insert_Treatment_Menu_Panel.
*********************************************************************************/
public Insert_Treatment_Menu_Panel()
{
setLayout(new GridLayout(10, 2));
initializeTextFields();
add(new JLabel("Enter information of Treatment to be added: "));
add(new JLabel(""));
add(new JLabel(" Patient SSN:"));
add(patient_ssn_field);
add(new JLabel(" Doctor SSN:"));
add(doctor_ssn_field);
add(new JLabel(" Treatment Start Date:"));
add(treatment_start_date_field);
add(new JLabel(" Treatment End Date:"));
add(treatment_end_date_field);
add(new JLabel(" Medication:"));
add(medicaton_field);
add(new JLabel(" Dosage:"));
add(dosage_field);
add(new JLabel(" Method of Delivery:"));
add(method_of_delivery_field);
add(new Back_Button());
add(new Submit_Button());
}
/*********************************************************************************
* Initializes the text fields for Insert_Treatment_Menu_Panel.
*********************************************************************************/
private void initializeTextFields()
{
patient_ssn_field = new JTextField(6);
doctor_ssn_field = new JTextField(6);
treatment_start_date_field = new JTextField(6);
treatment_end_date_field = new JTextField(6);
medicaton_field = new JTextField(2);
dosage_field = new JTextField(6);
method_of_delivery_field = new JTextField(16);
}
/******************************************************************************
* Submit button for Insert_Treatment_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
loadInput();
Doctor.insertPPT("TREATMENT", input);
JOptionPane.showMessageDialog(null, "Submitted");
}
});
}
/******************************************************************
* Load input from ssn field into corresponding string variable and
* return that string.
******************************************************************/
private String loadInput()
{
// get input from textfields and load them into a single string
input = patient_ssn_field.getText() + "\t" + doctor_ssn_field.getText() + "\t" +
treatment_start_date_field.getText() + "\t" + treatment_end_date_field.getText() + "\t" + medicaton_field.getText() +
"\t" + dosage_field.getText() + "\t" + method_of_delivery_field.getText();
// if this point is reached age and ssn were successfully retrieved
return input;
}
} // end Submit_Button class
} // end Insert Treatment menu class
/*****************************************************************************************************
* A menu displayed to the user to delete an existing Treatment from the database.
*****************************************************************************************************/
private class Delete_Treatment_Menu_Panel extends JPanel
{
/* Button to return the screen to the main menu */
private JButton submit_button;
/* Text fields for the user to enter intput data */
private JTextField treatment_id_field;
/*********************************************************************************
* Main constructor used for setting up the Delete_Treatment_Menu_Panel.
*********************************************************************************/
public Delete_Treatment_Menu_Panel()
{
setLayout(new GridLayout(4, 2));
initializeTextFields();
add(new Centered_Text_Panel("Enter ID of Treatment to be deleted:"));
add(treatment_id_field);
add(new JLabel(""));
add(new JLabel(""));
add(new Back_Button());
add(new Submit_Button());
}
/*********************************************************************************
* Initializes the text fields for Delete_Treatment_Menu_Panel.
*********************************************************************************/
private void initializeTextFields()
{
treatment_id_field = new JTextField(6);
}
/******************************************************************************
* Submit button for Delete_Treatment_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
loadInput();
Patient.delete(input, "TREATMENT");
JOptionPane.showMessageDialog(null, "Deleted");
}
});
}
/******************************************************************
* Load input from ssn field into corresponding string variable and
* return that string.
******************************************************************/
private String loadInput()
{
// get input from textfields and load them into a single string
input = treatment_id_field.getText();
// if this point is reached age and ssn were successfully retrieved
return input;
}
} // end Submit_Button class
} // end Delete_Treatment_Menu_Panel class
/*********************************************************************************
* Returns the user to the main treatment menu
*********************************************************************************/
private class Back_Button extends JButton
{
public Back_Button()
{
super("<- Back");
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
changeCurrentPanel(new Treatment_Button_Options());
}
});
}
}
} // end Treatment menu class