Mercurial > hg > orthanc
changeset 3091:476cba12c2b0 db-changes
IDatabaseWrapper::GetChildrenMetadata()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 05 Jan 2019 15:08:53 +0100 |
parents | 31244604f617 |
children | fc57988dbfd8 |
files | CMakeLists.txt OrthancServer/IDatabaseWrapper.h OrthancServer/SQLiteDatabaseWrapper.h OrthancServer/Search/Compatibility/ICreateInstance.cpp OrthancServer/Search/Compatibility/ICreateInstance.h OrthancServer/Search/Compatibility/IGetChildrenMetadata.cpp OrthancServer/Search/Compatibility/IGetChildrenMetadata.h OrthancServer/ServerIndex.cpp Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h |
diffstat | 10 files changed, 198 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Sat Jan 05 12:17:30 2019 +0100 +++ b/CMakeLists.txt Sat Jan 05 15:08:53 2019 +0100 @@ -73,6 +73,7 @@ OrthancServer/SQLiteDatabaseWrapper.cpp OrthancServer/Search/Compatibility/DatabaseLookup.cpp OrthancServer/Search/Compatibility/ICreateInstance.cpp + OrthancServer/Search/Compatibility/IGetChildrenMetadata.cpp OrthancServer/Search/Compatibility/ILookupResources.cpp OrthancServer/Search/Compatibility/SetOfResources.cpp OrthancServer/Search/DatabaseConstraint.cpp
--- a/OrthancServer/IDatabaseWrapper.h Sat Jan 05 12:17:30 2019 +0100 +++ b/OrthancServer/IDatabaseWrapper.h Sat Jan 05 15:08:53 2019 +0100 @@ -237,5 +237,9 @@ // them. However, some metadata might be already existing, and // have to be overwritten. virtual void SetResourcesContent(const ResourcesContent& content) = 0; + + virtual void GetChildrenMetadata(std::list<std::string>& target, + int64_t resourceId, + MetadataType metadata) = 0; }; }
--- a/OrthancServer/SQLiteDatabaseWrapper.h Sat Jan 05 12:17:30 2019 +0100 +++ b/OrthancServer/SQLiteDatabaseWrapper.h Sat Jan 05 15:08:53 2019 +0100 @@ -37,6 +37,7 @@ #include "../Core/SQLite/Connection.h" #include "Search/Compatibility/ICreateInstance.h" +#include "Search/Compatibility/IGetChildrenMetadata.h" #include "Search/Compatibility/ISetResourcesContent.h" #include "ServerToolbox.h" @@ -55,6 +56,7 @@ class SQLiteDatabaseWrapper : public IDatabaseWrapper, public Compatibility::ICreateInstance, + public Compatibility::IGetChildrenMetadata, public Compatibility::ISetResourcesContent { private: @@ -332,15 +334,25 @@ const std::string& patient, const std::string& study, const std::string& series, - const std::string& instance) ORTHANC_OVERRIDE + const std::string& instance) + ORTHANC_OVERRIDE { return ICreateInstance::Apply - (*this, *this, result, instanceId, patient, study, series, instance); + (*this, result, instanceId, patient, study, series, instance); } - virtual void SetResourcesContent(const Orthanc::ResourcesContent& content) ORTHANC_OVERRIDE + virtual void SetResourcesContent(const Orthanc::ResourcesContent& content) + ORTHANC_OVERRIDE { ISetResourcesContent::Apply(*this, content); } + + virtual void GetChildrenMetadata(std::list<std::string>& target, + int64_t resourceId, + MetadataType metadata) + ORTHANC_OVERRIDE + { + IGetChildrenMetadata::Apply(*this, target, resourceId, metadata); + } }; }
--- a/OrthancServer/Search/Compatibility/ICreateInstance.cpp Sat Jan 05 12:17:30 2019 +0100 +++ b/OrthancServer/Search/Compatibility/ICreateInstance.cpp Sat Jan 05 15:08:53 2019 +0100 @@ -40,8 +40,7 @@ { namespace Compatibility { - bool ICreateInstance::Apply(ICreateInstance& compatibility, - IDatabaseWrapper& database, + bool ICreateInstance::Apply(ICreateInstance& database, IDatabaseWrapper::CreateInstanceResult& result, int64_t& instanceId, const std::string& hashPatient, @@ -62,7 +61,7 @@ } } - instanceId = compatibility.CreateResource(hashInstance, ResourceType_Instance); + instanceId = database.CreateResource(hashInstance, ResourceType_Instance); result.isNewPatient_ = false; result.isNewStudy_ = false; @@ -116,32 +115,32 @@ // Create the series if needed if (result.isNewSeries_) { - result.seriesId_ = compatibility.CreateResource(hashSeries, ResourceType_Series); + result.seriesId_ = database.CreateResource(hashSeries, ResourceType_Series); } // Create the study if needed if (result.isNewStudy_) { - result.studyId_ = compatibility.CreateResource(hashStudy, ResourceType_Study); + result.studyId_ = database.CreateResource(hashStudy, ResourceType_Study); } // Create the patient if needed if (result.isNewPatient_) { - result.patientId_ = compatibility.CreateResource(hashPatient, ResourceType_Patient); + result.patientId_ = database.CreateResource(hashPatient, ResourceType_Patient); } // Create the parent-to-child links - compatibility.AttachChild(result.seriesId_, instanceId); + database.AttachChild(result.seriesId_, instanceId); if (result.isNewSeries_) { - compatibility.AttachChild(result.studyId_, result.seriesId_); + database.AttachChild(result.studyId_, result.seriesId_); } if (result.isNewStudy_) { - compatibility.AttachChild(result.patientId_, result.studyId_); + database.AttachChild(result.patientId_, result.studyId_); } // Sanity checks
--- a/OrthancServer/Search/Compatibility/ICreateInstance.h Sat Jan 05 12:17:30 2019 +0100 +++ b/OrthancServer/Search/Compatibility/ICreateInstance.h Sat Jan 05 15:08:53 2019 +0100 @@ -42,14 +42,17 @@ class ICreateInstance : public boost::noncopyable { public: + virtual bool LookupResource(int64_t& id, + ResourceType& type, + const std::string& publicId) = 0; + virtual int64_t CreateResource(const std::string& publicId, ResourceType type) = 0; virtual void AttachChild(int64_t parent, int64_t child) = 0; - static bool Apply(ICreateInstance& compatibility, - IDatabaseWrapper& database, + static bool Apply(ICreateInstance& database, IDatabaseWrapper::CreateInstanceResult& result, int64_t& instanceId, const std::string& patient,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Search/Compatibility/IGetChildrenMetadata.cpp Sat Jan 05 15:08:53 2019 +0100 @@ -0,0 +1,67 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "../../PrecompiledHeadersServer.h" +#include "IGetChildrenMetadata.h" + +namespace Orthanc +{ + namespace Compatibility + { + void IGetChildrenMetadata::Apply(IGetChildrenMetadata& database, + std::list<std::string>& target, + int64_t resourceId, + MetadataType metadata) + { + // This function comes from an optimization of + // "ServerIndex::GetSeriesStatus()" in Orthanc <= 1.5.1 + // Loop over the instances of this series + + target.clear(); + + std::list<int64_t> children; + database.GetChildrenInternalId(children, resourceId); + + std::set<int64_t> instances; + for (std::list<int64_t>::const_iterator + it = children.begin(); it != children.end(); ++it) + { + std::string value; + if (database.LookupMetadata(value, *it, metadata)) + { + target.push_back(value); + } + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Search/Compatibility/IGetChildrenMetadata.h Sat Jan 05 15:08:53 2019 +0100 @@ -0,0 +1,61 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../../ServerEnumerations.h" + +#include <boost/noncopyable.hpp> +#include <list> + +namespace Orthanc +{ + namespace Compatibility + { + class IGetChildrenMetadata : public boost::noncopyable + { + public: + virtual void GetChildrenInternalId(std::list<int64_t>& target, + int64_t id) = 0; + + virtual bool LookupMetadata(std::string& target, + int64_t id, + MetadataType type) = 0; + + static void Apply(IGetChildrenMetadata& database, + std::list<std::string>& target, + int64_t resourceId, + MetadataType metadata); + }; + } +}
--- a/OrthancServer/ServerIndex.cpp Sat Jan 05 12:17:30 2019 +0100 +++ b/OrthancServer/ServerIndex.cpp Sat Jan 05 15:08:53 2019 +0100 @@ -993,21 +993,25 @@ SeriesStatus ServerIndex::GetSeriesStatus(int64_t id, int64_t expectedNumberOfInstances) { - // Loop over the instances of this series - std::list<int64_t> children; - db_.GetChildrenInternalId(children, id); + std::list<std::string> values; + db_.GetChildrenMetadata(values, id, MetadataType_Instance_IndexInSeries); std::set<int64_t> instances; - for (std::list<int64_t>::const_iterator - it = children.begin(); it != children.end(); ++it) + + for (std::list<std::string>::const_iterator + it = values.begin(); it != values.end(); ++it) { - // Get the index of this instance in the series int64_t index; - if (!GetMetadataAsInteger(index, *it, MetadataType_Instance_IndexInSeries)) + + try + { + index = boost::lexical_cast<int64_t>(*it); + } + catch (boost::bad_lexical_cast&) { return SeriesStatus_Unknown; } - + if (!(index > 0 && index <= expectedNumberOfInstances)) { // Out-of-range instance index @@ -1200,9 +1204,13 @@ int64_t i; if (GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) + { result["IndexInSeries"] = static_cast<int>(i); + } else + { result["IndexInSeries"] = Json::nullValue; + } break; }
--- a/Plugins/Engine/OrthancPluginDatabase.cpp Sat Jan 05 12:17:30 2019 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Sat Jan 05 15:08:53 2019 +0100 @@ -1201,7 +1201,7 @@ { // Fallback to compatibility mode return ICreateInstance::Apply - (*this, *this, result, instanceId, patient, study, series, instance); + (*this, result, instanceId, patient, study, series, instance); } else { @@ -1306,4 +1306,14 @@ (metadata.empty() ? NULL : &metadata[0]))); } } + + + + void OrthancPluginDatabase::GetChildrenMetadata(std::list<std::string>& target, + int64_t resourceId, + MetadataType metadata) + { + // TODO + IGetChildrenMetadata::Apply(*this, target, resourceId, metadata); + } }
--- a/Plugins/Engine/OrthancPluginDatabase.h Sat Jan 05 12:17:30 2019 +0100 +++ b/Plugins/Engine/OrthancPluginDatabase.h Sat Jan 05 15:08:53 2019 +0100 @@ -36,9 +36,10 @@ #if ORTHANC_ENABLE_PLUGINS == 1 #include "../../Core/SharedLibrary.h" +#include "../../OrthancServer/Search/Compatibility/ICreateInstance.h" +#include "../../OrthancServer/Search/Compatibility/IGetChildrenMetadata.h" #include "../../OrthancServer/Search/Compatibility/ILookupResources.h" #include "../../OrthancServer/Search/Compatibility/ISetResourcesContent.h" -#include "../../OrthancServer/Search/Compatibility/ICreateInstance.h" #include "../Include/orthanc/OrthancCDatabasePlugin.h" #include "PluginsErrorDictionary.h" @@ -46,9 +47,10 @@ { class OrthancPluginDatabase : public IDatabaseWrapper, + public Compatibility::ICreateInstance, + public Compatibility::IGetChildrenMetadata, public Compatibility::ILookupResources, - public Compatibility::ISetResourcesContent, - public Compatibility::ICreateInstance + public Compatibility::ISetResourcesContent { private: class Transaction; @@ -353,6 +355,11 @@ virtual void SetResourcesContent(const Orthanc::ResourcesContent& content) ORTHANC_OVERRIDE; + + virtual void GetChildrenMetadata(std::list<std::string>& target, + int64_t resourceId, + MetadataType metadata) + ORTHANC_OVERRIDE; }; }