ctkDICOMRetrieve.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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.error ( "Setting Transfer Syntaxes" );
  164. logger.info ( "Setting Transfer Syntaxes" );
  165. OFList<OFString> transferSyntaxes;
  166. transferSyntaxes.push_back ( UID_LittleEndianExplicitTransferSyntax );
  167. transferSyntaxes.push_back ( UID_BigEndianExplicitTransferSyntax );
  168. transferSyntaxes.push_back ( UID_LittleEndianImplicitTransferSyntax );
  169. this->SCU.addPresentationContext (
  170. UID_MOVEStudyRootQueryRetrieveInformationModel, transferSyntaxes );
  171. this->SCU.addPresentationContext (
  172. UID_GETStudyRootQueryRetrieveInformationModel, transferSyntaxes );
  173. for (Uint16 i = 0; i < numberOfDcmLongSCUStorageSOPClassUIDs; i++)
  174. {
  175. this->SCU.addPresentationContext(dcmLongSCUStorageSOPClassUIDs[i],
  176. transferSyntaxes, ASC_SC_ROLE_SCP);
  177. }
  178. logger.error ( "Exit constructor" );
  179. }
  180. //------------------------------------------------------------------------------
  181. ctkDICOMRetrievePrivate::~ctkDICOMRetrievePrivate()
  182. {
  183. // At least now be kind to the server and release association
  184. if (this->SCU.isConnected())
  185. {
  186. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  187. }
  188. }
  189. //------------------------------------------------------------------------------
  190. bool ctkDICOMRetrievePrivate::initializeSCU( const QString& studyInstanceUID,
  191. const QString& seriesInstanceUID,
  192. const RetrieveType retrieveType,
  193. DcmDataset *retrieveParameters)
  194. {
  195. if ( !this->Database )
  196. {
  197. logger.error ( "No Database for retrieve transaction" );
  198. return false;
  199. }
  200. // If we like to query another server than before, be sure to disconnect first
  201. if (this->SCU.isConnected() && this->ConnectionParamsChanged)
  202. {
  203. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  204. }
  205. // Connect to server if not already connected
  206. if (!this->SCU.isConnected())
  207. {
  208. // Check and initialize networking parameters in DCMTK
  209. if ( !this->SCU.initNetwork().good() )
  210. {
  211. logger.error ( "Error initializing the network" );
  212. return false;
  213. }
  214. // Negotiate (i.e. start the) association
  215. logger.debug ( "Negotiating Association" );
  216. if ( !this->SCU.negotiateAssociation().good() )
  217. {
  218. logger.error ( "Error negotiating association" );
  219. return false;;
  220. }
  221. }
  222. this->ConnectionParamsChanged = false;
  223. // Setup query about what to be received from the PACS
  224. logger.debug ( "Setting Retrieve Parameters" );
  225. if ( retrieveType == RetrieveSeries )
  226. {
  227. retrieveParameters->putAndInsertString ( DCM_QueryRetrieveLevel, "SERIES" );
  228. retrieveParameters->putAndInsertString ( DCM_SeriesInstanceUID,
  229. seriesInstanceUID.toStdString().c_str() );
  230. // Always required to send all highler level unique keys, so add study here (we are in Study Root)
  231. retrieveParameters->putAndInsertString ( DCM_StudyInstanceUID,
  232. studyInstanceUID.toStdString().c_str() ); //TODO
  233. }
  234. else
  235. {
  236. retrieveParameters->putAndInsertString ( DCM_QueryRetrieveLevel, "STUDY" );
  237. retrieveParameters->putAndInsertString ( DCM_StudyInstanceUID,
  238. studyInstanceUID.toStdString().c_str() );
  239. }
  240. return true;
  241. }
  242. //------------------------------------------------------------------------------
  243. bool ctkDICOMRetrievePrivate::move ( const QString& studyInstanceUID,
  244. const QString& seriesInstanceUID,
  245. const RetrieveType retrieveType )
  246. {
  247. DcmDataset *retrieveParameters = new DcmDataset();
  248. if (! this->initializeSCU(studyInstanceUID, seriesInstanceUID, retrieveType, retrieveParameters) )
  249. {
  250. delete retrieveParameters;
  251. return false;
  252. }
  253. // Issue request
  254. logger.debug ( "Sending Move Request" );
  255. OFList<RetrieveResponse*> responses;
  256. T_ASC_PresentationContextID presID = this->SCU.findPresentationContextID(
  257. UID_MOVEStudyRootQueryRetrieveInformationModel,
  258. "" /* don't care about transfer syntax */ );
  259. if (presID == 0)
  260. {
  261. logger.error ( "MOVE Request failed: No valid Study Root MOVE Presentation Context available" );
  262. if (!this->KeepAssociationOpen)
  263. {
  264. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  265. }
  266. delete retrieveParameters;
  267. return false;
  268. }
  269. // do the actual move request
  270. OFCondition status = this->SCU.sendMOVERequest (
  271. presID, this->MoveDestinationAETitle.toStdString().c_str(),
  272. retrieveParameters, &responses );
  273. // Close association if we do not want to explicitly keep it open
  274. if (!this->KeepAssociationOpen)
  275. {
  276. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  277. }
  278. // Free some (little) memory
  279. delete retrieveParameters;
  280. // If we do not receive a single response, something is fishy
  281. if ( responses.begin() == responses.end() )
  282. {
  283. logger.error ( "No responses received at all! (at least one empty response always expected)" );
  284. //throw std::runtime_error( std::string("No responses received from server!") );
  285. return false;
  286. }
  287. /* The server is permitted to acknowledge every image that was received, or
  288. * to send a single move response.
  289. * If there is only a single response, this can mean the following:
  290. * 1) No images to transfer (Status Success and Number of Completed Subops = 0)
  291. * 2) All images transferred (Status Success and Number of Completed Subops > 0)
  292. * 3) Error code, i.e. no images transferred
  293. * 4) Warning (one or more failures, i.e. some images transferred)
  294. */
  295. if ( responses.size() == 1 )
  296. {
  297. RetrieveResponse* rsp = *responses.begin();
  298. logger.debug ( "MOVE response receveid with status: " +
  299. QString(DU_cmoveStatusString(rsp->m_status)) );
  300. if ( (rsp->m_status == STATUS_Success)
  301. || (rsp->m_status == STATUS_MOVE_Warning_SubOperationsCompleteOneOrMoreFailures))
  302. {
  303. if (rsp->m_numberOfCompletedSubops == 0)
  304. {
  305. logger.error ( "No images transferred by PACS!" );
  306. //throw std::runtime_error( std::string("No images transferred by PACS!") );
  307. return false;
  308. }
  309. }
  310. else
  311. {
  312. logger.error("MOVE request failed, server does report error");
  313. QString statusDetail("No details");
  314. if (rsp->m_statusDetail != NULL)
  315. {
  316. std::ostringstream out;
  317. rsp->m_statusDetail->print(out);
  318. statusDetail = "Status Detail: " + statusDetail.fromStdString(out.str());
  319. }
  320. statusDetail.prepend("MOVE request failed: ");
  321. logger.error(statusDetail);
  322. //throw std::runtime_error( statusDetail.toStdString() );
  323. return false;
  324. }
  325. }
  326. // Select the last MOVE response to output meaningful status information
  327. OFIterator<RetrieveResponse*> it = responses.begin();
  328. Uint32 numResults = responses.size();
  329. for (Uint32 i = 1; i < numResults; i++)
  330. {
  331. it++;
  332. }
  333. logger.debug ( "MOVE responses report for study: " + studyInstanceUID +"\n"
  334. + QString::number(static_cast<unsigned int>((*it)->m_numberOfCompletedSubops))
  335. + " images transferred, and\n"
  336. + QString::number(static_cast<unsigned int>((*it)->m_numberOfWarningSubops))
  337. + " images transferred with warning, and\n"
  338. + QString::number(static_cast<unsigned int>((*it)->m_numberOfFailedSubops))
  339. + " images transfers failed");
  340. return true;
  341. }
  342. //------------------------------------------------------------------------------
  343. bool ctkDICOMRetrievePrivate::get ( const QString& studyInstanceUID,
  344. const QString& seriesInstanceUID,
  345. const RetrieveType retrieveType )
  346. {
  347. Q_Q(ctkDICOMRetrieve);
  348. DcmDataset *retrieveParameters = new DcmDataset();
  349. if (! this->initializeSCU(studyInstanceUID, seriesInstanceUID, retrieveType, retrieveParameters) )
  350. {
  351. delete retrieveParameters;
  352. return false;
  353. }
  354. // Issue request
  355. logger.debug ( "Sending Get Request" );
  356. emit q->progress("Sending Get Request");
  357. emit q->progress(0);
  358. OFList<RetrieveResponse*> responses;
  359. T_ASC_PresentationContextID presID = this->SCU.findPresentationContextID(
  360. UID_GETStudyRootQueryRetrieveInformationModel,
  361. "" /* don't care about transfer syntax */ );
  362. if (presID == 0)
  363. {
  364. logger.error ( "GET Request failed: No valid Study Root GET Presentation Context available" );
  365. if (!this->KeepAssociationOpen)
  366. {
  367. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  368. }
  369. delete retrieveParameters;
  370. return false;
  371. }
  372. emit q->progress("Found Presentation Context");
  373. emit q->progress(1);
  374. // do the actual move request
  375. OFCondition status = this->SCU.sendCGETRequest (
  376. presID, retrieveParameters, &responses );
  377. emit q->progress("Sent Get Request");
  378. emit q->progress(2);
  379. // Close association if we do not want to explicitly keep it open
  380. if (!this->KeepAssociationOpen)
  381. {
  382. this->SCU.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);
  383. }
  384. // Free some (little) memory
  385. delete retrieveParameters;
  386. // If we do not receive a single response, something is fishy
  387. if ( responses.begin() == responses.end() )
  388. {
  389. logger.error ( "No responses received at all! (at least one empty response always expected)" );
  390. //throw std::runtime_error( std::string("No responses received from server!") );
  391. emit q->progress("No Responses from Server!");
  392. return false;
  393. }
  394. emit q->progress("Got Responses");
  395. emit q->progress(3);
  396. /* The server is permitted to acknowledge every image that was received, or
  397. * to send a single move response.
  398. * If there is only a single response, this can mean the following:
  399. * 1) No images to transfer (Status Success and Number of Completed Subops = 0)
  400. * 2) All images transferred (Status Success and Number of Completed Subops > 0)
  401. * 3) Error code, i.e. no images transferred
  402. * 4) Warning (one or more failures, i.e. some images transferred)
  403. */
  404. if ( responses.size() == 1 )
  405. {
  406. RetrieveResponse* rsp = *responses.begin();
  407. logger.debug ( "GET response receveid with status: " +
  408. QString(DU_cmoveStatusString(rsp->m_status)) );
  409. if ( (rsp->m_status == STATUS_Success)
  410. || (rsp->m_status == STATUS_GET_Warning_SubOperationsCompleteOneOrMoreFailures))
  411. {
  412. if (rsp->m_numberOfCompletedSubops == 0)
  413. {
  414. logger.error ( "No images transferred by PACS!" );
  415. //throw std::runtime_error( std::string("No images transferred by PACS!") );
  416. return false;
  417. }
  418. }
  419. else
  420. {
  421. logger.error("GET request failed, server does report error");
  422. QString statusDetail("No details");
  423. if (rsp->m_statusDetail != NULL)
  424. {
  425. std::ostringstream out;
  426. rsp->m_statusDetail->print(out);
  427. statusDetail = "Status Detail: " + statusDetail.fromStdString(out.str());
  428. }
  429. statusDetail.prepend("GET request failed: ");
  430. logger.error(statusDetail);
  431. //throw std::runtime_error( statusDetail.toStdString() );
  432. return false;
  433. }
  434. }
  435. // Select the last GET response to output meaningful status information
  436. OFIterator<RetrieveResponse*> it = responses.begin();
  437. Uint32 numResults = responses.size();
  438. for (Uint32 i = 1; i < numResults; i++)
  439. {
  440. it++;
  441. }
  442. logger.debug ( "GET responses report for study: " + studyInstanceUID +"\n"
  443. + QString::number(static_cast<unsigned int>((*it)->m_numberOfCompletedSubops))
  444. + " images transferred, and\n"
  445. + QString::number(static_cast<unsigned int>((*it)->m_numberOfWarningSubops))
  446. + " images transferred with warning, and\n"
  447. + QString::number(static_cast<unsigned int>((*it)->m_numberOfFailedSubops))
  448. + " images transfers failed");
  449. emit q->progress("Finished Get");
  450. emit q->progress(100);
  451. return true;
  452. }
  453. //------------------------------------------------------------------------------
  454. // ctkDICOMRetrieve methods
  455. //------------------------------------------------------------------------------
  456. ctkDICOMRetrieve::ctkDICOMRetrieve()
  457. : d_ptr(new ctkDICOMRetrievePrivate(*this))
  458. {
  459. Q_D(ctkDICOMRetrieve);
  460. d->SCU.retrieve = this; // give the dcmtk level access to this for emitting signals
  461. }
  462. //------------------------------------------------------------------------------
  463. ctkDICOMRetrieve::~ctkDICOMRetrieve()
  464. {
  465. }
  466. //------------------------------------------------------------------------------
  467. /// Set methods for connectivity
  468. void ctkDICOMRetrieve::setCallingAETitle( const QString& callingAETitle )
  469. {
  470. Q_D(ctkDICOMRetrieve);
  471. if (strcmp(callingAETitle.toStdString().c_str(), d->SCU.getAETitle().c_str()))
  472. {
  473. d->SCU.setAETitle(callingAETitle.toStdString().c_str());
  474. d->ConnectionParamsChanged = true;
  475. }
  476. }
  477. //------------------------------------------------------------------------------
  478. QString ctkDICOMRetrieve::callingAETitle() const
  479. {
  480. Q_D(const ctkDICOMRetrieve);
  481. return d->SCU.getAETitle().c_str();
  482. }
  483. //------------------------------------------------------------------------------
  484. void ctkDICOMRetrieve::setCalledAETitle( const QString& calledAETitle )
  485. {
  486. Q_D(ctkDICOMRetrieve);
  487. if (strcmp(calledAETitle.toStdString().c_str(),d->SCU.getPeerAETitle().c_str()))
  488. {
  489. d->SCU.setPeerAETitle(calledAETitle.toStdString().c_str());
  490. d->ConnectionParamsChanged = true;
  491. }
  492. }
  493. //------------------------------------------------------------------------------
  494. QString ctkDICOMRetrieve::calledAETitle()const
  495. {
  496. Q_D(const ctkDICOMRetrieve);
  497. return d->SCU.getPeerAETitle().c_str();
  498. }
  499. //------------------------------------------------------------------------------
  500. void ctkDICOMRetrieve::setHost( const QString& host )
  501. {
  502. Q_D(ctkDICOMRetrieve);
  503. if (strcmp(host.toStdString().c_str(), d->SCU.getPeerHostName().c_str()))
  504. {
  505. d->SCU.setPeerHostName(host.toStdString().c_str());
  506. d->ConnectionParamsChanged = true;
  507. }
  508. }
  509. //------------------------------------------------------------------------------
  510. QString ctkDICOMRetrieve::host()const
  511. {
  512. Q_D(const ctkDICOMRetrieve);
  513. return d->SCU.getPeerHostName().c_str();
  514. }
  515. //------------------------------------------------------------------------------
  516. void ctkDICOMRetrieve::setPort( int port )
  517. {
  518. Q_D(ctkDICOMRetrieve);
  519. if (d->SCU.getPeerPort() != port)
  520. {
  521. d->SCU.setPeerPort(port);
  522. d->ConnectionParamsChanged = true;
  523. }
  524. }
  525. //------------------------------------------------------------------------------
  526. int ctkDICOMRetrieve::port()const
  527. {
  528. Q_D(const ctkDICOMRetrieve);
  529. return d->SCU.getPeerPort();
  530. }
  531. //------------------------------------------------------------------------------
  532. void ctkDICOMRetrieve::setMoveDestinationAETitle( const QString& moveDestinationAETitle )
  533. {
  534. Q_D(ctkDICOMRetrieve);
  535. if (moveDestinationAETitle != d->MoveDestinationAETitle)
  536. {
  537. d->MoveDestinationAETitle = moveDestinationAETitle;
  538. d->ConnectionParamsChanged = true;
  539. }
  540. }
  541. //------------------------------------------------------------------------------
  542. QString ctkDICOMRetrieve::moveDestinationAETitle()const
  543. {
  544. Q_D(const ctkDICOMRetrieve);
  545. return d->MoveDestinationAETitle;
  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. }