ctkDICOMRetrieveMain.cpp 3.1 KB

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