Files
HIS-GUI/gui/dialogs/department_detail_dialog.cpp
e2hang ab53161caa 1
2026-04-06 23:29:55 +08:00

214 lines
8.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "department_detail_dialog.h"
#include <QFormLayout>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QVBoxLayout>
#include <QGroupBox>
#include "core/his_core.h"
#include "core/department_service.h"
#include "core/check_service.h"
#include "models/doctor.h"
#include "models/medicine.h"
#include "models/check.h"
// 职称转换函数
static QString doctorTitleToText(DoctorTitle t) {
switch (t) {
case DoctorTitle::Chief:
return QObject::tr("主任医师");
case DoctorTitle::AssociateChief:
return QObject::tr("副主任医师");
case DoctorTitle::Attending:
return QObject::tr("主治医师");
case DoctorTitle::Resident:
return QObject::tr("住院医师");
}
return QObject::tr("未知");
}
DepartmentDetailDialog::DepartmentDetailDialog(core::HisCore& core, const QString& departmentId, QWidget* parent)
: QDialog(parent), core_(core), departmentId_(departmentId) {
setupUI();
loadDepartmentInfo();
loadDoctors();
loadMedicines();
loadChecks();
}
void DepartmentDetailDialog::setupUI() {
setWindowTitle(tr("科室详情"));
setModal(true);
resize(800, 600);
auto* mainLayout = new QVBoxLayout(this);
// 科室基本信息
auto* infoGroup = new QGroupBox(tr("科室信息"), this);
auto* infoLayout = new QFormLayout(infoGroup);
deptNameLabel_ = new QLabel(this);
deptDescLabel_ = new QLabel(this);
deptDescLabel_->setWordWrap(true);
infoLayout->addRow(tr("科室名称:"), deptNameLabel_);
infoLayout->addRow(tr("科室描述:"), deptDescLabel_);
mainLayout->addWidget(infoGroup);
// 医生列表
auto* doctorGroup = new QGroupBox(tr("医生列表"), this);
auto* doctorLayout = new QVBoxLayout(doctorGroup);
doctorTable_ = new QTableWidget(0, 4, this);
doctorTable_->setHorizontalHeaderLabels({tr("医生ID"), tr("姓名"), tr("职称"), tr("出诊时间")});
doctorTable_->setSelectionBehavior(QAbstractItemView::SelectRows);
doctorTable_->setEditTriggers(QAbstractItemView::NoEditTriggers);
doctorTable_->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
doctorLayout->addWidget(doctorTable_);
mainLayout->addWidget(doctorGroup);
// 药品列表
auto* medicineGroup = new QGroupBox(tr("药品列表"), this);
auto* medicineLayout = new QVBoxLayout(medicineGroup);
medicineTable_ = new QTableWidget(0, 5, this);
medicineTable_->setHorizontalHeaderLabels({tr("药品ID"), tr("通用名称"), tr("商品名称"), tr("库存"), tr("单价")});
medicineTable_->setSelectionBehavior(QAbstractItemView::SelectRows);
medicineTable_->setEditTriggers(QAbstractItemView::NoEditTriggers);
medicineTable_->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
medicineLayout->addWidget(medicineTable_);
mainLayout->addWidget(medicineGroup);
// 检查项目列表
auto* checkGroup = new QGroupBox(tr("检查项目列表"), this);
auto* checkLayout = new QVBoxLayout(checkGroup);
checkTable_ = new QTableWidget(0, 3, this);
checkTable_->setHorizontalHeaderLabels({tr("检查ID"), tr("检查名称"), tr("价格")});
checkTable_->setSelectionBehavior(QAbstractItemView::SelectRows);
checkTable_->setEditTriggers(QAbstractItemView::NoEditTriggers);
checkTable_->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
checkLayout->addWidget(checkTable_);
mainLayout->addWidget(checkGroup);
// 按钮区域
auto* buttonLayout = new QHBoxLayout();
refreshButton_ = new QPushButton(tr("刷新"), this);
closeButton_ = new QPushButton(tr("关闭"), this);
buttonLayout->addWidget(refreshButton_);
buttonLayout->addStretch();
buttonLayout->addWidget(closeButton_);
mainLayout->addLayout(buttonLayout);
connect(refreshButton_, &QPushButton::clicked, this, &DepartmentDetailDialog::onRefresh);
connect(closeButton_, &QPushButton::clicked, this, &QDialog::close);
}
void DepartmentDetailDialog::loadDepartmentInfo() {
const auto* dept = core_.departmentService.findDepartment(departmentId_.toStdString());
if (dept) {
deptNameLabel_->setText(QString::fromStdString(dept->Name));
deptDescLabel_->setText(QString::fromStdString(dept->Description));
} else {
deptNameLabel_->setText(tr("未找到科室"));
deptDescLabel_->setText("");
}
}
void DepartmentDetailDialog::loadDoctors() {
// 动态查询医生列表
auto doctors = core_.departmentService.getDoctorsByDepartment(departmentId_.toStdString());
doctorTable_->setSortingEnabled(false);
doctorTable_->setRowCount(static_cast<int>(doctors.size()));
for (int i = 0; i < static_cast<int>(doctors.size()); ++i) {
const auto& doctor = doctors[i];
doctorTable_->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(doctor.DoctorID)));
doctorTable_->setItem(i, 1, new QTableWidgetItem(QString::fromStdString(doctor.Name)));
doctorTable_->setItem(i, 2, new QTableWidgetItem(doctorTitleToText(doctor.Title)));
doctorTable_->setItem(i, 3, new QTableWidgetItem(QString::fromStdString(doctor.Schedule)));
}
doctorTable_->setSortingEnabled(true);
}
void DepartmentDetailDialog::loadMedicines() {
// 动态查询药品列表
auto medicines = core_.departmentService.getMedicinesByDepartment(departmentId_.toStdString());
medicineTable_->setSortingEnabled(false);
medicineTable_->setRowCount(static_cast<int>(medicines.size()));
for (int i = 0; i < static_cast<int>(medicines.size()); ++i) {
const auto& medicine = medicines[i];
medicineTable_->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(medicine.MedicineID)));
medicineTable_->setItem(i, 1, new QTableWidgetItem(QString::fromStdString(medicine.GenericName)));
medicineTable_->setItem(i, 2, new QTableWidgetItem(QString::fromStdString(medicine.BrandName)));
QTableWidgetItem* stockItem = new QTableWidgetItem();
stockItem->setData(Qt::DisplayRole, medicine.StockQuantity);
medicineTable_->setItem(i, 3, stockItem);
QTableWidgetItem* priceItem = new QTableWidgetItem();
// 修改使用QString::number设置固定两位小数格式确保显示后两位小数如11111.01
priceItem->setText(QString::number(medicine.UnitPrice, 'f', 2));
// 同时设置DisplayRole以支持按数字排序
priceItem->setData(Qt::DisplayRole, medicine.UnitPrice);
medicineTable_->setItem(i, 4, priceItem);
}
medicineTable_->setSortingEnabled(true);
}
void DepartmentDetailDialog::loadChecks() {
// 动态查询检查项目列表
std::vector<Check> checks;
std::string deptId = departmentId_.toStdString();
std::string deptName = core_.departmentService.getDepartmentName(deptId);
if (!deptId.empty()) {
core_.checkService.for_eachCheck([&checks, &deptId, &deptName](const std::string&, const Check& check) {
// 同时匹配科室ID和科室名称确保兼容性
if (check.DepartmentID == deptId || check.DepartmentID == deptName) {
checks.push_back(check);
}
});
}
checkTable_->setSortingEnabled(false);
checkTable_->setRowCount(static_cast<int>(checks.size()));
for (int i = 0; i < static_cast<int>(checks.size()); ++i) {
const auto& check = checks[i];
checkTable_->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(check.CheckID)));
checkTable_->setItem(i, 1, new QTableWidgetItem(QString::fromStdString(check.Name)));
QTableWidgetItem* priceItem = new QTableWidgetItem();
priceItem->setData(Qt::DisplayRole, check.Price);
checkTable_->setItem(i, 2, priceItem);
}
checkTable_->setSortingEnabled(true);
}
void DepartmentDetailDialog::onRefresh() {
loadDepartmentInfo();
loadDoctors();
loadMedicines();
loadChecks();
QMessageBox::information(this, tr("刷新成功"), tr("科室信息已刷新"));
}