1 #include "vvQPacsConnection.h"
2 #include "gdcmCompositeNetworkFunctions.h"
3 #include <QtGui/qlistview.h>
8 #include "vvPacsSettingsDialog.h"
11 #include <itkGDCMImageIO.h>
12 #include <itkGDCMSeriesFileNames.h>
15 vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
19 setWindowTitle(QString::fromUtf8("PACS CONNECTION"));
21 ui.tabFilter->setTabText(0,QString(tr("Modality")));
22 ui.tabFilter->setTabText(1,QString(tr("Date")));
24 ui. tabNetwork->setTabText(0,QString(tr("Network")));
25 ui. tabNetwork->setTabText(1,QString(tr("Configuration")));
26 ui.check_ModAll->setEnabled(true);
27 ui.networkCombo->addItem("");
28 ui.networkCombo->addItems(getDicomServers());
31 connect(ui.networkCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(chooseServer(int)));
32 connect(ui.removeNetworkButton,SIGNAL(clicked()),this,SLOT(removeServer()));
33 connect(ui.NetworkButton,SIGNAL(clicked()),this,SLOT(modifyServer()));
34 connect(ui.exitButton,SIGNAL(clicked()),this,SLOT(close()));
40 bool vvQPacsConnection::close()
42 QApplication::restoreOverrideCursor();
43 return QWidget::close();
46 // remote a Dicom Server in VV settings
47 void vvQPacsConnection::removeServer()
49 removeDicomServer(m_nickname);
50 ui.networkCombo->removeItem(ui.networkCombo->findText(QString(m_nickname.c_str())));
55 // modify a Dicom Server in VV settings
56 void vvQPacsConnection::modifyServer()
58 AddDicomServer(ui.NameEdit->text().toStdString(),ui.AETitleEdit->text().toStdString(),ui.AdressEdit->text().toStdString(),ui.PortEdit->text().toStdString());
62 // refresh the list of Dicom Servers available from VV settings
63 void vvQPacsConnection::refreshNetworks()
65 ui.networkCombo->clear();
66 ui.networkCombo->addItem(QString());
67 ui.networkCombo->addItems(getDicomServers());
68 ui.NameEdit->setText(QString());
69 ui.AETitleEdit->setText(QString());
70 ui.AdressEdit->setText(QString());
71 ui.PortEdit->setText(QString());
72 ui.tabNetwork->setCurrentIndex(0);
75 void vvQPacsConnection::on_clearButton_clicked()
77 Patientmodel->removeRows(0, Patientmodel->rowCount(),QModelIndex());
78 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
79 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
80 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
83 void vvQPacsConnection::on_scanButton_clicked()
86 manageStudiesFilter(true);
88 // test first if echo works
89 bool didItWork = gdcm::CompositeNetworkFunctions::CEcho(m_adress.c_str(), atoi(m_port.c_str()), getDicomClientAETitle().c_str(), m_nickname.c_str() );
92 m_level =gdcm::ePatient;
93 std::vector<gdcm::DataSet> theDataSet;
94 f_query = mQFactory.getQueryPatient(ui.patientName->toPlainText().toStdString(), ui.patientID->toPlainText().toStdString());
96 bool cfindWork = gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
97 gdcm::CompositeNetworkFunctions::ConstructQuery(f_query.theRoot, f_query.theLevel ,f_query.keys),
98 theDataSet, getDicomClientAETitle().c_str() , m_nickname.c_str());
101 convertDataSet(theDataSet,Patientmodel,mQFactory.getPatientKeys("",""));
107 /// show Options DialogBox to set a new Dicom Server
108 void vvQPacsConnection::on_optionsButton_clicked()
110 vvPacsSettingsDialog *dg = new vvPacsSettingsDialog(this);
114 void vvQPacsConnection::convertDataSet(std::vector<gdcm::DataSet> i_ds, QStandardItemModel *i_model, std::vector< std::pair<gdcm::Tag, std::string> > keys)
117 std::vector<gdcm::DataSet>::iterator it_ds = i_ds.begin();
118 for(; it_ds != i_ds.end(); it_ds++)
120 QList<QStandardItem *> items;
121 const gdcm::DataSet ds = (*it_ds);
122 std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
124 for(; it_key != keys.end(); it_key++, ind++)
126 gdcm::DataElement de = ds.GetDataElement((*it_key).first);
127 QStandardItem *item = new QStandardItem;
128 const gdcm::ByteValue *bv = (de).GetByteValue();
131 std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
132 item->setText(tr(buffer.c_str()));
136 item->setText(tr(""));
140 item->setCheckable(true);
142 items.push_back(item);
144 i_model->appendRow(items);
148 // TreeViews creation
149 void vvQPacsConnection::createTreeView()
152 Patientmodel = new QStandardItemModel(0,2,this);
153 QStringList Patientlist;
154 Patientlist.push_back(tr("PATIENT NAME"));
155 Patientlist.push_back(tr("PATIENT ID"));
156 Patientmodel->setHorizontalHeaderLabels(Patientlist);
157 ui.patientTreeView->setModel(Patientmodel);
158 ui.patientTreeView->setEnabled(true);
159 connect(ui.patientTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStudies(QModelIndex)));
162 Studymodel = new QStandardItemModel(0,3,this);
163 QStringList Studylist;
164 Studylist.push_back(tr("DESCRIPTION"));
165 Studylist.push_back(tr("DATE"));
166 Studylist.push_back(tr("HOUR"));
167 Studylist.push_back(tr("STUDY ID"));
168 Studymodel->setHorizontalHeaderLabels(Studylist);
169 ui.studyTreeView->setModel(Studymodel);
170 connect(ui.studyTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectSeries(QModelIndex)));
174 Seriesmodel = new QStandardItemModel(0,2,this);
175 QStringList Serieslist;
176 Serieslist.push_back(tr("MODALITY"));
177 Serieslist.push_back(tr("DESCRIPTION"));
178 Serieslist.push_back(tr("no. accept."));
179 Seriesmodel->setHorizontalHeaderLabels(Serieslist);
180 ui.seriesTreeView->setModel(Seriesmodel);
181 connect(ui.seriesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImages(QModelIndex)));
182 connect(ui.imagesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImage(QModelIndex)));
184 Imagesmodel = new QStandardItemModel(0,1,this);
185 QStringList Imageslist;
186 Imageslist.push_back(tr("instance number"));
187 Imageslist.push_back(tr("sopuid"));
188 Imagesmodel->setHorizontalHeaderLabels(Imageslist);
189 ui.imagesTreeView->setModel(Imagesmodel);
192 // clean the different model Trees
193 void vvQPacsConnection::cleanTree()
195 Patientmodel->removeRows(0,Patientmodel->rowCount());
196 Studymodel->removeRows(0,Patientmodel->rowCount());
197 Seriesmodel->removeRows(0,Patientmodel->rowCount());
198 Imagesmodel->removeRows(0,Patientmodel->rowCount());
202 void vvQPacsConnection::selectStudies(const QModelIndex &index)
205 m_patient= Patientmodel->data(index.sibling(index.row(),1)).toString().toStdString();
206 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
207 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
208 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
209 manageSeriesFilter(true);
210 convertDataSet( findQuery( mQFactory.getQueryforStudy(m_patient, false)) , Studymodel, mQFactory.getQueryKeysforStudy("",true));
214 void vvQPacsConnection::clearMove()
219 void vvQPacsConnection::selectSeries(const QModelIndex &index)
221 m_study= Studymodel->data(index.sibling(index.row(),3)).toString().toStdString();
222 Seriesmodel->removeRows(0, Seriesmodel->rowCount());
223 Imagesmodel->removeRows(0, Imagesmodel->rowCount());
224 convertDataSet( findQuery( mQFactory.getQueryforSeries(m_patient,m_study, false)), Seriesmodel, mQFactory.getSeriesKeys("","",true));
228 void vvQPacsConnection::selectImages(const QModelIndex &index)
230 m_series = Seriesmodel->data(index.sibling(index.row(),2)).toString().toStdString();
231 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
232 convertDataSet( findQuery( mQFactory.getQueryforImages(m_patient,m_study, m_series, false) ), Imagesmodel, mQFactory.getQueryKeysforImages("","","",true));
236 void vvQPacsConnection::selectImage(const QModelIndex &index)
238 std::string _image = Imagesmodel->data(index.sibling(index.row(),1)).toString().toStdString();
239 mQFactory.setQueryforImage(m_patient,m_study, m_series, _image);
244 std::vector<gdcm::DataSet> vvQPacsConnection::findQuery(vvQuery i_query)
246 std::vector<gdcm::DataSet> theDataSet;
247 gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
248 gdcm::CompositeNetworkFunctions::ConstructQuery(i_query.theRoot, i_query.theLevel,i_query.keys), theDataSet,
249 getDicomClientAETitle().c_str(), m_nickname.c_str());
253 void vvQPacsConnection::manageStudiesFilter(bool i_enable)
255 ui.text_PHYS->setEnabled(i_enable);
256 ui.text_SDESC->setEnabled(i_enable);
257 ui.dateTab->setEnabled(i_enable);
261 void vvQPacsConnection::manageSeriesFilter(bool i_enable)
263 ui.modalityTab->setEnabled(i_enable);
267 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getStudyKeys(const std::string i_val)
269 std::vector< std::pair<gdcm::Tag, std::string> > keys;
271 gdcm::Tag tagsdc(0x0008,0x1030);
272 keys.push_back(std::make_pair(tagsdc, ""));
274 gdcm::Tag tagdb(0x0008,0x0020);
275 keys.push_back(std::make_pair(tagdb, ""));
277 gdcm::Tag tagsdh(0x0008,0x0030);
278 keys.push_back(std::make_pair(tagsdh, ""));
279 // Study Instance UID
280 gdcm::Tag tagsid(0x0020,0x000d);
281 keys.push_back(std::make_pair(tagsid, i_val));
286 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
288 std::vector< std::pair<gdcm::Tag, std::string> > keys;
290 gdcm::Tag tag(0x0010,0x0010);
291 keys.push_back(std::make_pair(tag, ""));
294 gdcm::Tag tagpid(0x0010,0x0020);
295 keys.push_back(std::make_pair(tagpid, ""));
298 gdcm::Tag tagmod(0x0008,0x0061);
299 keys.push_back(std::make_pair(tagmod, ""));
302 gdcm::Tag tagdb(0x0010,0x0030);
303 keys.push_back(std::make_pair(tagdb, ""));
306 gdcm::Tag tagsd(0x0020,0x000D);
307 keys.push_back(std::make_pair(tagsd, ""));
310 //gdcm::Tag tagst(8,30);
311 //keys.push_back(std::make_pair(tagst, ""));
313 //// Study Description
314 //gdcm::Tag tagsdc(8,1030);
315 //keys.push_back(std::make_pair(tagsdc, ""));
318 //gdcm::Tag tagacc(8,50);
319 //keys.push_back(std::make_pair(tagacc, ""));
324 void vvQPacsConnection::on_check_ModAll_clicked(bool state)
326 ui.check_MR->setEnabled(!state);
327 ui.check_CR->setEnabled(!state);
328 ui.check_OT->setEnabled(!state);
329 ui.check_RF->setEnabled(!state);
330 ui.check_SC->setEnabled(!state);
331 ui.check_CT->setEnabled(!state);
332 ui.check_US->setEnabled(!state);
333 ui.check_NM->setEnabled(!state);
334 ui.check_DR->setEnabled(!state);
335 ui.check_US->setEnabled(!state);
336 ui.check_NM->setEnabled(!state);
337 ui.check_DR->setEnabled(!state);
338 ui.check_SR->setEnabled(!state);
339 ui.check_XA->setEnabled(!state);
340 ui.check_MG->setEnabled(!state);
343 ui.check_MR->setChecked(state);
344 ui.check_CR->setChecked(state);
345 ui.check_OT->setChecked(state);
346 ui.check_RF->setChecked(state);
347 ui.check_SC->setChecked(state);
348 ui.check_CT->setChecked(state);
349 ui.check_US->setChecked(state);
350 ui.check_NM->setChecked(state);
351 ui.check_DR->setChecked(state);
352 ui.check_US->setChecked(state);
353 ui.check_NM->setChecked(state);
354 ui.check_DR->setChecked(state);
355 ui.check_SR->setChecked(state);
356 ui.check_XA->setChecked(state);
357 ui.check_MG->setChecked(state);
362 void vvQPacsConnection::chooseServer(int index)
364 std::map < std::string, std:: string> values = getDicomServer(ui.networkCombo->currentText());
365 m_port = values["PORT"];
366 m_aetitle = values["AETITLE"];
367 m_adress= values["ADRESS"];
368 m_nickname = values["nickname"];
369 ui.AdressEdit->setText(QString(m_adress.c_str()));
370 ui.AETitleEdit->setText(QString(m_aetitle.c_str()));
371 ui.NameEdit->setText(QString(m_nickname.c_str()));
372 ui.PortEdit->setText(QString(m_port.c_str()));
375 void vvQPacsConnection::on_importButton_clicked()
377 setCursor(QCursor(Qt::WaitCursor));
378 QString path = QString::fromStdString(getCMoveDirectory());
380 if (dirpath.exists())
382 QFileInfoList list = dirpath.entryInfoList( QDir::Files);
383 QFileInfoList::iterator it_file = dirpath.entryInfoList( QDir::Files).begin();
384 for(int i = 0; i < list.length() ; i++)
386 QFile::remove(list.at(i).filePath());
393 bool didItWork = gdcm::CompositeNetworkFunctions::CMove(m_adress.c_str(),atoi(m_port.c_str()),
394 gdcm::CompositeNetworkFunctions::ConstructQuery(mQFactory.getMoveQuery().theRoot, mQFactory.getMoveQuery().theLevel ,mQFactory.getMoveQuery().keys, gdcm::eMove),
395 getDicomClientPort(), getDicomClientAETitle().c_str(), m_aetitle.c_str(), path.toStdString().c_str() );
396 gdcm::Directory theDir;
397 theDir.Load(path.toStdString().c_str());
398 //m_files = theDir.GetFilenames();
400 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
401 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
402 nameGenerator->SetUseSeriesDetails(true);
404 //ds gerer recursive moi-meme pour progress ...
405 nameGenerator->SetInputDirectory(path.toStdString());
408 typedef std::vector<std::string> SeriesIdContainer;
409 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
410 std::map<std::string, std::vector<std::string>* > mListOfSeriesFilenames;
413 m_fileseries.clear();
415 for (unsigned int i=0; i<seriesUID.size(); i++) {
416 m_fileseries.push_back( nameGenerator->GetFileNames(seriesUID[i]));
420 setCursor(QCursor(Qt::ArrowCursor));
425 std::vector <std::string> vvQPacsConnection::getFileNames(int i_series)
427 std::vector <std::string> filenames;
428 gdcm::Directory::FilenamesType::iterator it = m_fileseries[i_series].begin();
429 for (;it != m_fileseries[i_series].end(); it++)
430 filenames.push_back(it->c_str());
433 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::fillMoveKeys()
435 std::vector< std::pair<gdcm::Tag, std::string> > keys;
439 //keys.push_back(getPatientKeys("",""));