Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 2128:9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Nov 2016 15:13:16 +0100 |
parents | bfa92c9328d7 |
children | ddc75c6c712d |
comparison
equal
deleted
inserted
replaced
2127:bfa92c9328d7 | 2128:9329ba17a069 |
---|---|
369 | 369 |
370 | 370 |
371 void ServerContext::ReadDicomAsJson(std::string& result, | 371 void ServerContext::ReadDicomAsJson(std::string& result, |
372 const std::string& instancePublicId) | 372 const std::string& instancePublicId) |
373 { | 373 { |
374 ReadFile(result, instancePublicId, FileContentType_DicomAsJson, true /* decompress if needed */); | 374 FileInfo attachment; |
375 if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) | |
376 { | |
377 ReadAttachment(result, attachment); | |
378 return; | |
379 } | |
380 | |
381 // The "DICOM as JSON" summary is not available from the Orthanc | |
382 // store (most probably deleted), reconstruct it from the DICOM file | |
383 std::string dicom; | |
384 ReadDicom(dicom, instancePublicId); | |
385 | |
386 LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: " << instancePublicId; | |
387 | |
388 ParsedDicomFile parsed(dicom); | |
389 | |
390 Json::Value summary; | |
391 parsed.DatasetToJson(summary); | |
392 | |
393 result = summary.toStyledString(); | |
394 | |
395 if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, result.c_str(), result.size())) | |
396 { | |
397 LOG(WARNING) << "Cannot associate the DICOM-as-JSON summary to instance: " << instancePublicId; | |
398 throw OrthancException(ErrorCode_InternalError); | |
399 } | |
375 } | 400 } |
376 | 401 |
377 | 402 |
378 void ServerContext::ReadDicomAsJson(Json::Value& result, | 403 void ServerContext::ReadDicomAsJson(Json::Value& result, |
379 const std::string& instancePublicId) | 404 const std::string& instancePublicId) |
387 throw OrthancException(ErrorCode_CorruptedFile); | 412 throw OrthancException(ErrorCode_CorruptedFile); |
388 } | 413 } |
389 } | 414 } |
390 | 415 |
391 | 416 |
392 void ServerContext::ReadFile(std::string& result, | 417 void ServerContext::ReadAttachment(std::string& result, |
393 const std::string& instancePublicId, | 418 const std::string& instancePublicId, |
394 FileContentType content, | 419 FileContentType content, |
395 bool uncompressIfNeeded) | 420 bool uncompressIfNeeded) |
396 { | 421 { |
397 FileInfo attachment; | 422 FileInfo attachment; |
398 if (!index_.LookupAttachment(attachment, instancePublicId, content)) | 423 if (!index_.LookupAttachment(attachment, instancePublicId, content)) |
399 { | 424 { |
425 LOG(WARNING) << "Unable to read attachment " << EnumerationToString(content) << " of instance " << instancePublicId; | |
400 throw OrthancException(ErrorCode_InternalError); | 426 throw OrthancException(ErrorCode_InternalError); |
401 } | 427 } |
402 | 428 |
403 if (uncompressIfNeeded) | 429 if (uncompressIfNeeded) |
404 { | 430 { |
405 StorageAccessor accessor(area_); | 431 ReadAttachment(result, attachment); |
406 accessor.Read(result, attachment); | |
407 } | 432 } |
408 else | 433 else |
409 { | 434 { |
410 // Do not interpret the content of the storage area, return the | 435 // Do not interpret the content of the storage area, return the |
411 // raw data | 436 // raw data |
412 area_.Read(result, attachment.GetUuid(), content); | 437 area_.Read(result, attachment.GetUuid(), content); |
413 } | 438 } |
414 } | 439 } |
415 | 440 |
416 | 441 |
417 void ServerContext::ReadFile(std::string& result, | 442 void ServerContext::ReadAttachment(std::string& result, |
418 const FileInfo& file) | 443 const FileInfo& attachment) |
419 { | 444 { |
445 // This will decompress the attachment | |
420 StorageAccessor accessor(area_); | 446 StorageAccessor accessor(area_); |
421 accessor.Read(result, file); | 447 accessor.Read(result, attachment); |
422 } | 448 } |
423 | 449 |
424 | 450 |
425 IDynamicObject* ServerContext::DicomCacheProvider::Provide(const std::string& instancePublicId) | 451 IDynamicObject* ServerContext::DicomCacheProvider::Provide(const std::string& instancePublicId) |
426 { | 452 { |