3
* $Id: comandoincluirhistorial.cpp $
6
* Copyright 2008-12 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
13
//#define _GINKGO_TRACE
14
#include <wx/filename.h>
17
#include <wx/msgdlg.h>
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>
36
#include "dialogopathssobreescribirbase.h"
38
#define IDC_INCLUIR 101
42
//lee un directorio en profundidad y lo incluye en el dicomdir
43
namespace LinkHistoryCommand {
44
LinkHistoryCommandParams::LinkHistoryCommandParams(const GNC::GCS::Ptr<IModeloDicom>& pModelo) :
46
m_abrirDespuesDeCargar(false),
51
LinkHistoryCommandParams::~LinkHistoryCommandParams()
56
LinkHistoryCommand::LinkHistoryCommand(LinkHistoryCommandParams* pParams) : IComando(pParams)
58
GTRACE(">> ComandoCarga::ComandoCarga(): " << this);
59
m_pLinkParams = pParams;
61
GTRACE("<< ComandoCarga::ComandoCarga(): " << this);
64
void LinkHistoryCommand::Execute()
66
std::list<long>* insertedSeriesPtr = &(m_pLinkParams->m_InsertedSeries);
68
NotificarProgreso(0.0f,_Std("Linking study..."));
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();
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);
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()));
102
if (fileList.empty()) {
103
//error no file in series
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);
115
void LinkHistoryCommand::Update()
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());
125
std::ostringstream errorOstr;
126
if (!m_pLinkParams->m_ErrorList.empty()) {
129
for (GNC::GCS::HistoryController::TAddErrorList::iterator it = m_pLinkParams->m_ErrorList.begin();it != m_pLinkParams->m_ErrorList.end(); ++it)
131
if ((*it).error == GNC::GCS::HistoryController::TAddError::TE_FileNotExist) {
133
errorOstr<< "\t" << _Std("This files doesn't exist:") << std::endl;
136
errorOstr << "\t\t" << (*it).path << std::endl;
140
for (GNC::GCS::HistoryController::TAddErrorList::iterator it = m_pLinkParams->m_ErrorList.begin();it != m_pLinkParams->m_ErrorList.end(); ++it)
142
if ((*it).error == GNC::GCS::HistoryController::TAddError::TE_WrongFormat) {
144
errorOstr<< "\t" << _Std("This files doesn't have DICOM format:") << std::endl;
147
errorOstr << "\t\t" << (*it).path << std::endl;
152
for (GNC::GCS::HistoryController::TAddErrorList::iterator it = m_pLinkParams->m_ErrorList.begin();it != m_pLinkParams->m_ErrorList.end(); ++it)
154
if ((*it).error == GNC::GCS::HistoryController::TAddError::TE_DICOMDir) {
156
errorOstr << "\t" <<_Std("This files are Dicom Dirs:") << std::endl;
159
errorOstr << "\t\t" << (*it).path << std::endl;
164
std::string errorString = errorOstr.str();
165
if (!errorString.empty()) {
166
LOG_ERROR("ComandoIncluirHistorial", errorOstr.str());
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);