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

« back to all changes in this revision

Viewing changes to src/cadxcore/main/gui/anonymize/anonymizepanel.cpp

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: AnonymizePanel.cpp $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-12 MetaEmotion S.L. All rights reserved.
 
7
 *  http://ginkgo-cadx.com
 
8
 *
 
9
 *  This file is licensed under LGPL v3 license.
 
10
 *  See License.txt for details
 
11
 *
 
12
 *
 
13
 */
 
14
#include "anonymizepanel.h"
 
15
#include <api/dicom/idicommanager.h>
 
16
#include <api/dicom/dcmdictionary.h>
 
17
#include <main/entorno.h>
 
18
#include <api/ientorno.h>
 
19
#include <api/controllers/icontroladorlog.h>
 
20
#include <api/controllers/iconfigurationcontroller.h>
 
21
#include <api/controllers/ipacscontroller.h>
 
22
#include <main/controllers/commandcontroller.h>
 
23
#include <main/controllers/historycontroller.h>
 
24
#include <commands/comandoexportacion.h>
 
25
 
 
26
GNC::GUI::AnonymizePanel::AnonymizePanel(wxWindow* pParent): GNC::GUI::AnonymizePanelBase(pParent)
 
27
{
 
28
}
 
29
 
 
30
GNC::GUI::AnonymizePanel::AnonymizePanel(wxWindow* pParent, const std::list<long>& seriesPk): GNC::GUI::AnonymizePanelBase(pParent)
 
31
{
 
32
        if (seriesPk.empty()) {
 
33
                LOG_ERROR("AnonymizePanel", "you have to select at least one series to anonymize");
 
34
        } else {
 
35
                InitSeries(seriesPk.front());
 
36
        }
 
37
}
 
38
 
 
39
GNC::GUI::AnonymizePanel::~AnonymizePanel()
 
40
{
 
41
        m_pTagsList->Disconnect(wxEVT_PG_CHANGED,wxPropertyGridEventHandler(AnonymizePanel::OnPropertyChanged),NULL,this);
 
42
        m_pTagsList->Disconnect(wxEVT_PG_DOUBLE_CLICK,wxPropertyGridEventHandler(AnonymizePanel::OnPropertyDobleClick),NULL,this);
 
43
}
 
44
 
 
45
void GNC::GUI::AnonymizePanel::InitSeries(long pkSeries)
 
46
{
 
47
        GNC::GCS::HistoryController::LightFileModelList fileModels;
 
48
        GNC::GCS::HistoryController::Instance()->GetSeriesSortedFileModels(pkSeries, fileModels);
 
49
 
 
50
        GIL::DICOM::IDICOMManager*      pDICOMManager = GNC::GCS::IEntorno::Instance()->GetPACSController()->CrearInstanciaDeDICOMManager();
 
51
        pDICOMManager->CargarFichero(fileModels.front().real_path, m_base);
 
52
        SetTags(m_base, m_pTagsList->GetRoot(), pDICOMManager);
 
53
        GNC::Entorno::Instance()->GetPACSController()->LiberarInstanciaDeDICOMManager(pDICOMManager);
 
54
 
 
55
        MapOfCheck[GKDCM_PatientName] = m_pCheckNombrePaciente;
 
56
        MapOfCheck[GKDCM_PatientID] = m_pCheckIdPaciente;
 
57
        MapOfCheck[GKDCM_InstitutionName] = m_pCheckInstituciones;
 
58
        MapOfCheck[GKDCM_ReferringPhysicianName] = m_pReferringPhysician;
 
59
        MapOfCheck[GKDCM_StudyDescription] = m_pCheckComentarios;
 
60
        MapOfCheck[GKDCM_SeriesDescription] = m_pCheckComentarios;
 
61
        MapOfCheck[GKDCM_ImageComments] = m_pCheckComentarios;
 
62
        
 
63
        GNC::GCS::IConfigurationController::TListGroups groups;
 
64
        GNC::GCS::IConfigurationController::Instance()->readGroupUser("/Core/AnonymizationSelection", groups);
 
65
        for (GNC::GCS::IConfigurationController::TListGroups::iterator it = groups.begin(); it != groups.end(); ++it)
 
66
        {
 
67
                if ((*it).find("tag") != (*it).end() && (*it).find("value") != (*it).end()) {
 
68
                        Anonymize((*it)["tag"], true, (*it)["value"]);
 
69
                }
 
70
        }
 
71
 
 
72
        m_pTagsList->Connect(wxEVT_PG_CHANGED,wxPropertyGridEventHandler(AnonymizePanel::OnPropertyChanged),NULL,this);
 
73
        m_pTagsList->Connect(wxEVT_PG_DOUBLE_CLICK,wxPropertyGridEventHandler(AnonymizePanel::OnPropertyDobleClick),NULL,this);
 
74
}
 
75
 
 
76
void GNC::GUI::AnonymizePanel::SetTags(GIL::DICOM::DicomDataset & base,wxPGPropArg idPadre,GIL::DICOM::IDICOMManager*   pDICOMManager) 
 
77
{
 
78
        for(GIL::DICOM::ListaTags::iterator it = base.tags.begin(); it!= base.tags.end(); ++it){
 
79
                wxString helpString = wxString::FromUTF8(pDICOMManager->GetDescription((*it).first).c_str());
 
80
                wxStringProperty* prop = NULL;
 
81
                wxString valor;
 
82
                if((*it).second.size()>100) {
 
83
                        valor=wxT("Datos");
 
84
                } else {
 
85
                        valor = wxString::FromUTF8((*it).second.c_str());
 
86
                }
 
87
 
 
88
                if(helpString.size()>0){
 
89
                        helpString = wxT("(") + wxString::FromUTF8((*it).first.c_str()) + wxT(") ") + helpString;
 
90
                        prop = new wxStringProperty(helpString,
 
91
                                wxPG_LABEL,valor);
 
92
                }else{
 
93
                        prop = new wxStringProperty(wxString::FromUTF8((*it).first.c_str()),
 
94
                                wxPG_LABEL,valor);
 
95
                }
 
96
                prop->SetHelpString(wxString::FromUTF8((*it).first.c_str()));
 
97
                m_pTagsList->AppendIn(idPadre, prop);
 
98
        }
 
99
 
 
100
        for(GIL::DICOM::DicomDataset::DatasetList::iterator it = base.secuencias.begin(); it!=base.secuencias.end(); ++it){
 
101
                wxStringProperty* prop = NULL;
 
102
                wxString helpString = wxString::FromUTF8(pDICOMManager->GetDescription((*it).tagName).c_str());
 
103
                if(helpString.size()>0){
 
104
                        helpString = wxT("(") + wxString::FromUTF8((*it).tagName.c_str()) + wxT(") ") + helpString;
 
105
                        prop = new wxStringProperty(helpString,
 
106
                                wxPG_LABEL,wxEmptyString);
 
107
                }else{
 
108
                        prop = new wxStringProperty(wxString::FromUTF8((*it).tagName.c_str()),
 
109
                                wxPG_LABEL,wxEmptyString);
 
110
                }
 
111
                prop->SetHelpString(wxString::FromUTF8((*it).tagName.c_str()));
 
112
                if(m_pTagsList->GetProperty(prop->GetName()) != NULL) {
 
113
                        ////////////////////////////////////std::cout<<"hasdfasdf";
 
114
                }
 
115
                wxPGId pIdSequencia = m_pTagsList->AppendIn(idPadre,prop);
 
116
 
 
117
                //recursion
 
118
                int i=0;
 
119
                for(GIL::DICOM::DicomDataset::DatasetList::iterator it2 = (*it).items.begin(); it2!= (*it).items.end(); ++it2, ++i) {
 
120
                        wxPGPropArg pIdItem = m_pTagsList->AppendIn(pIdSequencia,new wxStringProperty(wxString::Format(wxT("Item %d"),i),wxPG_LABEL,wxEmptyString));
 
121
                        SetTags((*it2),pIdItem,pDICOMManager);
 
122
                }
 
123
        }
 
124
}
 
125
 
 
126
void GNC::GUI::AnonymizePanel::OnCheckNombreApellidos( wxCommandEvent& /*event*/ )
 
127
{
 
128
        //se anonimiza 0010|0010 (nombre del paciente)
 
129
        std::string clave("0010|0010");
 
130
        Anonymize(clave,m_pCheckNombrePaciente->IsChecked());
 
131
}
 
132
 
 
133
void GNC::GUI::AnonymizePanel::OnCheckIdPaciente( wxCommandEvent& /*event*/ )
 
134
{
 
135
        //se anonimiza 0010|0020" (id del paciente)
 
136
        std::string clave("0010|0020");
 
137
        Anonymize(clave,m_pCheckIdPaciente->IsChecked());
 
138
}
 
139
 
 
140
void GNC::GUI::AnonymizePanel::OnCheckInstituciones( wxCommandEvent& /*event*/ )
 
141
{
 
142
        //se anonimiza (0008,0080) Institution Name
 
143
        std::string clave("0008|0080");
 
144
        Anonymize(clave,m_pCheckInstituciones->IsChecked());
 
145
}
 
146
 
 
147
void GNC::GUI::AnonymizePanel::OnCheckPhysician( wxCommandEvent& /*event*/ )
 
148
{
 
149
        //referring physician name
 
150
        std::string clave("0008|0090");
 
151
        Anonymize(clave,m_pReferringPhysician->IsChecked());
 
152
}
 
153
 
 
154
void GNC::GUI::AnonymizePanel::OnCheckComentarios( wxCommandEvent& /*event*/ )
 
155
{
 
156
        //descripcion del estudio, serie e imagenes
 
157
        //estudio
 
158
        {
 
159
                std::string clave("0008|1030");
 
160
                Anonymize(clave,m_pCheckComentarios->IsChecked());
 
161
        }
 
162
        //serie
 
163
        {
 
164
                std::string clave("0008|103e");
 
165
                Anonymize(clave,m_pCheckComentarios->IsChecked());
 
166
        }
 
167
        //imagen
 
168
        {
 
169
                std::string clave("0020|4000");
 
170
                Anonymize(clave,m_pCheckComentarios->IsChecked());
 
171
        }
 
172
}
 
173
 
 
174
void GNC::GUI::AnonymizePanel::Anonymize(const std::string& clave, bool anonimizar)
 
175
{
 
176
        wxString value = wxEmptyString;
 
177
 
 
178
        if(!anonimizar){
 
179
                std::string tmp;
 
180
                if(m_base.getTag(clave,tmp)){
 
181
                        value = wxString::FromUTF8(tmp.c_str());
 
182
                }
 
183
        }
 
184
 
 
185
        Anonymize(clave, anonimizar, std::string(value.ToUTF8()));
 
186
}
 
187
 
 
188
void GNC::GUI::AnonymizePanel::Anonymize(const std::string& clave, bool anonimizar, const std::string& value)
 
189
{
 
190
        if (MapOfCheck.find(clave) != MapOfCheck.end()) {
 
191
                MapOfCheck[clave]->SetValue(anonimizar);
 
192
        }
 
193
        wxString valueWx = wxString::FromUTF8(value.c_str());
 
194
        for(wxPGProperty* it=m_pTagsList->GetFirst();it!=NULL;it=m_pTagsList->GetNextSiblingProperty(it)){
 
195
                if(it->GetHelpString() == wxString::FromUTF8(clave.c_str())){
 
196
                        it->SetValueFromString(valueWx);
 
197
                        if(anonimizar){
 
198
                                m_pTagsList->SetPropertyCell(it->GetId(),0,it->GetLabel(),wxNullBitmap,*wxWHITE,*wxRED);
 
199
                                m_pTagsList->SetPropertyCell(it->GetId(),1,it->GetValue(),wxNullBitmap,*wxWHITE,*wxRED);
 
200
                        }else{
 
201
                                m_pTagsList->SetPropertyCell(it->GetId(),0,it->GetLabel());
 
202
                                m_pTagsList->SetPropertyCell(it->GetId(),1,it->GetValue());
 
203
                        }
 
204
                        it->ChangeFlag(wxPG_PROP_MODIFIED,anonimizar);
 
205
                        m_pTagsList->RefreshProperty(it);
 
206
                        return;
 
207
                }
 
208
        }
 
209
}
 
210
 
 
211
 
 
212
void GNC::GUI::AnonymizePanel::RemoveFromTable(const std::string& clave)
 
213
{
 
214
        for(wxPGProperty* it=m_pTagsList->GetFirst();it!=NULL;it=m_pTagsList->GetNextSiblingProperty(it)){
 
215
                if(it->GetHelpString() == wxString::FromUTF8(clave.c_str())){
 
216
                        m_pTagsList->DeleteProperty(it->GetId());
 
217
                        break;
 
218
                }
 
219
        }
 
220
}
 
221
 
 
222
void GNC::GUI::AnonymizePanel::GetTagsAnonymized(GIL::DICOM::DicomDataset & base)
 
223
{
 
224
        base.tags.clear();
 
225
        GNC::GCS::IConfigurationController::TListGroups configGroups;
 
226
        for(wxPGProperty* it=m_pTagsList->GetFirst();it!=NULL;it=m_pTagsList->GetNextSiblingProperty(it)){
 
227
                if(it->IsFlagSet(wxPG_PROP_MODIFIED)){
 
228
                        std::string clave(it->GetHelpString().ToUTF8());
 
229
                        std::string valor(it->GetValueAsString().ToUTF8());
 
230
                        base.tags[clave] = valor;
 
231
 
 
232
                        GNC::GCS::IConfigurationController::TMapValues group;
 
233
                        group["tag"] = clave;
 
234
                        group["value"] = valor;
 
235
                        configGroups.push_back(group);
 
236
                }
 
237
        }
 
238
        GNC::GCS::IConfigurationController::Instance()->writeGroupUser("/Core/AnonymizationSelection", configGroups);
 
239
        
 
240
}
 
241
 
 
242
bool GNC::GUI::AnonymizePanel::AnonymizePrivateTags()
 
243
{
 
244
        return m_pCheckAtributosPrivadosGinkgo->IsChecked();
 
245
}
 
246
 
 
247
void GNC::GUI::AnonymizePanel::OnPropertyChanged(wxPropertyGridEvent& event)
 
248
{
 
249
        wxPGProperty* selected= event.GetProperty();
 
250
        m_pTagsList->SetPropertyCell(selected->GetId(),0,selected->GetLabel(),wxNullBitmap,*wxWHITE,*wxRED);
 
251
        m_pTagsList->SetPropertyCell(selected->GetId(),1,selected->GetValue(),wxNullBitmap,*wxWHITE,*wxRED);
 
252
}
 
253
 
 
254
void GNC::GUI::AnonymizePanel::OnPropertyDobleClick(wxPropertyGridEvent& event)
 
255
{
 
256
        std::string clave(event.GetProperty()->GetHelpString().ToUTF8());
 
257
        Anonymize(clave,!event.GetProperty()->IsFlagSet(wxPG_PROP_MODIFIED));
 
258
}
 
259
 
 
260