Repository navigation
Expand file tree
/
Copy pathFrmPatientMenu.java
More file actions
146 lines (126 loc) · 5.55 KB
/
Copy pathFrmPatientMenu.java
File metadata and controls
146 lines (126 loc) · 5.55 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
package boundary;
import controller.TreatmentPlanController;
import controller.PatientController;
import entity.TreatmentPlan;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.util.Date;
/** Dialog – create a new Treatment Plan (DentalCare theme) */
public class FrmNewTreatmentPlan extends JDialog {
/* brand colours & fonts */
private static final Color PRIMARY_BLUE = new Color(0, 71, 171);
private static final Font UI_FONT = new Font("Segoe UI", Font.PLAIN, 14);
/* ───── components ───── */
private final JComboBox<Integer> cmbPatient = new JComboBox<>();
private final JSpinner spnStart = new JSpinner(new SpinnerDateModel());
private final JButton btnSave = new JButton("Save Plan");
/* ───── controllers & data ───── */
private final int staffID;
private final TreatmentPlanController planCtl = new TreatmentPlanController();
private final PatientController patientCtl = new PatientController();
/* ───── ctor ───── */
public FrmNewTreatmentPlan(Frame owner, int staffID) {
super(owner, "New Treatment Plan", true);
this.staffID = staffID;
buildUI();
}
/* ───── UI ───── */
private void buildUI() {
/* frame */
setSize(430, 270);
setLocationRelativeTo(getOwner());
setLayout(new BorderLayout());
getContentPane().setBackground(Color.WHITE);
getRootPane().setBorder(new LineBorder(PRIMARY_BLUE, 2));
/* header */
JLabel header = new JLabel("New Treatment Plan", SwingConstants.CENTER);
header.setFont(new Font("Segoe UI", Font.BOLD, 18));
header.setForeground(PRIMARY_BLUE);
header.setBorder(new EmptyBorder(12, 0, 6, 0));
add(header, BorderLayout.NORTH);
/* form */
JPanel form = new JPanel(new GridBagLayout());
form.setOpaque(false);
form.setBorder(new EmptyBorder(10, 25, 10, 25));
GridBagConstraints g = new GridBagConstraints();
g.insets = new Insets(10, 10, 10, 10);
g.anchor = GridBagConstraints.WEST;
/** populate patient combo */
patientCtl.getAllPatientIDs().forEach(cmbPatient::addItem);
cmbPatient.setBackground(Color.WHITE);
cmbPatient.setFont(UI_FONT);
cmbPatient.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
setFont(UI_FONT);
if (value != null) {
int id = (Integer) value;
String n = patientCtl.getPatientName(id); // "" if not found
setText(id + " – " + n);
}
return this;
}
});
/* start date spinner */
spnStart.setEditor(new JSpinner.DateEditor(spnStart, "yyyy-MM-dd"));
spnStart.setValue(new Date());
((JSpinner.DefaultEditor) spnStart.getEditor())
.getTextField().setFont(UI_FONT);
/* labels */
JLabel lblPatient = new JLabel("Patient:");
JLabel lblStart = new JLabel("Start Date:");
lblPatient.setFont(UI_FONT);
lblStart.setFont(UI_FONT);
/* layout */
g.gridx = 0; g.gridy = 0; form.add(lblPatient, g);
g.gridx = 1; form.add(cmbPatient, g);
g.gridx = 0; g.gridy = 1; form.add(lblStart, g);
g.gridx = 1; form.add(spnStart, g);
add(form, BorderLayout.CENTER);
/* save button */
btnSave.setBackground(PRIMARY_BLUE);
btnSave.setForeground(Color.WHITE);
btnSave.setFont(new Font("Segoe UI", Font.BOLD, 15));
btnSave.setFocusPainted(false);
btnSave.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
btnSave.setBorder(new EmptyBorder(10, 40, 10, 40));
btnSave.addActionListener(e -> save());
JPanel south = new JPanel();
south.setOpaque(false);
south.setBorder(new EmptyBorder(10, 10, 20, 10));
south.add(btnSave);
add(south, BorderLayout.SOUTH);
}
/* ───── save logic ───── */
private void save() {
Integer pid = (Integer) cmbPatient.getSelectedItem();
if (pid == null) {
JOptionPane.showMessageDialog(this, "Choose a patient.");
return;
}
Date start = (Date) spnStart.getValue();
TreatmentPlan p = new TreatmentPlan(
0, // planID → controller assigns MAX+1
pid,
staffID,
start,
start, // endDate = start for now
0.0,
"Active"
);
if (planCtl.insert(p)) {
JOptionPane.showMessageDialog(this,
"Plan #" + p.getPlanID() + " created ✔");
dispose();
} else {
JOptionPane.showMessageDialog(this,
"Patient already has an Active plan.",
"Cannot create",
JOptionPane.ERROR_MESSAGE);
}
}
}