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