# HG changeset patch # User Sebastien Jodogne # Date 1392220998 -3600 # Node ID 4789da60d6551465f79c6d50bed246e0db79a89a # Parent fd86dfe8f5849c35ffe2d7e65c935d1beb71c3e4 recycling with custom attachments diff -r fd86dfe8f584 -r 4789da60d655 OrthancServer/ServerIndex.cpp --- 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());