Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/ModalityWorklists/Plugin.cpp @ 5630:3b7fb32ecbb0 default tip
fix OrthancPlugin.doxygen
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 17 May 2024 13:23:58 +0200 |
parents | a7c88563c8cc |
children |
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 |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5280
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5280
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1802 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * 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
|
12 * |
1802 | 13 * This program is distributed in the hope that it will be useful, but |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
5538
6ce05f8b5b13
deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
23 #define MODALITY_WORKLISTS_NAME "worklists" |
6ce05f8b5b13
deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
24 |
4045 | 25 #include "../../../../OrthancFramework/Sources/Compatibility.h" |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
26 #include "../Common/OrthancPluginCppWrapper.h" |
1802 | 27 |
28 #include <boost/filesystem.hpp> | |
29 #include <json/value.h> | |
30 #include <string.h> | |
31 #include <iostream> | |
1814 | 32 #include <algorithm> |
1802 | 33 |
34 static std::string folder_; | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
35 static bool filterIssuerAet_ = false; |
4145
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
36 static unsigned int limitAnswers_ = 0; |
1802 | 37 |
38 /** | |
39 * This is the main function for matching a DICOM worklist against a query. | |
40 **/ | |
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
|
41 static bool MatchWorklist(OrthancPluginWorklistAnswers* answers, |
2214 | 42 const OrthancPluginWorklistQuery* query, |
43 const OrthancPlugins::FindMatcher& matcher, | |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
44 const std::string& path) |
1802 | 45 { |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
46 OrthancPlugins::MemoryBuffer dicom; |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
47 dicom.ReadFile(path); |
1802 | 48 |
2214 | 49 if (matcher.IsMatch(dicom)) |
1802 | 50 { |
51 // 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
|
52 OrthancPluginErrorCode code = OrthancPluginWorklistAddAnswer |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
53 (OrthancPlugins::GetGlobalContext(), answers, query, dicom.GetData(), dicom.GetSize()); |
1802 | 54 |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
55 if (code != OrthancPluginErrorCode_Success) |
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
56 { |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
57 ORTHANC_PLUGINS_LOG_ERROR("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
|
58 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
|
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 true; |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
62 } |
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
|
63 |
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
|
64 return false; |
1814 | 65 } |
66 | |
67 | |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
68 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
69 const char* issuerAet) |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
70 { |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
71 // Extract the DICOM instance underlying the C-Find query |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
72 OrthancPlugins::MemoryBuffer dicom; |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
73 dicom.GetDicomQuery(query); |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
74 |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
75 // 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
|
76 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
|
77 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
|
78 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
|
79 |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
80 ORTHANC_PLUGINS_LOG_INFO("Received worklist query from remote modality " + |
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
81 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
|
82 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
83 if (!filterIssuerAet_) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
84 { |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
85 return new OrthancPlugins::FindMatcher(query); |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
86 } |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
87 else |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
88 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
89 // 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
|
90 // 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
|
91 // 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
|
92 // requesting the ScheduledStationAETitle to correspond to the AET |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
93 // 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
|
94 // "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
|
95 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
100 if (!json.isMember(SCHEDULED_PROCEDURE_STEP_SEQUENCE)) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
101 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
102 // Create a ScheduledProcedureStepSequence sequence, with one empty element |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
103 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE] = Json::arrayValue; |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
104 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE].append(Json::objectValue); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
105 } |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
106 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
107 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
|
108 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
109 if (v.type() != Json::arrayValue || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
110 v.size() != 1 || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
111 v[0].type() != Json::objectValue) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
112 { |
2236 | 113 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
114 } |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
115 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
116 // Set the ScheduledStationAETitle if none was provided |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
117 if (!v[0].isMember(SCHEDULED_STATION_AETITLE) || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
118 v[0].type() != Json::stringValue || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
119 v[0][SCHEDULED_STATION_AETITLE].asString().size() == 0 || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
120 v[0][SCHEDULED_STATION_AETITLE].asString() == "*") |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
121 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
122 v[0][SCHEDULED_STATION_AETITLE] = issuerAet; |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
123 } |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
124 |
2827
d4fd4614f275
IncomingWorklistRequestFilter() to filter incoming C-FIND worklist queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
125 if (json.isMember(PREGNANCY_STATUS) && |
d4fd4614f275
IncomingWorklistRequestFilter() to filter incoming C-FIND worklist queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
126 json[PREGNANCY_STATUS].asString().size() == 0) |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
127 { |
2827
d4fd4614f275
IncomingWorklistRequestFilter() to filter incoming C-FIND worklist queries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
128 json.removeMember(PREGNANCY_STATUS); |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
129 } |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
130 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
131 // Encode the modified JSON as a DICOM instance, then convert it to a C-Find matcher |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
132 OrthancPlugins::MemoryBuffer modified; |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
133 modified.CreateDicom(json, OrthancPluginCreateDicomFlags_None); |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
134 |
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
135 return new OrthancPlugins::FindMatcher(modified); |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
136 } |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
137 } |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
138 |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
139 |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
140 |
1802 | 141 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, |
142 const OrthancPluginWorklistQuery* query, | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
143 const char* issuerAet, |
1802 | 144 const char* calledAet) |
145 { | |
146 try | |
147 { | |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
148 // Construct an object to match the worklists in the database against the C-Find query |
3768
6110a4995ace
replacing std::auto_ptr by std::unique_ptr in GDCM sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
149 std::unique_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, issuerAet)); |
1911 | 150 |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
151 // 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
|
152 namespace fs = boost::filesystem; |
2214 | 153 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
154 fs::path source(folder_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
155 fs::directory_iterator end; |
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 try |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
158 { |
5280 | 159 unsigned int parsedFilesCount = 0; |
160 unsigned int matchedWorklistCount = 0; | |
161 | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
162 for (fs::directory_iterator it(source); it != end; ++it) |
1802 | 163 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
164 fs::file_type type(it->status().type()); |
1814 | 165 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
166 if (type == fs::regular_file || |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
167 type == fs::reparse_file) // cf. BitBucket issue #11 |
1802 | 168 { |
5627
a7c88563c8cc
fix build with boost 1.85.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5572
diff
changeset
|
169 std::string extension = it->path().extension().string(); |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
170 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
|
171 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
172 if (extension == ".wl") |
1802 | 173 { |
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
|
174 parsedFilesCount++; |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
175 // 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
|
176 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
|
177 { |
4145
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
178 if (limitAnswers_ != 0 && |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
179 matchedWorklistCount >= limitAnswers_) |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
180 { |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
181 // Too many answers are to be returned wrt. the |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
182 // "LimitAnswers" configuration parameter. Mark the |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
183 // C-FIND result as incomplete. |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
184 OrthancPluginWorklistMarkIncomplete(OrthancPlugins::GetGlobalContext(), answers); |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
185 return OrthancPluginErrorCode_Success; |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
186 } |
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
187 |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
188 ORTHANC_PLUGINS_LOG_INFO("Worklist matched: " + it->path().string()); |
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
|
189 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
|
190 } |
1802 | 191 } |
192 } | |
193 } | |
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
|
194 |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
195 ORTHANC_PLUGINS_LOG_INFO("Worklist C-Find: parsed " + boost::lexical_cast<std::string>(parsedFilesCount) + |
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
196 " files, found " + boost::lexical_cast<std::string>(matchedWorklistCount) + " match(es)"); |
1802 | 197 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
198 catch (fs::filesystem_error&) |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
199 { |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
200 ORTHANC_PLUGINS_LOG_ERROR("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
|
201 return OrthancPluginErrorCode_DirectoryExpected; |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
202 } |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
203 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
204 return OrthancPluginErrorCode_Success; |
1802 | 205 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
206 catch (OrthancPlugins::PluginException& e) |
1802 | 207 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
208 return e.GetErrorCode(); |
1802 | 209 } |
210 } | |
211 | |
212 | |
213 extern "C" | |
214 { | |
215 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | |
216 { | |
5563 | 217 OrthancPlugins::SetGlobalContext(c, MODALITY_WORKLISTS_NAME); |
1802 | 218 |
219 /* Check the version of the Orthanc core */ | |
220 if (OrthancPluginCheckVersion(c) == 0) | |
221 { | |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
222 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
2268
ce5c13b95dac
New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
223 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
ce5c13b95dac
New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
224 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
1802 | 225 return -1; |
226 } | |
227 | |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
228 ORTHANC_PLUGINS_LOG_WARNING("Sample worklist plugin is initializing"); |
5538
6ce05f8b5b13
deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
229 OrthancPluginSetDescription2(c, MODALITY_WORKLISTS_NAME, "Serve DICOM modality worklists from a folder with Orthanc."); |
1802 | 230 |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
231 OrthancPlugins::OrthancConfiguration configuration; |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
232 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
233 OrthancPlugins::OrthancConfiguration worklists; |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
234 configuration.GetSection(worklists, "Worklists"); |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
235 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
236 bool enabled = worklists.GetBooleanValue("Enable", false); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
237 if (enabled) |
1802 | 238 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
239 if (worklists.LookupStringValue(folder_, "Database")) |
1802 | 240 { |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
241 ORTHANC_PLUGINS_LOG_WARNING("The database of worklists will be read from folder: " + folder_); |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2827
diff
changeset
|
242 OrthancPluginRegisterWorklistCallback(OrthancPlugins::GetGlobalContext(), Callback); |
1802 | 243 } |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
244 else |
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
245 { |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
246 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"Worklists.Database\" must contain a path"); |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
247 return -1; |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
248 } |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
249 |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
250 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false); |
4145
c5cdb6dc6865
New config option "Worklist.LimitAnswers" for the sample modality worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
251 limitAnswers_ = worklists.GetUnsignedIntegerValue("LimitAnswers", 0); |
1802 | 252 } |
253 else | |
254 { | |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
255 ORTHANC_PLUGINS_LOG_WARNING("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
|
256 } |
1802 | 257 |
258 return 0; | |
259 } | |
260 | |
261 | |
262 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
263 { | |
5572
f0dc99bc811c
removed circular dependency of OrthancPluginsCppWrapper with Orthanc::Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5563
diff
changeset
|
264 ORTHANC_PLUGINS_LOG_WARNING("Sample worklist plugin is finalizing"); |
1802 | 265 } |
266 | |
267 | |
268 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
269 { | |
5538
6ce05f8b5b13
deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
270 return MODALITY_WORKLISTS_NAME; |
1802 | 271 } |
272 | |
273 | |
274 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
275 { | |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
276 return MODALITY_WORKLISTS_VERSION; |
1802 | 277 } |
278 } |