changeset 1721:3bcb01028107 db-changes

removed another flavor of ServerIndex::LookupIdentifier
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 10:39:21 +0200
parents 88b74d8512be
children f1901004f3e4
files OrthancServer/OrthancMoveRequestHandler.cpp OrthancServer/OrthancMoveRequestHandler.h OrthancServer/ServerEnumerations.cpp OrthancServer/ServerEnumerations.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h
diffstat 6 files changed, 39 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/OrthancMoveRequestHandler.cpp	Tue Oct 20 10:24:10 2015 +0200
+++ b/OrthancServer/OrthancMoveRequestHandler.cpp	Tue Oct 20 10:39:21 2015 +0200
@@ -105,9 +105,11 @@
 
 
   bool OrthancMoveRequestHandler::LookupIdentifier(std::string& publicId,
-                                                   DicomTag tag,
+                                                   ResourceType level,
                                                    const DicomMap& input)
   {
+    DicomTag tag = GetIdentifierTag(level);
+
     if (!input.HasTag(tag))
     {
       return false;
@@ -116,7 +118,7 @@
     std::string value = input.GetValue(tag).AsString();
 
     std::list<std::string> ids;
-    context_.GetIndex().LookupIdentifier(ids, tag, value);
+    context_.GetIndex().LookupIdentifier(ids, tag, value, level);
 
     if (ids.size() != 1)
     {
@@ -156,14 +158,9 @@
      * Retrieve the query level.
      **/
 
-    ResourceType level;
     const DicomValue* levelTmp = input.TestAndGetValue(DICOM_TAG_QUERY_RETRIEVE_LEVEL);
 
-    if (levelTmp != NULL) 
-    {
-      level = StringToResourceType(levelTmp->AsString().c_str());
-    }
-    else
+    if (levelTmp == NULL) 
     {
       // The query level is not present in the C-Move request, which
       // does not follow the DICOM standard. This is for instance the
@@ -173,10 +170,10 @@
 
       std::string publicId;
 
-      if (LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input) ||
-          LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input) ||
-          LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input) ||
-          LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input))
+      if (LookupIdentifier(publicId, ResourceType_Instance, input) ||
+          LookupIdentifier(publicId, ResourceType_Series, input) ||
+          LookupIdentifier(publicId, ResourceType_Study, input) ||
+          LookupIdentifier(publicId, ResourceType_Patient, input))
       {
         return new OrthancMoveRequestIterator(context_, targetAet, publicId);
       }
@@ -187,42 +184,23 @@
       }
     }
 
+    assert(levelTmp != NULL);
+    ResourceType level = StringToResourceType(levelTmp->AsString().c_str());      
 
 
     /**
      * Lookup for the resource to be sent.
      **/
 
-    bool ok;
     std::string publicId;
 
-    switch (level)
+    if (LookupIdentifier(publicId, level, input))
     {
-      case ResourceType_Patient:
-        ok = LookupIdentifier(publicId, DICOM_TAG_PATIENT_ID, input);
-        break;
-
-      case ResourceType_Study:
-        ok = LookupIdentifier(publicId, DICOM_TAG_STUDY_INSTANCE_UID, input);
-        break;
-
-      case ResourceType_Series:
-        ok = LookupIdentifier(publicId, DICOM_TAG_SERIES_INSTANCE_UID, input);
-        break;
-
-      case ResourceType_Instance:
-        ok = LookupIdentifier(publicId, DICOM_TAG_SOP_INSTANCE_UID, input);
-        break;
-
-      default:
-        ok = false;
+      return new OrthancMoveRequestIterator(context_, targetAet, publicId);
     }
-
-    if (!ok)
+    else
     {
       throw OrthancException(ErrorCode_BadRequest);
     }
-
-    return new OrthancMoveRequestIterator(context_, targetAet, publicId);
   }
 }
--- a/OrthancServer/OrthancMoveRequestHandler.h	Tue Oct 20 10:24:10 2015 +0200
+++ b/OrthancServer/OrthancMoveRequestHandler.h	Tue Oct 20 10:39:21 2015 +0200
@@ -42,7 +42,7 @@
     ServerContext& context_;
 
     bool LookupIdentifier(std::string& publicId,
-                          DicomTag tag,
+                          ResourceType level,
                           const DicomMap& input);
 
   public:
--- a/OrthancServer/ServerEnumerations.cpp	Tue Oct 20 10:24:10 2015 +0200
+++ b/OrthancServer/ServerEnumerations.cpp	Tue Oct 20 10:39:21 2015 +0200
@@ -365,4 +365,25 @@
     }
   }
 
+
+  DicomTag GetIdentifierTag(ResourceType level)
+  {
+    switch (level)
+    {
+      case ResourceType_Patient:
+        return DICOM_TAG_PATIENT_ID;
+
+      case ResourceType_Study:
+        return DICOM_TAG_STUDY_INSTANCE_UID;
+        
+      case ResourceType_Series:
+        return DICOM_TAG_SERIES_INSTANCE_UID;
+        
+      case ResourceType_Instance:
+        return DICOM_TAG_SOP_INSTANCE_UID;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
 }
--- a/OrthancServer/ServerEnumerations.h	Tue Oct 20 10:24:10 2015 +0200
+++ b/OrthancServer/ServerEnumerations.h	Tue Oct 20 10:39:21 2015 +0200
@@ -35,6 +35,7 @@
 #include <map>
 
 #include "../Core/Enumerations.h"
+#include "../Core/DicomFormat/DicomTag.h"
 
 namespace Orthanc
 {
@@ -194,4 +195,6 @@
   const char* EnumerationToString(TransferSyntax syntax);
 
   ModalityManufacturer StringToModalityManufacturer(const std::string& manufacturer);
+
+  DicomTag GetIdentifierTag(ResourceType level);
 }
--- a/OrthancServer/ServerIndex.cpp	Tue Oct 20 10:24:10 2015 +0200
+++ b/OrthancServer/ServerIndex.cpp	Tue Oct 20 10:39:21 2015 +0200
@@ -1911,25 +1911,6 @@
   }
 
 
-  void ServerIndex::LookupIdentifier(std::list<std::string>& result,
-                                     const DicomTag& tag,
-                                     const std::string& value)
-  {
-    result.clear();
-
-    boost::mutex::scoped_lock lock(mutex_);
-
-    std::list<int64_t> id;
-    db_.LookupIdentifier(id, tag, value);
-
-    for (std::list<int64_t>::const_iterator 
-           it = id.begin(); it != id.end(); ++it)
-    {
-      result.push_back(db_.GetPublicId(*it));
-    }
-  }
-
-
   StoreStatus ServerIndex::AddAttachment(const FileInfo& attachment,
                                          const std::string& publicId)
   {
--- a/OrthancServer/ServerIndex.h	Tue Oct 20 10:24:10 2015 +0200
+++ b/OrthancServer/ServerIndex.h	Tue Oct 20 10:39:21 2015 +0200
@@ -241,10 +241,6 @@
                           const std::string& value,
                           ResourceType type);
 
-    void LookupIdentifier(std::list<std::string>& result,
-                          const DicomTag& tag,
-                          const std::string& value);
-
     StoreStatus AddAttachment(const FileInfo& attachment,
                               const std::string& publicId);