Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp @ 4802:6a23cd1fc66b
fix news
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 19 Oct 2021 17:00:23 +0200 |
parents | 45bce660ce3a |
children | f0038043fb97 94616af363ec |
rev | line source |
---|---|
2642 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4223
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
2642 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeadersServer.h" | |
35 #include "ResourceModificationJob.h" | |
36 | |
4045 | 37 #include "../../../OrthancFramework/Sources/Logging.h" |
38 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" | |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
39 #include "../ServerContext.h" |
2642 | 40 |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
41 #include <dcmtk/dcmdata/dcfilefo.h> |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
42 #include <dcmtk/dcmdata/dcdeftag.h> |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
43 #include <cassert> |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
44 |
2642 | 45 namespace Orthanc |
46 { | |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
47 static void FormatResource(Json::Value& target, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
48 ResourceType level, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
49 const std::string& id) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
50 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
51 target["Type"] = EnumerationToString(level); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
52 target["ID"] = id; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
53 target["Path"] = GetBasePath(level, id); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
54 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
55 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
56 class ResourceModificationJob::SingleOutput : public IOutput |
2642 | 57 { |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
58 private: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
59 ResourceType level_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
60 bool isFirst_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
61 std::string id_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
62 std::string patientId_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
63 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
64 public: |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
65 explicit SingleOutput(ResourceType level) : |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
66 level_(level), |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
67 isFirst_(true) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
68 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
69 if (level_ != ResourceType_Patient && |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
70 level_ != ResourceType_Study && |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
71 level_ != ResourceType_Series) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
72 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
73 throw OrthancException(ErrorCode_ParameterOutOfRange); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
74 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
75 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
76 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
77 virtual void Update(DicomInstanceHasher& hasher) ORTHANC_OVERRIDE |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
78 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
79 if (isFirst_) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
80 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
81 switch (level_) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
82 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
83 case ResourceType_Series: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
84 id_ = hasher.HashSeries(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
85 break; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
86 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
87 case ResourceType_Study: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
88 id_ = hasher.HashStudy(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
89 break; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
90 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
91 case ResourceType_Patient: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
92 id_ = hasher.HashPatient(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
93 break; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
94 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
95 default: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
96 throw OrthancException(ErrorCode_InternalError); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
97 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
98 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
99 patientId_ = hasher.HashPatient(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
100 isFirst_ = false; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
101 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
102 } |
2642 | 103 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
104 virtual void Format(Json::Value& target) const ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
105 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
106 assert(target.type() == Json::objectValue); |
2642 | 107 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
108 if (!isFirst_) |
2642 | 109 { |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
110 FormatResource(target, level_, id_); |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
111 target["PatientID"] = patientId_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
112 } |
2642 | 113 } |
114 | |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
115 virtual bool IsSingleResource() const ORTHANC_OVERRIDE |
2642 | 116 { |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
117 return true; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
118 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
119 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
120 ResourceType GetLevel() const |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
121 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
122 return level_; |
2642 | 123 } |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
124 }; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
125 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
126 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
127 class ResourceModificationJob::MultipleOutputs : public IOutput |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
128 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
129 private: |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
130 static void FormatResources(Json::Value& target, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
131 ResourceType level, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
132 const std::set<std::string>& resources) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
133 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
134 assert(target.type() == Json::arrayValue); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
135 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
136 for (std::set<std::string>::const_iterator |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
137 it = resources.begin(); it != resources.end(); ++it) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
138 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
139 Json::Value item = Json::objectValue; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
140 FormatResource(item, level, *it); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
141 target.append(item); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
142 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
143 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
144 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
145 std::set<std::string> instances_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
146 std::set<std::string> series_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
147 std::set<std::string> studies_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
148 std::set<std::string> patients_; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
149 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
150 public: |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
151 virtual void Update(DicomInstanceHasher& hasher) ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
152 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
153 instances_.insert(hasher.HashInstance()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
154 series_.insert(hasher.HashSeries()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
155 studies_.insert(hasher.HashStudy()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
156 patients_.insert(hasher.HashPatient()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
157 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
158 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
159 virtual void Format(Json::Value& target) const ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
160 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
161 assert(target.type() == Json::objectValue); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
162 Json::Value resources = Json::arrayValue; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
163 FormatResources(resources, ResourceType_Instance, instances_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
164 FormatResources(resources, ResourceType_Series, series_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
165 FormatResources(resources, ResourceType_Study, studies_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
166 FormatResources(resources, ResourceType_Patient, patients_); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
167 target["Resources"] = resources; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
168 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
169 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
170 virtual bool IsSingleResource() const ORTHANC_OVERRIDE |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
171 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
172 return false; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
173 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
174 }; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
175 |
2642 | 176 |
177 | |
178 bool ResourceModificationJob::HandleInstance(const std::string& instance) | |
179 { | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
180 if (modification_.get() == NULL || |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
181 output_.get() == NULL) |
2642 | 182 { |
2955 | 183 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
184 "No modification was provided for this job"); | |
2642 | 185 } |
186 | |
187 | |
188 LOG(INFO) << "Modifying instance in a job: " << instance; | |
189 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
190 |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
191 /** |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
192 * Retrieve the original instance from the DICOM cache. |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
193 **/ |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
194 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
195 std::unique_ptr<DicomInstanceHasher> originalHasher; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
196 std::unique_ptr<ParsedDicomFile> modified; |
2642 | 197 |
198 try | |
199 { | |
3942
5b882ad2ffd0
"/{patients|studies|series}/.../modify": New option "KeepSource"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
200 ServerContext::DicomCacheLocker locker(GetContext(), instance); |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
201 ParsedDicomFile& original = locker.GetDicom(); |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
202 |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
203 originalHasher.reset(new DicomInstanceHasher(original.GetHasher())); |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
204 modified.reset(original.Clone(true)); |
2642 | 205 } |
3430 | 206 catch (OrthancException& e) |
2642 | 207 { |
3430 | 208 LOG(WARNING) << "An error occurred while executing a Modification job on instance " << instance << ": " << e.GetDetails(); |
2642 | 209 return false; |
210 } | |
211 | |
212 | |
213 /** | |
214 * Compute the resulting DICOM instance. | |
215 **/ | |
216 | |
217 modification_->Apply(*modified); | |
218 | |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
219 const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject()); |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
220 |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
221 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
222 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
223 std::set<DicomTransferSyntax> syntaxes; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
224 syntaxes.insert(transferSyntax_); |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
225 |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
226 IDicomTranscoder::DicomImage source; |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
227 source.AcquireParsed(*modified); // "modified" is invalid below this point |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
228 |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
229 IDicomTranscoder::DicomImage transcoded; |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3948
diff
changeset
|
230 if (GetContext().Transcode(transcoded, source, syntaxes, true)) |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
231 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
232 modified.reset(transcoded.ReleaseAsParsedDicomFile()); |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
233 |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
234 // Fix the SOP instance UID in order the preserve the |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
235 // references between instance UIDs in the DICOM hierarchy |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
236 // (the UID might have changed in the case of lossy transcoding) |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
237 if (modified.get() == NULL || |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
238 modified->GetDcmtkObject().getDataset() == NULL || |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
239 !modified->GetDcmtkObject().getDataset()->putAndInsertString( |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
240 DCM_SOPInstanceUID, modifiedUid.c_str(), OFTrue /* replace */).good()) |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
241 { |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
242 throw OrthancException(ErrorCode_InternalError); |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
243 } |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
244 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
245 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
246 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
247 LOG(WARNING) << "Cannot transcode instance, keeping original transfer syntax: " << instance; |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3943
diff
changeset
|
248 modified.reset(source.ReleaseAsParsedDicomFile()); |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
249 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
250 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
251 |
3948
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
252 assert(modifiedUid == IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject())); |
3d2fc1b5cc8c
ResourceModificationJob: Fix the SOP instance UID to preserve references
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
253 |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
254 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*modified)); |
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
255 toStore->SetOrigin(origin_); |
2642 | 256 |
257 | |
258 /** | |
259 * Prepare the metadata information to associate with the | |
260 * resulting DICOM instance (AnonymizedFrom/ModifiedFrom). | |
261 **/ | |
262 | |
263 DicomInstanceHasher modifiedHasher = modified->GetHasher(); | |
264 | |
265 MetadataType metadataType = (isAnonymization_ ? | |
266 MetadataType_AnonymizedFrom : | |
267 MetadataType_ModifiedFrom); | |
268 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
269 if (originalHasher->HashSeries() != modifiedHasher.HashSeries()) |
2642 | 270 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
271 toStore->AddMetadata(ResourceType_Series, metadataType, originalHasher->HashSeries()); |
2642 | 272 } |
273 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
274 if (originalHasher->HashStudy() != modifiedHasher.HashStudy()) |
2642 | 275 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
276 toStore->AddMetadata(ResourceType_Study, metadataType, originalHasher->HashStudy()); |
2642 | 277 } |
278 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
279 if (originalHasher->HashPatient() != modifiedHasher.HashPatient()) |
2642 | 280 { |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
281 toStore->AddMetadata(ResourceType_Patient, metadataType, originalHasher->HashPatient()); |
2642 | 282 } |
283 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
284 assert(instance == originalHasher->HashInstance()); |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
285 toStore->AddMetadata(ResourceType_Instance, metadataType, instance); |
2642 | 286 |
287 | |
288 /** | |
289 * Store the resulting DICOM instance into the Orthanc store. | |
290 **/ | |
291 | |
292 std::string modifiedInstance; | |
4508
8f9090b137f1
Optimization in C-STORE SCP by avoiding an unnecessary DICOM parsing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
293 if (GetContext().Store(modifiedInstance, *toStore, |
3942
5b882ad2ffd0
"/{patients|studies|series}/.../modify": New option "KeepSource"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
294 StoreInstanceMode_Default) != StoreStatus_Success) |
2642 | 295 { |
2955 | 296 throw OrthancException(ErrorCode_CannotStoreInstance, |
297 "Error while storing a modified instance " + instance); | |
2642 | 298 } |
299 | |
3938 | 300 /** |
301 * The assertion below will fail if automated transcoding to a | |
302 * lossy transfer syntax is enabled in the Orthanc core, and if | |
303 * the source instance is not in this transfer syntax. | |
304 **/ | |
305 // assert(modifiedInstance == modifiedHasher.HashInstance()); | |
2642 | 306 |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
307 output_->Update(modifiedHasher); |
2642 | 308 |
309 return true; | |
310 } | |
311 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
312 |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
313 ResourceModificationJob::ResourceModificationJob(ServerContext& context) : |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
314 CleaningInstancesJob(context, true /* by default, keep source */), |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
315 isAnonymization_(false), |
4206 | 316 transcode_(false), |
317 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization | |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
318 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
319 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
320 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
321 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
322 void ResourceModificationJob::SetSingleResourceModification(DicomModification* modification, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
323 ResourceType outputLevel, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
324 bool isAnonymization) |
2642 | 325 { |
326 if (modification == NULL) | |
327 { | |
328 throw OrthancException(ErrorCode_NullPointer); | |
329 } | |
330 else if (IsStarted()) | |
331 { | |
332 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
333 } | |
334 else | |
335 { | |
336 modification_.reset(modification); | |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
337 output_.reset(new SingleOutput(outputLevel)); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
338 isAnonymization_ = isAnonymization; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
339 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
340 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
341 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
342 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
343 void ResourceModificationJob::SetMultipleResourcesModification(DicomModification* modification, |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
344 bool isAnonymization) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
345 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
346 if (modification == NULL) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
347 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
348 throw OrthancException(ErrorCode_NullPointer); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
349 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
350 else if (IsStarted()) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
351 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
352 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
353 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
354 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
355 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
356 modification_.reset(modification); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
357 output_.reset(new MultipleOutputs); |
2642 | 358 isAnonymization_ = isAnonymization; |
359 } | |
360 } | |
361 | |
362 | |
363 void ResourceModificationJob::SetOrigin(const DicomInstanceOrigin& origin) | |
364 { | |
365 if (IsStarted()) | |
366 { | |
367 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
368 } | |
369 else | |
370 { | |
371 origin_ = origin; | |
372 } | |
373 } | |
374 | |
375 | |
376 void ResourceModificationJob::SetOrigin(const RestApiCall& call) | |
377 { | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
378 SetOrigin(DicomInstanceOrigin::FromRest(call)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
379 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
380 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
381 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
382 const DicomModification& ResourceModificationJob::GetModification() const |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
383 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
384 if (modification_.get() == NULL) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
385 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
386 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
387 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
388 else |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
389 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
390 return *modification_; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
391 } |
2642 | 392 } |
393 | |
394 | |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
395 DicomTransferSyntax ResourceModificationJob::GetTransferSyntax() const |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
396 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
397 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
398 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
399 return transferSyntax_; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
400 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
401 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
402 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
403 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
404 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
405 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
406 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
407 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
408 void ResourceModificationJob::SetTranscode(DicomTransferSyntax syntax) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
409 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
410 if (IsStarted()) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
411 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
412 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
413 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
414 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
415 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
416 transcode_ = true; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
417 transferSyntax_ = syntax; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
418 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
419 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
420 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
421 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
422 void ResourceModificationJob::SetTranscode(const std::string& transferSyntaxUid) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
423 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
424 DicomTransferSyntax s; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
425 if (LookupTransferSyntax(s, transferSyntaxUid)) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
426 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
427 SetTranscode(s); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
428 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
429 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
430 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
431 throw OrthancException(ErrorCode_BadFileFormat, |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
432 "Unknown transfer syntax UID: " + transferSyntaxUid); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
433 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
434 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
435 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
436 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
437 void ResourceModificationJob::ClearTranscode() |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
438 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
439 if (IsStarted()) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
440 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
441 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
442 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
443 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
444 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
445 transcode_ = false; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
446 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
447 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
448 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
449 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
450 bool ResourceModificationJob::IsSingleResourceModification() const |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
451 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
452 if (modification_.get() == NULL) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
453 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
454 assert(output_.get() == NULL); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
455 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
456 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
457 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
458 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
459 assert(output_.get() != NULL); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
460 return output_->IsSingleResource(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
461 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
462 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
463 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
464 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
465 ResourceType ResourceModificationJob::GetOutputLevel() const |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
466 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
467 if (IsSingleResourceModification()) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
468 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
469 assert(modification_.get() != NULL && |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
470 output_.get() != NULL); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
471 return dynamic_cast<const SingleOutput&>(*output_).GetLevel(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
472 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
473 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
474 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
475 // Not applicable if multiple resources |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
476 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
477 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
478 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
479 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
480 |
2642 | 481 void ResourceModificationJob::GetPublicContent(Json::Value& value) |
482 { | |
3942
5b882ad2ffd0
"/{patients|studies|series}/.../modify": New option "KeepSource"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
483 CleaningInstancesJob::GetPublicContent(value); |
2642 | 484 |
485 value["IsAnonymization"] = isAnonymization_; | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
486 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
487 if (output_.get() != NULL) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
488 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
489 output_->Format(value); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
490 } |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
491 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
492 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
493 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
494 value["Transcode"] = GetTransferSyntaxUid(transferSyntax_); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
495 } |
2642 | 496 } |
497 | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
498 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
499 static const char* MODIFICATION = "Modification"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
500 static const char* ORIGIN = "Origin"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
501 static const char* IS_ANONYMIZATION = "IsAnonymization"; |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
502 static const char* TRANSCODE = "Transcode"; |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
503 static const char* OUTPUT_LEVEL = "OutputLevel"; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
504 static const char* IS_SINGLE_RESOURCE = "IsSingleResource"; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
505 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
506 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
507 ResourceModificationJob::ResourceModificationJob(ServerContext& context, |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
508 const Json::Value& serialized) : |
4223 | 509 CleaningInstancesJob(context, serialized, true /* by default, keep source */), |
510 transferSyntax_(DicomTransferSyntax_LittleEndianExplicit) // dummy initialization | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
511 { |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
512 assert(serialized.type() == Json::objectValue); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
513 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
514 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
515 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
516 if (serialized.isMember(TRANSCODE)) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
517 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
518 SetTranscode(SerializationToolbox::ReadString(serialized, TRANSCODE)); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
519 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
520 else |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
521 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
522 transcode_ = false; |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
523 } |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
524 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
525 bool isSingleResource; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
526 if (serialized.isMember(IS_SINGLE_RESOURCE)) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
527 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
528 isSingleResource = SerializationToolbox::ReadBoolean(serialized, IS_SINGLE_RESOURCE); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
529 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
530 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
531 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
532 isSingleResource = true; // Backward compatibility with Orthanc <= 1.9.3 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
533 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
534 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
535 bool isAnonymization = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
536 std::unique_ptr<DicomModification> modification(new DicomModification(serialized[MODIFICATION])); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
537 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
538 if (isSingleResource) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
539 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
540 ResourceType outputLevel; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
541 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
542 if (serialized.isMember(OUTPUT_LEVEL)) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
543 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
544 // New in Orthanc 1.9.4. This fixes an *incorrect* behavior in |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
545 // Orthanc <= 1.9.3, in which "outputLevel" would be set to |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
546 // "modification->GetLevel()" |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
547 outputLevel = StringToResourceType(SerializationToolbox::ReadString(serialized, OUTPUT_LEVEL).c_str()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
548 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
549 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
550 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
551 // Use the buggy convention from Orthanc <= 1.9.3 (which is |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
552 // the only thing we have at hand) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
553 outputLevel = modification->GetLevel(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
554 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
555 if (outputLevel == ResourceType_Instance) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
556 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
557 // This should never happen, but as "SingleOutput" doesn't |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
558 // support instance-level anonymization, don't take any risk |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
559 // and choose an arbitrary output level |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
560 outputLevel = ResourceType_Patient; |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
561 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
562 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
563 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
564 SetSingleResourceModification(modification.release(), outputLevel, isAnonymization); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
565 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
566 else |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
567 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
568 // New in Orthanc 1.9.4 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
569 SetMultipleResourcesModification(modification.release(), isAnonymization); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
570 } |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
571 } |
2642 | 572 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
573 bool ResourceModificationJob::Serialize(Json::Value& value) |
2642 | 574 { |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
575 if (modification_.get() == NULL) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
576 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
577 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
578 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
579 else if (!CleaningInstancesJob::Serialize(value)) |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
580 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
581 return false; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
582 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
583 else |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
584 { |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
585 assert(value.type() == Json::objectValue); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
586 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
587 value[IS_ANONYMIZATION] = isAnonymization_; |
3943
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
588 |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
589 if (transcode_) |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
590 { |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
591 value[TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
592 } |
b26d25d3c1c7
"/{patients|studies|series}/.../modify": New option "Transcode"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3942
diff
changeset
|
593 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
594 origin_.Serialize(value[ORIGIN]); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
595 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
596 Json::Value tmp; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
597 modification_->Serialize(tmp); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
598 value[MODIFICATION] = tmp; |
2642 | 599 |
4693
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
600 // New in Orthanc 1.9.4 |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
601 value[IS_SINGLE_RESOURCE] = IsSingleResourceModification(); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
602 if (IsSingleResourceModification()) |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
603 { |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
604 value[OUTPUT_LEVEL] = EnumerationToString(GetOutputLevel()); |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
605 } |
45bce660ce3a
added routes for bulk anonymization/modification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4508
diff
changeset
|
606 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
607 return true; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
608 } |
2642 | 609 } |
610 } |