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 CONNECTIONHHHH"));
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()));
38 // remote a Dicom Server in VV settings
39 void vvQPacsConnection::removeServer()
41 removeDicomServer(m_nickname);
42 ui.networkCombo->removeItem(ui.networkCombo->findText(QString(m_nickname.c_str())));
47 // modify a Dicom Server in VV settings
48 void vvQPacsConnection::modifyServer()
50 AddDicomServer(ui.NameEdit->text().toStdString(),ui.AETitleEdit->text().toStdString(),ui.AdressEdit->text().toStdString(),ui.PortEdit->text().toStdString());
54 // refresh the list of Dicom Servers available from VV settings
55 void vvQPacsConnection::refreshNetworks()
57 ui.networkCombo->clear();
58 ui.networkCombo->addItem(QString());
59 ui.networkCombo->addItems(getDicomServers());
60 ui.NameEdit->setText(QString());
61 ui.AETitleEdit->setText(QString());
62 ui.AdressEdit->setText(QString());
63 ui.PortEdit->setText(QString());
64 ui.tabNetwork->setCurrentIndex(0);
67 void vvQPacsConnection::on_clearButton_clicked()
69 Patientmodel->removeRows(0, Patientmodel->rowCount(),QModelIndex());
70 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
71 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
72 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
75 void vvQPacsConnection::on_scanButton_clicked()
78 manageStudiesFilter(true);
80 // test first if echo works
81 bool didItWork = gdcm::CompositeNetworkFunctions::CEcho(m_adress.c_str(), atoi(m_port.c_str()), getDicomClientAETitle().c_str(), m_nickname.c_str() );
84 m_level =gdcm::ePatient;
85 std::vector<gdcm::DataSet> theDataSet;
86 f_query = mQFactory.getQueryPatient(ui.patientName->toPlainText().toStdString(), ui.patientID->toPlainText().toStdString());
88 bool cfindWork = gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
89 gdcm::CompositeNetworkFunctions::ConstructQuery(f_query.theRoot, f_query.theLevel ,f_query.keys),
90 theDataSet, getDicomClientAETitle().c_str() , m_nickname.c_str());
93 convertDataSet(theDataSet,Patientmodel,mQFactory.getPatientKeys("",""));
99 /// show Options DialogBox to set a new Dicom Server
100 void vvQPacsConnection::on_optionsButton_clicked()
102 vvPacsSettingsDialog *dg = new vvPacsSettingsDialog(this);
106 void vvQPacsConnection::convertDataSet(std::vector<gdcm::DataSet> i_ds, QStandardItemModel *i_model, std::vector< std::pair<gdcm::Tag, std::string> > keys)
109 std::vector<gdcm::DataSet>::iterator it_ds = i_ds.begin();
110 for(; it_ds != i_ds.end(); it_ds++)
112 QList<QStandardItem *> items;
113 const gdcm::DataSet ds = (*it_ds);
114 std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
116 for(; it_key != keys.end(); it_key++, ind++)
118 gdcm::DataElement de = ds.GetDataElement((*it_key).first);
119 QStandardItem *item = new QStandardItem;
120 const gdcm::ByteValue *bv = (de).GetByteValue();
123 std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
124 item->setText(tr(buffer.c_str()));
128 item->setText(tr(""));
132 item->setCheckable(true);
134 items.push_back(item);
136 i_model->appendRow(items);
140 // TreeViews creation
141 void vvQPacsConnection::createTreeView()
144 Patientmodel = new QStandardItemModel(0,2,this);
145 QStringList Patientlist;
146 Patientlist.push_back(tr("PATIENT NAME"));
147 Patientlist.push_back(tr("PATIENT ID"));
148 Patientmodel->setHorizontalHeaderLabels(Patientlist);
149 ui.patientTreeView->setModel(Patientmodel);
150 ui.patientTreeView->setEnabled(true);
151 connect(ui.patientTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStudies(QModelIndex)));
154 Studymodel = new QStandardItemModel(0,3,this);
155 QStringList Studylist;
156 Studylist.push_back(tr("DESCRIPTION"));
157 Studylist.push_back(tr("DATE"));
158 Studylist.push_back(tr("HOUR"));
159 Studylist.push_back(tr("STUDY ID"));
160 Studymodel->setHorizontalHeaderLabels(Studylist);
161 ui.studyTreeView->setModel(Studymodel);
162 connect(ui.studyTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectSeries(QModelIndex)));
166 Seriesmodel = new QStandardItemModel(0,2,this);
167 QStringList Serieslist;
168 Serieslist.push_back(tr("MODALITY"));
169 Serieslist.push_back(tr("DESCRIPTION"));
170 Serieslist.push_back(tr("no. accept."));
171 Seriesmodel->setHorizontalHeaderLabels(Serieslist);
172 ui.seriesTreeView->setModel(Seriesmodel);
173 connect(ui.seriesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImages(QModelIndex)));
174 connect(ui.imagesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImage(QModelIndex)));
176 Imagesmodel = new QStandardItemModel(0,1,this);
177 QStringList Imageslist;
178 Imageslist.push_back(tr("instance number"));
179 Imageslist.push_back(tr("sopuid"));
180 Imagesmodel->setHorizontalHeaderLabels(Imageslist);
181 ui.imagesTreeView->setModel(Imagesmodel);
184 // clean the different model Trees
185 void vvQPacsConnection::cleanTree()
187 Patientmodel->removeRows(0,Patientmodel->rowCount());
188 Studymodel->removeRows(0,Patientmodel->rowCount());
189 Seriesmodel->removeRows(0,Patientmodel->rowCount());
190 Imagesmodel->removeRows(0,Patientmodel->rowCount());
194 void vvQPacsConnection::selectStudies(const QModelIndex &index)
197 m_patient= Patientmodel->data(index.sibling(index.row(),1)).toString().toStdString();
198 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
199 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
200 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
201 manageSeriesFilter(true);
202 convertDataSet( findQuery( mQFactory.getQueryforStudy(m_patient, false)) , Studymodel, mQFactory.getQueryKeysforStudy("",true));
206 void vvQPacsConnection::clearMove()
211 void vvQPacsConnection::selectSeries(const QModelIndex &index)
213 m_study= Studymodel->data(index.sibling(index.row(),3)).toString().toStdString();
214 Seriesmodel->removeRows(0, Seriesmodel->rowCount());
215 Imagesmodel->removeRows(0, Imagesmodel->rowCount());
216 convertDataSet( findQuery( mQFactory.getQueryforSeries(m_patient,m_study, false)), Seriesmodel, mQFactory.getSeriesKeys("","",true));
220 void vvQPacsConnection::selectImages(const QModelIndex &index)
222 m_series = Seriesmodel->data(index.sibling(index.row(),2)).toString().toStdString();
223 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
224 convertDataSet( findQuery( mQFactory.getQueryforImages(m_patient,m_study, m_series, false) ), Imagesmodel, mQFactory.getQueryKeysforImages("","","",true));
228 void vvQPacsConnection::selectImage(const QModelIndex &index)
230 std::string _image = Imagesmodel->data(index.sibling(index.row(),1)).toString().toStdString();
231 mQFactory.setQueryforImage(m_patient,m_study, m_series, _image);
236 std::vector<gdcm::DataSet> vvQPacsConnection::findQuery(vvQuery i_query)
238 std::vector<gdcm::DataSet> theDataSet;
239 gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
240 gdcm::CompositeNetworkFunctions::ConstructQuery(i_query.theRoot, i_query.theLevel,i_query.keys), theDataSet,
241 getDicomClientAETitle().c_str(), m_nickname.c_str());
245 void vvQPacsConnection::manageStudiesFilter(bool i_enable)
247 ui.text_PHYS->setEnabled(i_enable);
248 ui.text_SDESC->setEnabled(i_enable);
249 ui.dateTab->setEnabled(i_enable);
253 void vvQPacsConnection::manageSeriesFilter(bool i_enable)
255 ui.modalityTab->setEnabled(i_enable);
259 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getStudyKeys(const std::string i_val)
261 std::vector< std::pair<gdcm::Tag, std::string> > keys;
263 gdcm::Tag tagsdc(0x0008,0x1030);
264 keys.push_back(std::make_pair(tagsdc, ""));
266 gdcm::Tag tagdb(0x0008,0x0020);
267 keys.push_back(std::make_pair(tagdb, ""));
269 gdcm::Tag tagsdh(0x0008,0x0030);
270 keys.push_back(std::make_pair(tagsdh, ""));
271 // Study Instance UID
272 gdcm::Tag tagsid(0x0020,0x000d);
273 keys.push_back(std::make_pair(tagsid, i_val));
278 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
280 std::vector< std::pair<gdcm::Tag, std::string> > keys;
282 gdcm::Tag tag(0x0010,0x0010);
283 keys.push_back(std::make_pair(tag, ""));
286 gdcm::Tag tagpid(0x0010,0x0020);
287 keys.push_back(std::make_pair(tagpid, ""));
290 gdcm::Tag tagmod(0x0008,0x0061);
291 keys.push_back(std::make_pair(tagmod, ""));
294 gdcm::Tag tagdb(0x0010,0x0030);
295 keys.push_back(std::make_pair(tagdb, ""));
298 gdcm::Tag tagsd(0x0020,0x000D);
299 keys.push_back(std::make_pair(tagsd, ""));
302 //gdcm::Tag tagst(8,30);
303 //keys.push_back(std::make_pair(tagst, ""));
305 //// Study Description
306 //gdcm::Tag tagsdc(8,1030);
307 //keys.push_back(std::make_pair(tagsdc, ""));
310 //gdcm::Tag tagacc(8,50);
311 //keys.push_back(std::make_pair(tagacc, ""));
316 void vvQPacsConnection::on_check_ModAll_clicked(bool state)
318 ui.check_MR->setEnabled(!state);
319 ui.check_CR->setEnabled(!state);
320 ui.check_OT->setEnabled(!state);
321 ui.check_RF->setEnabled(!state);
322 ui.check_SC->setEnabled(!state);
323 ui.check_CT->setEnabled(!state);
324 ui.check_US->setEnabled(!state);
325 ui.check_NM->setEnabled(!state);
326 ui.check_DR->setEnabled(!state);
327 ui.check_US->setEnabled(!state);
328 ui.check_NM->setEnabled(!state);
329 ui.check_DR->setEnabled(!state);
330 ui.check_SR->setEnabled(!state);
331 ui.check_XA->setEnabled(!state);
332 ui.check_MG->setEnabled(!state);
335 ui.check_MR->setChecked(state);
336 ui.check_CR->setChecked(state);
337 ui.check_OT->setChecked(state);
338 ui.check_RF->setChecked(state);
339 ui.check_SC->setChecked(state);
340 ui.check_CT->setChecked(state);
341 ui.check_US->setChecked(state);
342 ui.check_NM->setChecked(state);
343 ui.check_DR->setChecked(state);
344 ui.check_US->setChecked(state);
345 ui.check_NM->setChecked(state);
346 ui.check_DR->setChecked(state);
347 ui.check_SR->setChecked(state);
348 ui.check_XA->setChecked(state);
349 ui.check_MG->setChecked(state);
354 void vvQPacsConnection::chooseServer(int index)
356 std::map < std::string, std:: string> values = getDicomServer(ui.networkCombo->currentText());
357 m_port = values["PORT"];
358 m_aetitle = values["AETITLE"];
359 m_adress= values["ADRESS"];
360 m_nickname = values["nickname"];
361 ui.AdressEdit->setText(QString(m_adress.c_str()));
362 ui.AETitleEdit->setText(QString(m_aetitle.c_str()));
363 ui.NameEdit->setText(QString(m_nickname.c_str()));
364 ui.PortEdit->setText(QString(m_port.c_str()));
367 void vvQPacsConnection::on_importButton_clicked()
369 setCursor(QCursor(Qt::WaitCursor));
370 QString path = QDir::homePath() +QString::fromStdString("/.move");
372 if (dirpath.exists())
374 QFileInfoList list = dirpath.entryInfoList( QDir::Files);
375 QFileInfoList::iterator it_file = dirpath.entryInfoList( QDir::Files).begin();
376 for(int i = 0; i < list.length() ; i++)
378 QFile::remove(list.at(i).filePath());
385 bool didItWork = gdcm::CompositeNetworkFunctions::CMove(m_adress.c_str(),atoi(m_port.c_str()),
386 gdcm::CompositeNetworkFunctions::ConstructQuery(mQFactory.getMoveQuery().theRoot, mQFactory.getMoveQuery().theLevel ,mQFactory.getMoveQuery().keys,true),
387 getDicomClientPort(), getDicomClientAETitle().c_str(), m_aetitle.c_str(), path.toStdString().c_str() );
388 gdcm::Directory theDir;
389 theDir.Load(path.toStdString().c_str());
390 //m_files = theDir.GetFilenames();
392 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
393 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
394 nameGenerator->SetUseSeriesDetails(true);
396 //ds gérer recursive moi-meme pour progress ...
397 nameGenerator->SetInputDirectory(path.toStdString());
400 typedef std::vector<std::string> SeriesIdContainer;
401 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
402 std::map<std::string, std::vector<std::string>* > mListOfSeriesFilenames;
405 for (unsigned int i=0; i<seriesUID.size(); i++) {
408 std::vector<std::string> * filenames = new std::vector<std::string>;
409 m_files = nameGenerator->GetFileNames(seriesUID[i]);
410 /* for (unsigned int j=0; j<temp.size(); j++) {
411 m_files->push_back(temp[j]);
417 setCursor(QCursor(Qt::ArrowCursor));
422 std::vector <std::string> vvQPacsConnection::getFileNames()
424 std::vector <std::string> filenames;
425 gdcm::Directory::FilenamesType::iterator it = m_files.begin();
426 for (;it != m_files.end(); it++)
427 filenames.push_back(it->c_str());
430 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::fillMoveKeys()
432 std::vector< std::pair<gdcm::Tag, std::string> > keys;
436 //keys.push_back(getPatientKeys("",""));