Mercurial > hg > orthanc
changeset 4559:19b1921aee06 db-changes
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Mar 2021 17:59:40 +0100 |
parents | 2f4d7ec9b993 |
children | 929409e40008 |
files | OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h |
diffstat | 2 files changed, 193 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerIndex.cpp Thu Mar 04 16:58:35 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.cpp Thu Mar 04 17:59:40 2021 +0100 @@ -1366,23 +1366,6 @@ } - bool ServerIndex::IsProtectedPatient(const std::string& publicId) - { - boost::mutex::scoped_lock lock(mutex_); - - // Lookup for the requested resource - int64_t id; - ResourceType type; - if (!db_.LookupResource(id, type, publicId) || - type != ResourceType_Patient) - { - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - - return db_.IsProtectedPatient(id); - } - - void ServerIndex::SetProtectedPatient(const std::string& publicId, bool isProtected) { @@ -1408,87 +1391,6 @@ } - void ServerIndex::GetChildren(std::list<std::string>& result, - const std::string& publicId) - { - result.clear(); - - boost::mutex::scoped_lock lock(mutex_); - - ResourceType type; - int64_t resource; - if (!db_.LookupResource(resource, type, publicId)) - { - throw OrthancException(ErrorCode_UnknownResource); - } - - if (type == ResourceType_Instance) - { - // An instance cannot have a child - throw OrthancException(ErrorCode_BadParameterType); - } - - std::list<int64_t> tmp; - db_.GetChildrenInternalId(tmp, resource); - - for (std::list<int64_t>::const_iterator - it = tmp.begin(); it != tmp.end(); ++it) - { - result.push_back(db_.GetPublicId(*it)); - } - } - - - void ServerIndex::GetChildInstances(std::list<std::string>& result, - const std::string& publicId) - { - result.clear(); - - boost::mutex::scoped_lock lock(mutex_); - - ResourceType type; - int64_t top; - if (!db_.LookupResource(top, type, publicId)) - { - throw OrthancException(ErrorCode_UnknownResource); - } - - if (type == ResourceType_Instance) - { - // The resource is already an instance: Do not go down the hierarchy - result.push_back(publicId); - return; - } - - std::stack<int64_t> toExplore; - toExplore.push(top); - - std::list<int64_t> tmp; - - while (!toExplore.empty()) - { - // Get the internal ID of the current resource - int64_t resource = toExplore.top(); - toExplore.pop(); - - if (db_.GetResourceType(resource) == ResourceType_Instance) - { - result.push_back(db_.GetPublicId(resource)); - } - else - { - // Tag all the children of this resource as to be explored - db_.GetChildrenInternalId(tmp, resource); - for (std::list<int64_t>::const_iterator - it = tmp.begin(); it != tmp.end(); ++it) - { - toExplore.push(*it); - } - } - } - } - - void ServerIndex::SetMetadata(const std::string& publicId, MetadataType type, const std::string& value) @@ -2330,7 +2232,7 @@ const Tuple& tuple) = 0; void Apply(ServerIndex& index, - T1 t1) + const T1& t1) { const Tuple tuple(t1); TupleOperationsWrapper<ReadOnlyOperationsT1, Tuple> wrapper(*this, tuple); @@ -2354,8 +2256,8 @@ const Tuple& tuple) = 0; void Apply(ServerIndex& index, - T1 t1, - T2 t2) + const T1& t1, + const T2& t2) { const Tuple tuple(t1, t2); TupleOperationsWrapper<ReadOnlyOperationsT2, Tuple> wrapper(*this, tuple); @@ -2380,9 +2282,9 @@ const Tuple& tuple) = 0; void Apply(ServerIndex& index, - T1 t1, - T2 t2, - T3 t3) + const T1& t1, + const T2& t2, + const T3& t3) { const Tuple tuple(t1, t2, t3); TupleOperationsWrapper<ReadOnlyOperationsT3, Tuple> wrapper(*this, tuple); @@ -2408,10 +2310,10 @@ const Tuple& tuple) = 0; void Apply(ServerIndex& index, - T1 t1, - T2 t2, - T3 t3, - T4 t4) + const T1& t1, + const T2& t2, + const T3& t3, + const T4& t4) { const Tuple tuple(t1, t2, t3, t4); TupleOperationsWrapper<ReadOnlyOperationsT4, Tuple> wrapper(*this, tuple); @@ -2438,11 +2340,11 @@ const Tuple& tuple) = 0; void Apply(ServerIndex& index, - T1 t1, - T2 t2, - T3 t3, - T4 t4, - T5 t5) + const T1& t1, + const T2& t2, + const T3& t3, + const T4& t4, + const T5& t5) { const Tuple tuple(t1, t2, t3, t4, t5); TupleOperationsWrapper<ReadOnlyOperationsT5, Tuple> wrapper(*this, tuple); @@ -2470,12 +2372,12 @@ const Tuple& tuple) = 0; void Apply(ServerIndex& index, - T1 t1, - T2 t2, - T3 t3, - T4 t4, - T5 t5, - T6 t6) + const T1& t1, + const T2& t2, + const T3& t3, + const T4& t4, + const T5& t5, + const T6& t6) { const Tuple tuple(t1, t2, t3, t4, t5, t6); TupleOperationsWrapper<ReadOnlyOperationsT6, Tuple> wrapper(*this, tuple); @@ -3084,4 +2986,148 @@ Operations operations; operations.Apply(*this, &target); } + + + bool ServerIndex::IsProtectedPatient(const std::string& publicId) + { + class Operations : public ReadOnlyOperationsT1<std::string> + { + private: + bool protected_; + + public: + Operations() : + protected_(false) + { + } + + bool IsProtected() const + { + return protected_; + } + + virtual void ApplyTuple(ReadOnlyTransaction& transaction, + const Tuple& tuple) ORTHANC_OVERRIDE + { + // Lookup for the requested resource + int64_t id; + ResourceType type; + if (!transaction.LookupResource(id, type, tuple.get<0>()) || + type != ResourceType_Patient) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + else + { + protected_ = transaction.IsProtectedPatient(id); + } + } + }; + + Operations operations; + operations.Apply(*this, publicId); + return operations.IsProtected(); + } + + + void ServerIndex::GetChildren(std::list<std::string>& result, + const std::string& publicId) + { + class Operations : public ReadOnlyOperationsT2<std::list<std::string>*, std::string> + { + public: + virtual void ApplyTuple(ReadOnlyTransaction& transaction, + const Tuple& tuple) ORTHANC_OVERRIDE + { + ResourceType type; + int64_t resource; + if (!transaction.LookupResource(resource, type, tuple.get<1>())) + { + throw OrthancException(ErrorCode_UnknownResource); + } + else if (type == ResourceType_Instance) + { + // An instance cannot have a child + throw OrthancException(ErrorCode_BadParameterType); + } + else + { + std::list<int64_t> tmp; + transaction.GetChildrenInternalId(tmp, resource); + + tuple.get<0>()->clear(); + + for (std::list<int64_t>::const_iterator + it = tmp.begin(); it != tmp.end(); ++it) + { + tuple.get<0>()->push_back(transaction.GetPublicId(*it)); + } + } + } + }; + + Operations operations; + operations.Apply(*this, &result, publicId); + } + + + void ServerIndex::GetChildInstances(std::list<std::string>& result, + const std::string& publicId) + { + class Operations : public ReadOnlyOperationsT2<std::list<std::string>*, std::string> + { + public: + virtual void ApplyTuple(ReadOnlyTransaction& transaction, + const Tuple& tuple) ORTHANC_OVERRIDE + { + tuple.get<0>()->clear(); + + ResourceType type; + int64_t top; + if (!transaction.LookupResource(top, type, tuple.get<1>())) + { + throw OrthancException(ErrorCode_UnknownResource); + } + else if (type == ResourceType_Instance) + { + // The resource is already an instance: Do not go down the hierarchy + tuple.get<0>()->push_back(tuple.get<1>()); + } + else + { + std::stack<int64_t> toExplore; + toExplore.push(top); + + std::list<int64_t> tmp; + while (!toExplore.empty()) + { + // Get the internal ID of the current resource + int64_t resource = toExplore.top(); + toExplore.pop(); + + // TODO - This could be optimized by seeing how many + // levels "type == transaction.GetResourceType(top)" is + // above the "instances level" + if (transaction.GetResourceType(resource) == ResourceType_Instance) + { + tuple.get<0>()->push_back(transaction.GetPublicId(resource)); + } + else + { + // Tag all the children of this resource as to be explored + transaction.GetChildrenInternalId(tmp, resource); + for (std::list<int64_t>::const_iterator + it = tmp.begin(); it != tmp.end(); ++it) + { + toExplore.push(*it); + } + } + } + } + } + }; + + Operations operations; + operations.Apply(*this, &result, publicId); + } }
--- a/OrthancServer/Sources/ServerIndex.h Thu Mar 04 16:58:35 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Thu Mar 04 17:59:40 2021 +0100 @@ -162,17 +162,9 @@ void LogExportedResource(const std::string& publicId, const std::string& remoteModality); - bool IsProtectedPatient(const std::string& publicId); - void SetProtectedPatient(const std::string& publicId, bool isProtected); - void GetChildren(std::list<std::string>& result, - const std::string& publicId); - - void GetChildInstances(std::list<std::string>& result, - const std::string& publicId); - void SetMetadata(const std::string& publicId, MetadataType type, const std::string& value); @@ -324,6 +316,12 @@ db_.GetChanges(target, done, since, maxResults); } + void GetChildrenInternalId(std::list<int64_t>& target, + int64_t id) + { + db_.GetChildrenInternalId(target, id); + } + void GetChildrenPublicId(std::list<std::string>& target, int64_t id) { @@ -359,11 +357,21 @@ db_.GetMainDicomTags(map, id); } + std::string GetPublicId(int64_t resourceId) + { + return db_.GetPublicId(resourceId); + } + uint64_t GetResourceCount(ResourceType resourceType) { return db_.GetResourceCount(resourceType); } + ResourceType GetResourceType(int64_t resourceId) + { + return db_.GetResourceType(resourceId); + } + uint64_t GetTotalCompressedSize() { return db_.GetTotalCompressedSize(); @@ -374,6 +382,11 @@ return db_.GetTotalUncompressedSize(); } + bool IsProtectedPatient(int64_t internalId) + { + return db_.IsProtectedPatient(internalId); + } + bool LookupAttachment(FileInfo& attachment, int64_t id, FileContentType contentType) @@ -492,5 +505,12 @@ void GetLastExportedResource(Json::Value& target); + bool IsProtectedPatient(const std::string& publicId); + + void GetChildren(std::list<std::string>& result, + const std::string& publicId); + + void GetChildInstances(std::list<std::string>& result, + const std::string& publicId); }; }