]> Creatis software - clitk.git/blob - vv/vvQPacsConnection.cxx
corrections for recent version of gdcm
[clitk.git] / vv / vvQPacsConnection.cxx
1 #ifndef _VVPACSCONNECTION_CXX
2 #define _VVPACSCONNECTION_CXX
3 #include "vvQPacsConnection.h"
4 #include "gdcmCompositeNetworkFunctions.h"
5 #include <QtGui/qlistview.h>
6 #include <qfile.h>
7 #include <QDate>
8 #include <QIcon>
9 #include <QDateTime>
10
11
12         vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
13                 :QDialog(i_parent)
14         {
15                  ui.setupUi(this);
16                  setWindowTitle(QString::fromUtf8("PACS CONNECTION"));
17                  createTreeView();
18                  ui.tabFilter->setTabText(0,QString(tr("Modality")));
19                  ui.tabFilter->setTabText(1,QString(tr("Date")));
20
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);
25                  QIcon icon;
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                  update();
36         }
37
38
39         void vvQPacsConnection::on_clearButton_clicked()
40         {
41                 Patientmodel->removeRows(0, Patientmodel->rowCount(),QModelIndex());
42                 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
43                 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
44                 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
45         }
46
47         void vvQPacsConnection::on_scanButton_clicked()
48         {
49                 //on_clearButton_clicked();
50                 manageStudiesFilter(true);
51                 #if defined (USE_GDCM2)
52             bool didItWork = gdcm::CompositeNetworkFunctions::CEcho( "127.0.0.1", 5678,
53                         "CREATIS", "CONQUESTSRV1" );
54                                 /*  tag.SetElement(8);
55                   tag.SetGroup(8);*/
56                 std::vector< std::pair<gdcm::Tag, std::string> > keys = getKeys();
57
58                 //std::pair<gdcm::Tag, std::string> pa;
59                 //pa.first = tag;
60                 //pa.second = "";
61                 ////keys.push_back(std::make_pair(tag, ""));
62                 gdcm::EQueryLevel theLevel = gdcm::eStudy;
63                 gdcm::ERootType theRoot  = gdcm::eStudyRootType;//ePatientRootType;
64                 //gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
65
66         
67                     std::vector<gdcm::DataSet> theDataSet;
68
69                           theLevel = gdcm::ePatient;
70   theRoot  = gdcm::ePatientRootType;//ePatientRootType;
71   gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,getPatientKeys(""));
72
73 //      
74 //theDataSet.clear();
75 //  gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet,
76 //       "CREATIS", "CONQUESTSRV1");
77 //   keys.clear();
78 //   keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0010), ""));                      
79 //                      
80                         gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet,
81        "CREATIS", "CONQUESTSRV1");
82   std::vector<gdcm::DataSet>::iterator it_ds = theDataSet.begin();
83 //
84   for(; it_ds != theDataSet.end(); it_ds++)
85   {
86
87           QList<QStandardItem *> items;
88           const gdcm::DataSet ds = (*it_ds);
89           std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
90           int ind = 0;
91           for(; it_key != keys.end(); it_key++, ind++)
92           {
93                   gdcm::DataElement de = ds.GetDataElement((*it_key).first);
94                   QStandardItem *item = new QStandardItem;
95                   const gdcm::ByteValue *bv = (de).GetByteValue();
96                   if( !de.IsEmpty() )
97                   {
98                           std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
99                           item->setText(tr(buffer.c_str()));
100                   }
101                   else
102                   {
103                           item->setText(tr(""));
104                   }
105                   if(ind ==0)
106                   {
107                         item->setCheckable(true);
108                   }
109                   items.push_back(item);
110           }
111           Patientmodel->appendRow(items);
112          }
113 //   gdcm::Tag tagtest(0x0020,0x1208);
114 //   keys.clear();
115 //   keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0010), ""));
116 ////  keys.push_back(std::make_pair(tagtest, ""));
117 //  theLevel = gdcm::ePatient;
118 //  theRoot  = gdcm::ePatientRootType;//ePatientRootType;
119 //  theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
120 //
121 //      
122 //theDataSet.clear();
123 //  gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet,
124 //       "CREATIS", "CONQUESTSRV1");
125 #endif
126         }
127
128
129         void vvQPacsConnection::on_importButton_clicked()
130         {
131                 QModelIndex index;
132                 QVariant elt= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
133                 
134                 gdcm::EQueryLevel theLevel = gdcm::ePatient;
135                 gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
136                 std::vector<gdcm::DataSet> theDataSet;
137                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
138                 
139                 // Study Description
140                 gdcm::Tag tagsdc(0x0010,0x0020);
141                 keys.push_back(std::make_pair(tagsdc, elt.toString().toStdString()));
142                                 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
143                 gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
144         
145                  bool didItWork =  gdcm::CompositeNetworkFunctions::CMove( "127.0.0.1", 5678, theQuery, 0,
146        "CREATIS", "CONQUESTSRV1", "d:\\temp_pacs_import\\" );
147         }
148
149         void vvQPacsConnection::convertDataSet(std::vector<gdcm::DataSet> i_ds, QStandardItemModel *i_model, std::vector< std::pair<gdcm::Tag, std::string> > keys)
150         {
151                 gdcm::Tag tagdb(0x0008,0x0020);
152                 std::vector<gdcm::DataSet>::iterator it_ds = i_ds.begin();
153                 for(; it_ds != i_ds.end(); it_ds++)
154                 {
155                         QList<QStandardItem *> items;
156                         const gdcm::DataSet ds = (*it_ds);
157                         std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
158                     int ind = 0;
159                     for(; it_key != keys.end(); it_key++, ind++)
160                     {
161                             gdcm::DataElement de = ds.GetDataElement((*it_key).first);
162                             QStandardItem *item = new QStandardItem;
163                             const gdcm::ByteValue *bv = (de).GetByteValue();
164                             if( !de.IsEmpty() )
165                             {
166                                     std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
167                                         /*if((*it_key).first == tagdb)
168                                         {
169                                                 QDate date;
170                                                 date.fromString(tr(buffer.c_str()),"yyyy'MM'd");
171                                                 item->setText(date.toString());
172                                         }
173                                         else
174                                         {*/
175                                                 item->setText(tr(buffer.c_str()));
176                                         //}
177                             }
178                             else
179                             {
180                                     item->setText(tr(""));
181                             }
182                             if(ind ==0)
183                             {
184                                    item->setCheckable(true);
185                             }
186                             items.push_back(item);
187                     }
188                         i_model->appendRow(items);
189                 }
190                 
191         }
192
193
194         void vvQPacsConnection::createTreeView()
195         {
196                 // Patient Tree View
197                 Patientmodel = new QStandardItemModel(0,2,this); 
198                 QStringList Patientlist;
199                 Patientlist.push_back(tr("PATIENT NAME"));
200                 Patientlist.push_back(tr("PATIENT ID"));
201                 Patientmodel->setHorizontalHeaderLabels(Patientlist);
202                 ui.patientTreeView->setModel(Patientmodel);
203                 ui.patientTreeView->setEnabled(true);
204                 connect(ui.patientTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStudies(QModelIndex)));
205                 
206                 // Study Tree View
207                 Studymodel = new QStandardItemModel(0,3,this); 
208                 QStringList Studylist;
209                 Studylist.push_back(tr("DESCRIPTION"));
210                 Studylist.push_back(tr("DATE"));
211                 Studylist.push_back(tr("HOUR"));
212                 Studymodel->setHorizontalHeaderLabels(Studylist);
213                 ui.studyTreeView->setModel(Studymodel);
214                 connect(ui.studyTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectSeries(QModelIndex)));
215
216
217                 // Series Tree View
218                 Seriesmodel = new QStandardItemModel(0,2,this); 
219                 QStringList Serieslist;
220                 Serieslist.push_back(tr("MODALITY"));
221                 Serieslist.push_back(tr("DESCRIPTION"));
222                 Serieslist.push_back(tr("no. accept."));
223                 Seriesmodel->setHorizontalHeaderLabels(Serieslist);
224                 ui.seriesTreeView->setModel(Seriesmodel);
225                 connect(ui.seriesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImages(QModelIndex)));
226
227                 // Images Tree View
228                 Imagesmodel = new QStandardItemModel(0,1,this); 
229                 QStringList Imageslist;
230                 Imageslist.push_back(tr("instance number"));
231                 Imagesmodel->setHorizontalHeaderLabels(Imageslist);
232                 ui.imagesTreeView->setModel(Imagesmodel);
233
234                 //model->setHeaderData(0, Qt::Horizontal,tr("test"),Qt::DisplayRole);
235                 /*QFileSystemModel *filemodel = new   QFileSystemModel;
236                 filemodel->insertColumn(1);
237                 filemodel->setHeaderData(1, Qt::Horizontal,"test",0);*/
238
239         }
240
241         void vvQPacsConnection::selectStudies(const QModelIndex &index)
242         {
243                 Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
244                 QVariant elt= Patientmodel->data(index.sibling(index.row(),1));
245                 m_patient=elt.toString().toStdString();
246                 manageSeriesFilter(true);
247                 gdcm::EQueryLevel theLevel = gdcm::eStudy;
248                 gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
249                 std::vector<gdcm::DataSet> theDataSet;
250                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
251                 
252                 // Study Description
253                 gdcm::Tag tagsd(0x0010,0x0020);
254                 keys.push_back(std::make_pair(tagsd, m_patient));
255                 // Study Description
256                 gdcm::Tag tagsdc(0x0008,0x1030);
257                 keys.push_back(std::make_pair(tagsdc, ""));
258                 // Study date
259                 gdcm::Tag tagdb(0x0008,0x0020);
260                 keys.push_back(std::make_pair(tagdb, ""));
261                 // Study Hour
262                 gdcm::Tag tagsdh(0x0008,0x0030);
263                 keys.push_back(std::make_pair(tagsdh, ""));
264                 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
265                 gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
266                 convertDataSet(theDataSet, Studymodel, getStudyKeys(""));
267         }
268
269
270         void vvQPacsConnection::selectSeries(const QModelIndex &index)
271         {
272                 Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
273                 QVariant elt= Studymodel->data(index.sibling(index.row(),3));
274                 QVariant elt2= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
275
276                 //manageImagesFilter(true);
277                 gdcm::EQueryLevel theLevel = gdcm::eSeries;
278                 gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
279                 std::vector<gdcm::DataSet> theDataSet;
280                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
281                 
282                 //Patient Unique key
283                 keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0020), m_patient));
284
285                 //Study Unique Key
286                 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000d), elt.toString().toStdString()));
287
288                 
289                 // Modality
290                 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
291                 // Description
292                 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
293                 // Acceptance NUmber????
294                 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), elt.toString().toStdString()));
295                 
296                 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
297                 keys.clear();
298                 // Modality
299                 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
300                 // Description
301                 keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
302                 // Acceptance NUmber????
303                 keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), elt.toString().toStdString()));
304
305
306
307                 gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
308                 convertDataSet(theDataSet, Seriesmodel, keys);
309         }
310
311         void vvQPacsConnection::selectImages(const QModelIndex &index)
312         {
313                 Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
314                 QVariant elt= Seriesmodel->data(index.sibling(index.row(),2));
315                 QVariant elt2= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
316
317                 //manageImagesFilter(true);
318                 gdcm::EQueryLevel theLevel = gdcm::eImage;
319                 gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
320                 std::vector<gdcm::DataSet> theDataSet;
321                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
322                 
323                 gdcm::Tag tagsd(0x0010,0x0020);
324                 keys.push_back(std::make_pair(tagsd, m_patient));
325
326                 gdcm::Tag tagss(0x0020,0x000e);
327                 keys.push_back(std::make_pair(tagss, elt.toString().toStdString()));
328                 //= getStudyKeys(elt.toString().toStdString());
329                 
330                 // Study Description
331                 gdcm::Tag tagsdc(0x0020,0x0013);
332                 keys.push_back(std::make_pair(tagsdc, ""));
333                 
334
335                 gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
336                 keys.clear();
337                 // Study Description
338
339                 keys.push_back(std::make_pair(tagsdc, ""));
340                 
341
342                 gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
343                 convertDataSet(theDataSet, Seriesmodel, keys);
344         }
345
346
347         void vvQPacsConnection::manageStudiesFilter(bool i_enable)
348         {
349                 ui.text_PHYS->setEnabled(i_enable);
350                 ui.text_SDESC->setEnabled(i_enable);
351                 ui.dateTab->setEnabled(i_enable);
352
353         }
354
355         void vvQPacsConnection::manageSeriesFilter(bool i_enable)
356         {
357                 ui.modalityTab->setEnabled(i_enable);
358         }
359
360         std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getPatientKeys(const std::string i_val)
361         {
362                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
363                 // Patient Name
364                  gdcm::Tag tag(0x0010,0x0010);
365                 keys.push_back(std::make_pair(tag, ""));
366
367                 //// Patient ID
368                 gdcm::Tag tagpid(0x0010,0x0020);
369                 keys.push_back(std::make_pair(tagpid, i_val));
370                 return keys;
371         }
372
373         std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getStudyKeys(const std::string i_val)
374         {
375                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
376                 // Study Description
377                 gdcm::Tag tagsdc(0x0008,0x1030);
378                 keys.push_back(std::make_pair(tagsdc, ""));
379                 // Study date
380                 gdcm::Tag tagdb(0x0008,0x0020);
381                 keys.push_back(std::make_pair(tagdb, ""));
382                 // Study Hour
383                 gdcm::Tag tagsdh(0x0008,0x0030);
384                 keys.push_back(std::make_pair(tagsdh, ""));
385                 // Study Instance UID
386                 gdcm::Tag tagsid(0x0020,0x000d);
387                 keys.push_back(std::make_pair(tagsid, i_val));
388
389                 return keys;
390         }
391
392
393         std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getSeriesKeys(const std::string i_val)
394         {
395                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
396                 // Modality
397                 gdcm::Tag tagsm(0x0008,0x0060);
398                 keys.push_back(std::make_pair(tagsm, ""));
399                 // Study date
400                 gdcm::Tag tagdb(0x0008,0x103e);
401                 keys.push_back(std::make_pair(tagdb, ""));
402                 // Study Hour
403                 gdcm::Tag tagsdh(0x0020,0x000e);
404                 keys.push_back(std::make_pair(tagsdh, ""));
405                 // Study Instance UID
406                 gdcm::Tag tagsid(0x0020,0x1209);
407                 keys.push_back(std::make_pair(tagsid, i_val));
408
409                 return keys;
410         }
411         std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
412         {
413                 std::vector< std::pair<gdcm::Tag, std::string> > keys;
414                 // Patient Name
415                  gdcm::Tag tag(0x0010,0x0010);
416                 keys.push_back(std::make_pair(tag, ""));
417
418                 //// Patient ID
419                 gdcm::Tag tagpid(0x0010,0x0020);
420                 keys.push_back(std::make_pair(tagpid, ""));
421
422                 // Modality
423                 gdcm::Tag tagmod(0x0008,0x0061);
424                 keys.push_back(std::make_pair(tagmod, ""));
425
426                 // date of birth
427                 gdcm::Tag tagdb(0x0010,0x0030);
428                 keys.push_back(std::make_pair(tagdb, ""));
429
430                 // Study Date
431                 gdcm::Tag tagsd(0x0020,0x000D);
432                 keys.push_back(std::make_pair(tagsd, ""));
433
434                 //// Study Time
435                 //gdcm::Tag tagst(8,30);
436                 //keys.push_back(std::make_pair(tagst, ""));
437
438                 //// Study Description
439                 //gdcm::Tag tagsdc(8,1030);
440                 //keys.push_back(std::make_pair(tagsdc, ""));
441
442                 //// Accession n°
443                 //gdcm::Tag tagacc(8,50);
444                 //keys.push_back(std::make_pair(tagacc, ""));
445
446                 return keys;
447         }
448
449         void vvQPacsConnection::on_check_ModAll_clicked(bool state)
450         {
451                 ui.check_MR->setEnabled(!state);
452                 ui.check_CR->setEnabled(!state);
453                 ui.check_OT->setEnabled(!state);
454                 ui.check_RF->setEnabled(!state);
455                 ui.check_SC->setEnabled(!state);
456                 ui.check_CT->setEnabled(!state);
457                 ui.check_US->setEnabled(!state);
458                 ui.check_NM->setEnabled(!state);
459                 ui.check_DR->setEnabled(!state);
460                 ui.check_US->setEnabled(!state);
461                 ui.check_NM->setEnabled(!state);
462                 ui.check_DR->setEnabled(!state);
463                 ui.check_SR->setEnabled(!state);
464                 ui.check_XA->setEnabled(!state);
465                 ui.check_MG->setEnabled(!state);
466                 if(state)
467                 {
468                         ui.check_MR->setChecked(state);
469                         ui.check_CR->setChecked(state);
470                         ui.check_OT->setChecked(state);
471                         ui.check_RF->setChecked(state);
472                         ui.check_SC->setChecked(state);
473                         ui.check_CT->setChecked(state);
474                         ui.check_US->setChecked(state);
475                         ui.check_NM->setChecked(state);
476                         ui.check_DR->setChecked(state);
477                         ui.check_US->setChecked(state);
478                         ui.check_NM->setChecked(state);
479                         ui.check_DR->setChecked(state);
480                         ui.check_SR->setChecked(state);
481                         ui.check_XA->setChecked(state);
482                         ui.check_MG->setChecked(state);
483                 }
484
485         }
486 #endif