comparison Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2289:89d17c72287b

Modality worklist: added logs to display the number of files parsed and number of matches
author Alain Mazy <alain@mazy.be>
date Fri, 23 Jun 2017 16:43:29 +0200
parents ce5c13b95dac
children 878b59270859
comparison
equal deleted inserted replaced
2288:c6772af6dea3 2289:89d17c72287b
6 * 6 *
7 * This program is free software: you can redistribute it and/or 7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the 9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version. 10 * License, or (at your option) any later version.
11 * 11 *
12 * This program is distributed in the hope that it will be useful, but 12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details. 15 * General Public License for more details.
16 * 16 *
33 static bool filterIssuerAet_ = false; 33 static bool filterIssuerAet_ = false;
34 34
35 /** 35 /**
36 * This is the main function for matching a DICOM worklist against a query. 36 * This is the main function for matching a DICOM worklist against a query.
37 **/ 37 **/
38 static void MatchWorklist(OrthancPluginWorklistAnswers* answers, 38 static bool MatchWorklist(OrthancPluginWorklistAnswers* answers,
39 const OrthancPluginWorklistQuery* query, 39 const OrthancPluginWorklistQuery* query,
40 const OrthancPlugins::FindMatcher& matcher, 40 const OrthancPlugins::FindMatcher& matcher,
41 const std::string& path) 41 const std::string& path)
42 { 42 {
43 OrthancPlugins::MemoryBuffer dicom(context_); 43 OrthancPlugins::MemoryBuffer dicom(context_);
52 if (code != OrthancPluginErrorCode_Success) 52 if (code != OrthancPluginErrorCode_Success)
53 { 53 {
54 OrthancPlugins::LogError(context_, "Error while adding an answer to a worklist request"); 54 OrthancPlugins::LogError(context_, "Error while adding an answer to a worklist request");
55 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); 55 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
56 } 56 }
57 } 57
58 return true;
59 }
60
61 return false;
58 } 62 }
59 63
60 64
61 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, 65 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query,
62 const char* issuerAet) 66 const char* issuerAet)
65 OrthancPlugins::MemoryBuffer dicom(context_); 69 OrthancPlugins::MemoryBuffer dicom(context_);
66 dicom.GetDicomQuery(query); 70 dicom.GetDicomQuery(query);
67 71
68 // Convert the DICOM as JSON, and dump it to the user in "--verbose" mode 72 // Convert the DICOM as JSON, and dump it to the user in "--verbose" mode
69 Json::Value json; 73 Json::Value json;
70 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, 74 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short,
71 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); 75 static_cast<OrthancPluginDicomToJsonFlags>(0), 0);
72 76
73 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + 77 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " +
74 std::string(issuerAet) + ":\n" + json.toStyledString()); 78 std::string(issuerAet) + ":\n" + json.toStyledString());
75 79
76 if (!filterIssuerAet_) 80 if (!filterIssuerAet_)
77 { 81 {
78 return new OrthancPlugins::FindMatcher(context_, query); 82 return new OrthancPlugins::FindMatcher(context_, query);
138 { 142 {
139 // Construct an object to match the worklists in the database against the C-Find query 143 // Construct an object to match the worklists in the database against the C-Find query
140 std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, issuerAet)); 144 std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, issuerAet));
141 145
142 // Loop over the regular files in the database folder 146 // Loop over the regular files in the database folder
143 namespace fs = boost::filesystem; 147 namespace fs = boost::filesystem;
144 148
145 fs::path source(folder_); 149 fs::path source(folder_);
146 fs::directory_iterator end; 150 fs::directory_iterator end;
151 int parsedFilesCount = 0;
152 int matchedWorklistCount = 0;
147 153
148 try 154 try
149 { 155 {
150 for (fs::directory_iterator it(source); it != end; ++it) 156 for (fs::directory_iterator it(source); it != end; ++it)
151 { 157 {
157 std::string extension = fs::extension(it->path()); 163 std::string extension = fs::extension(it->path());
158 std::transform(extension.begin(), extension.end(), extension.begin(), tolower); // Convert to lowercase 164 std::transform(extension.begin(), extension.end(), extension.begin(), tolower); // Convert to lowercase
159 165
160 if (extension == ".wl") 166 if (extension == ".wl")
161 { 167 {
168 parsedFilesCount++;
162 // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query 169 // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query
163 MatchWorklist(answers, query, *matcher, it->path().string()); 170 if (MatchWorklist(answers, query, *matcher, it->path().string()))
171 {
172 OrthancPlugins::LogInfo(context_, "Worklist matched: " + it->path().string());
173 matchedWorklistCount++;
174 }
164 } 175 }
165 } 176 }
166 } 177 }
178
179 std::ostringstream message;
180 message << "Worklist C-Find: parsed " << parsedFilesCount << " files, found " << matchedWorklistCount << " match(es)";
181 OrthancPlugins::LogInfo(context_, message.str());
182
167 } 183 }
168 catch (fs::filesystem_error&) 184 catch (fs::filesystem_error&)
169 { 185 {
170 OrthancPlugins::LogError(context_, "Inexistent folder while scanning for worklists: " + source.string()); 186 OrthancPlugins::LogError(context_, "Inexistent folder while scanning for worklists: " + source.string());
171 return OrthancPluginErrorCode_DirectoryExpected; 187 return OrthancPluginErrorCode_DirectoryExpected;
190 context_ = c; 206 context_ = c;
191 207
192 /* Check the version of the Orthanc core */ 208 /* Check the version of the Orthanc core */
193 if (OrthancPluginCheckVersion(c) == 0) 209 if (OrthancPluginCheckVersion(c) == 0)
194 { 210 {
195 OrthancPlugins::ReportMinimalOrthancVersion(context_, 211 OrthancPlugins::ReportMinimalOrthancVersion(context_,
196 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, 212 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
197 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, 213 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
198 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); 214 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
199 return -1; 215 return -1;
200 } 216 }