ctkDICOMDatabase.h 6.6 KB

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