fw4spl
DicomAnonymizer.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 #ifndef __FWGDCMIO_HELPER_DICOMANONYMIZER_HPP__
8 #define __FWGDCMIO_HELPER_DICOMANONYMIZER_HPP__
9 
10 #include "fwGdcmIO/config.hpp"
11 #include "fwGdcmIO/helper/tags.hpp"
12 
13 #include <fwZip/WriteZipArchive.hpp>
14 
15 #include <boost/date_time/gregorian/gregorian_types.hpp>
16 #include <boost/filesystem/path.hpp>
17 
18 #include <gdcmAnonymizer.h>
19 #include <gdcmDicts.h>
20 #include <gdcmStringFilter.h>
21 
22 #include <iostream>
23 #include <map>
24 #include <set>
25 #include <string>
26 
27 namespace fwJobs
28 {
29 class IJob;
30 class Observer;
31 }
32 
33 namespace fwGdcmIO
34 {
35 namespace helper
36 {
37 
42 class FWGDCMIO_CLASS_API DicomAnonymizer
43 {
44 public:
45 
47 
49  FWGDCMIO_API DicomAnonymizer();
50 
52  FWGDCMIO_API virtual ~DicomAnonymizer();
53 
55  typedef std::map< std::string, std::string > UIDMap;
56 
58  typedef std::map< ::gdcm::Tag, std::string > ExceptionTagMapType;
59 
61  FWGDCMIO_API void anonymize(const ::boost::filesystem::path& dirPath);
62 
63  FWGDCMIO_API void anonymize(std::istream& inputStream, std::ostream& outputStream);
64 
66  FWGDCMIO_API void addExceptionTag(uint16_t group, uint16_t element, const std::string& value = "");
67 
73  FWGDCMIO_API static void copyDirectory(const ::boost::filesystem::path& input,
74  const ::boost::filesystem::path& output);
75 
77  FWGDCMIO_API SPTR(::fwJobs::IJob) getJob() const;
78 
80  FWGDCMIO_API unsigned int getNextIndex();
81 
83  FWGDCMIO_API void resetIndex();
84 
86  FWGDCMIO_API void removeAnonymizeTag(const ::gdcm::Tag& tag);
87 
89  FWGDCMIO_API void setReferenceDate(const ::boost::gregorian::date& referenceDate);
90 
98  FWGDCMIO_API void addShiftDateTag(const ::gdcm::Tag& tag);
99 
105  FWGDCMIO_API void preservePrivateTag(const ::gdcm::Tag& tag);
106 
110  typedef std::set< ::gdcm::Tag > TagContainerType;
111  FWGDCMIO_API const TagContainerType& getActionCodeDTags();
112  FWGDCMIO_API const TagContainerType& getActionCodeZTags();
113  FWGDCMIO_API const TagContainerType& getActionCodeXTags();
114  FWGDCMIO_API const TagContainerType& getActionCodeKTags();
115  FWGDCMIO_API const TagContainerType& getActionCodeCTags();
116  FWGDCMIO_API const TagContainerType& getActionCodeUTags();
119 private:
120 
121  void anonymizationProcess(const ::boost::filesystem::path& dirPath);
122 
124  void applyActionCodeD(const ::gdcm::Tag& tag);
125 
134  void applyActionCodeZ(const ::gdcm::Tag& tag);
135 
147  void applyActionCodeX(const ::gdcm::Tag& tag);
148 
150  void applyActionCodeK(const ::gdcm::Tag& tag);
151 
156  void applyActionCodeC(const ::gdcm::Tag& tag);
157 
160  void applyActionCodeU(const ::gdcm::Tag& tag);
161 
167  void applyActionShiftDate(const ::gdcm::Tag& tag);
168 
170  void generateDummyValue(const ::gdcm::Tag& tag);
171 
173  ::gdcm::Anonymizer m_anonymizer;
174 
176  ::gdcm::StringFilter m_stringFilter;
177 
179  const ::gdcm::Dict& m_publicDictionary;
180 
182  UIDMap m_uidMap;
183 
185  ExceptionTagMapType m_exceptionTagMap;
186 
188  static const unsigned int s_NUMBER_OF_TAGS;
189 
191  SPTR(::fwJobs::Observer) m_observer;
192 
194  bool m_archiving;
195 
197  unsigned int m_fileIndex;
198 
200  ::boost::gregorian::date m_referenceDate;
201 
207  TagContainerType m_actionCodeDTags;
208  TagContainerType m_actionCodeZTags;
209  TagContainerType m_actionCodeXTags;
210  TagContainerType m_actionCodeKTags;
211  TagContainerType m_actionCodeCTags;
212  TagContainerType m_actionCodeUTags;
215  TagContainerType m_actionShiftDateTags;
217 
219  ::fwGdcmIO::helper::PrivateTagVecType m_privateTags;
220 };
221 
222 } // namespace helper
223 } // namespace fwGdcmIO
224 
225 #endif /*__FWGDCMIO_HELPER_DICOMANONYMIZER_HPP__*/
#define SPTR(_cls_)
This class is an interface for class managing job.
Definition: IJob.hpp:28
STL namespace.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
std::map< ::gdcm::Tag, std::string > ExceptionTagMapType
Map used to store exception value.
This class contains helpers to anonymize dicom files on filesystem. Anonymization is performed accord...
std::map< std::string, std::string > UIDMap
Map used to maintain UID consistency.
This namespace fwJobs provides jobs management.
#define fwCoreClassFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate methods for classes with one factory.