]> Creatis software - clitk.git/blobdiff - vv/vvQPacsConnection.cxx
Add patient ID and patient name search available.
[clitk.git] / vv / vvQPacsConnection.cxx
index a535e09168b441acd538bcd443cf31729c9b95ea..91b07b0f9fc6b33fbda0c8adeaf9f2a56333a17e 100644 (file)
@@ -9,6 +9,7 @@
 #include "vvUtils.h"
 
 
+
 vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
        :QDialog(i_parent)
 {
@@ -20,21 +21,19 @@ vvQPacsConnection::vvQPacsConnection(QWidget *i_parent)
 
        ui. tabNetwork->setTabText(0,QString(tr("Network")));
        ui. tabNetwork->setTabText(1,QString(tr("Configuration")));
-       //ui.setChecked(true);
-       //ui.on_check_ModAll_clicked(true);
-       
-       
+       ui.check_ModAll->setEnabled(true);
        ui.networkCombo->addItem("");
        ui.networkCombo->addItems(getDicomServers());
        
+       // Connection   
        connect(ui.networkCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(chooseServer(int)));
-       //connect(ui.scanButton,SIGNAL(clicked()),this,SLOT(on_scanButton_clicked()));
-       connect(ui.importButton, SIGNAL(clicked()), this, SLOT(on_importButton_clicked()));
        connect(ui.removeNetworkButton,SIGNAL(clicked()),this,SLOT(removeServer()));
        connect(ui.NetworkButton,SIGNAL(clicked()),this,SLOT(modifyServer()));
+       
        update();
 }
 
+// remote a Dicom Server in VV settings
 void vvQPacsConnection::removeServer()
 {
        removeDicomServer(m_nickname);
@@ -43,13 +42,14 @@ void vvQPacsConnection::removeServer()
        refreshNetworks();
 }
 
+// modify a Dicom Server in VV settings
 void vvQPacsConnection::modifyServer()
 {
        AddDicomServer(ui.NameEdit->text().toStdString(),ui.AETitleEdit->text().toStdString(),ui.AdressEdit->text().toStdString(),ui.PortEdit->text().toStdString());
        removeServer();
 }
 
-
+// refresh the list of Dicom Servers available from VV settings
 void vvQPacsConnection::refreshNetworks()
 {
        ui.networkCombo->clear();
@@ -72,25 +72,25 @@ void vvQPacsConnection::on_clearButton_clicked()
 
 void vvQPacsConnection::on_scanButton_clicked()
 {
-
+       cleanTree();
        manageStudiesFilter(true);
        bool didItWork = gdcm::CompositeNetworkFunctions::CEcho(m_adress.c_str(), atoi(m_port.c_str()), "CREATIS", m_nickname.c_str() );
        if (didItWork)
        {
                std::vector< std::pair<gdcm::Tag, std::string> > keys = getKeys();
 
-               gdcm::EQueryLevel theLevel = gdcm::eStudy;
-               gdcm::ERootType theRoot  = gdcm::eStudyRootType;//ePatientRootType;
-       
+               m_level =gdcm::ePatient;
                std::vector<gdcm::DataSet> theDataSet;
-               theLevel = gdcm::ePatient;
-               theRoot  = gdcm::ePatientRootType;//ePatientRootType;
-               gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,getPatientKeys(""));
-               bool cfindWork = gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet,   "CREATIS", m_nickname.c_str());
+               gdcm::EQueryLevel theLevel = gdcm::ePatient;
+               gdcm::ERootType theRoot  = gdcm::ePatientRootType;//ePatientRootType;
+               m_query =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,getPatientKeys(ui.patientName->toPlainText().toStdString(), 
+                                       ui.patientID->toPlainText().toStdString()));
+               bool cfindWork = gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), m_query, theDataSet,    "CREATIS", m_nickname.c_str());
                if( cfindWork)
                {
+                       convertDataSet(theDataSet,Patientmodel,getPatientKeys("",""));
                        std::vector<gdcm::DataSet>::iterator it_ds = theDataSet.begin();
-
+/*
                        for(; it_ds != theDataSet.end(); it_ds++)
                        {
                                QList<QStandardItem *> items;
@@ -118,11 +118,19 @@ void vvQPacsConnection::on_scanButton_clicked()
                                        items.push_back(item);
                                }
                                Patientmodel->appendRow(items);
-                       }
+                       }*/
                } // end cfindwork
        } // end didItwork
 }
 
+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::on_optionsButton_clicked()
 {
@@ -212,48 +220,37 @@ void vvQPacsConnection::createTreeView()
        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);
 }
 
 void vvQPacsConnection::selectStudies(const QModelIndex &index)
 {
+       m_level =gdcm::eStudy;
        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;
+       
        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(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet, "CREATIS", m_nickname.c_str());
-       convertDataSet(theDataSet, Studymodel, getStudyKeys(""));
+        m_query = mquery.composeQueryStudy(m_patient);
+       if (  gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), 
+               m_query, theDataSet, "CREATIS", m_nickname.c_str()) )
+       {
+               convertDataSet(theDataSet, Studymodel, getStudyKeys(""));
+       }
 }
 
 
 void vvQPacsConnection::selectSeries(const QModelIndex &index)
 {
+       m_level =gdcm::eSeries;
        Seriesmodel->removeRows(0, Seriesmodel->rowCount(),QModelIndex());
        QVariant elt= Studymodel->data(index.sibling(index.row(),3));
        QVariant elt2= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
 
-       //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;
 
@@ -270,22 +267,23 @@ void vvQPacsConnection::selectSeries(const QModelIndex &index)
        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();
+       m_query = mquery.composeQuerySeries(keys);
+       if ( gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), m_query, theDataSet, "CREATIS", m_nickname.c_str()), "C:\\Boost")
+       {
+               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(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet, "CREATIS", m_nickname.c_str());
-       convertDataSet(theDataSet, Seriesmodel, keys);
+               convertDataSet(theDataSet, Seriesmodel, getSeriesKeys(""));
+       }
 }
 
 void vvQPacsConnection::selectImages(const QModelIndex &index)
 {
+       m_level = gdcm::eImage;
        Imagesmodel->removeRows(0, Imagesmodel->rowCount(),QModelIndex());
        QVariant elt= Seriesmodel->data(index.sibling(index.row(),2));
        QVariant elt2= Patientmodel->data(index.sibling(ui.patientTreeView->selectionModel()->selectedRows().first().row(),1));
@@ -303,16 +301,22 @@ void vvQPacsConnection::selectImages(const QModelIndex &index)
        keys.push_back(std::make_pair(tagss, elt.toString().toStdString()));
        //= getStudyKeys(elt.toString().toStdString());
 
-       // Study Description
+       // Image Description
        gdcm::Tag tagsdc(0x0020,0x0013);
        keys.push_back(std::make_pair(tagsdc, ""));
+               gdcm::Tag tagsic(0x0008,0x0018);
 
 
+       keys.push_back(std::make_pair(tagsic, ""));
+
        gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, theLevel ,keys);
        keys.clear();
-       // Study Description
+       // SOP Instance UID 
+       
+
 
        keys.push_back(std::make_pair(tagsdc, ""));
+keys.push_back(std::make_pair(tagsic, ""));
 
        gdcm::CompositeNetworkFunctions::CFind(m_adress.c_str(), atoi(m_port.c_str()), theQuery, theDataSet, "CREATIS", m_nickname.c_str());
        convertDataSet(theDataSet, Imagesmodel, keys);
@@ -332,16 +336,16 @@ void vvQPacsConnection::manageSeriesFilter(bool i_enable)
        ui.modalityTab->setEnabled(i_enable);
 }
 
-std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getPatientKeys(const std::string i_val)
+std::vector< std::pair<gdcm::Tag, std::string> > vvQPacsConnection::getPatientKeys(const std::string i_patname, const std::string i_patid)
 {
        std::vector< std::pair<gdcm::Tag, std::string> > keys;
        // Patient Name
        gdcm::Tag tag(0x0010,0x0010);
-       keys.push_back(std::make_pair(tag, ""));
+       keys.push_back(std::make_pair(tag, i_patname));
 
        //// Patient ID
        gdcm::Tag tagpid(0x0010,0x0020);
-       keys.push_back(std::make_pair(tagpid, i_val));
+       keys.push_back(std::make_pair(tagpid, i_patid));
        return keys;
 }
 
@@ -474,21 +478,56 @@ void vvQPacsConnection::chooseServer(int index)
 
 void vvQPacsConnection::on_importButton_clicked()
        {
-       
+               int sel = 0;
+               //QModelIndexList list = ui.imagesTreeView-selectedIndexes();
+               QModelIndexList indices =  ui.imagesTreeView->selectionModel()->selectedRows(); 
+               QModelIndexList::iterator it = indices.begin();
+               for(; it != indices.end(); it++)
+                       sel = it->row();
                QModelIndex index;
                QVariant elt= Patientmodel->data(index.sibling(ui.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");
+       //      gdcm::Tag tagsdc(0x0010,0x0020);
+               //keys.push_back(std::make_pair(tagsdc, elt.toString().toStdString()));
+
        
-                bool didItWork =  gdcm::CompositeNetworkFunctions::CMove(m_adress.c_str(),atoi(m_port.c_str()), theQuery, 0,
-       "CREATIS", m_nickname.c_str() );
-       }
\ No newline at end of file
+       // Study Description
+
+
+               //gdcm::SmartPointer<gdcm::BaseRootQuery> theQuery =  gdcm::CompositeNetworkFunctions::ConstructQuery(theRoot, m_level ,fillMoveKeys(), true);
+
+               bool didItWork =  gdcm::CompositeNetworkFunctions::CMove(m_adress.c_str(),atoi(m_port.c_str()), m_query, getDicomClientPort(),
+      getDicomClientAETitle().c_str(), m_aetitle.c_str(),"D:\\move" );
+                gdcm::Directory theDir;
+               theDir.Load("D:\\move");
+          m_files =    theDir.GetFilenames();
+          accept();
+       }
+
+std::vector <std::string> vvQPacsConnection::getFileNames()
+{
+       std::vector <std::string> filenames;
+       gdcm::Directory::FilenamesType::iterator it = m_files.begin();
+       for (;it != m_files.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)
+       {
+       case gdcm::ePatient:
+                       //keys.push_back(getPatientKeys("",""));
+                       break;
+       }
+
+       return keys;
+}
\ No newline at end of file