annotate OrthancFramework/Sources/DicomParsing/DicomModification.cpp @ 4684:e3810750dc9d

simplified DicomModification::RelationshipsVisitor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Jun 2021 14:42:09 +0200
parents 2e850edf03d6
children 693f049729ba
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: 1818
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
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., 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
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2323
diff changeset
23 #include "../PrecompiledHeaders.h"
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "DicomModification.h"
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3709
diff changeset
26 #include "../Compatibility.h"
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2323
diff changeset
27 #include "../Logging.h"
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2323
diff changeset
28 #include "../OrthancException.h"
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
29 #include "../SerializationToolbox.h"
790
331eaf9d9d69 ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 789
diff changeset
30 #include "FromDcmtkBridge.h"
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
31 #include "ITagVisitor.h"
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3709
diff changeset
33 #include <memory> // For std::unique_ptr
795
d466b3606aca refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 790
diff changeset
34
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
35
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
36 static const std::string ORTHANC_DEIDENTIFICATION_METHOD_2008 =
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
37 "Orthanc " ORTHANC_VERSION " - PS 3.15-2008 Table E.1-1";
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
38
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
39 static const std::string ORTHANC_DEIDENTIFICATION_METHOD_2017c =
2314
c54c9523adf8 add basic profile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2313
diff changeset
40 "Orthanc " ORTHANC_VERSION " - PS 3.15-2017c Table E.1-1 Basic Profile";
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
41
4677
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
42 static const std::string ORTHANC_DEIDENTIFICATION_METHOD_2021b =
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
43 "Orthanc " ORTHANC_VERSION " - PS 3.15-2021b Table E.1-1 Basic Profile";
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
44
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
47 DicomModification::DicomTagRange::DicomTagRange(uint16_t groupFrom,
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
48 uint16_t groupTo,
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
49 uint16_t elementFrom,
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
50 uint16_t elementTo) :
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
51 groupFrom_(groupFrom),
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
52 groupTo_(groupTo),
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
53 elementFrom_(elementFrom),
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
54 elementTo_(elementTo)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
55 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
56 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
57
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
58
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
59 bool DicomModification::DicomTagRange::Contains(const DicomTag& tag) const
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
60 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
61 return (tag.GetGroup() >= groupFrom_ &&
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
62 tag.GetGroup() <= groupTo_ &&
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
63 tag.GetElement() >= elementFrom_ &&
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
64 tag.GetElement() <= elementTo_);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
65 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
66
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
67
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
68 class DicomModification::RelationshipsVisitor : public ITagVisitor
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
69 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
70 private:
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
71 DicomModification& that_;
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
72
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
73 // This method is only applicable to first-level tags
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
74 bool IsManuallyModified(const DicomTag& tag) const
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
75 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
76 return (that_.IsCleared(tag) ||
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
77 that_.IsRemoved(tag) ||
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
78 that_.IsReplaced(tag));
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
79 }
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
80
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
81 public:
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
82 explicit RelationshipsVisitor(DicomModification& that) :
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
83 that_(that)
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
84 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
85 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
86
3195
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
87 virtual void VisitNotSupported(const std::vector<DicomTag>& parentTags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
88 const std::vector<size_t>& parentIndexes,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
89 const DicomTag& tag,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
90 ValueRepresentation vr)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
91 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
92 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
93
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
94 virtual void VisitEmptySequence(const std::vector<DicomTag>& parentTags,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
95 const std::vector<size_t>& parentIndexes,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3194
diff changeset
96 const DicomTag& tag)
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
97 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
98 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
99
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
100 virtual void VisitBinary(const std::vector<DicomTag>& parentTags,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
101 const std::vector<size_t>& parentIndexes,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
102 const DicomTag& tag,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
103 ValueRepresentation vr,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
104 const void* data,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
105 size_t size)
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
106 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
107 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
108
3194
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
109 virtual void VisitIntegers(const std::vector<DicomTag>& parentTags,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
110 const std::vector<size_t>& parentIndexes,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
111 const DicomTag& tag,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
112 ValueRepresentation vr,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
113 const std::vector<int64_t>& values)
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
114 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
115 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
116
3194
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
117 virtual void VisitDoubles(const std::vector<DicomTag>& parentTags,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
118 const std::vector<size_t>& parentIndexes,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
119 const DicomTag& tag,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
120 ValueRepresentation vr,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
121 const std::vector<double>& value)
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
122 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
123 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
124
3194
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
125 virtual void VisitAttributes(const std::vector<DicomTag>& parentTags,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
126 const std::vector<size_t>& parentIndexes,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
127 const DicomTag& tag,
47ef29168698 support of value multiplicity in ITagVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
128 const std::vector<DicomTag>& value)
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
129 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
130 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
131
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
132 virtual Action VisitString(std::string& newValue,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
133 const std::vector<DicomTag>& parentTags,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
134 const std::vector<size_t>& parentIndexes,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
135 const DicomTag& tag,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
136 ValueRepresentation vr,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
137 const std::string& value)
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
138 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
139 /**
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
140 * Note that all the tags in "uids_" have the VR UI (unique
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
141 * identifier), and are considered as strings.
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
142 *
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
143 * Also, the tags "SOP Instance UID", "Series Instance UID" and
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
144 * "Study Instance UID" are *never* included in "uids_", as they
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
145 * are separately handed by "MapDicomTags()".
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
146 **/
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
147
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
148 assert(that_.uids_.find(DICOM_TAG_STUDY_INSTANCE_UID) == that_.uids_.end());
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
149 assert(that_.uids_.find(DICOM_TAG_SERIES_INSTANCE_UID) == that_.uids_.end());
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
150 assert(that_.uids_.find(DICOM_TAG_SOP_INSTANCE_UID) == that_.uids_.end());
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
151
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
152 if (parentTags.empty())
2521
6db878376018 support anonymization of CurrentRequestedProcedureEvidenceSequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2520
diff changeset
153 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
154 // We are on a first-level tag
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
155 if (that_.uids_.find(tag) != that_.uids_.end() &&
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
156 !IsManuallyModified(tag))
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
157 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
158 // This is a first-level UID tag that must be anonymized
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
159 assert(vr == ValueRepresentation_UniqueIdentifier ||
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
160 vr == ValueRepresentation_NotSupported /* for older versions of DCMTK */);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
161 newValue = that_.MapDicomIdentifier(value, ResourceType_Instance);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
162 return Action_Replace;
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
163 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
164 else
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
165 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
166 return Action_None;
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
167 }
3344
90b4a5001c24 Anonymization: Preserve hierarchical relationships in (0008,1115) [] (0020,000e)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3195
diff changeset
168 }
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
169 else
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
170 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
171 // We are within a sequence
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
172 if (tag == DICOM_TAG_STUDY_INSTANCE_UID)
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
173 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
174 newValue = that_.MapDicomIdentifier(value, ResourceType_Study);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
175 return Action_Replace;
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
176 }
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
177 else if (tag == DICOM_TAG_SERIES_INSTANCE_UID)
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
178 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
179 newValue = that_.MapDicomIdentifier(value, ResourceType_Series);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
180 return Action_Replace;
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
181 }
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
182 else if (tag == DICOM_TAG_SOP_INSTANCE_UID)
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
183 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
184 newValue = that_.MapDicomIdentifier(value, ResourceType_Instance);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
185 return Action_Replace;
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
186 }
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
187 else if (that_.uids_.find(tag) != that_.uids_.end())
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
188 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
189 assert(vr == ValueRepresentation_UniqueIdentifier ||
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
190 vr == ValueRepresentation_NotSupported /* for older versions of DCMTK */);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
191
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
192 if (parentTags.size() == 2 &&
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
193 parentTags[0] == DICOM_TAG_REFERENCED_FRAME_OF_REFERENCE_SEQUENCE &&
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
194 parentTags[1] == DICOM_TAG_RT_REFERENCED_STUDY_SEQUENCE &&
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
195 tag == DICOM_TAG_REFERENCED_SOP_INSTANCE_UID)
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
196 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
197 /**
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
198 * In RT-STRUCT, this ReferencedSOPInstanceUID is actually
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
199 * referencing a StudyInstanceUID !! (observed in many
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
200 * data sets including:
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
201 * https://wiki.cancerimagingarchive.net/display/Public/Lung+CT+Segmentation+Challenge+2017)
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
202 * Tested in "test_anonymize_relationships_5". Introduced
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
203 * in: https://hg.orthanc-server.com/orthanc/rev/3513
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
204 **/
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
205 newValue = that_.MapDicomIdentifier(value, ResourceType_Study);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
206 }
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
207 else
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
208 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
209 newValue = that_.MapDicomIdentifier(value, ResourceType_Instance);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
210 }
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
211
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
212 return Action_Replace;
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
213 }
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
214 else
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
215 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
216 return Action_None;
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
217 }
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
218 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
219 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
220
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
221 void RemoveRelationships(ParsedDicomFile& dicom) const
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
222 {
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
223 for (SetOfTags::const_iterator it = that_.uids_.begin(); it != that_.uids_.end(); ++it)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
224 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
225 assert(*it != DICOM_TAG_STUDY_INSTANCE_UID &&
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
226 *it != DICOM_TAG_SERIES_INSTANCE_UID &&
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
227 *it != DICOM_TAG_SOP_INSTANCE_UID);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
228
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
229 if (!IsManuallyModified(*it))
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
230 {
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
231 dicom.Remove(*it);
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
232 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
233 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
234
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
235 // The only two sequences with to the "X/Z/U*" rule in the
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
236 // basic profile. They were already present in Orthanc 1.9.3.
4684
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
237 if (!IsManuallyModified(DICOM_TAG_REFERENCED_IMAGE_SEQUENCE))
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
238 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
239 dicom.Remove(DICOM_TAG_REFERENCED_IMAGE_SEQUENCE);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
240 }
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
241
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
242 if (!IsManuallyModified(DICOM_TAG_SOURCE_IMAGE_SEQUENCE))
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
243 {
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
244 dicom.Remove(DICOM_TAG_SOURCE_IMAGE_SEQUENCE);
e3810750dc9d simplified DicomModification::RelationshipsVisitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4678
diff changeset
245 }
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
246 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
247 };
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
248
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
249
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
250 bool DicomModification::CancelReplacement(const DicomTag& tag)
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
251 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
252 Replacements::iterator it = replacements_.find(tag);
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
253
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
254 if (it != replacements_.end())
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
255 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
256 delete it->second;
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
257 replacements_.erase(it);
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
258 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
259 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
260 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
261 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
262 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
263 }
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
264 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
265
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
266
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
267 void DicomModification::ReplaceInternal(const DicomTag& tag,
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
268 const Json::Value& value)
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
269 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
270 Replacements::iterator it = replacements_.find(tag);
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
271
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
272 if (it != replacements_.end())
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
273 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
274 delete it->second;
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
275 it->second = NULL; // In the case of an exception during the clone
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
276 it->second = new Json::Value(value); // Clone
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
277 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
278 else
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
279 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
280 replacements_[tag] = new Json::Value(value); // Clone
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
281 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
282 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
283
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
284
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
285 void DicomModification::ClearReplacements()
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
286 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
287 for (Replacements::iterator it = replacements_.begin();
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
288 it != replacements_.end(); ++it)
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
289 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
290 delete it->second;
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
291 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
292
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
293 replacements_.clear();
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
294 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
295
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
296
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
297 void DicomModification::MarkNotOrthancAnonymization()
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
298 {
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
299 Replacements::iterator it = replacements_.find(DICOM_TAG_DEIDENTIFICATION_METHOD);
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
300
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
301 if (it != replacements_.end() &&
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
302 (it->second->asString() == ORTHANC_DEIDENTIFICATION_METHOD_2008 ||
4677
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
303 it->second->asString() == ORTHANC_DEIDENTIFICATION_METHOD_2017c ||
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
304 it->second->asString() == ORTHANC_DEIDENTIFICATION_METHOD_2021b))
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
305 {
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
306 delete it->second;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
307 replacements_.erase(it);
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
308 }
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
309 }
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
310
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
311 void DicomModification::RegisterMappedDicomIdentifier(const std::string& original,
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
312 const std::string& mapped,
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
313 ResourceType level)
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
314 {
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
315 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, original));
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
316
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
317 if (previous == uidMap_.end())
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
318 {
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
319 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped));
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
320 }
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
321 }
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
322
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
323 std::string DicomModification::MapDicomIdentifier(const std::string& original,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
324 ResourceType level)
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
325 {
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
326 const std::string stripped = Toolbox::StripSpaces(original);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
327
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
328 std::string mapped;
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
329
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
330 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, stripped));
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
331
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
332 if (previous == uidMap_.end())
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
333 {
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
334 if (identifierGenerator_ == NULL)
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
335 {
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
336 mapped = FromDcmtkBridge::GenerateUniqueIdentifier(level);
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
337 }
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
338 else
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
339 {
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
340 if (!identifierGenerator_->Apply(mapped, stripped, level, currentSource_))
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
341 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
342 throw OrthancException(ErrorCode_InternalError,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
343 "Unable to generate an anonymized ID");
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
344 }
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
345 }
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
346
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
347 uidMap_.insert(std::make_pair(std::make_pair(level, stripped), mapped));
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
348 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
349 else
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
350 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
351 mapped = previous->second;
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
352 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
353
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
354 return mapped;
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
355 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
356
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
357
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
358 void DicomModification::MapDicomTags(ParsedDicomFile& dicom,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
359 ResourceType level)
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3709
diff changeset
361 std::unique_ptr<DicomTag> tag;
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 switch (level)
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 {
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
365 case ResourceType_Study:
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 tag.reset(new DicomTag(DICOM_TAG_STUDY_INSTANCE_UID));
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 break;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
369 case ResourceType_Series:
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 tag.reset(new DicomTag(DICOM_TAG_SERIES_INSTANCE_UID));
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 break;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
373 case ResourceType_Instance:
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 tag.reset(new DicomTag(DICOM_TAG_SOP_INSTANCE_UID));
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 break;
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 default:
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 throw OrthancException(ErrorCode_InternalError);
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 std::string original;
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
382 if (!const_cast<const ParsedDicomFile&>(dicom).GetTagValue(original, *tag))
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 original = "";
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
387 std::string mapped = MapDicomIdentifier(original, level);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
389 dicom.Replace(*tag, mapped,
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
390 false /* don't try and decode data URI scheme for UIDs */,
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
391 DicomReplaceMode_InsertIfAbsent, privateCreator_);
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
392 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
394
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
395 DicomModification::DicomModification() :
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
396 removePrivateTags_(false),
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
397 level_(ResourceType_Instance),
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
398 allowManualIdentifiers_(true),
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
399 keepStudyInstanceUid_(false),
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
400 keepSeriesInstanceUid_(false),
3860
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
401 keepSopInstanceUid_(false),
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
402 updateReferencedRelationships_(true),
2721
062776ab4a21 fix issue #94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
403 isAnonymization_(false),
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
404 //privateCreator_("PrivateCreator"),
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
405 identifierGenerator_(NULL)
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
409 DicomModification::~DicomModification()
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
410 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
411 ClearReplacements();
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
412 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
413
787
ac18946afa74 refactoring of anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
414 void DicomModification::Keep(const DicomTag& tag)
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 {
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
416 bool wasRemoved = IsRemoved(tag);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
417 bool wasCleared = IsCleared(tag);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
418
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 removals_.erase(tag);
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
420 clearings_.erase(tag);
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
421 uids_.erase(tag);
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
422
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
423 bool wasReplaced = CancelReplacement(tag);
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 916
diff changeset
424
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
425 if (tag == DICOM_TAG_STUDY_INSTANCE_UID)
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
426 {
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
427 keepStudyInstanceUid_ = true;
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
428 }
2321
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
429 else if (tag == DICOM_TAG_SERIES_INSTANCE_UID)
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
430 {
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
431 keepSeriesInstanceUid_ = true;
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
432 }
3860
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
433 else if (tag == DICOM_TAG_SOP_INSTANCE_UID)
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
434 {
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
435 keepSopInstanceUid_ = true;
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
436 }
2321
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
437 else if (tag.IsPrivate())
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
438 {
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
439 privateTagsToKeep_.insert(tag);
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
440 }
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
441 else if (!wasRemoved &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
442 !wasReplaced &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
443 !wasCleared)
2321
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
444 {
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
445 LOG(WARNING) << "Marking this tag as to be kept has no effect: " << tag.Format();
65ffba10cace warning message in DicomModification::Keep()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2314
diff changeset
446 }
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
447
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
448 MarkNotOrthancAnonymization();
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 void DicomModification::Remove(const DicomTag& tag)
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 removals_.insert(tag);
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
454 clearings_.erase(tag);
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
455 uids_.erase(tag);
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
456 CancelReplacement(tag);
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
457 privateTagsToKeep_.erase(tag);
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
458
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
459 MarkNotOrthancAnonymization();
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
460 }
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
461
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
462 void DicomModification::Clear(const DicomTag& tag)
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
463 {
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
464 removals_.erase(tag);
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
465 clearings_.insert(tag);
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
466 uids_.erase(tag);
2323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2321
diff changeset
467 CancelReplacement(tag);
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 916
diff changeset
468 privateTagsToKeep_.erase(tag);
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
469
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
470 MarkNotOrthancAnonymization();
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 bool DicomModification::IsRemoved(const DicomTag& tag) const
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
475 if (removals_.find(tag) != removals_.end())
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
476 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
477 return true;
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
478 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
479 else
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
480 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
481 for (RemovedRanges::const_iterator it = removedRanges_.begin();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
482 it != removedRanges_.end(); it++)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
483 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
484 if (it->Contains(tag))
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
485 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
486 return true;
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
487 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
488 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
489
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
490 return false;
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
491 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
494 bool DicomModification::IsCleared(const DicomTag& tag) const
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
495 {
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
496 return clearings_.find(tag) != clearings_.end();
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
497 }
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
498
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 void DicomModification::Replace(const DicomTag& tag,
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
500 const Json::Value& value,
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
501 bool safeForAnonymization)
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 {
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
503 clearings_.erase(tag);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 removals_.erase(tag);
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
505 uids_.erase(tag);
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 916
diff changeset
506 privateTagsToKeep_.erase(tag);
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
507 ReplaceInternal(tag, value);
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
508
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
509 if (!safeForAnonymization)
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
510 {
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
511 MarkNotOrthancAnonymization();
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
512 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
515
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 bool DicomModification::IsReplaced(const DicomTag& tag) const
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 return replacements_.find(tag) != replacements_.end();
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
521 const Json::Value& DicomModification::GetReplacement(const DicomTag& tag) const
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 Replacements::const_iterator it = replacements_.find(tag);
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 if (it == replacements_.end())
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 throw OrthancException(ErrorCode_InexistentItem);
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 else
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 {
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
531 return *it->second;
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
535
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
536 std::string DicomModification::GetReplacementAsString(const DicomTag& tag) const
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
537 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
538 const Json::Value& json = GetReplacement(tag);
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
539
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
540 if (json.type() != Json::stringValue)
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
541 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
542 throw OrthancException(ErrorCode_BadParameterType);
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
543 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
544 else
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
545 {
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
546 return json.asString();
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
547 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
548 }
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
549
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
550
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 void DicomModification::SetRemovePrivateTags(bool removed)
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 removePrivateTags_ = removed;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
554
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
555 if (!removed)
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
556 {
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
557 MarkNotOrthancAnonymization();
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
558 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
561 bool DicomModification::ArePrivateTagsRemoved() const
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
562 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
563 return removePrivateTags_;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
564 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
565
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
566 void DicomModification::SetLevel(ResourceType level)
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 uidMap_.clear();
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 level_ = level;
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
570
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
571 if (level != ResourceType_Patient)
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
572 {
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
573 MarkNotOrthancAnonymization();
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
574 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
577 ResourceType DicomModification::GetLevel() const
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
578 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
579 return level_;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
580 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
581
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
582
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
583 static void SetupUidsFromOrthancInternal(std::set<DicomTag>& uids,
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
584 std::set<DicomTag>& removals,
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
585 const DicomTag& tag)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
586 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
587 uids.insert(tag);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
588 removals.erase(tag); // Necessary if unserializing a job from 1.9.3
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
589 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
590
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
591
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
592 void DicomModification::SetupUidsFromOrthanc_1_9_3()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
593 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
594 /**
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
595 * Values below come from the hardcoded UID of Orthanc 1.9.3
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
596 * in DicomModification::RelationshipsVisitor::VisitString() and
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
597 * DicomModification::RelationshipsVisitor::RemoveRelationships()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
598 * https://hg.orthanc-server.com/orthanc/file/Orthanc-1.9.3/OrthancFramework/Sources/DicomParsing/DicomModification.cpp#l117
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
599 **/
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
600 uids_.clear();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
601
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
602 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x0008, 0x0014)); // Instance Creator UID <= from SetupAnonymization2008()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
603 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x0008, 0x1155)); // Referenced SOP Instance UID <= from VisitString() + RemoveRelationships()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
604 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x0020, 0x0052)); // Frame of Reference UID <= from VisitString() + RemoveRelationships()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
605 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x0020, 0x0200)); // Synchronization Frame of Reference UID <= from SetupAnonymization2008()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
606 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x0040, 0xa124)); // UID <= from SetupAnonymization2008()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
607 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x0088, 0x0140)); // Storage Media File-set UID <= from SetupAnonymization2008()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
608 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x3006, 0x0024)); // Referenced Frame of Reference UID <= from VisitString() + RemoveRelationships()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
609 SetupUidsFromOrthancInternal(uids_, removals_, DicomTag(0x3006, 0x00c2)); // Related Frame of Reference UID <= from VisitString() + RemoveRelationships()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
610 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
611
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
612
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
613 void DicomModification::SetupAnonymization2008()
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 {
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
615 // This is Table E.1-1 from PS 3.15-2008 - DICOM Part 15: Security and System Management Profiles
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
616 // https://raw.githubusercontent.com/jodogne/dicom-specification/master/2008/08_15pu.pdf
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
617
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
618 SetupUidsFromOrthanc_1_9_3();
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
619
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
620 //uids_.insert(DicomTag(0x0008, 0x0014)); // Instance Creator UID => set in SetupUidsFromOrthanc_1_9_3()
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
621 //removals_.insert(DicomTag(0x0008, 0x0018)); // SOP Instance UID => set in Apply()
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
622 removals_.insert(DicomTag(0x0008, 0x0050)); // Accession Number
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
623 removals_.insert(DicomTag(0x0008, 0x0080)); // Institution Name
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
624 removals_.insert(DicomTag(0x0008, 0x0081)); // Institution Address
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
625 removals_.insert(DicomTag(0x0008, 0x0090)); // Referring Physician's Name
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
626 removals_.insert(DicomTag(0x0008, 0x0092)); // Referring Physician's Address
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
627 removals_.insert(DicomTag(0x0008, 0x0094)); // Referring Physician's Telephone Numbers
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
628 removals_.insert(DicomTag(0x0008, 0x1010)); // Station Name
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
629 removals_.insert(DicomTag(0x0008, 0x1030)); // Study Description
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
630 removals_.insert(DicomTag(0x0008, 0x103e)); // Series Description
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
631 removals_.insert(DicomTag(0x0008, 0x1040)); // Institutional Department Name
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
632 removals_.insert(DicomTag(0x0008, 0x1048)); // Physician(s) of Record
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
633 removals_.insert(DicomTag(0x0008, 0x1050)); // Performing Physicians' Name
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
634 removals_.insert(DicomTag(0x0008, 0x1060)); // Name of Physician(s) Reading Study
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
635 removals_.insert(DicomTag(0x0008, 0x1070)); // Operators' Name
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
636 removals_.insert(DicomTag(0x0008, 0x1080)); // Admitting Diagnoses Description
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
637 //uids_.insert(DicomTag(0x0008, 0x1155)); // Referenced SOP Instance UID => set in SetupUidsFromOrthanc_1_9_3()
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
638 removals_.insert(DicomTag(0x0008, 0x2111)); // Derivation Description
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
639 //removals_.insert(DicomTag(0x0010, 0x0010)); // Patient's Name => cf. below (*)
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
640 //removals_.insert(DicomTag(0x0010, 0x0020)); // Patient ID => cf. below (*)
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
641 removals_.insert(DicomTag(0x0010, 0x0030)); // Patient's Birth Date
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
642 removals_.insert(DicomTag(0x0010, 0x0032)); // Patient's Birth Time
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
643 removals_.insert(DicomTag(0x0010, 0x0040)); // Patient's Sex
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
644 removals_.insert(DicomTag(0x0010, 0x1000)); // Other Patient Ids
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
645 removals_.insert(DicomTag(0x0010, 0x1001)); // Other Patient Names
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
646 removals_.insert(DicomTag(0x0010, 0x1010)); // Patient's Age
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
647 removals_.insert(DicomTag(0x0010, 0x1020)); // Patient's Size
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
648 removals_.insert(DicomTag(0x0010, 0x1030)); // Patient's Weight
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
649 removals_.insert(DicomTag(0x0010, 0x1090)); // Medical Record Locator
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
650 removals_.insert(DicomTag(0x0010, 0x2160)); // Ethnic Group
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
651 removals_.insert(DicomTag(0x0010, 0x2180)); // Occupation
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
652 removals_.insert(DicomTag(0x0010, 0x21b0)); // Additional Patient's History
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
653 removals_.insert(DicomTag(0x0010, 0x4000)); // Patient Comments
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
654 removals_.insert(DicomTag(0x0018, 0x1000)); // Device Serial Number
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
655 removals_.insert(DicomTag(0x0018, 0x1030)); // Protocol Name
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
656 //removals_.insert(DicomTag(0x0020, 0x000d)); // Study Instance UID => set in Apply()
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
657 //removals_.insert(DicomTag(0x0020, 0x000e)); // Series Instance UID => set in Apply()
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
658 removals_.insert(DicomTag(0x0020, 0x0010)); // Study ID
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
659 //uids_.insert(DicomTag(0x0020, 0x0052)); // Frame of Reference UID => set in SetupUidsFromOrthanc_1_9_3()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
660 //uids_.insert(DicomTag(0x0020, 0x0200)); // Synchronization Frame of Reference UID => set in SetupUidsFromOrthanc_1_9_3()
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
661 removals_.insert(DicomTag(0x0020, 0x4000)); // Image Comments
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
662 removals_.insert(DicomTag(0x0040, 0x0275)); // Request Attributes Sequence
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
663 //uids_.insert(DicomTag(0x0040, 0xa124)); // UID => set in SetupUidsFromOrthanc_1_9_3()
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
664 removals_.insert(DicomTag(0x0040, 0xa730)); // Content Sequence
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
665 //uids_.insert(DicomTag(0x0088, 0x0140)); // Storage Media File-set UID => set in SetupUidsFromOrthanc_1_9_3()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
666 //uids_.insert(DicomTag(0x3006, 0x0024)); // Referenced Frame of Reference UID => set in SetupUidsFromOrthanc_1_9_3()
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
667 //uids_.insert(DicomTag(0x3006, 0x00c2)); // Related Frame of Reference UID => set in SetupUidsFromOrthanc_1_9_3()
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
669 // Some more removals (from the experience of DICOM files at the CHU of Liege)
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
670 removals_.insert(DicomTag(0x0010, 0x1040)); // Patient's Address
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
671 removals_.insert(DicomTag(0x0032, 0x1032)); // Requesting Physician
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
672 removals_.insert(DicomTag(0x0010, 0x2154)); // PatientTelephoneNumbers
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
673 removals_.insert(DicomTag(0x0010, 0x2000)); // Medical Alerts
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
674
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
675 // Set the DeidentificationMethod tag
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
676 ReplaceInternal(DICOM_TAG_DEIDENTIFICATION_METHOD, ORTHANC_DEIDENTIFICATION_METHOD_2008);
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
677 }
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
678
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
679
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
680 void DicomModification::SetupAnonymization2017c()
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
681 {
2313
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
682 /**
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
683 * This is Table E.1-1 from PS 3.15-2017c (DICOM Part 15: Security
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
684 * and System Management Profiles), "basic profile" column. It was
4675
7e4d1f2b3a8f GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
685 * generated automatically by calling:
7e4d1f2b3a8f GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
686 * "../../../OrthancServer/Resources/GenerateAnonymizationProfile.py
7e4d1f2b3a8f GenerateAnonymizationProfile.py can read from URL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
687 * https://raw.githubusercontent.com/jodogne/dicom-specification/master/2017c/part15.xml"
2313
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
688 **/
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
689
4676
caf963ee3de9 DicomModification_Anonymization2017c.impl.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4675
diff changeset
690 #include "DicomModification_Anonymization2017c.impl.h"
2313
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
691
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
692 // Set the DeidentificationMethod tag
d19e716b79fa switch to anonymization according to DICOM 2017c
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2311
diff changeset
693 ReplaceInternal(DICOM_TAG_DEIDENTIFICATION_METHOD, ORTHANC_DEIDENTIFICATION_METHOD_2017c);
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
694 }
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
695
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
696
4677
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
697 void DicomModification::SetupAnonymization2021b()
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
698 {
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
699 /**
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
700 * This is Table E.1-1 from PS 3.15-2021b (DICOM Part 15: Security
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
701 * and System Management Profiles), "basic profile" column. It was
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
702 * generated automatically by calling:
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
703 * "../../../OrthancServer/Resources/GenerateAnonymizationProfile.py
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
704 * https://raw.githubusercontent.com/jodogne/dicom-specification/master/2021b/part15.xml"
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
705 *
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
706 * http://dicom.nema.org/medical/dicom/2021b/output/chtml/part15/chapter_E.html#table_E.1-1a
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
707 * http://dicom.nema.org/medical/dicom/2021b/output/chtml/part15/chapter_E.html#table_E.1-1
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
708 **/
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
709
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
710 #include "DicomModification_Anonymization2021b.impl.h"
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
711
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
712 // Set the DeidentificationMethod tag
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
713 ReplaceInternal(DICOM_TAG_DEIDENTIFICATION_METHOD, ORTHANC_DEIDENTIFICATION_METHOD_2021b);
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
714 }
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
715
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
716
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
717 void DicomModification::SetupAnonymization(DicomVersion version)
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
718 {
2721
062776ab4a21 fix issue #94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
719 isAnonymization_ = true;
062776ab4a21 fix issue #94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
720
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
721 removals_.clear();
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
722 clearings_.clear();
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
723 removedRanges_.clear();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
724 uids_.clear();
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
725 ClearReplacements();
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
726 removePrivateTags_ = true;
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
727 level_ = ResourceType_Patient;
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
728 uidMap_.clear();
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
729 privateTagsToKeep_.clear();
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
730
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
731 switch (version)
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
732 {
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
733 case DicomVersion_2008:
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
734 SetupAnonymization2008();
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
735 break;
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
736
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
737 case DicomVersion_2017c:
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
738 SetupAnonymization2017c();
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
739 break;
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
740
4677
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
741 case DicomVersion_2021b:
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
742 SetupAnonymization2021b();
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
743 break;
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
744
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
745 default:
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
746 throw OrthancException(ErrorCode_ParameterOutOfRange);
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2277
diff changeset
747 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 // Set the PatientIdentityRemoved tag
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
750 ReplaceInternal(DicomTag(0x0012, 0x0062), "YES");
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 // (*) Choose a random patient name and ID
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
753 std::string patientId = FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient);
1698
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
754 ReplaceInternal(DICOM_TAG_PATIENT_ID, patientId);
d78b87f93bcf DicomModification use Json::Value
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1695
diff changeset
755 ReplaceInternal(DICOM_TAG_PATIENT_NAME, patientId);
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
756
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
757 // Sanity check
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
758 for (SetOfTags::const_iterator it = uids_.begin(); it != uids_.end(); ++it)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
759 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
760 ValueRepresentation vr = FromDcmtkBridge::LookupValueRepresentation(*it);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
761 if (vr != ValueRepresentation_UniqueIdentifier &&
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
762 vr != ValueRepresentation_NotSupported /* for older versions of DCMTK */)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
763 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
764 throw OrthancException(ErrorCode_InternalError);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
765 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
766 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 void DicomModification::Apply(ParsedDicomFile& toModify)
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 // Check the request
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
772 assert(ResourceType_Patient + 1 == ResourceType_Study &&
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
773 ResourceType_Study + 1 == ResourceType_Series &&
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
774 ResourceType_Series + 1 == ResourceType_Instance);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 if (IsRemoved(DICOM_TAG_PATIENT_ID) ||
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 IsRemoved(DICOM_TAG_STUDY_INSTANCE_UID) ||
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 IsRemoved(DICOM_TAG_SERIES_INSTANCE_UID) ||
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 IsRemoved(DICOM_TAG_SOP_INSTANCE_UID))
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 throw OrthancException(ErrorCode_BadRequest);
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 }
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
783
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
785 // Sanity checks at the patient level
788
7ebe4bf87196 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 787
diff changeset
786 if (level_ == ResourceType_Patient && !IsReplaced(DICOM_TAG_PATIENT_ID))
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
788 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
789 "When modifying a patient, her PatientID is required to be modified");
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
792 if (!allowManualIdentifiers_)
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
793 {
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
794 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
795 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
796 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
797 "When modifying a patient, the StudyInstanceUID cannot be manually modified");
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
798 }
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
799
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
800 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
801 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
802 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
803 "When modifying a patient, the SeriesInstanceUID cannot be manually modified");
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
804 }
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
805
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
806 if (level_ == ResourceType_Patient && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
807 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
808 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
809 "When modifying a patient, the SopInstanceUID cannot be manually modified");
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
810 }
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
811 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
812
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
813
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
814 // Sanity checks at the study level
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
815 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_PATIENT_ID))
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
816 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
817 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
818 "When modifying a study, the parent PatientID cannot be manually modified");
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
819 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
820
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
821 if (!allowManualIdentifiers_)
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
822 {
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
823 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
824 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
825 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
826 "When modifying a study, the SeriesInstanceUID cannot be manually modified");
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
827 }
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
828
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
829 if (level_ == ResourceType_Study && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
830 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
831 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
832 "When modifying a study, the SopInstanceUID cannot be manually modified");
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
833 }
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
834 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
835
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
837 // Sanity checks at the series level
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
838 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_PATIENT_ID))
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
839 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
840 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
841 "When modifying a series, the parent PatientID cannot be manually modified");
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
842 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
843
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
844 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
846 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
847 "When modifying a series, the parent StudyInstanceUID cannot be manually modified");
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
848 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
849
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
850 if (!allowManualIdentifiers_)
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
851 {
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
852 if (level_ == ResourceType_Series && IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
853 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
854 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
855 "When modifying a series, the SopInstanceUID cannot be manually modified");
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
856 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
859
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
860 // Sanity checks at the instance level
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
861 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_PATIENT_ID))
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
863 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
864 "When modifying an instance, the parent PatientID cannot be manually modified");
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
867 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
868 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
869 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
870 "When modifying an instance, the parent StudyInstanceUID cannot be manually modified");
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
871 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
872
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
873 if (level_ == ResourceType_Instance && IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
874 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
875 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
876 "When modifying an instance, the parent SeriesInstanceUID cannot be manually modified");
1160
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
877 }
80671157d051 generalization of create-dicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
878
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
879 // (0) Create a summary of the source file, if a custom generator
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
880 // is provided
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
881 if (identifierGenerator_ != NULL)
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
882 {
4139
a4f28efdfccf "maxTagLength" must be explicitly given to ParsedDicomFile::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
883 toModify.ExtractDicomSummary(currentSource_, ORTHANC_MAXIMUM_TAG_LENGTH);
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
884 }
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
885
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
886 // (1) Make sure the relationships are updated with the ids that we force too
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
887 // i.e: an RT-STRUCT is referencing its own StudyInstanceUID
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
888 if (isAnonymization_ && updateReferencedRelationships_)
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
889 {
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
890 if (IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
891 {
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
892 std::string original;
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
893 std::string replacement = GetReplacementAsString(DICOM_TAG_STUDY_INSTANCE_UID);
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
894 const_cast<const ParsedDicomFile&>(toModify).GetTagValue(original, DICOM_TAG_STUDY_INSTANCE_UID);
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
895 RegisterMappedDicomIdentifier(original, replacement, ResourceType_Study);
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
896 }
2535
d3476d90dcb7 DicomModification::SetDicomIdentifierGenerator()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
897
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
898 if (IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
899 {
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
900 std::string original;
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
901 std::string replacement = GetReplacementAsString(DICOM_TAG_SERIES_INSTANCE_UID);
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
902 const_cast<const ParsedDicomFile&>(toModify).GetTagValue(original, DICOM_TAG_SERIES_INSTANCE_UID);
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
903 RegisterMappedDicomIdentifier(original, replacement, ResourceType_Series);
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
904 }
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
905
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
906 if (IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
907 {
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
908 std::string original;
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
909 std::string replacement = GetReplacementAsString(DICOM_TAG_SOP_INSTANCE_UID);
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
910 const_cast<const ParsedDicomFile&>(toModify).GetTagValue(original, DICOM_TAG_SOP_INSTANCE_UID);
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
911 RegisterMappedDicomIdentifier(original, replacement, ResourceType_Instance);
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
912 }
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
913 }
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
914
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
915
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
916 // (2) Remove the private tags, if need be
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 if (removePrivateTags_)
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 {
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 916
diff changeset
919 toModify.RemovePrivateTags(privateTagsToKeep_);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
922 // (3) Clear the tags specified by the user
2310
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
923 for (SetOfTags::const_iterator it = clearings_.begin();
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
924 it != clearings_.end(); ++it)
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
925 {
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
926 toModify.Clear(*it, true /* only clear if the tag exists in the original file */);
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
927 }
b7fba68747f6 DicomModification::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
928
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
929 // (4) Remove the tags specified by the user
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 916
diff changeset
930 for (SetOfTags::const_iterator it = removals_.begin();
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 it != removals_.end(); ++it)
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 {
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 toModify.Remove(*it);
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
936 // (5) Replace the tags
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 for (Replacements::const_iterator it = replacements_.begin();
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 it != replacements_.end(); ++it)
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 {
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
940 toModify.Replace(it->first, *it->second, true /* decode data URI scheme */,
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
941 DicomReplaceMode_InsertIfAbsent, privateCreator_);
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
944 // (6) Update the DICOM identifiers
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
945 if (level_ <= ResourceType_Study &&
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
946 !IsReplaced(DICOM_TAG_STUDY_INSTANCE_UID))
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 {
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
948 if (keepStudyInstanceUid_)
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
949 {
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
950 LOG(WARNING) << "Modifying a study while keeping its original StudyInstanceUID: This should be avoided!";
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
951 }
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
952 else
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
953 {
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
954 MapDicomTags(toModify, ResourceType_Study);
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
955 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
958 if (level_ <= ResourceType_Series &&
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
959 !IsReplaced(DICOM_TAG_SERIES_INSTANCE_UID))
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 {
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
961 if (keepSeriesInstanceUid_)
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
962 {
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
963 LOG(WARNING) << "Modifying a series while keeping its original SeriesInstanceUID: This should be avoided!";
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
964 }
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
965 else
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
966 {
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
967 MapDicomTags(toModify, ResourceType_Series);
2194
3b40ca7470cc "Keep" option for modifications to keep original DICOM identifiers (advanced feature)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
968 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970
1279
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
971 if (level_ <= ResourceType_Instance && // Always true
7f3a65e84d4b More flexible /modify and /anonymize for single instance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1160
diff changeset
972 !IsReplaced(DICOM_TAG_SOP_INSTANCE_UID))
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 {
3860
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
974 if (keepSopInstanceUid_)
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
975 {
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
976 LOG(WARNING) << "Modifying an instance while keeping its original SOPInstanceUID: This should be avoided!";
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
977 }
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
978 else
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
979 {
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
980 MapDicomTags(toModify, ResourceType_Instance);
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
981 }
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
982 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
983
3513
7db879b014ff Fix lost relationships between CT and RT-STRUCT during anonymization
amazy
parents: 3344
diff changeset
984 // (7) Update the "referenced" relationships in the case of an anonymization
2721
062776ab4a21 fix issue #94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
985 if (isAnonymization_)
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
986 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
987 RelationshipsVisitor visitor(*this);
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
988
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
989 if (updateReferencedRelationships_)
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
990 {
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
991 const_cast<const ParsedDicomFile&>(toModify).Apply(visitor);
2506
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
992 }
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
993 else
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
994 {
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
995 visitor.RemoveRelationships(toModify);
51b91ead6c38 Preservation of UID relationships while anonymizing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
996 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 }
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 }
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
999
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1000 void DicomModification::SetAllowManualIdentifiers(bool check)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1001 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1002 allowManualIdentifiers_ = check;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1003 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1004
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1005 bool DicomModification::AreAllowManualIdentifiers() const
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1006 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1007 return allowManualIdentifiers_;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1008 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1009
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1010
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1011 static bool IsDatabaseKey(const DicomTag& tag)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1012 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1013 return (tag == DICOM_TAG_PATIENT_ID ||
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1014 tag == DICOM_TAG_STUDY_INSTANCE_UID ||
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1015 tag == DICOM_TAG_SERIES_INSTANCE_UID ||
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1016 tag == DICOM_TAG_SOP_INSTANCE_UID);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1017 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1018
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1019
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1020 static void ParseListOfTags(DicomModification& target,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1021 const Json::Value& query,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1022 DicomModification::TagOperation operation,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1023 bool force)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1024 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1025 if (!query.isArray())
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1026 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1027 throw OrthancException(ErrorCode_BadRequest);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1028 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1029
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1030 for (Json::Value::ArrayIndex i = 0; i < query.size(); i++)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1031 {
2844
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2721
diff changeset
1032 if (query[i].type() != Json::stringValue)
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2721
diff changeset
1033 {
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2721
diff changeset
1034 throw OrthancException(ErrorCode_BadRequest);
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2721
diff changeset
1035 }
99863d6245b2 New URI: "/studies/.../split" to split a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2721
diff changeset
1036
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1037 std::string name = query[i].asString();
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1038
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1039 DicomTag tag = FromDcmtkBridge::ParseTag(name);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1040
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1041 if (!force && IsDatabaseKey(tag))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1042 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1043 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1044 "Marking tag \"" + name + "\" as to be " +
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1045 (operation == DicomModification::TagOperation_Keep ? "kept" : "removed") +
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1046 " requires the \"Force\" option to be set to true");
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1047 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1048
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1049 switch (operation)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1050 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1051 case DicomModification::TagOperation_Keep:
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1052 target.Keep(tag);
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
1053 LOG(TRACE) << "Keep: " << name << " (" << tag.Format() << ")";
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1054 break;
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1055
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1056 case DicomModification::TagOperation_Remove:
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1057 target.Remove(tag);
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
1058 LOG(TRACE) << "Remove: " << name << " (" << tag.Format() << ")";
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1059 break;
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1060
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1061 default:
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1062 throw OrthancException(ErrorCode_InternalError);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1063 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1064 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1065 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1066
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1067
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1068 static void ParseReplacements(DicomModification& target,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1069 const Json::Value& replacements,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1070 bool force)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1071 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1072 if (!replacements.isObject())
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1073 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1074 throw OrthancException(ErrorCode_BadRequest);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1075 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1076
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1077 Json::Value::Members members = replacements.getMemberNames();
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1078 for (size_t i = 0; i < members.size(); i++)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1079 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1080 const std::string& name = members[i];
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1081 const Json::Value& value = replacements[name];
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1082
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1083 DicomTag tag = FromDcmtkBridge::ParseTag(name);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1084
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1085 if (!force && IsDatabaseKey(tag))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1086 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1087 throw OrthancException(ErrorCode_BadRequest,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1088 "Marking tag \"" + name + "\" as to be replaced " +
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1089 "requires the \"Force\" option to be set to true");
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1090 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1091
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1092 target.Replace(tag, value, false);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1093
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
1094 LOG(TRACE) << "Replace: " << name << " (" << tag.Format()
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
1095 << ") == " << value.toStyledString();
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1096 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1097 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1098
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1099
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1100 static bool GetBooleanValue(const std::string& member,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1101 const Json::Value& json,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1102 bool defaultValue)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1103 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1104 if (!json.isMember(member))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1105 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1106 return defaultValue;
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1107 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1108 else if (json[member].type() == Json::booleanValue)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1109 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1110 return json[member].asBool();
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1111 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1112 else
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1113 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1114 throw OrthancException(ErrorCode_BadFileFormat,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1115 "Member \"" + member + "\" should be a Boolean value");
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1116 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1117 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1118
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1119
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1120 void DicomModification::ParseModifyRequest(const Json::Value& request)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1121 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1122 if (!request.isObject())
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1123 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1124 throw OrthancException(ErrorCode_BadFileFormat);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1125 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1126
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1127 bool force = GetBooleanValue("Force", request, false);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1128
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1129 if (GetBooleanValue("RemovePrivateTags", request, false))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1130 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1131 SetRemovePrivateTags(true);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1132 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1133
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1134 if (request.isMember("Remove"))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1135 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1136 ParseListOfTags(*this, request["Remove"], TagOperation_Remove, force);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1137 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1138
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1139 if (request.isMember("Replace"))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1140 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1141 ParseReplacements(*this, request["Replace"], force);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1142 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1143
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1144 // The "Keep" operation only makes sense for the tags
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1145 // StudyInstanceUID, SeriesInstanceUID and SOPInstanceUID. Avoid
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1146 // this feature as much as possible, as this breaks the DICOM
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1147 // model of the real world, except if you know exactly what
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1148 // you're doing!
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1149 if (request.isMember("Keep"))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1150 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1151 ParseListOfTags(*this, request["Keep"], TagOperation_Keep, force);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1152 }
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1153
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1154 // New in Orthanc 1.6.0
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1155 if (request.isMember("PrivateCreator"))
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1156 {
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1157 privateCreator_ = SerializationToolbox::ReadString(request, "PrivateCreator");
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1158 }
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1159 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1160
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1161
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1162 void DicomModification::ParseAnonymizationRequest(bool& patientNameReplaced,
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1163 const Json::Value& request)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1164 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1165 if (!request.isObject())
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1166 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1167 throw OrthancException(ErrorCode_BadFileFormat);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1168 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1169
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1170 bool force = GetBooleanValue("Force", request, false);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1171
4677
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
1172 // DicomVersion version = DicomVersion_2008; // For Orthanc <= 1.2.0
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
1173 // DicomVersion version = DicomVersion_2017c; // For Orthanc between 1.3.0 and 1.9.3
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4676
diff changeset
1174 DicomVersion version = DicomVersion_2021b; // For Orthanc >= 1.9.4
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1175 if (request.isMember("DicomVersion"))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1176 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1177 if (request["DicomVersion"].type() != Json::stringValue)
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1178 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1179 throw OrthancException(ErrorCode_BadFileFormat);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1180 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1181 else
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1182 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1183 version = StringToDicomVersion(request["DicomVersion"].asString());
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1184 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1185 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1186
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1187 SetupAnonymization(version);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1188
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1189 std::string patientName = GetReplacementAsString(DICOM_TAG_PATIENT_NAME);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1190
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1191 if (GetBooleanValue("KeepPrivateTags", request, false))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1192 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1193 SetRemovePrivateTags(false);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1194 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1195
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1196 if (request.isMember("Remove"))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1197 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1198 ParseListOfTags(*this, request["Remove"], TagOperation_Remove, force);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1199 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1200
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1201 if (request.isMember("Replace"))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1202 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1203 ParseReplacements(*this, request["Replace"], force);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1204 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1205
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1206 if (request.isMember("Keep"))
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1207 {
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1208 ParseListOfTags(*this, request["Keep"], TagOperation_Keep, force);
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1209 }
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1210
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1211 patientNameReplaced = (IsReplaced(DICOM_TAG_PATIENT_NAME) &&
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1212 GetReplacement(DICOM_TAG_PATIENT_NAME) == patientName);
3709
1f4910999fe7 Fix issue #168 (Plugins can't read private tags from the configuration file)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1213
1f4910999fe7 Fix issue #168 (Plugins can't read private tags from the configuration file)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1214 // New in Orthanc 1.6.0
1f4910999fe7 Fix issue #168 (Plugins can't read private tags from the configuration file)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1215 if (request.isMember("PrivateCreator"))
1f4910999fe7 Fix issue #168 (Plugins can't read private tags from the configuration file)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1216 {
1f4910999fe7 Fix issue #168 (Plugins can't read private tags from the configuration file)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1217 privateCreator_ = SerializationToolbox::ReadString(request, "PrivateCreator");
1f4910999fe7 Fix issue #168 (Plugins can't read private tags from the configuration file)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1218 }
2519
2e6b7862ccf2 ParseAnonymizationRequest/ParseModifyRequest now in DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2506
diff changeset
1219 }
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2535
diff changeset
1220
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1221 void DicomModification::SetDicomIdentifierGenerator(DicomModification::IDicomIdentifierGenerator &generator)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1222 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1223 identifierGenerator_ = &generator;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1224 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1225
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1226
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1227
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1228
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1229 static const char* REMOVE_PRIVATE_TAGS = "RemovePrivateTags";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1230 static const char* LEVEL = "Level";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1231 static const char* ALLOW_MANUAL_IDENTIFIERS = "AllowManualIdentifiers";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1232 static const char* KEEP_STUDY_INSTANCE_UID = "KeepStudyInstanceUID";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1233 static const char* KEEP_SERIES_INSTANCE_UID = "KeepSeriesInstanceUID";
3860
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
1234 static const char* KEEP_SOP_INSTANCE_UID = "KeepSOPInstanceUID";
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1235 static const char* UPDATE_REFERENCED_RELATIONSHIPS = "UpdateReferencedRelationships";
2721
062776ab4a21 fix issue #94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1236 static const char* IS_ANONYMIZATION = "IsAnonymization";
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1237 static const char* REMOVALS = "Removals";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1238 static const char* CLEARINGS = "Clearings";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1239 static const char* PRIVATE_TAGS_TO_KEEP = "PrivateTagsToKeep";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1240 static const char* REPLACEMENTS = "Replacements";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1241 static const char* MAP_PATIENTS = "MapPatients";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1242 static const char* MAP_STUDIES = "MapStudies";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1243 static const char* MAP_SERIES = "MapSeries";
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1244 static const char* MAP_INSTANCES = "MapInstances";
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1245 static const char* PRIVATE_CREATOR = "PrivateCreator"; // New in Orthanc 1.6.0
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1246 static const char* UIDS = "Uids"; // New in Orthanc 1.9.4
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1247 static const char* REMOVED_RANGES = "RemovedRanges"; // New in Orthanc 1.9.4
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2535
diff changeset
1248
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2535
diff changeset
1249 void DicomModification::Serialize(Json::Value& value) const
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2535
diff changeset
1250 {
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1251 if (identifierGenerator_ != NULL)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1252 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1253 throw OrthancException(ErrorCode_InternalError,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2844
diff changeset
1254 "Cannot serialize a DicomModification with a custom identifier generator");
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1255 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1256
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1257 value = Json::objectValue;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1258 value[REMOVE_PRIVATE_TAGS] = removePrivateTags_;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1259 value[LEVEL] = EnumerationToString(level_);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1260 value[ALLOW_MANUAL_IDENTIFIERS] = allowManualIdentifiers_;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1261 value[KEEP_STUDY_INSTANCE_UID] = keepStudyInstanceUid_;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1262 value[KEEP_SERIES_INSTANCE_UID] = keepSeriesInstanceUid_;
3860
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
1263 value[KEEP_SOP_INSTANCE_UID] = keepSopInstanceUid_;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1264 value[UPDATE_REFERENCED_RELATIONSHIPS] = updateReferencedRelationships_;
2721
062776ab4a21 fix issue #94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1265 value[IS_ANONYMIZATION] = isAnonymization_;
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1266 value[PRIVATE_CREATOR] = privateCreator_;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1267
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1268 SerializationToolbox::WriteSetOfTags(value, removals_, REMOVALS);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1269 SerializationToolbox::WriteSetOfTags(value, clearings_, CLEARINGS);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1270 SerializationToolbox::WriteSetOfTags(value, privateTagsToKeep_, PRIVATE_TAGS_TO_KEEP);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1271
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1272 Json::Value& tmp = value[REPLACEMENTS];
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1273
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1274 tmp = Json::objectValue;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1275
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1276 for (Replacements::const_iterator it = replacements_.begin();
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1277 it != replacements_.end(); ++it)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1278 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1279 assert(it->second != NULL);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1280 tmp[it->first.Format()] = *it->second;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1281 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1282
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1283 Json::Value& mapPatients = value[MAP_PATIENTS];
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1284 Json::Value& mapStudies = value[MAP_STUDIES];
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1285 Json::Value& mapSeries = value[MAP_SERIES];
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1286 Json::Value& mapInstances = value[MAP_INSTANCES];
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1287
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1288 mapPatients = Json::objectValue;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1289 mapStudies = Json::objectValue;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1290 mapSeries = Json::objectValue;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1291 mapInstances = Json::objectValue;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1292
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1293 for (UidMap::const_iterator it = uidMap_.begin(); it != uidMap_.end(); ++it)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1294 {
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
1295 Json::Value* tmp2 = NULL;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1296
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1297 switch (it->first.first)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1298 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1299 case ResourceType_Patient:
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
1300 tmp2 = &mapPatients;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1301 break;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1302
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1303 case ResourceType_Study:
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
1304 tmp2 = &mapStudies;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1305 break;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1306
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1307 case ResourceType_Series:
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
1308 tmp2 = &mapSeries;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1309 break;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1310
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1311 case ResourceType_Instance:
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
1312 tmp2 = &mapInstances;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1313 break;
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1314
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1315 default:
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1316 throw OrthancException(ErrorCode_InternalError);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1317 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1318
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
1319 assert(tmp2 != NULL);
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4139
diff changeset
1320 (*tmp2) [it->first.second] = it->second;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1321 }
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1322
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1323 // New in Orthanc 1.9.4
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1324 SerializationToolbox::WriteSetOfTags(value, uids_, UIDS);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1325
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1326 // New in Orthanc 1.9.4
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1327 Json::Value ranges = Json::arrayValue;
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1328
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1329 for (RemovedRanges::const_iterator it = removedRanges_.begin(); it != removedRanges_.end(); ++it)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1330 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1331 Json::Value item = Json::arrayValue;
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1332 item.append(it->GetGroupFrom());
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1333 item.append(it->GetGroupTo());
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1334 item.append(it->GetElementFrom());
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1335 item.append(it->GetElementTo());
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1336 ranges.append(item);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1337 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1338
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1339 value[REMOVED_RANGES] = ranges;
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1340 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1341
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1342 void DicomModification::UnserializeUidMap(ResourceType level,
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1343 const Json::Value& serialized,
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1344 const char* field)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1345 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1346 if (!serialized.isMember(field) ||
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1347 serialized[field].type() != Json::objectValue)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1348 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1349 throw OrthancException(ErrorCode_BadFileFormat);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1350 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1351
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1352 Json::Value::Members names = serialized[field].getMemberNames();
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1353
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1354 for (Json::Value::Members::const_iterator it = names.begin(); it != names.end(); ++it)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1355 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1356 const Json::Value& value = serialized[field][*it];
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1357
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1358 if (value.type() != Json::stringValue)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1359 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1360 throw OrthancException(ErrorCode_BadFileFormat);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1361 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1362 else
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1363 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1364 uidMap_[std::make_pair(level, *it)] = value.asString();
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1365 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1366 }
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
1367 }
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
1368
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
1369
2666
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
1370 DicomModification::DicomModification(const Json::Value& serialized) :
2540ac79ab6c SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2662
diff changeset
1371 identifierGenerator_(NULL)
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
1372 {
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1373 removePrivateTags_ = SerializationToolbox::ReadBoolean(serialized, REMOVE_PRIVATE_TAGS);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1374 level_ = StringToResourceType(SerializationToolbox::ReadString(serialized, LEVEL).c_str());
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1375 allowManualIdentifiers_ = SerializationToolbox::ReadBoolean(serialized, ALLOW_MANUAL_IDENTIFIERS);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1376 keepStudyInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_STUDY_INSTANCE_UID);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1377 keepSeriesInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SERIES_INSTANCE_UID);
3860
9ccbbd55bc23 allow Keeping the SOPInstanceUID in /instances/../modify
Alain Mazy <alain@mazy.be>
parents: 3712
diff changeset
1378 keepSopInstanceUid_ = SerializationToolbox::ReadBoolean(serialized, KEEP_SOP_INSTANCE_UID);
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1379 updateReferencedRelationships_ = SerializationToolbox::ReadBoolean
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1380 (serialized, UPDATE_REFERENCED_RELATIONSHIPS);
2721
062776ab4a21 fix issue #94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2666
diff changeset
1381 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION);
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1382
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1383 if (serialized.isMember(PRIVATE_CREATOR))
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1384 {
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1385 privateCreator_ = SerializationToolbox::ReadString(serialized, PRIVATE_CREATOR);
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1386 }
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1387
2662
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1388 SerializationToolbox::ReadSetOfTags(removals_, serialized, REMOVALS);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1389 SerializationToolbox::ReadSetOfTags(clearings_, serialized, CLEARINGS);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1390 SerializationToolbox::ReadSetOfTags(privateTagsToKeep_, serialized, PRIVATE_TAGS_TO_KEEP);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1391
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1392 if (!serialized.isMember(REPLACEMENTS) ||
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1393 serialized[REPLACEMENTS].type() != Json::objectValue)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1394 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1395 throw OrthancException(ErrorCode_BadFileFormat);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1396 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1397
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1398 Json::Value::Members names = serialized[REPLACEMENTS].getMemberNames();
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1399
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1400 for (Json::Value::Members::const_iterator it = names.begin(); it != names.end(); ++it)
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1401 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1402 DicomTag tag(0, 0);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1403 if (!DicomTag::ParseHexadecimal(tag, it->c_str()))
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1404 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1405 throw OrthancException(ErrorCode_BadFileFormat);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1406 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1407 else
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1408 {
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1409 const Json::Value& value = serialized[REPLACEMENTS][*it];
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1410 replacements_.insert(std::make_pair(tag, new Json::Value(value)));
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1411 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1412 }
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1413
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1414 UnserializeUidMap(ResourceType_Patient, serialized, MAP_PATIENTS);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1415 UnserializeUidMap(ResourceType_Study, serialized, MAP_STUDIES);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1416 UnserializeUidMap(ResourceType_Series, serialized, MAP_SERIES);
47d812308d63 serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
1417 UnserializeUidMap(ResourceType_Instance, serialized, MAP_INSTANCES);
4678
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1418
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1419 // New in Orthanc 1.9.4
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1420 if (serialized.isMember(UIDS)) // Backward compatibility with Orthanc <= 1.9.3
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1421 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1422 SerializationToolbox::ReadSetOfTags(uids_, serialized, UIDS);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1423 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1424 else
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1425 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1426 SetupUidsFromOrthanc_1_9_3();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1427 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1428
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1429 // New in Orthanc 1.9.4
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1430 removedRanges_.clear();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1431 if (serialized.isMember(REMOVED_RANGES)) // Backward compatibility with Orthanc <= 1.9.3
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1432 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1433 const Json::Value& ranges = serialized[REMOVED_RANGES];
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1434
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1435 if (ranges.type() != Json::arrayValue)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1436 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1437 throw OrthancException(ErrorCode_BadFileFormat);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1438 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1439 else
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1440 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1441 for (Json::Value::ArrayIndex i = 0; i < ranges.size(); i++)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1442 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1443 if (ranges[i].type() != Json::arrayValue ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1444 ranges[i].size() != 4 ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1445 !ranges[i][0].isUInt() ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1446 !ranges[i][1].isUInt() ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1447 !ranges[i][2].isUInt() ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1448 !ranges[i][3].isUInt())
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1449 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1450 throw OrthancException(ErrorCode_BadFileFormat);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1451 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1452 else
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1453 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1454 Json::LargestUInt groupFrom = ranges[i][0].asUInt();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1455 Json::LargestUInt groupTo = ranges[i][1].asUInt();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1456 Json::LargestUInt elementFrom = ranges[i][2].asUInt();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1457 Json::LargestUInt elementTo = ranges[i][3].asUInt();
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1458
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1459 if (groupFrom > groupTo ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1460 elementFrom > elementTo ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1461 groupTo > 0xffffu ||
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1462 elementTo > 0xffffu)
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1463 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1464 throw OrthancException(ErrorCode_BadFileFormat);
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1465 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1466 else
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1467 {
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1468 removedRanges_.push_back(DicomTagRange(groupFrom, groupTo, elementFrom, elementTo));
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1469 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1470 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1471 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1472 }
2e850edf03d6 Full support for the anonymization of subsequences containing tags whose VR is UI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4677
diff changeset
1473 }
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2535
diff changeset
1474 }
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1475
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1476
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1477 void DicomModification::SetPrivateCreator(const std::string &privateCreator)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1478 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1479 privateCreator_ = privateCreator;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1480 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1481
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1482 const std::string &DicomModification::GetPrivateCreator() const
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1483 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1484 return privateCreator_;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
1485 }
786
b6d6b65142e8 DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 }