Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/ResourceModificationJob.cpp @ 2956:bfee0b9f3209
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Dec 2018 15:11:42 +0100 |
parents | bbfd95a0c429 |
children | 4e43e67f8ecf |
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 | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeadersServer.h" | |
35 #include "ResourceModificationJob.h" | |
36 | |
37 #include "../../Core/Logging.h" | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
38 #include "../../Core/SerializationToolbox.h" |
2642 | 39 |
40 namespace Orthanc | |
41 { | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
42 class ResourceModificationJob::Output : public boost::noncopyable |
2642 | 43 { |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
44 private: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
45 ResourceType level_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
46 bool isFirst_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
47 std::string id_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
48 std::string patientId_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
49 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
50 public: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
51 Output(ResourceType level) : |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
52 level_(level), |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
53 isFirst_(true) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
54 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
55 if (level_ != ResourceType_Patient && |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
56 level_ != ResourceType_Study && |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
57 level_ != ResourceType_Series) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
58 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
59 throw OrthancException(ErrorCode_ParameterOutOfRange); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
60 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
61 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
62 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
63 ResourceType GetLevel() const |
2642 | 64 { |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
65 return level_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
66 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
67 |
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 void Update(DicomInstanceHasher& hasher) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
70 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
71 if (isFirst_) |
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 switch (level_) |
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 case ResourceType_Series: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
76 id_ = hasher.HashSeries(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
77 break; |
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 case ResourceType_Study: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
80 id_ = hasher.HashStudy(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
81 break; |
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_Patient: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
84 id_ = hasher.HashPatient(); |
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 default: |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
88 throw OrthancException(ErrorCode_InternalError); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
89 } |
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 patientId_ = hasher.HashPatient(); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
92 isFirst_ = false; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
93 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
94 } |
2642 | 95 |
96 | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
97 bool Format(Json::Value& target) |
2642 | 98 { |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
99 if (isFirst_) |
2642 | 100 { |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
101 return false; |
2642 | 102 } |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
103 else |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
104 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
105 target = Json::objectValue; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
106 target["Type"] = EnumerationToString(level_); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
107 target["ID"] = id_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
108 target["Path"] = GetBasePath(level_, id_); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
109 target["PatientID"] = patientId_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
110 return true; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
111 } |
2642 | 112 } |
113 | |
114 | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
115 bool GetIdentifier(std::string& id) |
2642 | 116 { |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
117 if (isFirst_) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
118 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
119 return false; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
120 } |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
121 else |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
122 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
123 id = id_; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
124 return true; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
125 } |
2642 | 126 } |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
127 }; |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
128 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
129 |
2642 | 130 |
131 | |
132 bool ResourceModificationJob::HandleInstance(const std::string& instance) | |
133 { | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
134 if (modification_.get() == NULL || |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
135 output_.get() == NULL) |
2642 | 136 { |
2955 | 137 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
138 "No modification was provided for this job"); | |
2642 | 139 } |
140 | |
141 | |
142 LOG(INFO) << "Modifying instance in a job: " << instance; | |
143 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
144 |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
145 /** |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
146 * 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
|
147 **/ |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
148 |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
149 std::auto_ptr<DicomInstanceHasher> originalHasher; |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
150 std::auto_ptr<ParsedDicomFile> modified; |
2642 | 151 |
152 try | |
153 { | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
154 ServerContext::DicomCacheLocker locker(context_, instance); |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
155 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
|
156 |
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
157 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
|
158 modified.reset(original.Clone(true)); |
2642 | 159 } |
160 catch (OrthancException&) | |
161 { | |
162 LOG(WARNING) << "An instance was removed after the job was issued: " << instance; | |
163 return false; | |
164 } | |
165 | |
166 | |
167 /** | |
168 * Compute the resulting DICOM instance. | |
169 **/ | |
170 | |
171 modification_->Apply(*modified); | |
172 | |
173 DicomInstanceToStore toStore; | |
174 toStore.SetOrigin(origin_); | |
175 toStore.SetParsedDicomFile(*modified); | |
176 | |
177 | |
178 /** | |
179 * Prepare the metadata information to associate with the | |
180 * resulting DICOM instance (AnonymizedFrom/ModifiedFrom). | |
181 **/ | |
182 | |
183 DicomInstanceHasher modifiedHasher = modified->GetHasher(); | |
184 | |
185 MetadataType metadataType = (isAnonymization_ ? | |
186 MetadataType_AnonymizedFrom : | |
187 MetadataType_ModifiedFrom); | |
188 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
189 if (originalHasher->HashSeries() != modifiedHasher.HashSeries()) |
2642 | 190 { |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
191 toStore.AddMetadata(ResourceType_Series, metadataType, originalHasher->HashSeries()); |
2642 | 192 } |
193 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
194 if (originalHasher->HashStudy() != modifiedHasher.HashStudy()) |
2642 | 195 { |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
196 toStore.AddMetadata(ResourceType_Study, metadataType, originalHasher->HashStudy()); |
2642 | 197 } |
198 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
199 if (originalHasher->HashPatient() != modifiedHasher.HashPatient()) |
2642 | 200 { |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
201 toStore.AddMetadata(ResourceType_Patient, metadataType, originalHasher->HashPatient()); |
2642 | 202 } |
203 | |
2825
8aa6aef11b70
New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
204 assert(instance == originalHasher->HashInstance()); |
2642 | 205 toStore.AddMetadata(ResourceType_Instance, metadataType, instance); |
206 | |
207 | |
208 /** | |
209 * Store the resulting DICOM instance into the Orthanc store. | |
210 **/ | |
211 | |
212 std::string modifiedInstance; | |
213 if (context_.Store(modifiedInstance, toStore) != StoreStatus_Success) | |
214 { | |
2955 | 215 throw OrthancException(ErrorCode_CannotStoreInstance, |
216 "Error while storing a modified instance " + instance); | |
2642 | 217 } |
218 | |
219 assert(modifiedInstance == modifiedHasher.HashInstance()); | |
220 | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
221 output_->Update(modifiedHasher); |
2642 | 222 |
223 return true; | |
224 } | |
225 | |
226 | |
2842
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
227 bool ResourceModificationJob::HandleTrailingStep() |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
228 { |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
229 throw OrthancException(ErrorCode_InternalError); |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
230 } |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
231 |
ff0ed5ea9e4e
trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2825
diff
changeset
|
232 |
2642 | 233 void ResourceModificationJob::SetModification(DicomModification* modification, |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
234 ResourceType level, |
2642 | 235 bool isAnonymization) |
236 { | |
237 if (modification == NULL) | |
238 { | |
239 throw OrthancException(ErrorCode_NullPointer); | |
240 } | |
241 else if (IsStarted()) | |
242 { | |
243 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
244 } | |
245 else | |
246 { | |
247 modification_.reset(modification); | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
248 output_.reset(new Output(level)); |
2642 | 249 isAnonymization_ = isAnonymization; |
250 } | |
251 } | |
252 | |
253 | |
254 void ResourceModificationJob::SetOrigin(const DicomInstanceOrigin& origin) | |
255 { | |
256 if (IsStarted()) | |
257 { | |
258 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
259 } | |
260 else | |
261 { | |
262 origin_ = origin; | |
263 } | |
264 } | |
265 | |
266 | |
267 void ResourceModificationJob::SetOrigin(const RestApiCall& call) | |
268 { | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
269 SetOrigin(DicomInstanceOrigin::FromRest(call)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
270 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
271 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
272 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
273 const DicomModification& ResourceModificationJob::GetModification() const |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
274 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
275 if (modification_.get() == NULL) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
276 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
277 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
278 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
279 else |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
280 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
281 return *modification_; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
282 } |
2642 | 283 } |
284 | |
285 | |
286 void ResourceModificationJob::GetPublicContent(Json::Value& value) | |
287 { | |
288 SetOfInstancesJob::GetPublicContent(value); | |
289 | |
290 value["IsAnonymization"] = isAnonymization_; | |
2868
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
291 |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
292 if (output_.get() != NULL) |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
293 { |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
294 output_->Format(value); |
abce036683cd
sharing code within OrthancRestAnonymizeModify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2842
diff
changeset
|
295 } |
2642 | 296 } |
297 | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
298 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
299 static const char* MODIFICATION = "Modification"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
300 static const char* ORIGIN = "Origin"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
301 static const char* IS_ANONYMIZATION = "IsAnonymization"; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
302 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
303 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
304 ResourceModificationJob::ResourceModificationJob(ServerContext& context, |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
305 const Json::Value& serialized) : |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
306 SetOfInstancesJob(serialized), |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
307 context_(context) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
308 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
309 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
310 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
311 modification_.reset(new DicomModification(serialized[MODIFICATION])); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
312 } |
2642 | 313 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
314 bool ResourceModificationJob::Serialize(Json::Value& value) |
2642 | 315 { |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
316 if (!SetOfInstancesJob::Serialize(value)) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
317 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
318 return false; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
319 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
320 else |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
321 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
322 value[IS_ANONYMIZATION] = isAnonymization_; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
323 origin_.Serialize(value[ORIGIN]); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
324 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
325 Json::Value tmp; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
326 modification_->Serialize(tmp); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
327 value[MODIFICATION] = tmp; |
2642 | 328 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
329 return true; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
330 } |
2642 | 331 } |
332 } |