diff Plugins/Engine/OrthancPlugins.cpp @ 1821:580951a33583

OrthancPluginDicomFromJson
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2015 17:46:32 +0100
parents 9a6de24209cf
children f0f8a94c0858
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Tue Nov 24 17:24:37 2015 +0100
+++ b/Plugins/Engine/OrthancPlugins.cpp	Tue Nov 24 17:46:32 2015 +0100
@@ -414,6 +414,7 @@
 
   OrthancPlugins::OrthancPlugins()
   {
+    /* Sanity check of the compiler */
     if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
         sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
         sizeof(int32_t) != sizeof(_OrthancPluginService) ||
@@ -427,6 +428,7 @@
         sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) ||
         sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) ||
         sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
+        sizeof(int32_t) != sizeof(OrthancPluginDicomFromJsonFlags) ||
         sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) ||
         sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
         sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) ||
@@ -435,9 +437,11 @@
         static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast<int>(DicomToJsonFlags_IncludeUnknownTags) ||
         static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePixelData) != static_cast<int>(DicomToJsonFlags_IncludePixelData) ||
         static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToNull) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToNull) ||
-        static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToAscii))
+        static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToAscii) ||
+        static_cast<int>(OrthancPluginDicomFromJsonFlags_DecodeDataUriScheme) != static_cast<int>(DicomFromJsonFlags_DecodeDataUriScheme) ||
+        static_cast<int>(OrthancPluginDicomFromJsonFlags_GenerateIdentifiers) != static_cast<int>(DicomFromJsonFlags_GenerateIdentifiers))
+
     {
-      /* Sanity check of the compiler */
       throw OrthancException(ErrorCode_Plugin);
     }
 
@@ -1413,6 +1417,31 @@
   }
         
 
+  void OrthancPlugins::ApplyDicomFromJson(_OrthancPluginService service,
+                                          const void* parameters)
+  {
+    const _OrthancPluginDicomFromJson& p =
+      *reinterpret_cast<const _OrthancPluginDicomFromJson*>(parameters);
+
+    Json::Value json;
+    Json::Reader reader;
+    if (!reader.parse(p.json, json))
+    {
+      throw OrthancException(ErrorCode_BadJson);
+    }
+
+    std::string dicom;
+
+    {
+      std::auto_ptr<ParsedDicomFile> file
+        (ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(p.flags)));
+      file->SaveToMemoryBuffer(dicom);
+    }
+
+    CopyToMemoryBuffer(*p.target, dicom);
+  }
+        
+
   void OrthancPlugins::DatabaseAnswer(const void* parameters)
   {
     const _OrthancPluginDatabaseAnswer& p =
@@ -1938,6 +1967,10 @@
         ApplyDicomToJson(service, parameters);
         return true;
 
+      case _OrthancPluginService_DicomFromJson:
+        ApplyDicomFromJson(service, parameters);
+        return true;
+
       case _OrthancPluginService_WorklistAddAnswer:
       {
         const _OrthancPluginWorklistAnswersOperation& p =