Mercurial > hg > orthanc
comparison OrthancServer/ServerJobs/ResourceModificationJob.cpp @ 3943:b26d25d3c1c7 transcoding
"/{patients|studies|series}/.../modify": New option "Transcode"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 18 May 2020 21:37:31 +0200 |
parents | 5b882ad2ffd0 |
children | 0b3256c3ee14 |
comparison
equal
deleted
inserted
replaced
3942:5b882ad2ffd0 | 3943:b26d25d3c1c7 |
---|---|
36 | 36 |
37 #include "../../Core/Logging.h" | 37 #include "../../Core/Logging.h" |
38 #include "../../Core/SerializationToolbox.h" | 38 #include "../../Core/SerializationToolbox.h" |
39 #include "../ServerContext.h" | 39 #include "../ServerContext.h" |
40 | 40 |
41 #include <dcmtk/dcmdata/dcfilefo.h> | |
42 | |
41 namespace Orthanc | 43 namespace Orthanc |
42 { | 44 { |
43 class ResourceModificationJob::Output : public boost::noncopyable | 45 class ResourceModificationJob::Output : public boost::noncopyable |
44 { | 46 { |
45 private: | 47 private: |
169 * Compute the resulting DICOM instance. | 171 * Compute the resulting DICOM instance. |
170 **/ | 172 **/ |
171 | 173 |
172 modification_->Apply(*modified); | 174 modification_->Apply(*modified); |
173 | 175 |
176 if (transcode_) | |
177 { | |
178 std::set<DicomTransferSyntax> syntaxes; | |
179 syntaxes.insert(transferSyntax_); | |
180 | |
181 std::string s; | |
182 modified->SaveToMemoryBuffer(s); // TODO - AVOID THIS SERIALIZATION IF NO PLUGIN | |
183 | |
184 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded; | |
185 transcoded.reset(GetContext().TranscodeToParsed(modified->GetDcmtkObject(), s.empty() ? NULL : s.c_str(), s.size(), syntaxes, true)); | |
186 if (transcoded.get() == NULL) | |
187 { | |
188 LOG(WARNING) << "Cannot transcode instance, keeping original transfer syntax: " << instance; | |
189 } | |
190 else | |
191 { | |
192 modified.reset(ParsedDicomFile::AcquireDcmtkObject(transcoded->ReleaseDicom())); | |
193 } | |
194 } | |
195 | |
174 DicomInstanceToStore toStore; | 196 DicomInstanceToStore toStore; |
175 toStore.SetOrigin(origin_); | 197 toStore.SetOrigin(origin_); |
176 toStore.SetParsedDicomFile(*modified); | 198 toStore.SetParsedDicomFile(*modified); |
177 | 199 |
178 | 200 |
229 | 251 |
230 return true; | 252 return true; |
231 } | 253 } |
232 | 254 |
233 | 255 |
256 ResourceModificationJob::ResourceModificationJob(ServerContext& context) : | |
257 CleaningInstancesJob(context, true /* by default, keep source */), | |
258 modification_(new DicomModification), | |
259 isAnonymization_(false), | |
260 transcode_(false) | |
261 { | |
262 } | |
263 | |
264 | |
234 void ResourceModificationJob::SetModification(DicomModification* modification, | 265 void ResourceModificationJob::SetModification(DicomModification* modification, |
235 ResourceType level, | 266 ResourceType level, |
236 bool isAnonymization) | 267 bool isAnonymization) |
237 { | 268 { |
238 if (modification == NULL) | 269 if (modification == NULL) |
282 return *modification_; | 313 return *modification_; |
283 } | 314 } |
284 } | 315 } |
285 | 316 |
286 | 317 |
318 DicomTransferSyntax ResourceModificationJob::GetTransferSyntax() const | |
319 { | |
320 if (transcode_) | |
321 { | |
322 return transferSyntax_; | |
323 } | |
324 else | |
325 { | |
326 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
327 } | |
328 } | |
329 | |
330 | |
331 void ResourceModificationJob::SetTranscode(DicomTransferSyntax syntax) | |
332 { | |
333 if (IsStarted()) | |
334 { | |
335 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
336 } | |
337 else | |
338 { | |
339 transcode_ = true; | |
340 transferSyntax_ = syntax; | |
341 } | |
342 } | |
343 | |
344 | |
345 void ResourceModificationJob::SetTranscode(const std::string& transferSyntaxUid) | |
346 { | |
347 DicomTransferSyntax s; | |
348 if (LookupTransferSyntax(s, transferSyntaxUid)) | |
349 { | |
350 SetTranscode(s); | |
351 } | |
352 else | |
353 { | |
354 throw OrthancException(ErrorCode_BadFileFormat, | |
355 "Unknown transfer syntax UID: " + transferSyntaxUid); | |
356 } | |
357 } | |
358 | |
359 | |
360 void ResourceModificationJob::ClearTranscode() | |
361 { | |
362 if (IsStarted()) | |
363 { | |
364 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
365 } | |
366 else | |
367 { | |
368 transcode_ = false; | |
369 } | |
370 } | |
371 | |
372 | |
287 void ResourceModificationJob::GetPublicContent(Json::Value& value) | 373 void ResourceModificationJob::GetPublicContent(Json::Value& value) |
288 { | 374 { |
289 CleaningInstancesJob::GetPublicContent(value); | 375 CleaningInstancesJob::GetPublicContent(value); |
290 | 376 |
291 value["IsAnonymization"] = isAnonymization_; | 377 value["IsAnonymization"] = isAnonymization_; |
292 | 378 |
293 if (output_.get() != NULL) | 379 if (output_.get() != NULL) |
294 { | 380 { |
295 output_->Format(value); | 381 output_->Format(value); |
382 } | |
383 | |
384 if (transcode_) | |
385 { | |
386 value["Transcode"] = GetTransferSyntaxUid(transferSyntax_); | |
296 } | 387 } |
297 } | 388 } |
298 | 389 |
299 | 390 |
300 static const char* MODIFICATION = "Modification"; | 391 static const char* MODIFICATION = "Modification"; |
301 static const char* ORIGIN = "Origin"; | 392 static const char* ORIGIN = "Origin"; |
302 static const char* IS_ANONYMIZATION = "IsAnonymization"; | 393 static const char* IS_ANONYMIZATION = "IsAnonymization"; |
394 static const char* TRANSCODE = "Transcode"; | |
303 | 395 |
304 | 396 |
305 ResourceModificationJob::ResourceModificationJob(ServerContext& context, | 397 ResourceModificationJob::ResourceModificationJob(ServerContext& context, |
306 const Json::Value& serialized) : | 398 const Json::Value& serialized) : |
307 CleaningInstancesJob(context, serialized, true /* by default, keep source */) | 399 CleaningInstancesJob(context, serialized, true /* by default, keep source */) |
308 { | 400 { |
401 assert(serialized.type() == Json::objectValue); | |
402 | |
309 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION); | 403 isAnonymization_ = SerializationToolbox::ReadBoolean(serialized, IS_ANONYMIZATION); |
310 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); | 404 origin_ = DicomInstanceOrigin(serialized[ORIGIN]); |
311 modification_.reset(new DicomModification(serialized[MODIFICATION])); | 405 modification_.reset(new DicomModification(serialized[MODIFICATION])); |
406 | |
407 if (serialized.isMember(TRANSCODE)) | |
408 { | |
409 SetTranscode(SerializationToolbox::ReadString(serialized, TRANSCODE)); | |
410 } | |
411 else | |
412 { | |
413 transcode_ = false; | |
414 } | |
312 } | 415 } |
313 | 416 |
314 bool ResourceModificationJob::Serialize(Json::Value& value) | 417 bool ResourceModificationJob::Serialize(Json::Value& value) |
315 { | 418 { |
316 if (!CleaningInstancesJob::Serialize(value)) | 419 if (!CleaningInstancesJob::Serialize(value)) |
317 { | 420 { |
318 return false; | 421 return false; |
319 } | 422 } |
320 else | 423 else |
321 { | 424 { |
425 assert(value.type() == Json::objectValue); | |
426 | |
322 value[IS_ANONYMIZATION] = isAnonymization_; | 427 value[IS_ANONYMIZATION] = isAnonymization_; |
428 | |
429 if (transcode_) | |
430 { | |
431 value[TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); | |
432 } | |
433 | |
323 origin_.Serialize(value[ORIGIN]); | 434 origin_.Serialize(value[ORIGIN]); |
324 | 435 |
325 Json::Value tmp; | 436 Json::Value tmp; |
326 modification_->Serialize(tmp); | 437 modification_->Serialize(tmp); |
327 value[MODIFICATION] = tmp; | 438 value[MODIFICATION] = tmp; |