annotate Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2244:a3a65de1840f

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