1 #include "vvQPacsConnection.h"
2 #include "gdcmCompositeNetworkFunctions.h"
3 #include <QtGui/qlistview.h>
8 #include "vvPacsSettingsDialog.h"
12 vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
16 setWindowTitle(QString::fromUtf8("PACS CONNECTIONHHHH"));
18 ui.tabFilter->setTabText(0,QString(tr("Modality")));
19 ui.tabFilter->setTabText(1,QString(tr("Date")));
21 ui. tabNetwork->setTabText(0,QString(tr("Network")));
22 ui. tabNetwork->setTabText(1,QString(tr("Configuration")));
23 //ui.setChecked(true);
24 //ui.on_check_ModAll_clicked(true);
26 icon.addFile("basket_download.png",QSize(),QIcon::Normal,QIcon::Off);
27 ui.importButton->setIcon(icon);
28 icon.addFile("file_upload.png",QSize(),QIcon::Normal,QIcon::Off);
29 // exportButton->setIcon(icon);
30 icon.addFile("email_forward.png",QSize(),QIcon::Normal,QIcon::Off);
31 icon.addFile("edit.png",QSize(),QIcon::Normal,QIcon::Off);
32 ui.optionsButton->setIcon(icon);
33 icon.addFile("bullet_info.png",QSize(),QIcon::Normal,QIcon::Off);
34 ui.helpButton->setIcon(icon);
35 connect(ui.optionsButton,SIGNAL(clicked()),this,SLOT(setNewPacs()));
36 ui.networkCombo->addItems(getDicomServers());
37 connect(ui.networkCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(connectServer(int)));
38 connect(ui.scanButton,SIGNAL(clicked()),this,SLOT(on_scanButton_clicked()));
42 void vvQPacsConnection::refreshNetworks()
44 ui.networkCombo->clear();
45 ui.networkCombo->addItems(getDicomServers());
46 //ui.networkCombo->show();
49 void vvQPacsConnection::on_clearButton_clicked()
51 Patientmodel->removeRows(0, Patientmodel->rowCount(),QModelIndex());
52 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
53 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
54 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
57 void vvQPacsConnection::on_scanButton_clicked()
59 //on_clearButton_clicked();
60 manageStudiesFilter(true);
61 // #if defined (USE_GDCM2)
62 bool didItWork = gdcm::CompositeNetworkFunctions::CEcho(m_adress.c_str(), atoi(m_port.c_str()), "CREATIS", m_nickname.c_str() );
65 std::vector< std::pair<gdcm::Tag, std::string> > keys = getKeys();
67 //std::pair<gdcm::Tag, std::string> pa;
70 ////keys.push_back(std::make_pair(tag, ""));
71 gdcm::EQueryLevel theLevel = gdcm::eStudy;
72 gdcm::ERootType theRoot = gdcm::eStudyRootType;//ePatientRootType;
73 //gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery = gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
76 std::vector<gdcm::DataSet> theDataSet;
78 theLevel = gdcm::ePatient;
79 theRoot = gdcm::ePatientRootType;//ePatientRootType;
80 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery = gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,getPatientKeys(""));
84 // gdcm::CompositeNetworkFunctions::CFind(m_adress, m_port, theQuery, theDataSet,
85 // "CREATIS", m_nickname);
87 // keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0010), ""));
89 gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet,
90 "CREATIS", m_nickname.c_str());
91 std::vector<gdcm::DataSet>::iterator it_ds = theDataSet.begin();
93 for(; it_ds != theDataSet.end(); it_ds++)
96 QList<QStandardItem *> items;
97 const gdcm::DataSet ds = (*it_ds);
98 std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
100 for(; it_key != keys.end(); it_key++, ind++)
102 gdcm::DataElement de = ds.GetDataElement((*it_key).first);
103 QStandardItem *item = new QStandardItem;
104 const gdcm::ByteValue *bv = (de).GetByteValue();
107 std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
108 item->setText(tr(buffer.c_str()));
112 item->setText(tr(""));
116 item->setCheckable(true);
118 items.push_back(item);
120 Patientmodel->appendRow(items);
122 // gdcm::Tag tagtest(0x0020,0x1208);
124 // keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0010), ""));
125 //// keys.push_back(std::make_pair(tagtest, ""));
126 // theLevel = gdcm::ePatient;
127 // theRoot = gdcm::ePatientRootType;//ePatientRootType;
128 // theQuery = gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
131 //theDataSet.clear();
132 // gdcm::CompositeNetworkFunctions::CFind(m_adress, m_port, theQuery, theDataSet,
133 // "CREATIS",m_nickname);
138 void vvQPacsConnection::on_optionsButton_clicked()
141 vvPacsSettingsDialog *dg = new vvPacsSettingsDialog(this);
145 QVariant elt= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
147 gdcm::EQueryLevel theLevel = gdcm::ePatient;
148 gdcm::ERootType theRoot = gdcm::ePatientRootType;//ePatientRootType;
149 std::vector<gdcm::DataSet> theDataSet;
150 std::vector< std::pair<gdcm::Tag, std::string> > keys;
153 gdcm::Tag tagsdc(0x0010,0x0020);
154 keys.push_back(std::make_pair(tagsdc, elt.toString().toStdString()));
155 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery = gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
156 gdcm::CompositeNetworkFunctions::CFind(m_adress, m_port, theQuery, theDataSet, "CREATIS", m_nickname);
158 bool didItWork = gdcm::CompositeNetworkFunctions::CMove( m_adress, m_port, theQuery, 0,
159 "CREATIS", m_nickname,m_destination );*/
162 void vvQPacsConnection::convertDataSet(std::vector<gdcm::DataSet> i_ds, QStandardItemModel *i_model, std::vector< std::pair<gdcm::Tag, std::string> > keys)
164 gdcm::Tag tagdb(0x0008,0x0020);
165 std::vector<gdcm::DataSet>::iterator it_ds = i_ds.begin();
166 for(; it_ds != i_ds.end(); it_ds++)
168 QList<QStandardItem *> items;
169 const gdcm::DataSet ds = (*it_ds);
170 std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
172 for(; it_key != keys.end(); it_key++, ind++)
174 gdcm::DataElement de = ds.GetDataElement((*it_key).first);
175 QStandardItem *item = new QStandardItem;
176 const gdcm::ByteValue *bv = (de).GetByteValue();
179 std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
180 /*if((*it_key).first == tagdb)
183 date.fromString(tr(buffer.c_str()),"yyyy'MM'd");
184 item->setText(date.toString());
188 item->setText(tr(buffer.c_str()));
193 item->setText(tr(""));
197 item->setCheckable(true);
199 items.push_back(item);
201 i_model->appendRow(items);
207 void vvQPacsConnection::createTreeView()
210 Patientmodel = new QStandardItemModel(0,2,this);
211 QStringList Patientlist;
212 Patientlist.push_back(tr("PATIENT NAME"));
213 Patientlist.push_back(tr("PATIENT ID"));
214 Patientmodel->setHorizontalHeaderLabels(Patientlist);
215 ui.patientTreeView->setModel(Patientmodel);
216 ui.patientTreeView->setEnabled(true);
217 connect(ui.patientTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStudies(QModelIndex)));
220 Studymodel = new QStandardItemModel(0,3,this);
221 QStringList Studylist;
222 Studylist.push_back(tr("DESCRIPTION"));
223 Studylist.push_back(tr("DATE"));
224 Studylist.push_back(tr("HOUR"));
225 Studymodel->setHorizontalHeaderLabels(Studylist);
226 ui.studyTreeView->setModel(Studymodel);
227 connect(ui.studyTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectSeries(QModelIndex)));
231 Seriesmodel = new QStandardItemModel(0,2,this);
232 QStringList Serieslist;
233 Serieslist.push_back(tr("MODALITY"));
234 Serieslist.push_back(tr("DESCRIPTION"));
235 Serieslist.push_back(tr("no. accept."));
236 Seriesmodel->setHorizontalHeaderLabels(Serieslist);
237 ui.seriesTreeView->setModel(Seriesmodel);
238 connect(ui.seriesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImages(QModelIndex)));
241 Imagesmodel = new QStandardItemModel(0,1,this);
242 QStringList Imageslist;
243 Imageslist.push_back(tr("instance number"));
244 Imagesmodel->setHorizontalHeaderLabels(Imageslist);
245 ui.imagesTreeView->setModel(Imagesmodel);
247 //model->setHeaderData(0, Qt::Horizontal,tr("test"),Qt::DisplayRole);
248 /*QFileSystemModel *filemodel = new QFileSystemModel;
249 filemodel->insertColumn(1);
250 filemodel->setHeaderData(1, Qt::Horizontal,"test",0);*/
254 void vvQPacsConnection::selectStudies(const QModelIndex &index)
256 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
257 QVariant elt= Patientmodel->data(index.sibling(index.row(),1));
258 m_patient=elt.toString().toStdString();
259 manageSeriesFilter(true);
260 gdcm::EQueryLevel theLevel = gdcm::eStudy;
261 gdcm::ERootType theRoot = gdcm::ePatientRootType;//ePatientRootType;
262 std::vector<gdcm::DataSet> theDataSet;
263 std::vector< std::pair<gdcm::Tag, std::string> > keys;
266 gdcm::Tag tagsd(0x0010,0x0020);
267 keys.push_back(std::make_pair(tagsd, m_patient));
269 gdcm::Tag tagsdc(0x0008,0x1030);
270 keys.push_back(std::make_pair(tagsdc, ""));
272 gdcm::Tag tagdb(0x0008,0x0020);
273 keys.push_back(std::make_pair(tagdb, ""));
275 gdcm::Tag tagsdh(0x0008,0x0030);
276 keys.push_back(std::make_pair(tagsdh, ""));
277 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery = gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
278 gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet, "CREATIS", m_nickname.c_str());
279 convertDataSet(theDataSet, Studymodel, getStudyKeys(""));
283 void vvQPacsConnection::selectSeries(const QModelIndex &index)
285 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
286 QVariant elt= Studymodel->data(index.sibling(index.row(),3));
287 QVariant elt2= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
289 //manageImagesFilter(true);
290 gdcm::EQueryLevel theLevel = gdcm::eSeries;
291 gdcm::ERootType theRoot = gdcm::ePatientRootType;//ePatientRootType;
292 std::vector<gdcm::DataSet> theDataSet;
293 std::vector< std::pair<gdcm::Tag, std::string> > keys;
296 keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0020), m_patient));
299 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000d), elt.toString().toStdString()));
303 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
305 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
306 // Acceptance NUmber????
307 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), elt.toString().toStdString()));
309 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery = gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
312 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
314 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
315 // Acceptance NUmber????
316 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), elt.toString().toStdString()));
320 gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet, "CREATIS", m_nickname.c_str());
321 convertDataSet(theDataSet, Seriesmodel, keys);
324 void vvQPacsConnection::selectImages(const QModelIndex &index)
326 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
327 QVariant elt= Seriesmodel->data(index.sibling(index.row(),2));
328 QVariant elt2= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
330 //manageImagesFilter(true);
331 gdcm::EQueryLevel theLevel = gdcm::eImage;
332 gdcm::ERootType theRoot = gdcm::ePatientRootType;//ePatientRootType;
333 std::vector<gdcm::DataSet> theDataSet;
334 std::vector< std::pair<gdcm::Tag, std::string> > keys;
336 gdcm::Tag tagsd(0x0010,0x0020);
337 keys.push_back(std::make_pair(tagsd, m_patient));
339 gdcm::Tag tagss(0x0020,0x000e);
340 keys.push_back(std::make_pair(tagss, elt.toString().toStdString()));
341 //= getStudyKeys(elt.toString().toStdString());
344 gdcm::Tag tagsdc(0x0020,0x0013);
345 keys.push_back(std::make_pair(tagsdc, ""));
348 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery = gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
352 keys.push_back(std::make_pair(tagsdc, ""));
355 gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet, "CREATIS", m_nickname.c_str());
356 convertDataSet(theDataSet, Seriesmodel, keys);
360 void vvQPacsConnection::manageStudiesFilter(bool i_enable)
362 ui.text_PHYS->setEnabled(i_enable);
363 ui.text_SDESC->setEnabled(i_enable);
364 ui.dateTab->setEnabled(i_enable);
368 void vvQPacsConnection::manageSeriesFilter(bool i_enable)
370 ui.modalityTab->setEnabled(i_enable);
373 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getPatientKeys(const std::string i_val)
375 std::vector< std::pair<gdcm::Tag, std::string> > keys;
377 gdcm::Tag tag(0x0010,0x0010);
378 keys.push_back(std::make_pair(tag, ""));
381 gdcm::Tag tagpid(0x0010,0x0020);
382 keys.push_back(std::make_pair(tagpid, i_val));
386 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getStudyKeys(const std::string i_val)
388 std::vector< std::pair<gdcm::Tag, std::string> > keys;
390 gdcm::Tag tagsdc(0x0008,0x1030);
391 keys.push_back(std::make_pair(tagsdc, ""));
393 gdcm::Tag tagdb(0x0008,0x0020);
394 keys.push_back(std::make_pair(tagdb, ""));
396 gdcm::Tag tagsdh(0x0008,0x0030);
397 keys.push_back(std::make_pair(tagsdh, ""));
398 // Study Instance UID
399 gdcm::Tag tagsid(0x0020,0x000d);
400 keys.push_back(std::make_pair(tagsid, i_val));
406 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getSeriesKeys(const std::string i_val)
408 std::vector< std::pair<gdcm::Tag, std::string> > keys;
410 gdcm::Tag tagsm(0x0008,0x0060);
411 keys.push_back(std::make_pair(tagsm, ""));
413 gdcm::Tag tagdb(0x0008,0x103e);
414 keys.push_back(std::make_pair(tagdb, ""));
416 gdcm::Tag tagsdh(0x0020,0x000e);
417 keys.push_back(std::make_pair(tagsdh, ""));
418 // Study Instance UID
419 gdcm::Tag tagsid(0x0020,0x1209);
420 keys.push_back(std::make_pair(tagsid, i_val));
424 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
426 std::vector< std::pair<gdcm::Tag, std::string> > keys;
428 gdcm::Tag tag(0x0010,0x0010);
429 keys.push_back(std::make_pair(tag, ""));
432 gdcm::Tag tagpid(0x0010,0x0020);
433 keys.push_back(std::make_pair(tagpid, ""));
436 gdcm::Tag tagmod(0x0008,0x0061);
437 keys.push_back(std::make_pair(tagmod, ""));
440 gdcm::Tag tagdb(0x0010,0x0030);
441 keys.push_back(std::make_pair(tagdb, ""));
444 gdcm::Tag tagsd(0x0020,0x000D);
445 keys.push_back(std::make_pair(tagsd, ""));
448 //gdcm::Tag tagst(8,30);
449 //keys.push_back(std::make_pair(tagst, ""));
451 //// Study Description
452 //gdcm::Tag tagsdc(8,1030);
453 //keys.push_back(std::make_pair(tagsdc, ""));
456 //gdcm::Tag tagacc(8,50);
457 //keys.push_back(std::make_pair(tagacc, ""));
462 void vvQPacsConnection::on_check_ModAll_clicked(bool state)
464 ui.check_MR->setEnabled(!state);
465 ui.check_CR->setEnabled(!state);
466 ui.check_OT->setEnabled(!state);
467 ui.check_RF->setEnabled(!state);
468 ui.check_SC->setEnabled(!state);
469 ui.check_CT->setEnabled(!state);
470 ui.check_US->setEnabled(!state);
471 ui.check_NM->setEnabled(!state);
472 ui.check_DR->setEnabled(!state);
473 ui.check_US->setEnabled(!state);
474 ui.check_NM->setEnabled(!state);
475 ui.check_DR->setEnabled(!state);
476 ui.check_SR->setEnabled(!state);
477 ui.check_XA->setEnabled(!state);
478 ui.check_MG->setEnabled(!state);
481 ui.check_MR->setChecked(state);
482 ui.check_CR->setChecked(state);
483 ui.check_OT->setChecked(state);
484 ui.check_RF->setChecked(state);
485 ui.check_SC->setChecked(state);
486 ui.check_CT->setChecked(state);
487 ui.check_US->setChecked(state);
488 ui.check_NM->setChecked(state);
489 ui.check_DR->setChecked(state);
490 ui.check_US->setChecked(state);
491 ui.check_NM->setChecked(state);
492 ui.check_DR->setChecked(state);
493 ui.check_SR->setChecked(state);
494 ui.check_XA->setChecked(state);
495 ui.check_MG->setChecked(state);
500 void vvQPacsConnection::connectServer(int index)
502 std::map < std::string, std:: string> values = getDicomServer(ui.networkCombo->currentText());
503 m_port = values["PORT"];
504 m_aetitle = values["AETITLE"];
505 m_adress= values["ADRESS"];
506 m_nickname = values["nickname"];
507 ui.AdressEdit->setText(QString(m_adress.c_str()));
508 ui.AETitleEdit->setText(QString(m_aetitle.c_str()));
509 ui.NameEdit->setText(QString(m_nickname.c_str()));
510 ui.PortEdit->setText(QString(m_port.c_str()));
513 void vvQPacsConnection::setNewPacs()