Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH+BUG for the visual DICOM browser #1203

Merged
merged 8 commits into from
May 17, 2024
17 changes: 13 additions & 4 deletions Libs/DICOM/Core/Resources/dicom-qr-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ DROP INDEX IF EXISTS 'SeriesStudyIndex' ;
DROP INDEX IF EXISTS 'StudiesPatientIndex' ;

CREATE TABLE 'SchemaInfo' ( 'Version' VARCHAR(1024) NOT NULL );
INSERT INTO 'SchemaInfo' VALUES('0.6.2');
INSERT INTO 'SchemaInfo' VALUES('0.8.1');

CREATE TABLE 'Images' (
'SOPInstanceUID' VARCHAR(64) NOT NULL,
'Filename' VARCHAR(1024) NOT NULL ,
'URL' VARCHAR(2048) NULL,
'SeriesInstanceUID' VARCHAR(64) NOT NULL ,
'InsertTimestamp' VARCHAR(20) NOT NULL ,
'DisplayedFieldsUpdatedTimestamp' DATETIME NULL ,
PRIMARY KEY ('SOPInstanceUID') );
PRIMARY KEY ('SOPInstanceUID')
);

CREATE TABLE 'Patients' (
'UID' INTEGER PRIMARY KEY AUTOINCREMENT,
'PatientsName' VARCHAR(255) NULL ,
Expand All @@ -43,7 +46,10 @@ CREATE TABLE 'Patients' (
'InsertTimestamp' VARCHAR(20) NOT NULL ,
'DisplayedPatientsName' VARCHAR(255) NULL ,
'DisplayedNumberOfStudies' INT NULL ,
'DisplayedFieldsUpdatedTimestamp' DATETIME NULL );
'DisplayedFieldsUpdatedTimestamp' DATETIME NULL ,
'Connections' VARCHAR(2048) NULL
);

CREATE TABLE 'Studies' (
'StudyInstanceUID' VARCHAR(64) NOT NULL ,
'PatientsUID' INT NOT NULL ,
Expand All @@ -59,7 +65,9 @@ CREATE TABLE 'Studies' (
'InsertTimestamp' VARCHAR(20) NOT NULL ,
'DisplayedNumberOfSeries' INT NULL ,
'DisplayedFieldsUpdatedTimestamp' DATETIME NULL ,
PRIMARY KEY ('StudyInstanceUID') );
PRIMARY KEY ('StudyInstanceUID')
);

CREATE TABLE 'Series' (
'SeriesInstanceUID' VARCHAR(64) NOT NULL ,
'StudyInstanceUID' VARCHAR(64) NOT NULL ,
Expand Down Expand Up @@ -112,6 +120,7 @@ INSERT INTO 'ColumnDisplayProperties' VALUES('Patients', 'InsertTimestamp',
INSERT INTO 'ColumnDisplayProperties' VALUES('Patients', 'DisplayedPatientsName', 'Patient name', 0, 0, '');
INSERT INTO 'ColumnDisplayProperties' VALUES('Patients', 'DisplayedNumberOfStudies', 'Studies', 0, 0, '');
INSERT INTO 'ColumnDisplayProperties' VALUES('Patients', 'DisplayedFieldsUpdatedTimestamp', '', 0, 0, '');
INSERT INTO 'ColumnDisplayProperties' VALUES('Patients', 'Connections', '', 0, 0, '');

INSERT INTO 'ColumnDisplayProperties' VALUES('Studies', 'StudyInstanceUID', '', 0, 0, '');
INSERT INTO 'ColumnDisplayProperties' VALUES('Studies', 'PatientsUID', '', 0, 0, '');
Expand Down
2 changes: 1 addition & 1 deletion Libs/DICOM/Core/Resources/dicom-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CREATE TABLE 'Patients' (
'DisplayedPatientsName' VARCHAR(255) NULL ,
'DisplayedNumberOfStudies' INT NULL ,
'DisplayedLastStudyDate' DATE NULL ,
'DisplayedFieldsUpdatedTimestamp' DATETIME NULL,
'DisplayedFieldsUpdatedTimestamp' DATETIME NULL ,
'Connections' VARCHAR(2048) NULL
);

Expand Down
57 changes: 57 additions & 0 deletions Libs/DICOM/Core/ctkDICOMDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,63 @@ QString ctkDICOMDatabase::displayedNameForPatient(const QString patientUID)
return result;
}

//------------------------------------------------------------------------------
QDateTime ctkDICOMDatabase::insertDateTimeForPatient(const QString patientUID)
{
Q_D(ctkDICOMDatabase);
QDateTime result;
QSqlQuery query(d->Database);
query.prepare("SELECT InsertTimestamp FROM Patients WHERE UID=?");
query.addBindValue(patientUID);
if (!d->loggedExec(query))
{
return result;
}
if (query.next())
{
result = QDateTime::fromString(query.value(0).toString(), Qt::ISODate);
}
return result;
}

//------------------------------------------------------------------------------
QDateTime ctkDICOMDatabase::insertDateTimeForStudy(const QString studyInstanceUID)
{
Q_D(ctkDICOMDatabase);
QDateTime result;
QSqlQuery query(d->Database);
query.prepare("SELECT InsertTimestamp FROM Studies WHERE StudyInstanceUID=?");
query.addBindValue(studyInstanceUID);
if (!d->loggedExec(query))
{
return result;
}
if (query.next())
{
result = QDateTime::fromString(query.value(0).toString(), Qt::ISODate);
}
return result;
}

//------------------------------------------------------------------------------
QDateTime ctkDICOMDatabase::insertDateTimeForSeries(const QString seriesInstanceUID)
{
Q_D(ctkDICOMDatabase);
QDateTime result;
QSqlQuery query(d->Database);
query.prepare("SELECT InsertTimestamp FROM Series WHERE SeriesInstanceUID=?");
query.addBindValue(seriesInstanceUID);
if (!d->loggedExec(query))
{
return result;
}
if (query.next())
{
result = QDateTime::fromString(query.value(0).toString(), Qt::ISODate);
}
return result;
}

//------------------------------------------------------------------------------
QString ctkDICOMDatabase::fieldForPatient(const QString field, const QString patientUID)
{
Expand Down
3 changes: 3 additions & 0 deletions Libs/DICOM/Core/ctkDICOMDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMDatabase : public QObject
Q_INVOKABLE QString descriptionForStudy(const QString studyUID);
Q_INVOKABLE QString nameForPatient(const QString patientUID);
Q_INVOKABLE QString displayedNameForPatient(const QString patientUID);
Q_INVOKABLE QDateTime insertDateTimeForPatient(const QString patientUID);
Q_INVOKABLE QDateTime insertDateTimeForStudy(const QString studyInstanceUID);
Q_INVOKABLE QDateTime insertDateTimeForSeries(const QString seriesInstanceUID);
Q_INVOKABLE QString fieldForPatient(const QString field, const QString patientUID);
Q_INVOKABLE QString fieldForStudy(const QString field, const QString studyInstanceUID);
Q_INVOKABLE QString fieldForSeries(const QString field, const QString seriesInstanceUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMDisplayedFieldGeneratorAbstractRule
/// Utility function to convert a DICOM tag enum to string
static QString dicomTagToString(const DcmTagKey& tag)
{
return QString("%1,%2").arg(tag.getGroup(),4,16,QLatin1Char('0')).arg(tag.getElement(),4,16,QLatin1Char('0'));
return QString("%1,%2").arg(tag.getGroup(),4,16,QLatin1Char('0')).arg(tag.getElement(),4,16,QLatin1Char('0')).toUpper();
}

/// Register placeholder strings that still mean that a given field can be considered empty.
Expand Down
1 change: 0 additions & 1 deletion Libs/DICOM/Core/ctkDICOMQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ bool ctkDICOMQuery::queryPatients()
{
logger.warn(QString("ctkDICOMQuery: the number of responses of the query task at patients level "
"surpassed the maximum value of permitted results (i.e. %1).").arg(d->MaximumPatientsQuery));

break;
}
DcmDataset *dataset = (*it)->m_dataset;
Expand Down
1 change: 0 additions & 1 deletion Libs/DICOM/Core/ctkDICOMScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMScheduler : public ctkJobScheduler
Q_INVOKABLE void runJobs(const QMap<QString, ctkDICOMJobDetail>& jobDetails);
Q_INVOKABLE void raiseJobsPriorityForSeries(const QStringList& selectedSeriesInstanceUIDs,
QThread::Priority priority = QThread::HighestPriority);

///@}

///@{
Expand Down
26 changes: 20 additions & 6 deletions Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ctkDICOMPatientItemWidgetPrivate : public Ui_ctkDICOMPatientItemWidget
QString formatDate(const QString&);
bool isStudyItemAlreadyAdded(const QString& studyItem);
void clearLayout(QLayout* layout, bool deleteWidgets = true);
void createStudies(bool queryRetrieve = true);
void createStudies();
void updateAllowedServersUIFromDB();
void setAllDeniedServerEnabledStatus(bool enabled);
void saveAllowedServersStringListFromUI();
Expand Down Expand Up @@ -100,6 +100,8 @@ class ctkDICOMPatientItemWidgetPrivate : public Ui_ctkDICOMPatientItemWidget
QStringList AllowedServers = QStringList();

bool IsGUIUpdating;
bool QueryOn;
bool RetrieveOn;
};

//----------------------------------------------------------------------------
Expand All @@ -125,6 +127,8 @@ ctkDICOMPatientItemWidgetPrivate::ctkDICOMPatientItemWidgetPrivate(ctkDICOMPatie
this->StudiesListVerticalSpacer = new QSpacerItem(0, 5, QSizePolicy::Fixed, QSizePolicy::Expanding);

this->IsGUIUpdating = false;
this->QueryOn = true;
this->RetrieveOn = true;
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -233,7 +237,7 @@ void ctkDICOMPatientItemWidgetPrivate::clearLayout(QLayout* layout, bool deleteW
}

//----------------------------------------------------------------------------
void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
void ctkDICOMPatientItemWidgetPrivate::createStudies()
{
Q_Q(ctkDICOMPatientItemWidget);
if (this->IsGUIUpdating)
Expand Down Expand Up @@ -269,6 +273,7 @@ void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
QStringList studiesList = this->DicomDatabase->studiesForPatient(this->PatientItem);
if (studiesList.count() == 0)
{
q->emit updateGUIFinished();
return;
}

Expand Down Expand Up @@ -369,7 +374,11 @@ void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
if (cont < this->NumberOfStudiesPerPatient)
{
studyItemWidget->setCollapsed(false);
studyItemWidget->generateSeries(queryRetrieve);
studyItemWidget->generateSeries(this->QueryOn, this->RetrieveOn);
}
else
{
studyItemWidget->generateSeries(this->QueryOn, false);
}
cont++;

Expand All @@ -388,6 +397,7 @@ void ctkDICOMPatientItemWidgetPrivate::createStudies(bool queryRetrieve)
studiesListWidgetLayout->addItem(this->StudiesListVerticalSpacer);

this->IsGUIUpdating = false;
q->emit updateGUIFinished();
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -761,6 +771,8 @@ void ctkDICOMPatientItemWidget::addStudyItemWidget(const QString& studyItem)
this, SLOT(onSeriesItemClicked()));
this->connect(studyItemWidget->seriesListTableWidget(), SIGNAL(itemSelectionChanged()),
this, SLOT(raiseSelectedSeriesJobsPriority()));
this->connect(studyItemWidget, SIGNAL(updateGUIFinished()),
this, SIGNAL(updateGUIFinished()));

d->StudyItemWidgetsList.append(studyItemWidget);
}
Expand Down Expand Up @@ -830,12 +842,14 @@ void ctkDICOMPatientItemWidget::updateAllowedServersUIFromDB()
}

//------------------------------------------------------------------------------
void ctkDICOMPatientItemWidget::generateStudies(bool queryRetrieve)
void ctkDICOMPatientItemWidget::generateStudies(bool query, bool retrieve)
{
Q_D(ctkDICOMPatientItemWidget);

d->createStudies(queryRetrieve);
if (queryRetrieve && d->Scheduler && d->Scheduler->queryRetrieveServersCount() > 0)
d->QueryOn = query;
d->RetrieveOn = retrieve;
d->createStudies();
if (query && d->Scheduler && d->Scheduler->queryRetrieveServersCount() > 0)
{
d->Scheduler->queryStudies(d->PatientID,
QThread::NormalPriority,
Expand Down
6 changes: 5 additions & 1 deletion Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,17 @@ class CTK_DICOM_WIDGETS_EXPORT ctkDICOMPatientItemWidget : public QWidget
///@}

public Q_SLOTS:
void generateStudies(bool queryRetrieve = true);
void generateStudies(bool query = true, bool retrieve = true);
void generateSeriesAtToggle(bool toggled = true, const QString& studyItem = "");
void updateGUIFromScheduler(const QVariant& data);
void onSeriesItemClicked();
void raiseSelectedSeriesJobsPriority();
void onPatientServersCheckableComboBoxChanged();

Q_SIGNALS:
/// Emitted when the GUI finished to update after a studies query.
void updateGUIFinished();

protected:
QScopedPointer<ctkDICOMPatientItemWidgetPrivate> d_ptr;

Expand Down
Loading
Loading