Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkDicomLocalStorageWidget.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 // Qmitk
19 //#include <mitkLogMacros.h>
20 
21 // Qt
22 #include <QLabel>
23 #include <QMessageBox>
24 #include <QProgressDialog>
25 #include <QVariant>
26 
27 const std::string QmitkDicomLocalStorageWidget::Widget_ID = "org.mitk.Widgets.QmitkDicomLocalStorageWidget";
28 
30  : QWidget(parent), m_LocalIndexer(new ctkDICOMIndexer(parent)), m_Controls(nullptr)
31 {
32  CreateQtPartControl(this);
33 }
34 
36 {
37  m_LocalDatabase->closeDatabase();
38 }
39 
41 {
42  if (!m_Controls)
43  {
44  m_Controls = new Ui::QmitkDicomLocalStorageWidgetControls;
45  m_Controls->setupUi(parent);
46 
47  connect(m_Controls->deleteButton, SIGNAL(clicked()), this, SLOT(OnDeleteButtonClicked()));
48  connect(m_Controls->viewInternalDataButton, SIGNAL(clicked()), this, SLOT(OnViewButtonClicked()));
49 
50  connect(m_Controls->ctkDicomBrowser,
51  SIGNAL(seriesSelectionChanged(const QStringList &)),
52  this,
53  SLOT(OnSeriesSelectionChanged(const QStringList &)));
54  connect(m_Controls->ctkDicomBrowser,
55  SIGNAL(seriesSelectionChanged(const QStringList &)),
56  this,
57  SLOT(OnSeriesSelectionChanged(const QStringList &)));
58  connect(
59  m_Controls->ctkDicomBrowser, SIGNAL(seriesDoubleClicked(const QModelIndex &)), this, SLOT(OnViewButtonClicked()));
60 
61  connect(m_LocalIndexer, SIGNAL(indexingComplete()), this, SIGNAL(SignalFinishedImport()));
62 
63  m_Controls->ctkDicomBrowser->setTableOrientation(Qt::Vertical);
64  }
65 }
66 
68 {
69  if (m_LocalDatabase->isOpen())
70  {
71  m_LocalIndexer->addDirectory(*m_LocalDatabase, dicomData, m_LocalDatabase->databaseDirectory());
72  }
73 }
74 
75 void QmitkDicomLocalStorageWidget::OnStartDicomImport(const QStringList &dicomData)
76 {
77  if (m_LocalDatabase->isOpen())
78  {
79  m_LocalIndexer->addListOfFiles(*m_LocalDatabase, dicomData, m_LocalDatabase->databaseDirectory());
80  }
81 }
82 
84 {
85  if (!this->DeletePatients())
86  {
87  if (!this->DeleteStudies())
88  {
89  this->DeleteSeries();
90  }
91  }
92 
93  m_Controls->ctkDicomBrowser->updateTableViews();
94 }
95 
97 {
98  auto selectedPatientUIDs = m_Controls->ctkDicomBrowser->currentPatientsSelection();
99 
100  if (!selectedPatientUIDs.empty())
101  {
102  QStringList studyUIDs;
103 
104  for (const auto &patientUID : selectedPatientUIDs)
105  studyUIDs.append(m_LocalDatabase->studiesForPatient(patientUID));
106 
107  QStringList seriesUIDs;
108 
109  for (const auto &studyUID : studyUIDs)
110  seriesUIDs.append(m_LocalDatabase->seriesForStudy(studyUID));
111 
112  auto answer = QMessageBox::question(nullptr,
113  "Delete Patients",
114  QString("Do you really want to delete %1 %2, containing %3 series in %4 %5?")
115  .arg(selectedPatientUIDs.count())
116  .arg(selectedPatientUIDs.count() != 1 ? "patients" : "patient")
117  .arg(seriesUIDs.count())
118  .arg(studyUIDs.count())
119  .arg(studyUIDs.count() != 1 ? "studies" : "study"),
120  QMessageBox::Yes | QMessageBox::No,
121  QMessageBox::No);
122 
123  if (answer == QMessageBox::Yes)
124  {
125  for (const auto &patientUID : selectedPatientUIDs)
126  m_LocalDatabase->removePatient(patientUID);
127  }
128 
129  return true;
130  }
131 
132  return false;
133 }
134 
136 {
137  auto selectedStudyUIDs = m_Controls->ctkDicomBrowser->currentStudiesSelection();
138 
139  if (!selectedStudyUIDs.empty())
140  {
141  QStringList seriesUIDs;
142 
143  for (const auto &studyUID : selectedStudyUIDs)
144  seriesUIDs.append(m_LocalDatabase->seriesForStudy(studyUID));
145 
146  auto answer = QMessageBox::question(nullptr,
147  "Delete Studies",
148  QString("Do you really want to delete %1 %2, containing %3 series?")
149  .arg(selectedStudyUIDs.count())
150  .arg(selectedStudyUIDs.count() != 1 ? "studies" : "study")
151  .arg(seriesUIDs.count()),
152  QMessageBox::Yes | QMessageBox::No,
153  QMessageBox::No);
154 
155  if (answer == QMessageBox::Yes)
156  {
157  for (const auto &studyUID : selectedStudyUIDs)
158  m_LocalDatabase->removeStudy(studyUID);
159  }
160 
161  return true;
162  }
163 
164  return false;
165 }
166 
168 {
169  auto selectedSeriesUIDs = m_Controls->ctkDicomBrowser->currentSeriesSelection();
170 
171  if (!selectedSeriesUIDs.empty())
172  {
173  auto answer =
174  QMessageBox::question(nullptr,
175  "Delete Series",
176  QString("Do you really want to delete %1 series?").arg(selectedSeriesUIDs.count()),
177  QMessageBox::Yes | QMessageBox::No,
178  QMessageBox::No);
179 
180  if (answer == QMessageBox::Yes)
181  {
182  for (const auto &seriesUID : selectedSeriesUIDs)
183  m_LocalDatabase->removeSeries(seriesUID);
184  }
185 
186  return true;
187  }
188 
189  return false;
190 }
191 
193 {
194  QStringList uids = m_Controls->ctkDicomBrowser->currentSeriesSelection();
195  QString uid;
196  foreach (uid, uids)
197  {
198  QStringList filesForSeries = m_LocalDatabase->filesForSeries(uid);
199  QHash<QString, QVariant> eventProperty;
200  eventProperty.insert("FilesForSeries", filesForSeries);
201  if (!filesForSeries.isEmpty())
202  {
203  QString modality = m_LocalDatabase->fileValue(filesForSeries.at(0), "0008,0060");
204  eventProperty.insert("Modality", modality);
205  }
206  emit SignalDicomToDataManager(eventProperty);
207  }
208 }
209 
210 void QmitkDicomLocalStorageWidget::SetDatabaseDirectory(QString newDatatbaseDirectory)
211 {
212  QDir databaseDirecory = QDir(newDatatbaseDirectory);
213  if (!databaseDirecory.exists())
214  {
215  databaseDirecory.mkpath(databaseDirecory.absolutePath());
216  }
217  QString newDatatbaseFile = databaseDirecory.absolutePath() + QString("/ctkDICOM.sql");
218  this->SetDatabase(newDatatbaseFile);
219 }
220 
222 {
223  m_LocalDatabase = new ctkDICOMDatabase(databaseFile);
224  m_LocalDatabase->setParent(this);
225  m_Controls->ctkDicomBrowser->setDICOMDatabase(m_LocalDatabase);
226 }
227 
229 {
230  m_Controls->viewInternalDataButton->setEnabled((s.size() != 0));
231 }
QmitkDicomLocalStorageWidget(QWidget *parent)
QmitkDicomLocalStorageWidget(QWidget *parent) constructor.
void OnDeleteButtonClicked()
Called delete button was clicked.
virtual void CreateQtPartControl(QWidget *parent)
CreateQtPartControl(QWidget *parent) sets the view objects from ui_QmitkDicomExternalDataWidgetContro...
void SignalFinishedImport()
emitted when import into database is finished.
void SignalDicomToDataManager(QHash< QString, QVariant >)
emitted when view button is clicked.
virtual ~QmitkDicomLocalStorageWidget()
QmitkDicomExternalDataWidget destructor.
void OnSeriesSelectionChanged(const QStringList &)
Called when the selection in the series table has changed.
void SetDatabaseDirectory(QString newDatabaseDirectory)
SetDatabaseDirectory sets database directory.
void OnStartDicomImport(const QString &dicomData)
Called when adding a dicom directory. Starts a thread adding the directory.
void OnViewButtonClicked()
Called when view button was clicked.
Ui::QmitkDicomLocalStorageWidgetControls * m_Controls