changeset 4477:0a2c9790cb41

new primitive in plugin SDK: OrthancPluginCreateDicom2()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 27 Jan 2021 16:54:03 +0100
parents c1f36fd13730
children 5248be65146a
files NEWS OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Plugins/Engine/OrthancPlugins.h OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h
diffstat 4 files changed, 91 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Jan 26 18:25:52 2021 +0100
+++ b/NEWS	Wed Jan 27 16:54:03 2021 +0100
@@ -43,6 +43,7 @@
 * New functions in the SDK:
   - OrthancPluginCreateMemoryBuffer64()
   - OrthancPluginRegisterStorageArea2()
+  - OrthancPluginCreateDicom2()
 
 Maintenance
 -----------
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Tue Jan 26 18:25:52 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Jan 27 16:54:03 2021 +0100
@@ -3582,19 +3582,16 @@
   }
         
 
-  void OrthancPlugins::ApplyCreateDicom(_OrthancPluginService service,
-                                        const void* parameters)
+  void OrthancPlugins::ApplyCreateDicom(const _OrthancPluginCreateDicom& parameters,
+                                        const char* privateCreatorC)
   {
-    const _OrthancPluginCreateDicom& p =
-      *reinterpret_cast<const _OrthancPluginCreateDicom*>(parameters);
-
     Json::Value json;
 
-    if (p.json == NULL)
+    if (parameters.json == NULL)
     {
       json = Json::objectValue;
     }
-    else if (!Toolbox::ReadJson(json, p.json))
+    else if (!Toolbox::ReadJson(json, parameters.json))
     {
       throw OrthancException(ErrorCode_BadJson);
     }
@@ -3606,24 +3603,31 @@
       // configuration file)
       // https://bugs.orthanc-server.com/show_bug.cgi?id=168
       std::string privateCreator;
+
+      if (privateCreatorC == NULL)
       {
         OrthancConfiguration::ReaderLock lock;
         privateCreator = lock.GetConfiguration().GetDefaultPrivateCreator();
       }
+      else
+      {
+        // New in Orthanc 1.9.0
+        privateCreator.assign(privateCreatorC);
+      }
       
       std::unique_ptr<ParsedDicomFile> file
-        (ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(p.flags),
+        (ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(parameters.flags),
                                          privateCreator));
 
-      if (p.pixelData)
-      {
-        file->EmbedImage(*reinterpret_cast<const ImageAccessor*>(p.pixelData));
+      if (parameters.pixelData)
+      {
+        file->EmbedImage(*reinterpret_cast<const ImageAccessor*>(parameters.pixelData));
       }
 
       file->SaveToMemoryBuffer(dicom);
     }
 
-    CopyToMemoryBuffer(*p.target, dicom);
+    CopyToMemoryBuffer(*parameters.target, dicom);
   }
 
 
@@ -4200,8 +4204,21 @@
         return true;
 
       case _OrthancPluginService_CreateDicom:
-        ApplyCreateDicom(service, parameters);
+      {
+        const _OrthancPluginCreateDicom& p =
+          *reinterpret_cast<const _OrthancPluginCreateDicom*>(parameters);
+        ApplyCreateDicom(p, NULL);
         return true;
+      }
+
+      case _OrthancPluginService_CreateDicom2:
+      {
+        // New in Orthanc 1.9.0
+        const _OrthancPluginCreateDicom2& p =
+          *reinterpret_cast<const _OrthancPluginCreateDicom2*>(parameters);
+        ApplyCreateDicom(p.createDicom, p.privateCreator);
+        return true;
+      }
 
       case _OrthancPluginService_WorklistAddAnswer:
       {
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.h	Tue Jan 26 18:25:52 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.h	Wed Jan 27 16:54:03 2021 +0100
@@ -207,8 +207,8 @@
     void ApplyDicomToJson(_OrthancPluginService service,
                           const void* parameters);
 
-    void ApplyCreateDicom(_OrthancPluginService service,
-                          const void* parameters);
+    void ApplyCreateDicom(const _OrthancPluginCreateDicom& parameters,
+                          const char* privateCreatorC);
 
     void ApplyCreateImage(_OrthancPluginService service,
                           const void* parameters);
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Jan 26 18:25:52 2021 +0100
+++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Wed Jan 27 16:54:03 2021 +0100
@@ -439,6 +439,7 @@
     _OrthancPluginService_CreateMemoryBuffer = 38,   /* New in Orthanc 1.7.0 */
     _OrthancPluginService_GenerateRestApiAuthorizationToken = 39,   /* New in Orthanc 1.8.1 */
     _OrthancPluginService_CreateMemoryBuffer64 = 40, /* New in Orthanc 1.9.0 */
+    _OrthancPluginService_CreateDicom2 = 41,         /* New in Orthanc 1.9.0 */
     
     /* Registration of callbacks */
     _OrthancPluginService_RegisterRestCallback = 1000,
@@ -5317,6 +5318,12 @@
    * memory buffer. Additionally, an image to be encoded within the
    * DICOM instance can also be provided.
    *
+   * Private tags will be associated with the private creator whose
+   * value is specified in the "DefaultPrivateCreator" configuration
+   * option of Orthanc. The function OrthancPluginCreateDicom2() can
+   * be used if another private creator must be used to create this
+   * instance.
+   *
    * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
    * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
    * @param json The input JSON file.
@@ -5324,6 +5331,7 @@
    * @param flags Flags governing the output.
    * @return 0 if success, other value if error.
    * @ingroup Toolbox
+   * @see OrthancPluginCreateDicom2
    * @see OrthancPluginDicomBufferToJson
    **/
   ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom(
@@ -8423,6 +8431,56 @@
     context->InvokeService(context, _OrthancPluginService_RegisterStorageArea2, &params);
   }
 
+
+
+  typedef struct
+  {
+    _OrthancPluginCreateDicom  createDicom;
+    const char*                privateCreator;
+  } _OrthancPluginCreateDicom2;
+
+  /**
+   * @brief Create a DICOM instance from a JSON string and an image, with a private creator.
+   *
+   * This function takes as input a string containing a JSON file
+   * describing the content of a DICOM instance. As an output, it
+   * writes the corresponding DICOM instance to a newly allocated
+   * memory buffer. Additionally, an image to be encoded within the
+   * DICOM instance can also be provided.
+   *
+   * Contrarily to the function OrthancPluginCreateDicom(), this
+   * function can be explicitly provided with a private creator.
+   *
+   * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
+   * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
+   * @param json The input JSON file.
+   * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.
+   * @param flags Flags governing the output.
+   * @param privateCreator The private creator to be used for the private DICOM tags.
+   * Check out the global configuration option "Dictionary" of Orthanc.
+   * @return 0 if success, other value if error.
+   * @ingroup Toolbox
+   * @see OrthancPluginCreateDicom
+   * @see OrthancPluginDicomBufferToJson
+   **/
+  ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom2(
+    OrthancPluginContext*          context,
+    OrthancPluginMemoryBuffer*     target,
+    const char*                    json,
+    const OrthancPluginImage*      pixelData,
+    OrthancPluginCreateDicomFlags  flags,
+    const char*                    privateCreator)
+  {
+    _OrthancPluginCreateDicom2 params;
+    params.createDicom.target = target;
+    params.createDicom.json = json;
+    params.createDicom.pixelData = pixelData;
+    params.createDicom.flags = flags;
+    params.privateCreator = privateCreator;
+
+    return context->InvokeService(context, _OrthancPluginService_CreateDicom2, &params);
+  }
+
 #ifdef  __cplusplus
 }
 #endif