Ver código fonte

Fix for http://www.na-mic.org/Bug/view.php?id=2301

When two different studies for the same subject are being
inserted in the database, be sure to use the correct patientUID
value during the optimization or else the study won't be correctly
linked to the patient and won't be accessible via the database
(and won't show up in a GUI that relies on the database).
Steve Pieper 13 anos atrás
pai
commit
96ec6fa986
1 arquivos alterados com 27 adições e 9 exclusões
  1. 27 9
      Libs/DICOM/Core/ctkDICOMDatabase.cpp

+ 27 - 9
Libs/DICOM/Core/ctkDICOMDatabase.cpp

@@ -515,14 +515,27 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
     logger.error("SQLITE ERROR: " + fileExists.lastError().driverText());
     logger.error("SQLITE ERROR: " + fileExists.lastError().driverText());
     return;
     return;
   }
   }
-  qDebug() << "filename is: " << fileExists.value(1).toString();
-  qDebug() << "modified date is: " << QFileInfo(fileExists.value(1).toString()).lastModified();
-  qDebug() << "db mod date is: " << QDateTime::fromString(fileExists.value(0).toString(),Qt::ISODate);
-  if ( fileExists.next() && QFileInfo(fileExists.value(1).toString()).lastModified() < QDateTime::fromString(fileExists.value(0).toString(),Qt::ISODate) )
-  {
-    logger.debug ( "File " + fileExists.value(1).toString() + " already added" );
-    return;
-  }
+
+  QString databaseFilename(fileExists.value(1).toString());
+  QDateTime fileLastModified(QFileInfo(databaseFilename).lastModified());
+  QDateTime databaseInsertTimestamp(QDateTime::fromString(fileExists.value(0).toString(),Qt::ISODate));
+
+  qDebug() << "inserting filePath: " << filePath;
+  if (databaseFilename == "")
+    {
+    qDebug() << "database filename for " << sopInstanceUID << " is empty - we should insert on top of it";
+    }
+  else
+    {
+    qDebug() << "database filename for " << sopInstanceUID << " is: " << databaseFilename;
+    qDebug() << "modified date is: " << fileLastModified;
+    qDebug() << "db insert date is: " << databaseInsertTimestamp;
+    if ( fileExists.next() && fileLastModified < databaseInsertTimestamp )
+      {
+      logger.debug ( "File " + databaseFilename + " already added" );
+      return;
+      }
+    }
 
 
   //If the following fields can not be evaluated, cancel evaluation of the DICOM file
   //If the following fields can not be evaluated, cancel evaluation of the DICOM file
   QString patientsName(ctkDataset.GetElementAsString(DCM_PatientName) );
   QString patientsName(ctkDataset.GetElementAsString(DCM_PatientName) );
@@ -611,7 +624,7 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
   //The dbPatientID  is a unique number within the database, 
   //The dbPatientID  is a unique number within the database, 
   //generated by the sqlite autoincrement
   //generated by the sqlite autoincrement
   //The patientID  is the (non-unique) DICOM patient id
   //The patientID  is the (non-unique) DICOM patient id
-  int dbPatientID = -1;
+  int dbPatientID = lastPatientUID;
 
 
   if ( patientID != "" && patientsName != "" )
   if ( patientID != "" && patientsName != "" )
     {
     {
@@ -621,6 +634,7 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
           || lastPatientsBirthDate != patientsBirthDate 
           || lastPatientsBirthDate != patientsBirthDate 
           || lastPatientsName != patientsName )
           || lastPatientsName != patientsName )
       {
       {
+      qDebug() << "This looks like a different patient from last insert: " << patientID;
       // Ok, something is different from last insert, let's insert him if he's not
       // Ok, something is different from last insert, let's insert him if he's not
       // already in the db.
       // already in the db.
       //
       //
@@ -636,6 +650,7 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
       {
       {
         // we found him
         // we found him
         dbPatientID = checkPatientExistsQuery.value(checkPatientExistsQuery.record().indexOf("UID")).toInt();
         dbPatientID = checkPatientExistsQuery.value(checkPatientExistsQuery.record().indexOf("UID")).toInt();
+        qDebug() << "Found patient in the database as UId: " << dbPatientID;
       }
       }
       else
       else
         {
         {
@@ -654,6 +669,7 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
         loggedExec(insertPatientStatement);
         loggedExec(insertPatientStatement);
         dbPatientID = insertPatientStatement.lastInsertId().toInt();
         dbPatientID = insertPatientStatement.lastInsertId().toInt();
         logger.debug ( "New patient inserted: " + QString().setNum ( dbPatientID ) );
         logger.debug ( "New patient inserted: " + QString().setNum ( dbPatientID ) );
+        qDebug() << "New patient inserted as : " << dbPatientID;
         }
         }
       /// keep this for the next image
       /// keep this for the next image
       lastPatientUID = dbPatientID;
       lastPatientUID = dbPatientID;
@@ -662,6 +678,8 @@ void ctkDICOMDatabasePrivate::insert( const ctkDICOMDataset& ctkDataset, const Q
       lastPatientsName = patientsName;
       lastPatientsName = patientsName;
       }
       }
 
 
+    qDebug() << "Going to insert this instance with dbPatientID: " << dbPatientID;
+
     // Patient is in now. Let's continue with the study
     // Patient is in now. Let's continue with the study
 
 
     if ( studyInstanceUID != "" && lastStudyInstanceUID != studyInstanceUID )
     if ( studyInstanceUID != "" && lastStudyInstanceUID != studyInstanceUID )