changeset 5204:08e0c9c0ab39

added UserMetadata in /system
author Alain Mazy <am@osimis.io>
date Wed, 29 Mar 2023 19:24:09 +0200
parents f8f1c4a9a216
children ae3b5b29e379
files NEWS OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake OrthancFramework/Sources/EnumerationDictionary.h OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp OrthancServer/Sources/ServerEnumerations.cpp OrthancServer/Sources/ServerEnumerations.h
diffstat 6 files changed, 48 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Mar 29 11:23:37 2023 +0200
+++ b/NEWS	Wed Mar 29 19:24:09 2023 +0200
@@ -1,6 +1,12 @@
 Pending changes in the mainline
 ===============================
 
+REST API
+--------
+
+* API version upgraded to 20
+* /system: added UserMetadata
+
 Maintenance
 -----------
 
--- a/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Wed Mar 29 11:23:37 2023 +0200
+++ b/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Wed Mar 29 19:24:09 2023 +0200
@@ -38,7 +38,7 @@
 # Version of the Orthanc API, can be retrieved from "/system" URI in
 # order to check whether new URI endpoints are available even if using
 # the mainline version of Orthanc
-set(ORTHANC_API_VERSION "19")
+set(ORTHANC_API_VERSION "20")
 
 
 #####################################################################
--- a/OrthancFramework/Sources/EnumerationDictionary.h	Wed Mar 29 11:23:37 2023 +0200
+++ b/OrthancFramework/Sources/EnumerationDictionary.h	Wed Mar 29 19:24:09 2023 +0200
@@ -105,5 +105,10 @@
         return found->second;
       }
     }
+
+    const std::map<std::string, Enumeration>& GetAllEntries() const
+    {
+      return stringToEnumeration_;
+    }
   };
 }
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Wed Mar 29 11:23:37 2023 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Wed Mar 29 19:24:09 2023 +0200
@@ -50,14 +50,23 @@
 
   static void GetMainDicomTagsConfiguration(Json::Value& result)
   {
-      Json::Value v;
-      
       result["Patient"] = DicomMap::GetMainDicomTagsSignature(ResourceType_Patient);
       result["Study"] = DicomMap::GetMainDicomTagsSignature(ResourceType_Study);
       result["Series"] = DicomMap::GetMainDicomTagsSignature(ResourceType_Series);
       result["Instance"] = DicomMap::GetMainDicomTagsSignature(ResourceType_Instance);
   }
 
+  static void GetUserMetadataConfiguration(Json::Value& result)
+  {
+    std::map<std::string, int> userMetadata;
+    Orthanc::GetRegisteredUserMetadata(userMetadata);
+
+    for (std::map<std::string, int>::const_iterator it = userMetadata.begin(); it != userMetadata.end(); ++it)
+    {
+      result[it->first] = it->second;
+    }
+  }
+
   static void GetSystemInformation(RestApiGetCall& call)
   {
     static const char* const API_VERSION = "ApiVersion";
@@ -79,6 +88,7 @@
     static const char* const INGEST_TRANSCODING = "IngestTranscoding";
     static const char* const MAXIMUM_STORAGE_SIZE = "MaximumStorageSize";
     static const char* const MAXIMUM_STORAGE_MODE = "MaximumStorageMode";
+    static const char* const USER_METADATA = "UserMetadata";
 
     if (call.IsDocumentation())
     {
@@ -119,6 +129,8 @@
                         "The configured MaximumStorageSize in MB (new in Orthanc 1.11.3)")
         .SetAnswerField(MAXIMUM_STORAGE_MODE, RestApiCallDocumentation::Type_String,
                         "The configured MaximumStorageMode (new in Orthanc 1.11.3)")
+        .SetAnswerField(USER_METADATA, RestApiCallDocumentation::Type_JsonObject,
+                        "The configured UserMetadata (new in Orthanc 1.12.0)")
         .SetHttpGetSample("https://demo.orthanc-server.com/system", true);
       return;
     }
@@ -172,6 +184,9 @@
     result[MAIN_DICOM_TAGS] = Json::objectValue;
     GetMainDicomTagsConfiguration(result[MAIN_DICOM_TAGS]);
 
+    result[USER_METADATA] = Json::objectValue;
+    GetUserMetadataConfiguration(result[USER_METADATA]);
+
     call.GetOutput().AnswerJson(result);
   }
 
--- a/OrthancServer/Sources/ServerEnumerations.cpp	Wed Mar 29 11:23:37 2023 +0200
+++ b/OrthancServer/Sources/ServerEnumerations.cpp	Wed Mar 29 19:24:09 2023 +0200
@@ -112,6 +112,23 @@
     return dictMetadataType_.Translate(str);
   }
 
+  void GetRegisteredUserMetadata(std::map<std::string, int>& allEntries)
+  {
+    boost::mutex::scoped_lock lock(enumerationsMutex_);
+
+    allEntries.clear();
+
+    std::map<std::string, MetadataType> allEntriesTyped = dictMetadataType_.GetAllEntries();
+
+    for (std::map<std::string, MetadataType>::const_iterator it = allEntriesTyped.begin(); it != allEntriesTyped.end(); ++it)
+    {
+      if (it->second >= MetadataType_StartUser)
+      {
+        allEntries[it->first] = it->second;
+      }
+    }
+  }
+
   void RegisterUserContentType(int contentType,
                                const std::string& name,
                                const std::string& mime)
--- a/OrthancServer/Sources/ServerEnumerations.h	Wed Mar 29 11:23:37 2023 +0200
+++ b/OrthancServer/Sources/ServerEnumerations.h	Wed Mar 29 19:24:09 2023 +0200
@@ -216,6 +216,8 @@
 
   std::string EnumerationToString(MetadataType type);
 
+  void GetRegisteredUserMetadata(std::map<std::string, int>& allEntries);
+
   void RegisterUserContentType(int contentType,
                                const std::string& name,
                                const std::string& mime);