CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Signals | Public Member Functions | Protected Attributes | Properties | List of all members
ctkDICOMDatabase Class Reference

#include <Libs/DICOM/Core/ctkDICOMDatabase.h>

Inheritance diagram for ctkDICOMDatabase:
Inheritance graph
[legend]
Collaboration diagram for ctkDICOMDatabase:
Collaboration graph
[legend]

Signals

void databaseChanged ()
 Indicates that an in-memory database has been updated. More...
 
void instanceAdded (QString)
 
void patientAdded (int, QString, QString, QString)
 
void schemaUpdated ()
 Indicates schema update finished. More...
 
void schemaUpdateProgress (int)
 Indicates progress in updating schema (int is file number, string is file name) More...
 
void schemaUpdateProgress (QString)
 
void schemaUpdateStarted (int)
 Indicates that the schema is about to be updated and how many files will be processed. More...
 
void seriesAdded (QString)
 
void studyAdded (QString)
 

Public Member Functions

Q_INVOKABLE QStringList allFiles ()
 
Q_INVOKABLE QString cachedTag (const QString sopInstanceUID, const QString tag)
 Return the value of a cached tag. More...
 
Q_INVOKABLE bool cacheTag (const QString sopInstanceUID, const QString tag, const QString value)
 Insert an instance tag's value into to the cache. More...
 
Q_INVOKABLE bool cacheTags (const QStringList sopInstanceUIDs, const QStringList tags, const QStringList values)
 Insert lists of tags into the cache as a batch query operation. More...
 
Q_INVOKABLE bool cleanup ()
 
Q_INVOKABLE void closeDatabase ()
 close the database. It must not be used afterwards. More...
 
 ctkDICOMDatabase (QObject *parent=0)
 
 ctkDICOMDatabase (QString databaseFile)
 
const QSqlDatabase & database () const
 
const QString databaseDirectory () const
 
const QString databaseFilename () const
 
Q_INVOKABLE QString descriptionForSeries (const QString seriesUID)
 
Q_INVOKABLE QString descriptionForStudy (const QString studyUID)
 
Q_INVOKABLE QHash< QString, QString > descriptionsForFile (QString fileName)
 
Q_INVOKABLE bool fileExistsAndUpToDate (const QString &filePath)
 Check if file is already in database and up-to-date. More...
 
Q_INVOKABLE QString fileForInstance (const QString sopInstanceUID)
 
Q_INVOKABLE QStringList filesForSeries (const QString seriesUID)
 
Q_INVOKABLE QString fileValue (const QString fileName, const QString tag)
 
Q_INVOKABLE QString fileValue (const QString fileName, const unsigned short group, const unsigned short element)
 
Q_INVOKABLE QString groupElementToTag (const unsigned short &group, const unsigned short &element)
 
Q_INVOKABLE QStringList headerKeys ()
 
Q_INVOKABLE QString headerValue (const QString key)
 
Q_INVOKABLE bool initializeDatabase (const char *schemaFile=":/dicom/dicom-schema.sql")
 delete all data and (re-)initialize the database. More...
 
Q_INVOKABLE bool initializeTagCache ()
 Create a tagCache in the current database. Delete the existing one if it exists. More...
 
Q_INVOKABLE void insert (const ctkDICOMItem &ctkDataset, bool storeFile, bool generateThumbnail)
 
Q_INVOKABLE void insert (const QString &filePath, bool storeFile=true, bool generateThumbnail=true, bool createHierarchy=true, const QString &destinationDirectoryName=QString())
 
void insert (DcmItem *item, bool storeFile=true, bool generateThumbnail=true)
 
Q_INVOKABLE QDateTime insertDateTimeForInstance (const QString fileName)
 
Q_INVOKABLE QString instanceForFile (const QString fileName)
 
Q_INVOKABLE QStringList instancesForSeries (const QString seriesUID)
 
Q_INVOKABLE QString instanceValue (const QString sopInstanceUID, const QString tag)
 access element values for given instance More...
 
Q_INVOKABLE QString instanceValue (const QString sopInstanceUID, const unsigned short group, const unsigned short element)
 
bool isInMemory () const
 
bool isOpen () const
 
const QString lastError () const
 
Q_INVOKABLE void loadFileHeader (const QString fileName)
 
Q_INVOKABLE void loadInstanceHeader (const QString sopInstanceUID)
 load the header from a file and allow access to elements More...
 
Q_INVOKABLE QString nameForPatient (const QString patientUID)
 
virtual Q_INVOKABLE void openDatabase (const QString databaseFile, const QString &connectionName="")
 
Q_INVOKABLE QString patientForStudy (QString studyUID)
 
Q_INVOKABLE QStringList patients ()
 database accessors More...
 
Q_INVOKABLE void prepareInsert ()
 
Q_INVOKABLE bool removePatient (const QString &patientID)
 
Q_INVOKABLE bool removeSeries (const QString &seriesInstanceUID)
 
Q_INVOKABLE bool removeStudy (const QString &studyInstanceUID)
 
Q_INVOKABLE QString schemaVersion ()
 returns the schema version needed by the current version of this code More...
 
Q_INVOKABLE QString schemaVersionLoaded ()
 
Q_INVOKABLE QString seriesForFile (QString fileName)
 
Q_INVOKABLE QStringList seriesForStudy (const QString studyUID)
 
void setTagsToPrecache (const QStringList tags)
 application-defined tags of interest This list of tags is added to the internal tag cache during import operations. The list should be prepared by the application as a hint to the database that these tags are likely to be accessed later. Internally, the database will cache the values of these tags so that subsequent calls to fileValue or instanceValue will be able to use the cache rather than re-reading the file. More...
 
Q_INVOKABLE void setThumbnailGenerator (ctkDICOMAbstractThumbnailGenerator *generator)
 set thumbnail generator object More...
 
Q_INVOKABLE QStringList studiesForPatient (const QString patientUID)
 
Q_INVOKABLE QString studyForSeries (QString seriesUID)
 
Q_INVOKABLE bool tagCacheExists ()
 store values of previously requested instance elements These are meant to be internal methods used by the instanceValue and fileValue methods, but they can be used by calling classes to populate or access instance tag values as needed. More...
 
const QStringList tagsToPrecache ()
 
Q_INVOKABLE bool tagToGroupElement (const QString tag, unsigned short &group, unsigned short &element)
 
Q_INVOKABLE ctkDICOMAbstractThumbnailGeneratorthumbnailGenerator ()
 get thumbnail genrator object More...
 
Q_INVOKABLE bool updateSchema (const char *schemaFile=":/dicom/dicom-schema.sql")
 updates the database schema and reinserts all existing files More...
 
Q_INVOKABLE bool updateSchemaIfNeeded (const char *schemaFile=":/dicom/dicom-schema.sql")
 
virtual ~ctkDICOMDatabase ()
 

Protected Attributes

QScopedPointer< ctkDICOMDatabasePrivate > d_ptr
 

Properties

QString databaseDirectory
 
QString databaseFilename
 
bool isInMemory
 
bool isOpen
 
QString lastError
 
QStringList tagsToPrecache
 

Detailed Description

Class handling a database of DICOM objects. So far, an underlying SQLITE database is used for that. Usually, added DICOM objects are also stored within the file system. The SQLITE database file can be specified by the user. SQLITE (and this class) also support a special in memory mode, where no database file is created but the database is completely kept in memory (and after exiting the program, vanishes). If in "memory mode", the objects are not written to disk, otherwise they are stored in a subdirectory of the SQLITE database file directory called "dicom". Inside, a folder structure created which contains a directoy for each study, containing a directory for each series, containing a file for each object. The corresponding UIDs are used as filenames. Thumbnais for each image can be created; if so, they are stored in a directory parallel to "dicom" directory called "thumbs".

Definition at line 52 of file ctkDICOMDatabase.h.

Constructor & Destructor Documentation

◆ ctkDICOMDatabase() [1/2]

ctkDICOMDatabase::ctkDICOMDatabase ( QObject *  parent = 0)
explicit

◆ ctkDICOMDatabase() [2/2]

ctkDICOMDatabase::ctkDICOMDatabase ( QString  databaseFile)
explicit

◆ ~ctkDICOMDatabase()

virtual ctkDICOMDatabase::~ctkDICOMDatabase ( )
virtual

Member Function Documentation

◆ allFiles()

Q_INVOKABLE QStringList ctkDICOMDatabase::allFiles ( )

◆ cachedTag()

Q_INVOKABLE QString ctkDICOMDatabase::cachedTag ( const QString  sopInstanceUID,
const QString  tag 
)

Return the value of a cached tag.

◆ cacheTag()

Q_INVOKABLE bool ctkDICOMDatabase::cacheTag ( const QString  sopInstanceUID,
const QString  tag,
const QString  value 
)

Insert an instance tag's value into to the cache.

◆ cacheTags()

Q_INVOKABLE bool ctkDICOMDatabase::cacheTags ( const QStringList  sopInstanceUIDs,
const QStringList  tags,
const QStringList  values 
)

Insert lists of tags into the cache as a batch query operation.

◆ cleanup()

Q_INVOKABLE bool ctkDICOMDatabase::cleanup ( )

◆ closeDatabase()

Q_INVOKABLE void ctkDICOMDatabase::closeDatabase ( )

close the database. It must not be used afterwards.

◆ database()

const QSqlDatabase& ctkDICOMDatabase::database ( ) const

◆ databaseChanged

void ctkDICOMDatabase::databaseChanged ( )
signal

Indicates that an in-memory database has been updated.

◆ databaseDirectory()

const QString ctkDICOMDatabase::databaseDirectory ( ) const

Returns the absolute path of the database directory (where the database file resides in) in OS-prefered path format.

Returns
Absolute path to database directory

◆ databaseFilename()

const QString ctkDICOMDatabase::databaseFilename ( ) const

◆ descriptionForSeries()

Q_INVOKABLE QString ctkDICOMDatabase::descriptionForSeries ( const QString  seriesUID)

◆ descriptionForStudy()

Q_INVOKABLE QString ctkDICOMDatabase::descriptionForStudy ( const QString  studyUID)

◆ descriptionsForFile()

Q_INVOKABLE QHash<QString,QString> ctkDICOMDatabase::descriptionsForFile ( QString  fileName)

◆ fileExistsAndUpToDate()

Q_INVOKABLE bool ctkDICOMDatabase::fileExistsAndUpToDate ( const QString &  filePath)

Check if file is already in database and up-to-date.

◆ fileForInstance()

Q_INVOKABLE QString ctkDICOMDatabase::fileForInstance ( const QString  sopInstanceUID)

◆ filesForSeries()

Q_INVOKABLE QStringList ctkDICOMDatabase::filesForSeries ( const QString  seriesUID)

◆ fileValue() [1/2]

Q_INVOKABLE QString ctkDICOMDatabase::fileValue ( const QString  fileName,
const QString  tag 
)

◆ fileValue() [2/2]

Q_INVOKABLE QString ctkDICOMDatabase::fileValue ( const QString  fileName,
const unsigned short  group,
const unsigned short  element 
)

◆ groupElementToTag()

Q_INVOKABLE QString ctkDICOMDatabase::groupElementToTag ( const unsigned short &  group,
const unsigned short &  element 
)

◆ headerKeys()

Q_INVOKABLE QStringList ctkDICOMDatabase::headerKeys ( )

◆ headerValue()

Q_INVOKABLE QString ctkDICOMDatabase::headerValue ( const QString  key)

◆ initializeDatabase()

Q_INVOKABLE bool ctkDICOMDatabase::initializeDatabase ( const char *  schemaFile = ":/dicom/dicom-schema.sql")

delete all data and (re-)initialize the database.

◆ initializeTagCache()

Q_INVOKABLE bool ctkDICOMDatabase::initializeTagCache ( )

Create a tagCache in the current database. Delete the existing one if it exists.

◆ insert() [1/3]

Q_INVOKABLE void ctkDICOMDatabase::insert ( const ctkDICOMItem ctkDataset,
bool  storeFile,
bool  generateThumbnail 
)

Insert into the database if not already exsting.

Parameters
datasetThe dataset to store into the database. Usually, this is is a complete DICOM object, like a complete image. However the database also inserts partial objects, like studyl information to the database, even if no image data is contained. This can be helpful to store results from querying the PACS for patient/study/series or image information, where a full hierarchy is only constructed after some queries.
storeFileIf store file is set (default), then the dataset will be stored to disk. Note that in case of a memory-only database, this flag is ignored. Usually, this flag does only make sense if a full object is received.

◆ insert() [2/3]

Q_INVOKABLE void ctkDICOMDatabase::insert ( const QString &  filePath,
bool  storeFile = true,
bool  generateThumbnail = true,
bool  createHierarchy = true,
const QString &  destinationDirectoryName = QString() 
)

◆ insert() [3/3]

void ctkDICOMDatabase::insert ( DcmItem *  item,
bool  storeFile = true,
bool  generateThumbnail = true 
)

◆ insertDateTimeForInstance()

Q_INVOKABLE QDateTime ctkDICOMDatabase::insertDateTimeForInstance ( const QString  fileName)

◆ instanceAdded

void ctkDICOMDatabase::instanceAdded ( QString  )
signal

instance UID is provided instanceAdded arguments:

  • instanceUID (unique)

◆ instanceForFile()

Q_INVOKABLE QString ctkDICOMDatabase::instanceForFile ( const QString  fileName)

◆ instancesForSeries()

Q_INVOKABLE QStringList ctkDICOMDatabase::instancesForSeries ( const QString  seriesUID)

◆ instanceValue() [1/2]

Q_INVOKABLE QString ctkDICOMDatabase::instanceValue ( const QString  sopInstanceUID,
const QString  tag 
)

access element values for given instance

Parameters
sopInstanceUIDA string with the uid for a given instance (corresponding file will be found via database)
fileNameFull path to a dicom file to load.
keyA group,element tag in zero-filled hex
groupThe group portion of the tag as an integer
elementThe element portion of the tag as an integer @Returns empty string if element is missing

◆ instanceValue() [2/2]

Q_INVOKABLE QString ctkDICOMDatabase::instanceValue ( const QString  sopInstanceUID,
const unsigned short  group,
const unsigned short  element 
)

◆ isInMemory()

bool ctkDICOMDatabase::isInMemory ( ) const

Returns whether the database only resides in memory, i.e. the SQLITE DB is not written to stored to disk and DICOM objects are not stored to the file system.

Returns
True if in memory mode, false otherwise.

◆ isOpen()

bool ctkDICOMDatabase::isOpen ( ) const

Should be checked after trying to open the database @Returns true if database is open

◆ lastError()

const QString ctkDICOMDatabase::lastError ( ) const

◆ loadFileHeader()

Q_INVOKABLE void ctkDICOMDatabase::loadFileHeader ( const QString  fileName)

◆ loadInstanceHeader()

Q_INVOKABLE void ctkDICOMDatabase::loadInstanceHeader ( const QString  sopInstanceUID)

load the header from a file and allow access to elements

Parameters
sopInstanceUIDA string with the uid for a given instance (corresponding file will be found via database)
fileNameFull path to a dicom file to load.
keyA group,element tag in zero-filled hex

◆ nameForPatient()

Q_INVOKABLE QString ctkDICOMDatabase::nameForPatient ( const QString  patientUID)

◆ openDatabase()

virtual Q_INVOKABLE void ctkDICOMDatabase::openDatabase ( const QString  databaseFile,
const QString &  connectionName = "" 
)
virtual

open the SQLite database in

Parameters
databaseFile. If the file does not exist, a new database is created and initialized with the default schema
databaseFileThe file to store the SQLITE database should be stored to. If specified with ":memory:", the database is not written to disk at all but instead only kept in memory (and thus expires after destruction of this object).
connectionNameThe database connection name. If not specified then a random name is generated (reusing a connection name must be avoided as it breaks previously created database object that used the same connection name).
updatethe schema if it is found to be out of date

◆ patientAdded

void ctkDICOMDatabase::patientAdded ( int  ,
QString  ,
QString  ,
QString   
)
signal

Things inserted to database. patientAdded arguments:

  • int: database index of patient (unique) within CTK database
  • QString: patient ID (not unique across institutions)
  • QString: patient Name (not unique)
  • QString: patient Birth Date (not unique)

◆ patientForStudy()

Q_INVOKABLE QString ctkDICOMDatabase::patientForStudy ( QString  studyUID)

◆ patients()

Q_INVOKABLE QStringList ctkDICOMDatabase::patients ( )

database accessors

◆ prepareInsert()

Q_INVOKABLE void ctkDICOMDatabase::prepareInsert ( )

Reset cached item IDs to make sure previous inserts do not interfere with upcoming insert operations. Typically, it should be call just before a batch of files insertion is started.

This has to be called before an insert() call if there is a chance that items have been deleted from the database since the the last insert() call. If there has been not been any insert() calls since connected to the database, then it should be called before the first insert().

◆ removePatient()

Q_INVOKABLE bool ctkDICOMDatabase::removePatient ( const QString &  patientID)

◆ removeSeries()

Q_INVOKABLE bool ctkDICOMDatabase::removeSeries ( const QString &  seriesInstanceUID)

remove the series from the database, including images and thumbnails

◆ removeStudy()

Q_INVOKABLE bool ctkDICOMDatabase::removeStudy ( const QString &  studyInstanceUID)

◆ schemaUpdated

void ctkDICOMDatabase::schemaUpdated ( )
signal

Indicates schema update finished.

◆ schemaUpdateProgress [1/2]

void ctkDICOMDatabase::schemaUpdateProgress ( int  )
signal

Indicates progress in updating schema (int is file number, string is file name)

◆ schemaUpdateProgress [2/2]

void ctkDICOMDatabase::schemaUpdateProgress ( QString  )
signal

◆ schemaUpdateStarted

void ctkDICOMDatabase::schemaUpdateStarted ( int  )
signal

Indicates that the schema is about to be updated and how many files will be processed.

◆ schemaVersion()

Q_INVOKABLE QString ctkDICOMDatabase::schemaVersion ( )

returns the schema version needed by the current version of this code

◆ schemaVersionLoaded()

Q_INVOKABLE QString ctkDICOMDatabase::schemaVersionLoaded ( )

returns the schema version for the currently open database in order to support schema updating

◆ seriesAdded

void ctkDICOMDatabase::seriesAdded ( QString  )
signal

seriesAdded arguments:

  • seriesUID (unique)

◆ seriesForFile()

Q_INVOKABLE QString ctkDICOMDatabase::seriesForFile ( QString  fileName)

◆ seriesForStudy()

Q_INVOKABLE QStringList ctkDICOMDatabase::seriesForStudy ( const QString  studyUID)

◆ setTagsToPrecache()

void ctkDICOMDatabase::setTagsToPrecache ( const QStringList  tags)

application-defined tags of interest This list of tags is added to the internal tag cache during import operations. The list should be prepared by the application as a hint to the database that these tags are likely to be accessed later. Internally, the database will cache the values of these tags so that subsequent calls to fileValue or instanceValue will be able to use the cache rather than re-reading the file.

Parameters
tagsshould be a list of ascii hex group/element tags like "0008,0008" as in the instanceValue and fileValue calls

◆ setThumbnailGenerator()

Q_INVOKABLE void ctkDICOMDatabase::setThumbnailGenerator ( ctkDICOMAbstractThumbnailGenerator generator)

set thumbnail generator object

◆ studiesForPatient()

Q_INVOKABLE QStringList ctkDICOMDatabase::studiesForPatient ( const QString  patientUID)

◆ studyAdded

void ctkDICOMDatabase::studyAdded ( QString  )
signal

studyAdded arguments:

  • studyUID (unique)

◆ studyForSeries()

Q_INVOKABLE QString ctkDICOMDatabase::studyForSeries ( QString  seriesUID)

◆ tagCacheExists()

Q_INVOKABLE bool ctkDICOMDatabase::tagCacheExists ( )

store values of previously requested instance elements These are meant to be internal methods used by the instanceValue and fileValue methods, but they can be used by calling classes to populate or access instance tag values as needed.

Parameters
sopInstanceUIDA string with the uid for a given instance (corresponding file will be found via database)
keyA group,element tag in zero-filled hex @Returns empty string if element for uid is missing from cache

Lightweight check of tag cache existence (once db check per runtime)

◆ tagsToPrecache()

const QStringList ctkDICOMDatabase::tagsToPrecache ( )

◆ tagToGroupElement()

Q_INVOKABLE bool ctkDICOMDatabase::tagToGroupElement ( const QString  tag,
unsigned short &  group,
unsigned short &  element 
)

◆ thumbnailGenerator()

Q_INVOKABLE ctkDICOMAbstractThumbnailGenerator* ctkDICOMDatabase::thumbnailGenerator ( )

get thumbnail genrator object

◆ updateSchema()

Q_INVOKABLE bool ctkDICOMDatabase::updateSchema ( const char *  schemaFile = ":/dicom/dicom-schema.sql")

updates the database schema and reinserts all existing files

◆ updateSchemaIfNeeded()

Q_INVOKABLE bool ctkDICOMDatabase::updateSchemaIfNeeded ( const char *  schemaFile = ":/dicom/dicom-schema.sql")

updates the database schema only if the versions don't match Returns true if schema was updated

Member Data Documentation

◆ d_ptr

QScopedPointer<ctkDICOMDatabasePrivate> ctkDICOMDatabase::d_ptr
protected

Definition at line 291 of file ctkDICOMDatabase.h.

Property Documentation

◆ databaseDirectory

QString ctkDICOMDatabase::databaseDirectory
read

Definition at line 1 of file ctkDICOMDatabase.h.

◆ databaseFilename

QString ctkDICOMDatabase::databaseFilename
read

Definition at line 1 of file ctkDICOMDatabase.h.

◆ isInMemory

bool ctkDICOMDatabase::isInMemory
read

Definition at line 1 of file ctkDICOMDatabase.h.

◆ isOpen

bool ctkDICOMDatabase::isOpen
read

Definition at line 1 of file ctkDICOMDatabase.h.

◆ lastError

QString ctkDICOMDatabase::lastError
read

Definition at line 1 of file ctkDICOMDatabase.h.

◆ tagsToPrecache

QStringList ctkDICOMDatabase::tagsToPrecache
readwrite

Definition at line 1 of file ctkDICOMDatabase.h.


The documentation for this class was generated from the following file: