changeset 4499:6f99949b2878

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Feb 2021 14:25:21 +0100
parents 7b99e8bb8246
children 3b4940bca158
files OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h OrthancServer/UnitTestsSources/ServerIndexTests.cpp
diffstat 4 files changed, 22 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp	Tue Feb 09 11:37:13 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Tue Feb 09 14:25:21 2021 +0100
@@ -36,6 +36,7 @@
 
 #include "../../OrthancFramework/Sources/Cache/SharedArchive.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomElement.h"
+#include "../../OrthancFramework/Sources/DicomFormat/DicomStreamReader.h"
 #include "../../OrthancFramework/Sources/DicomParsing/DcmtkTranscoder.h"
 #include "../../OrthancFramework/Sources/DicomParsing/DicomModification.h"
 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
@@ -509,7 +510,14 @@
 
       default:
         throw OrthancException(ErrorCode_ParameterOutOfRange);
-    }    
+    }
+
+
+    bool hasPixelDataOffset;
+    uint64_t pixelDataOffset;
+    hasPixelDataOffset = DicomStreamReader::LookupPixelDataOffset(
+      pixelDataOffset, dicom.GetBufferData(), dicom.GetBufferSize());
+    
     
     try
     {
@@ -573,7 +581,7 @@
       typedef std::map<MetadataType, std::string>  InstanceMetadata;
       InstanceMetadata  instanceMetadata;
       StoreStatus status = index_.Store(
-        instanceMetadata, dicom, attachments, overwrite);
+        instanceMetadata, dicom, attachments, overwrite, hasPixelDataOffset, pixelDataOffset);
 
       // Only keep the metadata for the "instance" level
       dicom.GetMetadata().clear();
--- a/OrthancServer/Sources/ServerIndex.cpp	Tue Feb 09 11:37:13 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.cpp	Tue Feb 09 14:25:21 2021 +0100
@@ -39,7 +39,6 @@
 #endif
 
 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
-#include "../../OrthancFramework/Sources/DicomFormat/DicomStreamReader.h"
 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
 #include "../../OrthancFramework/Sources/Logging.h"
@@ -759,25 +758,10 @@
   StoreStatus ServerIndex::Store(std::map<MetadataType, std::string>& instanceMetadata,
                                  DicomInstanceToStore& instanceToStore,
                                  const Attachments& attachments,
-                                 bool overwrite)
+                                 bool overwrite,
+                                 bool hasPixelDataOffset,
+                                 uint64_t pixelDataOffset)
   {
-    std::string pixelDataOffset;
-
-    {
-      // Determining the pixel data offset is costly, don't do it
-      // within the mutex (new in Orthanc 1.9.1)
-      uint64_t offset;
-      if (DicomStreamReader::LookupPixelDataOffset(offset, instanceToStore.GetBufferData(),
-                                                   instanceToStore.GetBufferSize()))
-      {
-        pixelDataOffset = boost::lexical_cast<std::string>(offset);
-      }
-      else
-      {
-        pixelDataOffset.clear();
-      }
-    }
-    
     boost::mutex::scoped_lock lock(mutex_);
 
     const DicomMap& dicomSummary = instanceToStore.GetSummary();
@@ -991,8 +975,9 @@
 
         // New in Orthanc 1.9.1
         SetInstanceMetadata(content, instanceMetadata, instanceId,
-                            MetadataType_Instance_PixelDataOffset, pixelDataOffset);
-
+                            MetadataType_Instance_PixelDataOffset,
+                            (hasPixelDataOffset ? 
+                             boost::lexical_cast<std::string>(pixelDataOffset) : ""));
         
         const DicomValue* value;
         if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_SOP_CLASS_UID)) != NULL &&
--- a/OrthancServer/Sources/ServerIndex.h	Tue Feb 09 11:37:13 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.h	Tue Feb 09 14:25:21 2021 +0100
@@ -141,7 +141,9 @@
     StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata,
                       DicomInstanceToStore& instance,
                       const Attachments& attachments,
-                      bool overwrite);
+                      bool overwrite,
+                      bool hasPixelDataOffset,
+                      uint64_t pixelDataOffset);
 
     void GetGlobalStatistics(/* out */ uint64_t& diskSize,
                              /* out */ uint64_t& uncompressedSize,
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Tue Feb 09 11:37:13 2021 +0100
+++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Tue Feb 09 14:25:21 2021 +0100
@@ -728,7 +728,7 @@
     DicomInstanceToStore toStore;
     toStore.SetSummary(instance);
     ASSERT_EQ(StoreStatus_Success, index.Store(instanceMetadata, toStore, attachments,
-                                               false /* don't overwrite */));
+                                               false /* don't overwrite */, true /* pixel data offset */, 42));
     ASSERT_EQ(6u, instanceMetadata.size());
     ASSERT_TRUE(instanceMetadata.find(MetadataType_RemoteAet) != instanceMetadata.end());
     ASSERT_TRUE(instanceMetadata.find(MetadataType_Instance_ReceptionDate) != instanceMetadata.end());
@@ -736,6 +736,8 @@
     ASSERT_TRUE(instanceMetadata.find(MetadataType_Instance_SopClassUid) != instanceMetadata.end());
     ASSERT_TRUE(instanceMetadata.find(MetadataType_Instance_PixelDataOffset) != instanceMetadata.end());
 
+    ASSERT_EQ("42", instanceMetadata[MetadataType_Instance_PixelDataOffset]);
+
     // The default transfer syntax depends on the OS endianness
     std::string s = instanceMetadata[MetadataType_Instance_TransferSyntax];
     ASSERT_TRUE(s == "1.2.840.10008.1.2.1" ||