QtDcm.cpp
Go to the documentation of this file.
1 /*
2  QtDcm is a C++ Qt based library for communication and conversion of Dicom images.
3  Copyright (C) 2011 Alexandre Abadie <Alexandre.Abadie@univ-rennes1.fr>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #include "QtDcm.h"
21 
22 #include <QFileDialog>
23 
24 #include <QtDcmPatient.h>
25 #include <QtDcmStudy.h>
26 #include <QtDcmSerie.h>
27 #include <QtDcmServer.h>
28 #include <QtDcmImage.h>
29 #include <QtDcmPreferences.h>
30 #include <QtDcmPreferencesDialog.h>
31 #include <QtDcmManager.h>
32 
34 {
35 
36 public:
37  int mode;
38  QList<QString> imagesList;
39  QString currentSerieId;
40  QDate beginDate, endDate;
41  QMap<QString, QList<QString> > selectedSeries;
42 };
43 
44 QtDcm::QtDcm ( QWidget *parent )
45  : QWidget ( parent ), d ( new QtDcmPrivate )
46 {
47  QTextCodec::setCodecForLocale( QTextCodec::codecForName ( "iso" ) );
48  setupUi ( this );
49  d->mode = QtDcm::CD_MODE;
50 
51  //Initialize QTreeWidgetPatients
52  treeWidgetPatients->setColumnWidth ( 0, 400 );
53  treeWidgetPatients->setColumnWidth ( 1, 100 );
54  treeWidgetPatients->setColumnWidth ( 2, 100 );
55  const QStringList labelsPatients = QStringList()
56  << "Patients name"
57  << "ID"
58  << "Birthdate"
59  << "Sex";
60 
61  treeWidgetPatients->setHeaderLabels ( labelsPatients );
62  treeWidgetPatients->setContextMenuPolicy ( Qt::CustomContextMenu );
63 
64  //Initialize QTreeWidgetSeries
65  treeWidgetStudies->setColumnWidth ( 0, 200 );
66  treeWidgetStudies->setColumnWidth ( 1, 100 );
67  const QStringList labelsStudies = QStringList()
68  << "Studies description"
69  << "Date"
70  << "ID";
71 
72  treeWidgetStudies->setHeaderLabels ( labelsStudies );
73  treeWidgetStudies->setContextMenuPolicy ( Qt::CustomContextMenu );
74 
75  //Initialize QTreeWidgetSeries
76  treeWidgetSeries->setColumnWidth ( 0, 230 );
77  treeWidgetSeries->setColumnWidth ( 1, 100 );
78  treeWidgetSeries->setColumnWidth ( 2, 100 );
79  const QStringList labelsSeries = QStringList()
80  << "Series description"
81  << "Modality"
82  << "Date"
83  << "ID";
84 
85  treeWidgetSeries->setHeaderLabels ( labelsSeries );
86  treeWidgetSeries->setContextMenuPolicy ( Qt::CustomContextMenu );
87 
88  //Initialize widgets
89  QDate currentDate = QDate::currentDate();
90  startDateEdit->setDate ( currentDate.addYears(-100) );
91  endDateEdit->setDate ( currentDate );
92 
93  QtDcmManager::instance()->setPatientsTreeWidget ( treeWidgetPatients );
94  QtDcmManager::instance()->setStudiesTreeWidget ( treeWidgetStudies );
95  QtDcmManager::instance()->setSeriesTreeWidget ( treeWidgetSeries );
96  QtDcmManager::instance()->setStartDate ( startDateEdit->date() );
97  QtDcmManager::instance()->setEndDate ( endDateEdit->date() );
98 
100 }
101 
103 {
104  delete d;
105  d = NULL;
106 }
107 
109 {
110  // Initialize connections
111  connect ( treeWidgetPatients, &QTreeWidget::currentItemChanged,
113  connect ( treeWidgetStudies, &QTreeWidget::currentItemChanged,
115  connect ( treeWidgetSeries, &QTreeWidget::currentItemChanged,
117  connect ( treeWidgetSeries, &QTreeWidget::itemClicked,
119  connect ( nameEdit, &QLineEdit::textChanged,
121  connect ( serieDescriptionEdit, &QLineEdit::textChanged,
123  connect ( studyDescriptionEdit, &QLineEdit::textChanged,
125  connect ( searchButton, &QPushButton::clicked,
127  connect ( cdromButton, &QPushButton::clicked,
129  connect ( patientSexComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
131  connect ( serieModalityComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
133  connect ( pacsComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
135  connect ( startDateEdit, &QDateEdit::dateChanged,
137  connect ( endDateEdit, &QDateEdit::dateChanged,
138  this, &QtDcm::onEndDateChanged);
139 }
140 
142 {
143  pacsComboBox->blockSignals ( true );
144  pacsComboBox->clear();
145 
146  for ( int i = 0; i < QtDcmPreferences::instance()->servers().size(); i++ ) {
147  pacsComboBox->addItem ( QtDcmPreferences::instance()->servers().at ( i ).name() );
148  }
149 
150  pacsComboBox->blockSignals ( false );
151 }
152 
154 {
155  d->mode = QtDcm::PACS_MODE;
156  treeWidgetPatients->clear();
157  treeWidgetStudies->clear();
158  treeWidgetSeries->clear();
159  QtDcmManager::instance()->setCurrentPacs ( pacsComboBox->currentIndex() );
161 }
162 
164 {
165  treeWidgetPatients->clear();
166  treeWidgetStudies->clear();
167  treeWidgetSeries->clear();
168 }
169 
170 void QtDcm::onPatientItemSelected ( QTreeWidgetItem* current, QTreeWidgetItem* previous )
171 {
172  if (!current) {
173  return;
174  }
175 
178 
179  treeWidgetStudies->clear();
180 
181  if ( d->mode == QtDcm::PACS_MODE ) {
182  QtDcmManager::instance()->findStudiesScu ( current->text ( 0 ) );
183  }
184  else {
185  QtDcmManager::instance()->findStudiesDicomdir ( current->text ( 0 ) );
186  }
187 
189 }
190 
191 void QtDcm::onStudyItemSelected ( QTreeWidgetItem* current, QTreeWidgetItem* previous )
192 {
193  if (!current) {
194  return;
195  }
196 
197  treeWidgetSeries->clear();
198 
201 
202  if ( d->mode == QtDcm::PACS_MODE ) {
203  QtDcmManager::instance()->findSeriesScu ( treeWidgetPatients->currentItem()->text ( 0 ), current->data ( 2, 0 ).toString() );
204  }
205  else {
206  QtDcmManager::instance()->findSeriesDicomdir ( treeWidgetPatients->currentItem()->text ( 0 ), current->data ( 2, 0 ).toString() );
207  }
208 
210 }
211 
212 void QtDcm::onSerieItemSelected ( QTreeWidgetItem* current, QTreeWidgetItem* previous )
213 {
214  if (!current) {
215  return;
216  }
217 
219 
220  if ( d->mode == QtDcm::CD_MODE )
221  QtDcmManager::instance()->findImagesDicomdir ( current->text ( 3 ) );
222  else
223  QtDcmManager::instance()->findImagesScu ( current->text ( 3 ) );
224 
225  int elementCount = QtDcmManager::instance()->listOfImages().size();
226  QString institution = current->data ( 5, 0 ).toString();
227  QString opName = current->data ( 6, 0 ).toString();
228 
229  QtDcmManager::instance()->updateSerieInfo ( QString::number ( elementCount ), institution, opName );
230 // QtDcmManager::instance()->clearPreview();
231  QtDcmManager::instance()->getPreviewFromSelectedSerie ( current->text ( 3 ), elementCount / 2 );
232 }
233 
234 void QtDcm::onSerieItemClicked ( QTreeWidgetItem * item, int column )
235 {
236  if ( item->checkState ( 0 ) == Qt::Checked ) {
237  QtDcmManager::instance()->addSerieToImport ( item->text ( 3 ) );
238  }
239  else {
240  QtDcmManager::instance()->removeSerieToImport ( item->text ( 3 ) );
241  }
242 }
243 
245 {
246  this->openDicomdir();
247 }
248 
250 {
251  this->clearDisplay();
253 }
254 
256 {
258 }
259 
261 {
262  switch ( index )
263  {
264  case ALL_MODALITIES://*
266  break;
267 
268  case MR_MODALITY:
270  break;
271 
272  case CT_MODALITY:
274  break;
275 
276  case PET_MODALITY:
277  QtDcmManager::instance()->setModality ( "PET" );
278  break;
279  default:
280  qWarning() << "Modality not supported: " << serieModalityComboBox->currentText();
281  break;
282  }
283 
284  treeWidgetSeries->clear();
285 
286  if ( treeWidgetPatients->currentItem() && treeWidgetStudies->currentItem() ) {
287  if ( d->mode == QtDcm::PACS_MODE ) {
288  QtDcmManager::instance()->findSeriesScu ( treeWidgetPatients->currentItem()->text ( 0 ), treeWidgetStudies->currentItem()->data ( 2, 0 ).toString() );
289  }
290  else {
291  QtDcmManager::instance()->findSeriesDicomdir ( treeWidgetPatients->currentItem()->text ( 0 ), treeWidgetStudies->currentItem()->data ( 2, 0 ).toString() );
292  }
293  }
294 }
295 
297 {
298  switch ( index )
299  {
300  case ALL_GENDER:
302  this->queryPACS();
303  break;
304 
305  case M_GENDER:
307  this->queryPACS();
308  break;
309 
310  case F_GENDER:
312  this->queryPACS();
313  break;
314  default:
315  qWarning() << "Gender not supported: " << patientSexComboBox->currentText();
316  break;
317  }
318 }
319 
320 void QtDcm::onCurrentPacsChanged ( int index )
321 {
324 }
325 
326 void QtDcm::onStartDateChanged(const QDate &startdate)
327 {
328  if ( startdate > endDateEdit->date() ) {
329  startDateEdit->blockSignals(true);
330  startDateEdit->setDate ( endDateEdit->date() );
331  startDateEdit->blockSignals(false);
332  }
333 
334  QtDcmManager::instance()->setStartDate ( startDateEdit->date() );
335 
336  treeWidgetStudies->clear();
337  treeWidgetSeries->clear();
338 
339  if ( treeWidgetPatients->currentItem() ) {
340  if ( d->mode == QtDcm::PACS_MODE ) {
341  QtDcmManager::instance()->findStudiesScu ( treeWidgetPatients->currentItem()->text ( 0 ) );
342  }
343  else {
344  qDebug() << "Date filtering not available in CD-Rom mode";
345  }
346  }
347 }
348 
349 void QtDcm::onEndDateChanged (const QDate &enddate)
350 {
351  if ( enddate < startDateEdit->date() ) {
352  endDateEdit->blockSignals(true);
353  endDateEdit->setDate(startDateEdit->date() );
354  endDateEdit->blockSignals(false);
355  }
356 
357  QtDcmManager::instance()->setEndDate ( endDateEdit->date() );
358 
359  treeWidgetStudies->clear();
360  treeWidgetSeries->clear();
361 
362  if ( treeWidgetPatients->currentItem() ) {
363  if ( d->mode == QtDcm::PACS_MODE ) {
364  QtDcmManager::instance()->findStudiesScu ( treeWidgetPatients->currentItem()->text ( 0 ) );
365  }
366  else {
367  qDebug() << "Date filtering not available in CD-Rom mode";
368  }
369  }
370 }
371 
373 {
374  //Launch a dialog window for editing PACS settings
375  QtDcmPreferencesDialog dialog( this );
376  dialog.readPreferences();
377  if ( dialog.exec() ) {
378  dialog.updatePreferences();
379  }
380 }
381 
383 {
384  this->clearDisplay();
385  d->mode = QtDcm::CD_MODE;
386  // Open a QFileDialog for choosing a Dicomdir
387  QFileDialog dialog(this);
388  dialog.setWindowTitle ( tr ( "Open dicomdir" ) );
389  dialog.setNameFilters(QStringList() << "Dicomdir files (dicomdir* DICOMDIR*)");
390 
391  // Trying to open directly on one of the available drives
392  if (!QDir::drives().isEmpty()) {
393  dialog.setDirectory ( QDir::drives().first().absoluteDir() );
394  }
395 
396  QString fileName;
397  if ( dialog.exec() ) {
398  fileName = dialog.selectedFiles() [0];
399  }
400 
401  if ( !fileName.isEmpty() ) { // A file has been chosen{
402  if (QString::compare(fileName, "dicomdir", Qt::CaseInsensitive)) {
403  QtDcmManager::instance()->setDicomdir ( fileName );
404  this->loadPatientsFromDicomdir();
405  }
406  }
407 }
408 
409 void QtDcm::onPatientNameTextChanged (const QString &pName)
410 {
411  if (pName.isEmpty() ) {
413  }
414  else {
415  QtDcmManager::instance()->setPatientName ( pName + "*" );
416  }
417 
418  if ( d->mode == QtDcm::PACS_MODE ) {
420  }
421 }
422 
423 void QtDcm::onStudyDescriptionTextChanged (const QString &description)
424 {
425  if ( description.isEmpty() ) {
427  }
428  else {
429  QtDcmManager::instance()->setStudyDescription ( "*" + description + "*" );
430  }
431 
432  if ( d->mode == QtDcm::PACS_MODE ) {
433  treeWidgetStudies->clear();
434  treeWidgetSeries->clear();
435  }
436 
437  if ( treeWidgetPatients->currentItem() && d->mode == QtDcm::PACS_MODE ) {
438  QtDcmManager::instance()->findStudiesScu ( treeWidgetPatients->currentItem()->text ( 0 ) );
439  }
440 }
441 
442 void QtDcm::onSerieDescriptionTextChanged (const QString &description)
443 {
444  if ( description.isEmpty() ) {
446  }
447  else {
448  QtDcmManager::instance()->setSerieDescription ( "*" + description + "*" );
449  }
450 
451  if ( d->mode == QtDcm::PACS_MODE ) {
452  treeWidgetSeries->clear();
453  }
454 
455  if ( treeWidgetPatients->currentItem() && treeWidgetStudies->currentItem() && d->mode == QtDcm::PACS_MODE) {
456  QtDcmManager::instance()->findSeriesScu ( treeWidgetPatients->currentItem()->text ( 0 ), treeWidgetStudies->currentItem()->data ( 2, 0 ).toString() );
457  }
458 }
void findPatientsScu()
Find SCU with Dcmtk code.
void loadDicomdir()
This method read the dicomdir file and populate the patient treewidget.
void setSeriesTreeWidget(QTreeWidget *widget)
static QtDcmPreferences * instance()
void setPatientsTreeWidget(QTreeWidget *widget)
QtDcm(QWidget *parent=0)
Definition: QtDcm.cpp:44
void onStartDateChanged(const QDate &startdate)
Definition: QtDcm.cpp:326
void setSerieDescription(const QString &serieDescription)
Serie description setter.
void findImagesDicomdir(const QString &serieUID)
void removeSerieToImport(const QString &uid)
void onPatientItemSelected(QTreeWidgetItem *current, QTreeWidgetItem *previous)
Definition: QtDcm.cpp:170
void editPreferences()
Opens the PACS preferences dialog.
Definition: QtDcm.cpp:372
void getPreviewFromSelectedSerie(const QString &uid, int elementCount)
void onSerieItemSelected(QTreeWidgetItem *current, QTreeWidgetItem *previous)
Definition: QtDcm.cpp:212
void onCurrentModalityChanged(int index)
Definition: QtDcm.cpp:260
void setCurrentPacs(int index)
void findSeriesScu(const QString &patientName, const QString &studyUID)
static QtDcmManager * instance()
void queryPACS()
Definition: QtDcm.cpp:255
QList< QtDcmServer > servers() const
QtDcm server list getter.
void findSeriesDicomdir(const QString &patientName, const QString &studyDescription)
void setStudiesTreeWidget(QTreeWidget *widget)
void onStudyDescriptionTextChanged(const QString &description)
Definition: QtDcm.cpp:423
void updatePacsComboBox()
Updates the PACS list in combo box.
Definition: QtDcm.cpp:141
QList< QString > imagesList
Definition: QtDcm.cpp:38
void setPatientGender(const QString &sex)
void updateSerieInfo(const QString &eltCount, const QString &institution, const QString &name)
QMap< QString, QList< QString > > selectedSeries
Begin and end for Q/R retrieve parameters.
Definition: QtDcm.cpp:41
QList< QString > listOfImages() const
void setPatientName(const QString &patientName)
Patient name setter.
void addSerieToImport(const QString &uid)
void findImagesScu(const QString &uid)
void onEndDateChanged(const QDate &enddate)
Definition: QtDcm.cpp:349
void clearDisplay()
Definition: QtDcm.cpp:163
void findStudiesScu(const QString &patientName)
void setEndDate(const QDate &date)
Study date setter.
void loadPatientsFromDicomdir()
Definition: QtDcm.cpp:249
void setStudyDescription(const QString &studyDescription)
Study description setter.
void setStartDate(const QDate &date)
Study date setter.
void onSerieDescriptionTextChanged(const QString &description)
Definition: QtDcm.cpp:442
void onCurrentGenderChanged(int index)
Definition: QtDcm.cpp:296
QDate endDate
Definition: QtDcm.cpp:40
virtual ~QtDcm()
constructor
Definition: QtDcm.cpp:102
void onDicomMediaButtonClicked()
Definition: QtDcm.cpp:244
void openDicomdir()
Opens the dicomdir selectiondialog.
Definition: QtDcm.cpp:382
void initConnections()
Definition: QtDcm.cpp:108
void onPacsSearchButtonClicked()
Definition: QtDcm.cpp:153
void clearSerieInfo()
QDate beginDate
Id of the current selected serie.
Definition: QtDcm.cpp:40
void setDicomdir(const QString &dicomdir)
Set the dicomdir file name.
void onStudyItemSelected(QTreeWidgetItem *current, QTreeWidgetItem *previous)
Definition: QtDcm.cpp:191
void onCurrentPacsChanged(int index)
Definition: QtDcm.cpp:320
void setModality(const QString &modality)
Study modality setter.
QString currentSerieId
Contains the images filenames of the current serie (i.e selected in the treewidget) ...
Definition: QtDcm.cpp:39
int mode
Definition: QtDcm.cpp:37
void onPatientNameTextChanged(const QString &pName)
Definition: QtDcm.cpp:409
void clearPreview()
void clearListOfImages()
void findStudiesDicomdir(const QString &patientName)
void onSerieItemClicked(QTreeWidgetItem *current, int index)
Definition: QtDcm.cpp:234