ctkDICOMModelTest1.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // Qt includes
  15. #include <QCoreApplication>
  16. #include <QDebug>
  17. #include <QFileInfo>
  18. #include <QSqlQuery>
  19. // ctkDICOMCore includes
  20. #include "ctkDICOMDatabase.h"
  21. #include "ctkDICOMModel.h"
  22. #include "ctkModelTester.h"
  23. // STD includes
  24. #include <iostream>
  25. /* Test from build directory:
  26. ./CTK-build/bin/CTKDICOMCoreCxxTests ctkDICOMModelTest1 test.db ../CTK/Libs/DICOM/Core/Resources/dicom-sample.sql
  27. If you want a test with a GUI, look at ctkDICOMTest2 in DICOM/Widgets
  28. */
  29. int ctkDICOMModelTest1( int argc, char * argv [] )
  30. {
  31. QCoreApplication app(argc, argv);
  32. if (argc <= 2)
  33. {
  34. std::cerr << "Warning, no sql file given. Test stops" << std::endl;
  35. std::cerr << "Usage: qctkDICOMModelTest1 <scratch.db> <dumpfile.sql>" << std::endl;
  36. return EXIT_FAILURE;
  37. }
  38. try
  39. {
  40. ctkDICOMDatabase myCTK( argv[1] );
  41. if (!myCTK.initializeDatabase(argv[2]))
  42. {
  43. std::cerr << "Error when initializing the data base: " << argv[2]
  44. << " error: " << myCTK.lastError().toStdString();
  45. }
  46. /*
  47. QSqlQuery toto("SELECT PatientsName as 'Name tt' FROM Patients ORDER BY \"Name tt\" ASC", myCTK.database());
  48. qDebug() << "toto: " << myCTK.lastError() ;
  49. qDebug()<< toto.seek(0) << myCTK.lastError();
  50. qDebug() << toto.value(0).toString() << myCTK.lastError();
  51. QSqlQuery titi("SELECT StudyID as UID, StudyDescription as Name, ModalitiesInStudy as Scan, StudyDate as Date, AccessionNumber as Number, ReferringPhysician as Institution, ReferringPhysician as Referrer, PerformingPysiciansName as Performer FROM Studies WHERE PatientsUID='14'", myCTK.database());
  52. qDebug() << "titi: " << titi.seek(0) << myCTK.lastError();
  53. QSqlQuery tata("SELECT SeriesInstanceUID as UID, BodyPartExamined as Scan, SeriesDate as Date, AcquisitionNumber as Number FROM Series WHERE StudyInstanceUID='1.2.826.0.1.3680043.2.1125.1.73379483469717886505187028001198162'", myCTK.database());
  54. qDebug() << "tata: " << tata.seek(0) << myCTK.lastError();
  55. QSqlQuery tutu("SELECT SOPInstanceUID as UID, Filename as Name, SeriesInstanceUID as Date FROM Images WHERE SeriesInstanceUID='%1'", myCTK.database());
  56. qDebug() << "tutu: " << tutu.seek(0) << myCTK.lastError();
  57. */
  58. ctkModelTester tester;
  59. tester.setNestedInserts(true);
  60. tester.setThrowOnError(false);
  61. ctkDICOMModel model;
  62. tester.setModel(&model);
  63. model.setDatabase(myCTK.database());
  64. model.setDatabase(QSqlDatabase());
  65. model.setDatabase(myCTK.database());
  66. model.rowCount();
  67. qDebug() << model.rowCount() << model.columnCount();
  68. qDebug() << model.index(0,0);
  69. return EXIT_SUCCESS;
  70. }
  71. catch (std::exception e)
  72. {
  73. std::cerr << "Error when opening the data base file: " << argv[1]
  74. << " error: " << e.what();
  75. return EXIT_FAILURE;
  76. }
  77. }