changeset 6497:87138d16a90d

Avoid adding twice the same tag in DB for the same resource
author Alain Mazy <am@orthanc.team>
date Tue, 25 Nov 2025 19:33:40 +0100
parents 31e793f606bc
children 26e24c3ad974
files NEWS OrthancServer/Sources/Database/ResourcesContent.h
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Nov 25 16:07:04 2025 +0100
+++ b/NEWS	Tue Nov 25 19:33:40 2025 +0100
@@ -68,6 +68,9 @@
        while downloading the response.
 * Fix issue #227: In SQL, string literals must use 'single quotes'
   https://stackoverflow.com/a/25141338
+* Fix: Avoid adding twice the same tag in DB for the same resource e.g. when you have added TimeZoneOffsetFromUTC
+       to the ExtraMainDicomTags at Patient level.
+       https://discourse.orthanc-server.org/t/jobs-api-the-dicommovescu-job-doesnt-seems-to-track-progress/3140/14
 * Upgraded dependencies for static builds:
   - civetweb 1.16, including patch for CVE-2025-55763
   - SQLite 3.50.4
--- a/OrthancServer/Sources/Database/ResourcesContent.h	Tue Nov 25 16:07:04 2025 +0100
+++ b/OrthancServer/Sources/Database/ResourcesContent.h	Tue Nov 25 19:33:40 2025 +0100
@@ -122,6 +122,8 @@
     ListTags       tags_;
     ListMetadata   metadata_;
 
+    std::map<int64_t, std::set<DicomTag> > mainDicomTagsPerResource_;
+
   public:
     explicit ResourcesContent(bool isNewResource) :
       isNewResource_(isNewResource)
@@ -132,7 +134,18 @@
                          const DicomTag& tag,
                          const std::string& value)
     {
-      tags_.push_back(TagValue(resourceId, false, tag, value));
+      // avoid adding twice the same tag for the same resource e.g, when the same tag is registered at study and patient level 
+      // https://discourse.orthanc-server.org/t/jobs-api-the-dicommovescu-job-doesnt-seems-to-track-progress/3140/14
+      if (mainDicomTagsPerResource_.find(resourceId) == mainDicomTagsPerResource_.end())
+      {
+        mainDicomTagsPerResource_[resourceId] = std::set<DicomTag>();
+      }
+
+      if (mainDicomTagsPerResource_[resourceId].find(tag) == mainDicomTagsPerResource_[resourceId].end())
+      {
+        tags_.push_back(TagValue(resourceId, false, tag, value));
+        mainDicomTagsPerResource_[resourceId].insert(tag);
+      }
     }
 
     void AddIdentifierTag(int64_t resourceId,