annotate OrthancServer/DicomModification.h @ 2314:c54c9523adf8 issue-46-anonymization

add basic profile
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2017 22:09:27 +0200
parents d19e716b79fa
children f5fc61337bdf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1698
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
4 * Department, University Hospital of Liege, Belgium
2244
a3a65de1840f shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2209
diff changeset
5 * Copyright (C) 2017 Osimis, Belgium
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #pragma once
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 788
diff changeset
36 #include "ParsedDicomFile.h"
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 namespace Orthanc
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
40 class DicomModification : public boost::noncopyable
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 /**
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 * Process:
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 * (1) Remove private tags
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 * (2) Remove tags specified by the user
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 * (3) Replace tags
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 **/
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 private:
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
50 typedef std::set<DicomTag> SetOfTags;
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
51 typedef std::map<DicomTag, Json::Value*> Replacements;
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
52 typedef std::map< std::pair<ResourceType, std::string>, std::string> UidMap;
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
54 SetOfTags removals_;
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
55 SetOfTags clearings_;
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 Replacements replacements_;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 bool removePrivateTags_;
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
58 ResourceType level_;
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 UidMap uidMap_;
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
60 SetOfTags privateTagsToKeep_;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
61 bool allowManualIdentifiers_;
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
62 bool keepStudyInstanceUid_;
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
63 bool keepSeriesInstanceUid_;
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 void MapDicomIdentifier(ParsedDicomFile& dicom,
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
66 ResourceType level);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
68 void MarkNotOrthancAnonymization();
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
69
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
70 void ClearReplacements();
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
71
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
72 void RemoveInternal(const DicomTag& tag);
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
73
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
74 void ReplaceInternal(const DicomTag& tag,
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
75 const Json::Value& value);
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
76
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
77 void SetupAnonymization2008();
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
78
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
79 void SetupAnonymization2017c();
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
80
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 public:
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 DicomModification();
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
84 ~DicomModification();
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
85
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
86 void Keep(const DicomTag& tag);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 void Remove(const DicomTag& tag);
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
90 // Replace the DICOM tag as a NULL/empty value (e.g. for anonymization)
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
91 void Clear(const DicomTag& tag);
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
92
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 bool IsRemoved(const DicomTag& tag) const;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
95 bool IsCleared(const DicomTag& tag) const;
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
96
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
97 // "safeForAnonymization" tells Orthanc that this replacement does
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
98 // not break the anonymization process it implements (for internal use only)
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 void Replace(const DicomTag& tag,
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
100 const Json::Value& value, // Encoded using UTF-8
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
101 bool safeForAnonymization);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 bool IsReplaced(const DicomTag& tag) const;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
105 const Json::Value& GetReplacement(const DicomTag& tag) const;
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
106
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
107 std::string GetReplacementAsString(const DicomTag& tag) const;
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 void SetRemovePrivateTags(bool removed);
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 bool ArePrivateTagsRemoved() const
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return removePrivateTags_;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
116 void SetLevel(ResourceType level);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
118 ResourceType GetLevel() const
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 return level_;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
123 void SetupAnonymization(DicomVersion version);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 void Apply(ParsedDicomFile& toModify);
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
126
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
127 void SetAllowManualIdentifiers(bool check)
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
128 {
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
129 allowManualIdentifiers_ = check;
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
130 }
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
131
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
132 bool AreAllowManualIdentifiers() const
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
133 {
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
134 return allowManualIdentifiers_;
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
135 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 };
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }