fw4spl
SDicomSeriesAnonymizer.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "ioGdcm/SDicomSeriesAnonymizer.hpp"
8 
9 #include <fwCom/Signal.hxx>
10 
11 #include <fwData/Vector.hpp>
12 
13 #include <fwGdcmIO/helper/DicomSeriesAnonymizer.hpp>
14 
15 #include <fwGui/Cursor.hpp>
16 #include <fwGui/dialog/MessageDialog.hpp>
17 
18 #include <fwJobs/Aggregator.hpp>
19 #include <fwJobs/IJob.hpp>
20 
21 #include <fwMedData/DicomSeries.hpp>
22 #include <fwMedData/SeriesDB.hpp>
23 
24 #include <fwMedDataTools/helper/SeriesDB.hpp>
25 
26 #include <fwServices/macros.hpp>
27 
28 #include <vector>
29 
30 namespace ioGdcm
31 {
32 
33 fwServicesRegisterMacro( ::fwServices::IController, ::ioGdcm::SDicomSeriesAnonymizer);
34 
35 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL = "jobCreated";
36 
37 //------------------------------------------------------------------------------
38 
40  m_cancelled(false)
41 {
42  m_sigJobCreated = newSignal<JobCreatedSignal>(JOB_CREATED_SIGNAL);
43 }
44 
45 //------------------------------------------------------------------------------
46 
48 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
61 }
62 
63 //------------------------------------------------------------------------------
64 
66 {
67 }
68 
69 //------------------------------------------------------------------------------
70 
72 {
73  ::fwData::Vector::sptr vector = this->getInOut< ::fwData::Vector >("selectedSeries");
74 
76  dialog.setTitle("Series anonymization");
77 
78  // If the selection is not empty
79  if(!vector->empty())
80  {
81  dialog.setMessage( "Are you sure you want to anonymize the selected series ?" );
82  dialog.setIcon(::fwGui::dialog::IMessageDialog::QUESTION);
83  dialog.addButton(::fwGui::dialog::IMessageDialog::YES);
84  dialog.addButton(::fwGui::dialog::IMessageDialog::CANCEL);
85  ::fwGui::dialog::IMessageDialog::Buttons answer = dialog.show();
86 
87  if ( answer == ::fwGui::dialog::IMessageDialog::YES )
88  {
89  ::fwGui::Cursor cursor;
90  cursor.setCursor(::fwGui::ICursor::BUSY);
91  this->anonymize();
92  cursor.setDefaultCursor();
93  }
94  }
95  // If the selection is empty
96  else
97  {
98  dialog.setMessage( "Please select which series you want to anonymize." );
99  dialog.setIcon(::fwGui::dialog::IMessageDialog::INFO);
100  dialog.addButton(::fwGui::dialog::IMessageDialog::OK);
101  dialog.show();
102  }
103 }
104 
105 //------------------------------------------------------------------------------
106 
107 void SDicomSeriesAnonymizer::info(std::ostream& _sstream )
108 {
109  _sstream << "SDicomSeriesAnonymizer::info";
110 }
111 
112 //------------------------------------------------------------------------------
113 
115 {
116  ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB>("seriesDB");
117  ::fwData::Vector::sptr vector = this->getInOut< ::fwData::Vector >("selectedSeries");
118 
119  ::fwMedDataTools::helper::SeriesDB sDBhelper(seriesDB);
120 
121  ::fwGdcmIO::helper::DicomSeriesAnonymizer::sptr anonymizer =
122  ::fwGdcmIO::helper::DicomSeriesAnonymizer::New();
123  m_sigJobCreated->emit(anonymizer->getJob());
124 
125  std::vector< ::fwMedData::DicomSeries::sptr > anonymizedDicomSeriesVector;
126 
127  for(const auto& value : vector->getContainer())
128  {
129  ::fwMedData::DicomSeries::sptr dicomSeries = ::fwMedData::DicomSeries::dynamicCast(value);
130  ::fwMedData::DicomSeries::sptr anonymizedDicomSeries = ::fwMedData::DicomSeries::New();
131  anonymizer->anonymize(dicomSeries, anonymizedDicomSeries);
132  anonymizedDicomSeriesVector.push_back(anonymizedDicomSeries);
133 
134  m_cancelled = anonymizer->getJob()->cancelRequested();
135  if(m_cancelled)
136  {
137  break;
138  }
139  }
140 
141  if(!m_cancelled)
142  {
143  for(const auto& value : vector->getContainer())
144  {
145  ::fwMedData::DicomSeries::sptr dicomSeries = ::fwMedData::DicomSeries::dynamicCast(value);
146  sDBhelper.remove(dicomSeries);
147  }
148 
149  for(const auto& anonymizedDicomSeries : anonymizedDicomSeriesVector)
150  {
151  sDBhelper.add(anonymizedDicomSeries);
152  }
153  }
154 
155  // Notify SeriesDB
156  sDBhelper.notify();
157 }
158 
159 //------------------------------------------------------------------------------
160 
161 } // namespace ioGdcm
IOGDCM_API SDicomSeriesAnonymizer() noexcept
Constructor.
virtual FWGUI_API void setCursor(::fwGui::ICursor::CursorType cursor) override
Set the cursor.
virtual IOGDCM_API void stopping() override
Override.
Service to anonymize a DicomSeries.
IOGDCM_API void anonymize()
Override.
virtual IOGDCM_API ~SDicomSeriesAnonymizer() noexcept override
Destructor.
Defines the generic message box for IHM. Use the Delegate design pattern.
std::shared_ptr< JobCreatedSignal > m_sigJobCreated
Signal emitted when a job is created.
Defines an helper to modify an fwMedData::SeriesDB and create in parallel the message to announce thi...
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
virtual IOGDCM_API void starting() override
Override.
bool m_cancelled
Cancel information for jobs.
ioGdcm contains services use to deal with DICOM using the GDCM library.
Defines the generic cursor for IHM. Use the Delegate design pattern.
virtual IOGDCM_API void configuring() override
Do nothing.
IOGDCM_API void info(std::ostream &_sstream) override
Override.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
virtual FWGUI_API void setDefaultCursor() override
Set the default cursor.
IOGDCM_API void updating() override
Override.