diff OrthancServer/OrthancMoveRequestHandler.cpp @ 1726:9d8bb6bc2890

integration db-changes->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 11:22:50 +0200
parents 7e0b5e413c7c
children 1ae29c5e52fb ec66a16aa398
line wrap: on
line diff
--- a/OrthancServer/OrthancMoveRequestHandler.cpp	Fri Oct 16 17:26:11 2015 +0200
+++ b/OrthancServer/OrthancMoveRequestHandler.cpp	Tue Oct 20 11:22:50 2015 +0200
@@ -105,9 +105,34 @@
 
 
   bool OrthancMoveRequestHandler::LookupIdentifier(std::string& publicId,
-                                                   DicomTag tag,
+                                                   ResourceType level,
                                                    const DicomMap& input)
   {
+    DicomTag tag(0, 0);   // Dummy initialization
+
+    switch (level)
+    {
+      case ResourceType_Patient:
+        tag = DICOM_TAG_PATIENT_ID;
+        break;
+
+      case ResourceType_Study:
+        tag = (input.HasTag(DICOM_TAG_ACCESSION_NUMBER) ? 
+               DICOM_TAG_ACCESSION_NUMBER : DICOM_TAG_STUDY_INSTANCE_UID);
+        break;
+        
+      case ResourceType_Series:
+        tag = DICOM_TAG_SERIES_INSTANCE_UID;
+        break;
+        
+      case ResourceType_Instance:
+        tag = DICOM_TAG_SOP_INSTANCE_UID;
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+
     if (!input.HasTag(tag))
     {
       return false;
@@ -116,7 +141,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 +181,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 +193,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 +207,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);
   }
 }