Mercurial > hg > orthanc
diff OrthancServer/Sources/ServerContext.cpp @ 5299:c9ea57d73603 am-experimental
New URI /instances/{id}/file-until-pixel-data
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 23 May 2023 17:38:26 +0200 |
parents | c04230962098 |
children | f26ed26a7793 |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp Fri Apr 28 10:42:27 2023 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Tue May 23 17:38:26 2023 +0200 @@ -1129,32 +1129,47 @@ void ServerContext::ReadDicomForHeader(std::string& dicom, const std::string& instancePublicId) { - if (!ReadDicomUntilPixelData(dicom, instancePublicId)) - { - ReadDicom(dicom, instancePublicId); - } + ReadDicomUntilPixelData(dicom, instancePublicId); } bool ServerContext::ReadDicomUntilPixelData(std::string& dicom, const std::string& instancePublicId) { + FileInfo attachment; + int64_t revision; // Ignored + + // if the attachment exists as such return it directly + if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData)) + { + StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); + accessor.Read(dicom, attachment); + return true; + } + + // if the storage area can not read part of files, return the whole file if (!area_.HasReadRange()) { - return false; + ReadDicom(dicom, instancePublicId); + return true; } - - FileInfo attachment; - int64_t revision; // Ignored + + // else, read the start of the dicom file + if (!index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_Dicom)) { throw OrthancException(ErrorCode_InternalError, - "Unable to read the DICOM file of instance " + instancePublicId); + "Unable to read the DICOM file of instance " + instancePublicId); + } + + // if the attachment is compressed, return the whole file + if (attachment.GetCompressionType() != CompressionType_None) + { + ReadDicom(dicom, instancePublicId); + return true; } std::string s; - - if (attachment.GetCompressionType() == CompressionType_None && - index_.LookupMetadata(s, revision, instancePublicId, ResourceType_Instance, + if (index_.LookupMetadata(s, revision, instancePublicId, ResourceType_Instance, MetadataType_Instance_PixelDataOffset) && !s.empty()) { @@ -1175,7 +1190,8 @@ } } - return false; + ReadDicom(dicom, instancePublicId); + return true; }