changeset 3901:603a7b86fa5f transcoding

route "/instances/.../modify": New option "Transcode"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 May 2020 14:52:53 +0200
parents 32e95d28efb2
children 7459fcb1bdf7
files Core/DicomParsing/ParsedDicomFile.cpp NEWS OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp
diffstat 3 files changed, 53 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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.
 
--- 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<ParsedDicomFile> 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<DicomTransferSyntax> 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 */);
   }