Mercurial > hg > orthanc
comparison OrthancServer/ServerJobs/ResourceModificationJob.cpp @ 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 | 0b3256c3ee14 |
children | 5fe8c6d3212e |
comparison
equal
deleted
inserted
replaced
3947:cf6eb4fc6841 | 3948:3d2fc1b5cc8c |
---|---|
37 #include "../../Core/Logging.h" | 37 #include "../../Core/Logging.h" |
38 #include "../../Core/SerializationToolbox.h" | 38 #include "../../Core/SerializationToolbox.h" |
39 #include "../ServerContext.h" | 39 #include "../ServerContext.h" |
40 | 40 |
41 #include <dcmtk/dcmdata/dcfilefo.h> | 41 #include <dcmtk/dcmdata/dcfilefo.h> |
42 #include <dcmtk/dcmdata/dcdeftag.h> | |
43 #include <cassert> | |
42 | 44 |
43 namespace Orthanc | 45 namespace Orthanc |
44 { | 46 { |
45 class ResourceModificationJob::Output : public boost::noncopyable | 47 class ResourceModificationJob::Output : public boost::noncopyable |
46 { | 48 { |
171 * Compute the resulting DICOM instance. | 173 * Compute the resulting DICOM instance. |
172 **/ | 174 **/ |
173 | 175 |
174 modification_->Apply(*modified); | 176 modification_->Apply(*modified); |
175 | 177 |
178 const std::string modifiedUid = IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject()); | |
179 | |
176 if (transcode_) | 180 if (transcode_) |
177 { | 181 { |
178 std::set<DicomTransferSyntax> syntaxes; | 182 std::set<DicomTransferSyntax> syntaxes; |
179 syntaxes.insert(transferSyntax_); | 183 syntaxes.insert(transferSyntax_); |
180 | 184 |
184 IDicomTranscoder::DicomImage transcoded; | 188 IDicomTranscoder::DicomImage transcoded; |
185 bool hasSopInstanceUidChanged; | 189 bool hasSopInstanceUidChanged; |
186 if (GetContext().Transcode(transcoded, hasSopInstanceUidChanged, source, syntaxes, true)) | 190 if (GetContext().Transcode(transcoded, hasSopInstanceUidChanged, source, syntaxes, true)) |
187 { | 191 { |
188 modified.reset(transcoded.ReleaseAsParsedDicomFile()); | 192 modified.reset(transcoded.ReleaseAsParsedDicomFile()); |
193 | |
194 // Fix the SOP instance UID in order the preserve the | |
195 // references between instance UIDs in the DICOM hierarchy | |
196 // (the UID might have changed in the case of lossy transcoding) | |
197 if (modified.get() == NULL || | |
198 modified->GetDcmtkObject().getDataset() == NULL || | |
199 !modified->GetDcmtkObject().getDataset()->putAndInsertString( | |
200 DCM_SOPInstanceUID, modifiedUid.c_str(), OFTrue /* replace */).good()) | |
201 { | |
202 throw OrthancException(ErrorCode_InternalError); | |
203 } | |
189 } | 204 } |
190 else | 205 else |
191 { | 206 { |
192 LOG(WARNING) << "Cannot transcode instance, keeping original transfer syntax: " << instance; | 207 LOG(WARNING) << "Cannot transcode instance, keeping original transfer syntax: " << instance; |
193 modified.reset(source.ReleaseAsParsedDicomFile()); | 208 modified.reset(source.ReleaseAsParsedDicomFile()); |
194 } | 209 } |
195 } | 210 } |
211 | |
212 assert(modifiedUid == IDicomTranscoder::GetSopInstanceUid(modified->GetDcmtkObject())); | |
196 | 213 |
197 DicomInstanceToStore toStore; | 214 DicomInstanceToStore toStore; |
198 toStore.SetOrigin(origin_); | 215 toStore.SetOrigin(origin_); |
199 toStore.SetParsedDicomFile(*modified); | 216 toStore.SetParsedDicomFile(*modified); |
200 | 217 |