ctkDICOMDatabase.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010
  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. #ifndef __ctkDICOMDatabase_h
  15. #define __ctkDICOMDatabase_h
  16. // Qt includes
  17. #include <QObject>
  18. #include <QStringList>
  19. #include <QSqlDatabase>
  20. #include "ctkDICOMCoreExport.h"
  21. class ctkDICOMDatabasePrivate;
  22. class DcmDataset;
  23. class ctkDICOMAbstractThumbnailGenerator;
  24. /// Class handling a database of DICOM objects. So far, an underlying
  25. /// SQLITE database is used for that. Usually, added DICOM objects are also
  26. /// stored within the file system.
  27. /// The SQLITE database file can be specified by the user. SQLITE (and this
  28. /// class) also support a special in memory mode, where no database file is created
  29. /// but the database is completely kept in memory (and after exiting the program,
  30. /// vanishes). If in "memory mode", the objects are not written to disk,
  31. /// otherwise they are stored in a subdirectory of the SQLITE database file
  32. /// directory called "dicom". Inside, a folder structure created which contains
  33. /// a directoy for each study, containing a directory for each series, containing
  34. /// a file for each object. The corresponding UIDs are used as filenames.
  35. /// Thumbnais for each image can be created; if so, they are stored in a directory
  36. /// parallel to "dicom" directory called "thumbs".
  37. class CTK_DICOM_CORE_EXPORT ctkDICOMDatabase : public QObject
  38. {
  39. Q_OBJECT
  40. public:
  41. explicit ctkDICOMDatabase(QObject *parent = 0);
  42. explicit ctkDICOMDatabase(QString databaseFile);
  43. virtual ~ctkDICOMDatabase();
  44. const QSqlDatabase& database() const;
  45. const QString lastError() const;
  46. const QString databaseFilename() const;
  47. ///
  48. /// Returns the absolute path of the database directory
  49. /// (where the database file resides in) in OS-prefered path format.
  50. /// @return Absolute path to database directory
  51. const QString databaseDirectory() const;
  52. ///
  53. /// Returns whether the database only resides in memory, i.e. the
  54. /// SQLITE DB is not written to stored to disk and DICOM objects are not
  55. /// stored to the file system.
  56. /// @return True if in memory mode, false otherwise.
  57. bool isInMemory() const;
  58. ///
  59. /// set thumbnail generator object
  60. void setThumbnailGenerator(ctkDICOMAbstractThumbnailGenerator* generator);
  61. ///
  62. /// get thumbnail genrator object
  63. ctkDICOMAbstractThumbnailGenerator* thumbnailGenerator();
  64. ///
  65. /// open the SQLite database in @param databaseFile . If the file does not
  66. /// exist, a new database is created and initialized with the
  67. /// default schema
  68. ///
  69. /// @param databaseFile The file to store the SQLITE database should be
  70. /// stored to. If specified with ":memory:", the database is not
  71. /// written to disk at all but instead only kept in memory (and
  72. /// thus expires after destruction of this object).
  73. /// @param connectionName The database connection name.
  74. Q_INVOKABLE virtual void openDatabase(const QString databaseFile,
  75. const QString& connectionName = "DICOM-DB" );
  76. ///
  77. /// close the database. It must not be used afterwards.
  78. Q_INVOKABLE void closeDatabase();
  79. ///
  80. /// delete all data and reinitialize the database.
  81. Q_INVOKABLE bool initializeDatabase(const char* schemaFile = ":/dicom/dicom-schema.sql");
  82. ///
  83. /// \brief database accessors
  84. Q_INVOKABLE QStringList studiesForPatient (QString patientUID);
  85. Q_INVOKABLE QStringList seriesForStudy (QString studyUID);
  86. Q_INVOKABLE QStringList filesForSeries (QString seriesUID);
  87. ///
  88. /// \brief load the header from a file and allow access to elements
  89. Q_INVOKABLE void loadInstanceHeader (QString sopInstanceUID);
  90. Q_INVOKABLE void loadFileHeader (QString fileName);
  91. Q_INVOKABLE QStringList headerKeys ();
  92. Q_INVOKABLE QString headerValue (QString key);
  93. /** Insert into the database if not already exsting.
  94. * @param dataset The dataset to store into the database. Usually, this is
  95. * is a complete DICOM object, like a complete image. However
  96. * the database also inserts partial objects, like studyl
  97. * information to the database, even if no image data is
  98. * contained. This can be helpful to store results from
  99. * querying the PACS for patient/study/series or image
  100. * information, where a full hierarchy is only constructed
  101. * after some queries.
  102. * @param storeFile If store file is set (default), then the dataset will
  103. * be stored to disk. Note that in case of a memory-only
  104. * database, this flag is ignored. Usually, this flag
  105. * does only make sense if a full object is received.
  106. * @param @generateThumbnail If true, a thumbnail is generated.
  107. */
  108. void insert ( DcmDataset *dataset, bool storeFile = true, bool generateThumbnail = true);
  109. /***
  110. * Helper method: get the path that should be used to store this image.
  111. */
  112. QString pathForDataset( DcmDataset *dataset);
  113. signals:
  114. void databaseChanged();
  115. protected:
  116. QScopedPointer<ctkDICOMDatabasePrivate> d_ptr;
  117. private:
  118. Q_DECLARE_PRIVATE(ctkDICOMDatabase);
  119. Q_DISABLE_COPY(ctkDICOMDatabase);
  120. };
  121. #endif