Mercurial > hg > orthanc
annotate Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2239:15637de71fee
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Dec 2016 17:01:33 +0100 |
parents | 55843d0139d3 |
children | a3a65de1840f |
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 |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
21 #include "../Common/OrthancPluginCppWrapper.h" |
1802 | 22 |
23 #include <boost/filesystem.hpp> | |
24 #include <json/value.h> | |
25 #include <json/reader.h> | |
26 #include <string.h> | |
27 #include <iostream> | |
1814 | 28 #include <algorithm> |
1802 | 29 |
30 static OrthancPluginContext* context_ = NULL; | |
31 static std::string folder_; | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
32 static bool filterIssuerAet_ = false; |
1802 | 33 |
34 /** | |
35 * This is the main function for matching a DICOM worklist against a query. | |
36 **/ | |
2214 | 37 static void MatchWorklist(OrthancPluginWorklistAnswers* answers, |
38 const OrthancPluginWorklistQuery* query, | |
39 const OrthancPlugins::FindMatcher& matcher, | |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
40 const std::string& path) |
1802 | 41 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
42 OrthancPlugins::MemoryBuffer dicom(context_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
43 dicom.ReadFile(path); |
1802 | 44 |
2214 | 45 if (matcher.IsMatch(dicom)) |
1802 | 46 { |
47 // 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
|
48 OrthancPluginErrorCode code = OrthancPluginWorklistAddAnswer |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
49 (context_, answers, query, dicom.GetData(), dicom.GetSize()); |
1802 | 50 |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
51 if (code != OrthancPluginErrorCode_Success) |
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
52 { |
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
53 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
|
54 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
|
55 } |
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
56 } |
1814 | 57 } |
58 | |
59 | |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
60 static OrthancPlugins::FindMatcher* CreateMatcher(const OrthancPluginWorklistQuery* query, |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
61 const char* issuerAet) |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
62 { |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
63 // 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
|
64 OrthancPlugins::MemoryBuffer dicom(context_); |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
65 dicom.GetDicomQuery(query); |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
66 |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
67 // 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
|
68 Json::Value json; |
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
69 dicom.DicomToJson(json, OrthancPluginDicomToJsonFormat_Short, |
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
70 static_cast<OrthancPluginDicomToJsonFlags>(0), 0); |
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
71 |
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
72 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
|
73 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
|
74 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
75 if (!filterIssuerAet_) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
76 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
77 return new OrthancPlugins::FindMatcher(context_, query); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
78 } |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
79 else |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
80 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
81 // 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
|
82 // 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
|
83 // 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
|
84 // requesting the ScheduledStationAETitle to correspond to the AET |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
85 // 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
|
86 // "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
|
87 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
88 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
|
89 static const char* SCHEDULED_STATION_AETITLE = "0040,0001"; |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
90 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
91 if (!json.isMember(SCHEDULED_PROCEDURE_STEP_SEQUENCE)) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
92 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
93 // Create a ScheduledProcedureStepSequence sequence, with one empty element |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
94 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE] = Json::arrayValue; |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
95 json[SCHEDULED_PROCEDURE_STEP_SEQUENCE].append(Json::objectValue); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
96 } |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
97 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
98 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
|
99 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
100 if (v.type() != Json::arrayValue || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
101 v.size() != 1 || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
102 v[0].type() != Json::objectValue) |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
103 { |
2236 | 104 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
105 } |
2216
9a8fab016145
sample worklist plugin fine-tuning the C-Find query
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2215
diff
changeset
|
106 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
107 // Set the ScheduledStationAETitle if none was provided |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
108 if (!v[0].isMember(SCHEDULED_STATION_AETITLE) || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
109 v[0].type() != Json::stringValue || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
110 v[0][SCHEDULED_STATION_AETITLE].asString().size() == 0 || |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
111 v[0][SCHEDULED_STATION_AETITLE].asString() == "*") |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
112 { |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
113 v[0][SCHEDULED_STATION_AETITLE] = issuerAet; |
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 if (json.isMember("0010,21c0") && |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
117 json["0010,21c0"].asString().size() == 0) |
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 json.removeMember("0010,21c0"); |
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 |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
122 // 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
|
123 OrthancPlugins::MemoryBuffer modified(context_); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
124 modified.CreateDicom(json, OrthancPluginCreateDicomFlags_None); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
125 return new OrthancPlugins::FindMatcher(context_, modified); |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
126 } |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
127 } |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
128 |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
129 |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
130 |
1802 | 131 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers, |
132 const OrthancPluginWorklistQuery* query, | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
133 const char* issuerAet, |
1802 | 134 const char* calledAet) |
135 { | |
136 try | |
137 { | |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
138 // 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
|
139 std::auto_ptr<OrthancPlugins::FindMatcher> matcher(CreateMatcher(query, issuerAet)); |
1911 | 140 |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
141 // Loop over the regular files in the database folder |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
142 namespace fs = boost::filesystem; |
2214 | 143 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
144 fs::path source(folder_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
145 fs::directory_iterator end; |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
146 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
147 try |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
148 { |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
149 for (fs::directory_iterator it(source); it != end; ++it) |
1802 | 150 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
151 fs::file_type type(it->status().type()); |
1814 | 152 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
153 if (type == fs::regular_file || |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
154 type == fs::reparse_file) // cf. BitBucket issue #11 |
1802 | 155 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
156 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
|
157 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
|
158 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
159 if (extension == ".wl") |
1802 | 160 { |
2215
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
161 // We found a worklist (i.e. a DICOM find with extension ".wl"), match it against the query |
028214a95194
refactoring the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2214
diff
changeset
|
162 MatchWorklist(answers, query, *matcher, it->path().string()); |
1802 | 163 } |
164 } | |
165 } | |
166 } | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
167 catch (fs::filesystem_error&) |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
168 { |
2206
27106f7e3759
more refactoring of the worklist sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2205
diff
changeset
|
169 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
|
170 return OrthancPluginErrorCode_DirectoryExpected; |
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 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
173 // 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
|
174 // OrthancPluginMarkWorklistAnswersIncomplete(context_, answers); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
175 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
176 return OrthancPluginErrorCode_Success; |
1802 | 177 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
178 catch (OrthancPlugins::PluginException& e) |
1802 | 179 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
180 return e.GetErrorCode(); |
1802 | 181 } |
182 } | |
183 | |
184 | |
185 extern "C" | |
186 { | |
187 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | |
188 { | |
189 context_ = c; | |
190 | |
191 /* Check the version of the Orthanc core */ | |
192 if (OrthancPluginCheckVersion(c) == 0) | |
193 { | |
194 char info[1024]; | |
195 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
196 context_->orthancVersion, | |
197 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
198 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
199 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
200 OrthancPluginLogError(context_, info); | |
201 return -1; | |
202 } | |
203 | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
204 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
|
205 OrthancPluginSetDescription(context_, "Serve DICOM modality worklists from a folder with Orthanc."); |
1802 | 206 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
207 OrthancPlugins::OrthancConfiguration configuration(context_); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
208 |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
209 OrthancPlugins::OrthancConfiguration worklists; |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
210 configuration.GetSection(worklists, "Worklists"); |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
211 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
212 bool enabled = worklists.GetBooleanValue("Enable", false); |
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
213 if (enabled) |
1802 | 214 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
215 if (worklists.LookupStringValue(folder_, "Database")) |
1802 | 216 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
217 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
|
218 OrthancPluginRegisterWorklistCallback(context_, Callback); |
1802 | 219 } |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
220 else |
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
221 { |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
222 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
|
223 return -1; |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
224 } |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
225 |
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
226 filterIssuerAet_ = worklists.GetBooleanValue("FilterIssuerAet", false); |
1802 | 227 } |
228 else | |
229 { | |
2233
8f5b60647654
worklist sample: FilterIssuerAet configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2216
diff
changeset
|
230 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
|
231 } |
1802 | 232 |
233 return 0; | |
234 } | |
235 | |
236 | |
237 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
238 { | |
239 OrthancPluginLogWarning(context_, "Sample worklist plugin is finalizing"); | |
240 } | |
241 | |
242 | |
243 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
244 { | |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
245 return "worklists"; |
1802 | 246 } |
247 | |
248 | |
249 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
250 { | |
1808
9c2ffc4e938b
configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1802
diff
changeset
|
251 return MODALITY_WORKLISTS_VERSION; |
1802 | 252 } |
253 } |