# HG changeset patch # User Sebastien Jodogne # Date 1589901810 -7200 # Node ID 3d2fc1b5cc8c91d7ebc6228df7284e9c09ed5c43 # Parent cf6eb4fc6841413b4826258477ee4bc4f52e20ed ResourceModificationJob: Fix the SOP instance UID to preserve references diff -r cf6eb4fc6841 -r 3d2fc1b5cc8c Core/DicomParsing/IDicomTranscoder.h --- 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& allowedSyntaxes, bool allowNewSopInstanceUid) = 0; + + static std::string GetSopInstanceUid(DcmFileFormat& dicom); }; } diff -r cf6eb4fc6841 -r 3d2fc1b5cc8c Core/DicomParsing/ParsedDicomFile.cpp --- 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 } diff -r cf6eb4fc6841 -r 3d2fc1b5cc8c OrthancServer/ServerJobs/ResourceModificationJob.cpp --- 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 +#include +#include namespace Orthanc { @@ -173,6 +175,8 @@ modification_->Apply(*modified); + const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject()); + if (transcode_) { std::set 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);