36 #include <QMessageBox>
37 #include <QProgressDialog>
40 #include "ctkFileDialog.h"
42 #include "ctkDICOMDatabase.h"
43 #include "ctkDICOMIndexer.h"
50 DICOMIndexer = QSharedPointer<ctkDICOMIndexer> (
new ctkDICOMIndexer);
52 DisplayImportSummary =
true;
53 PatientsAddedDuringImport = 0;
54 StudiesAddedDuringImport = 0;
55 SeriesAddedDuringImport = 0;
56 InstancesAddedDuringImport = 0;
59 ImportDialog =
new ctkFileDialog();
60 QCheckBox* importCheckbox =
new QCheckBox(
"Copy on import", ImportDialog);
61 ImportDialog->setBottomWidget(importCheckbox);
62 ImportDialog->setFileMode(QFileDialog::Directory);
63 ImportDialog->setLabelText(QFileDialog::Accept,
"Import");
64 ImportDialog->setWindowTitle(
"Import DICOM files from directory ...");
65 ImportDialog->setWindowModality(Qt::ApplicationModal);
67 connect(ImportDialog, SIGNAL(fileSelected(QString)),
this,SLOT(
onImportDirectory(QString)));
72 delete IndexerProgress;
73 ImportDialog->deleteLater();
80 disconnect(DICOMDatabase.data(), SIGNAL(patientAdded(
int,QString,QString,QString)),
this,
81 SLOT(onPatientAdded(
int,QString,QString,QString)));
82 disconnect(DICOMDatabase.data(), SIGNAL(studyAdded(QString)),
this, SLOT(onStudyAdded(QString)));
83 disconnect(DICOMDatabase.data(), SIGNAL(seriesAdded(QString)),
this, SLOT(onSeriesAdded(QString)));
84 disconnect(DICOMDatabase.data(), SIGNAL(instanceAdded(QString)),
this, SLOT(onInstanceAdded(QString)));
87 DICOMDatabase = database;
91 connect(DICOMDatabase.data(), SIGNAL(patientAdded(
int,QString,QString,QString)),
this,
92 SLOT(onPatientAdded(
int,QString,QString,QString)));
93 connect(DICOMDatabase.data(), SIGNAL(studyAdded(QString)),
this, SLOT(onStudyAdded(QString)));
94 connect(DICOMDatabase.data(), SIGNAL(seriesAdded(QString)),
this, SLOT(onSeriesAdded(QString)));
95 connect(DICOMDatabase.data(), SIGNAL(instanceAdded(QString)),
this, SLOT(onInstanceAdded(QString)));
99 void DicomImporter::showIndexerDialog()
101 if (IndexerProgress == 0)
106 IndexerProgress =
new QProgressDialog(
"DICOM Import",
"Cancel", 0, 100, NULL,
107 Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
111 QLabel* progressLabel =
new QLabel(
"Initialization...");
112 IndexerProgress->setLabel(progressLabel);
113 IndexerProgress->setWindowModality(Qt::ApplicationModal);
114 IndexerProgress->setMinimumDuration(0);
115 IndexerProgress->setValue(0);
117 connect(IndexerProgress, SIGNAL(canceled()),
118 DICOMIndexer.data(), SLOT(cancel()));
120 connect(DICOMIndexer.data(), SIGNAL(progress(
int)),
121 IndexerProgress, SLOT(setValue(
int)));
122 connect(DICOMIndexer.data(), SIGNAL(indexingFilePath(QString)),
123 progressLabel, SLOT(setText(QString)));
124 connect(DICOMIndexer.data(), SIGNAL(indexingFilePath(QString)),
126 connect(DICOMIndexer.data(), SIGNAL(indexingFilePath(QString)),
127 this, SLOT(onFileIndexed(QString)));
130 connect(DICOMIndexer.data(), SIGNAL(indexingComplete()),
131 IndexerProgress, SLOT(close()));
133 connect(DICOMIndexer.data(), SIGNAL(indexingComplete()),
136 connect(IndexerProgress, SIGNAL(canceled()),
137 DICOMIndexer.data(), SLOT(cancel()));
138 connect(IndexerProgress, SIGNAL(canceled()),
142 connect(IndexerProgress, SIGNAL(canceled()),
144 connect(DICOMIndexer.data(), SIGNAL(indexingComplete()),
147 IndexerProgress->show();
152 return DisplayImportSummary;
157 DisplayImportSummary = onOff;
162 return PatientsAddedDuringImport;
167 return StudiesAddedDuringImport;
172 return SeriesAddedDuringImport;
177 return InstancesAddedDuringImport;
181 void DicomImporter::onFileIndexed(
const QString& filePath)
185 QCoreApplication::instance()->processEvents();
191 void DicomImporter::openImportDialog()
193 ImportDialog->show();
194 ImportDialog->raise();
198 void DicomImporter::onPatientAdded(
int databaseID, QString patientID, QString patientName, QString patientBirthDate )
200 Q_UNUSED(databaseID);
202 Q_UNUSED(patientName);
203 Q_UNUSED(patientBirthDate);
204 ++PatientsAddedDuringImport;
208 void DicomImporter::onStudyAdded(QString studyUID)
211 ++StudiesAddedDuringImport;
215 void DicomImporter::onSeriesAdded(QString seriesUID)
218 ++SeriesAddedDuringImport;
222 void DicomImporter::onInstanceAdded(QString instanceUID)
224 Q_UNUSED(instanceUID);
225 ++InstancesAddedDuringImport;
231 if (QDir(directory).exists())
233 QCheckBox* copyOnImport = qobject_cast<QCheckBox*>(ImportDialog->bottomWidget());
234 QString targetDirectory;
235 if (copyOnImport->checkState() == Qt::Checked)
237 targetDirectory = DICOMDatabase->databaseDirectory();
241 PatientsAddedDuringImport = 0;
242 StudiesAddedDuringImport = 0;
243 SeriesAddedDuringImport = 0;
244 InstancesAddedDuringImport = 0;
248 DICOMIndexer->addDirectory(*DICOMDatabase,directory,targetDirectory);
251 if (DisplayImportSummary)
253 QString message =
"Directory import completed.\n\n";
254 message += QString(
"%1 New Patients\n").arg(QString::number(PatientsAddedDuringImport));
255 message += QString(
"%1 New Studies\n").arg(QString::number(StudiesAddedDuringImport));
256 message += QString(
"%1 New Series\n").arg(QString::number(SeriesAddedDuringImport));
257 message += QString(
"%1 New Instances\n").arg(QString::number(InstancesAddedDuringImport));
258 QMessageBox::information(NULL,
"DICOM Directory Import", message);
int seriesAddedDuringImport()
bool displayImportSummary()
int studiesAddedDuringImport()
void setDatabase(QSharedPointer< ctkDICOMDatabase > database)
int patientsAddedDuringImport()
Accessors to status of last directory import operation.
void setDisplayImportSummary(bool)
DicomImporter(QObject *parent=NULL)
void onImportDirectory(QString directory)
void fileIndexed(QString)
int instancesAddedDuringImport()