changeset 1246:54bf0f0245f4

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Dec 2014 12:56:30 +0100
parents aea9277dee75
children 32fcc5dc7562
files OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/ExportedResource.h OrthancServer/ServerIndex.cpp
diffstat 4 files changed, 46 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Mon Dec 08 12:42:50 2014 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Mon Dec 08 12:56:30 2014 +0100
@@ -657,27 +657,19 @@
   }
 
 
-  void DatabaseWrapper::LogExportedResource(ResourceType resourceType,
-                                            const std::string& publicId,
-                                            const std::string& remoteModality,
-                                            const std::string& patientId,
-                                            const std::string& studyInstanceUid,
-                                            const std::string& seriesInstanceUid,
-                                            const std::string& sopInstanceUid,
-                                            const boost::posix_time::ptime& date)
+  void DatabaseWrapper::LogExportedResource(const ExportedResource& resource)
   {
     SQLite::Statement s(db_, SQLITE_FROM_HERE, 
                         "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
 
-    s.BindInt(0, resourceType);
-    s.BindString(1, publicId);
-    s.BindString(2, remoteModality);
-    s.BindString(3, patientId);
-    s.BindString(4, studyInstanceUid);
-    s.BindString(5, seriesInstanceUid);
-    s.BindString(6, sopInstanceUid);
-    s.BindString(7, boost::posix_time::to_iso_string(date));
-
+    s.BindInt(0, resource.GetResourceType());
+    s.BindString(1, resource.GetPublicId());
+    s.BindString(2, resource.GetModality());
+    s.BindString(3, resource.GetPatientId());
+    s.BindString(4, resource.GetStudyInstanceUid());
+    s.BindString(5, resource.GetSeriesInstanceUid());
+    s.BindString(6, resource.GetSopInstanceUid());
+    s.BindString(7, resource.GetDate());
     s.Run();      
   }
 
--- a/OrthancServer/DatabaseWrapper.h	Mon Dec 08 12:42:50 2014 +0100
+++ b/OrthancServer/DatabaseWrapper.h	Mon Dec 08 12:56:30 2014 +0100
@@ -142,28 +142,21 @@
     void LogChange(int64_t internalId,
                    const ServerIndexChange& change);
 
-    void GetChanges(std::list<ServerIndexChange>& target /* out */,
-                    bool& done /* out */,
+    void GetChanges(std::list<ServerIndexChange>& target /*out*/,
+                    bool& done /*out*/,
                     int64_t since,
                     unsigned int maxResults);
 
-    void GetLastChange(std::list<ServerIndexChange>& target /* out */);
+    void GetLastChange(std::list<ServerIndexChange>& target /*out*/);
 
-    void LogExportedResource(ResourceType resourceType,
-                             const std::string& publicId,
-                             const std::string& remoteModality,
-                             const std::string& patientId,
-                             const std::string& studyInstanceUid,
-                             const std::string& seriesInstanceUid,
-                             const std::string& sopInstanceUid,
-                             const boost::posix_time::ptime& date);
+    void LogExportedResource(const ExportedResource& resource);
     
-    void GetExportedResources(std::list<ExportedResource>& target /* out */,
-                              bool& done /* out */,
+    void GetExportedResources(std::list<ExportedResource>& target /*out*/,
+                              bool& done /*out*/,
                               int64_t since,
                               unsigned int maxResults);
 
-    void GetLastExportedResource(std::list<ExportedResource>& target /* out */);
+    void GetLastExportedResource(std::list<ExportedResource>& target /*out*/);
 
     uint64_t GetTotalCompressedSize();
     
--- a/OrthancServer/ExportedResource.h	Mon Dec 08 12:42:50 2014 +0100
+++ b/OrthancServer/ExportedResource.h	Mon Dec 08 12:56:30 2014 +0100
@@ -100,6 +100,26 @@
       return date_;
     }
 
+    const std::string& GetPatientId() const
+    {
+      return patientId_;
+    }
+
+    const std::string& GetStudyInstanceUid() const
+    {
+      return studyInstanceUid_;
+    }
+
+    const std::string& GetSeriesInstanceUid() const
+    {
+      return seriesInstanceUid_;
+    }
+
+    const std::string& GetSopInstanceUid() const
+    {
+      return sopInstanceUid_;
+    }
+
     void Format(Json::Value& item) const
     {
       item = Json::objectValue;
--- a/OrthancServer/ServerIndex.cpp	Mon Dec 08 12:42:50 2014 +0100
+++ b/OrthancServer/ServerIndex.cpp	Mon Dec 08 12:56:30 2014 +0100
@@ -1157,14 +1157,16 @@
     }
 
     // No need for a SQLite::ITransaction here, as we only insert 1 record
-    db_->LogExportedResource(type,
-                             publicId,
-                             remoteModality,
-                             patientId,
-                             studyInstanceUid,
-                             seriesInstanceUid,
-                             sopInstanceUid,
-                             boost::posix_time::second_clock::local_time());
+    ExportedResource resource(-1, 
+                              type,
+                              publicId,
+                              remoteModality,
+                              Toolbox::GetNowIsoString(),
+                              patientId,
+                              studyInstanceUid,
+                              seriesInstanceUid,
+                              sopInstanceUid);
+    db_->LogExportedResource(resource);
   }