Skip to content

Commit

Permalink
ENH: Updates dicom db schema to support urls
Browse files Browse the repository at this point in the history
Adds a URL field to the Images schema and provides
accessor methods for it.
  • Loading branch information
pieper committed Nov 13, 2023
1 parent ff515f9 commit 5200de9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Libs/DICOM/Core/Resources/dicom-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ DROP INDEX IF EXISTS 'SeriesStudyIndex' ;
DROP INDEX IF EXISTS 'StudiesPatientIndex' ;

CREATE TABLE 'SchemaInfo' ( 'Version' VARCHAR(1024) NOT NULL );
INSERT INTO 'SchemaInfo' VALUES('0.7.0');
INSERT INTO 'SchemaInfo' VALUES('0.8.0');

CREATE TABLE 'Images' (
'SOPInstanceUID' VARCHAR(64) NOT NULL,
'Filename' VARCHAR(1024) NOT NULL ,
'URL' VARCHAR(2048) NOT NULL ,
'SeriesInstanceUID' VARCHAR(64) NOT NULL ,
'InsertTimestamp' VARCHAR(20) NOT NULL ,
'DisplayedFieldsUpdatedTimestamp' DATETIME NULL ,
Expand Down
38 changes: 35 additions & 3 deletions Libs/DICOM/Core/ctkDICOMDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ctkDICOMDatabasePrivate::ctkDICOMDatabasePrivate(ctkDICOMDatabase& o)
, UseShortStoragePath(true)
, ThumbnailGenerator(nullptr)
, TagCacheVerified(false)
, SchemaVersion("0.7.0")
, SchemaVersion("0.8.0")
{
this->resetLastInsertedValues();
this->DisplayedFieldGenerator = new ctkDICOMDisplayedFieldGenerator(q_ptr);
Expand Down Expand Up @@ -965,7 +965,7 @@ void ctkDICOMDatabasePrivate::insert(const ctkDICOMItem& dataset, const QString&
}

QSqlQuery insertImageStatement(Database);
insertImageStatement.prepare("INSERT INTO Images ( 'SOPInstanceUID', 'Filename', 'SeriesInstanceUID', 'InsertTimestamp' ) VALUES ( ?, ?, ?, ? )");
insertImageStatement.prepare("INSERT INTO Images ( 'SOPInstanceUID', 'Filename', 'URL', 'SeriesInstanceUID', 'InsertTimestamp' ) VALUES ( ?, ?, NULL, ?, ? )");
insertImageStatement.addBindValue(sopInstanceUID);
insertImageStatement.addBindValue(storedFilePathInDatabase);
insertImageStatement.addBindValue(seriesInstanceUID);
Expand Down Expand Up @@ -1112,7 +1112,7 @@ void ctkDICOMDatabase::insert(const QList<ctkDICOMDatabase::IndexingResult>& ind

// Insert image files
QSqlQuery insertImageStatement(d->Database);
insertImageStatement.prepare("INSERT INTO Images ( 'SOPInstanceUID', 'Filename', 'SeriesInstanceUID', 'InsertTimestamp' ) VALUES ( ?, ?, ?, ? )");
insertImageStatement.prepare("INSERT INTO Images ( 'SOPInstanceUID', 'Filename', 'URL', 'SeriesInstanceUID', 'InsertTimestamp' ) VALUES ( ?, ?, NULL, ?, ? )");
insertImageStatement.addBindValue(sopInstanceUID);
insertImageStatement.addBindValue(d->internalPathFromAbsolute(storedFilePath));
insertImageStatement.addBindValue(seriesInstanceUID);
Expand Down Expand Up @@ -2125,6 +2125,22 @@ QString ctkDICOMDatabase::fileForInstance(QString sopInstanceUID)
return result;
}

//------------------------------------------------------------------------------
QString ctkDICOMDatabase::urlForInstance(QString sopInstanceUID)
{
Q_D(ctkDICOMDatabase);
QSqlQuery query(d->Database);
query.prepare("SELECT URL FROM Images WHERE SOPInstanceUID=?");
query.addBindValue(sopInstanceUID);
query.exec();
QString result;
if (query.next())
{
result = query.value(0).toString();
}
return result;
}

//------------------------------------------------------------------------------
QString ctkDICOMDatabase::seriesForFile(QString fileName)
{
Expand Down Expand Up @@ -2157,6 +2173,22 @@ QString ctkDICOMDatabase::instanceForFile(QString fileName)
return result;
}

//------------------------------------------------------------------------------
QString ctkDICOMDatabase::instanceForURL(QString url)
{
Q_D(ctkDICOMDatabase);
QSqlQuery query(d->Database);
query.prepare( "SELECT SOPInstanceUID FROM Images WHERE URL=?");
query.addBindValue(url);
query.exec();
QString result;
if (query.next())
{
result = query.value(0).toString();
}
return result;
}

//------------------------------------------------------------------------------
QDateTime ctkDICOMDatabase::insertDateTimeForInstance(QString sopInstanceUID)
{
Expand Down
2 changes: 2 additions & 0 deletions Libs/DICOM/Core/ctkDICOMDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMDatabase : public QObject
QStringList seriesFieldNames() const;

Q_INVOKABLE QString fileForInstance(const QString sopInstanceUID);
Q_INVOKABLE QString urlForInstance(const QString sopInstanceUID);
Q_INVOKABLE QString instanceForURL(const QString url);
Q_INVOKABLE QString seriesForFile(QString fileName);
Q_INVOKABLE QString instanceForFile(const QString fileName);
Q_INVOKABLE QDateTime insertDateTimeForInstance(const QString fileName);
Expand Down

0 comments on commit 5200de9

Please sign in to comment.