annotate Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2127:bfa92c9328d7

cleaning up
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 07 Nov 2016 13:59:36 +0100
parents 7a05144cb919
children 395522e46b2b
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
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 {
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
127 namespace fs = boost::filesystem;
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
128
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 Json::Value json;
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 if (!GetQueryDicom(json, query))
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 return OrthancPluginErrorCode_InternalError;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
1890
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1814
diff changeset
136 {
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1814
diff changeset
137 std::string msg = ("Received worklist query from remote modality " +
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1814
diff changeset
138 std::string(remoteAet) + ":\n" + json.toStyledString());
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1814
diff changeset
139 OrthancPluginLogInfo(context_, msg.c_str());
74dc6b764ff0 Fix modality worklists lookups if tags with UN (unknown) VR are present
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1814
diff changeset
140 }
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
142 fs::path source(folder_);
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
143 fs::directory_iterator end;
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 try
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
147 for (fs::directory_iterator it(source); it != end; ++it)
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
149 fs::file_type type(it->status().type());
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
150
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
151 if (type == fs::regular_file ||
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
152 type == fs::reparse_file) // cf. BitBucket issue #11
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
154 std::string extension = fs::extension(it->path());
1814
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
155 ToLowerCase(extension);
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
156
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
157 if (extension == ".wl")
1802
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 OrthancPluginErrorCode error = MatchWorklist(answers, query, it->path().string());
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 if (error)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 OrthancPluginLogError(context_, "Error while adding an answer to a worklist request");
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 return error;
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 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
169 catch (fs::filesystem_error&)
1802
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 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
172 OrthancPluginLogError(context_, description.c_str());
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return OrthancPluginErrorCode_DirectoryExpected;
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 // 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
177 // OrthancPluginMarkWorklistAnswersIncomplete(context_, answers);
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 return OrthancPluginErrorCode_Success;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
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 extern "C"
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 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 context_ = c;
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
188 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
189 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
190
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 /* Check the version of the Orthanc core */
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 if (OrthancPluginCheckVersion(c) == 0)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 char info[1024];
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 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
196 context_->orthancVersion,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 OrthancPluginLogError(context_, info);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 return -1;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
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 Json::Value configuration;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (!ConvertToJson(configuration, OrthancPluginGetConfiguration(context_)))
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 OrthancPluginLogError(context_, "Cannot access the configuration of the worklist server");
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 return -1;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
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 bool enabled = false;
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
212
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
213 if (configuration.isMember("Worklists"))
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
215 const Json::Value& config = configuration["Worklists"];
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
216 if (!config.isMember("Enable") ||
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
217 config["Enable"].type() != Json::booleanValue)
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
219 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
220 return -1;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
222 else
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
223 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
224 enabled = config["Enable"].asBool();
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
225 if (enabled)
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
226 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
227 if (!config.isMember("Database") ||
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
228 config["Database"].type() != Json::stringValue)
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 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
231 return -1;
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
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
234 folder_ = config["Database"].asString();
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
235 }
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
236 else
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
237 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
238 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
239 }
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
240 }
1802
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 else
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 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
245 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
247 if (enabled)
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
248 {
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
249 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
250 OrthancPluginLogWarning(context_, message.c_str());
1802
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 OrthancPluginRegisterWorklistCallback(context_, Callback);
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
253 }
1802
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 return 0;
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
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 OrthancPluginLogWarning(context_, "Sample worklist plugin is finalizing");
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
267 return "worklists";
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
273 return MODALITY_WORKLISTS_VERSION;
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }