Skip to content

Commit

Permalink
ENH: Add UI to filter enabled server on patient basis in the ctkDICOM…
Browse files Browse the repository at this point in the history
…VisualBrowserWidget

ENH: Change query button with a menu button with advanced settings to disable query/retrieve for the data search in the ctkDICOMVisualBrowserWidget
  • Loading branch information
Punzo committed Apr 4, 2024
1 parent 3958d22 commit 4f1fe7e
Show file tree
Hide file tree
Showing 18 changed files with 902 additions and 220 deletions.
5 changes: 3 additions & 2 deletions Libs/DICOM/Core/ctkDICOMDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,9 @@ bool ctkDICOMDatabasePrivate::applyDisplayedFieldsChanges( QMap<QString, QMap<QS
QMap<QString, QString> currentPatient = displayedFieldsMapPatient[compositeID];
if (currentPatient["PatientID"].isEmpty() || currentPatient["PatientsName"].isEmpty())
{
logger.error("Failed to find patient since PatientsName and/or PatientID are empty."
"If this error repeats, please remove manually from the database tha patient with the missing PatientsName/PatientID." );
logger.error("Unable to locate the patient due to missing values for PatientsName and/or PatientID. "
"If this error recurs, please manually remove the patient from the database, ensuring to"
" address the missing PatientsName/PatientID.");
continue;
}

Expand Down
126 changes: 106 additions & 20 deletions Libs/DICOM/Core/ctkDICOMScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ ctkDICOMSchedulerPrivate::~ctkDICOMSchedulerPrivate()
q->removeAllServers();
}

//------------------------------------------------------------------------------
bool ctkDICOMSchedulerPrivate::isServerEnabled(ctkDICOMServer *server,
const QStringList& enabledSevers)
{
if (!server)
{
return false;
}

if (!server->queryRetrieveEnabled())
{
return false;
}
else if (enabledSevers.contains("All") && enabledSevers.count() == 1)
{
return true;
}
else if (enabledSevers.contains(server->connectionName()))
{
return true;
}
else
{
return false;
}
}

//------------------------------------------------------------------------------
ctkDICOMServer* ctkDICOMSchedulerPrivate::getServerFromProxyServersByConnectionName(const QString& connectionName)
{
Expand Down Expand Up @@ -99,13 +126,14 @@ ctkDICOMScheduler::ctkDICOMScheduler(ctkDICOMSchedulerPrivate* pimpl, QObject* p
ctkDICOMScheduler::~ctkDICOMScheduler() = default;

//----------------------------------------------------------------------------
void ctkDICOMScheduler::queryPatients(QThread::Priority priority)
void ctkDICOMScheduler::queryPatients(QThread::Priority priority,
const QStringList& enabledSevers)
{
Q_D(ctkDICOMScheduler);

foreach (QSharedPointer<ctkDICOMServer> server, d->Servers)
{
if (!server->queryRetrieveEnabled())
if (!d->isServerEnabled(server.data(), enabledSevers))
{
continue;
}
Expand All @@ -126,13 +154,14 @@ void ctkDICOMScheduler::queryPatients(QThread::Priority priority)

//----------------------------------------------------------------------------
void ctkDICOMScheduler::queryStudies(const QString& patientID,
QThread::Priority priority)
QThread::Priority priority,
const QStringList& enabledSevers)
{
Q_D(ctkDICOMScheduler);

foreach (QSharedPointer<ctkDICOMServer> server, d->Servers)
{
if (!server->queryRetrieveEnabled())
if (!d->isServerEnabled(server.data(), enabledSevers))
{
continue;
}
Expand All @@ -154,13 +183,14 @@ void ctkDICOMScheduler::queryStudies(const QString& patientID,
//----------------------------------------------------------------------------
void ctkDICOMScheduler::querySeries(const QString& patientID,
const QString& studyInstanceUID,
QThread::Priority priority)
QThread::Priority priority,
const QStringList& enabledSevers)
{
Q_D(ctkDICOMScheduler);

foreach (QSharedPointer<ctkDICOMServer> server, d->Servers)
{
if (!server->queryRetrieveEnabled())
if (!d->isServerEnabled(server.data(), enabledSevers))
{
continue;
}
Expand All @@ -184,13 +214,14 @@ void ctkDICOMScheduler::querySeries(const QString& patientID,
void ctkDICOMScheduler::queryInstances(const QString& patientID,
const QString& studyInstanceUID,
const QString& seriesInstanceUID,
QThread::Priority priority)
QThread::Priority priority,
const QStringList& enabledSevers)
{
Q_D(ctkDICOMScheduler);

foreach (QSharedPointer<ctkDICOMServer> server, d->Servers)
{
if (!server->queryRetrieveEnabled())
if (!d->isServerEnabled(server.data(), enabledSevers))
{
continue;
}
Expand All @@ -214,13 +245,14 @@ void ctkDICOMScheduler::queryInstances(const QString& patientID,
//----------------------------------------------------------------------------
void ctkDICOMScheduler::retrieveStudy(const QString& patientID,
const QString& studyInstanceUID,
QThread::Priority priority)
QThread::Priority priority,
const QStringList& enabledSevers)
{
Q_D(ctkDICOMScheduler);

foreach (QSharedPointer<ctkDICOMServer> server, d->Servers)
{
if (!server->queryRetrieveEnabled())
if (!d->isServerEnabled(server.data(), enabledSevers))
{
continue;
}
Expand All @@ -243,13 +275,14 @@ void ctkDICOMScheduler::retrieveStudy(const QString& patientID,
void ctkDICOMScheduler::retrieveSeries(const QString& patientID,
const QString& studyInstanceUID,
const QString& seriesInstanceUID,
QThread::Priority priority)
QThread::Priority priority,
const QStringList& enabledSevers)
{
Q_D(ctkDICOMScheduler);

foreach (QSharedPointer<ctkDICOMServer> server, d->Servers)
{
if (!server->queryRetrieveEnabled())
if (!d->isServerEnabled(server.data(), enabledSevers))
{
continue;
}
Expand All @@ -274,13 +307,14 @@ void ctkDICOMScheduler::retrieveSOPInstance(const QString& patientID,
const QString& studyInstanceUID,
const QString& seriesInstanceUID,
const QString& SOPInstanceUID,
QThread::Priority priority)
QThread::Priority priority,
const QStringList& enabledSevers)
{
Q_D(ctkDICOMScheduler);

foreach (QSharedPointer<ctkDICOMServer> server, d->Servers)
{
if (!server->queryRetrieveEnabled())
if (!d->isServerEnabled(server.data(), enabledSevers))
{
continue;
}
Expand Down Expand Up @@ -573,6 +607,46 @@ int ctkDICOMScheduler::getServerIndexFromName(const QString& connectionName)
return -1;
}

//----------------------------------------------------------------------------
QStringList ctkDICOMScheduler::getAllServersConnectionNames()
{
Q_D(ctkDICOMScheduler);

QStringList connectionNames;
for (int serverIndex = 0; serverIndex < d->Servers.size(); ++serverIndex)
{
QSharedPointer<ctkDICOMServer> server = d->Servers.at(serverIndex);
if (!server)
{
continue;
}

connectionNames.append(server->connectionName());
}

return connectionNames;
}

//----------------------------------------------------------------------------
QStringList ctkDICOMScheduler::getConnectionNamesForActiveServers()
{
Q_D(ctkDICOMScheduler);

QStringList connectionNames;
for (int serverIndex = 0; serverIndex < d->Servers.size(); ++serverIndex)
{
QSharedPointer<ctkDICOMServer> server = d->Servers.at(serverIndex);
if (!server || (!server->queryRetrieveEnabled() && !server->storageEnabled()))
{
continue;
}

connectionNames.append(server->connectionName());
}

return connectionNames;
}

//----------------------------------------------------------------------------
void ctkDICOMScheduler::waitForFinishByDICOMUIDs(const QStringList& patientIDs,
const QStringList& studyInstanceUIDs,
Expand Down Expand Up @@ -783,16 +857,22 @@ void ctkDICOMScheduler::runJobs(const QMap<QString, ctkDICOMJobDetail> &jobDetai
this->queryPatients();
break;
case ctkDICOMJob::DICOMLevels::Studies:
this->queryStudies(jd.PatientID);
this->queryStudies(jd.PatientID,
QThread::NormalPriority,
QStringList(jd.ConnectionName));
break;
case ctkDICOMJob::DICOMLevels::Series:
this->querySeries(jd.PatientID,
jd.StudyInstanceUID);
jd.StudyInstanceUID,
QThread::NormalPriority,
QStringList(jd.ConnectionName));
break;
case ctkDICOMJob::DICOMLevels::Instances:
this->queryInstances(jd.PatientID,
jd.StudyInstanceUID,
jd.SeriesInstanceUID);
jd.SeriesInstanceUID,
QThread::NormalPriority,
QStringList(jd.ConnectionName));
break;
}
}
Expand All @@ -808,18 +888,24 @@ void ctkDICOMScheduler::runJobs(const QMap<QString, ctkDICOMJobDetail> &jobDetai
break;
case ctkDICOMJob::DICOMLevels::Studies:
this->retrieveStudy(jd.PatientID,
jd.StudyInstanceUID);
jd.StudyInstanceUID,
QThread::NormalPriority,
QStringList(jd.ConnectionName));
break;
case ctkDICOMJob::DICOMLevels::Series:
this->retrieveSeries(jd.PatientID,
jd.StudyInstanceUID,
jd.SeriesInstanceUID);
jd.SeriesInstanceUID,
QThread::NormalPriority,
QStringList(jd.ConnectionName));
break;
case ctkDICOMJob::DICOMLevels::Instances:
this->retrieveSOPInstance(jd.PatientID,
jd.StudyInstanceUID,
jd.SeriesInstanceUID,
jd.SOPInstanceUID);
jd.SOPInstanceUID,
QThread::NormalPriority,
QStringList(jd.ConnectionName));
break;
}
}
Expand Down
23 changes: 16 additions & 7 deletions Libs/DICOM/Core/ctkDICOMScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,53 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMScheduler : public ctkJobScheduler

/// Query Patients applying filters on all servers.
/// The method spans a ctkDICOMQueryJob for each server.
Q_INVOKABLE void queryPatients(QThread::Priority priority = QThread::LowPriority);
Q_INVOKABLE void queryPatients(QThread::Priority priority = QThread::LowPriority,
const QStringList& enabledSevers = QStringList("All"));

/// Query Studies applying filters on all servers.
/// The method spans a ctkDICOMQueryJob for each server.
Q_INVOKABLE void queryStudies(const QString& patientID,
QThread::Priority priority = QThread::LowPriority);
QThread::Priority priority = QThread::LowPriority,
const QStringList& enabledSevers = QStringList("All"));

/// Query Series applying filters on all servers.
/// The method spans a ctkDICOMQueryJob for each server.
Q_INVOKABLE void querySeries(const QString& patientID,
const QString& studyInstanceUID,
QThread::Priority priority = QThread::LowPriority);
QThread::Priority priority = QThread::LowPriority,
const QStringList& enabledSevers = QStringList("All"));

/// Query Instances applying filters on all servers.
/// The method spans a ctkDICOMQueryJob for each server.
Q_INVOKABLE void queryInstances(const QString& patientID,
const QString& studyInstanceUID,
const QString& seriesInstanceUID,
QThread::Priority priority = QThread::LowPriority);
QThread::Priority priority = QThread::LowPriority,
const QStringList& enabledSevers = QStringList("All"));

/// Retrieve Study.
/// The method spans a ctkDICOMRetrieveJob for each server.
Q_INVOKABLE void retrieveStudy(const QString& patientID,
const QString& studyInstanceUID,
QThread::Priority priority = QThread::LowPriority);
QThread::Priority priority = QThread::LowPriority,
const QStringList& enabledSevers = QStringList("All"));

/// Retrieve Series.
/// The method spans a ctkDICOMRetrieveJob for each server.
Q_INVOKABLE void retrieveSeries(const QString& patientID,
const QString& studyInstanceUID,
const QString& seriesInstanceUID,
QThread::Priority priority = QThread::LowPriority);
QThread::Priority priority = QThread::LowPriority,
const QStringList& enabledSevers = QStringList("All"));

/// Retrieve SOPInstance.
/// The method spans a ctkDICOMRetrieveJob for each server.
Q_INVOKABLE void retrieveSOPInstance(const QString& patientID,
const QString& studyInstanceUID,
const QString& seriesInstanceUID,
const QString& SOPInstanceUID,
QThread::Priority priority = QThread::LowPriority);
QThread::Priority priority = QThread::LowPriority,
const QStringList& enabledSevers = QStringList("All"));

/// Start a storage listener
Q_INVOKABLE void startListener(int port,
Expand Down Expand Up @@ -162,6 +169,8 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMScheduler : public ctkJobScheduler
Q_INVOKABLE void removeAllServers();
Q_INVOKABLE QString getServerNameFromIndex(int id);
Q_INVOKABLE int getServerIndexFromName(const QString& connectionName);
Q_INVOKABLE QStringList getAllServersConnectionNames();
Q_INVOKABLE QStringList getConnectionNamesForActiveServers();
///@}

///@{
Expand Down
1 change: 1 addition & 0 deletions Libs/DICOM/Core/ctkDICOMScheduler_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ctkDICOMSchedulerPrivate : public ctkJobSchedulerPrivate
ctkDICOMSchedulerPrivate(ctkDICOMScheduler& obj);
virtual ~ctkDICOMSchedulerPrivate();

bool isServerEnabled(ctkDICOMServer* server, const QStringList& enabledSevers);
ctkDICOMServer* getServerFromProxyServersByConnectionName(const QString&);

QSharedPointer<ctkDICOMDatabase> DicomDatabase;
Expand Down
Loading

0 comments on commit 4f1fe7e

Please sign in to comment.