221 lines
6.6 KiB
C++
221 lines
6.6 KiB
C++
#include "EditPatientDialog.h"
|
|
|
|
#include <QVBoxLayout>
|
|
#include <QLabel>
|
|
#include <QDateTime>
|
|
#include <QToolButton>
|
|
#include <QSqlTableModel>
|
|
#include <QSqlError>
|
|
#include <QUuid>
|
|
#include <QDebug>
|
|
#include <QFont>
|
|
#include <QFontMetrics>
|
|
#include <QRegExpValidator>
|
|
#include <QRegExp>
|
|
|
|
|
|
#include "dialogs/SelectDialog.h"
|
|
#include "dialogs/DialogManager.h"
|
|
#include "components/ListBox.h"
|
|
#include "components/ULineEdit.h"
|
|
#include "components/UTextEdit.h"
|
|
|
|
namespace
|
|
{
|
|
const int ENDLINE_SPACE = 3;
|
|
int queryValue(QSqlTableModel* model, int aColIDIndex, const QVariant& aPatId)
|
|
{
|
|
for (int i = 0; i < model->rowCount(); ++i)
|
|
{
|
|
if (model->data(model->index(i, aColIDIndex)) == aPatId) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
EditPatientDialog::EditPatientDialog(const QString& aTitle, QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f)
|
|
{
|
|
QVBoxLayout* layout = new QVBoxLayout(mFormWidget);
|
|
layout->setSpacing(10);
|
|
// add title
|
|
QLabel* lbl_title = new QLabel(this);
|
|
lbl_title->setAlignment(Qt::AlignCenter);
|
|
lbl_title->setText(aTitle);
|
|
lbl_title->setObjectName("title");
|
|
layout->addWidget(lbl_title);
|
|
|
|
//add old password
|
|
QLabel* lbl_id = new QLabel(this);
|
|
lbl_id->setText(tr("ID ") + QString("<font color='#930000'>*</font>"));
|
|
le_id = new ULineEdit(this);
|
|
le_id->setMaxLength(30);
|
|
le_id->setValidator(new QRegExpValidator(QRegExp("[a-zA-z0-9]+$"), le_id));
|
|
layout->addWidget(lbl_id);
|
|
layout->addWidget(le_id);
|
|
QLabel* lbl_endline1 = new QLabel(this);
|
|
lbl_endline1->setFixedHeight(ENDLINE_SPACE);
|
|
lbl_endline1->setObjectName("endline");
|
|
layout->addWidget(lbl_endline1);
|
|
|
|
QLabel* lbl_name = new QLabel(this);
|
|
lbl_name->setText(tr("Name") + QString("<font color='#930000'>*</font>"));
|
|
le_name = new ULineEdit(this);
|
|
le_name->setValidator(new QRegExpValidator(QRegExp("^[A-Za-z0-9\u4e00-\u9fa5]+$"), le_name));
|
|
le_name->setMaxLength(30);
|
|
layout->addWidget(lbl_name);
|
|
layout->addWidget(le_name);
|
|
QLabel* lbl_endline2 = new QLabel(this);
|
|
lbl_endline2->setFixedHeight(ENDLINE_SPACE);
|
|
lbl_endline2->setObjectName("endline");
|
|
layout->addWidget(lbl_endline2);
|
|
|
|
QLabel* lbl_sex = new QLabel(this);
|
|
lbl_sex->setText(tr("Gender"));
|
|
layout->addWidget(lbl_sex);
|
|
btnSex = new ListBox(this);
|
|
btnSex->setText(tr("Female"));
|
|
btnSex->setProperty("idx", 0);
|
|
|
|
btnSex->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
connect(btnSex, &QToolButton::clicked, [=]() {
|
|
SelectDialog dialog(this);
|
|
QStringList items;
|
|
items << tr("Female") << tr("Male") << tr("Other");
|
|
dialog.setValues(items);
|
|
dialog.setSelectedValue(items[btnSex->property("idx").toInt()]);
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
{
|
|
btnSex->setText(dialog.getSelectedValue());
|
|
btnSex->setProperty("idx", items.indexOf(dialog.getSelectedValue()));
|
|
}
|
|
});
|
|
layout->addWidget(btnSex);
|
|
QLabel* lbl_endline9 = new QLabel(this);
|
|
lbl_endline9->setFixedHeight(ENDLINE_SPACE);
|
|
lbl_endline9->setObjectName("endline");
|
|
layout->addWidget(lbl_endline9);
|
|
|
|
|
|
QLabel* lbl_date = new QLabel(this);
|
|
lbl_date->setText(tr("Birth Date"));
|
|
|
|
layout->addWidget(lbl_date);
|
|
btnDate = new ListBox(this);
|
|
btnDate->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
btnDate->setText("1990-06-15");
|
|
connect(btnDate, &QToolButton::clicked, [=]() {
|
|
DialogResult result = DialogManager::Default()->requestSelectDate(btnDate->text());
|
|
if (result.ResultCode == QDialog::Accepted)
|
|
{
|
|
btnDate->setText(result.ResultData.toString());
|
|
}
|
|
});
|
|
layout->addWidget(btnDate);
|
|
QLabel* lbl_endline5 = new QLabel(this);
|
|
lbl_endline5->setObjectName("endline");
|
|
lbl_endline5->setFixedHeight(ENDLINE_SPACE);
|
|
layout->addWidget(lbl_endline5);
|
|
|
|
lbl_error = new QLabel(this);
|
|
lbl_error->setObjectName("warn");
|
|
layout->addWidget(lbl_error);
|
|
lbl_error->setWordWrap(true);
|
|
}
|
|
|
|
EditPatientDialog::~EditPatientDialog()
|
|
{
|
|
|
|
}
|
|
|
|
void EditPatientDialog::setPatientInformation(PatientInformation* information)
|
|
{
|
|
if (information)
|
|
{
|
|
le_id->setText(information->ID);
|
|
btnSex->setText(information->Sex == tr("F") ? tr("Female") : (information->Sex == tr("M") ? tr("Male") : tr("Other")));
|
|
le_name->setText(information->Name);
|
|
btnDate->setText(information->BirthDate);
|
|
currentPatientUID = information->PatientUID;
|
|
AddDate = information->AddDate;
|
|
le_id->setEnabled(false);
|
|
}
|
|
|
|
}
|
|
|
|
void EditPatientDialog::clearPatientInformation()
|
|
{
|
|
le_id->setText("");
|
|
// le_date->setText("");
|
|
le_name->setText("");
|
|
}
|
|
|
|
void EditPatientDialog::showErrorMessage(const QString& aMessage)
|
|
{
|
|
QFontMetrics metrics(lbl_error->font());
|
|
if (metrics.width(aMessage)>450){
|
|
lbl_error->setMinimumHeight(80);
|
|
}
|
|
else{
|
|
lbl_error->setMinimumHeight(40);
|
|
}
|
|
lbl_error->setText(aMessage);
|
|
lbl_error->setVisible(true);
|
|
}
|
|
|
|
bool EditPatientDialog::updateReferenceData()
|
|
{
|
|
PatientInformation* inf = getPatientInformation();
|
|
|
|
if (le_id->text().isEmpty())
|
|
{
|
|
showErrorMessage(tr("ID can't be empty!"));
|
|
return false;
|
|
}
|
|
inf->ID = le_id->text().trimmed();
|
|
if (le_name->text().isEmpty())
|
|
{
|
|
showErrorMessage(tr("Patient Name can't be empty!"));
|
|
return false;
|
|
}
|
|
inf->Name = le_name->text().trimmed();
|
|
int selectedRow = 0;
|
|
bool isAdd = currentPatientUID.isEmpty();
|
|
if (isAdd)
|
|
{
|
|
int ref_rowid = queryValue(model, 1, inf->ID);
|
|
if (ref_rowid >= 0)
|
|
{
|
|
showErrorMessage(tr("The ID is already existed!"));
|
|
return false;
|
|
}
|
|
inf->PatientUID = QUuid::createUuid().toString();
|
|
inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
|
|
model->insertRow(0);
|
|
}
|
|
else
|
|
{
|
|
inf->PatientUID = currentPatientUID;
|
|
selectedRow = queryValue(model, 1, inf->ID);
|
|
inf->AddDate = AddDate;
|
|
}
|
|
inf->Sex = btnSex->text() == tr("Female") ? "F" : (tr("Male") == btnSex->text() ? "M" : "O");
|
|
inf->BirthDate = btnDate->text();
|
|
|
|
#define ADD_PATIENT_PROPERTY(val)\
|
|
model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf->val);
|
|
EDIT_PATIENT()
|
|
#undef ADD_PATIENT_PROPERTY
|
|
if (model->submitAll())
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
qDebug()<<model->lastError().text();
|
|
showErrorMessage("Submit fail by database error!");
|
|
return false;
|
|
}
|
|
|
|
}
|