~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/main/gui/adquisition/dialogoadquisicion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
ImportĀ upstreamĀ versionĀ 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*
 
3
*  $Id: dialogoadquisicion.cpp 3763 2011-04-25 12:07:55Z carlos $
 
4
*  Ginkgo CADx Project
 
5
*
 
6
*  Copyright 2008-10 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
*/
 
14
//#define _GINKGO_TRACE
 
15
 
 
16
#include <api/globals.h>
 
17
#include <api/ilock.h>
 
18
#include <set>
 
19
 
 
20
#include <wx/wx.h>
 
21
#include <wx/animate.h>
 
22
#include <wx/imaglist.h>
 
23
#include <wx/dnd.h>
 
24
#include <wx/config.h>
 
25
#include <wx/ginkgostyle/ginkgostyle.h>
 
26
#include <wx/propiedades/wxpropiedades.h>
 
27
 
 
28
#include "dialogoadquisicion.h"
 
29
 
 
30
#include <resources/ginkgoresourcemanager.h>
 
31
#include <main/entorno.h>
 
32
#include <main/controllers/controladorcomandos.h>
 
33
#include <main/controllers/controladorpermisos.h>
 
34
#include <main/controllers/controladorlog.h>
 
35
#include <main/controllers/controladorhistorial.h>
 
36
#include <main/controllers/controladoreventos.h>
 
37
#include <eventos/eventosginkgo.h>
 
38
#include <api/icontextoestudio.h>
 
39
 
 
40
#define SIZE_ICONOS 16
 
41
 
 
42
#define ICONO_ESTUDIO 0
 
43
#define ICONO_SERIE 1
 
44
#define ICONO_HOMBRE 2
 
45
#define ICONO_MUJER 3
 
46
#define ICONO_OTRO 4
 
47
#define SIZE_ICONOS 16
 
48
 
 
49
#define COL_PACS_ID 0
 
50
#define COL_PACS_DESCRIPTION 1
 
51
#define COL_PACS_MODE 2
 
52
 
 
53
namespace Descargas {
 
54
        enum Columnas
 
55
        {
 
56
                Col_PatientInfo,
 
57
                Col_Description,
 
58
                Col_Progress,
 
59
                Col_Status,
 
60
        };
 
61
 
 
62
        enum Estado
 
63
        {
 
64
                Parada,
 
65
                Iniciada,
 
66
                Terminada,
 
67
                Erronea
 
68
        };
 
69
 
 
70
        class DescargasGridTable;
 
71
 
 
72
        class Descarga : public GNC::GCS::IObservador
 
73
        {
 
74
        public:
 
75
                Descarga(DescargasGridTable* pGridTable, const std::string& s, const std::string& pd,const std::string& des, const std::string& uid, const std::string& mod, bool seriesMode)
 
76
                {
 
77
                        m_pGridTable = pGridTable;
 
78
                        Server = s;
 
79
                        PatientDescription = pd;
 
80
                        Description = des;
 
81
                        UID = uid;
 
82
                        Modality = mod;
 
83
                        SeriesMode = seriesMode;
 
84
                        StatusId = Parada;
 
85
                        m_pComando = NULL;
 
86
 
 
87
                        GNC::GCS::ControladorEventos::Instance()->Registrar(this, GNC::GCS::Eventos::EventoProgresoComando());
 
88
 
 
89
                        DoStop();
 
90
                }
 
91
 
 
92
                ~Descarga()
 
93
                {
 
94
                        GNC::Entorno::Instance()->GetControladorComandos()->AbortarComandosDeOwner(this);
 
95
                        GNC::GCS::ControladorEventos::Instance()->DesRegistrar(this, GNC::GCS::Eventos::EventoProgresoComando());
 
96
                        DoStop();
 
97
                }
 
98
 
 
99
                std::string Server;
 
100
 
 
101
                std::string PatientDescription;
 
102
                std::string Description;
 
103
                std::string Modality;
 
104
                std::string UID;
 
105
                bool SeriesMode;
 
106
 
 
107
                float       Progreso;
 
108
                std::string Status;
 
109
                Estado      StatusId;
 
110
 
 
111
                GADAPI::ComandoPACS* m_pComando;
 
112
                bool                 m_Abortar;
 
113
 
 
114
        private:
 
115
                void DoRun() {
 
116
                        if (StatusId == Iniciada) {
 
117
                                return;
 
118
                        }
 
119
                        if (m_pComando != NULL) {
 
120
                                GNC::GCS::ControladorComandos::Instance()->AbortarComando(m_pComando, false);
 
121
                                m_pComando = NULL;
 
122
                        }
 
123
 
 
124
                        GADAPI::ComandoPACSParams * pParams;
 
125
                        if (SeriesMode) {
 
126
                                pParams = new GADAPI::ComandoPACSParams(Server, UID, GADAPI::ComandoPACSParams::TA_Serie);
 
127
                        } else {
 
128
                                pParams = new GADAPI::ComandoPACSParams(Server, UID, GADAPI::ComandoPACSParams::TA_Estudio);
 
129
                        }
 
130
 
 
131
                        m_pComando = new GADAPI::ComandoPACS(pParams);
 
132
                        GNC::Entorno::Instance()->GetControladorComandos()->ProcessAsync(_Std("Downloading from PACS..."), m_pComando, this);
 
133
 
 
134
                        Status = _Std("Starting...");
 
135
                        StatusId = Iniciada;
 
136
 
 
137
                }
 
138
 
 
139
                void DoStop() {
 
140
                        if (StatusId == Parada || StatusId == Terminada || StatusId == Erronea) {
 
141
                                return;
 
142
                        }
 
143
                        Progreso = 0.0f;
 
144
                        m_Abortar = true;
 
145
 
 
146
                        Status = _Std("Stopped");
 
147
                        StatusId = Parada;
 
148
                        if (m_pComando != NULL) {
 
149
                                GNC::GCS::ControladorComandos::Instance()->AbortarComando(m_pComando, false);
 
150
                                m_pComando = NULL;
 
151
                                m_Abortar = true;
 
152
                        }
 
153
                }
 
154
 
 
155
                virtual void ProcesarEvento(GNC::GCS::Eventos::IEvento *evt);
 
156
 
 
157
                void OnProgresoInicio();
 
158
                void OnProgresoProgreso(float progresoNormalizado, const std::string& texto);
 
159
                void OnProgresoFinalizacion();
 
160
 
 
161
                DescargasGridTable* m_pGridTable;
 
162
 
 
163
                friend class DescargasGridTable;
 
164
        };
 
165
 
 
166
        class ProgresoCellRenderer : public wxGridCellFloatRenderer
 
167
        {
 
168
        public:
 
169
 
 
170
                ProgresoCellRenderer(DescargasGridTable* table)
 
171
                {
 
172
                        m_pGridTable = table;
 
173
                }
 
174
 
 
175
                ~ProgresoCellRenderer()
 
176
                {
 
177
                        ;
 
178
                }
 
179
 
 
180
                virtual void Draw(wxGrid& grid,
 
181
                        wxGridCellAttr& attr,
 
182
                        wxDC& dc,
 
183
                        const wxRect& cellRect,
 
184
                        int row, int col,
 
185
                        bool isSelected);
 
186
 
 
187
                virtual wxGridCellRenderer* Clone () const
 
188
                {
 
189
                        return new ProgresoCellRenderer(m_pGridTable);
 
190
                }
 
191
 
 
192
        private:
 
193
                DescargasGridTable* m_pGridTable;
 
194
        };
 
195
 
 
196
        class DescargasGridTable : public wxGridTableBase
 
197
        {
 
198
        public:
 
199
 
 
200
                GNC::GUI::DialogoAdquisicion* pDlg;
 
201
 
 
202
                std::vector<Descarga*> m_Descargas;
 
203
 
 
204
                DescargasGridTable(GNC::GUI::DialogoAdquisicion* pParent)
 
205
                {
 
206
                        pDlg = pParent;
 
207
                }
 
208
 
 
209
                ~DescargasGridTable()
 
210
                {
 
211
                        for(std::vector<Descarga*>::iterator it = m_Descargas.begin(); it!= m_Descargas.end(); ++it) {
 
212
                                delete (*it);
 
213
                        }
 
214
                        m_Descargas.clear();
 
215
                }
 
216
 
 
217
                virtual int GetNumberRows()
 
218
                {
 
219
                        return m_Descargas.size();
 
220
                }
 
221
                virtual int GetNumberCols()
 
222
                {
 
223
                        return 4;
 
224
                }
 
225
 
 
226
                int FindDescarga(const std::string& uid)
 
227
                {
 
228
                        int pos = -1;
 
229
                        for (unsigned int i = 0; pos == -1 && i < m_Descargas.size(); i++) {
 
230
                                if (m_Descargas[i]->UID == uid) {
 
231
                                        pos = (int)i;
 
232
                                }
 
233
                        }
 
234
                        return pos;
 
235
                }
 
236
 
 
237
                virtual bool AddDescarga(const std::string& s, const std::string& pd,const std::string& sd, const std::string& su, const std::string& sm, bool initIfStopped, bool seriesMode)
 
238
                {
 
239
 
 
240
 
 
241
                        if (s.empty() || su.empty()) {
 
242
                                LOG_ERROR("GUI/Adquisition", "Empty mandatory values (serverId | serieInstanceUID) while adding serie to download queue");
 
243
                                return false;
 
244
                        }
 
245
                        int pos = FindDescarga(su);
 
246
                        if (pos != -1) {
 
247
                                if (m_Descargas[pos]->StatusId != Descargas::Iniciada && initIfStopped) {
 
248
                                        GetView()->SelectRow(pos);
 
249
                                        IniciarDescarga(pos);
 
250
 
 
251
                                        return true;
 
252
                                } else {
 
253
                                        return false;
 
254
                                }
 
255
                        }
 
256
 
 
257
                        m_Descargas.push_back(new Descarga(this ,s, pd, sd, su, sm, seriesMode));
 
258
                        wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
 
259
                                m_Descargas.size() - 1, 1);
 
260
                        GetView()->Freeze();
 
261
                        GetView()->ProcessTableMessage( msg );
 
262
                        pos = FindDescarga(su);
 
263
                        GetView()->SelectRow(pos);
 
264
                        GetView()->Thaw();
 
265
                        IniciarDescarga(pos);
 
266
 
 
267
                        return true;
 
268
                }
 
269
 
 
270
                virtual void RemoveDescarga(Descarga* d)
 
271
                {
 
272
                        RemoveDescarga(FindDescarga(d->UID));
 
273
                }
 
274
 
 
275
                virtual void RemoveDescarga(const std::string& uid)
 
276
                {
 
277
                        RemoveDescarga(FindDescarga(uid));
 
278
 
 
279
                }
 
280
 
 
281
                virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 )
 
282
                {
 
283
                        bool removed = false;
 
284
                        for (unsigned int i = 0; i < numRows; i++) {
 
285
                                RemoveDescarga(pos);
 
286
                                removed = true;
 
287
                        }
 
288
                        return removed;
 
289
                }
 
290
 
 
291
                virtual void RemoveDescarga(int pos)
 
292
                {
 
293
                        if (pos < 0) {
 
294
                                return;
 
295
                        }
 
296
                        else {
 
297
                                delete m_Descargas[pos];
 
298
                                m_Descargas.erase(m_Descargas.begin() + pos);
 
299
                                wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, pos, 1);
 
300
                                GetView()->Freeze();
 
301
                                GetView()->ProcessTableMessage( msg );
 
302
                                pDlg->UpdateButtons();
 
303
                                GetView()->Thaw();
 
304
                        }
 
305
                }
 
306
 
 
307
                virtual void SetProgresoDescarga(int pos, float p)
 
308
                {
 
309
                        if (pos >= 0 && pos < (int)m_Descargas.size()) {
 
310
                                Descarga* d = m_Descargas[pos];
 
311
                                d->Progreso = p;
 
312
                                wxGridTableMessage msg( this, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES, pos, 1);
 
313
                                GetView()->Freeze();
 
314
                                GetView()->ProcessTableMessage( msg );
 
315
                                GetView()->Thaw();
 
316
                        }
 
317
 
 
318
                }
 
319
 
 
320
                virtual void SetEstadoDescarga(int pos, const std::string& text)
 
321
                {
 
322
                        if (pos >= 0 && pos < (int)m_Descargas.size()) {
 
323
                                Descarga* d = m_Descargas[pos];
 
324
                                d->Status = text;
 
325
                                wxGridTableMessage msg( this, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES, pos, 1);
 
326
                                GetView()->Freeze();
 
327
                                GetView()->ProcessTableMessage( msg );
 
328
                                GetView()->Thaw();
 
329
                        }
 
330
 
 
331
                }
 
332
 
 
333
                virtual void IniciarDescarga(int pos)
 
334
                {
 
335
                        if (pos >= 0 && pos < (int)m_Descargas.size()) {
 
336
                                Descarga* d = m_Descargas[pos];
 
337
                                d->DoRun();
 
338
                                wxGridTableMessage msg( this, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES, pos, 1);
 
339
                                GetView()->Freeze();
 
340
                                GetView()->ProcessTableMessage( msg );
 
341
                                pDlg->UpdateButtons();
 
342
                                GetView()->Thaw();
 
343
                        }
 
344
 
 
345
                }
 
346
 
 
347
                virtual void DetenerDescarga(int pos)
 
348
                {
 
349
                        if (pos >= 0 && pos < (int)m_Descargas.size()) {
 
350
                                Descarga* d = m_Descargas[pos];
 
351
                                d->DoStop();
 
352
                                wxGridTableMessage msg( this, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES, pos, 1);
 
353
                                GetView()->Freeze();
 
354
                                GetView()->ProcessTableMessage( msg );
 
355
                                pDlg->UpdateButtons();
 
356
                                GetView()->Thaw();
 
357
                        }
 
358
 
 
359
                }
 
360
 
 
361
                virtual Descarga const * GetDescarga(int i) const
 
362
                {
 
363
                        if (i < 0 || i > (int) m_Descargas.size()) {
 
364
                                return NULL;
 
365
                        }
 
366
                        else {
 
367
                                return m_Descargas[i];
 
368
                        }
 
369
                }
 
370
 
 
371
 
 
372
                virtual bool IsEmptyCell( int row, int /*col*/ )
 
373
                {
 
374
                        if (row >= (int)m_Descargas.size()) {
 
375
                                return true;
 
376
                        }
 
377
                        else {
 
378
                                return false;
 
379
                        }
 
380
                }
 
381
                virtual wxString GetValue( int row, int col )
 
382
                {
 
383
                        const Descarga& dr = *(m_Descargas[row]);
 
384
 
 
385
                        switch ( col )
 
386
                        {
 
387
                        case Col_PatientInfo:
 
388
                                return wxString::FromUTF8( (dr.PatientDescription).c_str() );
 
389
 
 
390
                        case Col_Description:
 
391
                                return wxString::FromUTF8( (dr.Description).c_str() );
 
392
 
 
393
                        case Col_Progress:
 
394
                                return wxString::Format(_T("%f"), 100.0f * dr.Progreso);
 
395
 
 
396
                        case Col_Status:
 
397
                                return wxString::FromUTF8( (dr.Status).c_str() );
 
398
                        }
 
399
 
 
400
                        return wxEmptyString;
 
401
                }
 
402
                virtual void SetValue( int /*row*/, int /*col*/, const wxString& /*value*/ )
 
403
                {
 
404
                        //const Descarga& dr = *(m_Descargas[row]);
 
405
                        ;
 
406
                }
 
407
 
 
408
                virtual wxString GetColLabelValue( int col )
 
409
                {
 
410
                        switch ( col )
 
411
                        {
 
412
                        case Col_PatientInfo:
 
413
                                return _("Patient");
 
414
 
 
415
                        case Col_Description:
 
416
                                return _("Description");
 
417
 
 
418
                        case Col_Progress:
 
419
                                return _("Progress");
 
420
 
 
421
                        case Col_Status:
 
422
                                return _("Status");
 
423
                        }
 
424
 
 
425
                        wxFAIL_MSG(_("unknown column"));
 
426
 
 
427
                        return wxEmptyString;
 
428
                }
 
429
 
 
430
                virtual wxString GetTypeName( int /*row*/, int col )
 
431
                {
 
432
 
 
433
                        switch ( col )
 
434
                        {
 
435
                        case Col_PatientInfo:
 
436
                                return wxGRID_VALUE_STRING;
 
437
 
 
438
                        case Col_Description:
 
439
                                return wxGRID_VALUE_STRING;
 
440
 
 
441
                        case Col_Progress:
 
442
                                return wxGRID_VALUE_FLOAT;
 
443
 
 
444
                        case Col_Status:
 
445
                                return wxGRID_VALUE_STRING;
 
446
                        }
 
447
 
 
448
                        wxFAIL_MSG(_("unknown column"));
 
449
 
 
450
                        return wxEmptyString;
 
451
                }
 
452
 
 
453
                virtual bool CanGetValueAs( int /*row*/, int col, const wxString& typeName )
 
454
                {
 
455
                        if ( typeName == wxGRID_VALUE_STRING )
 
456
                        {
 
457
                                return true;
 
458
                        }
 
459
                        else if ( typeName == wxGRID_VALUE_FLOAT )
 
460
                        {
 
461
                                if ( col == Col_Progress )
 
462
                                {
 
463
                                        return true;
 
464
                                }
 
465
                        }
 
466
                        return false;
 
467
                }
 
468
 
 
469
                virtual bool CanSetValueAs( int row, int col, const wxString& typeName )
 
470
                {
 
471
                        return CanGetValueAs(row, col, typeName);
 
472
                }
 
473
 
 
474
                virtual double GetValueAsDouble( int row, int col )
 
475
                {
 
476
                        const Descarga& dr = *(m_Descargas[row]);
 
477
 
 
478
                        switch ( col )
 
479
                        {
 
480
                        case Col_Progress:
 
481
                                return dr.Progreso;
 
482
                        }
 
483
                        return 0.0f;
 
484
                }
 
485
 
 
486
                virtual void SetValueAsDouble( int /*row*/, int /*col*/, double /*value*/ )
 
487
                {
 
488
                        ;
 
489
                        /*
 
490
                        BugsGridData& gd = gs_dataBugsGrid[row];
 
491
 
 
492
                        switch ( col )
 
493
                        {
 
494
                        case Col_Priority:
 
495
                        gd.prio = value;
 
496
                        break;
 
497
 
 
498
                        default:
 
499
                        wxFAIL_MSG(_T("unexpected column"));
 
500
                        }
 
501
                        */
 
502
                }
 
503
 
 
504
                virtual void OnChangeStatusDescarga(const Descarga& des) {
 
505
                        int pos = FindDescarga(des.UID);
 
506
                        wxArrayInt selectedRows = GetView()->GetSelectedRows();
 
507
                        for (wxArrayInt::iterator it = selectedRows.begin(); it != selectedRows.end(); ++it) {
 
508
                                if ((*it) == pos) {
 
509
                                        pDlg->UpdateButtons();
 
510
                                        break;
 
511
                                }
 
512
                        }
 
513
                }
 
514
        };
 
515
 
 
516
 
 
517
        void ProgresoCellRenderer::Draw(wxGrid& grid,
 
518
                wxGridCellAttr& attr,
 
519
                wxDC& dc,
 
520
                const wxRect& cellRect,
 
521
                int row, int col,
 
522
                bool isSelected)
 
523
        {
 
524
                wxGridCellRenderer::Draw(grid, attr, dc, cellRect, row, col, isSelected);
 
525
 
 
526
                float progreso = m_pGridTable->GetDescarga(row)->Progreso;
 
527
                if(progreso>1.0f)
 
528
                {
 
529
                        progreso = 1.0f;
 
530
                }
 
531
 
 
532
                dc.SetPen( wxPen( wxColour(58, 143, 255), 1, wxSOLID ) );
 
533
                dc.SetBrush(*wxTRANSPARENT_BRUSH);
 
534
                wxRect cr = cellRect;
 
535
                //cr.Deflate(1);
 
536
                dc.DrawRectangle(cr.x, cr.y, cr.width, cr.height);
 
537
 
 
538
                cr.width = (int) ( (float)cr.width * progreso );
 
539
 
 
540
                dc.GradientFillLinear(cr, wxColour(224, 237, 255), wxColour(119, 169, 255), wxEAST);
 
541
 
 
542
                SetTextColoursAndFont(grid, attr, dc, isSelected);
 
543
                int func = dc.GetLogicalFunction();
 
544
                dc.SetLogicalFunction(wxXOR);
 
545
 
 
546
                wxCoord tx = 0, ty = 0;
 
547
                wxString str = wxString::Format(wxT("%.02f%%"), 100.0f * progreso);
 
548
                dc.GetTextExtent(str, &tx, &ty, NULL, NULL, NULL);
 
549
 
 
550
                dc.DrawText(str, cellRect.x + (cellRect.width >> 1)  - (tx >> 1), cellRect.y + (cellRect.height >> 1) - (ty >> 1) );
 
551
                dc.SetLogicalFunction(func);
 
552
 
 
553
        }
 
554
 
 
555
        void Descarga::ProcesarEvento(GNC::GCS::Eventos::IEvento *evt)
 
556
        {
 
557
                GNC::GCS::Eventos::EventoProgresoComando* pEvt = dynamic_cast<GNC::GCS::Eventos::EventoProgresoComando*> (evt);
 
558
                if (pEvt == NULL  || pEvt->GetComando() == NULL || pEvt->GetComando() != m_pComando) {
 
559
                        return;
 
560
                }
 
561
                switch (pEvt->GetTipo()) {
 
562
        case GNC::GCS::Eventos::EventoProgresoComando::TEP_Iniciado:
 
563
                OnProgresoInicio();
 
564
                break;
 
565
        case GNC::GCS::Eventos::EventoProgresoComando::TEP_Progreso:
 
566
                OnProgresoProgreso(pEvt->GetProgresoNormalizado(), pEvt->GetTexto());
 
567
                break;
 
568
        case GNC::GCS::Eventos::EventoProgresoComando::TEP_Finalizado:
 
569
                OnProgresoFinalizacion();
 
570
                break;
 
571
        case GNC::GCS::Eventos::EventoProgresoComando::TEP_Unknown:
 
572
                break;
 
573
                }
 
574
                m_pGridTable->OnChangeStatusDescarga(*this);
 
575
        }
 
576
 
 
577
        void Descarga::OnProgresoInicio()
 
578
        {
 
579
                int did = m_pGridTable->FindDescarga(UID);
 
580
                m_pGridTable->SetEstadoDescarga(did, _Std("Started"));
 
581
        }
 
582
 
 
583
        void Descarga::OnProgresoProgreso(float progresoNormalizado, const std::string& texto)
 
584
        {
 
585
                int did = m_pGridTable->FindDescarga(UID);
 
586
 
 
587
                m_pGridTable->SetProgresoDescarga(did, progresoNormalizado);
 
588
                m_pGridTable->SetEstadoDescarga(did, texto);
 
589
 
 
590
        }
 
591
 
 
592
        void Descarga::OnProgresoFinalizacion()
 
593
        {
 
594
                int did = m_pGridTable->FindDescarga(UID);
 
595
 
 
596
                Progreso = 1.0f;
 
597
 
 
598
                if (!m_pComando->m_pPACSParams->m_pModelo->TieneImagenes()) {
 
599
                        std::string errorMsg;
 
600
 
 
601
                        if (m_pComando->m_pPACSParams->m_error.size() > 0) {
 
602
                                errorMsg = _Std("Error: ") + m_pComando->m_pPACSParams->m_error;
 
603
                        }
 
604
                        else {
 
605
                                errorMsg = _Std("Error: No images were downloaded");
 
606
                        }
 
607
                        Status = errorMsg;
 
608
                        StatusId = Erronea;
 
609
                        m_pGridTable->SetEstadoDescarga(did, errorMsg);
 
610
                }
 
611
                else {
 
612
                        Status = _Std("Finished");
 
613
                        StatusId = Terminada;
 
614
                        m_pGridTable->SetEstadoDescarga(did, _Std("Finished"));
 
615
                }
 
616
                m_pComando = NULL;
 
617
        }
 
618
}
 
619
 
 
620
 
 
621
//---------------------------------------------------------------------------
 
622
 
 
623
//---------------HELPER DRAG & DROP ---------
 
624
class wxDropTargetDescargas: public wxTextDropTarget
 
625
{
 
626
public:
 
627
        wxDropTargetDescargas():wxTextDropTarget()
 
628
        {
 
629
                SetDefaultAction(wxDragCopy);
 
630
        }
 
631
 
 
632
        ~wxDropTargetDescargas()
 
633
        {
 
634
        }
 
635
 
 
636
        virtual bool OnDropText(wxCoord /*x*/, wxCoord /*y*/, const wxString& text)
 
637
        {
 
638
                return text == wxT("");
 
639
        }
 
640
};
 
641
 
 
642
GNC::GUI::DialogoAdquisicion* GNC::GUI::DialogoAdquisicion::Instance()
 
643
{
 
644
        if (m_pInstance == NULL) {
 
645
                m_pInstance = new DialogoAdquisicion(GNC::Entorno::Instance()->GetVentanaRaiz());
 
646
        }
 
647
        return m_pInstance;
 
648
}
 
649
 
 
650
void GNC::GUI::DialogoAdquisicion::FreeInstance()
 
651
{
 
652
        if(m_pInstance!=NULL){
 
653
                m_pInstance->Close();
 
654
                m_pInstance = NULL;
 
655
        }
 
656
}
 
657
 
 
658
GNC::GUI::DialogoAdquisicion* GNC::GUI::DialogoAdquisicion::m_pInstance = NULL;
 
659
 
 
660
 
 
661
GNC::GUI::DialogoAdquisicion::DialogoAdquisicion(wxWindow* pParent) : DialogoAdquisicionBase(pParent)
 
662
{
 
663
        m_pComandoPACS = NULL;
 
664
        m_pImageList = new wxImageList(SIZE_ICONOS,SIZE_ICONOS,true);
 
665
        m_Mode = TD_SERIES;
 
666
 
 
667
        //animation
 
668
        m_pAnimation = new wxAnimationCtrl(m_pPanelPACS,wxID_ANY,GinkgoResourcesManager::BarraProgreso::GetIcoLoading());
 
669
        m_pAnimation->Hide();
 
670
        m_pSizerAnimation->Add(m_pAnimation, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
671
 
 
672
        m_pBotonIniciarPararTask->Enable(false);
 
673
        m_pBotonDeleteTask->Enable(false);
 
674
        m_pBotonOpenTask->Enable(false);
 
675
        m_AutoAddSeries = false;
 
676
        m_AutoAddSeriesItem = NULL;
 
677
 
 
678
        m_pDescargasGridTable = new Descargas::DescargasGridTable(this);
 
679
        m_pGridDescargas->SetTable(m_pDescargasGridTable, false, wxGrid::wxGridSelectRows);
 
680
 
 
681
        wxGridCellAttr *attrRO = new wxGridCellAttr();
 
682
        wxGridCellAttr *attrPG = new wxGridCellAttr();
 
683
 
 
684
        attrRO->SetReadOnly();
 
685
        attrPG->SetReadOnly();
 
686
        attrPG->SetRenderer(new Descargas::ProgresoCellRenderer(m_pDescargasGridTable));
 
687
 
 
688
        for (int i = 0; i < m_pDescargasGridTable->GetNumberCols(); i++) {
 
689
                if (i != Descargas::Col_Progress) {
 
690
                        m_pGridDescargas->SetColAttr(i, attrRO);
 
691
                }
 
692
                else {
 
693
                        m_pGridDescargas->SetColAttr(i, attrPG);
 
694
                }
 
695
        }
 
696
        m_pGridDescargas->SetMargins(0, 0);
 
697
        //m_pGridDescargas->EnableScrolling(false, true);
 
698
 
 
699
        m_pGridDescargas->Connect(wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEventHandler(DialogoAdquisicion::OnGridSelect), NULL, this);
 
700
        m_pGridDescargas->Connect(wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler(DialogoAdquisicion::OnGridDClick), NULL, this);
 
701
        m_pGridDescargas->Connect(wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler(DialogoAdquisicion::OnGridMenu), NULL, this);
 
702
        m_pGridDescargas->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(DialogoAdquisicion::OnGridKeyDown), NULL, this);
 
703
        m_pGridDescargas->SetDropTarget(new wxDropTargetDescargas());
 
704
 
 
705
        m_pImageList->Add(GinkgoResourcesManager::PanelHistorial::GetIcoEstudio());
 
706
        m_pImageList->Add(GinkgoResourcesManager::PanelHistorial::GetIcoSerie());
 
707
        m_pImageList->Add(GinkgoResourcesManager::PanelHistorial::GetIcoHombre());
 
708
        m_pImageList->Add(GinkgoResourcesManager::PanelHistorial::GetIcoMujer());
 
709
        m_pImageList->Add(GinkgoResourcesManager::PanelHistorial::GetIcoOtro());
 
710
        m_pTreeListResultados->SetImageList(m_pImageList);
 
711
 
 
712
        m_pTreeListResultados->SetMainColumn(0);
 
713
        m_pTreeListResultados->Connect(wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( DialogoAdquisicion::OnTreeSelChanged ), NULL, this);
 
714
        m_pTreeListResultados->Connect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( DialogoAdquisicion::OnTreeItemActivated ), NULL, this);
 
715
        m_pTreeListResultados->Connect(wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( DialogoAdquisicion::OnTreeItemMenu ), NULL, this);
 
716
        m_pTreeListResultados->Connect(wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxTreeEventHandler( DialogoAdquisicion::OnTreeItemExpanded ), NULL, this);
 
717
        m_pTreeListResultados->Connect(wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEventHandler( DialogoAdquisicion::OnTreeBeginDrag ), NULL, this);
 
718
 
 
719
 
 
720
        m_pPACSList->Connect(wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( DialogoAdquisicion::OnPACSChanged), NULL, this);
 
721
 
 
722
        /*
 
723
        for (int i = 0; i < 100; i++) {
 
724
        m_pDescargasGridTable->AddDescarga("server", "patientID", "patientName", "serieDescr", "serieIUID");
 
725
        m_pDescargasGridTable->SetProgresoDescarga( i, ((float) i) / 100.0f);
 
726
        }
 
727
        */
 
728
 
 
729
        if(GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits", "patient_scope")) {
 
730
                m_HardCodedPatientSearch = true;
 
731
                bool first = true;
 
732
                std::ostringstream os;
 
733
 
 
734
                GNC::GCS::IEntorno::ListaModelosIntegracion& modelos = GNC::Entorno::Instance()->GetModelosIntegracion();
 
735
 
 
736
                for (GNC::GCS::IEntorno::ListaModelosIntegracion::iterator it = modelos.begin(); it != modelos.end(); it++) {
 
737
 
 
738
                        GIL::IModeloIntegracion* modelo = *it;
 
739
                        GIL::TListaIdentificadores& ids = modelo->Paciente.listaIdentificadores;
 
740
 
 
741
                        for (GIL::TListaIdentificadores::iterator it = ids.begin(); it != ids.end(); it++)
 
742
                        {
 
743
                                if (first) {
 
744
                                        first = false;
 
745
                                }
 
746
                                else {
 
747
                                        os << "/";
 
748
                                }
 
749
                                os << (*it).valor;
 
750
                        }
 
751
 
 
752
                }
 
753
 
 
754
                int tmpIndex = m_pFieldCombo->FindString(_("Id"));
 
755
                if (tmpIndex > 0) {
 
756
                        m_pFieldCombo->Remove(tmpIndex,tmpIndex);
 
757
                }
 
758
                tmpIndex = m_pFieldCombo->FindString(_("Name"));
 
759
                if (tmpIndex > 0) {
 
760
                        m_pFieldCombo->Remove(tmpIndex,tmpIndex);
 
761
                }
 
762
 
 
763
                m_HardCodedPatientId = os.str();
 
764
        }
 
765
        else {
 
766
                int tmpIndex = m_pFieldCombo->FindString(_("Name"));
 
767
                if (tmpIndex < 0) {
 
768
                        m_pFieldCombo->Insert(_("Name"),0);
 
769
                }
 
770
                tmpIndex = m_pFieldCombo->FindString(_("Id"));
 
771
                if (tmpIndex < 0) {
 
772
                        m_pFieldCombo->Insert(_("Id"),0);
 
773
                }
 
774
                m_HardCodedPatientSearch = false;
 
775
        }
 
776
        m_pFieldCombo->Select(0);
 
777
 
 
778
        //modalities
 
779
        {
 
780
                const int MaxModalityNumber=20; // Modificar la constante si se aƱaden o quitan cĆ³digos de modalidad
 
781
                std::string modalidades[MaxModalityNumber] = {"CR","CT","DR","DX","IO","MG","MR","NM","OT","PT","RF","RG","SC","SR","US","XA","XC","ES","ECG","HD"};
 
782
                for(int i = 0; i<MaxModalityNumber; i++) {
 
783
                        wxCheckBox* pCheckBox = new wxCheckBox( m_pPanelPACS, wxID_ANY, wxString::FromUTF8(modalidades[i].c_str()), wxDefaultPosition, wxDefaultSize, 0 );
 
784
                        m_pModalitySizer->Add( pCheckBox, 0, wxALL, 2 );
 
785
                        m_modalitiesList.push_back(pCheckBox);
 
786
                        pCheckBox->Connect( wxEVT_KEY_UP, wxKeyEventHandler( DialogoAdquisicion::OnKeyDownFormulario ), NULL, this );
 
787
                }
 
788
                m_pPanelPACS->Layout();
 
789
                m_pPanelSearch->Layout();
 
790
                m_notebook1->Layout();
 
791
        }
 
792
 
 
793
        m_pModeloDicom = GnkPtr<IModeloDicom>(new IModeloDicom());
 
794
 
 
795
        Layout();
 
796
        AutoSizeGrid();
 
797
        m_pGridDescargas->EnableDragColSize(true);
 
798
 
 
799
        GNC::GCS::ControladorEventos::Instance()->Registrar(this, GNC::GCS::Eventos::EventoProgresoComando());
 
800
}
 
801
 
 
802
GNC::GUI::DialogoAdquisicion::~DialogoAdquisicion()
 
803
{
 
804
        GNC::Entorno::Instance()->GetControladorComandos()->AbortarComandosDeOwner(this);
 
805
        {
 
806
                m_pDescargasGridTable->Clear();
 
807
                this->m_pTreeListResultados->DeleteRoot();
 
808
        }
 
809
        delete m_pImageList;
 
810
        m_pAnimation->Destroy();
 
811
}
 
812
 
 
813
bool GNC::GUI::DialogoAdquisicion::Show(bool show)
 
814
{
 
815
        //se recarga la lista de servidores pacs
 
816
        m_pPACSList->DeleteRoot();
 
817
        wxTreeItemId root = m_pPACSList->AddRoot(wxT("Root"));
 
818
        for (DicomServerHolder* sl = DicomServerList::Instance()->GetList(); sl != NULL; sl = sl->next) {
 
819
                wxTreeItemId idItem = m_pPACSList->AppendItem(root, wxString::FromUTF8(sl->server.ID.c_str()));
 
820
                std::ostringstream ostr;
 
821
                ostr << sl->server.AET << "@" << sl->server.HostName << ":" << sl->server.Port;
 
822
                m_pPACSList->SetItemText(idItem, COL_PACS_DESCRIPTION, wxString::FromUTF8(ostr.str().c_str()));
 
823
                //mode (series or studies)
 
824
                m_pPACSList->SetItemText(idItem, COL_PACS_MODE, (sl->server.retrieveSeries?wxT("Series"):wxT("Studies")));
 
825
        }
 
826
 
 
827
        if(m_pPACSList->GetChildrenCount(root) == 0){
 
828
                m_pPACSList->AppendItem(root, _("There is no PACS server configured"));
 
829
                m_pPACSList->SetColumnWidth(0,220);
 
830
                m_pPACSList->Enable(false);
 
831
                m_pPanelPACS->Enable(false);
 
832
        } else {
 
833
                m_pPACSList->SetColumnWidth(0,80);
 
834
                {
 
835
                        wxConfigBase * config = wxConfigBase::Get();
 
836
                        //se actualiza el fichero de configuracion
 
837
                        config->SetPath(wxT("/GinkgoCore/Adquisicion"));
 
838
                        wxString pacsDefecto;
 
839
                        config->Read(wxT("PACSDefecto"),&pacsDefecto,wxT(""));
 
840
                        wxTreeItemId idItem = m_pPACSList->FindItem(root, pacsDefecto);
 
841
                        if (!idItem.IsOk()) {
 
842
                                wxTreeItemIdValue cookie;
 
843
                                idItem = m_pPACSList->GetFirstChild(root, cookie);
 
844
                                pacsDefecto = m_pPACSList->GetItemText(idItem);
 
845
                        }
 
846
                        m_pPACSList->SelectItem(idItem);
 
847
                        m_SelectedPACS = pacsDefecto;
 
848
                        m_Mode = (m_pPACSList->GetItemText(idItem, COL_PACS_MODE) == wxT("Series"))?TD_SERIES:TD_STUDIES;
 
849
                }
 
850
                m_pPACSList->Enable(true);
 
851
                m_pPanelPACS->Enable(true);
 
852
        }
 
853
 
 
854
        return DialogoAdquisicionBase::Show(show);
 
855
}
 
856
 
 
857
 
 
858
 
 
859
//---------------------------------------------------------------------------
 
860
//region Eventos de interfaz
 
861
void GNC::GUI::DialogoAdquisicion::OnPACSChanged(wxTreeEvent & event)
 
862
{
 
863
        wxTreeItemId item = event.GetItem();
 
864
        if (item.IsOk()) {
 
865
                wxString newSelection = m_pPACSList->GetItemText(event.GetItem());
 
866
                if (m_SelectedPACS != newSelection) {
 
867
                        m_SelectedPACS = newSelection;
 
868
                        //se guarda la opcion seleccionada
 
869
                        wxConfigBase * config = wxConfigBase::Get();
 
870
                        //se actualiza el fichero de configuracion
 
871
                        config->SetPath(wxT("/GinkgoCore/Adquisicion"));
 
872
 
 
873
                        config->Write(wxT("PACSDefecto"), m_SelectedPACS);
 
874
 
 
875
                        if(m_pComandoPACS != NULL)
 
876
                        {
 
877
                                GNC::Entorno::Instance()->GetControladorComandos()->AbortarComando(m_pComandoPACS, false);
 
878
                        }
 
879
                        m_pModeloDicom = GnkPtr<IModeloDicom>(new IModeloDicom());
 
880
                        {
 
881
                                //GNC::GCS::ILocker locker(m_TreeListResultadosLocker);
 
882
                                this->m_pTreeListResultados->DeleteRoot();
 
883
                                m_AutoAddSeries = false;
 
884
                                m_Mode = (m_pPACSList->GetItemText(item, COL_PACS_MODE) == wxT("Series"))?TD_SERIES:TD_STUDIES;
 
885
                        }
 
886
                }
 
887
        }
 
888
}
 
889
 
 
890
void GNC::GUI::DialogoAdquisicion::OnKeyDownFormulario( wxKeyEvent& event )
 
891
{
 
892
        if(event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) {
 
893
                wxCommandEvent evt;
 
894
                if (m_pTextControlField->IsEnabled()) {
 
895
                        OnBusquedaClick(evt);
 
896
                }
 
897
                event.Skip(false);
 
898
        }
 
899
        else {
 
900
                if(event.GetKeyCode() == WXK_ESCAPE) {
 
901
                        this->Hide();
 
902
                        event.Skip(false);
 
903
                }
 
904
        }
 
905
        event.Skip(true);
 
906
}
 
907
 
 
908
 
 
909
void GNC::GUI::DialogoAdquisicion::OnFechaDesdeDateChanged( wxDateEvent& /*event*/ )
 
910
{
 
911
        m_pBetween->SetValue(true);
 
912
}
 
913
 
 
914
 
 
915
 
 
916
void GNC::GUI::DialogoAdquisicion::OnFechaHastaDateChanged( wxDateEvent& /*event*/ )
 
917
{
 
918
        m_pBetween->SetValue(true);
 
919
}
 
920
 
 
921
void GNC::GUI::DialogoAdquisicion::OnCancelClick( wxCommandEvent&  )
 
922
{
 
923
        if (m_AutoAddSeries)  {
 
924
                m_AutoAddSeries = false;
 
925
                m_AutoAddSeriesItem = NULL;
 
926
        }
 
927
 
 
928
        if(m_pComandoPACS != NULL)
 
929
        {
 
930
                m_pTextControlField->ShowCancelButton(false);
 
931
                ShowAnimation(false);
 
932
                GNC::Entorno::Instance()->GetControladorComandos()->AbortarComando(m_pComandoPACS, false);
 
933
                m_pComandoPACS = NULL;
 
934
 
 
935
                //GNC::GCS::ILocker locker(m_TreeListResultadosLocker);
 
936
                if(m_lastExpanded.IsOk()) {
 
937
                        m_pTreeListResultados->Collapse(m_lastExpanded);
 
938
                } else {
 
939
                        LimpiarBusquedas(false);
 
940
                }
 
941
        }
 
942
}
 
943
 
 
944
void GNC::GUI::DialogoAdquisicion::OnBusquedaClick( wxCommandEvent&  )
 
945
{
 
946
 
 
947
        if (m_AutoAddSeries)  {
 
948
                m_AutoAddSeries = false;
 
949
                m_AutoAddSeriesItem = NULL;
 
950
        }
 
951
 
 
952
        if(m_pComandoPACS != NULL)
 
953
        {
 
954
                m_pTextControlField->ShowCancelButton(false);
 
955
                ShowAnimation(false);
 
956
                GNC::Entorno::Instance()->GetControladorComandos()->AbortarComando(m_pComandoPACS, false);
 
957
                m_pComandoPACS = NULL;
 
958
 
 
959
                //GNC::GCS::ILocker locker(m_TreeListResultadosLocker);
 
960
                if(m_lastExpanded.IsOk()) {
 
961
                        m_pTreeListResultados->Collapse(m_lastExpanded);
 
962
                } else {
 
963
                        LimpiarBusquedas(false);
 
964
                }
 
965
        }
 
966
 
 
967
        std::string server = GetServerSeleccionado();
 
968
        m_pModeloDicom = GnkPtr<IModeloDicom>(new IModeloDicom());
 
969
        if(server=="")
 
970
                return;
 
971
 
 
972
        std::string fechaDesde("");
 
973
        std::string fechaHasta("");
 
974
        std::string timeFrom("");
 
975
        std::string timeTo("");
 
976
        if (m_pBetween->GetValue()){
 
977
                if(m_pTextControlFechaDesde->GetValue().IsValid()){
 
978
                        fechaDesde =  std::string(m_pTextControlFechaDesde->GetValue().Format(wxT("%Y/%m/%d")).ToUTF8());
 
979
                }
 
980
                if(m_pTextControlFechaHasta->GetValue().IsValid()){
 
981
                        fechaHasta =  std::string(m_pTextControlFechaHasta->GetValue().Format(wxT("%Y/%m/%d")).ToUTF8());
 
982
                }
 
983
        } else if (m_pToday->GetValue() || m_pTodayAM->GetValue() || m_pTodayPM->GetValue()) {
 
984
                fechaDesde = fechaHasta = wxDateTime::Now().Format(wxT("%Y/%m/%d")).ToUTF8();
 
985
                if (m_pTodayAM->GetValue()) {
 
986
                        timeFrom = "000000";
 
987
                        timeTo = "115959";
 
988
                } else if (m_pTodayPM->GetValue()) {
 
989
                        timeFrom = "120000";
 
990
                        timeTo = "235959";
 
991
                }
 
992
        } else if (m_pYesterday->GetValue()) {
 
993
                fechaHasta = fechaDesde = wxDateTime::Now().Add(wxDateSpan(0,0,0,-1)).Format(wxT("%Y/%m/%d")).ToUTF8();
 
994
        } else if (m_pLastWeek->GetValue()) {
 
995
                fechaDesde = wxDateTime::Now().Add(wxDateSpan(0,0,-1,0)).Format(wxT("%Y/%m/%d")).ToUTF8();
 
996
        } else if (m_pLastMonth->GetValue()) {
 
997
                fechaDesde = wxDateTime::Now().Add(wxDateSpan(0,-1,0,0)).Format(wxT("%Y/%m/%d")).ToUTF8();
 
998
        } else if (m_pLastThreeMonths->GetValue()) {
 
999
                fechaDesde = wxDateTime::Now().Add(wxDateSpan(0,-3,0,0)).Format(wxT("%Y/%m/%d")).ToUTF8();
 
1000
        }
 
1001
 
 
1002
        if(fechaDesde == "" && fechaHasta == "" && m_pTextControlField->GetValue().size() == 0
 
1003
                && (m_HardCodedPatientSearch && m_HardCodedPatientId.size() == 0) )
 
1004
        {
 
1005
                int answer = wxMessageBox(_("Search without parameters could take al long time\nWould you like to continue?"),_("Search"), wxYES_NO , this);
 
1006
                if (answer == wxNO) {
 
1007
                        return;
 
1008
                }
 
1009
        }
 
1010
 
 
1011
        std::string idPaciente, nombrePaciente, studyUID, accNumber;
 
1012
 
 
1013
        if (m_HardCodedPatientSearch) {
 
1014
                idPaciente = m_HardCodedPatientId;
 
1015
                nombrePaciente = "";
 
1016
        }
 
1017
 
 
1018
        if (m_pFieldCombo->GetValue() == _("Id")) {
 
1019
                idPaciente = m_pTextControlField->GetValue().ToUTF8();
 
1020
        } else if (m_pFieldCombo->GetValue() == _("Name")) {
 
1021
                nombrePaciente = m_pTextControlField->GetValue().ToUTF8();
 
1022
        } else if (m_pFieldCombo->GetValue() == _("Acc#")) {
 
1023
                accNumber = m_pTextControlField->GetValue().ToUTF8();
 
1024
        } else if (m_pFieldCombo->GetValue() == _("Study UID")) {
 
1025
                studyUID = m_pTextControlField->GetValue().ToUTF8();
 
1026
        }
 
1027
 
 
1028
        //modalities checked
 
1029
 
 
1030
 
 
1031
        GADAPI::ComandoPACSParams * pParams = new GADAPI::ComandoPACSParams(
 
1032
                idPaciente,
 
1033
                nombrePaciente,
 
1034
                studyUID,
 
1035
                accNumber,
 
1036
                GetModalities(),
 
1037
                fechaDesde,fechaHasta,
 
1038
                timeFrom, timeTo,
 
1039
                server, GADAPI::ComandoPACSParams::TA_Estudio, m_pModeloDicom, this); // Buscamos los estudios del paciente
 
1040
 
 
1041
        m_pComandoPACS = new GADAPI::ComandoPACS(pParams);
 
1042
        GNC::Entorno::Instance()->GetControladorComandos()->ProcessAsync(_Std("Exploring PACS..."),m_pComandoPACS, this);
 
1043
        m_pTextControlField->ShowCancelButton(true);
 
1044
        ShowAnimation(true);
 
1045
}
 
1046
 
 
1047
std::string GNC::GUI::DialogoAdquisicion::GetModalities()
 
1048
{
 
1049
        std::string modalities;
 
1050
        bool all = true;
 
1051
 
 
1052
        for (TModalitiesVector::iterator it =m_modalitiesList.begin(); it !=m_modalitiesList.end(); it++) {
 
1053
                wxCheckBox* pCheck = dynamic_cast<wxCheckBox*>(*it);
 
1054
                if(pCheck != NULL)
 
1055
                        if(pCheck->IsChecked()){
 
1056
                                all = false;
 
1057
                                if (modalities == ""){
 
1058
                                        modalities = pCheck->GetLabel().ToUTF8();
 
1059
                                }
 
1060
                                else{
 
1061
                                        modalities.append("\\");
 
1062
                                        modalities.append(pCheck->GetLabel().ToUTF8());
 
1063
                                }
 
1064
                        }
 
1065
        }
 
1066
        if (all) {
 
1067
                modalities = "*";
 
1068
        }
 
1069
        return modalities;
 
1070
}
 
1071
 
 
1072
void GNC::GUI::DialogoAdquisicion::OnLimpiarClick( wxCommandEvent& /*event*/ )
 
1073
{
 
1074
        LimpiarBusquedas();
 
1075
}
 
1076
 
 
1077
void GNC::GUI::DialogoAdquisicion::OnIniciarPararTasksClick( wxCommandEvent& /*event*/ )
 
1078
{
 
1079
        int action = 0;
 
1080
 
 
1081
        m_pGridDescargas->BeginBatch();
 
1082
        for ( int i = 0; i < m_pGridDescargas->GetNumberRows(); i++ )
 
1083
        {
 
1084
                if ( m_pGridDescargas->IsInSelection( i , 0 ) )
 
1085
                {
 
1086
                        // Esto puede ser una fuente de problemas: OJO
 
1087
                        const Descargas::Descarga* d = m_pDescargasGridTable->GetDescarga(i);
 
1088
                        switch (d->StatusId) {
 
1089
case Descargas::Iniciada:
 
1090
        if (action == 0 ||action == 1) { // Para asegurar que solo se hace una operacion:
 
1091
                m_pDescargasGridTable->DetenerDescarga(i);
 
1092
                action = 1;
 
1093
        }
 
1094
        else {
 
1095
                std::cerr << "Error en la logica de control de tareas de descarga" << std::endl;
 
1096
        }
 
1097
        break;
 
1098
case Descargas::Parada:
 
1099
        if (action == 0 || action == 2) { // Para asegurar que solo se hace una operacion:
 
1100
                m_pDescargasGridTable->IniciarDescarga(i);
 
1101
                action = 2;
 
1102
        }
 
1103
        else {
 
1104
                std::cerr << "Error en la logica de control de tareas de descarga" << std::endl;
 
1105
        }
 
1106
        break;
 
1107
case Descargas::Terminada:
 
1108
        break;
 
1109
case Descargas::Erronea:
 
1110
        break;
 
1111
default:
 
1112
        std::cerr << "Error en la logica de control de tareas de descarga" << std::endl;
 
1113
        break;
 
1114
                        }
 
1115
 
 
1116
                }
 
1117
        }
 
1118
 
 
1119
        if (action == 1) { // Hemos detenido descargas iniciadas
 
1120
                m_pBotonIniciarPararTask->SetLabel(_("Start"));
 
1121
                m_pBotonDeleteTask->Enable(true);
 
1122
        }
 
1123
        else if (action == 2) { // Hemos iniciado descargas paradas
 
1124
                m_pBotonIniciarPararTask->SetLabel(_("Stop"));
 
1125
                m_pBotonDeleteTask->Enable(false);
 
1126
        }
 
1127
        m_pGridDescargas->EndBatch();
 
1128
}
 
1129
 
 
1130
void GNC::GUI::DialogoAdquisicion::OnDeleteTasksClick( wxCommandEvent& /*event*/ )
 
1131
{
 
1132
 
 
1133
        if ( m_pGridDescargas->IsSelection() )
 
1134
        {
 
1135
                int lastDeleted = -1;
 
1136
                int deletedCount = 0;
 
1137
                m_pGridDescargas->BeginBatch();
 
1138
                for ( int i = 0; i < m_pGridDescargas->GetNumberRows(); )
 
1139
                {
 
1140
                        if ( m_pGridDescargas->IsInSelection( i , 0 ) ) {
 
1141
                                m_pGridDescargas->DeleteRows( i, 1 );
 
1142
                                lastDeleted = i;
 
1143
                                ++deletedCount;
 
1144
                        } else
 
1145
                                i++;
 
1146
                }
 
1147
                m_pGridDescargas->EndBatch();
 
1148
                //cuando elimino selecciono la fila anterior
 
1149
                if (lastDeleted != -1) {
 
1150
                        lastDeleted = lastDeleted - deletedCount;
 
1151
                        if ( lastDeleted < 0 && m_pGridDescargas->GetNumberRows() > 0 ) {
 
1152
                                m_pGridDescargas->SelectRow(0);
 
1153
                        } else {
 
1154
                                if ( lastDeleted < m_pGridDescargas->GetNumberRows() ) {
 
1155
                                        m_pGridDescargas->SelectRow(lastDeleted);
 
1156
                                }
 
1157
                        }
 
1158
                }
 
1159
        }
 
1160
}
 
1161
 
 
1162
void GNC::GUI::DialogoAdquisicion::OnOpenTasksClick( wxCommandEvent& /*event*/ )
 
1163
{
 
1164
        if ( m_pGridDescargas->IsSelection() )
 
1165
        {
 
1166
                m_pGridDescargas->BeginBatch();
 
1167
                typedef std::list<const Descargas::Descarga*> TListaDescargas;
 
1168
                TListaDescargas listaAbrir;
 
1169
 
 
1170
                for ( int i = 0; i < m_pGridDescargas->GetNumberRows();++i )
 
1171
                {
 
1172
                        if ( m_pGridDescargas->IsInSelection( i , 0 ) ) {
 
1173
                                const Descargas::Descarga* d = m_pDescargasGridTable->GetDescarga(i);
 
1174
                                if (d->StatusId == Descargas::Terminada) {
 
1175
                                        listaAbrir.push_back(d);
 
1176
                                }
 
1177
                        }
 
1178
                }
 
1179
                //se comprueba que todas las series seleccionadas existen...
 
1180
                GNC::GCS::Eventos::EvtHandleDicom::ListaUIDs listaUIdsAbrir;
 
1181
                TListaDescargas listaNoExisten;
 
1182
                TListaDescargas listaAbrirDiagnosticos;
 
1183
 
 
1184
                for (TListaDescargas::iterator it = listaAbrir.begin(); it != listaAbrir.end();++it) {
 
1185
                        if ( ! GNC::GCS::ControladorHistorial::Instance()->ExisteSerie((*it)->UID) ) {
 
1186
                                listaNoExisten.push_back((*it));
 
1187
                        } else if ( (*it)->Modality == "SR" ) {
 
1188
                                listaAbrirDiagnosticos.push_back((*it));
 
1189
                        } else {
 
1190
                                listaUIdsAbrir.push_back((*it)->UID);
 
1191
                        }
 
1192
                }
 
1193
 
 
1194
                //uids que no existen en el historial
 
1195
                if (listaNoExisten.size() > 0) {
 
1196
                        DialogoNotFoundBase dlg(this);
 
1197
                        for ( TListaDescargas::iterator it = listaNoExisten.begin(); it != listaNoExisten.end(); ++it) {
 
1198
                                std::ostringstream ostr;
 
1199
                                if ((*it)->Description != "") {
 
1200
                                        ostr << (*it)->Description;
 
1201
                                } else {
 
1202
                                        ostr << (*it)->Modality << " (" << (*it)->UID << ")";
 
1203
                                }
 
1204
 
 
1205
                                dlg.m_pListaSeries->Append( wxString::FromUTF8(ostr.str().c_str()) );
 
1206
                        }
 
1207
 
 
1208
                        if (listaUIdsAbrir.size() > 0) {
 
1209
                                dlg.m_pPanelOk->Show(false);
 
1210
                        } else {
 
1211
                                dlg.m_pPanelOkCancel->Show(false);
 
1212
                        }
 
1213
 
 
1214
                        int answer = dlg.ShowModal();
 
1215
                        if (answer == wxID_CANCEL) {
 
1216
                                return;
 
1217
                        }
 
1218
                }
 
1219
 
 
1220
                //diagnosticos que se quieren abrir
 
1221
                if (listaAbrirDiagnosticos.size() > 0) {
 
1222
                        wxMessageBox(_("Diagnostic files can't be opened, you have to open the diagnosed series"), _("Info"),
 
1223
                                wxOK | wxICON_INFORMATION, this);
 
1224
                }
 
1225
 
 
1226
                if(listaUIdsAbrir.size() > 0) {
 
1227
                        GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Eventos::EvtHandleDicom(listaUIdsAbrir, GNC::GCS::Eventos::EvtHandleDicom::OpenSeries));
 
1228
                }
 
1229
                m_pGridDescargas->EndBatch();
 
1230
        }
 
1231
}
 
1232
 
 
1233
void GNC::GUI::DialogoAdquisicion::OnClearTasksClick( wxCommandEvent& /*event*/ )
 
1234
{
 
1235
        m_pGridDescargas->BeginBatch();
 
1236
        for ( int i = 0; i < m_pGridDescargas->GetNumberRows(); )
 
1237
        {
 
1238
                const Descargas::Descarga* d = m_pDescargasGridTable->GetDescarga(i);
 
1239
                if ( d->StatusId == Descargas::Terminada  || d->StatusId == Descargas::Erronea ) {
 
1240
                        m_pGridDescargas->DeleteRows( i, 1 );
 
1241
                } else
 
1242
                        i++;
 
1243
        }
 
1244
        m_pGridDescargas->EndBatch();
 
1245
}
 
1246
 
 
1247
void GNC::GUI::DialogoAdquisicion::OnCloseClick( wxCommandEvent& /*event*/ )
 
1248
{
 
1249
        Hide();
 
1250
}
 
1251
 
 
1252
void GNC::GUI::DialogoAdquisicion::OnDescargarClick( wxCommandEvent& /*event*/ )
 
1253
{
 
1254
        AddDescarga(true);
 
1255
}
 
1256
 
 
1257
// Eventos del Treelist
 
1258
void GNC::GUI::DialogoAdquisicion::OnTreeSelChanged(wxTreeEvent& event)
 
1259
{
 
1260
 
 
1261
        wxTreeItemId item = event.GetItem();
 
1262
        if(item.IsOk()){
 
1263
                wxTreeItemId idPadre = m_pTreeListResultados->GetItemParent(item);
 
1264
                m_pBDescargar->Enable(idPadre != m_pTreeListResultados->GetRootItem()); // El item es un estudio o una serie
 
1265
        } else {
 
1266
                m_pBDescargar->Enable(false);
 
1267
        }
 
1268
 
 
1269
        event.Skip(true);
 
1270
 
 
1271
}
 
1272
 
 
1273
void GNC::GUI::DialogoAdquisicion::OnTreeItemActivated(wxTreeEvent& event)
 
1274
{
 
1275
 
 
1276
        AddDescarga(false);
 
1277
 
 
1278
        event.Skip(true);
 
1279
 
 
1280
}
 
1281
 
 
1282
void GNC::GUI::DialogoAdquisicion::OnTreeItemMenu(wxTreeEvent& event)
 
1283
{
 
1284
        //clase menu contextual
 
1285
        class PopUpMenuDescargar: public wxMenu
 
1286
        {
 
1287
        public:
 
1288
                PopUpMenuDescargar(DialogoAdquisicion* pDlg, bool allowDownload) : wxMenu()
 
1289
                {
 
1290
                        m_pDlg = pDlg;
 
1291
                        if (allowDownload) {
 
1292
                                wxMenuItem* descargar = new wxMenuItem( this,wxID_ANY,_("Download"));
 
1293
#ifdef __WXMSW__
 
1294
                                descargar->SetBitmaps(GinkgoResourcesManager::Adquisicion::GetIcoDownload());
 
1295
#else
 
1296
                                descargar->SetBitmap(GinkgoResourcesManager::Adquisicion::GetIcoDownload());
 
1297
#endif
 
1298
                                Append(descargar);
 
1299
                                this->AppendSeparator();
 
1300
 
 
1301
                                Connect(descargar->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuDescargar::OnDescargar ), NULL, this);
 
1302
                        }
 
1303
                        wxMenuItem* props = new wxMenuItem( this, wxID_ANY, _("Properties..."));
 
1304
                        Append(props);
 
1305
                        Connect(props->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuDescargar::OnProperties ),NULL, this);
 
1306
 
 
1307
                }
 
1308
                ~PopUpMenuDescargar()
 
1309
                {
 
1310
                        m_pDlg = NULL;
 
1311
                        Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuDescargar::OnDescargar ), NULL, this);
 
1312
                        Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuDescargar::OnProperties ), NULL, this);
 
1313
                }
 
1314
 
 
1315
                void OnDescargar(wxCommandEvent& )
 
1316
                {
 
1317
                        if (m_pDlg) {
 
1318
                                m_pDlg->AddDescarga(true);
 
1319
                        }
 
1320
                }
 
1321
 
 
1322
                void OnProperties(wxCommandEvent& )
 
1323
                {
 
1324
                        if (m_pDlg) {
 
1325
                                m_pDlg->ShowProperties();
 
1326
                        }
 
1327
                }
 
1328
 
 
1329
                DialogoAdquisicion* m_pDlg;
 
1330
 
 
1331
        };
 
1332
        //
 
1333
        wxTreeItemId item = event.GetItem();
 
1334
        if(item.IsOk()){
 
1335
                wxTreeItemId idPadre = m_pTreeListResultados->GetItemParent(item);
 
1336
                if(idPadre != m_pTreeListResultados->GetRootItem() ){ // El item es un estudio o una serie
 
1337
                        wxTreeItemId idAbuelo = m_pTreeListResultados->GetItemParent(m_pTreeListResultados->GetItemParent(item));
 
1338
                        // Comprobamos que el item es un estudio o es una serie desplegada.
 
1339
                        if ( ( idAbuelo == m_pTreeListResultados->GetRootItem() ) || ! ( (m_pTreeListResultados->GetItemText(item, COLUMNA_UID)).empty() ) ) {
 
1340
 
 
1341
                                PopUpMenuDescargar* pMenu = new PopUpMenuDescargar(this, true);
 
1342
 
 
1343
                                m_pTreeListResultados->PopupMenu(pMenu);
 
1344
 
 
1345
                                delete pMenu;
 
1346
                        }
 
1347
                }
 
1348
                else {
 
1349
                        PopUpMenuDescargar* pMenu = new PopUpMenuDescargar(this, false);
 
1350
 
 
1351
                        m_pTreeListResultados->PopupMenu(pMenu);
 
1352
 
 
1353
                        delete pMenu;
 
1354
                }
 
1355
        }
 
1356
}
 
1357
 
 
1358
void GNC::GUI::DialogoAdquisicion::OnTreeItemExpanded(wxTreeEvent& event)
 
1359
{
 
1360
        {
 
1361
                //GNC::GCS::ILocker locker(m_TreeListResultadosLocker);
 
1362
                wxTreeItemId item = event.GetItem();
 
1363
 
 
1364
                if (m_AutoAddSeries && (m_AutoAddSeriesItem != item) )  {
 
1365
                        m_AutoAddSeries = false;
 
1366
                        m_AutoAddSeriesItem = NULL;
 
1367
                }
 
1368
 
 
1369
                if(item && item.IsOk()){
 
1370
                        m_pTreeListResultados->SortChildren(item);
 
1371
                        //si el abuelo del item es root => consultar
 
1372
                        if(m_pTreeListResultados->IsExpanded(item) && m_pTreeListResultados->GetItemParent(m_pTreeListResultados->GetItemParent(item)) == m_pTreeListResultados->GetRootItem())
 
1373
                        {
 
1374
                                //se cancela el anterior comando y se contrae el item expandido
 
1375
                                if(m_pComandoPACS != NULL)
 
1376
                                {
 
1377
                                        GNC::Entorno::Instance()->GetControladorComandos()->AbortarComando(m_pComandoPACS, false);
 
1378
                                        m_pComandoPACS = NULL;
 
1379
                                        if(m_lastExpanded.IsOk()) {
 
1380
                                                m_pTreeListResultados->Collapse(m_lastExpanded);
 
1381
                                        }
 
1382
                                }
 
1383
 
 
1384
                                std::string server=GetServerSeleccionado();
 
1385
                                if(server=="")
 
1386
                                        return;
 
1387
 
 
1388
                                GADAPI::ComandoPACSParams * pParams = new GADAPI::ComandoPACSParams(
 
1389
                                        "",
 
1390
                                        "",
 
1391
                                        std::string(m_pTreeListResultados->GetItemText(item,COLUMNA_UID).ToUTF8()),
 
1392
                                        "",
 
1393
                                        GetModalities(),
 
1394
                                        "",
 
1395
                                        "",
 
1396
                                        "",
 
1397
                                        "",server, GADAPI::ComandoPACSParams::TA_Serie, m_pModeloDicom, this);
 
1398
 
 
1399
                                m_pComandoPACS = new GADAPI::ComandoPACS(pParams);
 
1400
                                GNC::Entorno::Instance()->GetControladorComandos()->ProcessAsync(_Std("Exploring PACS..."),m_pComandoPACS, this);
 
1401
                                m_pTextControlField->ShowCancelButton(true);
 
1402
                                ShowAnimation(true);
 
1403
                                m_lastExpanded = item;
 
1404
                        }
 
1405
                        event.Skip(false);
 
1406
                } else {
 
1407
                        event.Skip(true);
 
1408
                }
 
1409
        }
 
1410
 
 
1411
}
 
1412
 
 
1413
void GNC::GUI::DialogoAdquisicion::OnTreeBeginDrag(wxTreeEvent& )
 
1414
{
 
1415
        wxTreeItemId seleccion = m_pTreeListResultados->GetSelection();
 
1416
        if(seleccion.IsOk()){
 
1417
                if(m_pTreeListResultados->GetItemParent(seleccion) == m_pTreeListResultados->GetRootItem()){
 
1418
                        //esto es para que de la impresion de que no podemos arrastrar la raiz
 
1419
                        class wxFooDataObject: public wxDataObjectSimple
 
1420
                        {
 
1421
                        public:
 
1422
                                wxFooDataObject():wxDataObjectSimple() {}
 
1423
                                ~wxFooDataObject() {}
 
1424
                        };
 
1425
                        wxFooDataObject myData;
 
1426
                        wxDropSource dragSource(myData,this);
 
1427
                        dragSource.DoDragDrop(wxDrag_AllowMove);
 
1428
                }else {
 
1429
                        //comenzamos drag & drop
 
1430
                        wxTextDataObject myData(wxT(""));
 
1431
                        wxDropSource dragSource(myData,this);
 
1432
                        wxDragResult result = dragSource.DoDragDrop(wxDrag_AllowMove);
 
1433
                        if (result == wxDragCopy) {
 
1434
                                AddDescarga(true);
 
1435
                        }
 
1436
                }
 
1437
        }
 
1438
}
 
1439
 
 
1440
void GNC::GUI::DialogoAdquisicion::UpdateButtons()
 
1441
{
 
1442
        int total = 0;
 
1443
        int iniciadas = 0;
 
1444
        int paradas = 0;
 
1445
        int terminadas = 0;
 
1446
 
 
1447
        m_pGridDescargas->BeginBatch();
 
1448
        for ( int i = 0; i < m_pGridDescargas->GetNumberRows(); i++)
 
1449
        {
 
1450
                if ( m_pGridDescargas->IsInSelection( i , 0 ) ) {
 
1451
                        const Descargas::Descarga* d = m_pDescargasGridTable->GetDescarga(i);
 
1452
                        switch( d->StatusId ) {
 
1453
case Descargas::Parada:
 
1454
        paradas++;
 
1455
        total++;
 
1456
        break;
 
1457
case Descargas::Iniciada:
 
1458
        iniciadas++;
 
1459
        total++;
 
1460
        break;
 
1461
case Descargas::Terminada:
 
1462
        terminadas++;
 
1463
        total++;
 
1464
case Descargas::Erronea:
 
1465
        terminadas++;
 
1466
        total++;
 
1467
        break;
 
1468
                        }
 
1469
                }
 
1470
        }
 
1471
        m_pGridDescargas->EndBatch();
 
1472
 
 
1473
        if (total == 0) {
 
1474
                m_pBotonIniciarPararTask->Enable(false);
 
1475
                m_pBotonIniciarPararTask->SetLabel(_("Start"));
 
1476
                m_pBotonOpenTask->Enable(false);
 
1477
                m_pBotonDeleteTask->Enable(false);
 
1478
                return;
 
1479
        }
 
1480
 
 
1481
        m_pBotonDeleteTask->Enable( (total == terminadas) || (total == (terminadas + paradas)) );
 
1482
        if (total == terminadas){
 
1483
                m_pBotonIniciarPararTask->Enable(false);
 
1484
                m_pBotonIniciarPararTask->SetLabel(_("Start"));
 
1485
                m_pBotonDeleteTask->Enable(true);
 
1486
        }
 
1487
        else if ( total == iniciadas) {
 
1488
                m_pBotonIniciarPararTask->Enable(true);
 
1489
                m_pBotonIniciarPararTask->SetLabel(_("Stop"));
 
1490
                m_pBotonDeleteTask->Enable(false);
 
1491
        }
 
1492
        else if ( total == (paradas + terminadas ) ) {
 
1493
                m_pBotonIniciarPararTask->Enable(true);
 
1494
                m_pBotonIniciarPararTask->SetLabel(_("Start"));
 
1495
                m_pBotonDeleteTask->Enable(true);
 
1496
        }
 
1497
        else if (total == paradas) {
 
1498
                m_pBotonIniciarPararTask->Enable(true);
 
1499
                m_pBotonIniciarPararTask->SetLabel(_("Start"));
 
1500
                m_pBotonDeleteTask->Enable(true);
 
1501
        }
 
1502
        else {
 
1503
                m_pBotonIniciarPararTask->Enable(false);
 
1504
                m_pBotonIniciarPararTask->SetLabel(_("Start"));
 
1505
                m_pBotonDeleteTask->Enable(false);
 
1506
        }
 
1507
 
 
1508
        m_pBotonOpenTask->Enable( total == terminadas);
 
1509
}
 
1510
 
 
1511
 
 
1512
void GNC::GUI::DialogoAdquisicion::OnGridSelect(wxGridRangeSelectEvent& event)
 
1513
{
 
1514
        UpdateButtons();
 
1515
 
 
1516
        event.Skip();
 
1517
}
 
1518
 
 
1519
void GNC::GUI::DialogoAdquisicion::OnGridKeyDown(wxKeyEvent& event)
 
1520
{
 
1521
        switch (event.GetKeyCode())
 
1522
        {
 
1523
        case WXK_DELETE:
 
1524
                {
 
1525
                        if ( m_pBotonDeleteTask->IsEnabled() ) {
 
1526
                                wxCommandEvent evt;
 
1527
                                OnDeleteTasksClick(evt);
 
1528
                        }
 
1529
                        event.Skip(false);
 
1530
                }
 
1531
                break;
 
1532
        case WXK_NUMPAD_ENTER:
 
1533
        case WXK_RETURN:
 
1534
                {
 
1535
                        if ( m_pBotonOpenTask->IsEnabled() ) {
 
1536
                                wxCommandEvent evt;
 
1537
                                OnOpenTasksClick(evt);
 
1538
                        }
 
1539
                        event.Skip(false);
 
1540
                }
 
1541
                break;
 
1542
        default:
 
1543
                event.Skip(true);
 
1544
        }
 
1545
}
 
1546
 
 
1547
void GNC::GUI::DialogoAdquisicion::OnGridDClick(wxGridEvent& event)
 
1548
{
 
1549
        if ( m_pBotonOpenTask->IsEnabled() ) {
 
1550
                wxCommandEvent evt;
 
1551
                OnOpenTasksClick(evt);
 
1552
        }
 
1553
        event.Skip();
 
1554
}
 
1555
 
 
1556
void GNC::GUI::DialogoAdquisicion::OnGridMenu(wxGridEvent& )
 
1557
{
 
1558
        //clase menu contextual
 
1559
        class PopUpMenuListaDescargas: public wxMenu
 
1560
        {
 
1561
        public:
 
1562
                PopUpMenuListaDescargas(DialogoAdquisicion* pDlg) : wxMenu()
 
1563
                {
 
1564
                        m_pDlg = pDlg;
 
1565
 
 
1566
                        if (m_pDlg->m_pBotonOpenTask->IsEnabled()) {
 
1567
                                wxMenuItem* menuItem = new wxMenuItem( this,wxID_ANY,m_pDlg->m_pBotonOpenTask->GetLabel());
 
1568
                                Append(menuItem);
 
1569
                                Connect(menuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuListaDescargas::OnOpen ),NULL,this);
 
1570
                                AppendSeparator();
 
1571
                        }
 
1572
 
 
1573
                        if (m_pDlg->m_pBotonIniciarPararTask->IsEnabled()) {
 
1574
                                wxMenuItem* menuItem = new wxMenuItem( this,wxID_ANY,m_pDlg->m_pBotonIniciarPararTask->GetLabel());
 
1575
                                Append(menuItem);
 
1576
                                Connect(menuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuListaDescargas::OnIniciarParar ),NULL,this);
 
1577
                                AppendSeparator();
 
1578
                        }
 
1579
 
 
1580
                        if (m_pDlg->m_pBotonDeleteTask->IsEnabled()) {
 
1581
                                wxMenuItem* menuItem = new wxMenuItem( this,wxID_ANY,m_pDlg->m_pBotonDeleteTask->GetLabel());
 
1582
#ifdef __WXMSW__
 
1583
                                menuItem->SetBitmaps(GinkgoResourcesManager::Adquisicion::GetIcoEliminarDescarga());
 
1584
#else
 
1585
                                menuItem->SetBitmap(GinkgoResourcesManager::Adquisicion::GetIcoEliminarDescarga());
 
1586
#endif
 
1587
                                Append(menuItem);
 
1588
                                Connect(menuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuListaDescargas::OnDelete ),NULL,this);
 
1589
                        }
 
1590
 
 
1591
                        {
 
1592
                                wxMenuItem* menuItem = new wxMenuItem( this,wxID_ANY,_("Clear Finished"));
 
1593
#ifdef __WXMSW__
 
1594
                                menuItem->SetBitmaps(GinkgoResourcesManager::Adquisicion::GetIcoClear());
 
1595
#else
 
1596
                                menuItem->SetBitmap(GinkgoResourcesManager::Adquisicion::GetIcoClear());
 
1597
#endif
 
1598
                                Append(menuItem);
 
1599
                                Connect(menuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuListaDescargas::OnClear ),NULL,this);
 
1600
                        }
 
1601
                }
 
1602
                ~PopUpMenuListaDescargas()
 
1603
                {
 
1604
                        m_pDlg = NULL;
 
1605
                        Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuListaDescargas::OnIniciarParar ),NULL,this);
 
1606
                        Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuListaDescargas::OnDelete ),NULL,this);
 
1607
                        Disconnect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( PopUpMenuListaDescargas::OnOpen ),NULL,this);
 
1608
                }
 
1609
 
 
1610
                void OnIniciarParar(wxCommandEvent& )
 
1611
                {
 
1612
                        wxCommandEvent evt;
 
1613
                        m_pDlg->OnIniciarPararTasksClick(evt);
 
1614
                }
 
1615
 
 
1616
                void OnDelete(wxCommandEvent& )
 
1617
                {
 
1618
                        wxCommandEvent evt;
 
1619
                        m_pDlg->OnDeleteTasksClick(evt);
 
1620
                }
 
1621
 
 
1622
                void OnOpen(wxCommandEvent& )
 
1623
                {
 
1624
                        wxCommandEvent evt;
 
1625
                        m_pDlg->OnOpenTasksClick(evt);
 
1626
                }
 
1627
 
 
1628
                void OnClear(wxCommandEvent& )
 
1629
                {
 
1630
                        wxCommandEvent evt;
 
1631
                        m_pDlg->OnClearTasksClick(evt);
 
1632
                }
 
1633
 
 
1634
                DialogoAdquisicion* m_pDlg;
 
1635
        };
 
1636
        //
 
1637
 
 
1638
        PopUpMenuListaDescargas* pMenu = new PopUpMenuListaDescargas(this);
 
1639
        m_pGridDescargas->PopupMenu(pMenu);
 
1640
        delete pMenu;
 
1641
}
 
1642
 
 
1643
void GNC::GUI::DialogoAdquisicion::OnGridSize( wxSizeEvent& event )
 
1644
{
 
1645
        /*m_pGridDescargas->SetSize(event.GetSize());
 
1646
        AutoSizeGrid();
 
1647
        */
 
1648
        event.Skip();
 
1649
}
 
1650
 
 
1651
//---------------------------------------------------------------------------
 
1652
//region Helpers
 
1653
 
 
1654
void GNC::GUI::DialogoAdquisicion::AutoSizeGrid()
 
1655
{
 
1656
        wxSize s = m_pGridDescargas->GetSize();
 
1657
 
 
1658
        float prop = 1.0f / ( (float)m_pGridDescargas->GetNumberCols() );
 
1659
 
 
1660
        int cw = s.GetWidth() - 10;
 
1661
        int aw = 0;
 
1662
        int i = 0;
 
1663
        for (; i < m_pGridDescargas->GetNumberCols() - 1; i++)
 
1664
        {
 
1665
                int iw = (int) (prop * (float)cw);
 
1666
                aw += iw;
 
1667
                m_pGridDescargas->SetColSize(i,  iw);
 
1668
        }
 
1669
        if ( i < m_pGridDescargas->GetNumberCols()) {
 
1670
                m_pGridDescargas->SetColSize(i, cw - aw );
 
1671
        }
 
1672
 
 
1673
 
 
1674
        m_pGridDescargas->Refresh();
 
1675
 
 
1676
}
 
1677
 
 
1678
std::string GNC::GUI::DialogoAdquisicion::GetServerSeleccionado()
 
1679
{
 
1680
        std::string id;
 
1681
        wxTreeItemId idItem = m_pPACSList->GetSelection();
 
1682
        if (idItem.IsOk()) {
 
1683
                id = std::string(m_pPACSList->GetItemText(idItem).ToUTF8());
 
1684
        } else {
 
1685
                wxMessageBox(_("Select a valid PACS Server"), _("Info"),
 
1686
                        wxOK | wxICON_INFORMATION, this);
 
1687
        }
 
1688
        return id;
 
1689
}
 
1690
 
 
1691
 
 
1692
// Obtiene el item seleccionado del TreeList de resultados, genera una descarga, la apila y la inicia.
 
1693
void GNC::GUI::DialogoAdquisicion::AddDescarga(bool lanzarBusqueda)
 
1694
{
 
1695
        {
 
1696
                //GNC::GCS::ILocker locker(m_TreeListResultadosLocker);
 
1697
                wxTreeItemId seleccion = m_pTreeListResultados->GetSelection();
 
1698
 
 
1699
                if(seleccion.IsOk()){
 
1700
                        if(m_pTreeListResultados->GetItemParent(seleccion) == m_pTreeListResultados->GetRootItem()){
 
1701
                                return;
 
1702
                        } //raiz
 
1703
                        else if(m_pTreeListResultados->GetItemParent(m_pTreeListResultados->GetItemParent(seleccion)) == m_pTreeListResultados->GetRootItem()){
 
1704
                                //studies
 
1705
                                if (m_Mode == TD_STUDIES) {
 
1706
                                        //download study node
 
1707
                                        std::string uidPaciente = std::string(m_pTreeListResultados->GetItemText(m_pTreeListResultados->GetItemParent(seleccion), COLUMNA_UID).ToUTF8());
 
1708
                                        std::string descPaciente = std::string(m_pTreeListResultados->GetItemText(m_pTreeListResultados->GetItemParent(seleccion)).ToUTF8());
 
1709
 
 
1710
                                        std::string uidStudy = std::string(m_pTreeListResultados->GetItemText(seleccion, COLUMNA_UID).ToUTF8());
 
1711
                                        std::string descStudy = std::string( (m_pTreeListResultados->GetItemText(seleccion) + _T("(") + m_pTreeListResultados->GetItemText(seleccion, COLUMNA_MODALIDAD) + _T(")") ).ToUTF8());
 
1712
                                        std::string modStudy =  std::string( m_pTreeListResultados->GetItemText(seleccion, COLUMNA_MODALIDAD ).ToUTF8());
 
1713
 
 
1714
                                        if (!modStudy.empty() && ! GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.download", modStudy)) {
 
1715
                                                LOG_ERROR("GUI/Adquisition", _Std("Download of modality ") << modStudy << _Std(" not allowed"));
 
1716
                                                wxMessageBox(_("You are not allowed to download this kind of modalities."),_("Modality download error"),wxICON_ERROR);
 
1717
                                        } else {
 
1718
                                                bool forceInit = true;
 
1719
                                                if (m_pDescargasGridTable->FindDescarga(uidStudy) != -1) {
 
1720
                                                        forceInit = wxMessageBox(_("Series were already in the download queue.\nDo you want to repeat download?"),_("Download warning"),wxICON_INFORMATION|wxYES_NO) == wxYES;
 
1721
                                                }
 
1722
 
 
1723
                                                bool downloaded = m_pDescargasGridTable->AddDescarga(GetServerSeleccionado(), descPaciente, descStudy, uidStudy,modStudy, forceInit, false);
 
1724
                                                m_pTreeListResultados->SetItemBold(seleccion, downloaded);
 
1725
                                        }
 
1726
 
 
1727
                                } else { 
 
1728
                                        //series mode, we have to search series in study
 
1729
                                        if (lanzarBusqueda) {
 
1730
 
 
1731
                                                //estamos en un estudio
 
1732
                                                std::string uidPaciente = std::string(m_pTreeListResultados->GetItemText(m_pTreeListResultados->GetItemParent(seleccion), COLUMNA_UID).ToUTF8());
 
1733
                                                std::string descPaciente = std::string(m_pTreeListResultados->GetItemText(m_pTreeListResultados->GetItemParent(seleccion)).ToUTF8());
 
1734
 
 
1735
                                                // Necesitamos buscar las series
 
1736
 
 
1737
                                                // Primero comprobamos que no estan ya desplegadas, y asi ahorramos una busqueda en el PACS.
 
1738
                                                wxTreeItemId eid = seleccion;
 
1739
                                                std::string server = GetServerSeleccionado();
 
1740
                                                int numSeriesDescargadas = 0;
 
1741
 
 
1742
                                                std::list<wxTreeItemId> s_items = m_pTreeListResultados->GetPublicChildren(eid);
 
1743
                                                std::set<std::string> listaModalidad;
 
1744
                                                bool forceInit = true;
 
1745
                                                bool questionMade = false;
 
1746
                                                for (std::list<wxTreeItemId>::iterator ititem = s_items.begin(); ititem != s_items.end(); ititem++) {
 
1747
                                                        wxTreeItemId cid = *ititem;
 
1748
 
 
1749
                                                        std::string uidSerie = std::string(m_pTreeListResultados->GetItemText(cid, COLUMNA_UID).ToUTF8());
 
1750
                                                        std::string modalidadSerie = std::string(m_pTreeListResultados->GetItemText(cid, COLUMNA_MODALIDAD).ToUTF8());
 
1751
                                                        if (!uidSerie.empty()) { // La serie esta desplegada
 
1752
                                                                if( GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.download", modalidadSerie) ) {
 
1753
                                                                        if (!questionMade && m_pDescargasGridTable->FindDescarga(uidSerie) != -1) {
 
1754
                                                                                forceInit = wxMessageBox(_("Series were already in the download queue.\nDo you want to force download?"),_("Download warning"),wxICON_INFORMATION|wxYES_NO) == wxYES;
 
1755
                                                                                questionMade = true;
 
1756
                                                                        }
 
1757
 
 
1758
                                                                        std::string descSerie = std::string( (m_pTreeListResultados->GetItemText(cid) + _T("(") + m_pTreeListResultados->GetItemText(cid, COLUMNA_MODALIDAD) + _T(")") ).ToUTF8());
 
1759
                                                                        bool downloaded = m_pDescargasGridTable->AddDescarga(server, descPaciente, descSerie, uidSerie,modalidadSerie,forceInit, true);
 
1760
                                                                        m_pTreeListResultados->SetItemBold(cid, downloaded);
 
1761
                                                                        numSeriesDescargadas++;
 
1762
                                                                } else {
 
1763
                                                                        listaModalidad.insert( modalidadSerie );
 
1764
                                                                }
 
1765
                                                        }
 
1766
                                                }
 
1767
                                                if (numSeriesDescargadas == 0 && listaModalidad.size() == 0)
 
1768
                                                {
 
1769
                                                        // Desplegamos la serie.
 
1770
 
 
1771
                                                        wxTreeItemId item = seleccion;
 
1772
                                                        // >>------- Es un cut&paste del evento OnTreeItemExpanded, pero mejor esto que complicar la interfaz invocandolo directamente (lockers, omision de evento, reset de estado de la auto descarga de series , etc..)
 
1773
                                                        //se cancela el anterior comando y se contrae el item expandido
 
1774
                                                        if(item && item.IsOk()){
 
1775
                                                                //si el abuelo del item es root => consultar
 
1776
                                                                m_AutoAddSeries = true;
 
1777
                                                                m_AutoAddSeriesItem = item;
 
1778
                                                        }
 
1779
 
 
1780
                                                        if(m_pComandoPACS != NULL)
 
1781
                                                        {
 
1782
                                                                GNC::Entorno::Instance()->GetControladorComandos()->AbortarComando(m_pComandoPACS, false);
 
1783
                                                                m_pComandoPACS = NULL;
 
1784
 
 
1785
                                                                if(m_lastExpanded.IsOk()) {
 
1786
                                                                        m_pTreeListResultados->Collapse(m_lastExpanded);
 
1787
                                                                        m_lastExpanded.Unset();
 
1788
                                                                }
 
1789
                                                        }
 
1790
                                                        std::string server=GetServerSeleccionado();
 
1791
 
 
1792
                                                        if(server=="") {
 
1793
                                                                return;
 
1794
                                                        }
 
1795
 
 
1796
                                                        GADAPI::ComandoPACSParams * pParams = new GADAPI::ComandoPACSParams(
 
1797
                                                                "",
 
1798
                                                                "",
 
1799
                                                                std::string(m_pTreeListResultados->GetItemText(item,COLUMNA_UID).ToUTF8()),
 
1800
                                                                "",
 
1801
                                                                GetModalities(),
 
1802
                                                                "",
 
1803
                                                                "",
 
1804
                                                                "",
 
1805
                                                                "",server, GADAPI::ComandoPACSParams::TA_Serie, m_pModeloDicom, this);
 
1806
 
 
1807
                                                        m_pComandoPACS = new GADAPI::ComandoPACS(pParams);
 
1808
                                                        GNC::Entorno::Instance()->GetControladorComandos()->ProcessAsync(_Std("Exploring PACS..."),m_pComandoPACS, this);
 
1809
                                                        m_pTextControlField->ShowCancelButton(true);
 
1810
                                                        ShowAnimation(true);
 
1811
                                                }
 
1812
                                                else if ( listaModalidad.size() > 0)
 
1813
                                                {
 
1814
                                                        std::ostringstream ostr;
 
1815
                                                        ostr << _Std("You are not allowed to download this kind of modalities (");
 
1816
                                                        bool primero = true;
 
1817
                                                        for (std::set<std::string>::iterator it = listaModalidad.begin(); it != listaModalidad.end(); ++it) {
 
1818
                                                                if (primero) {
 
1819
                                                                        ostr << (*it);
 
1820
                                                                        primero = false;
 
1821
                                                                }
 
1822
                                                                else {
 
1823
                                                                        ostr << ", " << (*it);
 
1824
                                                                }
 
1825
                                                        }
 
1826
                                                        ostr << ")";
 
1827
                                                        wxMessageBox(wxString::FromUTF8( ostr.str().c_str() ), _("Modality download error"), wxICON_ERROR);
 
1828
                                                }
 
1829
                                        }//lanzar busqueda
 
1830
                                }//series mode
 
1831
                                //fin estudio
 
1832
                        } else {
 
1833
                                //estamos en una serie
 
1834
                                std::string uidPaciente = std::string(m_pTreeListResultados->GetItemText(m_pTreeListResultados->GetItemParent(m_pTreeListResultados->GetItemParent(seleccion)), COLUMNA_UID).ToUTF8());
 
1835
                                std::string descPaciente = std::string(m_pTreeListResultados->GetItemText(m_pTreeListResultados->GetItemParent(m_pTreeListResultados->GetItemParent(seleccion))).ToUTF8());
 
1836
 
 
1837
                                std::string uidSerie = std::string(m_pTreeListResultados->GetItemText(seleccion, COLUMNA_UID).ToUTF8());
 
1838
                                std::string descSerie = std::string( (m_pTreeListResultados->GetItemText(seleccion) + _T("(") + m_pTreeListResultados->GetItemText(seleccion, COLUMNA_MODALIDAD) + _T(")") ).ToUTF8());
 
1839
                                std::string modSerie =  std::string( m_pTreeListResultados->GetItemText(seleccion, COLUMNA_MODALIDAD ).ToUTF8());
 
1840
 
 
1841
                                if (!modSerie.empty()) {
 
1842
                                        if(! GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.download", modSerie)) {
 
1843
                                                LOG_ERROR("GUI/Adquisition", _Std("Download of modality ") << modSerie << _Std(" not allowed"));
 
1844
                                                wxMessageBox(_("You are not allowed to download this kind of modalities."),_("Modality download error"),wxICON_ERROR);
 
1845
                                        }
 
1846
                                        else {
 
1847
                                                bool forceInit = true;
 
1848
                                                if (m_pDescargasGridTable->FindDescarga(uidSerie) != -1) {
 
1849
                                                        forceInit = wxMessageBox(_("Series were already in the download queue.\nDo you want to force download?"),_("Download warning"),wxICON_INFORMATION|wxYES_NO) == wxYES;
 
1850
                                                }
 
1851
 
 
1852
                                                bool downloaded = m_pDescargasGridTable->AddDescarga(GetServerSeleccionado(), descPaciente, descSerie, uidSerie,modSerie, forceInit, true);
 
1853
                                                m_pTreeListResultados->SetItemBold(seleccion, downloaded);
 
1854
                                        }
 
1855
                                }
 
1856
                        }
 
1857
                }
 
1858
                else {
 
1859
                        return;
 
1860
                }
 
1861
        }
 
1862
}
 
1863
 
 
1864
// Shows a dialog with the properties of selected treelist item
 
1865
void GNC::GUI::DialogoAdquisicion::ShowProperties()
 
1866
{
 
1867
 
 
1868
 
 
1869
        wxTreeItemId selection = m_pTreeListResultados->GetSelection();
 
1870
 
 
1871
        if(selection.IsOk()){
 
1872
                GNC::GUI::wxPropiedades::TListaMapasPropiedades listaMapas;
 
1873
 
 
1874
                wxTreeItemId patientTreeItemId;
 
1875
                wxTreeItemId studyTreeItemId;
 
1876
                wxTreeItemId serieTreeItemId;
 
1877
 
 
1878
                if(m_pTreeListResultados->GetItemParent(selection) == m_pTreeListResultados->GetRootItem()){
 
1879
                        //Patient Level
 
1880
                        patientTreeItemId = selection;
 
1881
                }
 
1882
                else if(m_pTreeListResultados->GetItemParent(m_pTreeListResultados->GetItemParent(selection)) == m_pTreeListResultados->GetRootItem()){
 
1883
                        studyTreeItemId   = selection;
 
1884
                        patientTreeItemId = m_pTreeListResultados->GetItemParent(selection);
 
1885
 
 
1886
                }
 
1887
                else {
 
1888
                        serieTreeItemId   = selection;
 
1889
                        studyTreeItemId   = m_pTreeListResultados->GetItemParent(selection);
 
1890
                        patientTreeItemId = m_pTreeListResultados->GetItemParent(studyTreeItemId);
 
1891
                }
 
1892
 
 
1893
                if (patientTreeItemId.IsOk()) {
 
1894
                        GNC::GUI::wxPropiedades::TMapaPropiedades mapaPropiedades;
 
1895
                        mapaPropiedades[_Std("Patient's Id")]   = std::string(m_pTreeListResultados->GetItemText(patientTreeItemId, COLUMNA_UID).ToUTF8());
 
1896
                        listaMapas.push_back(mapaPropiedades);
 
1897
                }
 
1898
                if (studyTreeItemId.IsOk()) {
 
1899
                        GNC::GUI::wxPropiedades::TMapaPropiedades mapaPropiedades;
 
1900
                        mapaPropiedades[_Std("Study Instance UID")] = std::string(m_pTreeListResultados->GetItemText(studyTreeItemId, COLUMNA_UID).ToUTF8());
 
1901
                        mapaPropiedades[_Std("Accession number")]   = std::string(m_pTreeListResultados->GetItemText(studyTreeItemId, COLUMNA_ACCNUMBER).ToUTF8());
 
1902
                        mapaPropiedades[_Std("Study date")] = std::string(m_pTreeListResultados->GetItemText(studyTreeItemId, COLUMNA_FECHA).ToUTF8());
 
1903
                        listaMapas.push_back(mapaPropiedades);
 
1904
                }
 
1905
                if (serieTreeItemId.IsOk()) {
 
1906
                        GNC::GUI::wxPropiedades::TMapaPropiedades mapaPropiedades;
 
1907
                        mapaPropiedades[_Std("Series Instance UID")] = std::string(m_pTreeListResultados->GetItemText(serieTreeItemId, COLUMNA_UID).ToUTF8());
 
1908
                        mapaPropiedades[_Std("Modality")] = std::string(m_pTreeListResultados->GetItemText(serieTreeItemId, COLUMNA_MODALIDAD).ToUTF8());
 
1909
                        mapaPropiedades[_Std("Series date")] = std::string(m_pTreeListResultados->GetItemText(serieTreeItemId, COLUMNA_FECHA).ToUTF8());
 
1910
 
 
1911
                        listaMapas.push_back(mapaPropiedades);
 
1912
                }
 
1913
 
 
1914
                GNC::GUI::wxPropiedades* pProp = new GNC::GUI::wxPropiedades(this, _Std("Search Results"), listaMapas);
 
1915
                pProp->Show();
 
1916
 
 
1917
        }
 
1918
 
 
1919
}
 
1920
 
 
1921
void GNC::GUI::DialogoAdquisicion::ShowAnimation(bool show)
 
1922
{
 
1923
        m_pAnimation->Show(show);
 
1924
        m_pPanelPACS->Layout();
 
1925
        m_pPanelPACS->Refresh(true);
 
1926
        if (show) {
 
1927
                m_pAnimation->Play();
 
1928
        } else {
 
1929
                m_pAnimation->Stop();
 
1930
        }
 
1931
}
 
1932
 
 
1933
void GNC::GUI::DialogoAdquisicion::LimpiarBusquedas(bool /*lock*/) {
 
1934
 
 
1935
        /*
 
1936
        GNC::GCS::ILocker* pLocker = NULL;
 
1937
        if (lock )
 
1938
        pLocker = new GNC::GCS::ILocker(m_TreeListResultadosLocker);
 
1939
        */
 
1940
 
 
1941
        m_pTreeListResultados->DeleteRoot();
 
1942
        m_pTreeListResultados->AddRoot(wxT("Top"));
 
1943
        m_pModeloDicom = GnkPtr<IModeloDicom>(new IModeloDicom());
 
1944
 
 
1945
        /*
 
1946
        if (pLocker != NULL) {
 
1947
        delete pLocker;
 
1948
        }
 
1949
        */
 
1950
 
 
1951
}
 
1952
 
 
1953
//endregion
 
1954
 
 
1955
 
 
1956
//---------------------------------------------------------------------------
 
1957
//region realizacion de la interfaz IComandoPACSNotificador
 
1958
void GNC::GUI::DialogoAdquisicion::PACSCargarListado(IModeloDicom * pModelo)
 
1959
{
 
1960
        {
 
1961
                //GNC::GCS::ILocker locker(m_TreeListResultadosLocker);
 
1962
                m_pTextControlField->ShowCancelButton(false);
 
1963
                ShowAnimation(false);
 
1964
                if(m_pComandoPACS == NULL)
 
1965
                {
 
1966
                        return;
 
1967
                }
 
1968
 
 
1969
                if (m_pComandoPACS->m_pPACSParams->m_Ambito == GADAPI::ComandoPACSParams::TA_Serie)
 
1970
                {
 
1971
                        wxTreeItemId pacienteTreeId;
 
1972
                        wxTreeItemId estudioTreeId;
 
1973
 
 
1974
                        m_lastExpanded.Unset();
 
1975
                        //actualizar el arbol
 
1976
                        const IModeloEstudio* estudio = NULL;
 
1977
                        pModelo->BuscarEstudio(m_pComandoPACS->m_pPACSParams->m_studyUID,&estudio);
 
1978
 
 
1979
                        m_pComandoPACS = NULL;
 
1980
 
 
1981
                        if (estudio != NULL) {
 
1982
                                std::set<std::string> listaModalidad;
 
1983
                                {//begin freeze/thaw
 
1984
                                        Freeze();
 
1985
                                        Refresh(true);
 
1986
                                        {
 
1987
                                                bool encontrado = false;
 
1988
                                                wxString wxUIDEstudio = wxString::FromUTF8(estudio->GetUID().c_str());
 
1989
 
 
1990
                                                std::list<wxTreeItemId> p_items = m_pTreeListResultados->GetPublicChildren(m_pTreeListResultados->GetRootItem());
 
1991
                                                for (std::list<wxTreeItemId>::iterator ititem = p_items.begin(); ititem != p_items.end() && !encontrado; ititem++) {
 
1992
                                                        pacienteTreeId = *ititem;
 
1993
 
 
1994
                                                        std::list<wxTreeItemId> e_items = m_pTreeListResultados->GetPublicChildren(pacienteTreeId);
 
1995
                                                        for (std::list<wxTreeItemId>::iterator ititem = e_items.begin(); ititem != e_items.end() && !encontrado; ititem++) {
 
1996
                                                                estudioTreeId = *ititem;
 
1997
 
 
1998
                                                                if(m_pTreeListResultados->GetItemText(estudioTreeId,COLUMNA_UID) == wxUIDEstudio) {
 
1999
                                                                        encontrado = true;
 
2000
                                                                        break;
 
2001
                                                                }
 
2002
                                                        }
 
2003
                                                }
 
2004
                                        }
 
2005
 
 
2006
                                        if(estudioTreeId.IsOk() && estudio->ListaSeries().size() > 0) {
 
2007
                                                m_pTreeListResultados->DeleteChildren(estudioTreeId);
 
2008
                                                bool forceInit = true;
 
2009
                                                bool questionMade = false;
 
2010
 
 
2011
                                                for (IModeloEstudio::ListaSeriesType::const_iterator it3 = estudio->ListaSeries().begin(); it3 != estudio->ListaSeries().end(); it3++) {
 
2012
                                                        const IModeloSerie& s = *it3;
 
2013
                                                        wxString uidSerie = wxString::FromUTF8(s.GetUID().c_str());
 
2014
                                                        wxString numeroDeImagenes = wxString::FromUTF8(s.GetNumero().c_str());
 
2015
                                                        wxString tipoSerie = wxString::FromUTF8(s.GetTipo().c_str());
 
2016
                                                        wxString descripcionSerie = wxString::FromUTF8(s.GetDescripcion().c_str());
 
2017
 
 
2018
                                                        wxDateTime fecha;
 
2019
                                                        wxDateTime hora;
 
2020
                                                        hora.ParseFormat( wxString::FromUTF8( (s.GetHora()).c_str() ).GetData(), wxT("%H%M%S"), wxDefaultDateTime);
 
2021
                                                        fecha.ParseFormat( wxString::FromUTF8( (s.GetFecha()).c_str() ).GetData(), wxT("%Y%m%d"), wxDefaultDateTime);
 
2022
 
 
2023
                                                        wxString fechaStr;
 
2024
 
 
2025
                                                        if(fecha.IsValid()){
 
2026
                                                                if (hora.IsValid()) {
 
2027
 
 
2028
                                                                        fecha.SetHour(hora.GetHour());
 
2029
                                                                        fecha.SetMinute(hora.GetMinute());
 
2030
                                                                        fecha.SetSecond(hora.GetSecond());
 
2031
 
 
2032
                                                                        fechaStr = wxString(fecha.Format(_("%m/%d/%Y %H:%M:%S"), wxDateTime::TimeZone(wxDateTime::GMT1)));
 
2033
                                                                }
 
2034
                                                                else {
 
2035
                                                                        fechaStr = wxString(fecha.Format(_("%m/%d/%Y 00:00:00"), wxDateTime::TimeZone(wxDateTime::GMT1)));
 
2036
                                                                }
 
2037
                                                        }
 
2038
                                                        else {
 
2039
                                                                fechaStr = _("00/00/0000 00:00:00");
 
2040
                                                        }
 
2041
 
 
2042
 
 
2043
                                                        wxTreeItemId serieTreeId = m_pTreeListResultados->AppendItem(estudioTreeId, descripcionSerie);
 
2044
                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_MODALIDAD, tipoSerie);
 
2045
 
 
2046
                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_FECHA, fechaStr);
 
2047
 
 
2048
                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_MEDICO, wxString::FromUTF8(s.GetDoctor().c_str()));
 
2049
                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_UID_VISIBLE, uidSerie);
 
2050
                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_UID, uidSerie);
 
2051
                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_ACCNUMBER, wxString::FromUTF8(estudio->GetAccNumber().c_str()));
 
2052
 
 
2053
                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_Normal);
 
2054
                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_Selected);
 
2055
                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_Expanded);
 
2056
                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_SelectedExpanded);
 
2057
 
 
2058
                                                        if (m_AutoAddSeries) {
 
2059
 
 
2060
                                                                std::string uidPaciente = std::string(m_pTreeListResultados->GetItemText(pacienteTreeId, COLUMNA_UID).ToUTF8());
 
2061
                                                                std::string descPaciente = std::string(m_pTreeListResultados->GetItemText(pacienteTreeId).ToUTF8());
 
2062
 
 
2063
                                                                std::string uidSerie = std::string(m_pTreeListResultados->GetItemText(serieTreeId, COLUMNA_UID).ToUTF8());
 
2064
                                                                std::string descSerie = std::string( (m_pTreeListResultados->GetItemText(serieTreeId) + _T("(") + m_pTreeListResultados->GetItemText(serieTreeId, COLUMNA_MODALIDAD) + _T(")") ).ToUTF8());
 
2065
 
 
2066
                                                                std::string modalidadSerie = std::string(m_pTreeListResultados->GetItemText(serieTreeId, COLUMNA_MODALIDAD).ToUTF8());
 
2067
 
 
2068
                                                                if( GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.download", modalidadSerie) ) {
 
2069
                                                                        if (!questionMade && m_pDescargasGridTable->FindDescarga(uidSerie) != -1) {
 
2070
                                                                                Thaw();
 
2071
                                                                                forceInit = wxMessageBox(_("Series were already in the download queue.\nDo you want to force download?"),_("Download warning"),wxICON_INFORMATION|wxYES_NO) == wxYES;
 
2072
                                                                                Freeze();
 
2073
                                                                                questionMade = true;
 
2074
                                                                        }
 
2075
 
 
2076
                                                                        bool downloaded = m_pDescargasGridTable->AddDescarga(GetServerSeleccionado(), descPaciente, descSerie, uidSerie, modalidadSerie,forceInit, true);
 
2077
                                                                        m_pTreeListResultados->SetItemBold(serieTreeId, downloaded);
 
2078
                                                                } else {
 
2079
                                                                        listaModalidad.insert(modalidadSerie);
 
2080
                                                                }
 
2081
                                                        }
 
2082
 
 
2083
                                                }
 
2084
                                                if (m_AutoAddSeries) {
 
2085
                                                        m_AutoAddSeries = false;
 
2086
                                                        m_AutoAddSeriesItem = NULL;
 
2087
                                                }
 
2088
                                                m_pTreeListResultados->SortChildren(estudioTreeId);
 
2089
                                                m_pTreeListResultados->Expand(estudioTreeId);
 
2090
 
 
2091
                                        } else if (estudioTreeId.IsOk()) {
 
2092
                                                m_pTreeListResultados->Collapse(estudioTreeId);
 
2093
                                        }
 
2094
                                        Thaw();
 
2095
                                } //end freeze
 
2096
 
 
2097
                                if ( listaModalidad.size() > 0) {
 
2098
                                        std::ostringstream ostr;
 
2099
                                        ostr << _Std("You are not allowed to download this kind of modalities (");
 
2100
                                        bool primero = true;
 
2101
                                        for (std::set<std::string>::iterator it = listaModalidad.begin(); it != listaModalidad.end(); ++it) {
 
2102
                                                if (primero) {
 
2103
                                                        ostr << (*it);
 
2104
                                                        primero = false;
 
2105
                                                } else {
 
2106
                                                        ostr << ", " << (*it);
 
2107
                                                }
 
2108
                                        }
 
2109
                                        ostr << ")";
 
2110
                                        wxMessageBox(wxString::FromUTF8( ostr.str().c_str() ), _("Modality download error"), wxICON_ERROR);
 
2111
                                }
 
2112
                        }
 
2113
                }
 
2114
                else
 
2115
                {
 
2116
                        //rellenar el arbol
 
2117
 
 
2118
 
 
2119
                        wxTreeItemId pacienteTreeId;
 
2120
                        wxTreeItemId estudioTreeId;
 
2121
                        wxTreeItemId serieTreeId;
 
2122
 
 
2123
                        if (m_pComandoPACS->m_pPACSParams->m_error.size() > 0) {
 
2124
                                m_pComandoPACS = NULL;
 
2125
                                return;
 
2126
                        }
 
2127
                        else if(pModelo->ListaPacientes().size() == 0){
 
2128
                                if (!m_pComandoPACS->EstaAbortado()) {
 
2129
                                        LimpiarBusquedas(false);
 
2130
                                        wxTreeItemId topTreeId = m_pTreeListResultados->GetRootItem();
 
2131
                                        if (! topTreeId || ! topTreeId.IsOk() ) {
 
2132
                                                topTreeId = m_pTreeListResultados->AddRoot(wxT("Top"));
 
2133
                                        }
 
2134
                                        m_pTreeListResultados->AppendItem(topTreeId, _("No results found"));
 
2135
                                }
 
2136
                                m_pComandoPACS = NULL;
 
2137
                                return;
 
2138
                        }
 
2139
 
 
2140
                        m_pComandoPACS = NULL;
 
2141
 
 
2142
                        LimpiarBusquedas(false);
 
2143
 
 
2144
                        wxTreeItemId topTreeId = m_pTreeListResultados->GetRootItem();
 
2145
                        if (! topTreeId || ! topTreeId.IsOk() ) {
 
2146
                                topTreeId = m_pTreeListResultados->AddRoot(wxT("Top"));
 
2147
                        }
 
2148
 
 
2149
                        if (!topTreeId) {
 
2150
                                m_pComandoPACS = NULL;
 
2151
                                return;
 
2152
                        }
 
2153
 
 
2154
 
 
2155
 
 
2156
                        {
 
2157
 
 
2158
                                wxWindowDisabler disableAll;
 
2159
                                Freeze();
 
2160
                                //Refresh(true);
 
2161
 
 
2162
                                for (IModeloDicom::ListaPacientesType::const_iterator it = pModelo->ListaPacientes().begin(); it != pModelo->ListaPacientes().end(); it++) {
 
2163
                                        const IModeloPaciente& p = *it;
 
2164
                                        std::string pacienteNombre = p.GetNombre() + " (" + p.GetUID() + ")";
 
2165
                                        wxString nombrePaciente = wxString::FromUTF8(pacienteNombre.c_str());
 
2166
                                        wxString uidPaciente = wxString::FromUTF8(p.GetUID().c_str());
 
2167
                                        //columnas
 
2168
 
 
2169
                                        bool notfound = true;
 
2170
                                        wxTreeItemId tid = topTreeId;
 
2171
                                        std::list<wxTreeItemId> p_items = m_pTreeListResultados->GetPublicChildren(topTreeId);
 
2172
                                        for (std::list<wxTreeItemId>::iterator ititem = p_items.begin(); ititem != p_items.end(); ititem++) {
 
2173
                                                wxTreeItemId cid = *ititem;
 
2174
                                                if (
 
2175
                                                        m_pTreeListResultados->GetItemText(cid) == nombrePaciente &&
 
2176
                                                        m_pTreeListResultados->GetItemText(cid, COLUMNA_UID) == uidPaciente
 
2177
                                                        ) {
 
2178
                                                                notfound = false;
 
2179
                                                                pacienteTreeId = cid;
 
2180
                                                }
 
2181
                                        }
 
2182
 
 
2183
                                        if (notfound) {
 
2184
                                                pacienteTreeId = m_pTreeListResultados->AppendItem(topTreeId, nombrePaciente);
 
2185
                                                m_pTreeListResultados->SetItemText(pacienteTreeId, COLUMNA_UID, uidPaciente);
 
2186
                                                //
 
2187
                                                // Estilo
 
2188
                                                m_pTreeListResultados->SetItemBold(pacienteTreeId, true);
 
2189
                                                m_pTreeListResultados->SetItemTextColour(pacienteTreeId, *wxBLUE);
 
2190
 
 
2191
                                                //iconos
 
2192
                                                int icono = 0;
 
2193
                                                if(p.GetSexo() == "M") {
 
2194
                                                        icono = ICONO_HOMBRE;
 
2195
                                                } else if(p.GetSexo() == "F") {
 
2196
                                                        icono = ICONO_MUJER;
 
2197
                                                } else {
 
2198
                                                        icono = ICONO_OTRO;
 
2199
                                                }
 
2200
 
 
2201
                                                m_pTreeListResultados->SetItemImage(pacienteTreeId,icono,wxTreeItemIcon_Normal);
 
2202
                                                m_pTreeListResultados->SetItemImage(pacienteTreeId,icono,wxTreeItemIcon_Selected);
 
2203
                                                m_pTreeListResultados->SetItemImage(pacienteTreeId,icono,wxTreeItemIcon_Expanded);
 
2204
                                                m_pTreeListResultados->SetItemImage(pacienteTreeId,icono,wxTreeItemIcon_SelectedExpanded);
 
2205
                                        }
 
2206
 
 
2207
                                        if (!pacienteTreeId) {
 
2208
                                                continue;
 
2209
                                        }
 
2210
                                        //ESTUDIOS
 
2211
                                        for (IModeloPaciente::ListaEstudiosType::const_iterator it2 = p.ListaEstudios().begin(); it2 != p.ListaEstudios().end(); it2++) {
 
2212
                                                const IModeloEstudio& e = *it2;
 
2213
                                                wxDateTime fecha;
 
2214
                                                wxDateTime hora;
 
2215
                                                hora.ParseFormat( wxString::FromUTF8( (e.GetHora()).c_str() ).GetData(), wxT("%H%M%S"), wxDefaultDateTime);
 
2216
                                                fecha.ParseFormat( wxString::FromUTF8( (e.GetFecha()).c_str() ).GetData(), wxT("%Y%m%d"), wxDefaultDateTime);
 
2217
 
 
2218
                                                wxString modalidadEstudio = wxString::FromUTF8(e.GetModalidad().c_str());
 
2219
                                                wxString uidEstudio = wxString::FromUTF8(e.GetUID().c_str());
 
2220
                                                wxString descripcionEstudio = wxString::FromUTF8(e.GetDescripcion().c_str());
 
2221
                                                wxString AccNumber = wxString::FromUTF8(e.GetAccNumber().c_str());
 
2222
                                                wxString medicoEstudio = wxString::FromUTF8(e.GetDoctor().c_str());
 
2223
 
 
2224
                                                wxString fechaStr;
 
2225
 
 
2226
                                                if(fecha.IsValid()){
 
2227
                                                        if (hora.IsValid()) {
 
2228
 
 
2229
                                                                fecha.SetHour(hora.GetHour());
 
2230
                                                                fecha.SetMinute(hora.GetMinute());
 
2231
                                                                fecha.SetSecond(hora.GetSecond());
 
2232
 
 
2233
                                                                fechaStr = wxString(fecha.Format(_("%m/%d/%Y %H:%M:%S"), wxDateTime::TimeZone(wxDateTime::GMT1)));
 
2234
                                                        }
 
2235
                                                        else {
 
2236
                                                                fechaStr = wxString(fecha.Format(_("%m/%d/%Y 00:00:00"), wxDateTime::TimeZone(wxDateTime::GMT1)));
 
2237
                                                        }
 
2238
                                                }
 
2239
                                                else {
 
2240
                                                        fechaStr = _("00/00/0000 00:00:00");
 
2241
                                                }
 
2242
 
 
2243
                                                std::list<wxTreeItemId> e_items = m_pTreeListResultados->GetPublicChildren(pacienteTreeId);
 
2244
                                                for (std::list<wxTreeItemId>::iterator ititem = e_items.begin(); ititem != e_items.end(); ititem++) {
 
2245
                                                        wxTreeItemId cid = *ititem;
 
2246
                                                        if (
 
2247
                                                                m_pTreeListResultados->GetItemText(cid) == descripcionEstudio &&
 
2248
                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_MODALIDAD) == modalidadEstudio&&
 
2249
                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_FECHA) == fechaStr &&
 
2250
                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_MEDICO) == medicoEstudio &&
 
2251
                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_UID_VISIBLE) == uidEstudio &&
 
2252
                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_UID) == uidEstudio &&
 
2253
                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_ACCNUMBER) == AccNumber
 
2254
                                                                ) {
 
2255
                                                                        notfound = false;
 
2256
                                                                        estudioTreeId = cid;
 
2257
                                                        }
 
2258
                                                }
 
2259
 
 
2260
                                                if (notfound) {
 
2261
                                                        //columnas
 
2262
                                                        estudioTreeId = m_pTreeListResultados->AppendItem(pacienteTreeId, descripcionEstudio);
 
2263
                                                        m_pTreeListResultados->SetItemText(estudioTreeId, COLUMNA_MODALIDAD, modalidadEstudio);
 
2264
                                                        m_pTreeListResultados->SetItemText(estudioTreeId, COLUMNA_FECHA, fechaStr);
 
2265
 
 
2266
                                                        m_pTreeListResultados->SetItemText(estudioTreeId, COLUMNA_MEDICO, medicoEstudio);
 
2267
                                                        m_pTreeListResultados->SetItemText(estudioTreeId, COLUMNA_UID_VISIBLE, uidEstudio);
 
2268
                                                        m_pTreeListResultados->SetItemText(estudioTreeId, COLUMNA_UID, uidEstudio);
 
2269
                                                        m_pTreeListResultados->SetItemText(estudioTreeId, COLUMNA_ACCNUMBER, AccNumber);
 
2270
                                                        //
 
2271
 
 
2272
                                                        //ICONOS...
 
2273
                                                        m_pTreeListResultados->SetItemImage(estudioTreeId,ICONO_ESTUDIO,wxTreeItemIcon_Normal);
 
2274
                                                        m_pTreeListResultados->SetItemImage(estudioTreeId,ICONO_ESTUDIO,wxTreeItemIcon_Selected);
 
2275
                                                        m_pTreeListResultados->SetItemImage(estudioTreeId,ICONO_ESTUDIO,wxTreeItemIcon_Expanded);
 
2276
                                                        m_pTreeListResultados->SetItemImage(estudioTreeId,ICONO_ESTUDIO,wxTreeItemIcon_SelectedExpanded);
 
2277
                                                }
 
2278
 
 
2279
                                                if (!estudioTreeId) {
 
2280
                                                        continue;
 
2281
                                                }
 
2282
                                                
 
2283
                                                if (m_Mode == TD_SERIES) 
 
2284
                                                {
 
2285
                                                        for (IModeloEstudio::ListaSeriesType::const_iterator it3 = e.ListaSeries().begin(); it3 != e.ListaSeries().end(); it3++) {
 
2286
                                                                const IModeloSerie& s = *it3;
 
2287
                                                                wxString uidSerie = wxString::FromUTF8(s.GetUID().c_str());
 
2288
                                                                wxString numeroDeImagenes = wxString::FromUTF8(s.GetNumero().c_str());
 
2289
                                                                wxString tipoSerie = wxString::FromUTF8(s.GetTipo().c_str());
 
2290
                                                                wxString descripcionSerie = wxString::FromUTF8(s.GetDescripcion().c_str());
 
2291
                                                                wxString medicoSerie = wxString::FromUTF8(s.GetDoctor().c_str());
 
2292
                                                                wxDateTime fechaSerie;
 
2293
                                                                wxDateTime horaSerie;
 
2294
                                                                hora.ParseFormat( wxString::FromUTF8( (s.GetHora()).c_str() ).GetData(), wxT("%H%M%S"), wxDefaultDateTime);
 
2295
                                                                fecha.ParseFormat( wxString::FromUTF8( (s.GetFecha()).c_str() ).GetData(), wxT("%Y%m%d"), wxDefaultDateTime);
 
2296
 
 
2297
                                                                wxString fechaSerieStr;
 
2298
 
 
2299
                                                                if(fechaSerie.IsValid()){
 
2300
                                                                        if (horaSerie.IsValid()) {
 
2301
                                                                                fechaSerie.SetHour(horaSerie.GetHour());
 
2302
                                                                                fechaSerie.SetMinute(horaSerie.GetMinute());
 
2303
                                                                                fechaSerie.SetSecond(horaSerie.GetSecond());
 
2304
 
 
2305
                                                                                fechaSerieStr = wxString(fechaSerie.Format(_("%m/%d/%Y %H:%M:%S"), wxDateTime::TimeZone(wxDateTime::GMT1)));
 
2306
                                                                        }
 
2307
                                                                        else {
 
2308
                                                                                fechaSerieStr = wxString(fechaSerie.Format(_("%m/%d/%Y 00:00:00"), wxDateTime::TimeZone(wxDateTime::GMT1)));
 
2309
                                                                        }
 
2310
                                                                }
 
2311
                                                                else {
 
2312
                                                                        fechaSerieStr = _("00/00/0000 00:00:00");
 
2313
                                                                }
 
2314
 
 
2315
                                                                std::list<wxTreeItemId> s_items = m_pTreeListResultados->GetPublicChildren(estudioTreeId);
 
2316
                                                                for (std::list<wxTreeItemId>::iterator ititem = s_items.begin(); ititem != s_items.end(); ititem++) {
 
2317
                                                                        wxTreeItemId cid = *ititem;
 
2318
 
 
2319
                                                                        if (
 
2320
                                                                                m_pTreeListResultados->GetItemText(cid) == descripcionSerie &&
 
2321
                                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_MODALIDAD) == tipoSerie &&
 
2322
                                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_FECHA) == fechaSerieStr &&
 
2323
                                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_MEDICO) == medicoSerie &&
 
2324
                                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_UID_VISIBLE) == uidSerie &&
 
2325
                                                                                m_pTreeListResultados->GetItemText(cid, COLUMNA_UID) == uidSerie
 
2326
 
 
2327
                                                                                ) {
 
2328
                                                                                        notfound = false;
 
2329
                                                                                        serieTreeId = cid;
 
2330
                                                                        }
 
2331
                                                                }
 
2332
                                                                if (notfound) {
 
2333
 
 
2334
                                                                        serieTreeId = m_pTreeListResultados->AppendItem(estudioTreeId, descripcionSerie);
 
2335
 
 
2336
                                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_MODALIDAD, tipoSerie);
 
2337
                                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_FECHA, fechaSerieStr);
 
2338
 
 
2339
                                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_MEDICO, medicoSerie);
 
2340
                                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_UID_VISIBLE, uidSerie);
 
2341
                                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_UID, uidSerie);
 
2342
                                                                        m_pTreeListResultados->SetItemText(serieTreeId, COLUMNA_ACCNUMBER, AccNumber);
 
2343
 
 
2344
                                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_Normal);
 
2345
                                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_Selected);
 
2346
                                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_Expanded);
 
2347
                                                                        m_pTreeListResultados->SetItemImage(serieTreeId,ICONO_SERIE,wxTreeItemIcon_SelectedExpanded);
 
2348
                                                                }
 
2349
                                                        }
 
2350
                                                        if(e.ListaSeries().size() == 0)
 
2351
                                                        {
 
2352
                                                                wxTreeItemId serieTreeId = m_pTreeListResultados->AppendItem(estudioTreeId, _("Searching..."));
 
2353
                                                        }
 
2354
                                                }//end TD_SERIES
 
2355
                                        }
 
2356
                                }
 
2357
                                m_pTreeListResultados->SortChildren(m_pTreeListResultados->GetRootItem());
 
2358
                                Thaw();
 
2359
                        }
 
2360
                }//else rellenar el arbol
 
2361
 
 
2362
                m_pTreeListResultados->Refresh(false);
 
2363
                //m_pBotonBusqueda->SetAutoLayout(true);
 
2364
        }
 
2365
}
 
2366
 
 
2367
 
 
2368
void GNC::GUI::DialogoAdquisicion::ProcesarEvento(GNC::GCS::Eventos::IEvento *evt)
 
2369
{
 
2370
        GNC::GCS::Eventos::EventoProgresoComando* pEvt = dynamic_cast<GNC::GCS::Eventos::EventoProgresoComando*> (evt);
 
2371
        if (pEvt == NULL  || pEvt->GetComando() == NULL || pEvt->GetComando() != m_pComandoPACS) {
 
2372
                return;
 
2373
        }
 
2374
        switch (pEvt->GetTipo()) {
 
2375
case GNC::GCS::Eventos::EventoProgresoComando::TEP_Iniciado:
 
2376
        break;
 
2377
case GNC::GCS::Eventos::EventoProgresoComando::TEP_Progreso:
 
2378
        break;
 
2379
case GNC::GCS::Eventos::EventoProgresoComando::TEP_Finalizado:
 
2380
        m_pTextControlField->ShowCancelButton(false);
 
2381
        ShowAnimation(false);
 
2382
        m_pComandoPACS = NULL;
 
2383
        break;
 
2384
case GNC::GCS::Eventos::EventoProgresoComando::TEP_Unknown:
 
2385
        break;
 
2386
        }
 
2387
}
 
2388
 
 
2389
//endregion