190 lines
5.8 KiB
C++
190 lines
5.8 KiB
C++
#include "WorkListManager.h"
|
|
|
|
#include <dcmtk/dcmnet/scu.h>
|
|
#include <dcmtk/dcmdata/dcpath.h>
|
|
#include "json/jsonobject.h"
|
|
|
|
#include <QDebug>
|
|
#include <QDate>
|
|
|
|
WorkListManager* WorkListManager::getInstance()
|
|
{
|
|
static WorkListManager instance;
|
|
return &instance;
|
|
}
|
|
|
|
void WorkListManager::setTableModel(QSqlTableModel* aModel)
|
|
{
|
|
mTableModel = aModel;
|
|
}
|
|
|
|
void WorkListManager::setTableView(QTableView* aTableView)
|
|
{
|
|
mTableView = aTableView;
|
|
}
|
|
|
|
QSqlTableModel* WorkListManager::getTableModel()
|
|
{
|
|
return mTableModel;
|
|
}
|
|
|
|
QTableView* WorkListManager::getTableView()
|
|
{
|
|
return mTableView;
|
|
}
|
|
|
|
void WorkListManager::setSearchString(const QString& aSearchString)
|
|
{
|
|
mSearchString += aSearchString;
|
|
}
|
|
|
|
QString WorkListManager::getSearchString()
|
|
{
|
|
QString temp = mSearchString;
|
|
mSearchString.clear();
|
|
return temp;
|
|
}
|
|
|
|
WorkListManager::WorkListManager()
|
|
{
|
|
}
|
|
|
|
WorkListManager::~WorkListManager()
|
|
{
|
|
}
|
|
|
|
QList<PatientInformationPointer> WorkListManager::getPatientFromWorkList(const QString& aAccessionNum, const QString& aPatientId)
|
|
{
|
|
DcmSCU scu;
|
|
OFString temp_str;
|
|
host serverInfo = JsonObject::Instance()->getServer(JsonObject::WORKLIST);
|
|
QByteArray ip = serverInfo.ip.toLatin1();
|
|
QByteArray aeTitle = serverInfo.ae.toLatin1();
|
|
OFList<OFString> overrideKeys;
|
|
overrideKeys.push_back(OFString((QString("0008,0050=") + aAccessionNum).toLatin1()));
|
|
overrideKeys.push_back(OFString((QString("0010,0020=") + aPatientId).toLatin1()));
|
|
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";
|
|
}
|
|
/*scu*/
|
|
OFList<OFString> syntaxes;
|
|
syntaxes.push_back(UID_LittleEndianImplicitTransferSyntax);
|
|
scu.setMaxReceivePDULength(ASC_DEFAULTMAXPDU);
|
|
scu.setACSETimeout(30);
|
|
scu.setDIMSEBlockingMode(DIMSE_BLOCKING);
|
|
scu.setDIMSETimeout(0);
|
|
scu.setAETitle(serverInfo.name.toLatin1().data());
|
|
scu.setPeerHostName(ip.data());
|
|
scu.setPeerPort(OFstatic_cast(Uint16, serverInfo.port.toInt()));
|
|
scu.setPeerAETitle(aeTitle.data());
|
|
scu.setVerbosePCMode(OFFalse);
|
|
scu.addPresentationContext(UID_FINDModalityWorklistInformationModel, syntaxes);//UID_FINDStudyRootQueryRetrieveInformationModel
|
|
OFCondition cond = scu.initNetwork();
|
|
|
|
if(cond.bad())
|
|
{
|
|
qDebug()<<cond.code() <<cond.text();
|
|
qDebug()<<"worklist initNetwork failed";
|
|
return QList<PatientInformationPointer>();
|
|
}
|
|
cond = scu.negotiateAssociation();
|
|
if(cond.bad())
|
|
{
|
|
qDebug()<<cond.code();//<< "----"<<cond.text();
|
|
qDebug()<<"worklist connect failed";
|
|
return QList<PatientInformationPointer>();
|
|
}
|
|
|
|
cond = EC_Normal;
|
|
T_ASC_PresentationContextID pcid = scu.findPresentationContextID(UID_FINDModalityWorklistInformationModel,"");
|
|
if (pcid == 0)
|
|
{
|
|
qDebug()<<"worklist pcid bad";
|
|
return QList<PatientInformationPointer>();
|
|
}
|
|
|
|
DcmFileFormat dcmff;
|
|
DcmDataset *dset = dcmff.getDataset();
|
|
OFList<QRResponse*> responses;
|
|
DcmPathProcessor proc;
|
|
proc.setItemWildcardSupport(OFFalse);
|
|
proc.checkPrivateReservations(OFFalse);
|
|
|
|
for(auto &item:overrideKeys)
|
|
{
|
|
proc.applyPathWithValue(dset, item);
|
|
}
|
|
QList<PatientInformationPointer> result;
|
|
cond = scu.sendFINDRequest(pcid, dset, &responses);
|
|
if (responses.size() > 1)
|
|
{
|
|
for(auto item = responses.begin(); item != responses.end(); ++item)
|
|
{
|
|
if ((*item)->m_dataset)
|
|
{
|
|
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<PatientInformationPointer>();
|
|
}
|
|
(*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);
|
|
}
|
|
}
|
|
|
|
OFListIterator(QRResponse*) iter = responses.begin();
|
|
OFListConstIterator(QRResponse*) last = responses.end();
|
|
while (iter != last)
|
|
{
|
|
delete (*iter);
|
|
iter = responses.erase(iter);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return QList<PatientInformationPointer>();
|
|
}
|
|
|
|
if (cond == EC_Normal)
|
|
{
|
|
scu.releaseAssociation();
|
|
}
|
|
else
|
|
{
|
|
if (cond == DUL_PEERREQUESTEDRELEASE)
|
|
scu.closeAssociation(DCMSCU_PEER_REQUESTED_RELEASE);
|
|
else if (cond == DUL_PEERABORTEDASSOCIATION)
|
|
scu.closeAssociation(DCMSCU_PEER_ABORTED_ASSOCIATION);
|
|
else
|
|
{
|
|
scu.abortAssociation();
|
|
}
|
|
|
|
}
|
|
return result;
|
|
}
|