ctkDICOMRetrieve.cpp 25 KB

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