changeset 5787:42ef98bb3c13 find-refactoring

Do not read from disk when not required
author Alain Mazy <am@orthanc.team>
date Tue, 17 Sep 2024 12:48:51 +0200
parents 09e337d45d22
children 61c9e5df64d7
files OrthancServer/Resources/Configuration.json OrthancServer/Sources/OrthancConfiguration.cpp OrthancServer/Sources/ResourceFinder.cpp OrthancServer/Sources/ServerEnumerations.h
diffstat 4 files changed, 43 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Resources/Configuration.json	Tue Sep 17 12:47:42 2024 +0200
+++ b/OrthancServer/Resources/Configuration.json	Tue Sep 17 12:48:51 2024 +0200
@@ -985,12 +985,21 @@
     // saved with another "ExtraMainDicomTags" configuration which means that
     // your response might be incomplete/inconsistent.
     // You should call patients|studies|series|instances/../reconstruct to rebuild
-    // the DB.  You may also check for the "Housekeeper" plugin
+    // the DB.  You may also check for the "Housekeeper" plugin.
     "W002_InconsistentDicomTagsInDb": true,
 
     // Display a warning message when Orthanc and its plugins are unable
     // to decode a frame (new in Orthanc 1.12.5).
-    "W003_DecoderFailure": true
+    "W003_DecoderFailure": true,
+
+    // Display a warning when the MainDicomTagsSignature metadata has not been
+    // found which means that the resource has been saved with a version prior
+    // to 1.11.0.
+    // You should call patients|studies|series|instances/../reconstruct to rebuild
+    // the DB.  You may also check for the "Housekeeper" plugin.
+    // (new in Orthanc 1.12.5)
+    "W004_NoMainDicomTagsSignature": true
+
   },
 
   // Configure Orthanc in read only mode.
--- a/OrthancServer/Sources/OrthancConfiguration.cpp	Tue Sep 17 12:47:42 2024 +0200
+++ b/OrthancServer/Sources/OrthancConfiguration.cpp	Tue Sep 17 12:48:51 2024 +0200
@@ -1161,6 +1161,10 @@
         {
           warning = Warnings_003_DecoderFailure;
         }
+        else if (name == "W004_NoMainDicomTagsSignature")
+        {
+          warning = Warnings_004_NoMainDicomTagsSignature;
+        }
         else
         {
           throw OrthancException(ErrorCode_BadFileFormat, name + " is not recognized as a valid warning name");
--- a/OrthancServer/Sources/ResourceFinder.cpp	Tue Sep 17 12:47:42 2024 +0200
+++ b/OrthancServer/Sources/ResourceFinder.cpp	Tue Sep 17 12:48:51 2024 +0200
@@ -807,6 +807,19 @@
     {
       DicomMap m;
       resource.GetMainDicomTags(m, level);
+      
+      // check which tags have been saved in DB
+      std::set<DicomTag> savedMainDicomTags;
+      std::string signature = DicomMap::GetDefaultMainDicomTagsSignature(ResourceType_Study); // default signature in case it's not in the metadata (= the signature for 1.11.0)
+      if (resource.LookupMetadata(signature, level, MetadataType_MainDicomTagsSignature))
+      {
+        if (level == ResourceType_Study) // when we retrieve the study tags, we actually also get the patient tags that are also saved at study level but not included in the signature
+        {
+          signature += ";" + DicomMap::GetDefaultMainDicomTagsSignature(ResourceType_Patient); // append the default signature (from before 1.11.0)
+        }
+
+        FromDcmtkBridge::ParseListOfTags(savedMainDicomTags, signature);
+      }
 
       for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it)
       {
@@ -815,9 +828,9 @@
         {
           requestedTags.SetValue(*it, value, false /* not binary */);
         }
-        else
+        else if (savedMainDicomTags.find(*it) == savedMainDicomTags.end())
         {
-          // This is the case where the Housekeeper should be run
+          // This is the case where the Housekeeper should be run because the tag has not been saved in DB
           missingTags.insert(*it);
         }
       }
@@ -930,10 +943,12 @@
                                ServerContext& context) const
   {
     bool isWarning002Enabled = false;
+    bool isWarning004Enabled = false;
 
     {
       OrthancConfiguration::ReaderLock lock;
       isWarning002Enabled = lock.GetConfiguration().IsWarningEnabled(Warnings_002_InconsistentDicomTagsInDb);
+      isWarning004Enabled = lock.GetConfiguration().IsWarningEnabled(Warnings_004_NoMainDicomTagsSignature);
     }
 
     FindResponse response;
@@ -983,7 +998,7 @@
       {
         InjectComputedTags(requestedTags, resource);
 
-        std::set<DicomTag> missingTags = requestedTagsFromFileStorage_;
+        std::set<DicomTag> missingTags = requestedTagsFromFileStorage_;  // this is actually the full list of requestedTags
         InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Patient, requestedPatientTags_);
         InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Study, requestedStudyTags_);
         InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Series, requestedSeriesTags_);
@@ -1013,6 +1028,15 @@
                       << "/" << resource.GetIdentifier()
                       << "/reconstruct to update the list of tags saved in DB or run the Housekeeper plugin.  Some MainDicomTags might be missing from this answer.";
         }
+        else if (isWarning004Enabled &&
+                 !resource.LookupMetadata(mainDicomTagsSignature, resource.GetLevel(), MetadataType_MainDicomTagsSignature))
+        {
+          LOG(WARNING) << "W004: " << Orthanc::GetResourceTypeText(resource.GetLevel(), false , false)
+                      << " has been stored a while ago and does not have a MainDicomTagsSignature, you should POST to /"
+                      << Orthanc::GetResourceTypeText(resource.GetLevel(), true, false)
+                      << "/" << resource.GetIdentifier()
+                      << "/reconstruct to update the list of tags saved in DB or run the Housekeeper plugin.  Some MainDicomTags might be missing from this answer.";
+        }
 
       }
 
--- a/OrthancServer/Sources/ServerEnumerations.h	Tue Sep 17 12:47:42 2024 +0200
+++ b/OrthancServer/Sources/ServerEnumerations.h	Tue Sep 17 12:48:51 2024 +0200
@@ -218,6 +218,7 @@
     Warnings_001_TagsBeingReadFromStorage,
     Warnings_002_InconsistentDicomTagsInDb,
     Warnings_003_DecoderFailure,              // new in Orthanc 1.12.5
+    Warnings_004_NoMainDicomTagsSignature     // new in Orthanc 1.12.5
   };