changeset 6558:72aca3bddaf7

fix LookupIdentifierExact to differentiate e.g '1234' and '_1234'
author Alain Mazy <am@orthanc.team>
date Tue, 13 Jan 2026 16:43:53 +0100
parents da36804105e3
children daf168bb0927
files NEWS OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp
diffstat 2 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Jan 12 18:46:50 2026 +0100
+++ b/NEWS	Tue Jan 13 16:43:53 2026 +0100
@@ -14,7 +14,6 @@
 * Fixed a security issue where one could hijack HTTP headers in the response
   through the `filename` argument of "/.../file" or "/.../archive" routes.
 
-
 Maintenance
 -----------
 
@@ -22,6 +21,8 @@
   applied to C-FIND (bug introduced in 1.12.5).
 * Allow executing multiple "/queries/../answers/../retrieve" in parallel
   https://discourse.orthanc-server.org/t/synchronous-jobs-limited-to-one-at-a-time/6365
+* Fix /tools/lookup and OrthancPluginLookupPatient that were considering '1234', '_1234' and '%1234'
+  as the same PatientID.
 * Upgraded dependencies for static builds:
   - boost 1.89.0
   - dcmtk 3.7.0
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Mon Jan 12 18:46:50 2026 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Jan 13 16:43:53 2026 +0100
@@ -1210,10 +1210,19 @@
 
     FindRequest request(level);
 
-    DicomTagConstraint c(tag, ConstraintType_Equal, value, true, true);
-
-    bool isIdentical;  // unused
-    request.GetDicomTagConstraints().AddConstraint(c.ConvertToDatabaseConstraint(isIdentical, level, DicomTagType_Identifier));
+    DicomTagConstraint c(tag, ConstraintType_Equal, value, false /* case sensitivity */, true /* mandatory */);
+
+    bool isIdentical;
+
+    std::unique_ptr<DatabaseDicomTagConstraint> dbConstraint(c.ConvertToDatabaseConstraint(isIdentical, level, DicomTagType_Identifier)); // first try to look in the identifier table (that is faster !)
+    
+    if (!isIdentical) // if an exact match can not be ensured because some values contained characters that are removed from the DicomIdentifier table during normalization, 
+                      // search in the MainDicomTags table instead.
+    {
+      dbConstraint.reset(c.ConvertToDatabaseConstraint(isIdentical, level, DicomTagType_Main));
+    }
+
+    request.GetDicomTagConstraints().AddConstraint(dbConstraint.release());
 
     FindResponse response;
     ExecuteFind(response, request);