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