# HG changeset patch # User Sebastien Jodogne # Date 1613128399 -3600 # Node ID 1f455b86b054db6ccd1defd76505da2e62ad6804 # Parent cff7fdfc83a4552e759b635f008925ec1e3e5a3a simplification in ServerContext diff -r cff7fdfc83a4 -r 1f455b86b054 OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Feb 12 11:33:16 2021 +0100 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Feb 12 12:13:19 2021 +0100 @@ -461,9 +461,9 @@ // This path allows one to avoid the JSON decoding if no // simplification is asked, and if no "ignore-length" argument // is present - std::string full; + Json::Value full; context.ReadDicomAsJson(full, publicId); - call.GetOutput().AnswerBuffer(full, MimeType_Json); + call.GetOutput().AnswerJson(full); } } diff -r cff7fdfc83a4 -r 1f455b86b054 OrthancServer/Sources/ServerContext.cpp --- a/OrthancServer/Sources/ServerContext.cpp Fri Feb 12 11:33:16 2021 +0100 +++ b/OrthancServer/Sources/ServerContext.cpp Fri Feb 12 12:13:19 2021 +0100 @@ -807,42 +807,6 @@ } - void ServerContext::ReadDicomAsJson(std::string& result, - const std::string& instancePublicId) - { - FileInfo attachment; - if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) - { - StorageAccessor accessor(area_, GetMetricsRegistry()); - accessor.Read(result, attachment); - } - else - { - // The "DICOM as JSON" summary is not available from the Orthanc - // store (most probably deleted), reconstruct it from the DICOM file - std::string dicom; - ReadDicom(dicom, instancePublicId); - - LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: " - << instancePublicId; - - ParsedDicomFile parsed(dicom); - - Json::Value summary; - OrthancConfiguration::DefaultDicomDatasetToJson(summary, parsed); - - result = summary.toStyledString(); - - if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, - result.c_str(), result.size())) - { - throw OrthancException(ErrorCode_InternalError, - "Cannot associate the DICOM-as-JSON summary to instance: " + instancePublicId); - } - } - } - - void ServerContext::ReadDicomAsJson(Json::Value& result, const std::string& instancePublicId, const std::set& ignoreTagLength) @@ -850,7 +814,39 @@ if (ignoreTagLength.empty()) { std::string tmp; - ReadDicomAsJson(tmp, instancePublicId); + + { + FileInfo attachment; + if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) + { + StorageAccessor accessor(area_, GetMetricsRegistry()); + accessor.Read(tmp, attachment); + } + else + { + // The "DICOM as JSON" summary is not available from the Orthanc + // store (most probably deleted), reconstruct it from the DICOM file + std::string dicom; + ReadDicom(dicom, instancePublicId); + + LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: " + << instancePublicId; + + ParsedDicomFile parsed(dicom); + + Json::Value summary; + OrthancConfiguration::DefaultDicomDatasetToJson(summary, parsed); + + tmp = summary.toStyledString(); + + if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, + tmp.c_str(), tmp.size())) + { + throw OrthancException(ErrorCode_InternalError, + "Cannot associate the DICOM-as-JSON summary to instance: " + instancePublicId); + } + } + } if (!Toolbox::ReadJson(result, tmp)) { diff -r cff7fdfc83a4 -r 1f455b86b054 OrthancServer/Sources/ServerContext.h --- a/OrthancServer/Sources/ServerContext.h Fri Feb 12 11:33:16 2021 +0100 +++ b/OrthancServer/Sources/ServerContext.h Fri Feb 12 12:13:19 2021 +0100 @@ -312,9 +312,6 @@ FileContentType attachmentType, CompressionType compression); - void ReadDicomAsJson(std::string& result, - const std::string& instancePublicId); - void ReadDicomAsJson(Json::Value& result, const std::string& instancePublicId, const std::set& ignoreTagLength);