changeset 1815:2abfdca9b915

OrthancPluginGetInstanceOrigin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2015 11:38:14 +0100
parents 7c5ea3e51839
children 87c069c94ac9
files NEWS OrthancServer/DicomInstanceToStore.h Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/PluginsEnumerations.cpp Plugins/Engine/PluginsEnumerations.h Plugins/Include/orthanc/OrthancCPlugin.h Plugins/Samples/Basic/Plugin.c
diffstat 7 files changed, 113 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Nov 24 11:03:09 2015 +0100
+++ b/NEWS	Tue Nov 24 11:38:14 2015 +0100
@@ -30,14 +30,20 @@
 Plugins
 -------
 
-* New functions "OrthancPluginDicomInstanceToJson()" and "OrthancPluginDicomBufferToJson()"
-* New function "OrthancPluginRegisterErrorCode()" to declare custom error codes
-* New function "OrthancPluginRegisterDictionaryTag()" to declare custom DICOM tags
-* New function "OrthancPluginRestApiGet2()" to provide HTTP headers when calling Orthanc API
-* New "OrthancStarted", "OrthancStopped", "UpdatedAttachment" 
-  and "UpdatedMetadata" events in change callbacks
+* New functions:
+  - "OrthancPluginDicomInstanceToJson()" to convert DICOM to JSON
+  - "OrthancPluginDicomBufferToJson()" to convert DICOM to JSON
+  - "OrthancPluginRegisterErrorCode()" to declare custom error codes
+  - "OrthancPluginRegisterDictionaryTag()" to declare custom DICOM tags
+  - "OrthancPluginRestApiGet2()" to provide HTTP headers when calling Orthanc API
+  - "OrthancPluginGetInstanceOrigin()" to know through which mechanism an instance was received
+* New events in change callbacks:
+  - "OrthancStarted"
+  - "OrthancStopped"
+  - "UpdatedAttachment" 
+  - "UpdatedMetadata"
 * "/system" URI gives information about the plugins used for storage area and DB back-end
-* Plugin callbacks should now return explicit "OrthancPluginErrorCode" instead of integers
+* Plugin callbacks must now return explicit "OrthancPluginErrorCode" (instead of integers)
 
 Lua
 ---
--- a/OrthancServer/DicomInstanceToStore.h	Tue Nov 24 11:03:09 2015 +0100
+++ b/OrthancServer/DicomInstanceToStore.h	Tue Nov 24 11:38:14 2015 +0100
@@ -171,6 +171,11 @@
 
     void SetPluginsOrigin();
 
+    RequestOrigin GetRequestOrigin() const
+    {
+      return origin_;
+    }
+
     const char* GetRemoteAet() const; 
 
     void SetBuffer(const std::string& dicom)
--- a/Plugins/Engine/OrthancPlugins.cpp	Tue Nov 24 11:03:09 2015 +0100
+++ b/Plugins/Engine/OrthancPlugins.cpp	Tue Nov 24 11:38:14 2015 +0100
@@ -429,6 +429,7 @@
         sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
         sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) ||
         sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
+        sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) ||
         static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeBinary) != static_cast<int>(DicomToJsonFlags_IncludeBinary) ||
         static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePrivateTags) != static_cast<int>(DicomToJsonFlags_IncludePrivateTags) ||
         static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast<int>(DicomToJsonFlags_IncludeUnknownTags) ||
@@ -1158,6 +1159,10 @@
         return;
       }
 
+      case _OrthancPluginService_GetInstanceOrigin:   // New in Orthanc 0.9.5
+        *p.resultOrigin = Plugins::Convert(instance.GetRequestOrigin());
+        return;
+
       default:
         throw OrthancException(ErrorCode_InternalError);
     }
@@ -1597,6 +1602,7 @@
       case _OrthancPluginService_GetInstanceSimplifiedJson:
       case _OrthancPluginService_HasInstanceMetadata:
       case _OrthancPluginService_GetInstanceMetadata:
+      case _OrthancPluginService_GetInstanceOrigin:
         AccessDicomInstance(service, parameters);
         return true;
 
--- a/Plugins/Engine/PluginsEnumerations.cpp	Tue Nov 24 11:03:09 2015 +0100
+++ b/Plugins/Engine/PluginsEnumerations.cpp	Tue Nov 24 11:38:14 2015 +0100
@@ -279,6 +279,31 @@
     }
 
 
+    OrthancPluginInstanceOrigin Convert(RequestOrigin origin)
+    {
+      switch (origin)
+      {
+        case RequestOrigin_DicomProtocol:
+          return OrthancPluginInstanceOrigin_DicomProtocol;
+
+        case RequestOrigin_Http:
+          return OrthancPluginInstanceOrigin_RestApi;
+
+        case RequestOrigin_Lua:
+          return OrthancPluginInstanceOrigin_Lua;
+
+        case RequestOrigin_Plugins:
+          return OrthancPluginInstanceOrigin_Plugins;
+
+        case RequestOrigin_Unknown:
+          return OrthancPluginInstanceOrigin_Unknown;
+
+        default:
+          throw OrthancException(ErrorCode_ParameterOutOfRange);
+      }
+    }
+
+
 #if !defined(ORTHANC_ENABLE_DCMTK) || ORTHANC_ENABLE_DCMTK != 0
     DcmEVR Convert(OrthancPluginValueRepresentation vr)
     {
--- a/Plugins/Engine/PluginsEnumerations.h	Tue Nov 24 11:03:09 2015 +0100
+++ b/Plugins/Engine/PluginsEnumerations.h	Tue Nov 24 11:38:14 2015 +0100
@@ -65,6 +65,8 @@
 
     IdentifierConstraintType Convert(OrthancPluginIdentifierConstraint constraint);
 
+    OrthancPluginInstanceOrigin Convert(RequestOrigin origin);
+
 #if !defined(ORTHANC_ENABLE_DCMTK) || ORTHANC_ENABLE_DCMTK != 0
     DcmEVR Convert(OrthancPluginValueRepresentation vr);
 #endif
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Nov 24 11:03:09 2015 +0100
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Nov 24 11:38:14 2015 +0100
@@ -445,6 +445,7 @@
     _OrthancPluginService_GetInstanceSimplifiedJson = 4004,
     _OrthancPluginService_HasInstanceMetadata = 4005,
     _OrthancPluginService_GetInstanceMetadata = 4006,
+    _OrthancPluginService_GetInstanceOrigin = 4007,
 
     /* Services for plugins implementing a database back-end */
     _OrthancPluginService_RegisterDatabaseBackend = 5000,
@@ -701,15 +702,29 @@
    **/
   typedef enum
   {
-    OrthancPluginIdentifierConstraint_Equal,           /*!< Equal */
-    OrthancPluginIdentifierConstraint_SmallerOrEqual,  /*!< Less or equal */
-    OrthancPluginIdentifierConstraint_GreaterOrEqual,  /*!< More or equal */
-    OrthancPluginIdentifierConstraint_Wildcard,        /*!< Case-sensitive wildcard matching (with * and ?) */
+    OrthancPluginIdentifierConstraint_Equal = 1,           /*!< Equal */
+    OrthancPluginIdentifierConstraint_SmallerOrEqual = 2,  /*!< Less or equal */
+    OrthancPluginIdentifierConstraint_GreaterOrEqual = 3,  /*!< More or equal */
+    OrthancPluginIdentifierConstraint_Wildcard = 4,        /*!< Case-sensitive wildcard matching (with * and ?) */
 
     _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff
   } OrthancPluginIdentifierConstraint;
 
 
+  /**
+   * The origin of a DICOM instance that has been received by Orthanc.
+   **/
+  typedef enum
+  {
+    OrthancPluginInstanceOrigin_Unknown = 1,        /*!< Unknown origin */
+    OrthancPluginInstanceOrigin_DicomProtocol = 2,  /*!< Instance received through DICOM protocol */
+    OrthancPluginInstanceOrigin_RestApi = 3,        /*!< Instance received through REST API of Orthanc */
+    OrthancPluginInstanceOrigin_Plugins = 4,        /*!< Instance added to Orthanc by a plugin */
+    OrthancPluginInstanceOrigin_Lua = 5,            /*!< Instance added to Orthanc by a Lua script */
+
+    _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff
+  } OrthancPluginInstanceOrigin;
+
 
   /**
    * @brief A memory buffer allocated by the core system of Orthanc.
@@ -962,7 +977,8 @@
         sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) ||
         sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
         sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) ||
-        sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint))
+        sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
+        sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin))
     {
       /* Mismatch in the size of the enumerations */
       return 0;
@@ -1910,11 +1926,12 @@
 
   typedef struct
   {
-    char**                      resultStringToFree;
-    const char**                resultString;
-    int64_t*                    resultInt64;
-    const char*                 key;
-    OrthancPluginDicomInstance* instance;
+    char**                       resultStringToFree;
+    const char**                 resultString;
+    int64_t*                     resultInt64;
+    const char*                  key;
+    OrthancPluginDicomInstance*  instance;
+    OrthancPluginInstanceOrigin* resultOrigin;   /* New in Orthanc 0.9.5 SDK */
   } _OrthancPluginAccessDicomInstance;
 
 
@@ -4249,6 +4266,39 @@
   }
 
 
+  /**
+   * @brief Get the origin of a DICOM file.
+   *
+   * This function returns the origin of a DICOM instance that has been received by Orthanc.
+   * 
+   * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
+   * @param instance The instance of interest.
+   * @return The origin of the instance.
+   * @ingroup Callbacks
+   **/
+  ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin(
+    OrthancPluginContext*       context,
+    OrthancPluginDicomInstance* instance)
+  {
+    OrthancPluginInstanceOrigin origin;
+
+    _OrthancPluginAccessDicomInstance params;
+    memset(&params, 0, sizeof(params));
+    params.resultOrigin = &origin;
+    params.instance = instance;
+
+    if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, &params) != OrthancPluginErrorCode_Success)
+    {
+      /* Error */
+      return OrthancPluginInstanceOrigin_Unknown;
+    }
+    else
+    {
+      return origin;
+    }
+  }
+
+
 #ifdef  __cplusplus
 }
 #endif
--- a/Plugins/Samples/Basic/Plugin.c	Tue Nov 24 11:03:09 2015 +0100
+++ b/Plugins/Samples/Basic/Plugin.c	Tue Nov 24 11:38:14 2015 +0100
@@ -262,8 +262,9 @@
   char* json;
   static int first = 1;
 
-  sprintf(buffer, "Just received a DICOM instance of size %d and ID %s from AET %s", 
+  sprintf(buffer, "Just received a DICOM instance of size %d and ID %s from origin %d (AET %s)", 
           (int) OrthancPluginGetInstanceSize(context, instance), instanceId, 
+          OrthancPluginGetInstanceOrigin(context, instance),
           OrthancPluginGetInstanceRemoteAet(context, instance));
 
   OrthancPluginLogWarning(context, buffer);