changeset 1797:23722a191e4e worklists

worklists are working
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 20 Nov 2015 11:37:58 +0100
parents 5e08a5fe6b27
children e92cd8841a5f
files OrthancServer/DicomProtocol/DicomFindAnswers.cpp OrthancServer/Search/HierarchicalMatcher.cpp OrthancServer/main.cpp
diffstat 3 files changed, 58 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomProtocol/DicomFindAnswers.cpp	Thu Nov 19 18:32:00 2015 +0100
+++ b/OrthancServer/DicomProtocol/DicomFindAnswers.cpp	Fri Nov 20 11:37:58 2015 +0100
@@ -48,12 +48,22 @@
   private:
     ParsedDicomFile* dicom_;
     DicomMap*        map_;
-    
+
+    void CleanupDicom()
+    {
+      if (dicom_ != NULL)
+      {
+        dicom_->Remove(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID);
+        dicom_->Remove(DICOM_TAG_SOP_INSTANCE_UID);
+      }
+    }
+
   public:
     Answer(ParsedDicomFile& dicom) : 
       dicom_(dicom.Clone()),
       map_(NULL)
     {
+      CleanupDicom();
     }
 
     Answer(const char* dicom,
@@ -61,6 +71,7 @@
       dicom_(new ParsedDicomFile(dicom, size)),
       map_(NULL)
     {
+      CleanupDicom();
     }
 
     Answer(const DicomMap& map) : 
--- a/OrthancServer/Search/HierarchicalMatcher.cpp	Thu Nov 19 18:32:00 2015 +0100
+++ b/OrthancServer/Search/HierarchicalMatcher.cpp	Fri Nov 20 11:37:58 2015 +0100
@@ -235,7 +235,7 @@
         if (!item.findAndGetSequence(tag, sequence).good() ||
             sequence == NULL)
         {
-          return false;
+          return true;
         }
 
         bool match = false;
@@ -260,10 +260,10 @@
   }
 
 
-  DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& item,
+  DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source,
                                                    Encoding encoding) const
   {
-    std::auto_ptr<DcmDataset> dataset(new DcmDataset);
+    std::auto_ptr<DcmDataset> target(new DcmDataset);
 
     for (Constraints::const_iterator it = constraints_.begin();
          it != constraints_.end(); ++it)
@@ -271,12 +271,12 @@
       DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
       
       DcmElement* element = NULL;
-      if (item.findAndGetElement(tag, element).good() &&
+      if (source.findAndGetElement(tag, element).good() &&
           element != NULL)
       {
         std::auto_ptr<DcmElement> cloned(FromDcmtkBridge::CreateElementForTag(it->first));
         cloned->copyFrom(*element);
-        dataset->insert(cloned.release());
+        target->insert(cloned.release());
       }
     }
 
@@ -286,7 +286,7 @@
       DcmTagKey tag = ToDcmtkBridge::Convert(it->first);
 
       DcmSequenceOfItems* sequence = NULL;
-      if (item.findAndGetSequence(tag, sequence).good() &&
+      if (source.findAndGetSequence(tag, sequence).good() &&
           sequence != NULL)
       {
         std::auto_ptr<DcmSequenceOfItems> cloned(new DcmSequenceOfItems(tag));
@@ -297,17 +297,22 @@
           {
             cloned->append(new DcmItem(*sequence->getItem(i)));
           }
-          else if (it->second->MatchInternal(*sequence->getItem(i), encoding))
+          else if (it->second->MatchInternal(*sequence->getItem(i), encoding))  // TODO Might be optimized
           {
-            cloned->append(it->second->ExtractInternal(*sequence->getItem(i), encoding));
+            // It is necessary to encapsulate the child dataset into a
+            // "DcmItem" object before it can be included in a
+            // sequence. Otherwise, "dciodvfy" reports an error "Bad
+            // tag in sequence - Expecting Item or Sequence Delimiter."
+            std::auto_ptr<DcmDataset> child(it->second->ExtractInternal(*sequence->getItem(i), encoding));
+            cloned->append(new DcmItem(*child));
           }
         }
 
-        dataset->insert(cloned.release());
+        target->insert(cloned.release());
       }
     }
 
-    return dataset.release();
+    return target.release();
   }
 
 
--- a/OrthancServer/main.cpp	Thu Nov 19 18:32:00 2015 +0100
+++ b/OrthancServer/main.cpp	Fri Nov 20 11:37:58 2015 +0100
@@ -57,6 +57,9 @@
 using namespace Orthanc;
 
 
+
+
+
 class OrthancStoreRequestHandler : public IStoreRequestHandler
 {
 private:
@@ -91,6 +94,8 @@
 };
 
 
+
+
 class OrthancWorklistRequestHandler : public IWorklistRequestHandler
 {
 private:
@@ -107,33 +112,42 @@
                       const std::string& remoteIp,
                       const std::string& remoteAet)
   {
-    printf("=====================================================================\n");
-    printf("Worklist\n");
-
     bool caseSensitivePN = Configuration::GetGlobalBoolParameter("CaseSensitivePN", false);
     HierarchicalMatcher matcher(query, caseSensitivePN);
 
-    std::cout << matcher.Format();
+    boost::filesystem::path source("/tmp/worklists/db/ORTHANCTEST");
+    boost::filesystem::directory_iterator end;
 
-    for (unsigned int i = 1; i <= 10; i++)
+    try
     {
-      std::string p = "/tmp/worklists/db/OFFIS/item" + boost::lexical_cast<std::string>(i) + ".wl";
-      std::string s;
-      Toolbox::ReadFile(s, p);
-      ParsedDicomFile f(s);
-      std::cout << p << " => " << matcher.Match(f) << std::endl;
+      for (boost::filesystem::directory_iterator it(source); it != end; ++it)
+      {
+        if (is_regular_file(it->status()))
+        {
+          std::string extension = boost::filesystem::extension(it->path());
+          Toolbox::ToLowerCase(extension);
 
-      if (matcher.Match(f))
-      {
-        std::auto_ptr<ParsedDicomFile> e(matcher.Extract(f));
+          if (extension == ".wl")
+          {
+            std::string s;
+            Toolbox::ReadFile(s, it->path().string());
+            ParsedDicomFile f(s);
 
-        Json::Value v;
-        e->ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0);
-        std::cout << v;
+            if (matcher.Match(f))
+            {
+              std::auto_ptr<ParsedDicomFile> e(matcher.Extract(f));
+              answers.Add(*e);
+            }
+          }
+        }
       }
     }
+    catch (boost::filesystem::filesystem_error&)
+    {
+      LOG(ERROR) << "Inexistent folder while scanning for worklists: " << source;
+    }
 
-    return true;
+    return true;  // All the worklists have been returned
   }
 };