Browse Source

Merge branch '218-fileindex'

Closes #218

* 218-fileindex:
  Improve schema update documentation
  Update schema to include index on filenames
  Style: put schema version in implementation not header
Steve Pieper 12 years ago
parent
commit
ebd8994bf9

+ 5 - 1
Libs/DICOM/Core/Resources/dicom-schema.sql

@@ -13,8 +13,10 @@ DROP TABLE IF EXISTS 'Series' ;
 DROP TABLE IF EXISTS 'Studies' ;
 DROP TABLE IF EXISTS 'Directories' ;
 
+DROP INDEX IF EXISTS 'ImagesFilenameIndex' ;
+
 CREATE TABLE 'SchemaInfo' ( 'Version' VARCHAR(1024) NOT NULL );
-INSERT INTO 'SchemaInfo' VALUES('0.5');
+INSERT INTO 'SchemaInfo' VALUES('0.5.1');
 
 CREATE TABLE 'Images' (
   'SOPInstanceUID' VARCHAR(64) NOT NULL,
@@ -61,6 +63,8 @@ CREATE TABLE 'Studies' (
   'StudyDescription' VARCHAR(255) NULL ,
   PRIMARY KEY ('StudyInstanceUID') );
 
+CREATE UNIQUE INDEX IF NOT EXISTS 'ImagesFilenameIndex' ON 'Images' ('Filename');
+
 CREATE TABLE 'Directories' (
   'Dirname' VARCHAR(1024) ,
   PRIMARY KEY ('Dirname') );

+ 16 - 4
Libs/DICOM/Core/ctkDICOMDatabase.cpp

@@ -432,6 +432,18 @@ QString ctkDICOMDatabase::schemaVersionLoaded()
   return QString("");
 }
 
+//------------------------------------------------------------------------------
+QString ctkDICOMDatabase::schemaVersion()
+{
+  // When changing schema version:
+  // * make sure this matches the Version value in the
+  //   SchemaInfo table defined in Resources/dicom-schema.sql
+  // * make sure the 'Images' contains a 'Filename' column
+  //   so that the ctkDICOMDatabasePrivate::filenames method
+  //   still works.
+  //
+  return QString("0.5.1");
+};
 
 //------------------------------------------------------------------------------
 bool ctkDICOMDatabase::updateSchemaIfNeeded(const char* schemaFile)
@@ -449,16 +461,16 @@ bool ctkDICOMDatabase::updateSchema(const char* schemaFile)
   // backup filelist
   // reinit with the new schema
   // reinsert everything
- 
+
   Q_D(ctkDICOMDatabase);
   d->createBackupFileList();
- 
+
   d->resetLastInsertedValues();
   this->initializeDatabase(schemaFile);
 
   QStringList allFiles = d->filenames("Filenames_backup");
   emit schemaUpdateStarted(allFiles.length());
-  
+
   int progressValue = 0;
   foreach(QString file, allFiles)
   {
@@ -1024,7 +1036,7 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
   QString studyInstanceUID(ctkDataset.GetElementAsString(DCM_StudyInstanceUID) );
   QString seriesInstanceUID(ctkDataset.GetElementAsString(DCM_SeriesInstanceUID) );
   QString patientID(ctkDataset.GetElementAsString(DCM_PatientID) );
-  if ( patientID.isEmpty() && !studyInstanceUID.isEmpty() ) 	 
+  if ( patientID.isEmpty() && !studyInstanceUID.isEmpty() )
   { // Use study instance uid as patient id if patient id is empty - can happen on anonymized datasets
     // see: http://www.na-mic.org/Bug/view.php?id=2040
     logger.warn("Patient ID is empty, using studyInstanceUID as patient ID");

+ 1 - 1
Libs/DICOM/Core/ctkDICOMDatabase.h

@@ -119,7 +119,7 @@ public:
   Q_INVOKABLE bool updateSchemaIfNeeded(const char* schemaFile = ":/dicom/dicom-schema.sql");
 
   /// returns the schema version needed by the current version of this code
-  Q_INVOKABLE QString schemaVersion() { return QString("0.5"); };
+  Q_INVOKABLE QString schemaVersion();
 
   /// returns the schema version for the currently open database
   /// in order to support schema updating