changeset 1374:a1745d9be6e9

CaseSensitivePN configuration option
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 28 May 2015 15:30:42 +0200
parents 4460e2622016
children 3d76e26b3865
files OrthancServer/DicomFindQuery.cpp OrthancServer/DicomFindQuery.h OrthancServer/OrthancFindRequestHandler.cpp OrthancServer/OrthancRestApi/OrthancRestResources.cpp Resources/Configuration.json
diffstat 5 files changed, 39 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomFindQuery.cpp	Wed May 27 10:50:59 2015 +0200
+++ b/OrthancServer/DicomFindQuery.cpp	Thu May 28 15:30:42 2015 +0200
@@ -156,10 +156,19 @@
     boost::regex pattern_;
 
   public:
-    WildcardConstraint(const std::string& wildcard)
+    WildcardConstraint(const std::string& wildcard,
+                       bool caseSensitive)
     {
-      pattern_ = boost::regex(Toolbox::WildcardToRegularExpression(wildcard),
-                              boost::regex::icase /* case insensitive search */);
+      std::string re = Toolbox::WildcardToRegularExpression(wildcard);
+
+      if (caseSensitive)
+      {
+        pattern_ = boost::regex(re);
+      }
+      else
+      {
+        pattern_ = boost::regex(re, boost::regex::icase /* case insensitive search */);
+      }
     }
 
     virtual bool Apply(const std::string& value) const
@@ -233,8 +242,11 @@
 
 
   void DicomFindQuery::SetConstraint(const DicomTag& tag,
-                                     const std::string& constraint)
+                                     const std::string& constraint,
+                                     bool caseSensitivePN)
   {
+    bool sensitive = (FromDcmtkBridge::IsPNValueRepresentation(tag) ? caseSensitivePN : true);
+
     // http://www.itk.org/Wiki/DICOM_QueryRetrieve_Explained
     // http://dicomiseasy.blogspot.be/2012/01/dicom-queryretrieve-part-i.html  
 
@@ -249,7 +261,7 @@
     else if (constraint.find('*') != std::string::npos ||
              constraint.find('?') != std::string::npos)
     {
-      AssignConstraint(tag, new WildcardConstraint(constraint));
+      AssignConstraint(tag, new WildcardConstraint(constraint, sensitive));
     }
     else
     {
@@ -284,7 +296,7 @@
        * (0020,000E) UI SeriesInstanceUID  => Case-sensitive
       **/
 
-      AssignConstraint(tag, new ValueConstraint(constraint, FromDcmtkBridge::IsPNValueRepresentation(tag)));
+      AssignConstraint(tag, new ValueConstraint(constraint, sensitive));
     }
   }
 
--- a/OrthancServer/DicomFindQuery.h	Wed May 27 10:50:59 2015 +0200
+++ b/OrthancServer/DicomFindQuery.h	Thu May 28 15:30:42 2015 +0200
@@ -91,7 +91,8 @@
     }
 
     void SetConstraint(const DicomTag& tag,
-                       const std::string& constraint);
+                       const std::string& constraint,
+                       bool caseSensitivePN);
 
     virtual bool RestrictIdentifier(std::string& value,
                                     DicomTag identifier) const;
--- a/OrthancServer/OrthancFindRequestHandler.cpp	Wed May 27 10:50:59 2015 +0200
+++ b/OrthancServer/OrthancFindRequestHandler.cpp	Thu May 28 15:30:42 2015 +0200
@@ -231,6 +231,8 @@
 
     // ModalityManufacturer manufacturer = modality.GetManufacturer();
 
+    bool caseSensitivePN = Configuration::GetGlobalBoolParameter("CaseSensitivePN", true);
+
 
     /**
      * Retrieve the query level.
@@ -293,7 +295,7 @@
       }
       else
       {
-        findQuery.SetConstraint(tag, value);
+        findQuery.SetConstraint(tag, value, caseSensitivePN);
       }
     }
 
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed May 27 10:50:59 2015 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Thu May 28 15:30:42 2015 +0200
@@ -859,7 +859,8 @@
         request.isMember("Level") &&
         request.isMember("Query") &&
         request["Level"].type() == Json::stringValue &&
-        request["Query"].type() == Json::objectValue)
+        request["Query"].type() == Json::objectValue &&
+        (!request.isMember("CaseSensitive") || request["CaseSensitive"].type() == Json::booleanValue))
     {
       bool expand = false;
       if (request.isMember("Expand"))
@@ -867,6 +868,12 @@
         expand = request["Expand"].asBool();
       }
 
+      bool caseSensitive = false;
+      if (request.isMember("CaseSensitive"))
+      {
+        caseSensitive = request["CaseSensitive"].asBool();
+      }
+
       std::string level = request["Level"].asString();
 
       DicomFindQuery query;
@@ -881,7 +888,8 @@
         }
 
         query.SetConstraint(FromDcmtkBridge::ParseTag(members[i]), 
-                            request["Query"][members[i]].asString());
+                            request["Query"][members[i]].asString(),
+                            caseSensitive);
       }
       
       std::list<std::string> resources;
--- a/Resources/Configuration.json	Wed May 27 10:50:59 2015 +0200
+++ b/Resources/Configuration.json	Thu May 28 15:30:42 2015 +0200
@@ -222,5 +222,10 @@
   // are issued. This option sets the number of seconds of inactivity
   // to wait before automatically closing a DICOM association. If set
   // to 0, the connection is closed immediately.
-  "DicomAssociationCloseDelay" : 5
+  "DicomAssociationCloseDelay" : 5,
+
+  // When handling a C-Find SCP request, setting this flag to "false"
+  // will enable case-insensitive match for PN value representation
+  // (such as PatientName). By default, the search is case-sensitive.
+  "CaseSensitivePN" : true
 }