changeset 5332:f5cb6310e0dc

fix handling of DICOM files without pixel data
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Jun 2023 09:35:31 +0200
parents f294780f0642
children 816968b5a031
files OrthancServer/Plugins/Engine/OrthancPlugins.cpp
diffstat 1 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Jun 26 13:04:42 2023 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Tue Jun 27 09:35:31 2023 +0200
@@ -4456,9 +4456,9 @@
 
         if (params.mode == OrthancPluginLoadDicomInstanceMode_EmptyPixelData)
         {
-          ValueRepresentation vr = parsed->GuessPixelDataValueRepresentation();
-
-          // Try and retrieve the VR of pixel data from the metadata of the instance
+          bool hasPixelData = false;
+          ValueRepresentation pixelDataVR = parsed->GuessPixelDataValueRepresentation();
+
           {
             PImpl::ServerContextLock lock(*pimpl_);
 
@@ -4468,13 +4468,14 @@
                   s, revision, params.instanceId,
                   ResourceType_Instance, MetadataType_Instance_PixelDataVR))
             {
+              hasPixelData = true;
               if (s == "OB")
               {
-                vr = ValueRepresentation_OtherByte;
+                pixelDataVR = ValueRepresentation_OtherByte;
               }
               else if (s == "OW")
               {
-                vr = ValueRepresentation_OtherWord;
+                pixelDataVR = ValueRepresentation_OtherWord;
               }
               else
               {
@@ -4482,9 +4483,24 @@
                              << params.instanceId << ": " << s;
               }
             }
+            else if (lock.GetContext().GetIndex().LookupMetadata(
+                       s, revision, params.instanceId,
+                       ResourceType_Instance, MetadataType_Instance_PixelDataOffset))
+            {
+              // This file was stored by an older version of Orthanc,
+              // "PixelDataVR" is not available, so use the guess
+              hasPixelData = true;
+            }
+            else
+            {
+              hasPixelData = false;
+            }
           }
-          
-          parsed->InjectEmptyPixelData(vr);
+
+          if (hasPixelData)
+          {
+            parsed->InjectEmptyPixelData(pixelDataVR);
+          }
         }
 
         target.reset(new DicomInstanceFromParsed(parsed.release()));