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

« back to all changes in this revision

Viewing changes to src/fooextension/fooextension/gui/importation/generaldata.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: generaldata.cpp 3681 2011-04-12 10:53:31Z tovar $
 
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
#include <api/ientorno.h>
 
15
#include <wx/msgdlg.h>
 
16
#include <wx/filedlg.h>
 
17
#include <wx/valtext.h>
 
18
#include <wx/busyinfo.h>
 
19
#include <wx/image.h>
 
20
#include <wx/filename.h>
 
21
#include <wx/dir.h>
 
22
#include <wx/msgdlg.h>
 
23
#include <wx/confbase.h>
 
24
#include <api/idicommanager.h>
 
25
#include <api/ientorno.h>
 
26
#include <string>
 
27
#include <sstream>
 
28
#include <cmath>
 
29
 
 
30
#include "generaldata.h"
 
31
#include <api/internacionalizacion.h>
 
32
#include <export/tagsprivadoscomunes.h>
 
33
#include <fooextension/license.h>
 
34
 
 
35
#include <fooextension/commands/dicomizecommand.h>
 
36
 
 
37
namespace FooExtension {
 
38
        namespace GUI {
 
39
 
 
40
                GeneralData::GeneralData(wxWindow* pParent,IWizard* pWizard,const std::string &dirTemporal ,GnkPtr<ImportationPersistentData> datosPersistentes ,GNC::GCS::IEntorno * pEntorno):GeneralDataBase(pParent),IPasoWizard(pWizard)
 
41
                {
 
42
                        Hide();
 
43
                        m_pEntorno=pEntorno;
 
44
                        m_pPersistentData=datosPersistentes;
 
45
 
 
46
                        wxDateTime date = wxDateTime::Now();
 
47
                        m_pStudyTime->SetDateTimeValue(date);
 
48
                        m_pSeriesTime->SetDateTimeValue(date);
 
49
                }
 
50
 
 
51
                GeneralData::~GeneralData()
 
52
                {
 
53
                }
 
54
 
 
55
 
 
56
                //region "IPasoWizard"
 
57
 
 
58
                void GeneralData::Attach(wxSizer *sizer){
 
59
                        m_pPatientId->SetFocus();
 
60
 
 
61
                        Show(true);
 
62
 
 
63
                        sizer->Add(this,10, wxEXPAND);
 
64
                        this->GetParent()->Layout();
 
65
                }
 
66
 
 
67
                void GeneralData::Detach(wxSizer *sizer){
 
68
                        Hide();
 
69
                        sizer->Detach(this);
 
70
                        sizer->GetContainingWindow()->Layout();
 
71
                }
 
72
 
 
73
                std::string GeneralData::GetTitle(){
 
74
                        return _Std("Title of this step");
 
75
                }
 
76
 
 
77
                std::string GeneralData::GetSubTitle(){
 
78
                        return _Std("Subtitle of this step");
 
79
                }
 
80
 
 
81
                //allows next
 
82
                bool GeneralData::Siguiente(){
 
83
                        return true;
 
84
                }
 
85
 
 
86
                //allows back
 
87
                bool GeneralData::Anterior(){
 
88
                        return true;
 
89
                }
 
90
 
 
91
                //allows cancel
 
92
                bool GeneralData::Cancelar(){
 
93
                        return true;
 
94
                }
 
95
 
 
96
                //validate data
 
97
                bool GeneralData::Validar(){
 
98
                        bool ok =  ValidateData();
 
99
                        if (ok) {
 
100
                                //fill in dicom tags, here you can add your own tags
 
101
                                FillInCommonTags(m_pPersistentData->baseImages);
 
102
                                //throws dicomization command...
 
103
                                //first create params...
 
104
                                FooExtension::GADAPI::DicomizeCommandParameters* pParams = new FooExtension::GADAPI::DicomizeCommandParameters(m_pPersistentData, m_pEntorno);
 
105
                                //secondly create command
 
106
                                FooExtension::GADAPI::DicomizeCommand* pCmd = new FooExtension::GADAPI::DicomizeCommand(pParams);
 
107
                                //Lastly call command controller to execute command asynchronous
 
108
                                m_pEntorno->GetControladorComandos()->ProcessAsync(_Std("Dicomization"), pCmd, NULL);
 
109
                        }
 
110
                        return ok;
 
111
                }
 
112
 
 
113
                bool GeneralData::ValidateData() {
 
114
                        wxString mensaje = wxEmptyString;
 
115
 
 
116
                        if (m_pPatientId->GetValue().IsEmpty()) {
 
117
                                mensaje += _("\n* The patient ID is required.");
 
118
                        }
 
119
 
 
120
                        if(m_pPatientSurname1->GetValue().size() + m_pPatientSurname2->GetValue().size() + m_pPatientName->GetValue().size() > 61) {
 
121
                                mensaje += _("\n* Concatenation of patient name and surnames can't be higher than 61.");
 
122
                        }
 
123
 
 
124
                        if ( m_pPatientBirthDate->GetValue().IsLaterThan(m_pStudyDate->GetValue()) ) {
 
125
                                mensaje += _("\n* The patient's birth date is after the date of study");
 
126
                        }
 
127
 
 
128
                        if(mensaje != wxEmptyString){
 
129
                                wxMessageBox(_("The following errors have occurred when validating fields") + mensaje, _("Error validating fields"), wxICON_ERROR);
 
130
 
 
131
                                return false;
 
132
                        } else {
 
133
                                m_pPersistentData->PatientFirstSurname = GetPatientFirstSurname();
 
134
                                m_pPersistentData->PatientSecondSurname=GetPatientSecondSurname();
 
135
                                m_pPersistentData->PatientAge=GetPatientAge();
 
136
                                m_pPersistentData->PatientBirthDate=GetPatientBirthDate();
 
137
                                m_pPersistentData->PatientId=GetPatientId();
 
138
                                m_pPersistentData->PatientName=GetPatientName();
 
139
                                m_pPersistentData->PatientSex=GetPatientSex();
 
140
                                m_pPersistentData->StudyDescription=GetStudyDescription();
 
141
                                m_pPersistentData->StudyDate=GetStudyDate();
 
142
                                m_pPersistentData->StudyTime=GetStudyTime();
 
143
                                m_pPersistentData->SeriesDescription=GetSeriesDescription();
 
144
                                m_pPersistentData->SeriesDate=GetSeriesDate();
 
145
                                m_pPersistentData->SeriesTime=GetSeriesTime();
 
146
                                return true;
 
147
                        }
 
148
                }
 
149
 
 
150
                void GeneralData::FillInCommonTags(GIL::DICOM::TipoJerarquia& base)
 
151
                {
 
152
                        //list of selected files
 
153
                        for(ListaFicheros::const_iterator it=m_pListaFicheros->begin(); it!= m_pListaFicheros->end(); it++) {
 
154
                                std::string path = (*it);
 
155
                                FooExtension::GUI::ImportationPersistentData::TDicomizedFile file;
 
156
                                file.imagePath = path;
 
157
 
 
158
                                m_pPersistentData->m_dicomizedFiles.push_back(file);
 
159
                        }
 
160
 
 
161
                        std::string tag;
 
162
 
 
163
                        //institucion
 
164
                        wxString wxTmp;
 
165
                        if(m_pPersistentData->InstitutionName == "" ){
 
166
                                wxConfigBase::Get()->Read(wxT("/GinkgoCore/Estacion/CentroNombre"),&wxTmp,wxEmptyString);
 
167
                                if(wxTmp != wxEmptyString){
 
168
                                        base.tags[std::string("0008|0080")] = std::string(wxTmp.ToUTF8());
 
169
                                }
 
170
                        } else {
 
171
                                base.tags[std::string("0008|0080")] = m_pPersistentData->InstitutionName;
 
172
                        }
 
173
 
 
174
                        //nombre del medico responsable de la institucion
 
175
                        if(m_pPersistentData->PhysicianName == ""){
 
176
                                wxConfigBase::Get()->Read(wxT("/GinkgoCore/Estacion/NombreMedico"),&wxTmp,wxEmptyString);
 
177
                                if(wxTmp != wxEmptyString){
 
178
                                        base.tags[std::string("0008|0090")] = std::string(wxTmp.ToUTF8());
 
179
                                }
 
180
                        } else {
 
181
                                base.tags[std::string("0008|0090")] = m_pPersistentData->PhysicianName;
 
182
                        }
 
183
 
 
184
                        base.tags[std::string("0008|0070")] = std::string("Metaemotion S.L.");
 
185
 
 
186
                        //description of the extension
 
187
                        base.tags[std::string("0008|1090")] = FOO_EXTENSION_DESCRIPTION;
 
188
 
 
189
                        //uid of the extension, used to open imported files with this extension
 
190
                        base.tags[std::string("0018|1030")] = FOO_EXTENSION_UID;
 
191
 
 
192
                        base.tags[std::string("0008|0020")] = m_pPersistentData->StudyDate;
 
193
 
 
194
                        base.tags[std::string("0008|0030")] =  m_pPersistentData->StudyTime;
 
195
 
 
196
                        base.tags[std::string("0008|1030")] = m_pPersistentData->StudyDescription;
 
197
 
 
198
                        base.tags[std::string("0008|0021")] = m_pPersistentData->SeriesDate;
 
199
 
 
200
                        base.tags[std::string("0008|0031")] = m_pPersistentData->SeriesTime;
 
201
 
 
202
                        base.tags[std::string("0008|103e")] = m_pPersistentData->SeriesDescription;
 
203
 
 
204
                        base.tags[std::string("0008|0022")] = m_pPersistentData->SeriesDate;
 
205
                        base.tags[std::string("0008|0032")] = m_pPersistentData->SeriesTime;
 
206
                        base.tags[std::string("0020|4000")] = m_pPersistentData->SeriesDescription;
 
207
 
 
208
 
 
209
                        base.tags[std::string("0010|0010")] = m_pPersistentData->PatientName + "^" + m_pPersistentData->PatientFirstSurname + "^" + m_pPersistentData->PatientSecondSurname;
 
210
 
 
211
                        base.tags[std::string("0010|0020")] = m_pPersistentData->PatientId;
 
212
 
 
213
                        base.tags[std::string("0010|1010")] = m_pPersistentData->PatientAge;
 
214
 
 
215
                        base.tags[std::string("0010|0030")] = m_pPersistentData->PatientBirthDate;
 
216
 
 
217
                        base.tags[std::string("0010|0040")] = m_pPersistentData->PatientSex;
 
218
                }
 
219
 
 
220
                //endregion
 
221
 
 
222
                std::string GeneralData::GetPatientName(){
 
223
                        return std::string(m_pPatientName->GetValue().ToUTF8());
 
224
                }
 
225
 
 
226
                std::string GeneralData::GetPatientFirstSurname(){
 
227
                        return std::string(m_pPatientSurname1->GetValue().ToUTF8());
 
228
                }
 
229
 
 
230
                std::string GeneralData::GetPatientSecondSurname(){
 
231
                        return std::string(m_pPatientSurname2->GetValue().ToUTF8());
 
232
                }
 
233
 
 
234
                std::string GeneralData::GetPatientId(){
 
235
                        return std::string(m_pPatientId->GetValue().ToUTF8());
 
236
                }
 
237
 
 
238
                std::string GeneralData::GetPatientBirthDate(){
 
239
                        return std::string(m_pPatientBirthDate->GetValue().Format(wxT("%Y%m%d")).ToUTF8());
 
240
                }
 
241
 
 
242
                std::string GeneralData::GetPatientAge()
 
243
                {
 
244
                        int age = CalculateAge();
 
245
                        std::ostringstream os;
 
246
                        os.fill('0');
 
247
                        os.width(3);
 
248
                        os << age << "Y";
 
249
                        return os.str();
 
250
                }
 
251
 
 
252
                std::string GeneralData::GetPatientSex(){
 
253
                        std::string str;
 
254
                        switch(m_pPatientSex->GetSelection()){
 
255
                                case 0:
 
256
                                        str = std::string("M");
 
257
                                        break;
 
258
                                case 1:
 
259
                                        str = std::string("F");
 
260
                                        break;
 
261
                                case 2:
 
262
                                        str = std::string("O");
 
263
                                        break;
 
264
                        }
 
265
                        return str;
 
266
                }
 
267
 
 
268
                void GeneralData::OnKillFocusEstudioTimeControl(wxFocusEvent &event)
 
269
                {
 
270
                        if(!m_pStudyTime->GetDateTimeValue().IsValid()){
 
271
                                wxDateTime ahora = wxDateTime::Now();
 
272
                                m_pStudyTime->SetDateTimeValue(ahora);
 
273
                        }
 
274
                }
 
275
 
 
276
 
 
277
                std::string GeneralData::GetStudyDate()
 
278
                {
 
279
                        if(m_pStudyDate->GetValue().IsValid()){
 
280
                                return std::string(m_pStudyDate->GetValue().Format(wxT("%Y%m%d")).ToUTF8());
 
281
                        }else{
 
282
                                return std::string("");
 
283
                        }
 
284
                }
 
285
 
 
286
                std::string GeneralData::GetStudyTime()
 
287
                {
 
288
                        if(m_pStudyTime->GetDateTimeValue().IsValid()){
 
289
                                return std::string(m_pStudyTime->GetDateTimeValue().Format(wxT("%H%M%S")).ToUTF8());
 
290
                        }else{
 
291
                                return std::string("");
 
292
                        }
 
293
                }
 
294
 
 
295
                std::string GeneralData::GetStudyDescription()
 
296
                {
 
297
                        return std::string(m_pStudyDescription->GetValue().ToUTF8());
 
298
                }
 
299
 
 
300
                void GeneralData::OnKillFocusSerieTimeControl(wxFocusEvent &event)
 
301
                {
 
302
                        if(!m_pSeriesTime->GetDateTimeValue().IsValid())
 
303
                        {
 
304
                                wxDateTime ahora = wxDateTime::Now();
 
305
                                m_pSeriesTime->SetDateTimeValue(ahora);
 
306
                        }
 
307
                }
 
308
 
 
309
 
 
310
                std::string GeneralData::GetSeriesDate()
 
311
                {
 
312
                        if(m_pSeriesDate->GetValue().IsValid()){
 
313
                                return std::string(m_pSeriesDate->GetValue().Format(wxT("%Y%m%d")).ToUTF8());
 
314
                        }else{
 
315
                                return std::string("");
 
316
                        }
 
317
                }
 
318
 
 
319
                std::string GeneralData::GetSeriesTime()
 
320
                {
 
321
                        if(m_pSeriesTime->GetDateTimeValue().IsValid()){
 
322
                                return std::string(m_pSeriesTime->GetDateTimeValue().Format(wxT("%H%M%S")).ToUTF8());
 
323
                        }else{
 
324
                                return std::string("");
 
325
                        }
 
326
                }
 
327
 
 
328
                std::string GeneralData::GetSeriesDescription()
 
329
                {
 
330
                        return std::string(m_pSeriesDescription->GetValue().ToUTF8());
 
331
                }
 
332
 
 
333
 
 
334
                int GeneralData::CalculateAge()
 
335
                {
 
336
                        wxDateTime fechaEstudio = m_pStudyDate->GetValue();
 
337
                        wxDateTime fechaNacimiento = m_pPatientBirthDate->GetValue();
 
338
                        int edad = 0;
 
339
                        if( (fechaEstudio.GetMonth() > fechaNacimiento.GetMonth()) ||
 
340
                                (fechaEstudio.GetMonth() == fechaNacimiento.GetMonth() && fechaEstudio.GetDay() >= fechaNacimiento.GetDay()) ){
 
341
                                        edad = fechaEstudio.GetYear() - fechaNacimiento.GetYear();
 
342
                        } else {
 
343
                                edad = fechaEstudio.GetYear() - fechaNacimiento.GetYear() - 1;
 
344
                        }
 
345
                        return edad;
 
346
                }
 
347
        }
 
348
}