-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmedicalsystem.cpp
More file actions
296 lines (254 loc) · 7.22 KB
/
medicalsystem.cpp
File metadata and controls
296 lines (254 loc) · 7.22 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
#include "medicalsystem.h"
MedicalSystem::MedicalSystem(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
initWindow();
}
void MedicalSystem::initWindow(void)
{
timer = new QTimer(this);
model = new QSqlTableModel(this);
model_d = new QSqlTableModel(this);
model_p = new QSqlTableModel(this);
timer->setInterval(1000); //设置定时器触发间隔
timer->start(); //设置定时器初始值
model->setTable("basic_inf"); //基本信息视图
model->select();
model_d->setTable("detail_inf"); //附加详细信息视图
model_d->select();
model_p->setTable("patient_inf");
model_p->select();
connect(timer, SIGNAL(timeout()), this, SLOT(on_timeUpdate()));
ui.doctorTableView->setModel(model); //数据网格信息加载
ui.doctorTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui.timeTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui.timeTableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}
void MedicalSystem::showDoctorPhoto(void)
{
QPixmap photo;
QModelIndex index;
for (int i = 0; i < model_d->rowCount(); i++)
{
index = model_d->index(i, 0);
QString current_name = model_d->data(index).toString();
if (current_name.compare(ui.nameLabel->text()) == 0)
{
index = model_d->index(i, 1);
break;
}
}
photo.loadFromData(model_d->data(index).toByteArray(), "JPG");
ui.photoLabel->setPixmap(photo);
}
void MedicalSystem::showDoctorBrief(void)
{
QModelIndex index;
for (int i = 0; i < model_d->rowCount(); i++)
{
index = model_d->index(i, 0);
QString current_name = model_d->data(index).toString();
if (current_name.compare(ui.nameLabel->text()) == 0)
{
index = model_d->index(i, 3);
break;
}
}
ui.briefTextEdit->setText(model_d->data(index).toString());
ui.briefTextEdit->setFont(QFont("楷体", 12));
}
void MedicalSystem::showDoctorTime(void)
{
QModelIndex index;
for (int i = 0; i < model_d->rowCount(); i++)
{
index = model_d->index(i, 0);
QString current_name = model_d->data(index).toString();
if (current_name.compare(ui.nameLabel->text()) == 0)
{
index = model_d->index(i, 2);
break;
}
}
QString surgery = model_d->data(index).toString();
for (uint8_t i = 0; i < surgery.length(); i++)
{
uint8_t num = surgery.mid(i, 1).toInt();
if (num > 0)
{
if (num < 6)
{
ui.timeTableWidget->setItem(i % 2, i / 2,
new QTableWidgetItem(QString::fromLocal8Bit("可预约")));
}
else
{
ui.timeTableWidget->setItem(i % 2, i / 2,
new QTableWidgetItem(QString::fromLocal8Bit("已约满")));
}
}
else
{
ui.timeTableWidget->setItem(i%2, i/2, new QTableWidgetItem(""));
}
}
}
bool MedicalSystem::checkPatientTime(uint8_t order)
{
QModelIndex index;
model_p->setTable("patient_inf");
model_p->select();
for (int i = 0; i < model_p->rowCount(); i++)
{
index = model_p->index(i, 1);
QString current_name = model_p->data(index).toString();
if (current_name.compare(ui.patientLineEdit->text()) == 0)
{
index = model_p->index(i, 4);
break;
}
}
QString time = model_p->data(index).toString();
uint8_t num = time.mid(order, 1).toInt();
if (num == 1)
{
return false;
}
else
{
time.replace(order, 1, QString::number(1));
QString cmd = tr("update register.patient set time = '%1'"
"where name = '%2';").arg(time).arg(ui.patientLineEdit->text());
QSqlQuery query; //定义数据库类
query.exec(cmd); //执行数据指令
return true;
}
}
void MedicalSystem::on_timeUpdate(void)
{
date = QDate::currentDate();
time = QTime::currentTime();
int year = date.year();
int month = date.month();
int day = date.day();
ui.yearLcdNumber->display(year);
ui.monthLcdNumber->display(month);
ui.dayLcdNumber->display(day);
ui.timeEdit->setTime(time);
}
void MedicalSystem::on_doctorTableView_clicked(const QModelIndex& index)
{
QDate date;
QModelIndex moedlIndex;
int row = 0;
if (index.data() != 0)
row = ui.doctorTableView->currentIndex().row();
moedlIndex = model->index(row, 0); //姓名
ui.nameLabel->setText(model->data(moedlIndex).toString());
moedlIndex = model->index(row, 1); //性别
QString sex = model->data(moedlIndex).toString();
(sex.compare(QString::fromLocal8Bit("男")) == 0) ?
ui.maleRadioButton->setChecked(true) : ui.femaleRadioButton->setChecked(true);
moedlIndex = model->index(row, 2); //出生日期
int now = date.currentDate().year();
int birth = model->data(moedlIndex).toDate().year();
ui.ageSpinBox->setValue(now - birth);
moedlIndex = model->index(row, 4); //职称
QString title = model->data(moedlIndex).toString();
ui.titleComboBox->setCurrentText(title);
showDoctorPhoto(); //照片
showDoctorBrief(); //简介
showDoctorTime(); //坐诊时间
}
void MedicalSystem::on_timeTableWidget_itemClicked(QTableWidgetItem* item)
{
if (isLogin == false)
{
QMessageBox::critical(0, QString::fromLocal8Bit("错误"),
QString::fromLocal8Bit("请先登录,否则无法预约!"));
return;
}
QString data = item->text();
if (data.compare(QString::fromLocal8Bit("可预约")) == 0)
{
uint8_t row = item->row();
uint8_t col = item->column();
uint8_t site = col * 2 + row;
if (checkPatientTime(site) == false)
{
QMessageBox::critical(0, QString::fromLocal8Bit("错误"),
QString::fromLocal8Bit("您已预约过当前时段。"));
return;
}
QString cmd = tr("select info from register.doctor "
"where name = '").append(ui.nameLabel->text()).append("';");
QSqlQuery query; //定义数据库类
query.exec(cmd); //执行数据指令
if (query.next())
{
QString info = query.value(0).toString();
uint8_t num = info.mid(col * 2 + row, 1).toInt();
num++;
info.replace(col * 2 + row, 1, QString::number(num));
if (num > 5)
{
ui.timeTableWidget->setItem(row, col,
new QTableWidgetItem(QString::fromLocal8Bit("已约满")));
}
QString cmd = tr("update register.doctor set info = '%1'"
"where name = '%2';").arg(info).arg(ui.nameLabel->text());
QSqlQuery query; //定义数据库类
query.exec(cmd); //执行数据指令
}
QMessageBox::information(0, QString::fromLocal8Bit("成功"),
QString::fromLocal8Bit("您已成功预约当前时段!"));
}
else if (data.compare("") == 0)
{
QMessageBox::critical(0, QString::fromLocal8Bit("错误"),
QString::fromLocal8Bit("当前时段无法预约,请选其他时段或医生。"));
}
else
{
QMessageBox::critical(0, QString::fromLocal8Bit("错误"),
QString::fromLocal8Bit("当前时段已约满,请选其他时段或医生。"));
}
}
void MedicalSystem::on_patientPushButton_clicked(void)
{
QModelIndex index;
for (int i = 0; i < model_p->rowCount(); i++)
{
index = model_p->index(i, 1);
QString current_name = model_p->data(index).toString();
if (current_name.compare(ui.patientLineEdit->text()) == 0)
{
isLogin = true;
break;
}
}
if (isLogin == true)
{
QMessageBox::information(0, QString::fromLocal8Bit("成功"),
QString::fromLocal8Bit("登录成功!"));
}
else
{
QMessageBox::critical(0, QString::fromLocal8Bit("错误"),
QString::fromLocal8Bit("无法查询您的信息!"));
}
}
void MedicalSystem::on_treeWidget_itemClicked(QTreeWidgetItem* item, int column)
{
QTreeWidgetItem* parent = item->parent();
if (NULL == parent)
{
model->setTable("basic_inf");
model->select();
return;
}
QString department = item->text(column);
model->setFilter(QString::fromLocal8Bit("部门 = '%1'").arg(department));
model->select();
}