ctkDICOMQueryMain.cpp 2.6 KB

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