changeset 3948:3d2fc1b5cc8c transcoding

ResourceModificationJob: Fix the SOP instance UID to preserve references
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 May 2020 17:23:30 +0200
parents cf6eb4fc6841
children ef696db8426f
files Core/DicomParsing/IDicomTranscoder.h Core/DicomParsing/ParsedDicomFile.cpp OrthancServer/ServerJobs/ResourceModificationJob.cpp
diffstat 3 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomParsing/IDicomTranscoder.h	Tue May 19 16:19:05 2020 +0200
+++ b/Core/DicomParsing/IDicomTranscoder.h	Tue May 19 17:23:30 2020 +0200
@@ -110,8 +110,6 @@
     static TranscodingType GetTranscodingType(DicomTransferSyntax target,
                                               DicomTransferSyntax source);
 
-    static std::string GetSopInstanceUid(DcmFileFormat& dicom);
-
     static void CheckTranscoding(DicomImage& transcoded,
                                  bool hasSopInstanceUidChanged,
                                  DicomTransferSyntax sourceSyntax,
@@ -129,5 +127,7 @@
                            DicomImage& source /* in, "GetParsed()" possibly modified */,
                            const std::set<DicomTransferSyntax>& allowedSyntaxes,
                            bool allowNewSopInstanceUid) = 0;
+
+    static std::string GetSopInstanceUid(DcmFileFormat& dicom);
   };
 }
--- a/Core/DicomParsing/ParsedDicomFile.cpp	Tue May 19 16:19:05 2020 +0200
+++ b/Core/DicomParsing/ParsedDicomFile.cpp	Tue May 19 17:23:30 2020 +0200
@@ -1655,6 +1655,9 @@
 
   bool ParsedDicomFile::LookupTransferSyntax(std::string& result)
   {
+#if 0
+    // This was the implementation in Orthanc <= 1.6.1
+
     // TODO - Shouldn't "dataset.getCurrentXfer()" be used instead of
     // using the meta header?
     const char* value = NULL;
@@ -1670,6 +1673,18 @@
     {
       return false;
     }
+#else
+    DicomTransferSyntax s;
+    if (FromDcmtkBridge::LookupOrthancTransferSyntax(s, GetDcmtkObject()))
+    {
+      result.assign(GetTransferSyntaxUid(s));
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+#endif
   }
 
 
--- a/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Tue May 19 16:19:05 2020 +0200
+++ b/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Tue May 19 17:23:30 2020 +0200
@@ -39,6 +39,8 @@
 #include "../ServerContext.h"
 
 #include <dcmtk/dcmdata/dcfilefo.h>
+#include <dcmtk/dcmdata/dcdeftag.h>
+#include <cassert>
 
 namespace Orthanc
 {
@@ -173,6 +175,8 @@
 
     modification_->Apply(*modified);
 
+    const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject());
+    
     if (transcode_)
     {
       std::set<DicomTransferSyntax> syntaxes;
@@ -186,6 +190,17 @@
       if (GetContext().Transcode(transcoded, hasSopInstanceUidChanged, source, syntaxes, true))
       {
         modified.reset(transcoded.ReleaseAsParsedDicomFile());
+
+        // Fix the SOP instance UID in order the preserve the
+        // references between instance UIDs in the DICOM hierarchy
+        // (the UID might have changed in the case of lossy transcoding)
+        if (modified.get() == NULL ||
+            modified->GetDcmtkObject().getDataset() == NULL ||
+            !modified->GetDcmtkObject().getDataset()->putAndInsertString(
+              DCM_SOPInstanceUID, modifiedUid.c_str(), OFTrue /* replace */).good())
+        {
+          throw OrthancException(ErrorCode_InternalError);
+        }
       }
       else
       {
@@ -194,6 +209,8 @@
       }
     }
 
+    assert(modifiedUid == IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject()));
+
     DicomInstanceToStore toStore;
     toStore.SetOrigin(origin_);
     toStore.SetParsedDicomFile(*modified);