changeset 2059:8e67325eaa3f

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Jun 2016 20:02:21 +0200
parents 43cd2ab060c7
children e12d83e9ee59
files OrthancServer/DicomProtocol/DicomFindAnswers.cpp OrthancServer/DicomProtocol/DicomFindAnswers.h OrthancServer/Internals/FindScp.cpp OrthancServer/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/QueryRetrieveHandler.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h UnitTestsSources/FromDcmtkTests.cpp
diffstat 8 files changed, 95 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomProtocol/DicomFindAnswers.cpp	Thu Jun 30 08:20:23 2016 +0200
+++ b/OrthancServer/DicomProtocol/DicomFindAnswers.cpp	Thu Jun 30 20:02:21 2016 +0200
@@ -50,29 +50,34 @@
     ParsedDicomFile* dicom_;
     DicomMap*        map_;
 
-    void CleanupDicom()
+    void CleanupDicom(bool isWorklist)
     {
-      if (dicom_ != NULL)
+      if (isWorklist &&
+          dicom_ != NULL)
       {
+        // These lines are necessary when serving worklists, otherwise
+        // Orthanc does not behave as "wlmscpfs"
         dicom_->Remove(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID);
         dicom_->Remove(DICOM_TAG_SOP_INSTANCE_UID);
       }
     }
 
   public:
-    Answer(ParsedDicomFile& dicom) : 
+    Answer(bool isWorklist,
+           ParsedDicomFile& dicom) : 
       dicom_(dicom.Clone()),
       map_(NULL)
     {
-      CleanupDicom();
+      CleanupDicom(isWorklist);
     }
 
-    Answer(const void* dicom,
+    Answer(bool isWorklist,
+           const void* dicom,
            size_t size) : 
       dicom_(new ParsedDicomFile(dicom, size)),
       map_(NULL)
     {
-      CleanupDicom();
+      CleanupDicom(isWorklist);
     }
 
     Answer(const DicomMap& map) : 
@@ -120,6 +125,20 @@
   };
 
 
+  void DicomFindAnswers::SetWorklist(bool isWorklist)
+  {
+    if (answers_.empty())
+    {
+      isWorklist_ = isWorklist;
+    }
+    else
+    {
+      // This set of answers is not empty anymore, cannot change its type
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+  }
+
+
   void DicomFindAnswers::Clear()
   {
     for (size_t i = 0; i < answers_.size(); i++)
@@ -149,14 +168,14 @@
 
   void DicomFindAnswers::Add(ParsedDicomFile& dicom)
   {
-    answers_.push_back(new Answer(dicom));
+    answers_.push_back(new Answer(isWorklist_, dicom));
   }
 
 
   void DicomFindAnswers::Add(const void* dicom,
                              size_t size)
   {
-    answers_.push_back(new Answer(dicom, size));
+    answers_.push_back(new Answer(isWorklist_, dicom, size));
   }
 
 
--- a/OrthancServer/DicomProtocol/DicomFindAnswers.h	Thu Jun 30 08:20:23 2016 +0200
+++ b/OrthancServer/DicomProtocol/DicomFindAnswers.h	Thu Jun 30 20:02:21 2016 +0200
@@ -41,13 +41,16 @@
   private:
     class Answer;
 
+    bool                 isWorklist_;
     std::vector<Answer*> answers_;
     bool                 complete_;
 
     Answer& GetAnswerInternal(size_t index) const;
 
   public:
-    DicomFindAnswers() : complete_(true)
+    DicomFindAnswers(bool isWorklist) : 
+      isWorklist_(isWorklist),
+      complete_(true)
     {
     }
 
@@ -56,6 +59,13 @@
       Clear();
     }
 
+    void SetWorklist(bool isWorklist);
+
+    bool IsWorklist() const
+    {
+      return isWorklist_;
+    }
+
     void Clear();
 
     void Reserve(size_t index);
--- a/OrthancServer/Internals/FindScp.cpp	Thu Jun 30 08:20:23 2016 +0200
+++ b/OrthancServer/Internals/FindScp.cpp	Thu Jun 30 20:02:21 2016 +0200
@@ -103,6 +103,10 @@
       const std::string* remoteIp_;
       const std::string* remoteAet_;
       const std::string* calledAet_;
+
+      FindScpData() : answers_(false)
+      {
+      }
     };
 
 
@@ -132,6 +136,8 @@
         {
           if (sopClassUid == UID_FINDModalityWorklistInformationModel)
           {
+            data.answers_.SetWorklist(true);
+
             if (data.worklistHandler_ != NULL)
             {
               ParsedDicomFile query(*requestIdentifiers);
@@ -147,6 +153,8 @@
           }
           else
           {
+            data.answers_.SetWorklist(false);
+
             if (data.findHandler_ != NULL)
             {
               std::list<DicomTag> sequencesToReturn;
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Jun 30 08:20:23 2016 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Jun 30 20:02:21 2016 +0200
@@ -178,7 +178,7 @@
     RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
     ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
 
-    DicomFindAnswers answers;
+    DicomFindAnswers answers(false);
     FindPatient(answers, locker.GetConnection(), fields);
 
     Json::Value result;
@@ -208,7 +208,7 @@
     RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
     ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
 
-    DicomFindAnswers answers;
+    DicomFindAnswers answers(false);
     FindStudy(answers, locker.GetConnection(), fields);
 
     Json::Value result;
@@ -239,7 +239,7 @@
     RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
     ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
 
-    DicomFindAnswers answers;
+    DicomFindAnswers answers(false);
     FindSeries(answers, locker.GetConnection(), fields);
 
     Json::Value result;
@@ -271,7 +271,7 @@
     RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
     ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
 
-    DicomFindAnswers answers;
+    DicomFindAnswers answers(false);
     FindInstance(answers, locker.GetConnection(), fields);
 
     Json::Value result;
@@ -308,7 +308,7 @@
     RemoteModalityParameters remote = Configuration::GetModalityUsingSymbolicName(call.GetUriComponent("id", ""));
     ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
 
-    DicomFindAnswers patients;
+    DicomFindAnswers patients(false);
     FindPatient(patients, locker.GetConnection(), m);
 
     // Loop over the found patients
@@ -326,7 +326,7 @@
 
       CopyTagIfExists(m, patients.GetAnswer(i), DICOM_TAG_PATIENT_ID);
 
-      DicomFindAnswers studies;
+      DicomFindAnswers studies(false);
       FindStudy(studies, locker.GetConnection(), m);
 
       patient["Studies"] = Json::arrayValue;
@@ -346,7 +346,7 @@
         CopyTagIfExists(m, studies.GetAnswer(j), DICOM_TAG_PATIENT_ID);
         CopyTagIfExists(m, studies.GetAnswer(j), DICOM_TAG_STUDY_INSTANCE_UID);
 
-        DicomFindAnswers series;
+        DicomFindAnswers series(false);
         FindSeries(series, locker.GetConnection(), m);
 
         // Loop over the found series
@@ -979,7 +979,7 @@
 
       std::auto_ptr<ParsedDicomFile> query(ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(0)));
 
-      DicomFindAnswers answers;
+      DicomFindAnswers answers(true);
 
       {
         ReusableDicomUserConnection::Locker locker(context.GetReusableDicomUserConnection(), localAet, remote);
--- a/OrthancServer/QueryRetrieveHandler.cpp	Thu Jun 30 08:20:23 2016 +0200
+++ b/OrthancServer/QueryRetrieveHandler.cpp	Thu Jun 30 20:02:21 2016 +0200
@@ -60,7 +60,8 @@
     context_(context),
     localAet_(context.GetDefaultLocalApplicationEntityTitle()),
     done_(false),
-    level_(ResourceType_Study)
+    level_(ResourceType_Study),
+    answers_(false)
   {
   }
 
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Jun 30 08:20:23 2016 +0200
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Jun 30 20:02:21 2016 +0200
@@ -51,6 +51,15 @@
     }
   }
 
+  
+  void PluginException::Check(OrthancPluginErrorCode code)
+  {
+    if (code != OrthancPluginErrorCode_Success)
+    {
+      throw PluginException(code);
+    }
+  }
+
 
   MemoryBuffer::MemoryBuffer(OrthancPluginContext* context) : 
     context_(context)
@@ -233,6 +242,18 @@
   }
 
 
+  void MemoryBuffer::CreateDicom(const Json::Value& tags,
+                                 OrthancPluginCreateDicomFlags flags)
+  {
+    Clear();
+
+    Json::FastWriter writer;
+    std::string s = writer.write(tags);
+    
+    PluginException::Check(OrthancPluginCreateDicom(context_, &buffer_, s.c_str(), NULL, flags));
+  }
+
+
   OrthancString::OrthancString(OrthancPluginContext* context,
                                char* str) :
     context_(context),
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Thu Jun 30 08:20:23 2016 +0200
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Thu Jun 30 20:02:21 2016 +0200
@@ -65,6 +65,8 @@
     }
 
     const char* GetErrorDescription(OrthancPluginContext* context) const;
+
+    static void Check(OrthancPluginErrorCode code);
   };
 
 
@@ -147,6 +149,9 @@
     {
       return RestApiPut(uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins);
     }
+
+    void CreateDicom(const Json::Value& tags,
+                     OrthancPluginCreateDicomFlags flags);
   };
 
 
@@ -355,19 +360,28 @@
   inline void LogError(OrthancPluginContext* context,
                        const std::string& message)
   {
-    OrthancPluginLogError(context, message.c_str());
+    if (context != NULL)
+    {
+      OrthancPluginLogError(context, message.c_str());
+    }
   }
 
   inline void LogWarning(OrthancPluginContext* context,
                          const std::string& message)
   {
-    OrthancPluginLogWarning(context, message.c_str());
+    if (context != NULL)
+    {
+      OrthancPluginLogWarning(context, message.c_str());
+    }
   }
 
   inline void LogInfo(OrthancPluginContext* context,
                       const std::string& message)
   {
-    OrthancPluginLogInfo(context, message.c_str());
+    if (context != NULL)
+    {
+      OrthancPluginLogInfo(context, message.c_str());
+    }
   }
 
 
--- a/UnitTestsSources/FromDcmtkTests.cpp	Thu Jun 30 08:20:23 2016 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Thu Jun 30 20:02:21 2016 +0200
@@ -687,7 +687,7 @@
 
 TEST(DicomFindAnswers, Basic)
 {
-  DicomFindAnswers a;
+  DicomFindAnswers a(false);
 
   {
     DicomMap m;