changeset 1716:2ca7888f8600 db-changes

refactoring DicomIdentifiers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 17 Oct 2015 12:16:27 +0200
parents c3baf74e443f
children 3926e6317a43
files Core/DicomFormat/DicomMap.cpp Core/DicomFormat/DicomTag.h OrthancServer/DatabaseWrapperBase.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerToolbox.cpp OrthancServer/ServerToolbox.h
diffstat 6 files changed, 56 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomFormat/DicomMap.cpp	Fri Oct 16 18:34:53 2015 +0200
+++ b/Core/DicomFormat/DicomMap.cpp	Sat Oct 17 12:16:27 2015 +0200
@@ -57,10 +57,10 @@
   {
     //DicomTag(0x0010, 0x1020), // PatientSize
     //DicomTag(0x0010, 0x1030)  // PatientWeight
-    DicomTag(0x0008, 0x0020),   // StudyDate
+    DICOM_TAG_STUDY_DATE,
     DicomTag(0x0008, 0x0030),   // StudyTime
-    DicomTag(0x0008, 0x1030),   // StudyDescription
     DicomTag(0x0020, 0x0010),   // StudyID
+    DICOM_TAG_STUDY_DESCRIPTION,
     DICOM_TAG_ACCESSION_NUMBER,
     DICOM_TAG_STUDY_INSTANCE_UID
   };
@@ -73,7 +73,7 @@
     DicomTag(0x0008, 0x0060),   // Modality
     DicomTag(0x0008, 0x0070),   // Manufacturer
     DicomTag(0x0008, 0x1010),   // StationName
-    DicomTag(0x0008, 0x103e),   // SeriesDescription
+    DICOM_TAG_SERIES_DESCRIPTION,
     DicomTag(0x0018, 0x0015),   // BodyPartExamined
     DicomTag(0x0018, 0x0024),   // SequenceName
     DicomTag(0x0018, 0x1030),   // ProtocolName
--- a/Core/DicomFormat/DicomTag.h	Fri Oct 16 18:34:53 2015 +0200
+++ b/Core/DicomFormat/DicomTag.h	Sat Oct 17 12:16:27 2015 +0200
@@ -109,6 +109,9 @@
   static const DicomTag DICOM_TAG_PATIENT_NAME(0x0010, 0x0010);
   static const DicomTag DICOM_TAG_ENCAPSULATED_DOCUMENT(0x0042, 0x0011);
 
+  static const DicomTag DICOM_TAG_STUDY_DESCRIPTION(0x0008, 0x1030);
+  static const DicomTag DICOM_TAG_SERIES_DESCRIPTION(0x0008, 0x103e);
+
   // The following is used for "modify/anonymize" operations
   static const DicomTag DICOM_TAG_SOP_CLASS_UID(0x0008, 0x0016);
   static const DicomTag DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID(0x0002, 0x0002);
--- a/OrthancServer/DatabaseWrapperBase.cpp	Fri Oct 16 18:34:53 2015 +0200
+++ b/OrthancServer/DatabaseWrapperBase.cpp	Sat Oct 17 12:16:27 2015 +0200
@@ -351,15 +351,6 @@
                    s.ColumnInt(2),
                    s.ColumnString(3));
     }
-
-    SQLite::Statement s2(db_, SQLITE_FROM_HERE, "SELECT * FROM DicomIdentifiers WHERE id=?");
-    s2.BindInt64(0, id);
-    while (s2.Step())
-    {
-      map.SetValue(s2.ColumnInt(1),
-                   s2.ColumnInt(2),
-                   s2.ColumnString(3));
-    }
   }
 
 
--- a/OrthancServer/ServerIndex.cpp	Fri Oct 16 18:34:53 2015 +0200
+++ b/OrthancServer/ServerIndex.cpp	Sat Oct 17 12:16:27 2015 +0200
@@ -627,7 +627,7 @@
 
       // Create the instance
       int64_t instance = CreateResource(hasher.HashInstance(), ResourceType_Instance);
-      Toolbox::SetMainDicomTags(db_, instance, ResourceType_Instance, dicomSummary, true);
+      Toolbox::SetMainDicomTags(db_, instance, ResourceType_Instance, dicomSummary);
 
       // Detect up to which level the patient/study/series/instance
       // hierarchy must be created
@@ -679,22 +679,21 @@
       if (isNewSeries)
       {
         series = CreateResource(hasher.HashSeries(), ResourceType_Series);
-        Toolbox::SetMainDicomTags(db_, series, ResourceType_Series, dicomSummary, true);
+        Toolbox::SetMainDicomTags(db_, series, ResourceType_Series, dicomSummary);
       }
 
       // Create the study if needed
       if (isNewStudy)
       {
         study = CreateResource(hasher.HashStudy(), ResourceType_Study);
-        Toolbox::SetMainDicomTags(db_, study, ResourceType_Study, dicomSummary, true);
-        Toolbox::SetMainDicomTags(db_, study, ResourceType_Patient, dicomSummary, false);  // New in version 0.9.5 (db v6)
+        Toolbox::SetMainDicomTags(db_, study, ResourceType_Study, dicomSummary);
       }
 
       // Create the patient if needed
       if (isNewPatient)
       {
         patient = CreateResource(hasher.HashPatient(), ResourceType_Patient);
-        Toolbox::SetMainDicomTags(db_, patient, ResourceType_Patient, dicomSummary, true);
+        Toolbox::SetMainDicomTags(db_, patient, ResourceType_Patient, dicomSummary);
       }
 
       // Create the parent-to-child links
--- a/OrthancServer/ServerToolbox.cpp	Fri Oct 16 18:34:53 2015 +0200
+++ b/OrthancServer/ServerToolbox.cpp	Sat Oct 17 12:16:27 2015 +0200
@@ -158,11 +158,39 @@
     }
 
 
+    static void SetMainDicomTagsInternal(IDatabaseWrapper& database,
+                                         int64_t resource,
+                                         const DicomMap& tags)
+    {
+      DicomArray flattened(tags);
+
+      for (size_t i = 0; i < flattened.GetSize(); i++)
+      {
+        const DicomElement& element = flattened.GetElement(i);
+        const DicomTag& tag = element.GetTag();
+        database.SetMainDicomTag(resource, tag, element.GetValue().AsString());
+      }
+    }
+
+
+    static void SetIdentifierTagInternal(IDatabaseWrapper& database,
+                                         int64_t resource,
+                                         const DicomMap& tags,
+                                         const DicomTag& tag)
+    {
+      const DicomValue* value = tags.TestAndGetValue(tag);
+      if (value != NULL &&
+          !value->IsNull())
+      {
+        database.SetIdentifierTag(resource, tag, value->AsString());
+      }
+    }
+
+
     void SetMainDicomTags(IDatabaseWrapper& database,
                           int64_t resource,
                           ResourceType level,
-                          const DicomMap& dicomSummary,
-                          bool includeIdentifiers)
+                          const DicomMap& dicomSummary)
     {
       // WARNING: The database should be locked with a transaction!
 
@@ -172,41 +200,39 @@
       {
         case ResourceType_Patient:
           dicomSummary.ExtractPatientInformation(tags);
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID);
           break;
 
         case ResourceType_Study:
           dicomSummary.ExtractStudyInformation(tags);
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_INSTANCE_UID);
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DESCRIPTION);  // ???
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DATE);  // ???
           break;
 
         case ResourceType_Series:
           dicomSummary.ExtractSeriesInformation(tags);
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SERIES_INSTANCE_UID);
           break;
 
         case ResourceType_Instance:
           dicomSummary.ExtractInstanceInformation(tags);
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_SOP_INSTANCE_UID);
           break;
 
         default:
           throw OrthancException(ErrorCode_InternalError);
       }
 
-      DicomArray flattened(tags);
-      for (size_t i = 0; i < flattened.GetSize(); i++)
-      {
-        const DicomElement& element = flattened.GetElement(i);
-        const DicomTag& tag = element.GetTag();
+      SetMainDicomTagsInternal(database, resource, tags);
 
-        if (tag.IsIdentifier())
-        {
-          if (includeIdentifiers)
-          {
-            database.SetIdentifierTag(resource, tag, element.GetValue().AsString());
-          }
-        }
-        else
-        {
-          database.SetMainDicomTag(resource, tag, element.GetValue().AsString());
-        }
+      // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
+      if (level == ResourceType_Study)
+      {
+        dicomSummary.ExtractPatientInformation(tags);
+        SetMainDicomTagsInternal(database, resource, tags);
+        SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_NAME);  // ???
+        SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_BIRTH_DATE);  // ???
       }
     }
 
@@ -306,31 +332,7 @@
         dicom.Convert(dicomSummary);
 
         database.ClearMainDicomTags(resource);
-
-        switch (level)
-        {
-          case ResourceType_Patient:
-            Toolbox::SetMainDicomTags(database, resource, ResourceType_Patient, dicomSummary, true);
-            break;
-
-          case ResourceType_Study:
-            Toolbox::SetMainDicomTags(database, resource, ResourceType_Study, dicomSummary, true);
-
-            // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
-            Toolbox::SetMainDicomTags(database, resource, ResourceType_Patient, dicomSummary, false);
-            break;
-
-          case ResourceType_Series:
-            Toolbox::SetMainDicomTags(database, resource, ResourceType_Series, dicomSummary, true);
-            break;
-
-          case ResourceType_Instance:
-            Toolbox::SetMainDicomTags(database, resource, ResourceType_Instance, dicomSummary, true);
-            break;
-
-          default:
-            throw OrthancException(ErrorCode_InternalError);
-        }
+        Toolbox::SetMainDicomTags(database, resource, level, dicomSummary);
       }
     }
   }
--- a/OrthancServer/ServerToolbox.h	Fri Oct 16 18:34:53 2015 +0200
+++ b/OrthancServer/ServerToolbox.h	Sat Oct 17 12:16:27 2015 +0200
@@ -49,8 +49,7 @@
     void SetMainDicomTags(IDatabaseWrapper& database,
                           int64_t resource,
                           ResourceType level,
-                          const DicomMap& dicomSummary,
-                          bool includeIdentifiers);
+                          const DicomMap& dicomSummary);
 
     bool FindOneChildInstance(int64_t& result,
                               IDatabaseWrapper& database,