Mercurial > hg > orthanc
annotate Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2925:a80ba85d89e6
Orthanc starts even if jobs from a previous execution cannot be unserialized
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Nov 2018 09:46:21 +0100 |
parents | d4fd4614f275 |
children | bb7a66efbeb1 |
rev | line source |
---|---|
1802 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1802 | 4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2289
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1802 | 6 * |
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 | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
11 * |
1802 | 12 * This program is distributed in the hope that it will be useful, but |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
22 #include "../Common/OrthancPluginCppWrapper.h" |
1802 | 23 |
24 #include <boost/filesystem.hpp> | |
25 #include <json/value.h> | |
26 #include <json/reader.h> | |
27 #include <string.h> | |
28 #include <iostream> | |
1814 | 29 #include <algorithm> |
1802 | 30 |
31 static OrthancPluginContext* context_ = NULL; | |
32 static std::string folder_; | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
33 static bool filterIssuerAet_ = false; |
1802 | 34 |
35 /** | |
36 * This is the main function for matching a DICOM worklist against a query. | |
37 **/ | |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
38 static bool MatchWorklist(OrthancPluginWorklistAnswers* answers, |
2214 | 39 const OrthancPluginWorklistQuery* query, |
40 const OrthancPlugins::FindMatcher& matcher, | |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
41 const std::string& path) |
1802 | 42 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
43 OrthancPlugins::MemoryBuffer dicom(context_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
44 dicom.ReadFile(path); |
1802 | 45 |
2214 | 46 if (matcher.IsMatch(dicom)) |
1802 | 47 { |
48 // This DICOM file matches the worklist query, add it to the answers | |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
49 OrthancPluginErrorCode code = OrthancPluginWorklistAddAnswer |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
50 (context_, answers, query, dicom.GetData(), dicom.GetSize()); |
1802 | 51 |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
52 if (code != OrthancPluginErrorCode_Success) |
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
53 { |
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
54 OrthancPlugins::LogError(context_, "Error while adding an answer to a worklist request"); |
2234
a78d15509a1c
cleaner separation of PluginException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
55 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
56 } |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
57 |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
58 return true; |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
59 } |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
60 |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
61 return false; |
1814 | 62 } |
63 | |
64 | |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
65 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
66 const char* issuerAet) |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
67 { |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
68 // Extract the DICOM instance underlying the C-Find query |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
69 OrthancPlugins::MemoryBuffer dicom(context_); |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
70 dicom.GetDicomQuery(query); |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
71 |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
72 // Convert the DICOM as JSON, and dump it to the user in "--verbose" mode |
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
73 Json::Value json; |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
74 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
75 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
76 |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
77 OrthancPlugins::LogInfo(context_, "Received worklist query from remote modality " + |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
78 std::string(issuerAet) + ":\n" + json.toStyledString()); |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
79 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
80 if (!filterIssuerAet_) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
81 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
82 return new OrthancPlugins::FindMatcher(context_, query); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
83 } |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
84 else |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
85 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
86 // Alternative sample showing how to fine-tune an incoming C-Find |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
87 // request, before matching it against the worklist database. The |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
88 // code below will restrict the original DICOM request by |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
89 // requesting the ScheduledStationAETitle to correspond to the AET |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
90 // of the C-Find issuer. This code will make the integration test |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
91 // "test_filter_issuer_aet" succeed (cf. the orthanc-tests repository). |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
92 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
93 static const char* SCHEDULED_PROCEDURE_STEP_SEQUENCE = "0040,0100"; |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
94 static const char* SCHEDULED_STATION_AETITLE = "0040,0001"; |
2827
d4fd4614f275
IncomingWorklistRequestFilter() to filter incoming C-FIND worklist queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
95 static const char* PREGNANCY_STATUS = "0010,21c0"; |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
96 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
97 if (!json.isMember(SCHEDULED_PROCEDURE_STEP_SEQUENCE)) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
98 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
99 // Create a ScheduledProcedureStepSequence sequence, with one empty element |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
100 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE] = Json::arrayValue; |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
101 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE].append(Json::objectValue); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
102 } |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
103 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
104 Json::Value& v = json[SCHEDULED_PROCEDURE_STEP_SEQUENCE]; |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
105 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
106 if (v.type() != Json::arrayValue || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
107 v.size() != 1 || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
108 v[0].type() != Json::objectValue) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
109 { |
2236 | 110 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
111 } |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
112 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
113 // Set the ScheduledStationAETitle if none was provided |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
114 if (!v[0].isMember(SCHEDULED_STATION_AETITLE) || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
115 v[0].type() != Json::stringValue || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
116 v[0][SCHEDULED_STATION_AETITLE].asString().size() == 0 || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
117 v[0][SCHEDULED_STATION_AETITLE].asString() == "*") |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
118 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
119 v[0][SCHEDULED_STATION_AETITLE] = issuerAet; |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
120 } |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
121 |
2827
d4fd4614f275
IncomingWorklistRequestFilter() to filter incoming C-FIND worklist queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
122 if (json.isMember(PREGNANCY_STATUS) && |
d4fd4614f275
IncomingWorklistRequestFilter() to filter incoming C-FIND worklist queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
123 json[PREGNANCY_STATUS].asString().size() == 0) |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
124 { |
2827
d4fd4614f275
IncomingWorklistRequestFilter() to filter incoming C-FIND worklist queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
125 json.removeMember(PREGNANCY_STATUS); |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
126 } |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
127 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
128 // Encode the modified JSON as a DICOM instance, then convert it to a C-Find matcher |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
129 OrthancPlugins::MemoryBuffer modified(context_); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
130 modified.CreateDicom(json, OrthancPluginCreateDicomFlags_None); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
131 return new OrthancPlugins::FindMatcher(context_, modified); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
132 } |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
133 } |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
134 |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
135 |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
136 |
1802 | 137 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, |
138 const OrthancPluginWorklistQuery* query, | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
139 const char* issuerAet, |
1802 | 140 const char* calledAet) |
141 { | |
142 try | |
143 { | |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
144 // Construct an object to match the worklists in the database against the C-Find query |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
145 std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, issuerAet)); |
1911 | 146 |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
147 // Loop over the regular files in the database folder |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
148 namespace fs = boost::filesystem; |
2214 | 149 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
150 fs::path source(folder_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
151 fs::directory_iterator end; |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
152 int parsedFilesCount = 0; |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
153 int matchedWorklistCount = 0; |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
154 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
155 try |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
156 { |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
157 for (fs::directory_iterator it(source); it != end; ++it) |
1802 | 158 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
159 fs::file_type type(it->status().type()); |
1814 | 160 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
161 if (type == fs::regular_file || |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
162 type == fs::reparse_file) // cf. BitBucket issue #11 |
1802 | 163 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
164 std::string extension = fs::extension(it->path()); |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
165 std::transform(extension.begin(), extension.end(), extension.begin(), tolower); // Convert to lowercase |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
166 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
167 if (extension == ".wl") |
1802 | 168 { |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
169 parsedFilesCount++; |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
170 // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
171 if (MatchWorklist(answers, query, *matcher, it->path().string())) |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
172 { |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
173 OrthancPlugins::LogInfo(context_, "Worklist matched: " + it->path().string()); |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
174 matchedWorklistCount++; |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
175 } |
1802 | 176 } |
177 } | |
178 } | |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
179 |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
180 std::ostringstream message; |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
181 message << "Worklist C-Find: parsed " << parsedFilesCount << " files, found " << matchedWorklistCount << " match(es)"; |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
182 OrthancPlugins::LogInfo(context_, message.str()); |
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
183 |
1802 | 184 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
185 catch (fs::filesystem_error&) |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
186 { |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
187 OrthancPlugins::LogError(context_, "Inexistent folder while scanning for worklists: " + source.string()); |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
188 return OrthancPluginErrorCode_DirectoryExpected; |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
189 } |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
190 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
191 // Uncomment the following line if too many answers are to be returned |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
192 // OrthancPluginMarkWorklistAnswersIncomplete(context_, answers); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
193 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
194 return OrthancPluginErrorCode_Success; |
1802 | 195 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
196 catch (OrthancPlugins::PluginException& e) |
1802 | 197 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
198 return e.GetErrorCode(); |
1802 | 199 } |
200 } | |
201 | |
202 | |
203 extern "C" | |
204 { | |
205 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | |
206 { | |
207 context_ = c; | |
208 | |
209 /* Check the version of the Orthanc core */ | |
210 if (OrthancPluginCheckVersion(c) == 0) | |
211 { | |
2289
89d17c72287b
Modality worklist: added logs to display the number of files parsed and number of matches
Alain Mazy <alain@mazy.be>
parents:
2268
diff
changeset
|
212 OrthancPlugins::ReportMinimalOrthancVersion(context_, |
2268
ce5c13b95dac
New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
213 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
ce5c13b95dac
New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
214 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
ce5c13b95dac
New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
215 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
1802 | 216 return -1; |
217 } | |
218 | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
219 OrthancPlugins::LogWarning(context_, "Sample worklist plugin is initializing"); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
220 OrthancPluginSetDescription(context_, "Serve DICOM modality worklists from a folder with Orthanc."); |
1802 | 221 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
222 OrthancPlugins::OrthancConfiguration configuration(context_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
223 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
224 OrthancPlugins::OrthancConfiguration worklists; |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
225 configuration.GetSection(worklists, "Worklists"); |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
226 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
227 bool enabled = worklists.GetBooleanValue("Enable", false); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
228 if (enabled) |
1802 | 229 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
230 if (worklists.LookupStringValue(folder_, "Database")) |
1802 | 231 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
232 OrthancPlugins::LogWarning(context_, "The database of worklists will be read from folder: " + folder_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
233 OrthancPluginRegisterWorklistCallback(context_, Callback); |
1802 | 234 } |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
235 else |
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
236 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
237 OrthancPlugins::LogError(context_, "The configuration option \"Worklists.Database\" must contain a path"); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
238 return -1; |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
239 } |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
240 |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
241 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false); |
1802 | 242 } |
243 else | |
244 { | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
245 OrthancPlugins::LogWarning(context_, "Worklist server is disabled by the configuration file"); |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
246 } |
1802 | 247 |
248 return 0; | |
249 } | |
250 | |
251 | |
252 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
253 { | |
254 OrthancPluginLogWarning(context_, "Sample worklist plugin is finalizing"); | |
255 } | |
256 | |
257 | |
258 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
259 { | |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
260 return "worklists"; |
1802 | 261 } |
262 | |
263 | |
264 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
265 { | |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
266 return MODALITY_WORKLISTS_VERSION; |
1802 | 267 } |
268 } |