comparison Plugins/Samples/ModalityWorklists/Plugin.cpp @ 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
comparison
equal deleted inserted replaced
2214:b1d93286b315 2215:028214a95194
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 59
60 OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query,
61 const char* remoteAet)
62 {
63 OrthancPlugins::MemoryBuffer dicom(context_);
64 dicom.GetDicomQuery(query);
65
66 {
67 Json::Value json;
68 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short,
69 static_cast<OrthancPluginDicomToJsonFlags>(0), 0);
70
71 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " +
72 std::string(remoteAet) + ":\n" + json.toStyledString());
73 }
74
75 return new OrthancPlugins::FindMatcher(context_, query);
76 //return new OrthancPlugins::FindMatcher(context_, dicom);
77 }
78
79
80
60 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, 81 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers,
61 const OrthancPluginWorklistQuery* query, 82 const OrthancPluginWorklistQuery* query,
62 const char* remoteAet, 83 const char* remoteAet,
63 const char* calledAet) 84 const char* calledAet)
64 { 85 {
65 try 86 try
66 { 87 {
88 // Construct an object to match the worklists in the database against the C-Find query
89 std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, remoteAet));
90
91 // Loop over the regular files in the database folder
67 namespace fs = boost::filesystem; 92 namespace fs = boost::filesystem;
68
69 {
70 OrthancPlugins::MemoryBuffer dicom(context_);
71 dicom.GetDicomQuery(query);
72
73 Json::Value json;
74 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short,
75 static_cast<OrthancPluginDicomToJsonFlags>(0), 0);
76
77 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " +
78 std::string(remoteAet) + ":\n" + json.toStyledString());
79 }
80
81 OrthancPlugins::FindMatcher matcher(context_, query);
82 93
83 fs::path source(folder_); 94 fs::path source(folder_);
84 fs::directory_iterator end; 95 fs::directory_iterator end;
85 96
86 try 97 try
95 std::string extension = fs::extension(it->path()); 106 std::string extension = fs::extension(it->path());
96 std::transform(extension.begin(), extension.end(), extension.begin(), tolower); // Convert to lowercase 107 std::transform(extension.begin(), extension.end(), extension.begin(), tolower); // Convert to lowercase
97 108
98 if (extension == ".wl") 109 if (extension == ".wl")
99 { 110 {
100 MatchWorklist(answers, query, matcher, it->path().string()); 111 // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query
112 MatchWorklist(answers, query, *matcher, it->path().string());
101 } 113 }
102 } 114 }
103 } 115 }
104 } 116 }
105 catch (fs::filesystem_error&) 117 catch (fs::filesystem_error&)