ctkDICOMRetrieve.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #include <stdexcept>
  15. // Qt includes
  16. // ctkDICOMCore includes
  17. #include "ctkDICOMRetrieve.h"
  18. #include "ctkLogger.h"
  19. // DCMTK includes
  20. #include "dcmtk/dcmnet/dimse.h"
  21. #include "dcmtk/dcmnet/diutil.h"
  22. #include <dcmtk/dcmdata/dcfilefo.h>
  23. #include <dcmtk/dcmdata/dcfilefo.h>
  24. #include <dcmtk/dcmdata/dcdeftag.h>
  25. #include <dcmtk/dcmdata/dcdatset.h>
  26. #include <dcmtk/ofstd/ofcond.h>
  27. #include <dcmtk/ofstd/ofstring.h>
  28. #include <dcmtk/ofstd/ofstd.h> /* for class OFStandard */
  29. #include <dcmtk/dcmdata/dcddirif.h> /* for class DicomDirInterface */
  30. #include <dcmtk/dcmjpeg/djdecode.h> /* for dcmjpeg decoders */
  31. #include <dcmtk/dcmjpeg/djencode.h> /* for dcmjpeg encoders */
  32. #include <dcmtk/dcmdata/dcrledrg.h> /* for DcmRLEDecoderRegistration */
  33. #include <dcmtk/dcmdata/dcrleerg.h> /* for DcmRLEEncoderRegistration */
  34. // NOTE: using ctk stand-in class for now - switch back
  35. // to dcmtk's scu.h when cget support is in a release version
  36. //#include <dcmtk/dcmnet/scu.h>
  37. #include <ctkDcmSCU.h>
  38. #include "dcmtk/oflog/oflog.h"
  39. static ctkLogger logger("org.commontk.dicom.DICOMRetrieve");
  40. //------------------------------------------------------------------------------
  41. // A customized local implemenation of the DcmSCU so that Qt signals can be emitted
  42. // when retrieve results are obtained
  43. class ctkDICOMRetrieveSCUPrivate : public ctkDcmSCU
  44. {
  45. public:
  46. ctkDICOMRetrieve *retrieve;
  47. ctkDICOMRetrieveSCUPrivate()
  48. {
  49. this->retrieve = 0;
  50. };
  51. ~ctkDICOMRetrieveSCUPrivate() {};
  52. // called when a move reponse comes in: indicates that the
  53. // move request is being handled by the remote server.
  54. virtual OFCondition handleMOVEResponse(const T_ASC_PresentationContextID presID,
  55. RetrieveResponse *response,
  56. OFBool &waitForNextResponse)
  57. {
  58. if (this->retrieve)
  59. {
  60. emit this->retrieve->progress("Got move request");
  61. emit this->retrieve->progress(0);
  62. return this->ctkDcmSCU::handleMOVEResponse(
  63. presID, response, waitForNextResponse);
  64. }
  65. return false;
  66. };
  67. // called when a data set is coming in from a server in
  68. // response to a CGET
  69. virtual OFCondition handleSTORERequest(const T_ASC_PresentationContextID presID,
  70. DcmDataset *incomingObject,
  71. OFBool& continueCGETSession,
  72. Uint16& cStoreReturnStatus)
  73. {
  74. if (this->retrieve)
  75. {
  76. OFString instanceUID;
  77. incomingObject->findAndGetOFString(DCM_SOPInstanceUID, instanceUID);
  78. QString qInstanceUID(instanceUID.c_str());
  79. emit this->retrieve->progress("Got STORE request for " + qInstanceUID);
  80. emit this->retrieve->progress(0);
  81. continueCGETSession = !this->retrieve->wasCanceled();
  82. if (this->retrieve && this->retrieve->database())
  83. {
  84. this->retrieve->database()->insert(incomingObject);
  85. return ECC_Normal;
  86. }
  87. else
  88. {
  89. return this->ctkDcmSCU::handleSTORERequest(
  90. presID, incomingObject, continueCGETSession, cStoreReturnStatus);
  91. }
  92. }
  93. return false;
  94. };
  95. // called when status information from remote server
  96. // comes in from CGET
  97. virtual OFCondition handleCGETResponse(const T_ASC_PresentationContextID presID,
  98. RetrieveResponse* response,
  99. OFBool& continueCGETSession)
  100. {
  101. if (this->retrieve)
  102. {
  103. emit this->retrieve->progress("Got CGET response");
  104. emit this->retrieve->progress(0);
  105. continueCGETSession = !this->retrieve->wasCanceled();
  106. return this->ctkDcmSCU::handleCGETResponse(presID, response, continueCGETSession);
  107. }
  108. return false;
  109. };
  110. };
  111. //------------------------------------------------------------------------------
  112. class ctkDICOMRetrievePrivate: public QObject
  113. {
  114. Q_DECLARE_PUBLIC( ctkDICOMRetrieve );
  115. protected:
  116. ctkDICOMRetrieve* const q_ptr;
  117. public:
  118. ctkDICOMRetrievePrivate(ctkDICOMRetrieve& obj);
  119. ~ctkDICOMRetrievePrivate();
  120. /// Keep the currently negotiated connection to the
  121. /// peer host open unless the connection parameters change
  122. bool WasCanceled;
  123. bool KeepAssociationOpen;
  124. bool ConnectionParamsChanged;
  125. bool LastRetrieveType;
  126. QSharedPointer<ctkDICOMDatabase> Database;
  127. ctkDICOMRetrieveSCUPrivate SCU;
  128. QString MoveDestinationAETitle;
  129. // do the retrieve, handling both series and study retrieves
  130. enum RetrieveType { RetrieveNone, RetrieveSeries, RetrieveStudy };
  131. bool initializeSCU(const QString& studyInstanceUID,
  132. const QString& seriesInstanceUID,
  133. const RetrieveType retrieveType,
  134. DcmDataset *retrieveParameters);
  135. bool move ( const QString& studyInstanceUID,
  136. const QString& seriesInstanceUID,
  137. const RetrieveType retrieveType );
  138. bool get ( const QString& studyInstanceUID,
  139. const QString& seriesInstanceUID,
  140. const RetrieveType retrieveType );
  141. };
  142. //------------------------------------------------------------------------------
  143. // ctkDICOMRetrievePrivate methods
  144. //------------------------------------------------------------------------------
  145. ctkDICOMRetrievePrivate::ctkDICOMRetrievePrivate(ctkDICOMRetrieve& obj)
  146. : q_ptr(&obj)
  147. {
  148. this->Database = QSharedPointer<ctkDICOMDatabase> (0);
  149. this->WasCanceled = false;
  150. this->KeepAssociationOpen = true;
  151. this->ConnectionParamsChanged = false;
  152. this->LastRetrieveType = RetrieveNone;
  153. // Register the JPEG libraries in case we need them
  154. // (registration only happens once, so it's okay to call repeatedly)
  155. // register global JPEG decompression codecs
  156. DJDecoderRegistration::registerCodecs();
  157. // register global JPEG compression codecs
  158. DJEncoderRegistration::registerCodecs();
  159. // register RLE compression codec
  160. DcmRLEEncoderRegistration::registerCodecs();
  161. // register RLE decompression codec
  162. DcmRLEDecoderRegistration::registerCodecs();
  163. logger.info ( "Setting Transfer Syntaxes" );
  164. OFList<OFString> transferSyntaxes;
  165. transferSyntaxes.push_back ( UID_LittleEndianExplicitTransferSyntax );
  166. transferSyntaxes.push_back ( UID_BigEndianExplicitTransferSyntax );
  167. transferSyntaxes.push_back ( UID_LittleEndianImplicitTransferSyntax );
  168. this->SCU.addPresentationContext (
  169. UID_MOVEStudyRootQueryRetrieveInformationModel, transferSyntaxes );
  170. this->SCU.addPresentationContext (
  171. UID_GETStudyRootQueryRetrieveInformationModel, transferSyntaxes );
  172. for (Uint16 i = 0; i < numberOfDcmLongSCUStorageSOPClassUIDs; i++)
  173. {
  174. this->SCU.addPresentationContext(dcmLongSCUStorageSOPClassUIDs[i],
  175. transferSyntaxes, ASC_SC_ROLE_SCP);
  176. }
  177. }
  178. //------------------------------------------------------------------------------
  179. ctkDICOMRetrievePrivate::~ctkDICOMRetrievePrivate()
  180. {
  181. // At least now be kind to the server and release association
  182. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  183. }
  184. //------------------------------------------------------------------------------
  185. bool ctkDICOMRetrievePrivate::initializeSCU( const QString& studyInstanceUID,
  186. const QString& seriesInstanceUID,
  187. const RetrieveType retrieveType,
  188. DcmDataset *retrieveParameters)
  189. {
  190. if ( !this->Database )
  191. {
  192. logger.error ( "No Database for retrieve transaction" );
  193. return false;
  194. }
  195. // If we like to query another server than before, be sure to disconnect first
  196. if (this->SCU.isConnected() && this->ConnectionParamsChanged)
  197. {
  198. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  199. }
  200. // Connect to server if not already connected
  201. if (!this->SCU.isConnected())
  202. {
  203. // Check and initialize networking parameters in DCMTK
  204. if ( !this->SCU.initNetwork().good() )
  205. {
  206. logger.error ( "Error initializing the network" );
  207. return false;
  208. }
  209. // Negotiate (i.e. start the) association
  210. logger.debug ( "Negotiating Association" );
  211. if ( !this->SCU.negotiateAssociation().good() )
  212. {
  213. logger.error ( "Error negotiating association" );
  214. return false;;
  215. }
  216. }
  217. this->ConnectionParamsChanged = false;
  218. // Setup query about what to be received from the PACS
  219. logger.debug ( "Setting Retrieve Parameters" );
  220. if ( retrieveType == RetrieveSeries )
  221. {
  222. retrieveParameters->putAndInsertString ( DCM_QueryRetrieveLevel, "SERIES" );
  223. retrieveParameters->putAndInsertString ( DCM_SeriesInstanceUID,
  224. seriesInstanceUID.toStdString().c_str() );
  225. // Always required to send all highler level unique keys, so add study here (we are in Study Root)
  226. retrieveParameters->putAndInsertString ( DCM_StudyInstanceUID,
  227. studyInstanceUID.toStdString().c_str() ); //TODO
  228. }
  229. else
  230. {
  231. retrieveParameters->putAndInsertString ( DCM_QueryRetrieveLevel, "STUDY" );
  232. retrieveParameters->putAndInsertString ( DCM_StudyInstanceUID,
  233. studyInstanceUID.toStdString().c_str() );
  234. }
  235. return true;
  236. }
  237. //------------------------------------------------------------------------------
  238. bool ctkDICOMRetrievePrivate::move ( const QString& studyInstanceUID,
  239. const QString& seriesInstanceUID,
  240. const RetrieveType retrieveType )
  241. {
  242. DcmDataset *retrieveParameters = new DcmDataset();
  243. if (! this->initializeSCU(studyInstanceUID, seriesInstanceUID, retrieveType, retrieveParameters) )
  244. {
  245. delete retrieveParameters;
  246. return false;
  247. }
  248. // Issue request
  249. logger.debug ( "Sending Move Request" );
  250. OFList<RetrieveResponse*> responses;
  251. T_ASC_PresentationContextID presID = this->SCU.findPresentationContextID(
  252. UID_MOVEStudyRootQueryRetrieveInformationModel,
  253. "" /* don't care about transfer syntax */ );
  254. if (presID == 0)
  255. {
  256. logger.error ( "MOVE Request failed: No valid Study Root MOVE Presentation Context available" );
  257. if (!this->KeepAssociationOpen)
  258. {
  259. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  260. }
  261. delete retrieveParameters;
  262. return false;
  263. }
  264. // do the actual move request
  265. OFCondition status = this->SCU.sendMOVERequest (
  266. presID, this->MoveDestinationAETitle.toStdString().c_str(),
  267. retrieveParameters, &responses );
  268. // Close association if we do not want to explicitly keep it open
  269. if (!this->KeepAssociationOpen)
  270. {
  271. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  272. }
  273. // Free some (little) memory
  274. delete retrieveParameters;
  275. // If we do not receive a single response, something is fishy
  276. if ( responses.begin() == responses.end() )
  277. {
  278. logger.error ( "No responses received at all! (at least one empty response always expected)" );
  279. //throw std::runtime_error( std::string("No responses received from server!") );
  280. return false;
  281. }
  282. /* The server is permitted to acknowledge every image that was received, or
  283. * to send a single move response.
  284. * If there is only a single response, this can mean the following:
  285. * 1) No images to transfer (Status Success and Number of Completed Subops = 0)
  286. * 2) All images transferred (Status Success and Number of Completed Subops > 0)
  287. * 3) Error code, i.e. no images transferred
  288. * 4) Warning (one or more failures, i.e. some images transferred)
  289. */
  290. if ( responses.size() == 1 )
  291. {
  292. RetrieveResponse* rsp = *responses.begin();
  293. logger.debug ( "MOVE response receveid with status: " +
  294. QString(DU_cmoveStatusString(rsp->m_status)) );
  295. if ( (rsp->m_status == STATUS_Success)
  296. || (rsp->m_status == STATUS_MOVE_Warning_SubOperationsCompleteOneOrMoreFailures))
  297. {
  298. if (rsp->m_numberOfCompletedSubops == 0)
  299. {
  300. logger.error ( "No images transferred by PACS!" );
  301. //throw std::runtime_error( std::string("No images transferred by PACS!") );
  302. return false;
  303. }
  304. }
  305. else
  306. {
  307. logger.error("MOVE request failed, server does report error");
  308. QString statusDetail("No details");
  309. if (rsp->m_statusDetail != NULL)
  310. {
  311. std::ostringstream out;
  312. rsp->m_statusDetail->print(out);
  313. statusDetail = "Status Detail: " + statusDetail.fromStdString(out.str());
  314. }
  315. statusDetail.prepend("MOVE request failed: ");
  316. logger.error(statusDetail);
  317. //throw std::runtime_error( statusDetail.toStdString() );
  318. return false;
  319. }
  320. }
  321. // Select the last MOVE response to output meaningful status information
  322. OFIterator<RetrieveResponse*> it = responses.begin();
  323. Uint32 numResults = responses.size();
  324. for (Uint32 i = 1; i < numResults; i++)
  325. {
  326. it++;
  327. }
  328. logger.debug ( "MOVE responses report for study: " + studyInstanceUID +"\n"
  329. + QString::number(static_cast<unsigned int>((*it)->m_numberOfCompletedSubops))
  330. + " images transferred, and\n"
  331. + QString::number(static_cast<unsigned int>((*it)->m_numberOfWarningSubops))
  332. + " images transferred with warning, and\n"
  333. + QString::number(static_cast<unsigned int>((*it)->m_numberOfFailedSubops))
  334. + " images transfers failed");
  335. return true;
  336. }
  337. //------------------------------------------------------------------------------
  338. bool ctkDICOMRetrievePrivate::get ( const QString& studyInstanceUID,
  339. const QString& seriesInstanceUID,
  340. const RetrieveType retrieveType )
  341. {
  342. Q_Q(ctkDICOMRetrieve);
  343. DcmDataset *retrieveParameters = new DcmDataset();
  344. if (! this->initializeSCU(studyInstanceUID, seriesInstanceUID, retrieveType, retrieveParameters) )
  345. {
  346. delete retrieveParameters;
  347. return false;
  348. }
  349. // Issue request
  350. logger.debug ( "Sending Get Request" );
  351. emit q->progress("Sending Get Request");
  352. emit q->progress(0);
  353. OFList<RetrieveResponse*> responses;
  354. T_ASC_PresentationContextID presID = this->SCU.findPresentationContextID(
  355. UID_GETStudyRootQueryRetrieveInformationModel,
  356. "" /* don't care about transfer syntax */ );
  357. if (presID == 0)
  358. {
  359. logger.error ( "GET Request failed: No valid Study Root GET Presentation Context available" );
  360. if (!this->KeepAssociationOpen)
  361. {
  362. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  363. }
  364. delete retrieveParameters;
  365. return false;
  366. }
  367. emit q->progress("Found Presentation Context");
  368. emit q->progress(1);
  369. // do the actual move request
  370. OFCondition status = this->SCU.sendCGETRequest (
  371. presID, retrieveParameters, &responses );
  372. emit q->progress("Sent Get Request");
  373. emit q->progress(2);
  374. // Close association if we do not want to explicitly keep it open
  375. if (!this->KeepAssociationOpen)
  376. {
  377. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  378. }
  379. // Free some (little) memory
  380. delete retrieveParameters;
  381. // If we do not receive a single response, something is fishy
  382. if ( responses.begin() == responses.end() )
  383. {
  384. logger.error ( "No responses received at all! (at least one empty response always expected)" );
  385. //throw std::runtime_error( std::string("No responses received from server!") );
  386. emit q->progress("No Responses from Server!");
  387. return false;
  388. }
  389. emit q->progress("Got Responses");
  390. emit q->progress(3);
  391. /* The server is permitted to acknowledge every image that was received, or
  392. * to send a single move response.
  393. * If there is only a single response, this can mean the following:
  394. * 1) No images to transfer (Status Success and Number of Completed Subops = 0)
  395. * 2) All images transferred (Status Success and Number of Completed Subops > 0)
  396. * 3) Error code, i.e. no images transferred
  397. * 4) Warning (one or more failures, i.e. some images transferred)
  398. */
  399. if ( responses.size() == 1 )
  400. {
  401. RetrieveResponse* rsp = *responses.begin();
  402. logger.debug ( "GET response receveid with status: " +
  403. QString(DU_cmoveStatusString(rsp->m_status)) );
  404. if ( (rsp->m_status == STATUS_Success)
  405. || (rsp->m_status == STATUS_GET_Warning_SubOperationsCompleteOneOrMoreFailures))
  406. {
  407. if (rsp->m_numberOfCompletedSubops == 0)
  408. {
  409. logger.error ( "No images transferred by PACS!" );
  410. //throw std::runtime_error( std::string("No images transferred by PACS!") );
  411. return false;
  412. }
  413. }
  414. else
  415. {
  416. logger.error("GET request failed, server does report error");
  417. QString statusDetail("No details");
  418. if (rsp->m_statusDetail != NULL)
  419. {
  420. std::ostringstream out;
  421. rsp->m_statusDetail->print(out);
  422. statusDetail = "Status Detail: " + statusDetail.fromStdString(out.str());
  423. }
  424. statusDetail.prepend("GET request failed: ");
  425. logger.error(statusDetail);
  426. //throw std::runtime_error( statusDetail.toStdString() );
  427. return false;
  428. }
  429. }
  430. // Select the last GET response to output meaningful status information
  431. OFIterator<RetrieveResponse*> it = responses.begin();
  432. Uint32 numResults = responses.size();
  433. for (Uint32 i = 1; i < numResults; i++)
  434. {
  435. it++;
  436. }
  437. logger.debug ( "GET responses report for study: " + studyInstanceUID +"\n"
  438. + QString::number(static_cast<unsigned int>((*it)->m_numberOfCompletedSubops))
  439. + " images transferred, and\n"
  440. + QString::number(static_cast<unsigned int>((*it)->m_numberOfWarningSubops))
  441. + " images transferred with warning, and\n"
  442. + QString::number(static_cast<unsigned int>((*it)->m_numberOfFailedSubops))
  443. + " images transfers failed");
  444. emit q->progress("Finished Get");
  445. emit q->progress(100);
  446. return true;
  447. }
  448. //------------------------------------------------------------------------------
  449. // ctkDICOMRetrieve methods
  450. //------------------------------------------------------------------------------
  451. ctkDICOMRetrieve::ctkDICOMRetrieve()
  452. : d_ptr(new ctkDICOMRetrievePrivate(*this))
  453. {
  454. Q_D(ctkDICOMRetrieve);
  455. d->SCU.retrieve = this; // give the dcmtk level access to this for emitting signals
  456. }
  457. //------------------------------------------------------------------------------
  458. ctkDICOMRetrieve::~ctkDICOMRetrieve()
  459. {
  460. }
  461. //------------------------------------------------------------------------------
  462. /// Set methods for connectivity
  463. void ctkDICOMRetrieve::setCallingAETitle( const QString& callingAETitle )
  464. {
  465. Q_D(ctkDICOMRetrieve);
  466. if (strcmp(callingAETitle.toStdString().c_str(), d->SCU.getAETitle().c_str()))
  467. {
  468. d->SCU.setAETitle(callingAETitle.toStdString().c_str());
  469. d->ConnectionParamsChanged = true;
  470. }
  471. }
  472. //------------------------------------------------------------------------------
  473. QString ctkDICOMRetrieve::callingAETitle() const
  474. {
  475. Q_D(const ctkDICOMRetrieve);
  476. return d->SCU.getAETitle().c_str();
  477. }
  478. //------------------------------------------------------------------------------
  479. void ctkDICOMRetrieve::setCalledAETitle( const QString& calledAETitle )
  480. {
  481. Q_D(ctkDICOMRetrieve);
  482. if (strcmp(calledAETitle.toStdString().c_str(),d->SCU.getPeerAETitle().c_str()))
  483. {
  484. d->SCU.setPeerAETitle(calledAETitle.toStdString().c_str());
  485. d->ConnectionParamsChanged = true;
  486. }
  487. }
  488. //------------------------------------------------------------------------------
  489. QString ctkDICOMRetrieve::calledAETitle()const
  490. {
  491. Q_D(const ctkDICOMRetrieve);
  492. return d->SCU.getPeerAETitle().c_str();
  493. }
  494. //------------------------------------------------------------------------------
  495. void ctkDICOMRetrieve::setHost( const QString& host )
  496. {
  497. Q_D(ctkDICOMRetrieve);
  498. if (strcmp(host.toStdString().c_str(), d->SCU.getPeerHostName().c_str()))
  499. {
  500. d->SCU.setPeerHostName(host.toStdString().c_str());
  501. d->ConnectionParamsChanged = true;
  502. }
  503. }
  504. //------------------------------------------------------------------------------
  505. QString ctkDICOMRetrieve::host()const
  506. {
  507. Q_D(const ctkDICOMRetrieve);
  508. return d->SCU.getPeerHostName().c_str();
  509. }
  510. //------------------------------------------------------------------------------
  511. void ctkDICOMRetrieve::setPort( int port )
  512. {
  513. Q_D(ctkDICOMRetrieve);
  514. if (d->SCU.getPeerPort() != port)
  515. {
  516. d->SCU.setPeerPort(port);
  517. d->ConnectionParamsChanged = true;
  518. }
  519. }
  520. //------------------------------------------------------------------------------
  521. int ctkDICOMRetrieve::port()const
  522. {
  523. Q_D(const ctkDICOMRetrieve);
  524. return d->SCU.getPeerPort();
  525. }
  526. //------------------------------------------------------------------------------
  527. void ctkDICOMRetrieve::setMoveDestinationAETitle( const QString& moveDestinationAETitle )
  528. {
  529. Q_D(ctkDICOMRetrieve);
  530. if (moveDestinationAETitle != d->MoveDestinationAETitle)
  531. {
  532. d->MoveDestinationAETitle = moveDestinationAETitle;
  533. d->ConnectionParamsChanged = true;
  534. }
  535. }
  536. //------------------------------------------------------------------------------
  537. QString ctkDICOMRetrieve::moveDestinationAETitle()const
  538. {
  539. Q_D(const ctkDICOMRetrieve);
  540. return d->MoveDestinationAETitle;
  541. }
  542. //------------------------------------------------------------------------------
  543. void ctkDICOMRetrieve::setDatabase(QSharedPointer<ctkDICOMDatabase> dicomDatabase)
  544. {
  545. Q_D(ctkDICOMRetrieve);
  546. d->Database = dicomDatabase;
  547. }
  548. //------------------------------------------------------------------------------
  549. QSharedPointer<ctkDICOMDatabase> ctkDICOMRetrieve::database()const
  550. {
  551. Q_D(const ctkDICOMRetrieve);
  552. return d->Database;
  553. }
  554. //------------------------------------------------------------------------------
  555. void ctkDICOMRetrieve::setKeepAssociationOpen(const bool keepOpen)
  556. {
  557. Q_D(ctkDICOMRetrieve);
  558. d->KeepAssociationOpen = keepOpen;
  559. }
  560. //------------------------------------------------------------------------------
  561. bool ctkDICOMRetrieve::keepAssociationOpen()
  562. {
  563. Q_D(const ctkDICOMRetrieve);
  564. return d->KeepAssociationOpen;
  565. }
  566. void ctkDICOMRetrieve::setWasCanceled(const bool wasCanceled)
  567. {
  568. Q_D(ctkDICOMRetrieve);
  569. d->WasCanceled = wasCanceled;
  570. }
  571. //------------------------------------------------------------------------------
  572. bool ctkDICOMRetrieve::wasCanceled()
  573. {
  574. Q_D(const ctkDICOMRetrieve);
  575. return d->WasCanceled;
  576. }
  577. //------------------------------------------------------------------------------
  578. bool ctkDICOMRetrieve::moveStudy(const QString& studyInstanceUID)
  579. {
  580. if (studyInstanceUID.isEmpty())
  581. {
  582. logger.error("Cannot receive series: Study Instance UID empty.");
  583. return false;
  584. }
  585. Q_D(ctkDICOMRetrieve);
  586. logger.info ( "Starting moveStudy" );
  587. return d->move ( studyInstanceUID, "", ctkDICOMRetrievePrivate::RetrieveStudy );
  588. }
  589. //------------------------------------------------------------------------------
  590. bool ctkDICOMRetrieve::getStudy(const QString& studyInstanceUID)
  591. {
  592. if (studyInstanceUID.isEmpty())
  593. {
  594. logger.error("Cannot receive series: Study Instance UID empty.");
  595. return false;
  596. }
  597. Q_D(ctkDICOMRetrieve);
  598. logger.info ( "Starting getStudy" );
  599. return d->get ( studyInstanceUID, "", ctkDICOMRetrievePrivate::RetrieveStudy );
  600. }
  601. //------------------------------------------------------------------------------
  602. bool ctkDICOMRetrieve::moveSeries(const QString& studyInstanceUID,
  603. const QString& seriesInstanceUID)
  604. {
  605. if (studyInstanceUID.isEmpty() || seriesInstanceUID.isEmpty())
  606. {
  607. logger.error("Cannot receive series: Either Study or Series Instance UID empty.");
  608. return false;
  609. }
  610. Q_D(ctkDICOMRetrieve);
  611. logger.info ( "Starting moveSeries" );
  612. return d->move ( studyInstanceUID, seriesInstanceUID, ctkDICOMRetrievePrivate::RetrieveSeries );
  613. }
  614. //------------------------------------------------------------------------------
  615. bool ctkDICOMRetrieve::getSeries(const QString& studyInstanceUID,
  616. const QString& seriesInstanceUID)
  617. {
  618. if (studyInstanceUID.isEmpty() || seriesInstanceUID.isEmpty())
  619. {
  620. logger.error("Cannot receive series: Either Study or Series Instance UID empty.");
  621. return false;
  622. }
  623. Q_D(ctkDICOMRetrieve);
  624. logger.info ( "Starting getSeries" );
  625. return d->get ( studyInstanceUID, seriesInstanceUID, ctkDICOMRetrievePrivate::RetrieveSeries );
  626. }
  627. //------------------------------------------------------------------------------
  628. void ctkDICOMRetrieve::cancel()
  629. {
  630. Q_D(ctkDICOMRetrieve);
  631. d->WasCanceled = true;
  632. }