Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Samples/Sanitizer/Plugin.cpp @ 4845:02d77189d8ba received-instance-callback
added ReceivedInstanceCallback + sample C++ plugin
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 09 Dec 2021 17:22:40 +0100 |
parents | |
children | 4addabcab158 |
comparison
equal
deleted
inserted
replaced
4844:55e8fb8e8028 | 4845:02d77189d8ba |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium | |
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
7 * | |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "../../../../OrthancFramework/Sources/Compatibility.h" | |
24 #include "../Common/OrthancPluginCppWrapper.h" | |
25 | |
26 #include <boost/filesystem.hpp> | |
27 #include <json/value.h> | |
28 #include <string.h> | |
29 #include <iostream> | |
30 | |
31 | |
32 | |
33 | |
34 OrthancPluginReceivedInstanceCallbackResult ReceivedInstanceCallback(const void* receivedDicomBuffer, | |
35 uint64_t receivedDicomBufferSize, | |
36 void** modifiedDicomBuffer, | |
37 uint64_t* modifiedDicomBufferSize) | |
38 // OrthancPluginMemoryBuffer* modifiedDicomBuffer) | |
39 { | |
40 // note: this sample plugin won't work with multi-frame images or badly formed images | |
41 // OrthancPluginCreateDicom and OrthancPluginDicomBufferToJson do not support multi-frame and are quite touchy with invalid tag values | |
42 | |
43 Json::Value receivedDicomAsJson; | |
44 OrthancPlugins::OrthancString str; | |
45 str.Assign(OrthancPluginDicomBufferToJson | |
46 (OrthancPlugins::GetGlobalContext(), | |
47 receivedDicomBuffer, | |
48 receivedDicomBufferSize, | |
49 OrthancPluginDicomToJsonFormat_Short, | |
50 static_cast<OrthancPluginDicomToJsonFlags>(OrthancPluginDicomToJsonFlags_IncludeBinary | OrthancPluginDicomToJsonFlags_IncludePrivateTags | OrthancPluginDicomToJsonFlags_IncludeUnknownTags | OrthancPluginDicomToJsonFlags_SkipGroupLengths | OrthancPluginDicomToJsonFlags_IncludePixelData), | |
51 0)); | |
52 | |
53 str.ToJson(receivedDicomAsJson); | |
54 | |
55 if (receivedDicomAsJson["0008,0080"] != "My Institution") | |
56 { | |
57 receivedDicomAsJson["0008,0080"] = "My Institution"; | |
58 | |
59 OrthancPluginMemoryBuffer modifiedDicom; | |
60 std::string serializedModifiedDicomAsJson; | |
61 OrthancPlugins::WriteFastJson(serializedModifiedDicomAsJson, receivedDicomAsJson); | |
62 OrthancPluginErrorCode createResult = OrthancPluginCreateDicom(OrthancPlugins::GetGlobalContext(), | |
63 &modifiedDicom, | |
64 serializedModifiedDicomAsJson.c_str(), | |
65 NULL, | |
66 OrthancPluginCreateDicomFlags_DecodeDataUriScheme); | |
67 | |
68 if (createResult == OrthancPluginErrorCode_Success) | |
69 { | |
70 *modifiedDicomBuffer = modifiedDicom.data; | |
71 *modifiedDicomBufferSize = modifiedDicom.size; | |
72 | |
73 return OrthancPluginReceivedInstanceCallbackResult_Modified; | |
74 } | |
75 else | |
76 { | |
77 return OrthancPluginReceivedInstanceCallbackResult_KeepAsIs; | |
78 } | |
79 } | |
80 | |
81 return OrthancPluginReceivedInstanceCallbackResult_KeepAsIs; | |
82 } | |
83 | |
84 | |
85 extern "C" | |
86 { | |
87 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | |
88 { | |
89 OrthancPlugins::SetGlobalContext(c); | |
90 | |
91 /* Check the version of the Orthanc core */ | |
92 // if (OrthancPluginCheckVersion(c) == 0) | |
93 // { | |
94 // OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
95 // ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
96 // ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
97 // return -1; | |
98 // } | |
99 | |
100 OrthancPlugins::LogWarning("Sanitizer plugin is initializing"); | |
101 OrthancPluginSetDescription(c, "Sample plugin to sanitize incoming DICOM instances."); | |
102 | |
103 OrthancPluginRegisterReceivedInstanceCallback(c, ReceivedInstanceCallback); | |
104 | |
105 return 0; | |
106 } | |
107 | |
108 | |
109 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
110 { | |
111 OrthancPlugins::LogWarning("Sanitizer plugin is finalizing"); | |
112 } | |
113 | |
114 | |
115 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
116 { | |
117 return "sanitizer"; | |
118 } | |
119 | |
120 | |
121 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
122 { | |
123 return "0.1"; | |
124 } | |
125 } |