annotate Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2771:87a3a8c04d8a worklists

close old branch
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Jul 2018 09:45:17 +0200
parents 7c5ea3e51839
children 74dc6b764ff0
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * 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
8 * published by the Free Software Foundation, either version 3 of the
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * 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
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * General Public License for more details.
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 *
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * 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
18 **/
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 #include <orthanc/OrthancCPlugin.h>
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include <boost/filesystem.hpp>
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <json/value.h>
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <json/reader.h>
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <string.h>
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <iostream>
1814
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
28 #include <algorithm>
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 static OrthancPluginContext* context_ = NULL;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 static std::string folder_;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 static bool ReadFile(std::string& result,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 const std::string& path)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 OrthancPluginMemoryBuffer tmp;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 if (OrthancPluginReadFile(context_, &tmp, path.c_str()))
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 return false;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 else
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 result.assign(reinterpret_cast<const char*>(tmp.data), tmp.size);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 OrthancPluginFreeMemoryBuffer(context_, &tmp);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 return true;
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 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 /**
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 * 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
53 **/
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 static OrthancPluginErrorCode MatchWorklist(OrthancPluginWorklistAnswers* answers,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const OrthancPluginWorklistQuery* query,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const std::string& path)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 std::string dicom;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if (!ReadFile(dicom, path))
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 // Cannot read this file, ignore this error
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return OrthancPluginErrorCode_Success;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
1810
796d0b087fb8 more consistent naming in worklist primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1808
diff changeset
65 if (OrthancPluginWorklistIsMatch(context_, query, dicom.c_str(), dicom.size()))
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 // This DICOM file matches the worklist query, add it to the answers
1810
796d0b087fb8 more consistent naming in worklist primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1808
diff changeset
68 return OrthancPluginWorklistAddAnswer
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 (context_, answers, query, dicom.c_str(), dicom.size());
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 else
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 // This DICOM file does not match
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 return OrthancPluginErrorCode_Success;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 static bool ConvertToJson(Json::Value& result,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 char* content)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (content == NULL)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 return false;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 else
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 Json::Reader reader;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 bool success = reader.parse(content, content + strlen(content), result);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 OrthancPluginFreeString(context_, content);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 return success;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 static bool GetQueryDicom(Json::Value& value,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 const OrthancPluginWorklistQuery* query)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 OrthancPluginMemoryBuffer dicom;
1810
796d0b087fb8 more consistent naming in worklist primitives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1808
diff changeset
101 if (OrthancPluginWorklistGetDicomQuery(context_, &dicom, query))
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 return false;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 char* json = OrthancPluginDicomBufferToJson(context_, reinterpret_cast<const char*>(dicom.data),
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 dicom.size,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 OrthancPluginDicomToJsonFormat_Short,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 static_cast<OrthancPluginDicomToJsonFlags>(0), 0);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 OrthancPluginFreeMemoryBuffer(context_, &dicom);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 return ConvertToJson(value, json);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
1814
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
116 static void ToLowerCase(std::string& s)
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
117 {
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
118 std::transform(s.begin(), s.end(), s.begin(), tolower);
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
119 }
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
120
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
121
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 const OrthancPluginWorklistQuery* query,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 const char* remoteAet,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 const char* calledAet)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 Json::Value json;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (!GetQueryDicom(json, query))
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 return OrthancPluginErrorCode_InternalError;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 std::cout << "Received worklist query from remote modality " << remoteAet
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 << ":" << std::endl << json.toStyledString();
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 boost::filesystem::path source(folder_);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 boost::filesystem::directory_iterator end;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 try
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 for (boost::filesystem::directory_iterator it(source); it != end; ++it)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 if (is_regular_file(it->status()))
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 std::string extension = boost::filesystem::extension(it->path());
1814
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
147 ToLowerCase(extension);
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
148
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
149 if (extension == ".wl")
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 OrthancPluginErrorCode error = MatchWorklist(answers, query, it->path().string());
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 if (error)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 OrthancPluginLogError(context_, "Error while adding an answer to a worklist request");
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 return error;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 catch (boost::filesystem::filesystem_error&)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 std::string description = std::string("Inexistent folder while scanning for worklists: ") + source.string();
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 OrthancPluginLogError(context_, description.c_str());
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 return OrthancPluginErrorCode_DirectoryExpected;
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 // Uncomment the following line if too many answers are to be returned
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 // OrthancPluginMarkWorklistAnswersIncomplete(context_, answers);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 return OrthancPluginErrorCode_Success;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 extern "C"
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 context_ = c;
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
180 OrthancPluginLogWarning(context_, "Sample worklist plugin is initializing");
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
181 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
182
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 /* Check the version of the Orthanc core */
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 if (OrthancPluginCheckVersion(c) == 0)
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 char info[1024];
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 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
188 context_->orthancVersion,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 OrthancPluginLogError(context_, info);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 return -1;
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 Json::Value configuration;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 if (!ConvertToJson(configuration, OrthancPluginGetConfiguration(context_)))
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
199 OrthancPluginLogError(context_, "Cannot access the configuration of the worklist server");
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 return -1;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
203 bool enabled = false;
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
204
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
205 if (configuration.isMember("Worklists"))
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
207 const Json::Value& config = configuration["Worklists"];
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
208 if (!config.isMember("Enable") ||
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
209 config["Enable"].type() != Json::booleanValue)
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
211 OrthancPluginLogError(context_, "The configuration option \"Worklists.Enable\" must contain a Boolean");
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 return -1;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
214 else
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
215 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
216 enabled = config["Enable"].asBool();
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
217 if (enabled)
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
218 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
219 if (!config.isMember("Database") ||
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
220 config["Database"].type() != Json::stringValue)
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
221 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
222 OrthancPluginLogError(context_, "The configuration option \"Worklists.Database\" must contain a path");
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
223 return -1;
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
224 }
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
226 folder_ = config["Database"].asString();
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
227 }
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
228 else
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
229 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
230 OrthancPluginLogWarning(context_, "Worklists server is disabled by the configuration file");
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
231 }
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 else
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
236 OrthancPluginLogWarning(context_, "Worklists server is disabled, no suitable configuration section was provided");
1802
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
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
239 if (enabled)
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
240 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
241 std::string message = "The database of worklists will be read from folder: " + folder_;
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
242 OrthancPluginLogWarning(context_, message.c_str());
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
244 OrthancPluginRegisterWorklistCallback(context_, Callback);
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
245 }
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 return 0;
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 OrthancPluginLogWarning(context_, "Sample worklist plugin is finalizing");
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
259 return "worklists";
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
265 return MODALITY_WORKLISTS_VERSION;
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }