changeset 2622:3603a2e14592

New option "?short" to list DICOM tags using their hexadecimal ID
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 May 2018 10:08:04 +0200
parents c9bb0c89ccc1
children bd6e0b70e915 442e7ef5cc41
files NEWS OrthancServer/OrthancRestApi/OrthancRestResources.cpp
diffstat 2 files changed, 67 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue May 22 08:10:55 2018 +0200
+++ b/NEWS	Wed May 23 10:08:04 2018 +0200
@@ -9,11 +9,19 @@
 REST API
 --------
 
-* ".../tags" URI was returning only the first value of DicomTags containing 
-  multiple numerical value.  It now returns all values in a string separated
-  by \\ (i.e.: "1\\2\\3").  Note that, for data already in Orthanc, you'll need
-  to reconstruct the data by sending a POST request to the ".../reconstruct" URI.
-  This change triggered an update of ORTHANC_API_VERSION from 1.0 to 1.1
+* New option "?short" to list DICOM tags using their hexadecimal ID in:
+  - "/instances/.../tags?short"
+  - "/instances/.../header?short"
+  - "/{patients|studies|series}/.../instances-tags?short"
+  - "/{patients|studies|series}/.../shared-tags?short"
+  - "/{patients|studies|series|instances}/.../module?short"
+  - "/studies/.../module-patient?short"
+* "/instances/.../tags" URI was returning only the first value of
+  DicomTags containing multiple numerical value.  It now returns all
+  values in a string separated by \\ (i.e.: "1\\2\\3").  Note that,
+  for data already in Orthanc, you'll need to reconstruct the data by
+  sending a POST request to the ".../reconstruct" URI.  This change
+  triggered an update of ORTHANC_API_VERSION from 1.0 to 1.1
 
 Maintenance
 -----------
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Tue May 22 08:10:55 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed May 23 10:08:04 2018 +0200
@@ -50,12 +50,12 @@
 {
   static void AnswerDicomAsJson(RestApiCall& call,
                                 const Json::Value& dicom,
-                                bool simplify)
+                                DicomToJsonFormat mode)
   {
-    if (simplify)
+    if (mode != DicomToJsonFormat_Full)
     {
       Json::Value simplified;
-      ServerToolbox::SimplifyTags(simplified, dicom, DicomToJsonFormat_Human);
+      ServerToolbox::SimplifyTags(simplified, dicom, mode);
       call.GetOutput().AnswerJson(simplified);
     }
     else
@@ -65,6 +65,30 @@
   }
 
 
+  static DicomToJsonFormat GetDicomFormat(const RestApiGetCall& call)
+  {
+    if (call.HasArgument("simplify"))
+    {
+      return DicomToJsonFormat_Human;
+    }
+    else if (call.HasArgument("short"))
+    {
+      return DicomToJsonFormat_Short;
+    }
+    else
+    {
+      return DicomToJsonFormat_Full;
+    }
+  }
+
+
+  static void AnswerDicomAsJson(RestApiGetCall& call,
+                                const Json::Value& dicom)
+  {
+    AnswerDicomAsJson(call, dicom, GetDicomFormat(call));
+  }
+
+
   static void ParseSetOfTags(std::set<DicomTag>& target,
                              const RestApiGetCall& call,
                              const std::string& argument)
@@ -236,7 +260,7 @@
   }
 
 
-  template <bool simplify>
+  template <DicomToJsonFormat format>
   static void GetInstanceTags(RestApiGetCall& call)
   {
     ServerContext& context = OrthancRestApi::GetContext(call);
@@ -246,18 +270,18 @@
     std::set<DicomTag> ignoreTagLength;
     ParseSetOfTags(ignoreTagLength, call, "ignore-length");
     
-    if (simplify ||
+    if (format != DicomToJsonFormat_Full ||
         !ignoreTagLength.empty())
     {
       Json::Value full;
       context.ReadDicomAsJson(full, publicId, ignoreTagLength);
-      AnswerDicomAsJson(call, full, simplify);
+      AnswerDicomAsJson(call, full, format);
     }
     else
     {
       // This path allows to avoid the JSON decoding if no
-      // simplification is asked, or if no "ignore-length" argument is
-      // present
+      // simplification is asked, and if no "ignore-length" argument
+      // is present
       std::string full;
       context.ReadDicomAsJson(full, publicId);
       call.GetOutput().AnswerBuffer(full, "application/json");
@@ -267,15 +291,22 @@
 
   static void GetInstanceTagsBis(RestApiGetCall& call)
   {
-    bool simplify = call.HasArgument("simplify");
-
-    if (simplify)
+    switch (GetDicomFormat(call))
     {
-      GetInstanceTags<true>(call);
-    }
-    else
-    {
-      GetInstanceTags<false>(call);
+      case DicomToJsonFormat_Human:
+        GetInstanceTags<DicomToJsonFormat_Human>(call);
+        break;
+
+      case DicomToJsonFormat_Short:
+        GetInstanceTags<DicomToJsonFormat_Short>(call);
+        break;
+
+      case DicomToJsonFormat_Full:
+        GetInstanceTags<DicomToJsonFormat_Full>(call);
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_InternalError);
     }
   }
 
@@ -1044,13 +1075,12 @@
   {
     ServerContext& context = OrthancRestApi::GetContext(call);
     std::string publicId = call.GetUriComponent("id", "");
-    bool simplify = call.HasArgument("simplify");
 
     Json::Value sharedTags;
     if (ExtractSharedTags(sharedTags, context, publicId))
     {
       // Success: Send the value of the shared tags
-      AnswerDicomAsJson(call, sharedTags, simplify);
+      AnswerDicomAsJson(call, sharedTags);
     }
   }
 
@@ -1071,7 +1101,6 @@
 
     ServerContext& context = OrthancRestApi::GetContext(call);
     std::string publicId = call.GetUriComponent("id", "");
-    bool simplify = call.HasArgument("simplify");
 
     std::set<DicomTag> ignoreTagLength;
     ParseSetOfTags(ignoreTagLength, call, "ignore-length");
@@ -1111,7 +1140,7 @@
       }      
     }
 
-    AnswerDicomAsJson(call, result, simplify);
+    AnswerDicomAsJson(call, result);
   }
     
 
@@ -1306,7 +1335,7 @@
   {
     ServerContext& context = OrthancRestApi::GetContext(call);
     std::string publicId = call.GetUriComponent("id", "");
-    bool simplify = call.HasArgument("simplify");
+    DicomToJsonFormat format = GetDicomFormat(call);
 
     std::set<DicomTag> ignoreTagLength;
     ParseSetOfTags(ignoreTagLength, call, "ignore-length");
@@ -1325,10 +1354,10 @@
       Json::Value full;
       context.ReadDicomAsJson(full, *it, ignoreTagLength);
 
-      if (simplify)
+      if (format != DicomToJsonFormat_Full)
       {
         Json::Value simplified;
-        ServerToolbox::SimplifyTags(simplified, full, DicomToJsonFormat_Human);
+        ServerToolbox::SimplifyTags(simplified, full, format);
         result[*it] = simplified;
       }
       else
@@ -1409,7 +1438,6 @@
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     std::string publicId = call.GetUriComponent("id", "");
-    bool simplify = call.HasArgument("simplify");
 
     std::string dicomContent;
     context.ReadDicom(dicomContent, publicId);
@@ -1422,7 +1450,7 @@
     Json::Value header;
     dicom.HeaderToJson(header, DicomToJsonFormat_Full);
 
-    AnswerDicomAsJson(call, header, simplify);
+    AnswerDicomAsJson(call, header);
   }
 
 
@@ -1495,7 +1523,7 @@
     Register("/instances/{id}/file", GetInstanceFile);
     Register("/instances/{id}/export", ExportInstanceFile);
     Register("/instances/{id}/tags", GetInstanceTagsBis);
-    Register("/instances/{id}/simplified-tags", GetInstanceTags<true>);
+    Register("/instances/{id}/simplified-tags", GetInstanceTags<DicomToJsonFormat_Human>);
     Register("/instances/{id}/frames", ListFrames);
 
     Register("/instances/{id}/frames/{frame}/preview", GetImage<ImageExtractionMode_Preview>);