changeset 4729:4e2247df6327

Added "Short" and "Full" options in /modalities/id/find-worklist
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Jun 2021 10:41:35 +0200
parents b5ca12bfce8c
children 7826ac059c31
files NEWS OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake OrthancFramework/Sources/DicomNetworking/DicomFindAnswers.cpp OrthancFramework/Sources/DicomNetworking/DicomFindAnswers.h OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/Sources/ServerJobs/DicomMoveScuJob.cpp OrthancServer/Sources/ServerJobs/DicomMoveScuJob.h
diffstat 8 files changed, 92 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Jun 25 09:12:49 2021 +0200
+++ b/NEWS	Fri Jun 25 10:41:35 2021 +0200
@@ -1,6 +1,13 @@
 Pending changes in the mainline
 ===============================
 
+REST API
+--------
+
+* API version upgraded to 14
+* Added "Short" and "Full" options to control the format of DICOM tags in:
+  - POST /modalities/id/find-worklist
+
 
 Version 1.9.4 (2021-06-24)
 ==========================
--- a/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Fri Jun 25 09:12:49 2021 +0200
+++ b/OrthancFramework/Resources/CMake/OrthancFrameworkParameters.cmake	Fri Jun 25 10:41:35 2021 +0200
@@ -37,7 +37,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 "13")
+set(ORTHANC_API_VERSION "14")
 
 
 #####################################################################
--- a/OrthancFramework/Sources/DicomNetworking/DicomFindAnswers.cpp	Fri Jun 25 09:12:49 2021 +0200
+++ b/OrthancFramework/Sources/DicomNetworking/DicomFindAnswers.cpp	Fri Jun 25 10:41:35 2021 +0200
@@ -197,24 +197,22 @@
 
   void DicomFindAnswers::ToJson(Json::Value& target,
                                 size_t index,
-                                bool simplify) const
+                                DicomToJsonFormat format) const
   {
-    DicomToJsonFormat format = (simplify ? DicomToJsonFormat_Human : DicomToJsonFormat_Full);
-    
     const ParsedDicomFile& answer = GetAnswer(index);
     answer.DatasetToJson(target, format, DicomToJsonFlags_None, 0);
   }
 
 
   void DicomFindAnswers::ToJson(Json::Value& target,
-                                bool simplify) const
+                                DicomToJsonFormat format) const
   {
     target = Json::arrayValue;
 
     for (size_t i = 0; i < GetSize(); i++)
     {
       Json::Value answer;
-      ToJson(answer, i, simplify);
+      ToJson(answer, i, format);
       target.append(answer);
     }
   }
@@ -236,5 +234,21 @@
   {
     return Add(const_cast<const ParsedDicomFile&>(dicom));
   }
+
+  void DicomFindAnswers::ToJson(Json::Value& target,
+                                size_t index,
+                                bool simplify) const
+  {
+    DicomToJsonFormat format = (simplify ? DicomToJsonFormat_Human : DicomToJsonFormat_Full);
+    ToJson(target, index, format);
+  }
+
+
+  void DicomFindAnswers::ToJson(Json::Value& target,
+                                bool simplify) const
+  {
+    DicomToJsonFormat format = (simplify ? DicomToJsonFormat_Human : DicomToJsonFormat_Full);
+    ToJson(target, format);
+  }
 #endif
 }
--- a/OrthancFramework/Sources/DicomNetworking/DicomFindAnswers.h	Fri Jun 25 09:12:49 2021 +0200
+++ b/OrthancFramework/Sources/DicomNetworking/DicomFindAnswers.h	Fri Jun 25 10:41:35 2021 +0200
@@ -39,6 +39,13 @@
 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
     // Alias for binary compatibility with Orthanc Framework 1.7.2 => don't use it anymore
     void Add(ParsedDicomFile& dicom);
+
+    void ToJson(Json::Value& target,
+                bool simplify) const;
+
+    void ToJson(Json::Value& target,
+                size_t index,
+                bool simplify) const;
 #endif
 
   public:
@@ -72,11 +79,11 @@
     DcmDataset* ExtractDcmDataset(size_t index) const;
 
     void ToJson(Json::Value& target,
-                bool simplify) const;
+                DicomToJsonFormat format) const;
 
     void ToJson(Json::Value& target,
                 size_t index,
-                bool simplify) const;
+                DicomToJsonFormat format) const;
 
     bool IsComplete() const;
 
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Fri Jun 25 09:12:49 2021 +0200
+++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Fri Jun 25 10:41:35 2021 +0200
@@ -689,7 +689,7 @@
   }
 
   Json::Value j;
-  a.ToJson(j, true);
+  a.ToJson(j, DicomToJsonFormat_Human);
   ASSERT_EQ(3u, j.size());
 
   //std::cout << j;
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Fri Jun 25 09:12:49 2021 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Fri Jun 25 10:41:35 2021 +0200
@@ -391,7 +391,7 @@
     }
 
     Json::Value result;
-    answers.ToJson(result, true);
+    answers.ToJson(result, DicomToJsonFormat_Human);
     call.GetOutput().AnswerJson(result);
   }
 
@@ -434,7 +434,7 @@
     }
 
     Json::Value result;
-    answers.ToJson(result, true);
+    answers.ToJson(result, DicomToJsonFormat_Human);
     call.GetOutput().AnswerJson(result);
   }
 
@@ -478,7 +478,7 @@
     }
 
     Json::Value result;
-    answers.ToJson(result, true);
+    answers.ToJson(result, DicomToJsonFormat_Human);
     call.GetOutput().AnswerJson(result);
   }
 
@@ -523,7 +523,7 @@
     }
 
     Json::Value result;
-    answers.ToJson(result, true);
+    answers.ToJson(result, DicomToJsonFormat_Human);
     call.GetOutput().AnswerJson(result);
   }
 
@@ -577,7 +577,7 @@
     for (size_t i = 0; i < patients.GetSize(); i++)
     {
       Json::Value patient;
-      patients.ToJson(patient, i, true);
+      patients.ToJson(patient, i, DicomToJsonFormat_Human);
 
       DicomMap::SetupFindStudyTemplate(m);
       if (!MergeQueryAndTemplate(m, call))
@@ -596,7 +596,7 @@
       for (size_t j = 0; j < studies.GetSize(); j++)
       {
         Json::Value study;
-        studies.ToJson(study, j, true);
+        studies.ToJson(study, j, DicomToJsonFormat_Human);
 
         DicomMap::SetupFindSeriesTemplate(m);
         if (!MergeQueryAndTemplate(m, call))
@@ -615,7 +615,7 @@
         for (size_t k = 0; k < series.GetSize(); k++)
         {
           Json::Value series2;
-          series.ToJson(series2, k, true);
+          series.ToJson(series2, k, DicomToJsonFormat_Human);
           study["Series"].append(series2);
         }
 
@@ -2140,13 +2140,16 @@
   {
     if (call.IsDocumentation())
     {
+      OrthancRestApi::DocumentDicomFormat(call, DicomToJsonFormat_Human);
+
       call.GetDocumentation()
         .SetTag("Networking")
         .SetSummary("C-FIND SCU for worklist")
         .SetDescription("Trigger C-FIND SCU command against the remote worklists of the DICOM modality "
                         "whose identifier is provided in URL")
         .SetUriArgument("id", "Identifier of the modality of interest")
-        .AddRequestType(MimeType_Json, "Associative array containing the query on the values of the DICOM tags")
+        .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject,
+                         "Associative array containing the filter on the values of the DICOM tags", true)
         .AddAnswerType(MimeType_Json, "JSON array describing the DICOM tags of the matching worklists");
       return;
     }
@@ -2154,9 +2157,23 @@
     Json::Value json;
     if (call.ParseJsonRequest(json))
     {
-      std::unique_ptr<ParsedDicomFile> query
-        (ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(0),
-                                         "" /* no private creator */));
+      std::unique_ptr<ParsedDicomFile> query;
+      DicomToJsonFormat format;
+
+      if (json.isMember(KEY_QUERY))
+      {
+        // New in Orthanc 1.9.5
+        query.reset(ParsedDicomFile::CreateFromJson(json[KEY_QUERY], static_cast<DicomFromJsonFlags>(0),
+                                                    "" /* no private creator */));
+        format = OrthancRestApi::GetDicomFormat(json, DicomToJsonFormat_Human);
+      }
+      else
+      {
+        // Compatibility with Orthanc <= 1.9.4
+        query.reset(ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(0),
+                                                    "" /* no private creator */));
+        format = DicomToJsonFormat_Human;
+      }
 
       DicomFindAnswers answers(true);
 
@@ -2166,7 +2183,7 @@
       }
 
       Json::Value result;
-      answers.ToJson(result, true);
+      answers.ToJson(result, format);
       call.GetOutput().AnswerJson(result);
     }
     else
--- a/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.cpp	Fri Jun 25 09:12:49 2021 +0200
+++ b/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.cpp	Fri Jun 25 10:41:35 2021 +0200
@@ -203,11 +203,24 @@
   }
   
 
+  void DicomMoveScuJob::SetQueryFormat(DicomToJsonFormat format)
+  {
+    if (IsStarted())
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      queryFormat_ = format;
+    }
+  }
+
+
   void DicomMoveScuJob::GetPublicContent(Json::Value& value)
   {
     SetOfCommandsJob::GetPublicContent(value);
 
-    value["LocalAet"] = parameters_.GetLocalApplicationEntityTitle();
+    value[LOCAL_AET] = parameters_.GetLocalApplicationEntityTitle();
     value["RemoteAet"] = parameters_.GetRemoteModality().GetApplicationEntityTitle();
     value["Query"] = query_;
   }
@@ -219,7 +232,8 @@
     context_(context),
     parameters_(DicomAssociationParameters::UnserializeJob(serialized)),
     targetAet_(SerializationToolbox::ReadString(serialized, TARGET_AET)),
-    query_(Json::arrayValue)
+    query_(Json::arrayValue),
+    queryFormat_(DicomToJsonFormat_Short)
   {
     if (serialized.isMember(QUERY) &&
         serialized[QUERY].type() == Json::arrayValue)
--- a/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.h	Fri Jun 25 09:12:49 2021 +0200
+++ b/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.h	Fri Jun 25 10:41:35 2021 +0200
@@ -53,6 +53,7 @@
     DicomAssociationParameters  parameters_;
     std::string                 targetAet_;
     Json::Value                 query_;
+    DicomToJsonFormat           queryFormat_;  // New in 1.9.5
 
     std::unique_ptr<DicomControlUserConnection>  connection_;
     
@@ -61,7 +62,8 @@
   public:
     explicit DicomMoveScuJob(ServerContext& context) :
       context_(context),
-      query_(Json::arrayValue)
+      query_(Json::arrayValue),
+      queryFormat_(DicomToJsonFormat_Short)
     {
     }
 
@@ -91,6 +93,13 @@
     
     void SetTargetAet(const std::string& aet);
 
+    void SetQueryFormat(DicomToJsonFormat format);
+
+    DicomToJsonFormat GetQueryFormat() const
+    {
+      return queryFormat_;
+    }
+
     virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE;
 
     virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE