Mercurial > hg > orthanc
comparison Plugins/Samples/DatabasePlugin/Database.h @ 1671:2f2e2ec17bc4 db-changes
sample database plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 01 Oct 2015 17:44:43 +0200 |
parents | |
children | 81d718bba599 |
comparison
equal
deleted
inserted
replaced
1670:16955f8fec4d | 1671:2f2e2ec17bc4 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #pragma once | |
34 | |
35 #include <orthanc/OrthancCppDatabasePlugin.h> | |
36 | |
37 #include "../../../Core/SQLite/Connection.h" | |
38 #include "../../../Core/SQLite/Transaction.h" | |
39 #include "../../../OrthancServer/DatabaseWrapperBase.h" | |
40 #include "../../Engine/PluginsEnumerations.h" | |
41 | |
42 #include <memory> | |
43 | |
44 class Database : public OrthancPlugins::IDatabaseBackend | |
45 { | |
46 private: | |
47 class SignalRemainingAncestor; | |
48 | |
49 std::string path_; | |
50 Orthanc::SQLite::Connection db_; | |
51 Orthanc::DatabaseWrapperBase base_; | |
52 SignalRemainingAncestor* signalRemainingAncestor_; | |
53 | |
54 std::auto_ptr<Orthanc::SQLite::Transaction> transaction_; | |
55 | |
56 public: | |
57 Database(const std::string& path); | |
58 | |
59 virtual void Open(); | |
60 | |
61 virtual void Close(); | |
62 | |
63 virtual void AddAttachment(int64_t id, | |
64 const OrthancPluginAttachment& attachment); | |
65 | |
66 virtual void AttachChild(int64_t parent, | |
67 int64_t child) | |
68 { | |
69 base_.AttachChild(parent, child); | |
70 } | |
71 | |
72 virtual void ClearChanges() | |
73 { | |
74 db_.Execute("DELETE FROM Changes"); | |
75 } | |
76 | |
77 virtual void ClearExportedResources() | |
78 { | |
79 db_.Execute("DELETE FROM ExportedResources"); | |
80 } | |
81 | |
82 virtual int64_t CreateResource(const char* publicId, | |
83 OrthancPluginResourceType type) | |
84 { | |
85 return base_.CreateResource(publicId, Orthanc::Plugins::Convert(type)); | |
86 } | |
87 | |
88 virtual void DeleteAttachment(int64_t id, | |
89 int32_t attachment) | |
90 { | |
91 base_.DeleteAttachment(id, static_cast<Orthanc::FileContentType>(attachment)); | |
92 } | |
93 | |
94 virtual void DeleteMetadata(int64_t id, | |
95 int32_t metadataType) | |
96 { | |
97 base_.DeleteMetadata(id, static_cast<Orthanc::MetadataType>(metadataType)); | |
98 } | |
99 | |
100 virtual void DeleteResource(int64_t id); | |
101 | |
102 virtual void GetAllPublicIds(std::list<std::string>& target, | |
103 OrthancPluginResourceType resourceType) | |
104 { | |
105 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType)); | |
106 } | |
107 | |
108 virtual void GetAllPublicIds(std::list<std::string>& target, | |
109 OrthancPluginResourceType resourceType, | |
110 uint64_t since, | |
111 uint64_t limit) | |
112 { | |
113 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType), since, limit); | |
114 } | |
115 | |
116 virtual void GetChanges(bool& done /*out*/, | |
117 int64_t since, | |
118 uint32_t maxResults); | |
119 | |
120 virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/, | |
121 int64_t id) | |
122 { | |
123 base_.GetChildrenInternalId(target, id); | |
124 } | |
125 | |
126 virtual void GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
127 int64_t id) | |
128 { | |
129 base_.GetChildrenPublicId(target, id); | |
130 } | |
131 | |
132 virtual void GetExportedResources(bool& done /*out*/, | |
133 int64_t since, | |
134 uint32_t maxResults); | |
135 | |
136 virtual void GetLastChange(); | |
137 | |
138 virtual void GetLastExportedResource(); | |
139 | |
140 virtual void GetMainDicomTags(int64_t id); | |
141 | |
142 virtual std::string GetPublicId(int64_t resourceId); | |
143 | |
144 virtual uint64_t GetResourceCount(OrthancPluginResourceType resourceType) | |
145 { | |
146 return base_.GetResourceCount(Orthanc::Plugins::Convert(resourceType)); | |
147 } | |
148 | |
149 virtual OrthancPluginResourceType GetResourceType(int64_t resourceId); | |
150 | |
151 virtual uint64_t GetTotalCompressedSize() | |
152 { | |
153 return base_.GetTotalCompressedSize(); | |
154 } | |
155 | |
156 virtual uint64_t GetTotalUncompressedSize() | |
157 { | |
158 return base_.GetTotalUncompressedSize(); | |
159 } | |
160 | |
161 virtual bool IsExistingResource(int64_t internalId) | |
162 { | |
163 return base_.IsExistingResource(internalId); | |
164 } | |
165 | |
166 virtual bool IsProtectedPatient(int64_t internalId) | |
167 { | |
168 return base_.IsProtectedPatient(internalId); | |
169 } | |
170 | |
171 virtual void ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
172 int64_t id); | |
173 | |
174 virtual void ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
175 int64_t id); | |
176 | |
177 virtual void LogChange(const OrthancPluginChange& change); | |
178 | |
179 virtual void LogExportedResource(const OrthancPluginExportedResource& resource); | |
180 | |
181 virtual bool LookupAttachment(int64_t id, | |
182 int32_t contentType); | |
183 | |
184 virtual bool LookupGlobalProperty(std::string& target /*out*/, | |
185 int32_t property) | |
186 { | |
187 return base_.LookupGlobalProperty(target, static_cast<Orthanc::GlobalProperty>(property)); | |
188 } | |
189 | |
190 virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, | |
191 uint16_t group, | |
192 uint16_t element, | |
193 const char* value) | |
194 { | |
195 base_.LookupIdentifier(target, Orthanc::DicomTag(group, element), value); | |
196 } | |
197 | |
198 virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, | |
199 const char* value) | |
200 { | |
201 base_.LookupIdentifier(target, value); | |
202 } | |
203 | |
204 virtual bool LookupMetadata(std::string& target /*out*/, | |
205 int64_t id, | |
206 int32_t metadataType) | |
207 { | |
208 return base_.LookupMetadata(target, id, static_cast<Orthanc::MetadataType>(metadataType)); | |
209 } | |
210 | |
211 virtual bool LookupParent(int64_t& parentId /*out*/, | |
212 int64_t resourceId); | |
213 | |
214 virtual bool LookupResource(int64_t& id /*out*/, | |
215 OrthancPluginResourceType& type /*out*/, | |
216 const char* publicId); | |
217 | |
218 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/) | |
219 { | |
220 return base_.SelectPatientToRecycle(internalId); | |
221 } | |
222 | |
223 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/, | |
224 int64_t patientIdToAvoid) | |
225 { | |
226 return base_.SelectPatientToRecycle(internalId, patientIdToAvoid); | |
227 } | |
228 | |
229 | |
230 virtual void SetGlobalProperty(int32_t property, | |
231 const char* value) | |
232 { | |
233 base_.SetGlobalProperty(static_cast<Orthanc::GlobalProperty>(property), value); | |
234 } | |
235 | |
236 virtual void SetMainDicomTag(int64_t id, | |
237 uint16_t group, | |
238 uint16_t element, | |
239 const char* value) | |
240 { | |
241 base_.SetMainDicomTag(id, Orthanc::DicomTag(group, element), value); | |
242 } | |
243 | |
244 virtual void SetIdentifierTag(int64_t id, | |
245 uint16_t group, | |
246 uint16_t element, | |
247 const char* value) | |
248 { | |
249 base_.SetMainDicomTag(id, Orthanc::DicomTag(group, element), value); | |
250 } | |
251 | |
252 virtual void SetMetadata(int64_t id, | |
253 int32_t metadataType, | |
254 const char* value) | |
255 { | |
256 base_.SetMetadata(id, static_cast<Orthanc::MetadataType>(metadataType), value); | |
257 } | |
258 | |
259 virtual void SetProtectedPatient(int64_t internalId, | |
260 bool isProtected) | |
261 { | |
262 base_.SetProtectedPatient(internalId, isProtected); | |
263 } | |
264 | |
265 virtual void StartTransaction(); | |
266 | |
267 virtual void RollbackTransaction(); | |
268 | |
269 virtual void CommitTransaction(); | |
270 | |
271 virtual uint32_t GetDatabaseVersion(); | |
272 | |
273 virtual void UpgradeDatabase(uint32_t targetVersion, | |
274 OrthancPluginStorageArea* storageArea); | |
275 | |
276 virtual void ClearMainDicomTags(int64_t internalId) | |
277 { | |
278 base_.ClearMainDicomTags(internalId); | |
279 } | |
280 }; |