changeset 1713:4db9200c7f46 db-changes

SetIdentifierTag
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Oct 2015 18:17:22 +0200
parents a7745f3a2cc4
children 81d718bba599
files OrthancServer/DatabaseWrapper.h OrthancServer/DatabaseWrapperBase.cpp OrthancServer/DatabaseWrapperBase.h OrthancServer/IDatabaseWrapper.h OrthancServer/ServerToolbox.cpp Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h UnitTestsSources/ServerIndexTests.cpp
diffstat 8 files changed, 57 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.h	Fri Oct 16 17:36:59 2015 +0200
+++ b/OrthancServer/DatabaseWrapper.h	Fri Oct 16 18:17:22 2015 +0200
@@ -178,6 +178,13 @@
       base_.SetMainDicomTag(id, tag, value);
     }
 
+    virtual void SetIdentifierTag(int64_t id,
+                                 const DicomTag& tag,
+                                 const std::string& value)
+    {
+      base_.SetIdentifierTag(id, tag, value);
+    }
+
     virtual void GetMainDicomTags(DicomMap& map,
                                   int64_t id)
     {
--- a/OrthancServer/DatabaseWrapperBase.cpp	Fri Oct 16 17:36:59 2015 +0200
+++ b/OrthancServer/DatabaseWrapperBase.cpp	Fri Oct 16 18:17:22 2015 +0200
@@ -329,18 +329,20 @@
                                             const DicomTag& tag,
                                             const std::string& value)
   {
-    if (tag.IsIdentifier())
-    {
-      SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)");
-      SetMainDicomTagsInternal(s, id, tag, value);
-    }
-    else
-    {
-      SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
-      SetMainDicomTagsInternal(s, id, tag, value);
-    }
+    SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
+    SetMainDicomTagsInternal(s, id, tag, value);
   }
 
+
+  void DatabaseWrapperBase::SetIdentifierTag(int64_t id,
+                                             const DicomTag& tag,
+                                             const std::string& value)
+  {
+    SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)");
+    SetMainDicomTagsInternal(s, id, tag, value);
+  }
+
+
   void DatabaseWrapperBase::GetMainDicomTags(DicomMap& map,
                                              int64_t id)
   {
--- a/OrthancServer/DatabaseWrapperBase.h	Fri Oct 16 17:36:59 2015 +0200
+++ b/OrthancServer/DatabaseWrapperBase.h	Fri Oct 16 18:17:22 2015 +0200
@@ -132,6 +132,10 @@
                          const DicomTag& tag,
                          const std::string& value);
 
+    void SetIdentifierTag(int64_t id,
+                          const DicomTag& tag,
+                          const std::string& value);
+
     void GetMainDicomTags(DicomMap& map,
                           int64_t id);
 
--- a/OrthancServer/IDatabaseWrapper.h	Fri Oct 16 17:36:59 2015 +0200
+++ b/OrthancServer/IDatabaseWrapper.h	Fri Oct 16 18:17:22 2015 +0200
@@ -178,6 +178,10 @@
                                  const DicomTag& tag,
                                  const std::string& value) = 0;
 
+    virtual void SetIdentifierTag(int64_t id,
+                                  const DicomTag& tag,
+                                  const std::string& value) = 0;
+
     virtual void SetMetadata(int64_t id,
                              MetadataType type,
                              const std::string& value) = 0;
--- a/OrthancServer/ServerToolbox.cpp	Fri Oct 16 17:36:59 2015 +0200
+++ b/OrthancServer/ServerToolbox.cpp	Fri Oct 16 18:17:22 2015 +0200
@@ -194,11 +194,18 @@
       for (size_t i = 0; i < flattened.GetSize(); i++)
       {
         const DicomElement& element = flattened.GetElement(i);
+        const DicomTag& tag = element.GetTag();
 
-        if (includeIdentifiers ||
-            !element.GetTag().IsIdentifier())
+        if (tag.IsIdentifier())
         {
-          database.SetMainDicomTag(resource, element.GetTag(), element.GetValue().AsString());
+          if (includeIdentifiers)
+          {
+            database.SetIdentifierTag(resource, tag, element.GetValue().AsString());
+          }
+        }
+        else
+        {
+          database.SetMainDicomTag(resource, tag, element.GetValue().AsString());
         }
       }
     }
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Fri Oct 16 17:36:59 2015 +0200
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Fri Oct 16 18:17:22 2015 +0200
@@ -711,18 +711,20 @@
     tmp.element = tag.GetElement();
     tmp.value = value.c_str();
 
-    OrthancPluginErrorCode code;
+    CheckSuccess(backend_.setMainDicomTag(payload_, id, &tmp));
+  }
+
 
-    if (tag.IsIdentifier())
-    {
-      code = backend_.setIdentifierTag(payload_, id, &tmp);
-    }
-    else
-    {
-      code = backend_.setMainDicomTag(payload_, id, &tmp);
-    }
+  void OrthancPluginDatabase::SetIdentifierTag(int64_t id,
+                                               const DicomTag& tag,
+                                               const std::string& value)
+  {
+    OrthancPluginDicomTag tmp;
+    tmp.group = tag.GetGroup();
+    tmp.element = tag.GetElement();
+    tmp.value = value.c_str();
 
-    CheckSuccess(code);
+    CheckSuccess(backend_.setIdentifierTag(payload_, id, &tmp));
   }
 
 
--- a/Plugins/Engine/OrthancPluginDatabase.h	Fri Oct 16 17:36:59 2015 +0200
+++ b/Plugins/Engine/OrthancPluginDatabase.h	Fri Oct 16 18:17:22 2015 +0200
@@ -235,6 +235,10 @@
                                  const DicomTag& tag,
                                  const std::string& value);
 
+    virtual void SetIdentifierTag(int64_t id,
+                                  const DicomTag& tag,
+                                  const std::string& value);
+
     virtual void SetMetadata(int64_t id,
                              MetadataType type,
                              const std::string& value);
--- a/UnitTestsSources/ServerIndexTests.cpp	Fri Oct 16 17:36:59 2015 +0200
+++ b/UnitTestsSources/ServerIndexTests.cpp	Fri Oct 16 18:17:22 2015 +0200
@@ -686,10 +686,10 @@
     index_->CreateResource("d", ResourceType_Series)   // 3
   };
 
-  index_->SetMainDicomTag(a[0], DICOM_TAG_STUDY_INSTANCE_UID, "0");
-  index_->SetMainDicomTag(a[1], DICOM_TAG_STUDY_INSTANCE_UID, "1");
-  index_->SetMainDicomTag(a[2], DICOM_TAG_STUDY_INSTANCE_UID, "0");
-  index_->SetMainDicomTag(a[3], DICOM_TAG_SERIES_INSTANCE_UID, "0");
+  index_->SetIdentifierTag(a[0], DICOM_TAG_STUDY_INSTANCE_UID, "0");
+  index_->SetIdentifierTag(a[1], DICOM_TAG_STUDY_INSTANCE_UID, "1");
+  index_->SetIdentifierTag(a[2], DICOM_TAG_STUDY_INSTANCE_UID, "0");
+  index_->SetIdentifierTag(a[3], DICOM_TAG_SERIES_INSTANCE_UID, "0");
 
   std::list<int64_t> s;