changeset 704:4789da60d655

recycling with custom attachments
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Feb 2014 17:03:18 +0100
parents fd86dfe8f584
children a9cff2c077d4
files OrthancServer/ServerIndex.cpp
diffstat 1 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/ServerIndex.cpp	Tue Feb 11 17:31:58 2014 +0100
+++ b/OrthancServer/ServerIndex.cpp	Wed Feb 12 17:03:18 2014 +0100
@@ -1608,9 +1608,30 @@
       return StoreStatus_Failure;  // Inexistent resource
     }
 
+    // Remove possible previous attachment
     db_->DeleteAttachment(resourceId, attachment.GetContentType());
 
-    // TODO Integrate the recycling mechanism!!
+    // Locate the patient of the target resource
+    int64_t patientId = resourceId;
+    for (;;)
+    {
+      int64_t parent;
+      if (db_->LookupParent(parent, patientId))
+      {
+        // We have not reached the patient level yet
+        patientId = parent;
+      }
+      else
+      {
+        // We have reached the patient level
+        break;
+      }
+    }
+
+    // Possibly apply the recycling mechanism while preserving this patient
+    assert(db_->GetResourceType(patientId) == ResourceType_Patient);
+    Recycle(attachment.GetCompressedSize(), db_->GetPublicId(patientId));
+
     db_->AddAttachment(resourceId, attachment);
 
     t.Commit(attachment.GetCompressedSize());