Add WorkList Module.

This commit is contained in:
sunwen
2022-09-29 17:36:55 +08:00
parent 1fe306b532
commit 3a6a755ef1
22 changed files with 803 additions and 4 deletions

View File

@@ -0,0 +1,3 @@
#include "ActionCreator.h"
QMap<QString,AsyncActionPointer> ActionCreator::mAsyncActionContainer;

View File

@@ -0,0 +1,31 @@
#ifndef GUI_ACTIONCREATOR_H
#define GUI_ACTIONCREATOR_H
#include "AsyncAction.h"
#include <QList>
#include <QMap>
class ActionCreator
{
public:
template <typename T>
static T* getAsyncAction(const QString& aActionId)
{
if (mAsyncActionContainer.contains(aActionId))
{
return static_cast<T*>(mAsyncActionContainer.value(aActionId).data());
}
else
{
T* action = new T();
mAsyncActionContainer.insert(aActionId, AsyncActionPointer(action));
return action;
}
};
private:
static QMap<QString, AsyncActionPointer> mAsyncActionContainer;
};
#endif //GUI_ACTIONCREATOR_H

View File

@@ -0,0 +1,22 @@
#include "AsyncAction.h"
#include <QThreadPool>
#include <QThread>
#include <QDebug>
AsyncAction::AsyncAction(QObject* aParent)
: QObject(aParent)
, QRunnable()
{
setAutoDelete(false);
}
AsyncAction::~AsyncAction()
{
}
void AsyncAction::execute()
{
QThreadPool::globalInstance()->start(this);
}

41
src/action/AsyncAction.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef GUI_ASYNCACTION_H
#define GUI_ASYNCACTION_H
#include <QObject>
#include <QString>
#include <QRunnable>
#include <QSharedPointer>
enum ActionCode :unsigned int
{
Sucessed, Failed
};
class ActionResult
{
public:
ActionResult(ActionCode aCode = Sucessed, const QString& aMessage = "")
{
Code = aCode;
Message = aMessage;
}
ActionCode Code;
QString Message;
};
class AsyncAction : public QObject, public QRunnable
{
Q_OBJECT
public:
explicit AsyncAction(QObject* aParent);
~AsyncAction();
void execute();
signals:
void actionCompleted(const ActionResult& aResult);
};
typedef QSharedPointer<AsyncAction> AsyncActionPointer;
#endif //GUI_ASYNCACTION_H

View File

@@ -0,0 +1,77 @@
#include "GetWorkListAction.h"
#include "dicom/WorkListManager.h"
#include <QThread>
#include <QDateTime>
#include <QSqlTableModel>
#include <QUuid>
#include <QDebug>
GetWorkListAction::GetWorkListAction(QObject* aParent)
: AsyncAction(aParent)
, mSqlModel(nullptr)
{
}
GetWorkListAction::~GetWorkListAction()
{
}
void GetWorkListAction::run()
{
if (!mQueryData.isEmpty())
{
PatientInformationPointer info = WorkListManager::getPatientFromWorkList(mQueryData.mAccessionNum, mQueryData.mPatientId);
emit actionCompleted(insertPatientFromWorkList(info));
}
else
{
emit actionCompleted(ActionResult(Failed,tr("Search Query Error")));
}
}
void GetWorkListAction::setWorkListQueryData(const WorkListQueryData& aQueryData)
{
mQueryData = aQueryData;
}
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"));;
}
}

View File

@@ -0,0 +1,46 @@
#ifndef GUI_GETWORKLISTACTION_H
#define GUI_GETWORKLISTACTION_H
#include "AsyncAction.h"
#include "forms/select/PatientInformation.h"
class QSqlTableModel;
class WorkListQueryData
{
public:
WorkListQueryData(const QString& aAccessionNum = QString(),const QString& aPatientId = QString())
: mAccessionNum(aAccessionNum)
, mPatientId(aPatientId)
{
};
bool isEmpty()
{
return mAccessionNum.isEmpty() && mPatientId.isEmpty();
}
QString mAccessionNum;
QString mPatientId;
};
class GetWorkListAction : public AsyncAction
{
Q_OBJECT
public:
explicit GetWorkListAction(QObject* aParent = nullptr);
~GetWorkListAction() override;
void run() override;
void setWorkListQueryData(const WorkListQueryData& aQueryData);
void setSqlModel(QSqlTableModel* aSqlModel);
private:
ActionResult insertPatientFromWorkList(PatientInformationPointer aPatientInformation);
private:
WorkListQueryData mQueryData;
QSqlTableModel* mSqlModel;
};
#endif //GUI_GETWORKLISTACTION_H