changeset 5303:9504de20d43d am-experimental

new SDK function OrthancPluginEncodeDicomWebJson3 that allows injecting an empty PixelData element at the end
author Alain Mazy <am@osimis.io>
date Thu, 25 May 2023 17:19:52 +0200
parents f26ed26a7793
children 79fa77e9fa0d
files NEWS OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h
diffstat 5 files changed, 98 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed May 24 08:56:41 2023 +0200
+++ b/NEWS	Thu May 25 17:19:52 2023 +0200
@@ -24,6 +24,12 @@
   the content of the response.  Useful since the dicomWeb format is very slow
   to serialize.
 
+* New functions in the SDK:
+  - OrthancPluginEncodeDicomWebJson3()
+  TODO: Xml version
+
+
+
 Version 1.12.0 (2023-04-14)
 ===========================
 
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Wed May 24 08:56:41 2023 +0200
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Thu May 25 17:19:52 2023 +0200
@@ -1755,8 +1755,19 @@
   }
 
 
-  void ParsedDicomFile::Apply(ITagVisitor& visitor) const
+  void ParsedDicomFile::Apply(ITagVisitor& visitor, bool injectEmptyPixelData) const
   {
+    DcmItem& dataset = *GetDcmtkObjectConst().getDataset();
+
+    if (injectEmptyPixelData)
+    {
+      DcmTag emptyPixelData(DCM_PixelData, EVR_PixelData);
+      if (!dataset.insertEmptyElement(emptyPixelData, false).good())
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
+    }
+
     FromDcmtkBridge::Apply(*GetDcmtkObjectConst().getDataset(), visitor, GetDefaultDicomEncoding());
   }
 
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h	Wed May 24 08:56:41 2023 +0200
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h	Thu May 25 17:19:52 2023 +0200
@@ -273,7 +273,7 @@
 
     bool LookupPhotometricInterpretation(PhotometricInterpretation& result) const;
 
-    void Apply(ITagVisitor& visitor) const;
+    void Apply(ITagVisitor& visitor, bool injectEmptyPixelData = false) const;
 
     // Decode the given frame, using the built-in DICOM decoder of Orthanc
     ImageAccessor* DecodeFrame(unsigned int frame) const;
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed May 24 08:56:41 2023 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Thu May 25 17:19:52 2023 +0200
@@ -1052,12 +1052,13 @@
 
       void Apply(char** target,
                  bool isJson,
-                 const ParsedDicomFile& dicom)
+                 const ParsedDicomFile& dicom,
+                 bool injectEmptyPixelData)
       {
         DicomWebJsonVisitor visitor;
         visitor.SetFormatter(*this);
 
-        dicom.Apply(visitor);
+        dicom.Apply(visitor, injectEmptyPixelData);
 
         std::string s;
 
@@ -1077,10 +1078,11 @@
       void Apply(char** target,
                  bool isJson,
                  const void* dicom,
-                 size_t dicomSize) 
+                 size_t dicomSize,
+                 bool injectEmptyPixelData) 
       {
         ParsedDicomFile parsed(dicom, dicomSize);
-        Apply(target, isJson, parsed);
+        Apply(target, isJson, parsed, injectEmptyPixelData);
       }
     };
   }
@@ -3636,7 +3638,8 @@
         DicomWebBinaryFormatter formatter(p.dicomWebCallback, p.dicomWebPayload);
         formatter.Apply(p.targetStringToFree,
                         (service == _OrthancPluginService_GetInstanceDicomWebJson),
-                        instance.GetParsedDicomFile());
+                        instance.GetParsedDicomFile(),
+                        false);
         return;
       }
 
@@ -5195,7 +5198,7 @@
         DicomWebBinaryFormatter formatter(p.callback);
         formatter.Apply(p.target,
                         (service == _OrthancPluginService_EncodeDicomWebJson),
-                        p.dicom, p.dicomSize);
+                        p.dicom, p.dicomSize, false);
         return true;
       }
 
@@ -5208,7 +5211,19 @@
         DicomWebBinaryFormatter formatter(p.callback, p.payload);
         formatter.Apply(p.target,
                         (service == _OrthancPluginService_EncodeDicomWebJson2),
-                        p.dicom, p.dicomSize);
+                        p.dicom, p.dicomSize, false);
+        return true;
+      }
+
+      case _OrthancPluginService_EncodeDicomWebJson3:
+      {
+        const _OrthancPluginEncodeDicomWeb3& p =
+          *reinterpret_cast<const _OrthancPluginEncodeDicomWeb3*>(parameters);
+
+        DicomWebBinaryFormatter formatter(p.callback, p.payload);
+        formatter.Apply(p.target,
+                        (service == _OrthancPluginService_EncodeDicomWebJson3),
+                        p.dicom, p.dicomSize, p.injectEmptyPixelData);
         return true;
       }
 
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Wed May 24 08:56:41 2023 +0200
+++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h	Thu May 25 17:19:52 2023 +0200
@@ -447,6 +447,7 @@
     _OrthancPluginService_CreateMemoryBuffer64 = 40, /* New in Orthanc 1.9.0 */
     _OrthancPluginService_CreateDicom2 = 41,         /* New in Orthanc 1.9.0 */
     _OrthancPluginService_GetDatabaseServerIdentifier = 42,         /* New in Orthanc 1.11.1 */
+    _OrthancPluginService_EncodeDicomWebJson3 = 43,  /* New in Orthanc 1.12.1 */
 
     /* Registration of callbacks */
     _OrthancPluginService_RegisterRestCallback = 1000,
@@ -7256,6 +7257,62 @@
   }
 
 
+  typedef struct
+  {
+    char**                                target;
+    const void*                           dicom;
+    uint32_t                              dicomSize;
+    OrthancPluginDicomWebBinaryCallback2  callback;
+    void*                                 payload;
+    bool                                  injectEmptyPixelData;
+  } _OrthancPluginEncodeDicomWeb3;
+
+  /**
+   * @brief Convert a DICOM instance to DICOMweb JSON.
+   *
+   * This function converts a memory buffer containing a DICOM instance,
+   * into its DICOMweb JSON representation.
+   *
+   * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
+   * @param dicom Pointer to the DICOM instance.
+   * @param dicomSize Size of the DICOM instance.
+   * @param callback Callback to set the value of the binary tags.
+   * @param payload User payload.
+   * @return The NULL value in case of error, or the JSON document. This string must
+   * be freed by OrthancPluginFreeString().
+   * @see OrthancPluginCreateDicom()
+   * @ingroup Toolbox
+   **/
+  ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson3(
+    OrthancPluginContext*                 context,
+    const void*                           dicom,
+    uint32_t                              dicomSize,
+    OrthancPluginDicomWebBinaryCallback2  callback,
+    void*                                 payload,
+    bool                                  injectEmptyPixelData)
+  {
+    char* target = NULL;
+    
+    _OrthancPluginEncodeDicomWeb3 params;
+    params.target = &target;
+    params.dicom = dicom;
+    params.dicomSize = dicomSize;
+    params.callback = callback;
+    params.payload = payload;
+    params.injectEmptyPixelData = injectEmptyPixelData;
+
+
+    if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson3, &params) != OrthancPluginErrorCode_Success)
+    {
+      /* Error */
+      return NULL;
+    }
+    else
+    {
+      return target;
+    }
+  }
+
   /**
    * @brief Convert a DICOM instance to DICOMweb XML.
    *