]> Creatis software - clitk.git/blobdiff - vv/vvQPacsConnection.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvQPacsConnection.cxx
index 0f3f91657f3c3c7e7056bb8bbebb6d6781acd164..4ae0d33b9981bdddc7a31e98e2f2aa0b55c16b7f 100644 (file)
 #include <QtGui/qlistview.h>
 #include <qfile.h>
 #include <QDate>
+#include <QIcon>
 #include <QDateTime>
-
-
-       vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
-               :QWidget(i_parent)
-       {
-                setupUi(this);
-                setWindowTitle(QString::fromUtf8("DCM API PACS"));
-                createTreeView();
-                tabFilter->setTabText(0,QString(tr("Modality")));
-                tabFilter->setTabText(1,QString(tr("Date")));
-
-                tabNetwork->setTabText(0,QString(tr("Network")));
-                tabNetwork->setTabText(1,QString(tr("Configuration")));
-                check_ModAll->setChecked(true);
-                on_check_ModAll_clicked(true);
-                QIcon icon;
-                icon.addFile("basket_download.png",QSize(),QIcon::Normal,QIcon::Off);
-                importButton->setIcon(icon);
-                icon.addFile("file_upload.png",QSize(),QIcon::Normal,QIcon::Off);
-               // exportButton->setIcon(icon);
-                icon.addFile("email_forward.png",QSize(),QIcon::Normal,QIcon::Off);
-                icon.addFile("edit.png",QSize(),QIcon::Normal,QIcon::Off);
-                optionsButton->setIcon(icon);
-                icon.addFile("bullet_info.png",QSize(),QIcon::Normal,QIcon::Off);
-                helpButton->setIcon(icon);
-                update();
-       }
-
-
-       void vvQPacsConnection::on_clearButton_clicked()
-       {
-               Patientmodel->removeRows(0, Patientmodel->rowCount(),QModelIndex());
-               Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
-               Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
-               Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
-       }
-
-       void vvQPacsConnection::on_scanButton_clicked()
-       {
-               //on_clearButton_clicked();
-               manageStudiesFilter(true);
-               #if defined (USE_GDCM2)
-           bool didItWork = gdcm::CompositeNetworkFunctions::CEcho( "127.0.0.1", 5678,
-                       "CREATIS", "CONQUESTSRV1" );
-                               /*  tag.SetElement(8);
-                 tag.SetGroup(8);*/
-               std::vector< std::pair<gdcm::Tag, std::string> > keys = getKeys();
-
-               //std::pair<gdcm::Tag, std::string> pa;
-               //pa.first = tag;
-               //pa.second = "";
-               ////keys.push_back(std::make_pair(tag, ""));
-               gdcm::EQueryLevel theLevel = gdcm::eStudy;
-               gdcm::ERootType theRoot  = gdcm::eStudyRootType;//ePatientRootType;
-               //gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
-
+#include "vvPacsSettingsDialog.h"
+#include "vvUtils.h"
+#include <algorithm>
+#include <itkGDCMImageIO.h>
+#include <itkGDCMSeriesFileNames.h>
+
+
+vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
+       :QDialog(i_parent)
+{
+       ui.setupUi(this);
+       setWindowTitle(QString::fromUtf8("PACS CONNECTION"));
+       createTreeView();
+       ui.tabFilter->setTabText(0,QString(tr("Modality")));
+       ui.tabFilter->setTabText(1,QString(tr("Date")));
+
+       ui. tabNetwork->setTabText(0,QString(tr("Network")));
+       ui. tabNetwork->setTabText(1,QString(tr("Configuration")));
+       ui.check_ModAll->setEnabled(true);
+       ui.networkCombo->addItem("");
+       ui.networkCombo->addItems(getDicomServers());
        
-                   std::vector<gdcm::DataSet> theDataSet;
-
-                         theLevel = gdcm::ePatient;
-  theRoot  = gdcm::ePatientRootType;//ePatientRootType;
-  gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,getPatientKeys(""));
-
-//     
-//theDataSet.clear();
-//  gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet,
-//       "CREATIS", "CONQUESTSRV1");
-//   keys.clear();
-//   keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0010), ""));                     
-//                     
-                       gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet,
-       "CREATIS", "CONQUESTSRV1");
-  std::vector<gdcm::DataSet>::iterator it_ds = theDataSet.begin();
-//
-  for(; it_ds != theDataSet.end(); it_ds++)
-  {
-
-         QList<QStandardItem *> items;
-         const gdcm::DataSet ds = (*it_ds);
-         std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
-         int ind = 0;
-         for(; it_key != keys.end(); it_key++, ind++)
-         {
-                 gdcm::DataElement de = ds.GetDataElement((*it_key).first);
-                 QStandardItem *item = new QStandardItem;
-                 const gdcm::ByteValue *bv = (de).GetByteValue();
-                 if( !de.IsEmpty() )
-                 {
-                         std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
-                         item->setText(tr(buffer.c_str()));
-                 }
-                 else
-                 {
-                         item->setText(tr(""));
-                 }
-                 if(ind ==0)
-                 {
-                       item->setCheckable(true);
-                 }
-                 items.push_back(item);
-         }
-         Patientmodel->appendRow(items);
-        }
-//   gdcm::Tag tagtest(0x0020,0x1208);
-//   keys.clear();
-//   keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0010), ""));
-////  keys.push_back(std::make_pair(tagtest, ""));
-//  theLevel = gdcm::ePatient;
-//  theRoot  = gdcm::ePatientRootType;//ePatientRootType;
-//  theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
-//
-//     
-//theDataSet.clear();
-//  gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet,
-//       "CREATIS", "CONQUESTSRV1");
-#endif
-       }
-
-
-       void vvQPacsConnection::on_importButton_clicked()
-       {
-               QModelIndex index;
-               QVariant elt= Patientmodel->data(index.sibling(patientTreeView->selectionModel()->selectedRows().first().row(),1));
-               
-               gdcm::EQueryLevel theLevel = gdcm::ePatient;
-               gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
-               std::vector<gdcm::DataSet> theDataSet;
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               
-               // Study Description
-               gdcm::Tag tagsdc(0x0010,0x0020);
-               keys.push_back(std::make_pair(tagsdc, elt.toString().toStdString()));
-                               gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
-               gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
+       // Connection   
+       connect(ui.networkCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(chooseServer(int)));
+       connect(ui.removeNetworkButton,SIGNAL(clicked()),this,SLOT(removeServer()));
+       connect(ui.NetworkButton,SIGNAL(clicked()),this,SLOT(modifyServer()));
+       connect(ui.exitButton,SIGNAL(clicked()),this,SLOT(close()));
        
-                bool didItWork =  gdcm::CompositeNetworkFunctions::CMove( "127.0.0.1", 5678, theQuery, 0,
-       "CREATIS", "CONQUESTSRV1", "d:\\temp_pacs_import\\" );
-       }
-
-       void vvQPacsConnection::convertDataSet(std::vector<gdcm::DataSet> i_ds, QStandardItemModel *i_model, std::vector< std::pair<gdcm::Tag, std::string> > keys)
-       {
-               gdcm::Tag tagdb(0x0008,0x0020);
-               std::vector<gdcm::DataSet>::iterator it_ds = i_ds.begin();
-               for(; it_ds != i_ds.end(); it_ds++)
-               {
-                       QList<QStandardItem *> items;
-                       const gdcm::DataSet ds = (*it_ds);
-                       std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
-                   int ind = 0;
-                   for(; it_key != keys.end(); it_key++, ind++)
-                   {
-                           gdcm::DataElement de = ds.GetDataElement((*it_key).first);
-                           QStandardItem *item = new QStandardItem;
-                           const gdcm::ByteValue *bv = (de).GetByteValue();
-                           if( !de.IsEmpty() )
-                           {
-                                   std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
-                                       /*if((*it_key).first == tagdb)
-                                       {
-                                               QDate date;
-                                               date.fromString(tr(buffer.c_str()),"yyyy'MM'd");
-                                               item->setText(date.toString());
-                                       }
-                                       else
-                                       {*/
-                                               item->setText(tr(buffer.c_str()));
-                                       //}
-                           }
-                           else
-                           {
-                                   item->setText(tr(""));
-                           }
-                           if(ind ==0)
-                           {
-                                  item->setCheckable(true);
-                           }
-                           items.push_back(item);
-                   }
-                       i_model->appendRow(items);
-               }
-               
-       }
-
-
-       void vvQPacsConnection::createTreeView()
+       update();
+}
+
+// Exit window
+bool vvQPacsConnection::close()
+{
+    QApplication::restoreOverrideCursor();
+    return QWidget::close();
+}
+
+// remote a Dicom Server in VV settings
+void vvQPacsConnection::removeServer()
+{
+       removeDicomServer(m_nickname);
+       ui.networkCombo->removeItem(ui.networkCombo->findText(QString(m_nickname.c_str())));
+       m_nickname="";
+       refreshNetworks();
+}
+
+// modify a Dicom Server in VV settings
+void vvQPacsConnection::modifyServer()
+{
+       int indexCombo = ui.networkCombo->currentIndex();
+       removeDicomServer(m_nickname);
+       AddDicomServer(ui.NameEdit->text().toStdString(),ui.AETitleEdit->text().toStdString(),ui.AdressEdit->text().toStdString(),ui.PortEdit->text().toStdString());
+       ui.networkCombo->clear();
+       ui.networkCombo->addItem(QString());
+       ui.networkCombo->addItems(getDicomServers());
+       ui.networkCombo->setCurrentIndex(indexCombo);
+}
+
+// refresh the list of Dicom Servers available from VV settings
+void vvQPacsConnection::refreshNetworks()
+{
+       ui.networkCombo->clear();
+       ui.networkCombo->addItem(QString());
+       ui.networkCombo->addItems(getDicomServers());
+       ui.NameEdit->setText(QString());
+       ui.AETitleEdit->setText(QString());
+       ui.AdressEdit->setText(QString());
+       ui.PortEdit->setText(QString());
+       ui.tabNetwork->setCurrentIndex(0);
+}
+
+void vvQPacsConnection::on_clearButton_clicked()
+{
+       Patientmodel->removeRows(0, Patientmodel->rowCount(),QModelIndex());
+       Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
+       Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
+       Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
+}
+
+void vvQPacsConnection::on_scanButton_clicked()
+{
+       cleanTree();
+       manageStudiesFilter(true);
+
+       // test first if echo works
+       bool didItWork = gdcm::CompositeNetworkFunctions::CEcho(m_adress.c_str(), atoi(m_port.c_str()), getDicomClientAETitle().c_str(), m_nickname.c_str() );
+       if (didItWork)
        {
-               // Patient Tree View
-               Patientmodel = new QStandardItemModel(0,2,this); 
-               QStringList Patientlist;
-               Patientlist.push_back(tr("PATIENT NAME"));
-               Patientlist.push_back(tr("PATIENT ID"));
-               Patientmodel->setHorizontalHeaderLabels(Patientlist);
-               patientTreeView->setModel(Patientmodel);
-               patientTreeView->setEnabled(true);
-               connect(patientTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStudies(QModelIndex)));
-               
-               // Study Tree View
-               Studymodel = new QStandardItemModel(0,3,this); 
-               QStringList Studylist;
-               Studylist.push_back(tr("DESCRIPTION"));
-               Studylist.push_back(tr("DATE"));
-               Studylist.push_back(tr("HOUR"));
-               Studymodel->setHorizontalHeaderLabels(Studylist);
-               studyTreeView->setModel(Studymodel);
-               connect(studyTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectSeries(QModelIndex)));
-
-
-               // Series Tree View
-               Seriesmodel = new QStandardItemModel(0,2,this); 
-               QStringList Serieslist;
-               Serieslist.push_back(tr("MODALITY"));
-               Serieslist.push_back(tr("DESCRIPTION"));
-               Serieslist.push_back(tr("no. accept."));
-               Seriesmodel->setHorizontalHeaderLabels(Serieslist);
-               seriesTreeView->setModel(Seriesmodel);
-               connect(seriesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImages(QModelIndex)));
-
-               // Images Tree View
-               Imagesmodel = new QStandardItemModel(0,1,this); 
-               QStringList Imageslist;
-               Imageslist.push_back(tr("instance number"));
-               Imagesmodel->setHorizontalHeaderLabels(Imageslist);
-               imagesTreeView->setModel(Imagesmodel);
-
-               //model->setHeaderData(0, Qt::Horizontal,tr("test"),Qt::DisplayRole);
-               /*QFileSystemModel *filemodel = new   QFileSystemModel;
-               filemodel->insertColumn(1);
-               filemodel->setHeaderData(1, Qt::Horizontal,"test",0);*/
-
-       }
-
-       void vvQPacsConnection::selectStudies(const QModelIndex &index)
-       {
-               Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
-               QVariant elt= Patientmodel->data(index.sibling(index.row(),1));
-               m_patient=elt.toString().toStdString();
-               manageSeriesFilter(true);
-               gdcm::EQueryLevel theLevel = gdcm::eStudy;
-               gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
+               m_level =gdcm::ePatient;
                std::vector<gdcm::DataSet> theDataSet;
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               
-               // Study Description
-               gdcm::Tag tagsd(0x0010,0x0020);
-               keys.push_back(std::make_pair(tagsd, m_patient));
-               // Study Description
-               gdcm::Tag tagsdc(0x0008,0x1030);
-               keys.push_back(std::make_pair(tagsdc, ""));
-               // Study date
-               gdcm::Tag tagdb(0x0008,0x0020);
-               keys.push_back(std::make_pair(tagdb, ""));
-               // Study Hour
-               gdcm::Tag tagsdh(0x0008,0x0030);
-               keys.push_back(std::make_pair(tagsdh, ""));
-               gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
-               gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
-               convertDataSet(theDataSet, Studymodel, getStudyKeys(""));
-       }
-
-
-       void vvQPacsConnection::selectSeries(const QModelIndex &index)
-       {
-               Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
-               QVariant elt= Studymodel->data(index.sibling(index.row(),3));
-               QVariant elt2= Patientmodel->data(index.sibling(patientTreeView->selectionModel()->selectedRows().first().row(),1));
+               f_query = mQFactory.getQueryPatient(ui.patientName->toPlainText().toStdString(),        ui.patientID->toPlainText().toStdString());
 
-               //manageImagesFilter(true);
-               gdcm::EQueryLevel theLevel = gdcm::eSeries;
-               gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
-               std::vector<gdcm::DataSet> theDataSet;
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               
-               //Patient Unique key
-               keys.push_back(std::make_pair(gdcm::Tag(0x0010,0x0020), m_patient));
-
-               //Study Unique Key
-               keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000d), elt.toString().toStdString()));
-
-               
-               // Modality
-               keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
-               // Description
-               keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
-               // Acceptance NUmber????
-               keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), elt.toString().toStdString()));
-               
-               gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
-               keys.clear();
-               // Modality
-               keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
-               // Description
-               keys.push_back(std::make_pair(gdcm::Tag(0x0008,0x0060), elt.toString().toStdString()));
-               // Acceptance NUmber????
-               keys.push_back(std::make_pair(gdcm::Tag(0x0020,0x000e), elt.toString().toStdString()));
-
-
-
-               gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
-               convertDataSet(theDataSet, Seriesmodel, keys);
-       }
+               bool cfindWork = gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), 
+                       gdcm::CompositeNetworkFunctions::ConstructQuery(f_query.theRoot, f_query.theLevel ,f_query.keys),
+                       theDataSet, getDicomClientAETitle().c_str()     , m_nickname.c_str());
+               if( cfindWork)
+               {
+                       convertDataSet(theDataSet,Patientmodel,mQFactory.getPatientKeys("",""));
+               } // end cfindwork
+       } // end didItwork
+}
 
-       void vvQPacsConnection::selectImages(const QModelIndex &index)
-       {
-               Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
-               QVariant elt= Seriesmodel->data(index.sibling(index.row(),2));
-               QVariant elt2= Patientmodel->data(index.sibling(patientTreeView->selectionModel()->selectedRows().first().row(),1));
 
-               //manageImagesFilter(true);
-               gdcm::EQueryLevel theLevel = gdcm::eImageOrFrame;
-               gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
-               std::vector<gdcm::DataSet> theDataSet;
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               
-               gdcm::Tag tagsd(0x0010,0x0020);
-               keys.push_back(std::make_pair(tagsd, m_patient));
-
-               gdcm::Tag tagss(0x0020,0x000e);
-               keys.push_back(std::make_pair(tagss, elt.toString().toStdString()));
-               //= getStudyKeys(elt.toString().toStdString());
-               
-               // Study Description
-               gdcm::Tag tagsdc(0x0020,0x0013);
-               keys.push_back(std::make_pair(tagsdc, ""));
-               
-
-               gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
-               keys.clear();
-               // Study Description
-
-               keys.push_back(std::make_pair(tagsdc, ""));
-               
-
-               gdcm::CompositeNetworkFunctions::CFind("127.0.0.1", 5678, theQuery, theDataSet, "CREATIS", "CONQUESTSRV1");
-               convertDataSet(theDataSet, Seriesmodel, keys);
-       }
+/// show Options DialogBox to set a new Dicom Server
+void vvQPacsConnection::on_optionsButton_clicked()
+{
+       vvPacsSettingsDialog *dg  = new vvPacsSettingsDialog(this);
+       dg->show();
+}
 
+void vvQPacsConnection::convertDataSet(std::vector<gdcm::DataSet> i_ds, QStandardItemModel *i_model, std::vector< std::pair<gdcm::Tag, std::string> > keys)
+{
 
-       void vvQPacsConnection::manageStudiesFilter(bool i_enable)
+       std::vector<gdcm::DataSet>::iterator it_ds = i_ds.begin();
+       for(; it_ds != i_ds.end(); it_ds++)
        {
-               text_PHYS->setEnabled(i_enable);
-               text_SDESC->setEnabled(i_enable);
-               dateTab->setEnabled(i_enable);
-
+               QList<QStandardItem *> items;
+               const gdcm::DataSet ds = (*it_ds);
+               std::vector< std::pair<gdcm::Tag, std::string> >::iterator it_key = keys.begin();
+               int ind = 0;
+               for(; it_key != keys.end(); it_key++, ind++)
+               {
+                       gdcm::DataElement de = ds.GetDataElement((*it_key).first);
+                       QStandardItem *item = new QStandardItem;
+                       const gdcm::ByteValue *bv = (de).GetByteValue();
+                       if( !de.IsEmpty() )
+                       {
+                               std::string buffer = std::string( bv->GetPointer(), bv->GetLength() );
+                               item->setText(tr(buffer.c_str()));
+                       }
+                       else
+                       {
+                               item->setText(tr(""));
+                       }
+                       if(ind ==0)
+                       {
+                               item->setCheckable(true);
+                       }
+                       items.push_back(item);
+               }
+               i_model->appendRow(items);
        }
-
-       void vvQPacsConnection::manageSeriesFilter(bool i_enable)
+}
+
+// TreeViews creation
+void vvQPacsConnection::createTreeView()
+{
+       // Patient Tree View
+       Patientmodel = new QStandardItemModel(0,2,this); 
+       QStringList Patientlist;
+       Patientlist.push_back(tr("PATIENT NAME"));
+       Patientlist.push_back(tr("PATIENT ID"));
+       Patientmodel->setHorizontalHeaderLabels(Patientlist);
+       ui.patientTreeView->setModel(Patientmodel);
+       ui.patientTreeView->setEnabled(true);
+       connect(ui.patientTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStudies(QModelIndex)));
+
+       // Study Tree View
+       Studymodel = new QStandardItemModel(0,3,this); 
+       QStringList Studylist;
+       Studylist.push_back(tr("DESCRIPTION"));
+       Studylist.push_back(tr("DATE"));
+       Studylist.push_back(tr("HOUR"));
+       Studylist.push_back(tr("STUDY ID"));
+       Studymodel->setHorizontalHeaderLabels(Studylist);
+       ui.studyTreeView->setModel(Studymodel);
+       connect(ui.studyTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectSeries(QModelIndex)));
+
+
+       // Series Tree View
+       Seriesmodel = new QStandardItemModel(0,2,this); 
+       QStringList Serieslist;
+       Serieslist.push_back(tr("MODALITY"));
+       Serieslist.push_back(tr("DESCRIPTION"));
+       Serieslist.push_back(tr("no. accept."));
+       Seriesmodel->setHorizontalHeaderLabels(Serieslist);
+       ui.seriesTreeView->setModel(Seriesmodel);
+       connect(ui.seriesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImages(QModelIndex)));
+               connect(ui.imagesTreeView, SIGNAL(clicked(QModelIndex)), this, SLOT(selectImage(QModelIndex)));
+       // Images Tree View
+       Imagesmodel = new QStandardItemModel(0,1,this); 
+       QStringList Imageslist;
+       Imageslist.push_back(tr("instance number"));
+       Imageslist.push_back(tr("sopuid"));
+       Imagesmodel->setHorizontalHeaderLabels(Imageslist);
+       ui.imagesTreeView->setModel(Imagesmodel);
+}
+
+// clean the different model Trees
+void vvQPacsConnection::cleanTree()
+{
+       Patientmodel->removeRows(0,Patientmodel->rowCount());
+       Studymodel->removeRows(0,Patientmodel->rowCount());
+       Seriesmodel->removeRows(0,Patientmodel->rowCount());
+       Imagesmodel->removeRows(0,Patientmodel->rowCount());
+
+}
+
+void vvQPacsConnection::selectStudies(const QModelIndex &index)
+{
+
+               m_patient= Patientmodel->data(index.sibling(index.row(),1)).toString().toStdString();           
+       Studymodel->removeRows(0, Studymodel->rowCount(),QModelIndex());
+       Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
+       Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
+       manageSeriesFilter(true);
+       convertDataSet( findQuery( mQFactory.getQueryforStudy(m_patient, false)) , Studymodel, mQFactory.getQueryKeysforStudy("",true));
+}
+
+
+void vvQPacsConnection::clearMove()
+{
+
+}
+
+void vvQPacsConnection::selectSeries(const QModelIndex &index)
+{
+       m_study= Studymodel->data(index.sibling(index.row(),3)).toString().toStdString();
+       Seriesmodel->removeRows(0, Seriesmodel->rowCount());
+       Imagesmodel->removeRows(0, Imagesmodel->rowCount());
+    convertDataSet( findQuery( mQFactory.getQueryforSeries(m_patient,m_study, false)), Seriesmodel, mQFactory.getSeriesKeys("","",true));
+       
+}
+
+void vvQPacsConnection::selectImages(const QModelIndex &index)
+{
+       m_series = Seriesmodel->data(index.sibling(index.row(),2)).toString().toStdString();
+       Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
+       convertDataSet( findQuery( mQFactory.getQueryforImages(m_patient,m_study, m_series, false) ),  Imagesmodel, mQFactory.getQueryKeysforImages("","","",true));
+}
+
+void vvQPacsConnection::selectImage(const QModelIndex &index)
+{
+       std::string _image = Imagesmodel->data(index.sibling(index.row(),1)).toString().toStdString();
+       mQFactory.setQueryforImage(m_patient,m_study, m_series, _image);
+       
+}
+
+
+std::vector<gdcm::DataSet> vvQPacsConnection::findQuery(vvQuery i_query)
+{
+          std::vector<gdcm::DataSet> theDataSet;
+          gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), 
+               gdcm::CompositeNetworkFunctions::ConstructQuery(i_query.theRoot, i_query.theLevel,i_query.keys), theDataSet,  
+               getDicomClientAETitle().c_str(), m_nickname.c_str());
+       return theDataSet;
+}
+
+void vvQPacsConnection::manageStudiesFilter(bool i_enable)
+{
+       ui.text_PHYS->setEnabled(i_enable);
+       ui.text_SDESC->setEnabled(i_enable);
+       ui.dateTab->setEnabled(i_enable);
+
+}
+
+void vvQPacsConnection::manageSeriesFilter(bool i_enable)
+{
+       ui.modalityTab->setEnabled(i_enable);
+}
+
+
+std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getStudyKeys(const std::string i_val)
+{
+       std::vector< std::pair<gdcm::Tag, std::string> > keys;
+       // Study Description
+       gdcm::Tag tagsdc(0x0008,0x1030);
+       keys.push_back(std::make_pair(tagsdc, ""));
+       // Study date
+       gdcm::Tag tagdb(0x0008,0x0020);
+       keys.push_back(std::make_pair(tagdb, ""));
+       // Study Hour
+       gdcm::Tag tagsdh(0x0008,0x0030);
+       keys.push_back(std::make_pair(tagsdh, ""));
+       // Study Instance UID
+       gdcm::Tag tagsid(0x0020,0x000d);
+       keys.push_back(std::make_pair(tagsid, i_val));
+
+       return keys;
+}
+
+std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
+{
+       std::vector< std::pair<gdcm::Tag, std::string> > keys;
+       // Patient Name
+       gdcm::Tag tag(0x0010,0x0010);
+       keys.push_back(std::make_pair(tag, ""));
+
+       //// Patient ID
+       gdcm::Tag tagpid(0x0010,0x0020);
+       keys.push_back(std::make_pair(tagpid, ""));
+
+       // Modality
+       gdcm::Tag tagmod(0x0008,0x0061);
+       keys.push_back(std::make_pair(tagmod, ""));
+
+       // date of birth
+       gdcm::Tag tagdb(0x0010,0x0030);
+       keys.push_back(std::make_pair(tagdb, ""));
+
+       // Study Date
+       gdcm::Tag tagsd(0x0020,0x000D);
+       keys.push_back(std::make_pair(tagsd, ""));
+
+       //// Study Time
+       //gdcm::Tag tagst(8,30);
+       //keys.push_back(std::make_pair(tagst, ""));
+
+       //// Study Description
+       //gdcm::Tag tagsdc(8,1030);
+       //keys.push_back(std::make_pair(tagsdc, ""));
+
+       //// Accession
+       //gdcm::Tag tagacc(8,50);
+       //keys.push_back(std::make_pair(tagacc, ""));
+
+       return keys;
+}
+
+void vvQPacsConnection::on_check_ModAll_clicked(bool state)
+{
+       ui.check_MR->setEnabled(!state);
+       ui.check_CR->setEnabled(!state);
+       ui.check_OT->setEnabled(!state);
+       ui.check_RF->setEnabled(!state);
+       ui.check_SC->setEnabled(!state);
+       ui.check_CT->setEnabled(!state);
+       ui.check_US->setEnabled(!state);
+       ui.check_NM->setEnabled(!state);
+       ui.check_DR->setEnabled(!state);
+       ui.check_US->setEnabled(!state);
+       ui.check_NM->setEnabled(!state);
+       ui.check_DR->setEnabled(!state);
+       ui.check_SR->setEnabled(!state);
+       ui.check_XA->setEnabled(!state);
+       ui.check_MG->setEnabled(!state);
+       if(state)
        {
-               modalityTab->setEnabled(i_enable);
+               ui.check_MR->setChecked(state);
+               ui.check_CR->setChecked(state);
+               ui.check_OT->setChecked(state);
+               ui.check_RF->setChecked(state);
+               ui.check_SC->setChecked(state);
+               ui.check_CT->setChecked(state);
+               ui.check_US->setChecked(state);
+               ui.check_NM->setChecked(state);
+               ui.check_DR->setChecked(state);
+               ui.check_US->setChecked(state);
+               ui.check_NM->setChecked(state);
+               ui.check_DR->setChecked(state);
+               ui.check_SR->setChecked(state);
+               ui.check_XA->setChecked(state);
+               ui.check_MG->setChecked(state);
        }
 
-       std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getPatientKeys(const std::string i_val)
+}
+
+void vvQPacsConnection::chooseServer(int index)
+{
+       std::map < std::string, std:: string> values = getDicomServer(ui.networkCombo->currentText());
+       m_port = values["PORT"];
+       m_aetitle = values["AETITLE"];
+       m_adress= values["ADRESS"];
+       m_nickname = values["nickname"];
+       ui.AdressEdit->setText(QString(m_adress.c_str()));
+       ui.AETitleEdit->setText(QString(m_aetitle.c_str()));
+       ui.NameEdit->setText(QString(m_nickname.c_str()));
+       ui.PortEdit->setText(QString(m_port.c_str()));
+}
+
+void vvQPacsConnection::on_importButton_clicked()
        {
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               // Patient Name
-                gdcm::Tag tag(0x0010,0x0010);
-               keys.push_back(std::make_pair(tag, ""));
-
-               //// Patient ID
-               gdcm::Tag tagpid(0x0010,0x0020);
-               keys.push_back(std::make_pair(tagpid, i_val));
-               return keys;
+               setCursor(QCursor(Qt::WaitCursor));
+               QString path = QString::fromStdString(getCMoveDirectory());
+               QDir dirpath (path);
+               if (dirpath.exists())
+               {
+                       QFileInfoList list = dirpath.entryInfoList( QDir::Files);
+                       QFileInfoList::iterator it_file = dirpath.entryInfoList( QDir::Files).begin();
+                       for(int i = 0; i < list.length() ; i++)
+                       {
+                                       QFile::remove(list.at(i).filePath());
+                       }
+               }
+               else
+               {
+                       dirpath.mkdir(path);
+               }
+               bool didItWork =  gdcm::CompositeNetworkFunctions::CMove(m_adress.c_str(),atoi(m_port.c_str()),
+                       gdcm::CompositeNetworkFunctions::ConstructQuery(mQFactory.getMoveQuery().theRoot, mQFactory.getMoveQuery().theLevel ,mQFactory.getMoveQuery().keys, gdcm::eMove),
+                       getDicomClientPort(),  getDicomClientAETitle().c_str(), m_aetitle.c_str(), path.toStdString().c_str() );
+               gdcm::Directory theDir;
+               theDir.Load(path.toStdString().c_str());
+     //m_files =       theDir.GetFilenames();
+
+     typedef itk::GDCMSeriesFileNames NamesGeneratorType;
+     NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
+     nameGenerator->SetUseSeriesDetails(true);
+
+     //ds gerer recursive moi-meme pour progress ...
+     nameGenerator->SetInputDirectory(path.toStdString());
+
+     // insert in table
+     typedef std::vector<std::string> SeriesIdContainer;
+     const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
+       std::map<std::string, std::vector<std::string>* > mListOfSeriesFilenames;
+
+
+          m_fileseries.clear();
+          
+     for (unsigned int i=0; i<seriesUID.size(); i++) {
+               m_fileseries.push_back( nameGenerator->GetFileNames(seriesUID[i]));
+        }
+          
+          accept();
+         setCursor(QCursor(Qt::ArrowCursor));
        }
 
-       std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getStudyKeys(const std::string i_val)
-       {
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               // Study Description
-               gdcm::Tag tagsdc(0x0008,0x1030);
-               keys.push_back(std::make_pair(tagsdc, ""));
-               // Study date
-               gdcm::Tag tagdb(0x0008,0x0020);
-               keys.push_back(std::make_pair(tagdb, ""));
-               // Study Hour
-               gdcm::Tag tagsdh(0x0008,0x0030);
-               keys.push_back(std::make_pair(tagsdh, ""));
-               // Study Instance UID
-               gdcm::Tag tagsid(0x0020,0x000d);
-               keys.push_back(std::make_pair(tagsid, i_val));
-
-               return keys;
-       }
 
 
-       std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getSeriesKeys(const std::string i_val)
-       {
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               // Modality
-               gdcm::Tag tagsm(0x0008,0x0060);
-               keys.push_back(std::make_pair(tagsm, ""));
-               // Study date
-               gdcm::Tag tagdb(0x0008,0x103e);
-               keys.push_back(std::make_pair(tagdb, ""));
-               // Study Hour
-               gdcm::Tag tagsdh(0x0020,0x000e);
-               keys.push_back(std::make_pair(tagsdh, ""));
-               // Study Instance UID
-               gdcm::Tag tagsid(0x0020,0x1209);
-               keys.push_back(std::make_pair(tagsid, i_val));
-
-               return keys;
-       }
-       std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getKeys()
+std::vector <std::string> vvQPacsConnection::getFileNames(int i_series)
+{
+       std::vector <std::string> filenames;
+       gdcm::Directory::FilenamesType::iterator it = m_fileseries[i_series].begin();
+       for (;it != m_fileseries[i_series].end(); it++)
+               filenames.push_back(it->c_str());
+       return filenames;
+}
+std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::fillMoveKeys()
+{
+       std::vector< std::pair<gdcm::Tag, std::string> > keys;
+       switch(m_level)
        {
-               std::vector< std::pair<gdcm::Tag, std::string> > keys;
-               // Patient Name
-                gdcm::Tag tag(0x0010,0x0010);
-               keys.push_back(std::make_pair(tag, ""));
-
-               //// Patient ID
-               gdcm::Tag tagpid(0x0010,0x0020);
-               keys.push_back(std::make_pair(tagpid, ""));
-
-               // Modality
-               gdcm::Tag tagmod(0x0008,0x0061);
-               keys.push_back(std::make_pair(tagmod, ""));
-
-               // date of birth
-               gdcm::Tag tagdb(0x0010,0x0030);
-               keys.push_back(std::make_pair(tagdb, ""));
-
-               // Study Date
-               gdcm::Tag tagsd(0x0020,0x000D);
-               keys.push_back(std::make_pair(tagsd, ""));
-
-               //// Study Time
-               //gdcm::Tag tagst(8,30);
-               //keys.push_back(std::make_pair(tagst, ""));
-
-               //// Study Description
-               //gdcm::Tag tagsdc(8,1030);
-               //keys.push_back(std::make_pair(tagsdc, ""));
-
-               //// Accession n°
-               //gdcm::Tag tagacc(8,50);
-               //keys.push_back(std::make_pair(tagacc, ""));
-
-               return keys;
+       case gdcm::ePatient:
+                       //keys.push_back(getPatientKeys("",""));
+                       break;
        }
 
-       void vvQPacsConnection::on_check_ModAll_clicked(bool state)
-       {
-               check_MR->setEnabled(!state);
-               check_CR->setEnabled(!state);
-               check_OT->setEnabled(!state);
-               check_RF->setEnabled(!state);
-               check_SC->setEnabled(!state);
-               check_CT->setEnabled(!state);
-               check_US->setEnabled(!state);
-               check_NM->setEnabled(!state);
-               check_DR->setEnabled(!state);
-               check_US->setEnabled(!state);
-               check_NM->setEnabled(!state);
-               check_DR->setEnabled(!state);
-               check_SR->setEnabled(!state);
-               check_XA->setEnabled(!state);
-               check_MG->setEnabled(!state);
-               if(state)
-               {
-                       check_MR->setChecked(state);
-                       check_CR->setChecked(state);
-                       check_OT->setChecked(state);
-                       check_RF->setChecked(state);
-                       check_SC->setChecked(state);
-                       check_CT->setChecked(state);
-                       check_US->setChecked(state);
-                       check_NM->setChecked(state);
-                       check_DR->setChecked(state);
-                       check_US->setChecked(state);
-                       check_NM->setChecked(state);
-                       check_DR->setChecked(state);
-                       check_SR->setChecked(state);
-                       check_XA->setChecked(state);
-                       check_MG->setChecked(state);
-               }
-
-       }
\ No newline at end of file
+       return keys;
+}