1 #include "vvQPacsConnection.h"
2 #include "gdcmCompositeNetworkFunctions.h"
3 #include <QtGui/qlistview.h>
8 #include "vvPacsSettingsDialog.h"
13 vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
17 setWindowTitle(QString::fromUtf8("PACS CONNECTIONHHHH"));
19 ui.tabFilter->setTabText(0,QString(tr("Modality")));
20 ui.tabFilter->setTabText(1,QString(tr("Date")));
22 ui. tabNetwork->setTabText(0,QString(tr("Network")));
23 ui. tabNetwork->setTabText(1,QString(tr("Configuration")));
24 ui.check_ModAll->setEnabled(true);
25 ui.networkCombo->addItem("");
26 ui.networkCombo->addItems(getDicomServers());
29 connect(ui.networkCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(chooseServer(int)));
30 connect(ui.removeNetworkButton,SIGNAL(clicked()),this,SLOT(removeServer()));
31 connect(ui.NetworkButton,SIGNAL(clicked()),this,SLOT(modifyServer()));
36 // remote a Dicom Server in VV settings
37 void vvQPacsConnection::removeServer()
39 removeDicomServer(m_nickname);
40 ui.networkCombo->removeItem(ui.networkCombo->findText(QString(m_nickname.c_str())));
45 // modify a Dicom Server in VV settings
46 void vvQPacsConnection::modifyServer()
48 AddDicomServer(ui.NameEdit->text().toStdString(),ui.AETitleEdit->text().toStdString(),ui.AdressEdit->text().toStdString(),ui.PortEdit->text().toStdString());
52 // refresh the list of Dicom Servers available from VV settings
53 void vvQPacsConnection::refreshNetworks()
55 ui.networkCombo->clear();
56 ui.networkCombo->addItem(QString());
57 ui.networkCombo->addItems(getDicomServers());
58 ui.NameEdit->setText(QString());
59 ui.AETitleEdit->setText(QString());
60 ui.AdressEdit->setText(QString());
61 ui.PortEdit->setText(QString());
62 ui.tabNetwork->setCurrentIndex(0);
65 void vvQPacsConnection::on_clearButton_clicked()
67 Patientmodel->removeRows(0, Patientmodel->rowCount(),QModelIndex());
68 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
69 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
70 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
73 void vvQPacsConnection::on_scanButton_clicked()
76 manageStudiesFilter(true);
78 // test first if echo works
79 bool didItWork = gdcm::CompositeNetworkFunctions::CEcho(m_adress.c_str(), atoi(m_port.c_str()), getDicomClientAETitle().c_str(), m_nickname.c_str() );
82 m_level =gdcm::ePatient;
83 std::vector<gdcm::DataSet> theDataSet;
84 f_query = getQueryPatient(ui.patientName->toPlainText().toStdString(), ui.patientID->toPlainText().toStdString());
86 bool cfindWork = gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
87 gdcm::CompositeNetworkFunctions::ConstructQuery(f_query.theRoot, f_query.theLevel ,f_query.keys),
88 theDataSet, getDicomClientAETitle().c_str() , m_nickname.c_str());
91 convertDataSet(theDataSet,Patientmodel,getPatientKeys("",""));
97 /// show Options DialogBox to set a new Dicom Server
98 void vvQPacsConnection::on_optionsButton_clicked()
100 vvPacsSettingsDialog *dg = new vvPacsSettingsDialog(this);
104 void vvQPacsConnection::convertDataSet(std::vector<gdcm::DataSet> i_ds, QStandardItemModel *i_model, std::vector< std::pair<gdcm::Tag, std::string> > keys)
107 std::vector<gdcm::DataSet>::iterator it_ds = i_ds.begin();
108 for(; it_ds != i_ds.end(); it_ds++)
110 QList<QStandardItem *> items;
111 const gdcm::DataSet ds = (*it_ds);
112 std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
114 for(; it_key != keys.end(); it_key++, ind++)
116 gdcm::DataElement de = ds.GetDataElement((*it_key).first);
117 QStandardItem *item = new QStandardItem;
118 const gdcm::ByteValue *bv = (de).GetByteValue();
121 std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
122 item->setText(tr(buffer.c_str()));
126 item->setText(tr(""));
130 item->setCheckable(true);
132 items.push_back(item);
134 i_model->appendRow(items);
138 // TreeViews creation
139 void vvQPacsConnection::createTreeView()
142 Patientmodel = new QStandardItemModel(0,2,this);
143 QStringList Patientlist;
144 Patientlist.push_back(tr("PATIENT NAME"));
145 Patientlist.push_back(tr("PATIENT ID"));
146 Patientmodel->setHorizontalHeaderLabels(Patientlist);
147 ui.patientTreeView->setModel(Patientmodel);
148 ui.patientTreeView->setEnabled(true);
149 connect(ui.patientTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStudies(QModelIndex)));
152 Studymodel = new QStandardItemModel(0,3,this);
153 QStringList Studylist;
154 Studylist.push_back(tr("DESCRIPTION"));
155 Studylist.push_back(tr("DATE"));
156 Studylist.push_back(tr("HOUR"));
157 Studylist.push_back(tr("STUDY ID"));
158 Studymodel->setHorizontalHeaderLabels(Studylist);
159 ui.studyTreeView->setModel(Studymodel);
160 connect(ui.studyTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectSeries(QModelIndex)));
164 Seriesmodel = new QStandardItemModel(0,2,this);
165 QStringList Serieslist;
166 Serieslist.push_back(tr("MODALITY"));
167 Serieslist.push_back(tr("DESCRIPTION"));
168 Serieslist.push_back(tr("no. accept."));
169 Seriesmodel->setHorizontalHeaderLabels(Serieslist);
170 ui.seriesTreeView->setModel(Seriesmodel);
171 connect(ui.seriesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImages(QModelIndex)));
174 Imagesmodel = new QStandardItemModel(0,1,this);
175 QStringList Imageslist;
176 Imageslist.push_back(tr("instance number"));
177 Imageslist.push_back(tr("sopuid"));
178 Imagesmodel->setHorizontalHeaderLabels(Imageslist);
179 ui.imagesTreeView->setModel(Imagesmodel);
182 // clean the different model Trees
183 void vvQPacsConnection::cleanTree()
185 Patientmodel->removeRows(0,Patientmodel->rowCount());
186 Studymodel->removeRows(0,Patientmodel->rowCount());
187 Seriesmodel->removeRows(0,Patientmodel->rowCount());
188 Imagesmodel->removeRows(0,Patientmodel->rowCount());
192 void vvQPacsConnection::selectStudies(const QModelIndex &index)
196 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
197 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
198 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
199 QVariant elt= Patientmodel->data(index.sibling(index.row(),1));
200 m_patient=elt.toString().toStdString();
201 manageSeriesFilter(true);
203 std::vector<gdcm::DataSet> theDataSet;
204 m_query = getQueryPatient("",m_patient);
205 f_query = getQueryforStudy(m_patient, false);
208 if ( gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
209 gdcm::CompositeNetworkFunctions::ConstructQuery(f_query.theRoot, f_query.theLevel ,f_query.keys)
210 , theDataSet, getDicomClientAETitle().c_str(), m_nickname.c_str()) )
212 convertDataSet(theDataSet, Studymodel, getQueryKeysforStudy("",true));
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());
226 std::vector<gdcm::DataSet> theDataSet;
228 m_query = getQueryforSeries(m_patient,m_study, false);
229 f_query =getQueryforSeries(m_patient,m_study, false);
230 if ( gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
231 gdcm::CompositeNetworkFunctions::ConstructQuery(f_query.theRoot, f_query.theLevel ,f_query.keys), theDataSet,
232 getDicomClientAETitle().c_str(), m_nickname.c_str()))
235 convertDataSet(theDataSet, Seriesmodel, getSeriesKeys("","",true));
239 void vvQPacsConnection::selectImages(const QModelIndex &index)
241 m_series = Seriesmodel->data(index.sibling(index.row(),2)).toString().toStdString();
242 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
245 //manageImagesFilter(true);
247 std::vector<gdcm::DataSet> theDataSet;
248 std::vector< std::pair<gdcm::Tag, std::string> > keys;
249 f_query =getQueryforImages(m_patient,m_study, m_series, false);
250 m_query =getQueryforImages(m_patient,m_study, m_series, false);
251 if( gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()),
252 gdcm::CompositeNetworkFunctions::ConstructQuery(f_query.theRoot, f_query.theLevel ,f_query.keys), theDataSet,
253 getDicomClientAETitle().c_str(), m_nickname.c_str()))
255 convertDataSet(theDataSet, Imagesmodel, getQueryKeysforImages("","","",true));
260 void vvQPacsConnection::manageStudiesFilter(bool i_enable)
262 ui.text_PHYS->setEnabled(i_enable);
263 ui.text_SDESC->setEnabled(i_enable);
264 ui.dateTab->setEnabled(i_enable);
268 void vvQPacsConnection::manageSeriesFilter(bool i_enable)
270 ui.modalityTab->setEnabled(i_enable);
273 vvQuery vvQPacsConnection::getQueryPatient(const std::string i_patname, const std::string i_patid)
276 query.theRoot = gdcm::ePatientRootType;
277 query.theLevel = gdcm::ePatient;
278 query.keys = getPatientKeys(i_patname, i_patid);
283 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getPatientKeys(const std::string i_patname, const std::string i_patid)
285 std::vector< std::pair<gdcm::Tag, std::string> > keys;
287 gdcm::Tag tag(0x0010,0x0010);
288 keys.push_back(std::make_pair(tag, i_patname));
291 gdcm::Tag tagpid(0x0010,0x0020);
292 keys.push_back(std::make_pair(tagpid, i_patid));
296 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getStudyKeys(const std::string i_val)
298 std::vector< std::pair<gdcm::Tag, std::string> > keys;
300 gdcm::Tag tagsdc(0x0008,0x1030);
301 keys.push_back(std::make_pair(tagsdc, ""));
303 gdcm::Tag tagdb(0x0008,0x0020);
304 keys.push_back(std::make_pair(tagdb, ""));
306 gdcm::Tag tagsdh(0x0008,0x0030);
307 keys.push_back(std::make_pair(tagsdh, ""));
308 // Study Instance UID
309 gdcm::Tag tagsid(0x0020,0x000d);
310 keys.push_back(std::make_pair(tagsid, i_val));
315 vvQuery vvQPacsConnection::getQueryforSeries(const std::string patient_id, const std::string series_id, bool bdisplay)
318 query.theRoot = gdcm::ePatientRootType;
319 query.theLevel = gdcm::eSeries;
320 query.keys = getSeriesKeys(patient_id, series_id, bdisplay);
323 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getSeriesKeys(const std::string patient_id, const std::string study_id, bool bdisplay)
325 std::vector< std::pair<gdcm::Tag, std::string> > keys;
327 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), ""));
330 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x103e),""));
331 // Series Instance UID
332 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), ""));
338 // Study Instance UID
339 gdcm::Tag tagsid(0x0020,0x1209);
340 keys.push_back(std::make_pair(tagsid, study_id));
345 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
347 std::vector< std::pair<gdcm::Tag, std::string> > keys;
349 gdcm::Tag tag(0x0010,0x0010);
350 keys.push_back(std::make_pair(tag, ""));
353 gdcm::Tag tagpid(0x0010,0x0020);
354 keys.push_back(std::make_pair(tagpid, ""));
357 gdcm::Tag tagmod(0x0008,0x0061);
358 keys.push_back(std::make_pair(tagmod, ""));
361 gdcm::Tag tagdb(0x0010,0x0030);
362 keys.push_back(std::make_pair(tagdb, ""));
365 gdcm::Tag tagsd(0x0020,0x000D);
366 keys.push_back(std::make_pair(tagsd, ""));
369 //gdcm::Tag tagst(8,30);
370 //keys.push_back(std::make_pair(tagst, ""));
372 //// Study Description
373 //gdcm::Tag tagsdc(8,1030);
374 //keys.push_back(std::make_pair(tagsdc, ""));
377 //gdcm::Tag tagacc(8,50);
378 //keys.push_back(std::make_pair(tagacc, ""));
383 void vvQPacsConnection::on_check_ModAll_clicked(bool state)
385 ui.check_MR->setEnabled(!state);
386 ui.check_CR->setEnabled(!state);
387 ui.check_OT->setEnabled(!state);
388 ui.check_RF->setEnabled(!state);
389 ui.check_SC->setEnabled(!state);
390 ui.check_CT->setEnabled(!state);
391 ui.check_US->setEnabled(!state);
392 ui.check_NM->setEnabled(!state);
393 ui.check_DR->setEnabled(!state);
394 ui.check_US->setEnabled(!state);
395 ui.check_NM->setEnabled(!state);
396 ui.check_DR->setEnabled(!state);
397 ui.check_SR->setEnabled(!state);
398 ui.check_XA->setEnabled(!state);
399 ui.check_MG->setEnabled(!state);
402 ui.check_MR->setChecked(state);
403 ui.check_CR->setChecked(state);
404 ui.check_OT->setChecked(state);
405 ui.check_RF->setChecked(state);
406 ui.check_SC->setChecked(state);
407 ui.check_CT->setChecked(state);
408 ui.check_US->setChecked(state);
409 ui.check_NM->setChecked(state);
410 ui.check_DR->setChecked(state);
411 ui.check_US->setChecked(state);
412 ui.check_NM->setChecked(state);
413 ui.check_DR->setChecked(state);
414 ui.check_SR->setChecked(state);
415 ui.check_XA->setChecked(state);
416 ui.check_MG->setChecked(state);
421 void vvQPacsConnection::chooseServer(int index)
423 std::map < std::string, std:: string> values = getDicomServer(ui.networkCombo->currentText());
424 m_port = values["PORT"];
425 m_aetitle = values["AETITLE"];
426 m_adress= values["ADRESS"];
427 m_nickname = values["nickname"];
428 ui.AdressEdit->setText(QString(m_adress.c_str()));
429 ui.AETitleEdit->setText(QString(m_aetitle.c_str()));
430 ui.NameEdit->setText(QString(m_nickname.c_str()));
431 ui.PortEdit->setText(QString(m_port.c_str()));
434 void vvQPacsConnection::on_importButton_clicked()
437 bool didItWork = gdcm::CompositeNetworkFunctions::CMove(m_adress.c_str(),atoi(m_port.c_str()),
438 gdcm::CompositeNetworkFunctions::ConstructQuery(m_query.theRoot, m_query.theLevel ,m_query.keys,true), getDicomClientPort(),
439 getDicomClientAETitle().c_str(), m_aetitle.c_str(),"D:\\move" );
440 gdcm::Directory theDir;
441 theDir.Load("D:\\move");
442 m_files = theDir.GetFilenames();
446 std::vector <std::string> vvQPacsConnection::getFileNames()
448 std::vector <std::string> filenames;
449 gdcm::Directory::FilenamesType::iterator it = m_files.begin();
450 for (;it != m_files.end(); it++)
451 filenames.push_back(it->c_str());
454 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::fillMoveKeys()
456 std::vector< std::pair<gdcm::Tag, std::string> > keys;
460 //keys.push_back(getPatientKeys("",""));
467 vvQuery vvQPacsConnection::getQueryforStudy(const std::string patient_id, bool bdisplay)
470 query.keys = getQueryKeysforStudy( patient_id, bdisplay);
471 query.theRoot = gdcm::ePatientRootType;
472 query.theLevel = gdcm::eStudy;
476 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getQueryKeysforStudy(const std::string patient_id, bool bdisplay)
478 std::vector< std::pair<gdcm::Tag, std::string> > keys;
482 gdcm::Tag tagsdc(0x0008,0x1030);
483 keys.push_back(std::make_pair(tagsdc, ""));
485 gdcm::Tag tagdb(0x0008,0x0020);
486 keys.push_back(std::make_pair(tagdb, ""));
488 gdcm::Tag tagsdh(0x0008,0x0030);
489 keys.push_back(std::make_pair(tagsdh, ""));
492 gdcm::Tag tagsid(0x020,0x000d);
493 keys.push_back(std::make_pair(tagsid, ""));
498 gdcm::Tag tagsd(0x0010,0x0020);
499 keys.push_back(std::make_pair(tagsd, patient_id));
505 vvQuery vvQPacsConnection::getQueryforImages(const std::string patient_id, const std::string study_id, const std::string series_id,bool bdisplay)
508 query.keys = getQueryKeysforImages( patient_id, study_id, series_id, bdisplay);
509 query.theRoot = gdcm::ePatientRootType;
510 query.theLevel = gdcm::eImage;
514 std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getQueryKeysforImages(const std::string patient_id, const std::string study_id, const std::string series_id,bool bdisplay)
517 std::vector< std::pair<gdcm::Tag, std::string> > keys;
522 keys.push_back(std::make_pair(gdcm::Tag (0x0010,0x0020), patient_id));
525 // keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000d), study_id));
528 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), series_id));
532 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x0013), ""));
534 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0018), ""));