Mercurial > hg > orthanc
annotate Plugins/Samples/DatabasePlugin/Database.h @ 2156:2fd8c1fa6076 Orthanc-1.1.0
version in doxygen
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 17 Nov 2016 09:30:22 +0100 |
parents | b1291df2f780 |
children | a3a65de1840f |
rev | line source |
---|---|
1671 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1671 | 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 | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
102 virtual void GetAllInternalIds(std::list<int64_t>& target, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
103 OrthancPluginResourceType resourceType) |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
104 { |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
105 base_.GetAllInternalIds(target, Orthanc::Plugins::Convert(resourceType)); |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
106 } |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
107 |
1671 | 108 virtual void GetAllPublicIds(std::list<std::string>& target, |
109 OrthancPluginResourceType resourceType) | |
110 { | |
111 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType)); | |
112 } | |
113 | |
114 virtual void GetAllPublicIds(std::list<std::string>& target, | |
115 OrthancPluginResourceType resourceType, | |
116 uint64_t since, | |
117 uint64_t limit) | |
118 { | |
119 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType), since, limit); | |
120 } | |
121 | |
122 virtual void GetChanges(bool& done /*out*/, | |
123 int64_t since, | |
124 uint32_t maxResults); | |
125 | |
126 virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/, | |
127 int64_t id) | |
128 { | |
129 base_.GetChildrenInternalId(target, id); | |
130 } | |
131 | |
132 virtual void GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
133 int64_t id) | |
134 { | |
135 base_.GetChildrenPublicId(target, id); | |
136 } | |
137 | |
138 virtual void GetExportedResources(bool& done /*out*/, | |
139 int64_t since, | |
140 uint32_t maxResults); | |
141 | |
142 virtual void GetLastChange(); | |
143 | |
144 virtual void GetLastExportedResource(); | |
145 | |
146 virtual void GetMainDicomTags(int64_t id); | |
147 | |
148 virtual std::string GetPublicId(int64_t resourceId); | |
149 | |
150 virtual uint64_t GetResourceCount(OrthancPluginResourceType resourceType) | |
151 { | |
152 return base_.GetResourceCount(Orthanc::Plugins::Convert(resourceType)); | |
153 } | |
154 | |
155 virtual OrthancPluginResourceType GetResourceType(int64_t resourceId); | |
156 | |
157 virtual uint64_t GetTotalCompressedSize() | |
158 { | |
159 return base_.GetTotalCompressedSize(); | |
160 } | |
161 | |
162 virtual uint64_t GetTotalUncompressedSize() | |
163 { | |
164 return base_.GetTotalUncompressedSize(); | |
165 } | |
166 | |
167 virtual bool IsExistingResource(int64_t internalId) | |
168 { | |
169 return base_.IsExistingResource(internalId); | |
170 } | |
171 | |
172 virtual bool IsProtectedPatient(int64_t internalId) | |
173 { | |
174 return base_.IsProtectedPatient(internalId); | |
175 } | |
176 | |
177 virtual void ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
178 int64_t id); | |
179 | |
180 virtual void ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
181 int64_t id); | |
182 | |
183 virtual void LogChange(const OrthancPluginChange& change); | |
184 | |
185 virtual void LogExportedResource(const OrthancPluginExportedResource& resource); | |
186 | |
187 virtual bool LookupAttachment(int64_t id, | |
188 int32_t contentType); | |
189 | |
190 virtual bool LookupGlobalProperty(std::string& target /*out*/, | |
191 int32_t property) | |
192 { | |
193 return base_.LookupGlobalProperty(target, static_cast<Orthanc::GlobalProperty>(property)); | |
194 } | |
195 | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
196 virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
197 OrthancPluginResourceType level, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
198 uint16_t group, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
199 uint16_t element, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
200 OrthancPluginIdentifierConstraint constraint, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
201 const char* value) |
1671 | 202 { |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
203 base_.LookupIdentifier(target, Orthanc::Plugins::Convert(level), |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
204 Orthanc::DicomTag(group, element), |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
205 Orthanc::Plugins::Convert(constraint), value); |
1671 | 206 } |
207 | |
208 virtual bool LookupMetadata(std::string& target /*out*/, | |
209 int64_t id, | |
210 int32_t metadataType) | |
211 { | |
212 return base_.LookupMetadata(target, id, static_cast<Orthanc::MetadataType>(metadataType)); | |
213 } | |
214 | |
215 virtual bool LookupParent(int64_t& parentId /*out*/, | |
216 int64_t resourceId); | |
217 | |
218 virtual bool LookupResource(int64_t& id /*out*/, | |
219 OrthancPluginResourceType& type /*out*/, | |
220 const char* publicId); | |
221 | |
222 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/) | |
223 { | |
224 return base_.SelectPatientToRecycle(internalId); | |
225 } | |
226 | |
227 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/, | |
228 int64_t patientIdToAvoid) | |
229 { | |
230 return base_.SelectPatientToRecycle(internalId, patientIdToAvoid); | |
231 } | |
232 | |
233 | |
234 virtual void SetGlobalProperty(int32_t property, | |
235 const char* value) | |
236 { | |
237 base_.SetGlobalProperty(static_cast<Orthanc::GlobalProperty>(property), value); | |
238 } | |
239 | |
240 virtual void SetMainDicomTag(int64_t id, | |
241 uint16_t group, | |
242 uint16_t element, | |
243 const char* value) | |
244 { | |
245 base_.SetMainDicomTag(id, Orthanc::DicomTag(group, element), value); | |
246 } | |
247 | |
248 virtual void SetIdentifierTag(int64_t id, | |
249 uint16_t group, | |
250 uint16_t element, | |
251 const char* value) | |
252 { | |
1714 | 253 base_.SetIdentifierTag(id, Orthanc::DicomTag(group, element), value); |
1671 | 254 } |
255 | |
256 virtual void SetMetadata(int64_t id, | |
257 int32_t metadataType, | |
258 const char* value) | |
259 { | |
260 base_.SetMetadata(id, static_cast<Orthanc::MetadataType>(metadataType), value); | |
261 } | |
262 | |
263 virtual void SetProtectedPatient(int64_t internalId, | |
264 bool isProtected) | |
265 { | |
266 base_.SetProtectedPatient(internalId, isProtected); | |
267 } | |
268 | |
269 virtual void StartTransaction(); | |
270 | |
271 virtual void RollbackTransaction(); | |
272 | |
273 virtual void CommitTransaction(); | |
274 | |
275 virtual uint32_t GetDatabaseVersion(); | |
276 | |
277 virtual void UpgradeDatabase(uint32_t targetVersion, | |
278 OrthancPluginStorageArea* storageArea); | |
279 | |
280 virtual void ClearMainDicomTags(int64_t internalId) | |
281 { | |
282 base_.ClearMainDicomTags(internalId); | |
283 } | |
284 }; |