# HG changeset patch # User Alain Mazy # Date 1684856306 -7200 # Node ID c9ea57d736036d6fdfe9f055ef5edd8d47dd1373 # Parent c042309620984020d05fbf7e116ab4df1524195f New URI /instances/{id}/file-until-pixel-data diff -r c04230962098 -r c9ea57d73603 NEWS --- a/NEWS Fri Apr 28 10:42:27 2023 +0200 +++ b/NEWS Tue May 23 17:38:26 2023 +0200 @@ -1,6 +1,11 @@ Pending changes in the mainline =============================== +REST API +-------- + +* New URI /instances/{id}/file-until-pixel-data + Maintenance ----------- diff -r c04230962098 -r c9ea57d73603 OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Fri Apr 28 10:42:27 2023 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Tue May 23 17:38:26 2023 +0200 @@ -421,6 +421,30 @@ } + static void GetInstanceFileUntiPixelData(RestApiGetCall& call) + { + if (call.IsDocumentation()) + { + call.GetDocumentation() + .SetTag("Instances") + .SetSummary("Download DICOM Header (without the pixel data)") + .SetDescription("Download one DICOM instance header") + .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest") + .SetHttpHeader("Accept", "This HTTP header can be set to retrieve the DICOM instance in DICOMweb format") + .AddAnswerType(MimeType_Dicom, "The DICOM instance"); + return; + } + + ServerContext& context = OrthancRestApi::GetContext(call); + + std::string publicId = call.GetUriComponent("id", ""); + + std::string buffer; + context.ReadDicomUntilPixelData(buffer, publicId); + call.GetOutput().AnswerBuffer(buffer, MimeType_Binary); + } + + static void ExportInstanceFile(RestApiPostCall& call) { if (call.IsDocumentation()) @@ -4011,6 +4035,7 @@ Register("/studies/{id}/module-patient", GetModule); Register("/instances/{id}/file", GetInstanceFile); + Register("/instances/{id}/file-until-pixel-data", GetInstanceFileUntiPixelData); Register("/instances/{id}/export", ExportInstanceFile); Register("/instances/{id}/tags", GetInstanceTags); Register("/instances/{id}/simplified-tags", GetInstanceSimplifiedTags); diff -r c04230962098 -r c9ea57d73603 OrthancServer/Sources/ServerContext.cpp --- 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; }