diff --git a/src/action/AsyncAction.h b/src/action/AsyncAction.h index bb16247..23fa92c 100644 --- a/src/action/AsyncAction.h +++ b/src/action/AsyncAction.h @@ -2,7 +2,7 @@ #define GUI_ASYNCACTION_H #include -#include +#include #include #include @@ -14,13 +14,13 @@ enum ActionCode :unsigned int class ActionResult { public: - ActionResult(ActionCode aCode = Sucessed, const QString& aMessage = "") + ActionResult(ActionCode aCode = Sucessed, const QVariant& aData = QVariant()) { Code = aCode; - Message = aMessage; + Data = aData; } ActionCode Code; - QString Message; + QVariant Data; }; class AsyncAction : public QObject, public QRunnable diff --git a/src/action/GetWorkListAction.cpp b/src/action/GetWorkListAction.cpp index a7d6b3f..cd15a79 100644 --- a/src/action/GetWorkListAction.cpp +++ b/src/action/GetWorkListAction.cpp @@ -1,11 +1,6 @@ #include "GetWorkListAction.h" #include "dicom/WorkListManager.h" - -#include -#include -#include -#include -#include +#include "forms/select/PatientInformation.h" GetWorkListAction::GetWorkListAction(QObject* aParent) : AsyncAction(aParent) @@ -23,8 +18,15 @@ void GetWorkListAction::run() { if (!mQueryData.isEmpty()) { - PatientInformationPointer info = WorkListManager::getPatientFromWorkList(mQueryData.mAccessionNum, mQueryData.mPatientId); - emit actionCompleted(insertPatientFromWorkList(info)); + QList patients = WorkListManager::getPatientFromWorkList(mQueryData.mAccessionNum, mQueryData.mPatientId); + if(patients.isEmpty()) + { + emit actionCompleted(ActionResult(Failed,tr("WorkList Search Failed"))); + } + else + { + emit actionCompleted(ActionResult(Sucessed, QVariant::fromValue(patients))); + } } else { @@ -41,37 +43,3 @@ void GetWorkListAction::setSqlModel(QSqlTableModel* aSqlModel) { mSqlModel = aSqlModel; } - -ActionResult GetWorkListAction::insertPatientFromWorkList(PatientInformationPointer aPatientInformation) -{ - if (mSqlModel == nullptr) - { - return ActionResult(Failed,tr("DB Unknow Error")); - } - if (aPatientInformation.isNull()) - { - return ActionResult(Failed,tr("WorkList Search Failed")); - } - mSqlModel->setFilter(QString("PatientID='%1'").arg(aPatientInformation->ID)); - if (mSqlModel->rowCount() > 0) - { - mSqlModel->setFilter(""); - return ActionResult(Failed,tr("Same Patient Existed")); - } - mSqlModel->setFilter(""); - aPatientInformation->PatientUID = QUuid::createUuid().toString(); - aPatientInformation->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); - mSqlModel->insertRow(0); -#define ADD_PATIENT_PROPERTY(val)\ - mSqlModel->setData(mSqlModel->index(0, PatientInformationEnum:: val),aPatientInformation->val); - EDIT_PATIENT() -#undef ADD_PATIENT_PROPERTY - if (mSqlModel->submitAll()) - { - return ActionResult(); - } - else - { - return ActionResult(Failed,tr("DB Error,Patient Write Failed"));; - } -} diff --git a/src/action/GetWorkListAction.h b/src/action/GetWorkListAction.h index 4ca7d44..6746c51 100644 --- a/src/action/GetWorkListAction.h +++ b/src/action/GetWorkListAction.h @@ -2,7 +2,6 @@ #define GUI_GETWORKLISTACTION_H #include "AsyncAction.h" -#include "forms/select/PatientInformation.h" class QSqlTableModel; @@ -35,12 +34,10 @@ public: void setWorkListQueryData(const WorkListQueryData& aQueryData); void setSqlModel(QSqlTableModel* aSqlModel); -private: - ActionResult insertPatientFromWorkList(PatientInformationPointer aPatientInformation); private: WorkListQueryData mQueryData; QSqlTableModel* mSqlModel; }; -#endif //GUI_GETWORKLISTACTION_H \ No newline at end of file +#endif //GUI_GETWORKLISTACTION_H diff --git a/src/dialogs/DialogManager.cpp b/src/dialogs/DialogManager.cpp index 27746e4..b66398e 100644 --- a/src/dialogs/DialogManager.cpp +++ b/src/dialogs/DialogManager.cpp @@ -313,9 +313,9 @@ DialogResult DialogManager::requestEditRouteInfo(const QStringList& aEditData) return DialogResult(ret,dialog.getList()); } -int DialogManager::requestGetWorkList(QSqlTableModel* aModel) +int DialogManager::requestGetWorkList(QSqlTableModel* aModel, QTableView* aTableView) { - GetWorkListDialog dialog(aModel,mTopWidget); + GetWorkListDialog dialog(aModel, aTableView, mTopWidget); setTopWidget(&dialog); dialog.setWindowModality(Qt::WindowModal); int ret = dialog.exec(); diff --git a/src/dialogs/DialogManager.h b/src/dialogs/DialogManager.h index 8f41d7e..7f48534 100644 --- a/src/dialogs/DialogManager.h +++ b/src/dialogs/DialogManager.h @@ -14,6 +14,7 @@ class GUIMessageDialog; class QSqlTableModel; +class QTableView; class PatientInformation; class LoginDialog; class ScreenSaverWindow; @@ -59,7 +60,7 @@ public: int requestEditDicomConfig(); int requestInputAdminPasswd(); int requestEditNetworkConfig(); - int requestGetWorkList(QSqlTableModel* aModel); + int requestGetWorkList(QSqlTableModel* aModel, QTableView* aTableView); DialogResult requestEditIpAndNetMask(); DialogResult requestEditIpAndNetMask(const QStringList& aEditData); DialogResult requestEditRouteInfo(); diff --git a/src/dialogs/GetWorkListDialog.cpp b/src/dialogs/GetWorkListDialog.cpp index 69a1c4e..c7d5605 100644 --- a/src/dialogs/GetWorkListDialog.cpp +++ b/src/dialogs/GetWorkListDialog.cpp @@ -2,17 +2,33 @@ #include #include +#include +#include #include +#include +#include +#include +#include #include "components/ULineEdit.h" #include "action/GetWorkListAction.h" #include "action/ActionCreator.h" -GetWorkListDialog::GetWorkListDialog(QSqlTableModel* aSqlModel, QWidget* aParent, Qt::WindowFlags aFlags) +GetWorkListDialog::GetWorkListDialog(QSqlTableModel* aSqlModel, QTableView* aTableView, QWidget* aParent, Qt::WindowFlags aFlags) : AsyncActionDialog(ActionCreator::getAsyncAction("GetWorkListAction"),"Work List", aParent, aFlags) , mAccessionNumber(new ULineEdit(mContentWidget)) , mPatientId(new ULineEdit(mContentWidget)) , mErrorLabel(new QLabel(mContentWidget)) + , mAccessionNumText(new QLabel(mContentWidget)) + , mAccessionNumEndLine(new QLabel(mContentWidget)) + , mPatientIDText(new QLabel(mContentWidget)) + , mPatientIDLine(new QLabel(mContentWidget)) + , mPatientSelectTable(new QTableView(mContentWidget)) + , mMode(PatientSearchMode) + , mPatientSelectModel(new QStandardItemModel(mContentWidget)) + , mSqlModel(aSqlModel) + , mTableView(aTableView) + , mSearchedPatients() { initializeContentWidgets(); GetWorkListAction* action = qobject_cast(getAction()); @@ -30,22 +46,41 @@ void GetWorkListDialog::initializeContentWidgets() { QVBoxLayout* contentLayout = new QVBoxLayout(mContentWidget); //Accession Nummber - QLabel* accessionNumText = new QLabel(mContentWidget); - accessionNumText->setText(tr("Accession Nummber")); - contentLayout->addWidget(accessionNumText); + mAccessionNumText->setText(tr("Accession Nummber")); + contentLayout->addWidget(mAccessionNumText); contentLayout->addWidget(mAccessionNumber); - QLabel* endLine1 = new QLabel(mContentWidget); - endLine1->setObjectName("endline"); - contentLayout->addWidget(endLine1); + mAccessionNumEndLine->setObjectName("endline"); + contentLayout->addWidget(mAccessionNumEndLine); //PatientId - QLabel* patientIdText = new QLabel(mContentWidget); - patientIdText->setText(tr("Patient ID")); - contentLayout->addWidget(patientIdText); + mPatientIDText->setText(tr("Patient ID")); + contentLayout->addWidget(mPatientIDText); contentLayout->addWidget(mPatientId); - QLabel* endLine2 = new QLabel(mContentWidget); - endLine2->setObjectName("endline"); - contentLayout->addWidget(endLine2); + mPatientIDLine->setObjectName("endline"); + contentLayout->addWidget(mPatientIDLine); + + //TableView + contentLayout->addWidget(mPatientSelectTable); + mPatientSelectModel->setColumnCount(4); + mPatientSelectModel->setHorizontalHeaderItem(0, new QStandardItem("Patient ID")); + mPatientSelectModel->setHorizontalHeaderItem(1, new QStandardItem("Accession Number")); + mPatientSelectModel->setHorizontalHeaderItem(2, new QStandardItem("Patient Name")); + mPatientSelectModel->setHorizontalHeaderItem(3, new QStandardItem("Scheduled Date")); + mPatientSelectTable->setModel(mPatientSelectModel); + mPatientSelectTable->setColumnWidth(0, 200); + mPatientSelectTable->setColumnWidth(1, 200); + mPatientSelectTable->setColumnWidth(2, 200); + mPatientSelectTable->setColumnWidth(3, 200); + + mPatientSelectTable->setAlternatingRowColors(true); + mPatientSelectTable->setSelectionMode(QAbstractItemView::SingleSelection); + mPatientSelectTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + mPatientSelectTable->setSelectionBehavior(QAbstractItemView::SelectRows); + // mTableView->verticalHeader()->setDefaultSectionSize(38); + // mTableView->horizontalHeader()->setStretchLastSection(true); + mPatientSelectTable->viewport()->ungrabGesture(Qt::PanGesture); + mPatientSelectTable->setSortingEnabled(false); // enable sortingEnabled + mPatientSelectTable->hide(); //ErrorLabel contentLayout->addWidget(mErrorLabel); @@ -55,6 +90,11 @@ void GetWorkListDialog::initializeContentWidgets() bool GetWorkListDialog::updateReferenceData() { + if(mMode == PatientSelectMode) + { + insertPatient(mSearchedPatients.at(mPatientSelectTable->currentIndex().row())); + return true; + } QString accessionNum = mAccessionNumber->text(); QString patientId = mPatientId->text(); if (accessionNum.isEmpty() && patientId.isEmpty()) @@ -77,10 +117,108 @@ void GetWorkListDialog::handleFinishedAction(const ActionResult& aResult) { if (aResult.Code == Failed) { - mErrorLabel->setText(aResult.Message); + mErrorLabel->setText(aResult.Data.toString()); mContentWidget->show(); mBtnWidget->show(); mErrorLabel->show(); + return; + } + + mSearchedPatients = aResult.Data.value>(); + + if(mSearchedPatients.size() > 1) + { + updatePatientSelectTable(); + } + else if(mSearchedPatients.size() == 1) + { + insertPatient(mSearchedPatients.at(0)); + AsyncActionDialog::handleFinishedAction(aResult); } - AsyncActionDialog::handleFinishedAction(aResult); +} + +void GetWorkListDialog::updatePatientSelectTable() +{ + int rowCount = mSearchedPatients.size(); + + mPatientSelectModel->setRowCount(rowCount); + for(int i=0; iindex(i, 0, QModelIndex()); + mPatientSelectModel->setData(index, patient->ID); + + index = mPatientSelectModel->index(i, 1, QModelIndex()); + mPatientSelectModel->setData(index, patient->AccessionNumber); + + index = mPatientSelectModel->index(i, 2, QModelIndex()); + mPatientSelectModel->setData(index, patient->Name); + + index = mPatientSelectModel->index(i, 3, QModelIndex()); + mPatientSelectModel->setData(index, patient->ScheduledStartDate); + } + showPatientSelectTable(); +} + +void GetWorkListDialog::showPatientSelectTable() +{ + setFixedWidth(900); + QRect re = geometry(); + setGeometry(re.x() - 200, re.y(), 900, re.height()); + mMode = PatientSelectMode; + mAccessionNumber->hide(); + mPatientId->hide(); + mErrorLabel->hide(); + mAccessionNumText->hide(); + mAccessionNumEndLine->hide(); + mPatientIDText->hide(); + mPatientIDLine->hide(); + + mPatientSelectTable->show(); + mContentWidget->show(); + mBtnWidget->show(); + mLoadingWidget->hide(); +} + +void GetWorkListDialog::insertPatient(PatientInformationPointer aPatient) +{ + if (mSqlModel == nullptr) + { + return; + } + if (aPatient.isNull()) + { + return; + } + mSqlModel->setFilter(QString("PatientID='%1' And AccessionNumber='%2'").arg(aPatient->ID).arg(aPatient->AccessionNumber)); + if (mSqlModel->rowCount() > 0) + { + mSqlModel->setFilter(""); + int patientIdIndex = mSqlModel->record().indexOf("PatientID"); + int accessionNumberIndex = mSqlModel->record().indexOf("AccessionNumber"); + for (int i = 0; i < mSqlModel->rowCount(); ++i) + { + if (mSqlModel->data(mSqlModel->index(i, patientIdIndex)) == aPatient->ID && + mSqlModel->data(mSqlModel->index(i, accessionNumberIndex)) == aPatient->AccessionNumber) + { + mTableView->selectRow(i); + return; + } + } + return; + } + mSqlModel->setFilter(""); + aPatient->PatientUID = QUuid::createUuid().toString(); + aPatient->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); + mSqlModel->insertRow(0); +#define ADD_PATIENT_PROPERTY(val)\ + mSqlModel->setData(mSqlModel->index(0, PatientInformationEnum:: val),aPatient->val); + EDIT_PATIENT() + #undef ADD_PATIENT_PROPERTY + if (!mSqlModel->submitAll()) + { + mErrorLabel->setText( tr("DB Error,Patient Write Failed")); + mErrorLabel->show(); + } + mTableView->selectRow(0); } diff --git a/src/dialogs/GetWorkListDialog.h b/src/dialogs/GetWorkListDialog.h index 2be3f5c..5da5617 100644 --- a/src/dialogs/GetWorkListDialog.h +++ b/src/dialogs/GetWorkListDialog.h @@ -2,17 +2,25 @@ #define GUI_GETWORKLISTDIALOG_H #include "dialogs/AsyncActionDialog.h" +#include "forms/select/PatientInformation.h" class ULineEdit; class QLabel; class QSqlTableModel; +class QTableView; +class QStandardItemModel; + +enum GetWorkListDialogMode +{ + PatientSearchMode = 0, PatientSelectMode +}; class GetWorkListDialog : public AsyncActionDialog { Q_OBJECT public: - explicit GetWorkListDialog(QSqlTableModel* aSqlModel, QWidget* aParent = nullptr, Qt::WindowFlags aFlags = Qt::WindowFlags()); + explicit GetWorkListDialog(QSqlTableModel* aSqlModel, QTableView* aTableView, QWidget* aParent = nullptr, Qt::WindowFlags aFlags = Qt::WindowFlags()); ~GetWorkListDialog() override; protected: @@ -20,12 +28,25 @@ protected: private: void initializeContentWidgets(); + void updatePatientSelectTable(); + void showPatientSelectTable(); + void insertPatient(PatientInformationPointer aPatient); virtual void handleFinishedAction(const ActionResult& aResult) override; private: ULineEdit* mAccessionNumber; ULineEdit* mPatientId; QLabel* mErrorLabel; + QLabel* mAccessionNumText; + QLabel* mAccessionNumEndLine; + QLabel* mPatientIDText; + QLabel* mPatientIDLine; + QTableView* mPatientSelectTable; + GetWorkListDialogMode mMode; + QStandardItemModel* mPatientSelectModel; + QSqlTableModel* mSqlModel; + QTableView* mTableView; + QList mSearchedPatients; }; diff --git a/src/dicom/WorkListManager.cpp b/src/dicom/WorkListManager.cpp index 6d4532c..397bc96 100644 --- a/src/dicom/WorkListManager.cpp +++ b/src/dicom/WorkListManager.cpp @@ -5,6 +5,7 @@ #include "json/jsonobject.h" #include +#include WorkListManager::WorkListManager() { @@ -14,7 +15,7 @@ WorkListManager::~WorkListManager() { } -PatientInformationPointer WorkListManager::getPatientFromWorkList(const QString& aAccessionNum, const QString& aPatientId) +QList WorkListManager::getPatientFromWorkList(const QString& aAccessionNum, const QString& aPatientId) { DcmSCU scu; OFString temp_str; @@ -27,6 +28,7 @@ PatientInformationPointer WorkListManager::getPatientFromWorkList(const QString& overrideKeys.push_back("0010,0010"); overrideKeys.push_back("0010,0030"); overrideKeys.push_back("0010,0040"); + overrideKeys.push_back("0040,0002"); if (!dcmDataDict.isDictionaryLoaded()) { qDebug()<<"dcmdatadict error"; @@ -38,7 +40,7 @@ PatientInformationPointer WorkListManager::getPatientFromWorkList(const QString& scu.setACSETimeout(30); scu.setDIMSEBlockingMode(DIMSE_BLOCKING); scu.setDIMSETimeout(0); - scu.setAETitle("USCT"); + scu.setAETitle(serverInfo.name.toLatin1().data()); scu.setPeerHostName(ip.data()); scu.setPeerPort(OFstatic_cast(Uint16, serverInfo.port.toInt())); scu.setPeerAETitle(aeTitle.data()); @@ -50,14 +52,14 @@ PatientInformationPointer WorkListManager::getPatientFromWorkList(const QString& { qDebug()<(); } cond = scu.negotiateAssociation(); if(cond.bad()) { qDebug()<(); } cond = EC_Normal; @@ -65,7 +67,7 @@ PatientInformationPointer WorkListManager::getPatientFromWorkList(const QString& if (pcid == 0) { qDebug()<<"worklist pcid bad"; - return PatientInformationPointer(); + return QList(); } DcmFileFormat dcmff; @@ -79,42 +81,41 @@ PatientInformationPointer WorkListManager::getPatientFromWorkList(const QString& { proc.applyPathWithValue(dset, item); } - - - PatientInformationPointer result = PatientInformationPointer(new PatientInformation()); + QList result; cond = scu.sendFINDRequest(pcid, dset, &responses); - if (!responses.empty()) + if (responses.size() > 1) { - auto item = *responses.begin(); - if (item->m_dataset) + for(auto item = responses.begin(); item != responses.end(); ++item) { - OFString ID; - OFString Name; - OFString BirthDate; - OFString Sex; - OFString AccessionNumber; - item->m_dataset->findAndGetOFString(DCM_PatientID, ID); - if (ID.empty()) + if ((*item)->m_dataset) { - return PatientInformationPointer(); + PatientInformationPointer patient = PatientInformationPointer(new PatientInformation()); + OFString ID; + OFString Name; + OFString BirthDate; + OFString Sex; + OFString AccessionNumber; + OFString scheduledStartDateStr; + (*item)->m_dataset->findAndGetOFString(DCM_PatientID, ID); + + if (ID.empty()) + { + return QList(); + } + (*item)->m_dataset->findAndGetOFString(DCM_PatientName, Name); + (*item)->m_dataset->findAndGetOFString(DCM_PatientBirthDate, BirthDate); + (*item)->m_dataset->findAndGetOFString(DCM_PatientSex, Sex); + (*item)->m_dataset->findAndGetOFString(DCM_AccessionNumber, AccessionNumber); + (*item)->m_dataset->findAndGetOFString(DCM_ScheduledProcedureStepStartDate, scheduledStartDateStr); + //(*item)->m_dataset->print(std::cerr); + patient->ID = QString(ID.c_str()); + patient->Name = QString(Name.c_str()); + patient->BirthDate = QString(BirthDate.c_str()).insert(4,"-").insert(7,"-"); + patient->Sex = QString(Sex.c_str()); + patient->AccessionNumber = QString(AccessionNumber.c_str()); + patient->ScheduledStartDate = QString(scheduledStartDateStr.c_str()); + result.push_back(patient); } - item->m_dataset->findAndGetOFString(DCM_PatientName, Name); - item->m_dataset->findAndGetOFString(DCM_PatientBirthDate, BirthDate); - item->m_dataset->findAndGetOFString(DCM_PatientSex, Sex); - item->m_dataset->findAndGetOFString(DCM_AccessionNumber, AccessionNumber); - result->ID = QString(ID.c_str()); - result->Name = QString(Name.c_str()); - result->BirthDate = QString(BirthDate.c_str()).insert(4,"-").insert(7,"-"); - result->Sex = QString(Sex.c_str()); - result->AccessionNumber = QString(AccessionNumber.c_str()); - //if (patientName.bad()) - //{ - // std::cout << patientName.text() << std::endl; - //} - } - else - { - return PatientInformationPointer(); } OFListIterator(QRResponse*) iter = responses.begin(); @@ -127,7 +128,7 @@ PatientInformationPointer WorkListManager::getPatientFromWorkList(const QString& } else { - return PatientInformationPointer(); + return QList(); } if (cond == EC_Normal) diff --git a/src/dicom/WorkListManager.h b/src/dicom/WorkListManager.h index a582081..14f90c3 100644 --- a/src/dicom/WorkListManager.h +++ b/src/dicom/WorkListManager.h @@ -2,6 +2,7 @@ #define GUI_WORKLISTMANAGER_H #include +#include #include "forms/select/PatientInformation.h" @@ -11,8 +12,8 @@ public: WorkListManager(); ~WorkListManager(); - static PatientInformationPointer getPatientFromWorkList(const QString& aAccessionNum, const QString& aPatientId); + static QList getPatientFromWorkList(const QString& aAccessionNum, const QString& aPatientId); }; -#endif //GUI_WORKLISTMANAGER_H \ No newline at end of file +#endif //GUI_WORKLISTMANAGER_H diff --git a/src/forms/select/PatientInformation.h b/src/forms/select/PatientInformation.h index d88b72c..be50f1a 100644 --- a/src/forms/select/PatientInformation.h +++ b/src/forms/select/PatientInformation.h @@ -40,6 +40,7 @@ public: : QObject() { } + QString ScheduledStartDate; PatientInformation* Copy() { PatientInformation* n=new PatientInformation; diff --git a/src/forms/select/SelectFormWidget.cpp b/src/forms/select/SelectFormWidget.cpp index 11da4fe..eb431d8 100644 --- a/src/forms/select/SelectFormWidget.cpp +++ b/src/forms/select/SelectFormWidget.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "components/SlideTableView.h" @@ -85,10 +86,7 @@ void SelectFormWidget::initGeneralButtons(QHBoxLayout *layout) { connect(mBtnAccount, &QToolButton::clicked, DialogManager::Default(),&DialogManager::requestEditSelfAccount); connect(mBtnWorklist, &QToolButton::clicked, [&]() { - if (DialogManager::Default()->requestGetWorkList(mModel) == QDialog::Accepted) - { - mPatTable->selectRow(0); - } + DialogManager::Default()->requestGetWorkList(mModel, mPatTable); }); } @@ -237,7 +235,7 @@ void SelectFormWidget::initTableView(QHBoxLayout *contentLayout) {// TableView f void SelectFormWidget::initDataModel() {//TODO:单独初始化预防SQL错误 mModel = SQLHelper::getTable("Patient"); - mModel->sort(5, Qt::DescendingOrder); + mModel->sort(mModel->record().indexOf("AddDate"), Qt::DescendingOrder); mModel->select(); mModel->setHeaderData(1, Qt::Horizontal, "ID"); mModel->setHeaderData(2, Qt::Horizontal, tr("AccessionNumber"));