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

« back to all changes in this revision

Viewing changes to src/cadxcore/commands/linkhistorycommand.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: comandoincluirhistorial.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
#include <wx/filename.h>
 
15
#include <wx/file.h>
 
16
#include <wx/dir.h>
 
17
#include <wx/msgdlg.h>
 
18
#include <wx/uri.h>
 
19
 
 
20
#include <api/globals.h>
 
21
#include <api/internationalization/internationalization.h>
 
22
#include <api/ivista.h>
 
23
#include <api/controllers/icontroladorvistas.h>
 
24
#include <api/imodelointegracion.h>
 
25
#include <api/controllers/icontroladorcarga.h>
 
26
#include <api/dicom/imodelodicom.h>
 
27
#include <main/entorno.h>
 
28
#include "linkhistorycommand.h"
 
29
#include <main/controllers/commandcontroller.h>
 
30
#include <main/controllers/historycontroller.h>
 
31
#include <main/gui/history3/historypanel3.h>
 
32
#include <main/controllers/controladoreventos.h>
 
33
#include <main/controllers/controladorlog.h>
 
34
#include <main/controllers/pacscontroller.h>
 
35
 
 
36
#include "dialogopathssobreescribirbase.h"
 
37
 
 
38
#define IDC_INCLUIR       101
 
39
 
 
40
namespace GADAPI {
 
41
 
 
42
        //lee un directorio en profundidad y lo incluye en el dicomdir
 
43
        namespace LinkHistoryCommand {
 
44
                LinkHistoryCommandParams::LinkHistoryCommandParams(const GNC::GCS::Ptr<IModeloDicom>& pModelo) :
 
45
                                m_pModelo(pModelo),
 
46
                                m_abrirDespuesDeCargar(false),
 
47
                                m_informar(true)
 
48
 
 
49
                { }
 
50
 
 
51
                LinkHistoryCommandParams::~LinkHistoryCommandParams()
 
52
                {
 
53
                }
 
54
 
 
55
 
 
56
                LinkHistoryCommand::LinkHistoryCommand(LinkHistoryCommandParams* pParams) : IComando(pParams)
 
57
                {
 
58
                        GTRACE(">> ComandoCarga::ComandoCarga(): " << this);
 
59
                        m_pLinkParams = pParams;
 
60
                        SetId(IDC_INCLUIR);
 
61
                        GTRACE("<< ComandoCarga::ComandoCarga(): " << this);
 
62
                }
 
63
 
 
64
                void LinkHistoryCommand::Execute()
 
65
                {
 
66
                        std::list<long>* insertedSeriesPtr = &(m_pLinkParams->m_InsertedSeries);
 
67
 
 
68
                        NotificarProgreso(0.0f,_Std("Linking study..."));
 
69
 
 
70
                        //first iteration insert downloaded slices into history as usual...
 
71
                        if (m_pLinkParams->m_pModelo.IsValid()) {
 
72
                                //listamos las imagenes que nos hemos bajado
 
73
                                GNC::GCS::HistoryController::StringList urlList;
 
74
                                for (IModeloDicom::ListaPacientesType::const_iterator it = m_pLinkParams->m_pModelo->ListaPacientes().begin(); it != m_pLinkParams->m_pModelo->ListaPacientes().end(); ++it) {
 
75
                                        const IModeloPaciente& p = *it;
 
76
                                        for (IModeloPaciente::ListaEstudiosType::const_iterator it2 = p.ListaEstudios().begin(); it2 != p.ListaEstudios().end(); ++it2) {
 
77
                                                const IModeloEstudio& e = *it2;
 
78
                                                for (IModeloEstudio::ListaSeriesType::const_iterator it3 = e.ListaSeries().begin(); it3 != e.ListaSeries().end(); ++it3) {
 
79
                                                        const IModeloSerie& s = *it3;
 
80
                                                        //first of all insert files...
 
81
                                                        GNC::GCS::HistoryController::StringList fileList;
 
82
                                                        GNC::GCS::IHistoryController::DICOMFileModelList fileModels;
 
83
                                                        for (IModeloSerie::ListaImagenesType::const_iterator it4 = s.ListaImagenes().begin(); it4 != s.ListaImagenes().end(); ++it4) {
 
84
                                                                const IModeloImagen& im = *it4;
 
85
                                                                std::string path = im.GetPathImagen();
 
86
                                                                wxFileName filename(FROMPATH(im.GetPathImagen()));
 
87
                                                                if(filename.GetExt().Lower() == wxT("dcm") || GIL::DICOM::PACSController::Instance()->EsDICOM(im.GetPathImagen(), false, true) ) {
 
88
                                                                        fileList.push_back(im.GetPathImagen());
 
89
                                                                } else if (!path.empty()) {
 
90
                                                                        GNC::GCS::IHistoryController::DICOMFileModel fileModel;
 
91
                                                                                fileModel.file.file_path = im.GetPathImagen();
 
92
                                                                                long in = 0;
 
93
                                                                                wxString::FromUTF8(im.GetInstanceNumber().c_str()).ToLong(&in);
 
94
                                                                                fileModel.file.instance_number = in;
 
95
                                                                                fileModel.file.sopiuid = im.GetUID();
 
96
                                                                                fileModels.push_back(fileModel);
 
97
                                                                } else {
 
98
                                                                        LOG_ERROR("LINKCommand", "trying to link an instance without wado url: " << im.GetUID());
 
99
                                                                        m_pLinkParams->m_ErrorList.push_back(GNC::GCS::HistoryController::TAddError(GNC::GCS::IHistoryController::TAddError::TE_WrongFormat, im.GetUID()));
 
100
                                                                } 
 
101
                                                        }
 
102
                                                        if (fileList.empty()) {
 
103
                                                                //error no file in series
 
104
                                                                return;
 
105
                                                        }
 
106
                                                        if (GNC::GCS::HistoryController::Instance()->AddFiles(fileList, m_pLinkParams->m_ErrorList, insertedSeriesPtr, this, GNC::GCS::HistoryController::TAA_MOVE)) {
 
107
                                                                GNC::GCS::HistoryController::Instance()->LinkFilesToSeries(insertedSeriesPtr->back(), fileModels,this);
 
108
                                                        }
 
109
                                                }
 
110
                                        }
 
111
                                }
 
112
                        }
 
113
                }
 
114
 
 
115
                void LinkHistoryCommand::Update()
 
116
                {
 
117
                        wxString message = wxT("");
 
118
                        message += _("Image acquisition finished.");
 
119
                        message += wxT("\n");
 
120
                        if (m_pLinkParams->m_ErrorList.size() > 0)
 
121
                                message += wxString::Format(_("\nThere are %d errors (see log for more detailed description)"), m_pLinkParams->m_ErrorList.size());
 
122
 
 
123
                        //log
 
124
                        {
 
125
                                std::ostringstream errorOstr;
 
126
                                if (!m_pLinkParams->m_ErrorList.empty()) {
 
127
 
 
128
                                        bool first = true;
 
129
                                        for (GNC::GCS::HistoryController::TAddErrorList::iterator it = m_pLinkParams->m_ErrorList.begin();it != m_pLinkParams->m_ErrorList.end(); ++it)
 
130
                                        {
 
131
                                                if ((*it).error == GNC::GCS::HistoryController::TAddError::TE_FileNotExist) {
 
132
                                                        if (first) {
 
133
                                                                errorOstr<< "\t" << _Std("This files doesn't exist:") << std::endl;
 
134
                                                                first = false;
 
135
                                                        }
 
136
                                                        errorOstr << "\t\t" << (*it).path << std::endl;
 
137
                                                }
 
138
                                        }
 
139
                                        first = true;
 
140
                                        for (GNC::GCS::HistoryController::TAddErrorList::iterator it = m_pLinkParams->m_ErrorList.begin();it != m_pLinkParams->m_ErrorList.end(); ++it)
 
141
                                        {
 
142
                                                if ((*it).error == GNC::GCS::HistoryController::TAddError::TE_WrongFormat) {
 
143
                                                        if (first) {
 
144
                                                                errorOstr<< "\t" << _Std("This files doesn't have DICOM format:") << std::endl;
 
145
                                                                first = false;
 
146
                                                        }
 
147
                                                        errorOstr << "\t\t" << (*it).path << std::endl;
 
148
                                                }
 
149
                                        }
 
150
                                        
 
151
                                        first = true;
 
152
                                        for (GNC::GCS::HistoryController::TAddErrorList::iterator it = m_pLinkParams->m_ErrorList.begin();it != m_pLinkParams->m_ErrorList.end(); ++it)
 
153
                                        {
 
154
                                                if ((*it).error == GNC::GCS::HistoryController::TAddError::TE_DICOMDir) {
 
155
                                                        if (first) {
 
156
                                                                errorOstr << "\t" <<_Std("This files are Dicom Dirs:") << std::endl;
 
157
                                                                first = false;
 
158
                                                        }
 
159
                                                        errorOstr << "\t\t" << (*it).path << std::endl;
 
160
                                                }
 
161
                                        }
 
162
                                }
 
163
                                
 
164
                                std::string errorString = errorOstr.str();
 
165
                                if (!errorString.empty()) {
 
166
                                        LOG_ERROR("ComandoIncluirHistorial", errorOstr.str());
 
167
                                }
 
168
                        }
 
169
 
 
170
                        GNC::GUI::HistoryPanel3::Instance()->ReloadCombos(false);
 
171
                        GNC::GUI::HistoryPanel3::Instance()->RefreshSearch();
 
172
                        const int MAX_OPENED_STUDIES = 3;
 
173
                        if (m_pLinkParams->m_abrirDespuesDeCargar){
 
174
                                std::set<long> openedStudies;
 
175
                                for (std::list<long>::iterator it = m_pLinkParams->m_InsertedSeries.begin(); it != m_pLinkParams->m_InsertedSeries.end() && openedStudies.size() < MAX_OPENED_STUDIES; ++it) {
 
176
                                        GNC::GCS::HistoryController::SeriesModel seriesModel = GNC::GCS::HistoryController::Instance()->GetSeriesModel((*it));
 
177
                                        GNC::GUI::HistoryPanel3::Instance()->OpenSeriesOrStudy(seriesModel.study_fk, false);
 
178
                                }                               
 
179
                        }
 
180
                }
 
181
        }
 
182
}
 
183