changeset 1717:3926e6317a43 db-changes

SetIdentifierTagInternal
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 19 Oct 2015 17:45:34 +0200
parents 2ca7888f8600
children 2b812969e136
files OrthancServer/DatabaseWrapper.cpp OrthancServer/ServerIndex.cpp OrthancServer/ServerToolbox.cpp OrthancServer/ServerToolbox.h Plugins/Samples/DatabasePlugin/Database.cpp
diffstat 5 files changed, 42 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DatabaseWrapper.cpp	Sat Oct 17 12:16:27 2015 +0200
+++ b/OrthancServer/DatabaseWrapper.cpp	Mon Oct 19 17:45:34 2015 +0200
@@ -268,6 +268,8 @@
 
   void DatabaseWrapper::Open()
   {
+    db_.Execute("PRAGMA ENCODING=\"UTF-8\";");
+
     // Performance tuning of SQLite with PRAGMAs
     // http://www.sqlite.org/pragma.html
     db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;");
--- a/OrthancServer/ServerIndex.cpp	Sat Oct 17 12:16:27 2015 +0200
+++ b/OrthancServer/ServerIndex.cpp	Mon Oct 19 17:45:34 2015 +0200
@@ -873,29 +873,6 @@
   }
 
 
-  static std::string GetPatientIdOfStudy(IDatabaseWrapper& db,
-                                         int64_t resourceId)
-  {
-    int64_t patient;
-    if (!db.LookupParent(patient, resourceId))
-    {
-      throw OrthancException(ErrorCode_InternalError);
-    }
-
-    DicomMap tags;
-    db.GetMainDicomTags(tags, patient);
-
-    if (tags.HasTag(DICOM_TAG_PATIENT_ID))
-    {
-      return tags.GetValue(DICOM_TAG_PATIENT_ID).AsString();
-    }
-    else
-    {
-      return "";
-    }
-  }
-
-
   void ServerIndex::MainDicomTagsToJson(Json::Value& target,
                                         int64_t resourceId,
                                         ResourceType resourceType)
@@ -914,8 +891,6 @@
 
       target["PatientMainDicomTags"] = Json::objectValue;
       FromDcmtkBridge::ToJson(target["PatientMainDicomTags"], t2, true);
-
-      target["PatientMainDicomTags"]["PatientID"] = GetPatientIdOfStudy(db_, resourceId);
     }
     else
     {
@@ -2136,7 +2111,6 @@
       {
         case ResourceType_Patient:
           tmp.ExtractPatientInformation(result);
-          result.SetValue(DICOM_TAG_PATIENT_ID, GetPatientIdOfStudy(db_, id));
           return true;
 
         case ResourceType_Study:
--- a/OrthancServer/ServerToolbox.cpp	Sat Oct 17 12:16:27 2015 +0200
+++ b/OrthancServer/ServerToolbox.cpp	Mon Oct 19 17:45:34 2015 +0200
@@ -182,11 +182,31 @@
       if (value != NULL &&
           !value->IsNull())
       {
-        database.SetIdentifierTag(resource, tag, value->AsString());
+        std::string s = value->AsString();
+
+        if (!tag.IsIdentifier())
+        {
+          s = NormalizeIdentifierTag(s);
+        }
+
+        database.SetIdentifierTag(resource, tag, s);
       }
     }
 
 
+    static void AttachPatientInformation(IDatabaseWrapper& database,
+                                         int64_t resource,
+                                         const DicomMap& dicomSummary)
+    {
+      DicomMap tags;
+      dicomSummary.ExtractPatientInformation(tags);
+      SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID);
+      SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_NAME);
+      SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_BIRTH_DATE);
+      SetMainDicomTagsInternal(database, resource, tags);
+    }
+
+
     void SetMainDicomTags(IDatabaseWrapper& database,
                           int64_t resource,
                           ResourceType level,
@@ -199,15 +219,18 @@
       switch (level)
       {
         case ResourceType_Patient:
-          dicomSummary.ExtractPatientInformation(tags);
-          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_PATIENT_ID);
+          AttachPatientInformation(database, resource, dicomSummary);
           break;
 
         case ResourceType_Study:
+          // Duplicate the patient tags at the study level (new in Orthanc 0.9.5 - db v6)
+          AttachPatientInformation(database, resource, dicomSummary);
+
           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);  // ???
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_ACCESSION_NUMBER);
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DESCRIPTION);
+          SetIdentifierTagInternal(database, resource, tags, DICOM_TAG_STUDY_DATE);
           break;
 
         case ResourceType_Series:
@@ -225,15 +248,6 @@
       }
 
       SetMainDicomTagsInternal(database, resource, tags);
-
-      // 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);  // ???
-      }
     }
 
 
@@ -335,5 +349,13 @@
         Toolbox::SetMainDicomTags(database, resource, level, dicomSummary);
       }
     }
+
+
+    std::string NormalizeIdentifierTag(const std::string& value)
+    {
+      std::string s = Toolbox::ConvertToAscii(Toolbox::StripSpaces(value));
+      Toolbox::ToUpperCase(s);
+      return s;
+    }
   }
 }
--- a/OrthancServer/ServerToolbox.h	Sat Oct 17 12:16:27 2015 +0200
+++ b/OrthancServer/ServerToolbox.h	Mon Oct 19 17:45:34 2015 +0200
@@ -59,5 +59,7 @@
     void ReconstructMainDicomTags(IDatabaseWrapper& database,
                                   IStorageArea& storageArea,
                                   ResourceType level);
+
+    std::string NormalizeIdentifierTag(const std::string& value);
   }
 }
--- a/Plugins/Samples/DatabasePlugin/Database.cpp	Sat Oct 17 12:16:27 2015 +0200
+++ b/Plugins/Samples/DatabasePlugin/Database.cpp	Mon Oct 19 17:45:34 2015 +0200
@@ -184,6 +184,8 @@
 {
   db_.Open(path_);
 
+  db_.Execute("PRAGMA ENCODING=\"UTF-8\";");
+
   // http://www.sqlite.org/pragma.html
   db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;");
   db_.Execute("PRAGMA JOURNAL_MODE=WAL;");