Mercurial > hg > orthanc
annotate Core/DicomParsing/DicomModification.h @ 2573:3372c5255333 jobs
StoreScuJob, Orthanc Explorer for jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 May 2018 17:56:14 +0200 |
parents | d3476d90dcb7 |
children | 2f3007bf0708 |
rev | line source |
---|---|
786 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 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 |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
786 | 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 | |
790 | 36 #include "ParsedDicomFile.h" |
786 | 37 |
38 namespace Orthanc | |
39 { | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
40 class DicomModification : public boost::noncopyable |
786 | 41 { |
42 /** | |
43 * Process: | |
44 * (1) Remove private tags | |
45 * (2) Remove tags specified by the user | |
46 * (3) Replace tags | |
47 **/ | |
48 | |
2519
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
49 public: |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
50 enum TagOperation |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
51 { |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
52 TagOperation_Keep, |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
53 TagOperation_Remove |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
54 }; |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
55 |
2535
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
56 class IDicomIdentifierGenerator : public boost::noncopyable |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
57 { |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
58 public: |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
59 virtual ~IDicomIdentifierGenerator() |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
60 { |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
61 } |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
62 |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
63 virtual bool Apply(std::string& target, |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
64 const std::string& sourceIdentifier, |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
65 ResourceType level, |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
66 const DicomMap& sourceDicom) = 0; |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
67 }; |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
68 |
786 | 69 private: |
2506
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
70 class RelationshipsVisitor; |
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
71 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
790
diff
changeset
|
72 typedef std::set<DicomTag> SetOfTags; |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
73 typedef std::map<DicomTag, Json::Value*> Replacements; |
788 | 74 typedef std::map< std::pair<ResourceType, std::string>, std::string> UidMap; |
786 | 75 |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
790
diff
changeset
|
76 SetOfTags removals_; |
2310
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
77 SetOfTags clearings_; |
786 | 78 Replacements replacements_; |
79 bool removePrivateTags_; | |
788 | 80 ResourceType level_; |
786 | 81 UidMap uidMap_; |
991
2f76b92addd4
keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
790
diff
changeset
|
82 SetOfTags privateTagsToKeep_; |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
83 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
|
84 bool keepStudyInstanceUid_; |
3b40ca7470cc
"Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
85 bool keepSeriesInstanceUid_; |
2506
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
86 bool updateReferencedRelationships_; |
2535
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
87 DicomMap currentSource_; |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
88 |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
89 IDicomIdentifierGenerator* identifierGenerator_; |
786 | 90 |
2506
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
91 std::string MapDicomIdentifier(const std::string& original, |
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
92 ResourceType level); |
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
93 |
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
94 void MapDicomTags(ParsedDicomFile& dicom, |
51b91ead6c38
Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
95 ResourceType level); |
786 | 96 |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
97 void MarkNotOrthancAnonymization(); |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
98 |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
99 void ClearReplacements(); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
100 |
2323 | 101 bool CancelReplacement(const DicomTag& tag); |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
102 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
103 void ReplaceInternal(const DicomTag& tag, |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
104 const Json::Value& value); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
105 |
2309
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
106 void SetupAnonymization2008(); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
107 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
108 void SetupAnonymization2017c(); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
109 |
786 | 110 public: |
111 DicomModification(); | |
112 | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
113 ~DicomModification(); |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
114 |
787
ac18946afa74
refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
786
diff
changeset
|
115 void Keep(const DicomTag& tag); |
786 | 116 |
117 void Remove(const DicomTag& tag); | |
118 | |
2310
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
119 // 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
|
120 void Clear(const DicomTag& tag); |
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
121 |
786 | 122 bool IsRemoved(const DicomTag& tag) const; |
123 | |
2310
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
124 bool IsCleared(const DicomTag& tag) const; |
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
125 |
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
126 // "safeForAnonymization" tells Orthanc that this replacement does |
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
127 // not break the anonymization process it implements (for internal use only) |
786 | 128 void Replace(const DicomTag& tag, |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
129 const Json::Value& value, // Encoded using UTF-8 |
2310
b7fba68747f6
DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2309
diff
changeset
|
130 bool safeForAnonymization); |
786 | 131 |
132 bool IsReplaced(const DicomTag& tag) const; | |
133 | |
1698
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
134 const Json::Value& GetReplacement(const DicomTag& tag) const; |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
135 |
d78b87f93bcf
DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1695
diff
changeset
|
136 std::string GetReplacementAsString(const DicomTag& tag) const; |
786 | 137 |
138 void SetRemovePrivateTags(bool removed); | |
139 | |
140 bool ArePrivateTagsRemoved() const | |
141 { | |
142 return removePrivateTags_; | |
143 } | |
144 | |
788 | 145 void SetLevel(ResourceType level); |
786 | 146 |
788 | 147 ResourceType GetLevel() const |
786 | 148 { |
149 return level_; | |
150 } | |
151 | |
2309
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
152 void SetupAnonymization(DicomVersion version); |
786 | 153 |
154 void Apply(ParsedDicomFile& toModify); | |
1279
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
155 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
156 void SetAllowManualIdentifiers(bool check) |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
157 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
158 allowManualIdentifiers_ = check; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
159 } |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
160 |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
161 bool AreAllowManualIdentifiers() const |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
162 { |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
163 return allowManualIdentifiers_; |
7f3a65e84d4b
More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
991
diff
changeset
|
164 } |
2519
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
165 |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
166 void ParseModifyRequest(const Json::Value& request); |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
167 |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
168 void ParseAnonymizationRequest(bool& patientNameReplaced, |
2e6b7862ccf2
ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2506
diff
changeset
|
169 const Json::Value& request); |
2535
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
170 |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
171 void SetDicomIdentifierGenerator(IDicomIdentifierGenerator& generator) |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
172 { |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
173 identifierGenerator_ = &generator; |
d3476d90dcb7
DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2519
diff
changeset
|
174 } |
786 | 175 }; |
176 } |