annotate Plugins/Samples/ModalityWorklists/Plugin.cpp @ 2205:395522e46b2b

refactoring of the worklist sample using OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Dec 2016 16:16:25 +0100
parents 7a05144cb919
children 27106f7e3759
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
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
21 #include "../Common/OrthancPluginCppWrapper.h"
1802
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 /**
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 * 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
36 **/
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 static OrthancPluginErrorCode MatchWorklist(OrthancPluginWorklistAnswers* answers,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 const OrthancPluginWorklistQuery* query,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 const std::string& path)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
41 OrthancPlugins::MemoryBuffer dicom(context_);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
42 dicom.ReadFile(path);
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
44 if (OrthancPluginWorklistIsMatch(context_, query, dicom.GetData(), dicom.GetSize()))
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 // 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
47 return OrthancPluginWorklistAddAnswer
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
48 (context_, answers, query, dicom.GetData(), dicom.GetSize());
1802
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 else
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 DICOM file does not match
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 return OrthancPluginErrorCode_Success;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
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
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
59 static void GetQueryDicom(Json::Value& value,
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
60 const OrthancPluginWorklistQuery* query)
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
62 OrthancPlugins::MemoryBuffer dicom(context_);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
63 dicom.GetDicomQuery(query);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
64
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
65 OrthancPlugins::OrthancString str(context_);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
66 str.DicomToJson(dicom, OrthancPluginDicomToJsonFormat_Short,
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
67 static_cast<OrthancPluginDicomToJsonFlags>(0), 0);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
68
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
69 str.ToJson(value);
1802
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
1814
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
73 static void ToLowerCase(std::string& s)
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
74 {
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
75 std::transform(s.begin(), s.end(), s.begin(), tolower);
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
76 }
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
77
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
78
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 OrthancPluginErrorCode Callback(OrthancPluginWorklistAnswers* answers,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 const OrthancPluginWorklistQuery* query,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 const char* remoteAet,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 const char* calledAet)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 try
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
86 namespace fs = boost::filesystem;
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
87
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
89 Json::Value json;
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
90 GetQueryDicom(json, query);
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
91
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
92 std::string msg = ("Received worklist query from remote modality " +
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
93 std::string(remoteAet) + ":\n" + json.toStyledString());
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
94 OrthancPluginLogInfo(context_, msg.c_str());
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
95 }
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
96
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
97 fs::path source(folder_);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
98 fs::directory_iterator end;
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
99
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
100 try
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
101 {
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
102 for (fs::directory_iterator it(source); it != end; ++it)
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
104 fs::file_type type(it->status().type());
1814
7c5ea3e51839 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1813
diff changeset
105
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
106 if (type == fs::regular_file ||
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
107 type == fs::reparse_file) // cf. BitBucket issue #11
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
109 std::string extension = fs::extension(it->path());
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
110 ToLowerCase(extension);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
111
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
112 if (extension == ".wl")
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
114 OrthancPluginErrorCode error = MatchWorklist(answers, query, it->path().string());
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
115 if (error)
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
116 {
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
117 OrthancPluginLogError(context_, "Error while adding an answer to a worklist request");
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
118 return error;
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
119 }
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
124 catch (fs::filesystem_error&)
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
125 {
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
126 std::string description = std::string("Inexistent folder while scanning for worklists: ") + source.string();
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
127 OrthancPluginLogError(context_, description.c_str());
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
128 return OrthancPluginErrorCode_DirectoryExpected;
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
129 }
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
130
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
131 // 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
132 // OrthancPluginMarkWorklistAnswersIncomplete(context_, answers);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
133
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
134 return OrthancPluginErrorCode_Success;
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
136 catch (OrthancPlugins::PluginException& e)
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
138 return e.GetErrorCode();
1802
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 }
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 extern "C"
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 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 context_ = c;
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 /* Check the version of the Orthanc core */
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 if (OrthancPluginCheckVersion(c) == 0)
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 char info[1024];
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 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
154 context_->orthancVersion,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 OrthancPluginLogError(context_, info);
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 return -1;
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
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
162 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
163 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
164
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
165 OrthancPlugins::OrthancConfiguration configuration(context_);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
166
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
167 OrthancPlugins::OrthancConfiguration worklists;
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
168 configuration.GetSection(worklists, "Worklists");
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
169
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
170 bool enabled = worklists.GetBooleanValue("Enable", false);
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
171 if (enabled)
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
173 if (worklists.LookupStringValue(folder_, "Database"))
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
175 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
176 OrthancPluginRegisterWorklistCallback(context_, Callback);
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
178 else
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
179 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
180 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
181 return -1;
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
182 }
1802
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 else
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
2205
395522e46b2b refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
186 OrthancPlugins::LogWarning(context_, "Worklists 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
187 }
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 return 0;
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
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 OrthancPluginLogWarning(context_, "Sample worklist plugin is finalizing");
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
1808
9c2ffc4e938b configuration of the sample modality worklists plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1802
diff changeset
201 return "worklists";
1802
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
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
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 return MODALITY_WORKLISTS_VERSION;
1802
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
138664eb59de sample worklist plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }