changeset 189:ccbc2cf64a0d

record main dicom tags and changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Nov 2012 18:03:48 +0100
parents 090cefdab1d1
children b6cef9d45cc3
files OrthancServer/DatabaseWrapper.cpp OrthancServer/DatabaseWrapper.h OrthancServer/PrepareDatabase2.sql OrthancServer/ServerIndex.cpp
diffstat 4 files changed, 49 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Mon Nov 12 17:43:12 2012 +0100
+++ b/OrthancServer/DatabaseWrapper.cpp	Mon Nov 12 18:03:48 2012 +0100
@@ -178,7 +178,33 @@
     s.BindInt(0, type);
     s.BindString(1, publicId);
     s.Run();
-    return db_.GetLastInsertRowId();
+    int64_t id = db_.GetLastInsertRowId();
+
+    ChangeType changeType;
+    switch (type)
+    {
+    case ResourceType_Patient: 
+      changeType = ChangeType_NewPatient; 
+      break;
+
+    case ResourceType_Study: 
+      changeType = ChangeType_NewStudy; 
+      break;
+
+    case ResourceType_Series: 
+      changeType = ChangeType_NewSeries; 
+      break;
+
+    case ResourceType_Instance: 
+      changeType = ChangeType_NewInstance; 
+      break;
+
+    default:
+      throw OrthancException(ErrorCode_InternalError);
+    }
+
+    LogChange(changeType, id, type);
+    return id;
   }
 
   bool DatabaseWrapper::LookupResource(const std::string& publicId,
@@ -385,13 +411,13 @@
 
 
   void DatabaseWrapper::LogChange(ChangeType changeType,
-                                  const std::string& publicId,
+                                  int64_t internalId,
                                   ResourceType resourceType,
                                   const boost::posix_time::ptime& date)
   {
     SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)");
     s.BindInt(0, changeType);
-    s.BindString(1, publicId);
+    s.BindInt(1, internalId);
     s.BindInt(2, resourceType);
     s.BindString(3, boost::posix_time::to_iso_string(date));
     s.Run();      
--- a/OrthancServer/DatabaseWrapper.h	Mon Nov 12 17:43:12 2012 +0100
+++ b/OrthancServer/DatabaseWrapper.h	Mon Nov 12 18:03:48 2012 +0100
@@ -130,13 +130,13 @@
                              int64_t id);
 
     void LogChange(ChangeType changeType,
-                   const std::string& publicId,
+                   int64_t internalId,
                    ResourceType resourceType,
-                   const boost::posix_time::ptime& date);
+                   const boost::posix_time::ptime& date = boost::posix_time::second_clock::local_time());
 
     void LogExportedInstance(const std::string& remoteModality,
                              DicomInstanceHasher& hasher,
-                             const boost::posix_time::ptime& date);
+                             const boost::posix_time::ptime& date = boost::posix_time::second_clock::local_time());
     
     int64_t GetTableRecordCount(const std::string& table);
     
--- a/OrthancServer/PrepareDatabase2.sql	Mon Nov 12 17:43:12 2012 +0100
+++ b/OrthancServer/PrepareDatabase2.sql	Mon Nov 12 18:03:48 2012 +0100
@@ -38,7 +38,7 @@
 CREATE TABLE Changes(
        seq INTEGER PRIMARY KEY AUTOINCREMENT,
        changeType INTEGER,
-       publicId TEXT,
+       internalId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
        resourceType INTEGER,
        date TEXT
        );
@@ -61,7 +61,7 @@
 CREATE INDEX MainDicomTagsIndex2 ON MainDicomTags(tagGroup, tagElement);
 CREATE INDEX MainDicomTagsIndexValues ON MainDicomTags(value COLLATE BINARY);
 
-CREATE INDEX ChangesIndex ON Changes(publicId);
+CREATE INDEX ChangesIndex ON Changes(internalId);
 
 CREATE TRIGGER AttachedFileDeleted
 AFTER DELETE ON AttachedFiles
--- a/OrthancServer/ServerIndex.cpp	Mon Nov 12 17:43:12 2012 +0100
+++ b/OrthancServer/ServerIndex.cpp	Mon Nov 12 18:03:48 2012 +0100
@@ -452,7 +452,7 @@
 
   namespace Internals
   {
-    class ServerIndexListenerTmp : public IServerIndexListener
+    class ServerIndexListenerTodo : public IServerIndexListener
     {
     public:
       virtual void SignalRemainingAncestor(ResourceType parentType,
@@ -472,7 +472,7 @@
 
   ServerIndex::ServerIndex(const std::string& storagePath)
   {
-    listener2_.reset(new Internals::ServerIndexListenerTmp);
+    listener2_.reset(new Internals::ServerIndexListenerTodo);
 
     if (storagePath == ":memory:")
     {
@@ -540,38 +540,51 @@
       // Create the patient/study/series/instance hierarchy
       instance = db2_->CreateResource(hasher.HashInstance(), ResourceType_Instance);
 
+      DicomMap dicom;
+      dicomSummary.ExtractInstanceInformation(dicom);
+      db2_->SetMainDicomTags(instance, dicom);
+
       if (!db2_->LookupResource(hasher.HashSeries(), series, type))
       {
         // This is a new series
         isNewSeries = true;
         series = db2_->CreateResource(hasher.HashSeries(), ResourceType_Series);
+        dicomSummary.ExtractSeriesInformation(dicom);
+        db2_->SetMainDicomTags(series, dicom);
         db2_->AttachChild(series, instance);
 
         if (!db2_->LookupResource(hasher.HashStudy(), study, type))
         {
           // This is a new study
           study = db2_->CreateResource(hasher.HashStudy(), ResourceType_Study);
+          dicomSummary.ExtractStudyInformation(dicom);
+          db2_->SetMainDicomTags(study, dicom);
           db2_->AttachChild(study, series);
 
           if (!db2_->LookupResource(hasher.HashPatient(), patient, type))
           {
             // This is a new patient
             patient = db2_->CreateResource(hasher.HashPatient(), ResourceType_Patient);
+            dicomSummary.ExtractPatientInformation(dicom);
+            db2_->SetMainDicomTags(patient, dicom);
             db2_->AttachChild(patient, study);
           }
           else
           {
             assert(type == ResourceType_Patient);
+            db2_->AttachChild(patient, study);
           }
         }
         else
         {
           assert(type == ResourceType_Study);
+          db2_->AttachChild(study, series);
         }
       }
       else
       {
         assert(type == ResourceType_Series);
+        db2_->AttachChild(series, instance);
       }
 
       // Attach the files to the newly created instance