Mercurial > hg > orthanc
diff OrthancServer/ServerContext.cpp @ 2409:e4045b3c9772
ignore-length argument if retrieving DICOM tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 27 Sep 2017 17:36:13 +0200 |
parents | 7284093111b0 |
children | 878b59270859 |
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp Mon Sep 25 14:50:13 2017 +0200 +++ b/OrthancServer/ServerContext.cpp Wed Sep 27 17:36:13 2017 +0200 @@ -383,48 +383,82 @@ } - void ServerContext::ReadDicomAsJson(std::string& result, - const std::string& instancePublicId) + void ServerContext::ReadDicomAsJsonInternal(std::string& result, + const std::string& instancePublicId) { FileInfo attachment; if (index_.LookupAttachment(attachment, instancePublicId, FileContentType_DicomAsJson)) { ReadAttachment(result, attachment); - return; } + 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); - // 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; + LOG(INFO) << "Reconstructing the missing DICOM-as-JSON summary for instance: " + << instancePublicId; - ParsedDicomFile parsed(dicom); + ParsedDicomFile parsed(dicom); - Json::Value summary; - parsed.DatasetToJson(summary); + Json::Value summary; + parsed.DatasetToJson(summary); + + result = summary.toStyledString(); - result = summary.toStyledString(); + if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, + result.c_str(), result.size())) + { + LOG(WARNING) << "Cannot associate the DICOM-as-JSON summary to instance: " << instancePublicId; + throw OrthancException(ErrorCode_InternalError); + } + } + } + - if (!AddAttachment(instancePublicId, FileContentType_DicomAsJson, result.c_str(), result.size())) + void ServerContext::ReadDicomAsJson(std::string& result, + const std::string& instancePublicId, + const std::set<DicomTag>& ignoreTagLength) + { + if (ignoreTagLength.empty()) { - LOG(WARNING) << "Cannot associate the DICOM-as-JSON summary to instance: " << instancePublicId; - throw OrthancException(ErrorCode_InternalError); + ReadDicomAsJsonInternal(result, instancePublicId); + } + else + { + Json::Value tmp; + ReadDicomAsJson(tmp, instancePublicId, ignoreTagLength); + result = tmp.toStyledString(); } } void ServerContext::ReadDicomAsJson(Json::Value& result, - const std::string& instancePublicId) + const std::string& instancePublicId, + const std::set<DicomTag>& ignoreTagLength) { - std::string tmp; - ReadDicomAsJson(tmp, instancePublicId); + if (ignoreTagLength.empty()) + { + std::string tmp; + ReadDicomAsJsonInternal(tmp, instancePublicId); - Json::Reader reader; - if (!reader.parse(tmp, result)) + Json::Reader reader; + if (!reader.parse(tmp, result)) + { + throw OrthancException(ErrorCode_CorruptedFile); + } + } + else { - throw OrthancException(ErrorCode_CorruptedFile); + // The "DicomAsJson" attachment might have stored some tags as + // "too long". We are forced to re-parse the DICOM file. + std::string dicom; + ReadDicom(dicom, instancePublicId); + + ParsedDicomFile parsed(dicom); + parsed.DatasetToJson(result, ignoreTagLength); } }