Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPluginDatabase.h @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | Plugins/Engine/OrthancPluginDatabase.h@94f4a18a79cc |
children | 05b8fd21089c |
comparison
equal
deleted
inserted
replaced
4043:6c6239aec462 | 4044:d25f4c0fa160 |
---|---|
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-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #if ORTHANC_ENABLE_PLUGINS == 1 | |
37 | |
38 #include "../../Core/SharedLibrary.h" | |
39 #include "../../OrthancServer/Database/Compatibility/ICreateInstance.h" | |
40 #include "../../OrthancServer/Database/Compatibility/IGetChildrenMetadata.h" | |
41 #include "../../OrthancServer/Database/Compatibility/ILookupResources.h" | |
42 #include "../../OrthancServer/Database/Compatibility/ILookupResourceAndParent.h" | |
43 #include "../../OrthancServer/Database/Compatibility/ISetResourcesContent.h" | |
44 #include "../Include/orthanc/OrthancCDatabasePlugin.h" | |
45 #include "PluginsErrorDictionary.h" | |
46 | |
47 namespace Orthanc | |
48 { | |
49 class OrthancPluginDatabase : | |
50 public IDatabaseWrapper, | |
51 public Compatibility::ICreateInstance, | |
52 public Compatibility::IGetChildrenMetadata, | |
53 public Compatibility::ILookupResources, | |
54 public Compatibility::ILookupResourceAndParent, | |
55 public Compatibility::ISetResourcesContent | |
56 { | |
57 private: | |
58 class Transaction; | |
59 | |
60 typedef std::pair<int64_t, ResourceType> AnswerResource; | |
61 typedef std::map<MetadataType, std::string> AnswerMetadata; | |
62 | |
63 SharedLibrary& library_; | |
64 PluginsErrorDictionary& errorDictionary_; | |
65 _OrthancPluginDatabaseAnswerType type_; | |
66 OrthancPluginDatabaseBackend backend_; | |
67 OrthancPluginDatabaseExtensions extensions_; | |
68 void* payload_; | |
69 IDatabaseListener* listener_; | |
70 | |
71 bool fastGetTotalSize_; | |
72 uint64_t currentDiskSize_; | |
73 | |
74 std::list<std::string> answerStrings_; | |
75 std::list<int32_t> answerInt32_; | |
76 std::list<int64_t> answerInt64_; | |
77 std::list<AnswerResource> answerResources_; | |
78 std::list<FileInfo> answerAttachments_; | |
79 | |
80 DicomMap* answerDicomMap_; | |
81 std::list<ServerIndexChange>* answerChanges_; | |
82 std::list<ExportedResource>* answerExportedResources_; | |
83 bool* answerDone_; | |
84 std::list<std::string>* answerMatchingResources_; | |
85 std::list<std::string>* answerMatchingInstances_; | |
86 AnswerMetadata* answerMetadata_; | |
87 | |
88 OrthancPluginDatabaseContext* GetContext() | |
89 { | |
90 return reinterpret_cast<OrthancPluginDatabaseContext*>(this); | |
91 } | |
92 | |
93 void CheckSuccess(OrthancPluginErrorCode code); | |
94 | |
95 void ResetAnswers(); | |
96 | |
97 void ForwardAnswers(std::list<int64_t>& target); | |
98 | |
99 void ForwardAnswers(std::list<std::string>& target); | |
100 | |
101 bool ForwardSingleAnswer(std::string& target); | |
102 | |
103 bool ForwardSingleAnswer(int64_t& target); | |
104 | |
105 public: | |
106 OrthancPluginDatabase(SharedLibrary& library, | |
107 PluginsErrorDictionary& errorDictionary, | |
108 const OrthancPluginDatabaseBackend& backend, | |
109 const OrthancPluginDatabaseExtensions* extensions, | |
110 size_t extensionsSize, | |
111 void *payload); | |
112 | |
113 virtual void Open() | |
114 ORTHANC_OVERRIDE; | |
115 | |
116 virtual void Close() | |
117 ORTHANC_OVERRIDE | |
118 { | |
119 CheckSuccess(backend_.close(payload_)); | |
120 } | |
121 | |
122 const SharedLibrary& GetSharedLibrary() const | |
123 { | |
124 return library_; | |
125 } | |
126 | |
127 virtual void AddAttachment(int64_t id, | |
128 const FileInfo& attachment) | |
129 ORTHANC_OVERRIDE; | |
130 | |
131 virtual void AttachChild(int64_t parent, | |
132 int64_t child) | |
133 ORTHANC_OVERRIDE; | |
134 | |
135 virtual void ClearChanges() | |
136 ORTHANC_OVERRIDE; | |
137 | |
138 virtual void ClearExportedResources() | |
139 ORTHANC_OVERRIDE; | |
140 | |
141 virtual int64_t CreateResource(const std::string& publicId, | |
142 ResourceType type) | |
143 ORTHANC_OVERRIDE; | |
144 | |
145 virtual void DeleteAttachment(int64_t id, | |
146 FileContentType attachment) | |
147 ORTHANC_OVERRIDE; | |
148 | |
149 virtual void DeleteMetadata(int64_t id, | |
150 MetadataType type) | |
151 ORTHANC_OVERRIDE; | |
152 | |
153 virtual void DeleteResource(int64_t id) | |
154 ORTHANC_OVERRIDE; | |
155 | |
156 virtual void FlushToDisk() | |
157 ORTHANC_OVERRIDE | |
158 { | |
159 } | |
160 | |
161 virtual bool HasFlushToDisk() const | |
162 ORTHANC_OVERRIDE | |
163 { | |
164 return false; | |
165 } | |
166 | |
167 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target, | |
168 int64_t id) | |
169 ORTHANC_OVERRIDE; | |
170 | |
171 virtual void GetAllPublicIds(std::list<std::string>& target, | |
172 ResourceType resourceType) | |
173 ORTHANC_OVERRIDE; | |
174 | |
175 virtual void GetAllPublicIds(std::list<std::string>& target, | |
176 ResourceType resourceType, | |
177 size_t since, | |
178 size_t limit) | |
179 ORTHANC_OVERRIDE; | |
180 | |
181 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, | |
182 bool& done /*out*/, | |
183 int64_t since, | |
184 uint32_t maxResults) | |
185 ORTHANC_OVERRIDE; | |
186 | |
187 virtual void GetChildrenInternalId(std::list<int64_t>& target, | |
188 int64_t id) | |
189 ORTHANC_OVERRIDE; | |
190 | |
191 virtual void GetChildrenPublicId(std::list<std::string>& target, | |
192 int64_t id) | |
193 ORTHANC_OVERRIDE; | |
194 | |
195 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, | |
196 bool& done /*out*/, | |
197 int64_t since, | |
198 uint32_t maxResults) | |
199 ORTHANC_OVERRIDE; | |
200 | |
201 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) | |
202 ORTHANC_OVERRIDE; | |
203 | |
204 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) | |
205 ORTHANC_OVERRIDE; | |
206 | |
207 virtual void GetMainDicomTags(DicomMap& map, | |
208 int64_t id) | |
209 ORTHANC_OVERRIDE; | |
210 | |
211 virtual std::string GetPublicId(int64_t resourceId) | |
212 ORTHANC_OVERRIDE; | |
213 | |
214 virtual uint64_t GetResourceCount(ResourceType resourceType) | |
215 ORTHANC_OVERRIDE; | |
216 | |
217 virtual ResourceType GetResourceType(int64_t resourceId) | |
218 ORTHANC_OVERRIDE; | |
219 | |
220 virtual uint64_t GetTotalCompressedSize() | |
221 ORTHANC_OVERRIDE; | |
222 | |
223 virtual uint64_t GetTotalUncompressedSize() | |
224 ORTHANC_OVERRIDE; | |
225 | |
226 virtual bool IsExistingResource(int64_t internalId) | |
227 ORTHANC_OVERRIDE; | |
228 | |
229 virtual bool IsProtectedPatient(int64_t internalId) | |
230 ORTHANC_OVERRIDE; | |
231 | |
232 virtual void ListAvailableAttachments(std::list<FileContentType>& target, | |
233 int64_t id) | |
234 ORTHANC_OVERRIDE; | |
235 | |
236 virtual void LogChange(int64_t internalId, | |
237 const ServerIndexChange& change) | |
238 ORTHANC_OVERRIDE; | |
239 | |
240 virtual void LogExportedResource(const ExportedResource& resource) | |
241 ORTHANC_OVERRIDE; | |
242 | |
243 virtual bool LookupAttachment(FileInfo& attachment, | |
244 int64_t id, | |
245 FileContentType contentType) | |
246 ORTHANC_OVERRIDE; | |
247 | |
248 virtual bool LookupGlobalProperty(std::string& target, | |
249 GlobalProperty property) | |
250 ORTHANC_OVERRIDE; | |
251 | |
252 virtual bool LookupMetadata(std::string& target, | |
253 int64_t id, | |
254 MetadataType type) | |
255 ORTHANC_OVERRIDE; | |
256 | |
257 virtual bool LookupParent(int64_t& parentId, | |
258 int64_t resourceId) | |
259 ORTHANC_OVERRIDE; | |
260 | |
261 virtual bool LookupResource(int64_t& id, | |
262 ResourceType& type, | |
263 const std::string& publicId) | |
264 ORTHANC_OVERRIDE; | |
265 | |
266 virtual bool SelectPatientToRecycle(int64_t& internalId) | |
267 ORTHANC_OVERRIDE; | |
268 | |
269 virtual bool SelectPatientToRecycle(int64_t& internalId, | |
270 int64_t patientIdToAvoid) | |
271 ORTHANC_OVERRIDE; | |
272 | |
273 virtual void SetGlobalProperty(GlobalProperty property, | |
274 const std::string& value) | |
275 ORTHANC_OVERRIDE; | |
276 | |
277 virtual void ClearMainDicomTags(int64_t id) | |
278 ORTHANC_OVERRIDE; | |
279 | |
280 virtual void SetMainDicomTag(int64_t id, | |
281 const DicomTag& tag, | |
282 const std::string& value) | |
283 ORTHANC_OVERRIDE; | |
284 | |
285 virtual void SetIdentifierTag(int64_t id, | |
286 const DicomTag& tag, | |
287 const std::string& value) | |
288 ORTHANC_OVERRIDE; | |
289 | |
290 virtual void SetMetadata(int64_t id, | |
291 MetadataType type, | |
292 const std::string& value) | |
293 ORTHANC_OVERRIDE; | |
294 | |
295 virtual void SetProtectedPatient(int64_t internalId, | |
296 bool isProtected) | |
297 ORTHANC_OVERRIDE; | |
298 | |
299 virtual IDatabaseWrapper::ITransaction* StartTransaction() | |
300 ORTHANC_OVERRIDE; | |
301 | |
302 virtual void SetListener(IDatabaseListener& listener) | |
303 ORTHANC_OVERRIDE | |
304 { | |
305 listener_ = &listener; | |
306 } | |
307 | |
308 virtual unsigned int GetDatabaseVersion() | |
309 ORTHANC_OVERRIDE; | |
310 | |
311 virtual void Upgrade(unsigned int targetVersion, | |
312 IStorageArea& storageArea) | |
313 ORTHANC_OVERRIDE; | |
314 | |
315 void AnswerReceived(const _OrthancPluginDatabaseAnswer& answer); | |
316 | |
317 virtual bool IsDiskSizeAbove(uint64_t threshold) | |
318 ORTHANC_OVERRIDE; | |
319 | |
320 virtual void ApplyLookupResources(std::list<std::string>& resourcesId, | |
321 std::list<std::string>* instancesId, | |
322 const std::vector<DatabaseConstraint>& lookup, | |
323 ResourceType queryLevel, | |
324 size_t limit) | |
325 ORTHANC_OVERRIDE; | |
326 | |
327 virtual bool CreateInstance(CreateInstanceResult& result, | |
328 int64_t& instanceId, | |
329 const std::string& patient, | |
330 const std::string& study, | |
331 const std::string& series, | |
332 const std::string& instance) | |
333 ORTHANC_OVERRIDE; | |
334 | |
335 // From the "ILookupResources" interface | |
336 virtual void GetAllInternalIds(std::list<int64_t>& target, | |
337 ResourceType resourceType) | |
338 ORTHANC_OVERRIDE; | |
339 | |
340 // From the "ILookupResources" interface | |
341 virtual void LookupIdentifier(std::list<int64_t>& result, | |
342 ResourceType level, | |
343 const DicomTag& tag, | |
344 Compatibility::IdentifierConstraintType type, | |
345 const std::string& value) | |
346 ORTHANC_OVERRIDE; | |
347 | |
348 // From the "ILookupResources" interface | |
349 virtual void LookupIdentifierRange(std::list<int64_t>& result, | |
350 ResourceType level, | |
351 const DicomTag& tag, | |
352 const std::string& start, | |
353 const std::string& end) | |
354 ORTHANC_OVERRIDE; | |
355 | |
356 virtual void SetResourcesContent(const Orthanc::ResourcesContent& content) | |
357 ORTHANC_OVERRIDE; | |
358 | |
359 virtual void GetChildrenMetadata(std::list<std::string>& target, | |
360 int64_t resourceId, | |
361 MetadataType metadata) | |
362 ORTHANC_OVERRIDE; | |
363 | |
364 virtual int64_t GetLastChangeIndex() ORTHANC_OVERRIDE; | |
365 | |
366 virtual void TagMostRecentPatient(int64_t patient) ORTHANC_OVERRIDE; | |
367 | |
368 virtual bool LookupResourceAndParent(int64_t& id, | |
369 ResourceType& type, | |
370 std::string& parentPublicId, | |
371 const std::string& publicId) | |
372 ORTHANC_OVERRIDE; | |
373 }; | |
374 } | |
375 | |
376 #endif |