changeset 5939:73d5b77e5d62

"CaseSensitive" is not available in "/tools/count-resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Dec 2024 15:40:48 +0100
parents 5e5069357246
children 327618bac696
files OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp
diffstat 2 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Dec 17 10:13:42 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Dec 17 15:40:48 2024 +0100
@@ -3214,6 +3214,18 @@
       }
     };
 
+    class Compatibility : public ReadOnlyOperationsT3<uint64_t&, const FindRequest&, const IDatabaseWrapper::Capabilities&>
+    {
+    public:
+      virtual void ApplyTuple(ReadOnlyTransaction& transaction,
+                              const Tuple& tuple) ORTHANC_OVERRIDE
+      {
+        std::list<std::string> identifiers;
+        transaction.ExecuteFind(identifiers, tuple.get<2>(), tuple.get<1>());
+        tuple.get<0>() = identifiers.size();
+      }
+    };
+
     IDatabaseWrapper::Capabilities capabilities = db_.GetDatabaseCapabilities();
 
     if (db_.HasIntegratedFind())
@@ -3223,7 +3235,8 @@
     }
     else
     {
-      throw OrthancException(ErrorCode_NotImplemented);
+      Compatibility operations;
+      operations.Apply(*this, count, request, capabilities);
     }
   }
 
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Dec 17 10:13:42 2024 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Tue Dec 17 15:40:48 2024 +0100
@@ -3101,8 +3101,6 @@
       RestApiCallDocumentation& doc = call.GetDocumentation();
 
       doc.SetTag("System")
-        .SetRequestField(KEY_CASE_SENSITIVE, RestApiCallDocumentation::Type_Boolean,
-                         "Enable case-sensitive search for PN value representations (defaults to configuration option `CaseSensitivePN`)", false)
         .SetRequestField(KEY_LEVEL, RestApiCallDocumentation::Type_String,
                          "Level of the query (`Patient`, `Study`, `Series` or `Instance`)", true)
         .SetRequestField(KEY_QUERY, RestApiCallDocumentation::Type_JsonObject,
@@ -3124,6 +3122,8 @@
       {
         case FindType_Find:
           doc.SetSummary("Look for local resources")
+          .SetRequestField(KEY_CASE_SENSITIVE, RestApiCallDocumentation::Type_Boolean,
+                           "Enable case-sensitive search for PN value representations (defaults to configuration option `CaseSensitivePN`)", false)
           .SetDescription("This URI can be used to perform a search on the content of the local Orthanc server, "
                           "in a way that is similar to querying remote DICOM modalities using C-FIND SCU: "
                           "https://orthanc.uclouvain.be/book/users/rest.html#performing-finds-within-orthanc")
@@ -3141,7 +3141,7 @@
           break;
         case FindType_Count:
           doc.SetSummary("Count local resources")
-          .SetDescription("This URI can be used to count the resources that are matching criterias on the content of the local Orthanc server, "
+          .SetDescription("This URI can be used to count the resources that are matching criteria on the content of the local Orthanc server, "
                           "in a way that is similar to tools/find")
           .AddAnswerType(MimeType_Json, "A JSON object with the `Count` of matching resources");
           break;
@@ -3281,6 +3281,12 @@
         if (request.isMember(KEY_CASE_SENSITIVE))
         {
           caseSensitive = request[KEY_CASE_SENSITIVE].asBool();
+
+          if (requestType == FindType_Count && caseSensitive)
+          {
+            throw OrthancException(ErrorCode_ParameterOutOfRange, "Setting \"" + std::string(KEY_CASE_SENSITIVE) +
+                                                                  "\" to \"true\" is not supported by /tools/count-resources");
+          }
         }
 
         { // DICOM Tag query
@@ -3552,7 +3558,10 @@
         answer["Count"] = Json::Value::UInt64(count);
         call.GetOutput().AnswerJson(answer);
       }
-
+      else
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
     }
   }
 
@@ -4343,10 +4352,7 @@
 
     Register("/tools/lookup", Lookup);
     Register("/tools/find", Find<FindType_Find>);
-    if (context_.GetIndex().HasFindSupport())
-    {
-      Register("/tools/count-resources", Find<FindType_Count>);
-    }
+    Register("/tools/count-resources", Find<FindType_Count>);
 
     Register("/patients/{id}/studies", GetChildResources<ResourceType_Patient, ResourceType_Study>);
     Register("/patients/{id}/series", GetChildResources<ResourceType_Patient, ResourceType_Series>);