Patient table change, add order by add date
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
|
#include "components/SlideableTableView.h"
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
@@ -22,6 +23,15 @@
|
|||||||
item->setTextAlignment(Qt::AlignmentFlag::AlignCenter);\
|
item->setTextAlignment(Qt::AlignmentFlag::AlignCenter);\
|
||||||
table->setItem(row,col,item);
|
table->setItem(row,col,item);
|
||||||
|
|
||||||
|
|
||||||
|
int queryValue(QSqlTableModel* model, int colID, QVariant var)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < model->rowCount(); ++i) {
|
||||||
|
if (model->data(model->index(i,colID))==var) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
||||||
TabFormWidget(parent)
|
TabFormWidget(parent)
|
||||||
{
|
{
|
||||||
@@ -60,33 +70,38 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
QHBoxLayout* contentLayout =new QHBoxLayout();
|
QHBoxLayout* contentLayout =new QHBoxLayout();
|
||||||
this->ui->contentWidget->setLayout(contentLayout);
|
this->ui->contentWidget->setLayout(contentLayout);
|
||||||
// TableView for patient
|
// TableView for patient
|
||||||
QTableView* table= new QTableView(this);
|
QTableView* table= new SlideableTableView(this);
|
||||||
table->setAlternatingRowColors(true);
|
table->setAlternatingRowColors(true);
|
||||||
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
table->verticalHeader()->setDefaultSectionSize(38);
|
table->verticalHeader()->setDefaultSectionSize(38);
|
||||||
table->horizontalHeader()->setStretchLastSection(true);
|
table->horizontalHeader()->setStretchLastSection(true);
|
||||||
//dat from SQLITE
|
//data from SQLITE
|
||||||
|
|
||||||
auto model = SQLHelper::getTable("Patient");
|
auto model = SQLHelper::getTable("Patient");
|
||||||
model->setFilter("Flag=0");
|
model->setFilter("Flag=0");
|
||||||
|
model->sort(5,Qt::DescendingOrder);
|
||||||
model->select();
|
model->select();
|
||||||
|
|
||||||
model->setHeaderData(1,Qt::Horizontal,"ID");
|
model->setHeaderData(1,Qt::Horizontal,"ID");
|
||||||
model->setHeaderData(2,Qt::Horizontal,"Name");
|
model->setHeaderData(2,Qt::Horizontal,"Name");
|
||||||
model->setHeaderData(3,Qt::Horizontal,"Birth Date");
|
model->setHeaderData(3,Qt::Horizontal,"Birth Date");
|
||||||
|
model->setHeaderData(5,Qt::Horizontal,"Add Date");
|
||||||
table->setModel((QAbstractItemModel*)model);
|
table->setModel((QAbstractItemModel*)model);
|
||||||
table->hideColumn(0);
|
table->hideColumn(0);
|
||||||
table->hideColumn(6);
|
table->hideColumn(7);
|
||||||
|
|
||||||
|
|
||||||
table->show();
|
table->show();
|
||||||
|
|
||||||
|
// table->setSortingEnabled(true);
|
||||||
table->setColumnWidth(1,250);
|
table->setColumnWidth(1,250);
|
||||||
table->setColumnWidth(2,250);
|
table->setColumnWidth(2,250);
|
||||||
table->setColumnWidth(3,120);
|
table->setColumnWidth(3,120);
|
||||||
table->setColumnWidth(4,60);
|
table->setColumnWidth(4,60);
|
||||||
|
table->setColumnWidth(5,250);
|
||||||
|
// table->sortByColumn(5);
|
||||||
|
// table->setSortingEnabled(true);
|
||||||
contentLayout->addWidget(table);
|
contentLayout->addWidget(table);
|
||||||
QWidget* spacerLine2= new QWidget(this);
|
QWidget* spacerLine2= new QWidget(this);
|
||||||
spacerLine2->setFixedWidth(2);
|
spacerLine2->setFixedWidth(2);
|
||||||
@@ -136,15 +151,28 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
connect(edit_patient, &EditPatientForm::editCancel,[=](){
|
connect(edit_patient, &EditPatientForm::editCancel,[=](){
|
||||||
btnSelect->setEnabled(true);
|
btnSelect->setEnabled(true);
|
||||||
});
|
});
|
||||||
connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf){
|
connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf, bool& result){
|
||||||
int selectedRow = currentRow;
|
int selectedRow = currentRow;
|
||||||
bool isAdd = inf->PatientUID.isEmpty();
|
bool isAdd = inf->PatientUID.isEmpty();
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
|
int ref_rowid = queryValue(model, 1, inf->ID);
|
||||||
|
if(ref_rowid>=0)
|
||||||
|
{
|
||||||
|
//非触屏时,如果被选中的行在选中区域外,以下代码可能会出错
|
||||||
|
//但是触屏时一般没问题
|
||||||
|
qDebug()<<ref_rowid;
|
||||||
|
table->scrollTo(model->index(ref_rowid,3));
|
||||||
|
table->selectRow(ref_rowid);
|
||||||
|
result = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
selectedRow = model->rowCount();
|
selectedRow = model->rowCount();
|
||||||
inf->PatientUID = QUuid::createUuid().toString();
|
inf->PatientUID = QUuid::createUuid().toString();
|
||||||
printf(inf->PatientUID.toStdString().data());
|
inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
|
||||||
model->insertRow(selectedRow);
|
model->insertRow(0);
|
||||||
|
selectedRow = 0;
|
||||||
}
|
}
|
||||||
|
qDebug()<<inf->PatientUID<<inf->AddDate;
|
||||||
#define ADD_PATIENT_PROPERTY(val)\
|
#define ADD_PATIENT_PROPERTY(val)\
|
||||||
model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf-> val);
|
model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf-> val);
|
||||||
EDIT_PATIENT()
|
EDIT_PATIENT()
|
||||||
@@ -221,6 +249,7 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SelectFormWidget::~SelectFormWidget()
|
SelectFormWidget::~SelectFormWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int currentRow = -1;
|
int currentRow = -1;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,10 @@ void SlideableTableView::mouseReleaseEvent(QMouseEvent *ev) {
|
|||||||
{
|
{
|
||||||
isDragging = false;
|
isDragging = false;
|
||||||
}
|
}
|
||||||
if (this->verticalScrollBar()->isVisible())
|
|
||||||
{
|
// if (this->verticalScrollBar()->isVisible())
|
||||||
QApplication::sendEvent(this->verticalScrollBar(),ev);
|
// {
|
||||||
}
|
// QApplication::sendEvent(this->verticalScrollBar(),ev);
|
||||||
|
// }
|
||||||
QTableView::mouseReleaseEvent(ev);
|
QTableView::mouseReleaseEvent(ev);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ EditPatientForm::EditPatientForm(QWidget *parent) :
|
|||||||
ui(new Ui::EditPatientForm)
|
ui(new Ui::EditPatientForm)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->lbl_Sex->setText(tr("Gender"));
|
||||||
QHBoxLayout* sexlayout =new QHBoxLayout(ui->sexpanelwidget);
|
QHBoxLayout* sexlayout =new QHBoxLayout(ui->sexpanelwidget);
|
||||||
sexlayout->setMargin(6);
|
sexlayout->setMargin(6);
|
||||||
ADD_TOOL_SIZE_BTN_TO_LAYOUT(F,":/icons/female_d.png",30, sexlayout);
|
ADD_TOOL_SIZE_BTN_TO_LAYOUT(F,":/icons/female_d.png",30, sexlayout);
|
||||||
ADD_TOOL_SIZE_BTN_TO_LAYOUT(M,":/icons/male_d.png", 30,sexlayout);
|
ADD_TOOL_SIZE_BTN_TO_LAYOUT(M,":/icons/male_d.png", 30,sexlayout);
|
||||||
// btnFemale->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
// btnFemale->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||||
// btnMale->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
// btnMale->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||||
|
|
||||||
btnF->setObjectName("sexBtn");
|
btnF->setObjectName("sexBtn");
|
||||||
btnM->setObjectName("sexBtn");
|
btnM->setObjectName("sexBtn");
|
||||||
btnF->setText("Female");
|
btnF->setText("Female");
|
||||||
@@ -53,8 +55,9 @@ EditPatientForm::EditPatientForm(QWidget *parent) :
|
|||||||
if (ui->tbx_ID->text().isEmpty())return;
|
if (ui->tbx_ID->text().isEmpty())return;
|
||||||
if (ui->tbx_Name->text().isEmpty())return;
|
if (ui->tbx_Name->text().isEmpty())return;
|
||||||
storePatientInformation();
|
storePatientInformation();
|
||||||
this->setEditEnable(false);
|
bool result = true;
|
||||||
emit editAccept(getPatientInformation());
|
emit editAccept(getPatientInformation(), result);
|
||||||
|
if (result) this->setEditEnable(false);
|
||||||
});
|
});
|
||||||
ui->tbx_Dob->setDisplayFormat("yyyy/MM/dd");
|
ui->tbx_Dob->setDisplayFormat("yyyy/MM/dd");
|
||||||
}
|
}
|
||||||
@@ -74,6 +77,7 @@ void EditPatientForm::setPatientInformation(PatientInformation *information) {
|
|||||||
btnFemale->setChecked(information->Sex=="F");
|
btnFemale->setChecked(information->Sex=="F");
|
||||||
btnMale->setChecked(information->Sex!="F");
|
btnMale->setChecked(information->Sex!="F");
|
||||||
currentPatientUID = information->PatientUID;
|
currentPatientUID = information->PatientUID;
|
||||||
|
AddDate = information->AddDate;
|
||||||
storePatientInformation();
|
storePatientInformation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,6 +90,7 @@ void EditPatientForm::clearPatientInformation() {
|
|||||||
btnMale->setChecked(false);
|
btnMale->setChecked(false);
|
||||||
ui->rtbx_Comment->setText("");
|
ui->rtbx_Comment->setText("");
|
||||||
currentPatientUID = "";
|
currentPatientUID = "";
|
||||||
|
AddDate = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditPatientForm::setEditEnable(bool enable) {
|
void EditPatientForm::setEditEnable(bool enable) {
|
||||||
@@ -108,6 +113,7 @@ void EditPatientForm::setEditEnable(bool enable) {
|
|||||||
|
|
||||||
void EditPatientForm::storePatientInformation() {
|
void EditPatientForm::storePatientInformation() {
|
||||||
store.PatientUID =currentPatientUID;
|
store.PatientUID =currentPatientUID;
|
||||||
|
store.AddDate = AddDate;
|
||||||
store.ID = ui->tbx_ID->text();
|
store.ID = ui->tbx_ID->text();
|
||||||
store.BirthDate = ui->tbx_Dob->date().toString("yyyy-MM-dd");
|
store.BirthDate = ui->tbx_Dob->date().toString("yyyy-MM-dd");
|
||||||
store.Name = ui->tbx_Name->text();
|
store.Name = ui->tbx_Name->text();
|
||||||
@@ -118,6 +124,7 @@ void EditPatientForm::storePatientInformation() {
|
|||||||
|
|
||||||
void EditPatientForm::restorePatientInformation() {
|
void EditPatientForm::restorePatientInformation() {
|
||||||
currentPatientUID = store.PatientUID;
|
currentPatientUID = store.PatientUID;
|
||||||
|
AddDate = store.AddDate;
|
||||||
ui->tbx_ID->setText(store.ID);
|
ui->tbx_ID->setText(store.ID);
|
||||||
ui->tbx_Dob->setDate(QDate::fromString(store.BirthDate,"yyyy-MM-dd"));
|
ui->tbx_Dob->setDate(QDate::fromString(store.BirthDate,"yyyy-MM-dd"));
|
||||||
ui->tbx_Name->setText(store.Name);
|
ui->tbx_Name->setText(store.Name);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ ADD_PATIENT_PROPERTY(ID)\
|
|||||||
ADD_PATIENT_PROPERTY(Name)\
|
ADD_PATIENT_PROPERTY(Name)\
|
||||||
ADD_PATIENT_PROPERTY(BirthDate)\
|
ADD_PATIENT_PROPERTY(BirthDate)\
|
||||||
ADD_PATIENT_PROPERTY(Sex)\
|
ADD_PATIENT_PROPERTY(Sex)\
|
||||||
|
ADD_PATIENT_PROPERTY(AddDate)\
|
||||||
ADD_PATIENT_PROPERTY(Comment)\
|
ADD_PATIENT_PROPERTY(Comment)\
|
||||||
ADD_PATIENT_PROPERTY(Flag)
|
ADD_PATIENT_PROPERTY(Flag)
|
||||||
|
|
||||||
@@ -67,11 +68,12 @@ public:
|
|||||||
void restorePatientInformation();
|
void restorePatientInformation();
|
||||||
void setEditEnable(bool enable);
|
void setEditEnable(bool enable);
|
||||||
signals:
|
signals:
|
||||||
void editAccept(PatientInformation * detail);
|
void editAccept(PatientInformation * detail,bool & accept);
|
||||||
void editCancel();
|
void editCancel();
|
||||||
private:
|
private:
|
||||||
Ui::EditPatientForm *ui;
|
Ui::EditPatientForm *ui;
|
||||||
QString currentPatientUID;
|
QString currentPatientUID;
|
||||||
|
QString AddDate;
|
||||||
PatientInformation store;
|
PatientInformation store;
|
||||||
bool editEnable=false;
|
bool editEnable=false;
|
||||||
QToolButton* btnEditAccept;
|
QToolButton* btnEditAccept;
|
||||||
|
|||||||
Reference in New Issue
Block a user