comparison OrthancFramework/Sources/DicomParsing/DicomModification.h @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Core/DicomParsing/DicomModification.h@9ccbbd55bc23
children e00f3d089991
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #include "ParsedDicomFile.h"
37
38 namespace Orthanc
39 {
40 class DicomModification : public boost::noncopyable
41 {
42 /**
43 * Process:
44 * (1) Remove private tags
45 * (2) Remove tags specified by the user
46 * (3) Replace tags
47 **/
48
49 public:
50 enum TagOperation
51 {
52 TagOperation_Keep,
53 TagOperation_Remove
54 };
55
56 class IDicomIdentifierGenerator : public boost::noncopyable
57 {
58 public:
59 virtual ~IDicomIdentifierGenerator()
60 {
61 }
62
63 virtual bool Apply(std::string& target,
64 const std::string& sourceIdentifier,
65 ResourceType level,
66 const DicomMap& sourceDicom) = 0;
67 };
68
69 private:
70 class RelationshipsVisitor;
71
72 typedef std::set<DicomTag> SetOfTags;
73 typedef std::map<DicomTag, Json::Value*> Replacements;
74 typedef std::map< std::pair<ResourceType, std::string>, std::string> UidMap;
75
76 SetOfTags removals_;
77 SetOfTags clearings_;
78 Replacements replacements_;
79 bool removePrivateTags_;
80 ResourceType level_;
81 UidMap uidMap_;
82 SetOfTags privateTagsToKeep_;
83 bool allowManualIdentifiers_;
84 bool keepStudyInstanceUid_;
85 bool keepSeriesInstanceUid_;
86 bool keepSopInstanceUid_;
87 bool updateReferencedRelationships_;
88 bool isAnonymization_;
89 DicomMap currentSource_;
90 std::string privateCreator_;
91
92 IDicomIdentifierGenerator* identifierGenerator_;
93
94 std::string MapDicomIdentifier(const std::string& original,
95 ResourceType level);
96
97 void RegisterMappedDicomIdentifier(const std::string& original,
98 const std::string& mapped,
99 ResourceType level);
100
101 void MapDicomTags(ParsedDicomFile& dicom,
102 ResourceType level);
103
104 void MarkNotOrthancAnonymization();
105
106 void ClearReplacements();
107
108 bool CancelReplacement(const DicomTag& tag);
109
110 void ReplaceInternal(const DicomTag& tag,
111 const Json::Value& value);
112
113 void SetupAnonymization2008();
114
115 void SetupAnonymization2017c();
116
117 void UnserializeUidMap(ResourceType level,
118 const Json::Value& serialized,
119 const char* field);
120
121 public:
122 DicomModification();
123
124 DicomModification(const Json::Value& serialized);
125
126 ~DicomModification();
127
128 void Keep(const DicomTag& tag);
129
130 void Remove(const DicomTag& tag);
131
132 // Replace the DICOM tag as a NULL/empty value (e.g. for anonymization)
133 void Clear(const DicomTag& tag);
134
135 bool IsRemoved(const DicomTag& tag) const;
136
137 bool IsCleared(const DicomTag& tag) const;
138
139 // "safeForAnonymization" tells Orthanc that this replacement does
140 // not break the anonymization process it implements (for internal use only)
141 void Replace(const DicomTag& tag,
142 const Json::Value& value, // Encoded using UTF-8
143 bool safeForAnonymization);
144
145 bool IsReplaced(const DicomTag& tag) const;
146
147 const Json::Value& GetReplacement(const DicomTag& tag) const;
148
149 std::string GetReplacementAsString(const DicomTag& tag) const;
150
151 void SetRemovePrivateTags(bool removed);
152
153 bool ArePrivateTagsRemoved() const
154 {
155 return removePrivateTags_;
156 }
157
158 void SetLevel(ResourceType level);
159
160 ResourceType GetLevel() const
161 {
162 return level_;
163 }
164
165 void SetupAnonymization(DicomVersion version);
166
167 void Apply(ParsedDicomFile& toModify);
168
169 void SetAllowManualIdentifiers(bool check)
170 {
171 allowManualIdentifiers_ = check;
172 }
173
174 bool AreAllowManualIdentifiers() const
175 {
176 return allowManualIdentifiers_;
177 }
178
179 void ParseModifyRequest(const Json::Value& request);
180
181 void ParseAnonymizationRequest(bool& patientNameReplaced,
182 const Json::Value& request);
183
184 void SetDicomIdentifierGenerator(IDicomIdentifierGenerator& generator)
185 {
186 identifierGenerator_ = &generator;
187 }
188
189 void Serialize(Json::Value& value) const;
190
191 void SetPrivateCreator(const std::string& privateCreator)
192 {
193 privateCreator_ = privateCreator;
194 }
195
196 const std::string& GetPrivateCreator()
197 {
198 return privateCreator_;
199 }
200 };
201 }