# HG changeset patch # User Sebastien Jodogne # Date 1588855973 -7200 # Node ID 603a7b86fa5f714fd14d7793b06abdebd49590fb # Parent 32e95d28efb2baf26bf5675d20ec661985af7c20 route "/instances/.../modify": New option "Transcode" diff -r 32e95d28efb2 -r 603a7b86fa5f Core/DicomParsing/ParsedDicomFile.cpp --- a/Core/DicomParsing/ParsedDicomFile.cpp Thu May 07 12:37:36 2020 +0200 +++ b/Core/DicomParsing/ParsedDicomFile.cpp Thu May 07 14:52:53 2020 +0200 @@ -869,7 +869,7 @@ std::string serialized; if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset())) { - output.AnswerBuffer(serialized, MimeType_Binary); + output.AnswerBuffer(serialized, MimeType_Dicom); } } #endif diff -r 32e95d28efb2 -r 603a7b86fa5f NEWS --- a/NEWS Thu May 07 12:37:36 2020 +0200 +++ b/NEWS Thu May 07 14:52:53 2020 +0200 @@ -12,6 +12,7 @@ - "/queries/.../answers/../retrieve": "TargetAet" not mandatory anymore (defaults to the local AET) * Changes: + - "/instances/.../modify": New option "Transcode" - "/ordered-slices": reverted the change introduced in 1.5.8 and go-back to 1.5.7 behaviour. diff -r 32e95d28efb2 -r 603a7b86fa5f OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Thu May 07 12:37:36 2020 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Thu May 07 14:52:53 2020 +0200 @@ -112,19 +112,46 @@ static void AnonymizeOrModifyInstance(DicomModification& modification, - RestApiPostCall& call) + RestApiPostCall& call, + bool transcode, + DicomTransferSyntax targetSyntax) { + ServerContext& context = OrthancRestApi::GetContext(call); std::string id = call.GetUriComponent("id", ""); std::unique_ptr modified; { - ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); + ServerContext::DicomCacheLocker locker(context, id); modified.reset(locker.GetDicom().Clone(true)); } modification.Apply(*modified); - modified->Answer(call.GetOutput()); + + if (transcode) + { + std::string saved; + modified->SaveToMemoryBuffer(saved); + + std::string transcoded; + bool hasSopInstanceUidChanged; + std::set ts; + ts.insert(targetSyntax); + if (context.TranscodeMemoryBuffer(transcoded, hasSopInstanceUidChanged, saved, ts, true)) + { + call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom); + } + else + { + throw OrthancException(ErrorCode_InternalError, + "Cannot transcode to transfer syntax: " + + std::string(GetTransferSyntaxUid(targetSyntax))); + } + } + else + { + modified->Answer(call.GetOutput()); + } } @@ -153,7 +180,25 @@ modification.SetLevel(ResourceType_Instance); } - AnonymizeOrModifyInstance(modification, call); + if (request.isMember("Transcode")) + { + std::string s = SerializationToolbox::ReadString(request, "Transcode"); + + DicomTransferSyntax syntax; + if (LookupTransferSyntax(syntax, s)) + { + AnonymizeOrModifyInstance(modification, call, true, syntax); + } + else + { + throw OrthancException(ErrorCode_ParameterOutOfRange, "Unknown transfer syntax: " + s); + } + } + else + { + AnonymizeOrModifyInstance(modification, call, false /* no transcoding */, + DicomTransferSyntax_LittleEndianImplicit /* unused */); + } } @@ -165,7 +210,8 @@ Json::Value request; ParseAnonymizationRequest(request, modification, call); - AnonymizeOrModifyInstance(modification, call); + AnonymizeOrModifyInstance(modification, call, false /* no transcoding */, + DicomTransferSyntax_LittleEndianImplicit /* unused */); }