ctkDICOMQueryMain.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* Notes:
  15. *
  16. * This program is a test driver for the DcmScu class and puts the results
  17. * in an sqlite database. This command will query a public dicom server:
  18. *
  19. * ../CTK-build/bin/ctkDICOMQuery test.db FINDSCU MI2B2 mi2b2.slicer.org 11112
  20. * or this one:
  21. * ../CTK-build/bin/ctkDICOMQuery test.db FINDSCU DICOMSERVER dicomserver.co.uk 11112
  22. *
  23. * you can get a similar
  24. * functionality with this command line:
  25. *
  26. * findscu --verbose -aec MI2B2 -P -k "0010,0010=F*" mi2b2.slicer.org 11112 patqry.dcm | grep Patients
  27. *
  28. */
  29. // Qt includes
  30. #include <QApplication>
  31. #include <QTextStream>
  32. // CTK includes
  33. #include <ctkDICOMQuery.h>
  34. #include <ctkDICOMDatabase.h>
  35. #include "ctkLogger.h"
  36. // DCMTK includes
  37. #include "dcmtk/oflog/oflog.h"
  38. // STD includes
  39. #include <cstdlib>
  40. #include <iostream>
  41. #include <fstream>
  42. void print_usage()
  43. {
  44. std::cerr << "Usage:\n";
  45. std::cerr << " ctkDICOMQuery database callingAETitle calledAETitle host port\n";
  46. return;
  47. }
  48. /**
  49. *
  50. */
  51. int main(int argc, char** argv)
  52. {
  53. ctkLogger::configure();
  54. ctkLogger logger ( "org.commontk.core.Logger" );
  55. logger.setDebug();
  56. if (argc < 5)
  57. {
  58. print_usage();
  59. return EXIT_FAILURE;
  60. }
  61. QCoreApplication app(argc, argv);
  62. QTextStream out(stdout);
  63. ctkDICOMDatabase myCTK;
  64. logger.debug ( "Opening database " + QString ( argv[1] ) );
  65. myCTK.openDatabase ( argv[1] );
  66. logger.debug ( "Last error: " + myCTK.lastError() );
  67. if ( myCTK.database().isOpen() )
  68. {
  69. logger.debug ( "Database is open" );
  70. }
  71. else
  72. {
  73. logger.debug ( "Database is not open" );
  74. }
  75. ctkDICOMQuery query;
  76. query.setCallingAETitle ( QString ( argv[2] ) );
  77. query.setCalledAETitle ( QString ( argv[3] ) );
  78. query.setHost ( QString ( argv[4] ) );
  79. int port;
  80. bool ok;
  81. port = QString ( argv[5] ).toInt ( &ok );
  82. if ( !ok )
  83. {
  84. std::cerr << "Could not convert " << argv[5] << " to an integer" << std::endl;
  85. print_usage();
  86. return EXIT_FAILURE;
  87. }
  88. query.setPort ( port );
  89. try
  90. {
  91. query.query ( myCTK );
  92. }
  93. catch (std::exception e)
  94. {
  95. return EXIT_FAILURE;
  96. }
  97. return EXIT_SUCCESS;
  98. }