Mercurial > hg > orthanc-indexer
changeset 1:d745ea3db32c
fix import of external DICOM
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 20 Sep 2021 16:10:42 +0200 |
parents | 6b08fcddd900 |
children | 76affd640431 |
files | Sources/IndexerDatabase.cpp Sources/IndexerDatabase.h Sources/Plugin.cpp Sources/UnitTestsMain.cpp |
diffstat | 4 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/Sources/IndexerDatabase.cpp Wed Sep 15 22:34:25 2021 +0200 +++ b/Sources/IndexerDatabase.cpp Mon Sep 20 16:10:42 2021 +0200 @@ -234,7 +234,7 @@ } -void IndexerDatabase::AddAttachment(const std::string& uuid, +bool IndexerDatabase::AddAttachment(const std::string& uuid, const std::string& instanceId) { boost::mutex::scoped_lock lock(mutex_); @@ -250,7 +250,7 @@ if (!statement.Step() || statement.ColumnInt64(0) == 0) { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); + return false; } } @@ -263,6 +263,7 @@ } transaction.Commit(); + return true; }
--- a/Sources/IndexerDatabase.h Wed Sep 15 22:34:25 2021 +0200 +++ b/Sources/IndexerDatabase.h Mon Sep 20 16:10:42 2021 +0200 @@ -87,7 +87,10 @@ // shouldn't do lengthy operations void Apply(IFileVisitor& visitor); - void AddAttachment(const std::string& uuid, + // Returns "false" iff. this instance has not been previously + // registerded using "AddDicomInstance()", which indicates the + // import of an external DICOM file + bool AddAttachment(const std::string& uuid, const std::string& instanceId); bool LookupAttachment(std::string& path,
--- a/Sources/Plugin.cpp Wed Sep 15 22:34:25 2021 +0200 +++ b/Sources/Plugin.cpp Mon Sep 20 16:10:42 2021 +0200 @@ -286,11 +286,11 @@ { std::string instanceId; if (type == OrthancPluginContentType_Dicom && - ComputeInstanceId(instanceId, content, size)) + ComputeInstanceId(instanceId, content, size) && + database_.AddAttachment(uuid, instanceId)) { // This attachment corresponds to an external DICOM file that is // stored in one of the indexed folders, only store a link to it - database_.AddAttachment(uuid, instanceId); } else {
--- a/Sources/UnitTestsMain.cpp Wed Sep 15 22:34:25 2021 +0200 +++ b/Sources/UnitTestsMain.cpp Mon Sep 20 16:10:42 2021 +0200 @@ -248,8 +248,8 @@ // Secondly, the storage area plugin parses DICOM attachments in // order to extract their Orthanc ID, and indexes them in the DB - db.AddAttachment("uuid1", "instance1"); - ASSERT_THROW(db.AddAttachment("uuid2", "instance2"), Orthanc::OrthancException); + ASSERT_TRUE(db.AddAttachment("uuid1", "instance1")); + ASSERT_FALSE(db.AddAttachment("uuid2", "instance2")); ASSERT_TRUE(db.LookupAttachment(path, "uuid1")); ASSERT_EQ("sample.dcm", path); @@ -311,7 +311,8 @@ // Secondly, the storage area plugin parses DICOM attachments in // order to extract their Orthanc ID, and indexes them in the DB - db.AddAttachment("uuid1", "instance1"); + ASSERT_TRUE(db.AddAttachment("uuid1", "instance1")); + ASSERT_THROW(db.AddAttachment("uuid1", "instance1"), Orthanc::OrthancException); // Constraint violation ASSERT_TRUE(db.LookupAttachment(path, "uuid1")); ASSERT_TRUE(path == "copy1.dcm" || path == "copy2.dcm");