ctkDICOMRetrieve.cpp 25 KB

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