Mercurial > hg > orthanc
changeset 2215:028214a95194
refactoring the worklist sample
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 10 Dec 2016 11:41:17 +0100 |
parents | b1d93286b315 |
children | 9a8fab016145 |
files | Plugins/Engine/OrthancPlugins.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h Plugins/Samples/ModalityWorklists/Plugin.cpp |
diffstat | 4 files changed, 48 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp Sat Dec 10 11:24:58 2016 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Sat Dec 10 11:41:17 2016 +0100 @@ -2630,7 +2630,7 @@ else { ParsedDicomFile query(p.dicom, p.size); - reinterpret_cast<const HierarchicalMatcher*>(p.matcher)->Match(query); + *p.isMatch = reinterpret_cast<const HierarchicalMatcher*>(p.matcher)->Match(query) ? 1 : 0; return true; } }
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Sat Dec 10 11:24:58 2016 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Sat Dec 10 11:41:17 2016 +0100 @@ -848,12 +848,13 @@ } - FindMatcher::FindMatcher(OrthancPluginContext* context, - const void* query, - uint32_t size) : - context_(context), - worklist_(NULL) + void FindMatcher::SetupDicom(OrthancPluginContext* context, + const void* query, + uint32_t size) { + context_ = context; + worklist_ = NULL; + matcher_ = OrthancPluginCreateFindMatcher(context_, query, size); if (matcher_ == NULL) {
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Sat Dec 10 11:24:58 2016 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Sat Dec 10 11:41:17 2016 +0100 @@ -341,13 +341,26 @@ OrthancPluginFindMatcher* matcher_; const OrthancPluginWorklistQuery* worklist_; + void SetupDicom(OrthancPluginContext* context, + const void* query, + uint32_t size); + public: FindMatcher(OrthancPluginContext* context, const OrthancPluginWorklistQuery* worklist); FindMatcher(OrthancPluginContext* context, const void* query, - uint32_t size); + uint32_t size) + { + SetupDicom(context, query, size); + } + + FindMatcher(OrthancPluginContext* context, + const MemoryBuffer& dicom) + { + SetupDicom(context, dicom.GetData(), dicom.GetSize()); + } ~FindMatcher();
--- a/Plugins/Samples/ModalityWorklists/Plugin.cpp Sat Dec 10 11:24:58 2016 +0100 +++ b/Plugins/Samples/ModalityWorklists/Plugin.cpp Sat Dec 10 11:41:17 2016 +0100 @@ -57,6 +57,27 @@ } +OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, + const char* remoteAet) +{ + OrthancPlugins::MemoryBuffer dicom(context_); + dicom.GetDicomQuery(query); + + { + Json::Value json; + dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, + static_cast<OrthancPluginDicomToJsonFlags>(0), 0); + + OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + + std::string(remoteAet) + ":\n" + json.toStyledString()); + } + + return new OrthancPlugins::FindMatcher(context_, query); + //return new OrthancPlugins::FindMatcher(context_, dicom); +} + + + OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, const OrthancPluginWorklistQuery* query, const char* remoteAet, @@ -64,21 +85,11 @@ { try { - namespace fs = boost::filesystem; - - { - OrthancPlugins::MemoryBuffer dicom(context_); - dicom.GetDicomQuery(query); + // Construct an object to match the worklists in the database against the C-Find query + std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, remoteAet)); - Json::Value json; - dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, - static_cast<OrthancPluginDicomToJsonFlags>(0), 0); - - OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + - std::string(remoteAet) + ":\n" + json.toStyledString()); - } - - OrthancPlugins::FindMatcher matcher(context_, query); + // Loop over the regular files in the database folder + namespace fs = boost::filesystem; fs::path source(folder_); fs::directory_iterator end; @@ -97,7 +108,8 @@ if (extension == ".wl") { - MatchWorklist(answers, query, matcher, it->path().string()); + // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query + MatchWorklist(answers, query, *matcher, it->path().string()); } } }