~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/commands/pacsdownloadcommand.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*
 
3
*  $Id: comandopacs.cpp $
 
4
*  Ginkgo CADx Project
 
5
*
 
6
*  Copyright 2008-12 MetaEmotion S.L. All rights reserved.
 
7
*  http://ginkgo-cadx.com
 
8
*
 
9
*  This file is licensed under LGPL v3 license.
 
10
*  See License.txt for details
 
11
*
 
12
*/
 
13
//#define _GINKGO_TRACE
 
14
 
 
15
#include <sstream>
 
16
#include <map>
 
17
 
 
18
#include <api/api.h>
 
19
#include <api/globals.h>
 
20
#include <api/ientorno.h>
 
21
 
 
22
#include <api/controllers/icontroladorlog.h>
 
23
#include <main/controllers/commandcontroller.h>
 
24
#include <api/controllers/ieventscontroller.h>
 
25
#include <api/controllers/icontroladorpermisos.h>
 
26
 
 
27
#include <eventos/mensajes.h>
 
28
 
 
29
#include <main/controllers/dcmtk/dicomservers.h>
 
30
 
 
31
#include "pacsdownloadcommand.h"
 
32
#include "comandoincluirhistorial.h"
 
33
#include "linkhistorycommand.h"
 
34
 
 
35
 
 
36
#define IDC_PACS_BUSCAR                  61
 
37
#define IDC_PACS_DESCARGAR               62
 
38
#define IDC_PACS_SUBIR                           64
 
39
 
 
40
#define ID_REFRESCO_PROGRESO 1
 
41
 
 
42
#define PARALLEL
 
43
 
 
44
// Singleton de persistencia
 
45
namespace GADAPI
 
46
{
 
47
 
 
48
        PACSDownloadCommandParams::PACSDownloadCommandParams(const std::string& serverSeleccionado, const GIL::DICOM::DicomDataset& base, bool link) :
 
49
                m_base(base),
 
50
                m_link(link)
 
51
        {                       
 
52
                m_base = base;
 
53
                m_pModelo = GNC::GCS::Ptr<IModeloDicom>(new IModeloDicom());
 
54
 
 
55
                if(serverSeleccionado == "") {
 
56
                        //usaremos el primer servidor (por defecto)
 
57
                        if(!DicomServerList::Instance()->Empty()) {
 
58
                                m_serverSeleccionado = DicomServerList::Instance()->GetDefaultServer()->ID;
 
59
                        } else {
 
60
                                throw GIL::DICOM::PACSException(_Std("There is not any Remote PACS configured"));
 
61
                        }
 
62
                } else {
 
63
                        m_serverSeleccionado = serverSeleccionado;
 
64
                }
 
65
 
 
66
                m_error = "";
 
67
        }
 
68
 
 
69
        PACSDownloadCommandParams::~PACSDownloadCommandParams()
 
70
        {
 
71
        }
 
72
 
 
73
        PACSDownloadCommand::PACSDownloadCommand(PACSDownloadCommandParams* pParams) : IComando(pParams)
 
74
        {
 
75
                m_pPACSParams = pParams;
 
76
                SetId(IDC_PACS_DESCARGAR);
 
77
                EsperaA(IDC_PACS_DESCARGAR);
 
78
#if !defined(PARALLEL)
 
79
                EsperaA(IDC_PACS_BUSCAR);
 
80
                EsperaA(IDC_PACS_DESCARGAR);
 
81
                EsperaA(IDC_PACS_SUBIR);
 
82
#endif
 
83
        }
 
84
 
 
85
        void PACSDownloadCommand::Execute()
 
86
        {
 
87
                std::string tarea= _Std("Downloading files ...");
 
88
                if (!NotificarProgreso(0.0f,tarea)) {
 
89
                    return;
 
90
                }
 
91
 
 
92
                GIL::DICOM::IPACSController* pCI = NULL;
 
93
 
 
94
                try {
 
95
                        pCI = GNC::GCS::IEntorno::Instance()->GetPACSController();
 
96
                        pCI->GetConnection(this);
 
97
                        pCI->QueryRetrieve(this, m_pPACSParams->m_serverSeleccionado, m_pPACSParams->m_pModelo, m_pPACSParams->m_base, this, m_pPACSParams->m_link);
 
98
                }
 
99
                catch (GinkgoNoServerFoundException& ) {
 
100
                        m_pPACSParams->m_error= _Std("Server ID not found. ID = ") + m_pPACSParams->m_serverSeleccionado;
 
101
                        m_pPACSParams->m_pModelo->Error = true;
 
102
                }
 
103
                catch (GIL::DICOM::PACSException& ex) {
 
104
                        m_pPACSParams->m_error =  (const std::string)ex;
 
105
                        m_pPACSParams->m_pModelo->Error = true;
 
106
                }
 
107
                catch (std::exception& ex) {
 
108
                        m_pPACSParams->m_error= ex.what();
 
109
                        m_pPACSParams->m_pModelo->Error = true;
 
110
                }
 
111
                catch (...)
 
112
                {
 
113
                        m_pPACSParams->m_error= _Std("Internal Error");
 
114
                        m_pPACSParams->m_pModelo->Error = true;
 
115
                }
 
116
                if (pCI) {
 
117
                        pCI->ReleaseConnection(this);
 
118
                }
 
119
                GTRACE(m_pPACSParams->m_pModelo);
 
120
                NotificarProgreso(1.0f,tarea);
 
121
        }
 
122
 
 
123
        void PACSDownloadCommand::Update()
 
124
        {
 
125
                if (EstaAbortado()) {
 
126
                    return;
 
127
                }
 
128
                
 
129
                
 
130
                if(!m_pPACSParams->m_error.empty()){
 
131
                        LOG_ERROR("C-MOVE/C-GET", "Error Downloading study: " << m_pPACSParams->m_error);
 
132
                        GNC::GCS::IEventsController::Instance()->ProcesarEvento(new GNC::GCS::Events::EventoMensajes(NULL, _Std("Error downloading study: ") + "\n" + m_pPACSParams->m_error, GNC::GCS::Events::EventoMensajes::PopUpMessage,false, GNC::GCS::Events::EventoMensajes::Error));
 
133
                        return;
 
134
                }
 
135
                else {
 
136
                        if (!m_pPACSParams->m_link) 
 
137
                        {//move downloaded images to history
 
138
                                std::list<std::string> rutas;
 
139
                                std::string rutaImagen;
 
140
                                if (m_pPACSParams->m_pModelo.IsValid()) {
 
141
                                        //listamos las imagenes que nos hemos bajado
 
142
                                        for (IModeloDicom::ListaPacientesType::const_iterator it = m_pPACSParams->m_pModelo->ListaPacientes().begin(); it != m_pPACSParams->m_pModelo->ListaPacientes().end(); ++it) {
 
143
                                                const IModeloPaciente& p = *it;
 
144
                                                for (IModeloPaciente::ListaEstudiosType::const_iterator it2 = p.ListaEstudios().begin(); it2 != p.ListaEstudios().end(); ++it2) {
 
145
                                                        const IModeloEstudio& e = *it2;
 
146
                                                        for (IModeloEstudio::ListaSeriesType::const_iterator it3 = e.ListaSeries().begin(); it3 != e.ListaSeries().end(); ++it3) {
 
147
                                                                const IModeloSerie& s = *it3;
 
148
                                                                for (IModeloSerie::ListaImagenesType::const_iterator it4 = s.ListaImagenes().begin(); it4 != s.ListaImagenes().end(); ++it4) {
 
149
                                                                        const IModeloImagen& im = *it4;
 
150
                                                                        rutas.push_back(im.GetPathImagen());
 
151
                                                                }
 
152
                                                        }
 
153
                                                }
 
154
                                        }
 
155
                                }
 
156
 
 
157
                                //si ha descargado algo...
 
158
                                if(rutas.empty()){
 
159
                                        return;
 
160
                                }
 
161
 
 
162
                                //se lanza un evento para incluir las imagenes en el historial
 
163
                                GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorialParams* pParams = new GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorialParams(rutas, true, GNC::GCS::IHistoryController::TAA_MOVE);
 
164
                                GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorial * pCmd = new GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorial(pParams);
 
165
                                GNC::GCS::ICommandController::Instance()->ProcessAsync(_Std("Including files..."), pCmd, NULL);
 
166
                        }
 
167
                        else 
 
168
                        {
 
169
                                //link images... 
 
170
                                GADAPI::LinkHistoryCommand::LinkHistoryCommandParams* pParams = new GADAPI::LinkHistoryCommand::LinkHistoryCommandParams(m_pPACSParams->m_pModelo);
 
171
                                GADAPI::LinkHistoryCommand::LinkHistoryCommand * pCmd = new GADAPI::LinkHistoryCommand::LinkHistoryCommand(pParams);
 
172
                                GNC::GCS::ICommandController::Instance()->ProcessAsync(_Std("Including files..."), pCmd, NULL);
 
173
                        }
 
174
                }
 
175
        }
 
176
 
 
177
        
 
178
 
 
179
        bool PACSDownloadCommand::NotificarProgreso(float progresoNormalizado,const std::string &texto) {
 
180
                if (EstaAbortado())
 
181
                {
 
182
                        return false;
 
183
                }
 
184
                return IComando::NotificarProgreso(progresoNormalizado, texto);
 
185
        }
 
186
 
 
187
        void PACSDownloadCommand::LiberarRecursos()
 
188
        {
 
189
        }
 
190
 
 
191
}