ctkDICOMDatabase.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. Q_PROPERTY(bool isOpen READ isOpen)
  41. Q_PROPERTY(QString lastError READ lastError)
  42. Q_PROPERTY(QString databaseFilename READ databaseFilename)
  43. public:
  44. explicit ctkDICOMDatabase(QObject *parent = 0);
  45. explicit ctkDICOMDatabase(QString databaseFile);
  46. virtual ~ctkDICOMDatabase();
  47. const QSqlDatabase& database() const;
  48. const QString lastError() const;
  49. const QString databaseFilename() const;
  50. ///
  51. /// Returns the absolute path of the database directory
  52. /// (where the database file resides in) in OS-prefered path format.
  53. /// @return Absolute path to database directory
  54. const QString databaseDirectory() const;
  55. ///
  56. /// Should be checked after trying to open the database
  57. /// @Returns true if database is open
  58. bool isOpen() const;
  59. ///
  60. /// Returns whether the database only resides in memory, i.e. the
  61. /// SQLITE DB is not written to stored to disk and DICOM objects are not
  62. /// stored to the file system.
  63. /// @return True if in memory mode, false otherwise.
  64. bool isInMemory() const;
  65. ///
  66. /// set thumbnail generator object
  67. void setThumbnailGenerator(ctkDICOMAbstractThumbnailGenerator* generator);
  68. ///
  69. /// get thumbnail genrator object
  70. ctkDICOMAbstractThumbnailGenerator* thumbnailGenerator();
  71. ///
  72. /// open the SQLite database in @param databaseFile . If the file does not
  73. /// exist, a new database is created and initialized with the
  74. /// default schema
  75. ///
  76. /// @param databaseFile The file to store the SQLITE database should be
  77. /// stored to. If specified with ":memory:", the database is not
  78. /// written to disk at all but instead only kept in memory (and
  79. /// thus expires after destruction of this object).
  80. /// @param connectionName The database connection name.
  81. Q_INVOKABLE virtual void openDatabase(const QString databaseFile,
  82. const QString& connectionName = "DICOM-DB" );
  83. ///
  84. /// close the database. It must not be used afterwards.
  85. Q_INVOKABLE void closeDatabase();
  86. ///
  87. /// delete all data and reinitialize the database.
  88. Q_INVOKABLE bool initializeDatabase(const char* schemaFile = ":/dicom/dicom-schema.sql");
  89. ///
  90. /// \brief database accessors
  91. Q_INVOKABLE QStringList patients ();
  92. Q_INVOKABLE QStringList studiesForPatient (QString patientUID);
  93. Q_INVOKABLE QStringList seriesForStudy (QString studyUID);
  94. Q_INVOKABLE QStringList filesForSeries (QString seriesUID);
  95. ///
  96. /// \brief load the header from a file and allow access to elements
  97. Q_INVOKABLE void loadInstanceHeader (QString sopInstanceUID);
  98. Q_INVOKABLE void loadFileHeader (QString fileName);
  99. Q_INVOKABLE QStringList headerKeys ();
  100. Q_INVOKABLE QString headerValue (QString key);
  101. /// Insert into the database if not already exsting.
  102. /// @param dataset The dataset to store into the database. Usually, this is
  103. /// is a complete DICOM object, like a complete image. However
  104. /// the database also inserts partial objects, like studyl
  105. /// information to the database, even if no image data is
  106. /// contained. This can be helpful to store results from
  107. /// querying the PACS for patient/study/series or image
  108. /// information, where a full hierarchy is only constructed
  109. /// after some queries.
  110. /// @param storeFile If store file is set (default), then the dataset will
  111. /// be stored to disk. Note that in case of a memory-only
  112. /// database, this flag is ignored. Usually, this flag
  113. /// does only make sense if a full object is received.
  114. /// @param @generateThumbnail If true, a thumbnail is generated.
  115. ///
  116. void insert ( DcmDataset *dataset, bool storeFile = true, bool generateThumbnail = true);
  117. ///
  118. /// Helper method: get the path that should be used to store this image.
  119. ///
  120. QString pathForDataset( DcmDataset *dataset);
  121. signals:
  122. void databaseChanged();
  123. protected:
  124. QScopedPointer<ctkDICOMDatabasePrivate> d_ptr;
  125. private:
  126. Q_DECLARE_PRIVATE(ctkDICOMDatabase);
  127. Q_DISABLE_COPY(ctkDICOMDatabase);
  128. };
  129. #endif