ctkDICOMRetrieveMain.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c)
  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.commontk.org/LICENSE
  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. // Qt includes
  15. #include <QApplication>
  16. #include <QTextStream>
  17. // CTK includes
  18. #include <ctkDICOMRetrieve.h>
  19. #include <ctkDICOMDatabase.h>
  20. #include "ctkLogger.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. #include <fstream>
  25. void print_usage()
  26. {
  27. std::cerr << "Usage:\n";
  28. std::cerr << " ctkDICOMRetrieve StudyUID OutputDirectory callingAETitle callingPort calledAETitle host calledPort moveDestinationAETitle\n";
  29. return;
  30. }
  31. /**
  32. *
  33. */
  34. int main(int argc, char** argv)
  35. {
  36. ctkLogger::configure();
  37. ctkLogger logger ( "org.commontk.dicom.DICOMRetieveApp" );
  38. logger.setDebug();
  39. if (argc < 9)
  40. {
  41. print_usage();
  42. return EXIT_FAILURE;
  43. }
  44. QCoreApplication app(argc, argv);
  45. QTextStream out(stdout);
  46. QString StudyUID ( argv[1] );
  47. QDir OutputDirectory ( argv[2] );
  48. QString CallingAETitle ( argv[3] );
  49. bool ok;
  50. int CallingPort = QString ( argv[4] ).toInt ( &ok );
  51. if ( !ok )
  52. {
  53. std::cerr << "Could not convert " << argv[4] << " to an integer for the callingPort" << std::endl;
  54. print_usage();
  55. return EXIT_FAILURE;
  56. }
  57. QString CalledAETitle ( argv[5] );
  58. QString Host ( argv[6] );
  59. int CalledPort = QString ( argv[7] ).toInt ( &ok );
  60. if ( !ok )
  61. {
  62. std::cerr << "Could not convert " << argv[7] << " to an integer for the calledPoint" << std::endl;
  63. print_usage();
  64. return EXIT_FAILURE;
  65. }
  66. QString MoveDestinationAETitle ( argv[8] );
  67. ctkDICOMRetrieve retrieve;
  68. retrieve.setCallingAETitle ( CallingAETitle );
  69. retrieve.setCallingPort ( CallingPort );
  70. retrieve.setCalledAETitle ( CalledAETitle );
  71. retrieve.setCalledPort ( CalledPort );
  72. retrieve.setHost ( Host );
  73. retrieve.setMoveDestinationAETitle ( MoveDestinationAETitle );
  74. logger.info ( "StudyUID: " + StudyUID + "\n"
  75. + "OutputDirectory: " + OutputDirectory.absolutePath() + "\n"
  76. + "CallingAETitle: " + CallingAETitle + "\n"
  77. + "CallingPort: " + QString::number ( CallingPort ) + "\n"
  78. + "CalledAEtitle: " + CalledAETitle + "\n"
  79. + "Host: " + Host + "\n"
  80. + "CalledPort: " + QString::number ( CalledPort ) + "\n" );
  81. QSharedPointer<ctkDICOMDatabase> dicomDatabase = QSharedPointer<ctkDICOMDatabase> (new ctkDICOMDatabase);
  82. dicomDatabase->openDatabase( OutputDirectory.absoluteFilePath(QString("ctkDICOM.sql")) );
  83. retrieve.setDICOMDatabase( dicomDatabase );
  84. logger.info ( "Starting to retrieve" );
  85. try
  86. {
  87. retrieve.retrieveStudy ( StudyUID );
  88. }
  89. catch (std::exception e)
  90. {
  91. logger.error ( "Retrieve failed" );
  92. return EXIT_FAILURE;
  93. }
  94. logger.info ( "Retrieve success" );
  95. return EXIT_SUCCESS;
  96. }