diff OrthancServer/ServerToolbox.cpp @ 1709:2ad22b2970a2 db-changes

SearchableStudies
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 13 Oct 2015 17:48:30 +0200
parents 0bbcfd9695e5
children 5ebd6cbb3da8
line wrap: on
line diff
--- a/OrthancServer/ServerToolbox.cpp	Tue Oct 13 16:57:55 2015 +0200
+++ b/OrthancServer/ServerToolbox.cpp	Tue Oct 13 17:48:30 2015 +0200
@@ -307,11 +307,19 @@
             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);
+
+            DicomMap module;
+            Toolbox::ExtractModule(module, dicomSummary, DicomModule_Patient, true  /* normalize */);
+            Toolbox::ExtractModule(module, dicomSummary, DicomModule_Study, true  /* normalize */);
+            database.StoreStudyModule(resource, module);
+
             break;
+          }
 
           case ResourceType_Series:
             Toolbox::SetMainDicomTags(database, resource, ResourceType_Series, dicomSummary, true);
@@ -326,5 +334,34 @@
         }
       }
     }
+
+
+    void ExtractModule(DicomMap& result,   // WARNING: Will not be cleared!
+                       const DicomMap& summary,
+                       DicomModule module,
+                       bool normalize)
+    {
+      typedef std::set<DicomTag> ModuleTags;
+      ModuleTags moduleTags;
+      DicomTag::AddTagsForModule(moduleTags, module);
+
+      for (ModuleTags::const_iterator tag = moduleTags.begin(); tag != moduleTags.end(); ++tag)
+      {
+        const DicomValue* value = summary.TestAndGetValue(*tag);
+        if (value != NULL &&
+            !value->IsNull())
+        {
+          std::string t = value->AsString();
+
+          if (normalize)
+          {
+            t = StripSpaces(ConvertToAscii(t));
+            ToUpperCase(t);
+          }
+
+          result.SetValue(*tag, t);
+        }      
+      }
+    }
   }
 }