diff OrthancServer/DatabaseWrapper.cpp @ 1286:b4acdb37e43b

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Feb 2015 16:51:19 +0100
parents 32fcc5dc7562
children 6e7e5ed91c2d
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Tue Feb 03 15:00:42 2015 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Tue Feb 03 16:51:19 2015 +0100
@@ -494,32 +494,30 @@
 
   static void SetMainDicomTagsInternal(SQLite::Statement& s,
                                        int64_t id,
-                                       const DicomElement& element)
+                                       const DicomTag& tag,
+                                       const std::string& value)
   {
     s.BindInt64(0, id);
-    s.BindInt(1, element.GetTag().GetGroup());
-    s.BindInt(2, element.GetTag().GetElement());
-    s.BindString(3, element.GetValue().AsString());
+    s.BindInt(1, tag.GetGroup());
+    s.BindInt(2, tag.GetElement());
+    s.BindString(3, value);
     s.Run();
   }
 
 
-  void DatabaseWrapper::SetMainDicomTags(int64_t id,
-                                         const DicomMap& tags)
+  void DatabaseWrapper::SetMainDicomTag(int64_t id,
+                                        const DicomTag& tag,
+                                        const std::string& value)
   {
-    DicomArray flattened(tags);
-    for (size_t i = 0; i < flattened.GetSize(); i++)
+    if (tag.IsIdentifier())
     {
-      if (flattened.GetElement(i).GetTag().IsIdentifier())
-      {
-        SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)");
-        SetMainDicomTagsInternal(s, id, flattened.GetElement(i));
-      }
-      else
-      {
-        SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
-        SetMainDicomTagsInternal(s, id, flattened.GetElement(i));
-      }
+      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);
     }
   }