QtDcmFindScu.cpp
Go to the documentation of this file.
1 /*
2  QtDcm is a C++ Qt based library for communication and conversion of Dicom images.
3  Copyright (C) 2011 Alexandre Abadie <Alexandre.Abadie@univ-rennes1.fr>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #define QT_NO_CAST_TO_ASCII
21 
22 #ifdef WITH_OPENSSL
23 #include "dcmtk/dcmtls/tlstrans.h"
24 #include "dcmtk/dcmtls/tlslayer.h"
25 #endif
26 
27 #include <QTcpSocket>
28 
29 #include <QtDcmFindCallback.h>
30 #include <QtDcmManager.h>
31 #include <QtDcmPreferences.h>
32 #include <QtDcmServer.h>
33 #include <QtDcmFindScu.h>
34 
36 {
37 public:
39  QTcpSocket * socket;
41 };
42 
43 QtDcmFindScu::QtDcmFindScu ( QObject * parent )
44  : QObject(parent),
45  d( new QtDcmFindScu::Private )
46 {
48  d->socket = new QTcpSocket(this);
49  d->networkTimeout = 30;
50 }
51 
53 {
54  delete d;
55  d = NULL;
56 }
57 
58 
59 void QtDcmFindScu::findPatientsScu (const QString &patientName)
60 {
61  this->findPatientsScu ( patientName, "*" );
62 }
63 
64 void QtDcmFindScu::findPatientsScu (const QString &patientName, const QString &patientSex)
65 {
66  OFList<OFString> overrideKeys;
67  overrideKeys.push_back ( ( QString ( "QueryRetrieveLevel=" ) + QString ( "" "PATIENT" "" ) ).toUtf8().data() );
68  overrideKeys.push_back ( ( QString ( "PatientName=" ) + patientName ).toUtf8().data() );
69 
70  //Patient leqvel
71  overrideKeys.push_back ( QString ( "PatientID" ).toUtf8().data() );
72  overrideKeys.push_back ( QString ( "PatientSex=" + patientSex ).toUtf8().data() );
73  overrideKeys.push_back ( QString ( "PatientBirthDate" ).toUtf8().data() );
74 
75  doQuery ( overrideKeys, QtDcmFindCallback::PATIENT );
76 
77 }
78 
79 void QtDcmFindScu::findStudiesScu (const QString &patientName)
80 {
81  this->findStudiesScu ( patientName, "*", QDate ( 1900,01,01 ).toString ( "yyyyMMdd" ),QDate::currentDate().toString ( "yyyyMMdd" ) );
82 }
83 
84 void QtDcmFindScu::findStudiesScu(const QString &patientName, const QString &studyDescription)
85 {
86  this->findStudiesScu ( patientName, studyDescription, QDate ( 1900,01,01 ).toString ( "yyyyMMdd" ),QDate::currentDate().toString ( "yyyyMMdd" ) );
87 }
88 
89 void QtDcmFindScu::findStudiesScu (const QString &patientName, const QString &studyDescription, const QString &startDate, const QString &endDate)
90 {
91  OFList<OFString> overrideKeys;
92  overrideKeys.push_back ( ( QString ( "QueryRetrieveLevel=" ) + QString ( "" "STUDY" "" ) ).toUtf8().data() );
93  overrideKeys.push_back ( ( QString ( "PatientName=" ) + patientName ).toUtf8().data() );
94  overrideKeys.push_back ( ( QString ( "StudyDescription=" ) + studyDescription ).toUtf8().data() );
95  overrideKeys.push_back ( QString ( "StudyDate=" + startDate + "-" + endDate ).toUtf8().data() );
96 
97  //Study level
98  overrideKeys.push_back ( QString ( "StudyInstanceUID" ).toUtf8().data() );
99 
100  doQuery ( overrideKeys, QtDcmFindCallback::STUDY );
101 
102 }
103 
104 void QtDcmFindScu::findSeriesScu (const QString &patientName, const QString &studyUID)
105 {
106  this->findSeriesScu ( patientName, studyUID, "*", "*", "*" );
107 }
108 
109 void QtDcmFindScu::findSeriesScu (const QString &patientName, const QString &studyUID, const QString &studyDescription, const QString &modality)
110 {
111  this->findSeriesScu ( patientName, studyUID, studyDescription, "*", modality );
112 }
113 
114 void QtDcmFindScu::findSeriesScu (const QString &patientName, const QString &studyUID, const QString &studyDescription, const QString &serieDescription, const QString &modality)
115 {
116  OFList<OFString> overrideKeys;
117  overrideKeys.push_back ( ( QString ( "QueryRetrieveLevel=" ) + QString ( "" "SERIES" "" ) ).toUtf8().data() );
118  overrideKeys.push_back ( ( QString ( "PatientName=" ) + patientName ).toUtf8().data() );
119  overrideKeys.push_back ( QString ( "StudyInstanceUID=" + studyUID ).toUtf8().data() );
120  overrideKeys.push_back ( QString ( "StudyDescription=" + studyDescription ).toUtf8().data() );
121  overrideKeys.push_back ( ( QString ( "SeriesDescription=" ) + serieDescription ).toUtf8().data() );
122  overrideKeys.push_back ( QString ( "Modality=" + modality ).toUtf8().data() );
123 
124  //Study level
125  overrideKeys.push_back ( QString ( "StudyDate" ).toUtf8().data() );
126 
127  //Serie level
128  overrideKeys.push_back ( QString ( "SeriesInstanceUID" ).toUtf8().data() );
129  overrideKeys.push_back ( QString ( "InstitutionName" ).toUtf8().data() );
130  overrideKeys.push_back ( QString ( "InstitutionAddress" ).toUtf8().data() );
131  overrideKeys.push_back ( QString ( "PerformingPhysicianName" ).toUtf8().data() );
132  overrideKeys.push_back ( QString ( "AcquisitionNumber" ).toUtf8().data() );
133  overrideKeys.push_back ( QString ( "NumberOfSeriesRelatedInstances" ).toUtf8().data() );
134 
135  doQuery ( overrideKeys, QtDcmFindCallback::SERIE );
136 }
137 
138 void QtDcmFindScu::findImagesScu (const QString &seriesUID)
139 {
140  OFList<OFString> overrideKeys;
141  overrideKeys.push_back ( ( QString ( "QueryRetrieveLevel=" ) + QString ( "" "IMAGE" "" ) ).toUtf8().data() );
142  overrideKeys.push_back ( QString ( "SeriesInstanceUID=" + seriesUID ).toUtf8().data() );
143 
144  //Image level
145  overrideKeys.push_back ( QString ( "SOPInstanceUID" ).toUtf8().data() );
146  overrideKeys.push_back ( QString ( "InstanceNumber" ).toUtf8().data() );
147 
148  doQuery ( overrideKeys, QtDcmFindCallback::IMAGES );
149 }
150 
151 void QtDcmFindScu::findImageScu (const QString &imageUID)
152 {
153  OFList<OFString> overrideKeys;
154  overrideKeys.push_back ( ( QString ( "QueryRetrieveLevel=" ) + QString ( "" "IMAGE" "" ) ).toUtf8().data() );
155 // overrideKeys.push_back ( QString ( "SeriesInstanceUID=" + seriesUID ).toUtf8().data() );
156 // overrideKeys.push_back ( QString ( "InstanceNumber=" + instanceNumber ).toUtf8().data() );
157 
158  //Image level
159  overrideKeys.push_back ( QString ( "SOPInstanceUID="+ imageUID ).toUtf8().data() );
160 
161  doQuery ( overrideKeys, QtDcmFindCallback::IMAGE );
162 }
163 
165 {
166  bool result = true;
167  d->socket->setSocketOption ( QAbstractSocket::LowDelayOption, 1 );
168  d->socket->connectToHost ( d->manager->currentPacs().address(), d->manager->currentPacs().port().toInt() );
169  if ( d->socket->waitForConnected ( timeout ) ) {
170  d->socket->disconnectFromHost();
171  }
172  else {
173  d->manager->displayErrorMessage ( "Cannot connect to server " + d->manager->currentPacs().address() + " on port " + d->manager->currentPacs().port() + " !" );
174  result = false;
175  }
176 
177  return result;
178 }
179 
180 bool QtDcmFindScu::doQuery ( const OFList<OFString>& overrideKeys, QtDcmFindCallback::cbType level )
181 {
182  //Image level
183  OFList<OFString> fileNameList;
184  DcmFindSCU findscu;
185  OFList<OFString> keys = overrideKeys;
186 
187  // test connection
188  if ( !this->checkServerConnection(10000) ) {
189  return false;
190  }
191 
192  if ( findscu.initializeNetwork ( d->networkTimeout ).bad() ) {
193  QtDcmManager::instance()->displayErrorMessage ( tr ( "Cannot establish network connection" ) );
194  return false;
195  }
196 
197  QtDcmFindCallback callback( level );
198  if ( findscu.performQuery ( d->manager->currentPacs().address().toUtf8().data(),
199  d->manager->currentPacs().port().toInt(),
200  QtDcmPreferences::instance()->aetitle().toUtf8().data(),
201  d->manager->currentPacs().aetitle().toUtf8().data(),
202  UID_FINDPatientRootQueryRetrieveInformationModel, EXS_Unknown,
203  DIMSE_BLOCKING, 0, ASC_DEFAULTMAXPDU, false, false, 1, false, -1, &keys, &callback, &fileNameList ).bad() ) {
204  QtDcmManager::instance()->displayErrorMessage ( tr ( "Cannot perform query C-FIND" ) );
205  }
206 
207  if ( findscu.dropNetwork().bad() ) {
208  QtDcmManager::instance()->displayErrorMessage ( tr ( "Cannot drop network" ) );
209  }
210 
211  return true;
212 }
QString port() const
PACS server port getter (QtDcm only ports between 1000 and 100000)
Definition: QtDcmServer.h:69
void findImagesScu(const QString &seriesUID)
virtual ~QtDcmFindScu()
static QtDcmPreferences * instance()
bool doQuery(const OFList< OFString > &overrideKeys, QtDcmFindCallback::cbType level)
QtDcmServer currentPacs() const
QString aetitle() const
PACS AETitle getter.
Definition: QtDcmServer.h:49
static QtDcmManager * instance()
QtDcmFindScu(QObject *parent=0)
This class is in charge of the different process (dcm2nii), pacs query/retrieve (dcm4chee), temporary directory creation and removing, PACS server settings.
Definition: QtDcmManager.h:44
void findPatientsScu(const QString &patientName)
void displayErrorMessage(const QString &message)
Convenience method that display error message in a QMessageBox window.
QString aetitle() const
QtDcm local AETitle getter.
bool checkServerConnection(int timeout=10000)
test if the current selected pacs is available returns false if timeout (10sec) is reached ...
QtDcmManager * manager
void findStudiesScu(const QString &patientName)
void findImageScu(const QString &imageUID)
void findSeriesScu(const QString &patientName, const QString &studyUID)
QString address() const
PACS server hostname getter.
Definition: QtDcmServer.h:79