Mercurial > hg > orthanc
annotate OrthancServer/Resources/Graveyard/DatabasePluginSample/Database.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 | Resources/Graveyard/DatabasePluginSample/Database.h@94f4a18a79cc |
children | cd363608551a |
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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1671 | 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 #include <orthanc/OrthancCppDatabasePlugin.h> | |
37 | |
38 #include "../../../Core/SQLite/Connection.h" | |
39 #include "../../../Core/SQLite/Transaction.h" | |
40 #include "../../../OrthancServer/DatabaseWrapperBase.h" | |
41 #include "../../Engine/PluginsEnumerations.h" | |
42 | |
43 #include <memory> | |
44 | |
45 class Database : public OrthancPlugins::IDatabaseBackend | |
46 { | |
47 private: | |
48 class SignalRemainingAncestor; | |
49 | |
50 std::string path_; | |
51 Orthanc::SQLite::Connection db_; | |
52 Orthanc::DatabaseWrapperBase base_; | |
53 SignalRemainingAncestor* signalRemainingAncestor_; | |
54 | |
55 std::auto_ptr<Orthanc::SQLite::Transaction> transaction_; | |
56 | |
57 public: | |
58 Database(const std::string& path); | |
59 | |
60 virtual void Open(); | |
61 | |
62 virtual void Close(); | |
63 | |
64 virtual void AddAttachment(int64_t id, | |
65 const OrthancPluginAttachment& attachment); | |
66 | |
67 virtual void AttachChild(int64_t parent, | |
68 int64_t child) | |
69 { | |
70 base_.AttachChild(parent, child); | |
71 } | |
72 | |
73 virtual void ClearChanges() | |
74 { | |
75 db_.Execute("DELETE FROM Changes"); | |
76 } | |
77 | |
78 virtual void ClearExportedResources() | |
79 { | |
80 db_.Execute("DELETE FROM ExportedResources"); | |
81 } | |
82 | |
83 virtual int64_t CreateResource(const char* publicId, | |
84 OrthancPluginResourceType type) | |
85 { | |
86 return base_.CreateResource(publicId, Orthanc::Plugins::Convert(type)); | |
87 } | |
88 | |
89 virtual void DeleteAttachment(int64_t id, | |
90 int32_t attachment) | |
91 { | |
92 base_.DeleteAttachment(id, static_cast<Orthanc::FileContentType>(attachment)); | |
93 } | |
94 | |
95 virtual void DeleteMetadata(int64_t id, | |
96 int32_t metadataType) | |
97 { | |
98 base_.DeleteMetadata(id, static_cast<Orthanc::MetadataType>(metadataType)); | |
99 } | |
100 | |
101 virtual void DeleteResource(int64_t id); | |
102 | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
103 virtual void GetAllInternalIds(std::list<int64_t>& target, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
104 OrthancPluginResourceType resourceType) |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
105 { |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
106 base_.GetAllInternalIds(target, Orthanc::Plugins::Convert(resourceType)); |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
107 } |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
108 |
1671 | 109 virtual void GetAllPublicIds(std::list<std::string>& target, |
110 OrthancPluginResourceType resourceType) | |
111 { | |
112 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType)); | |
113 } | |
114 | |
115 virtual void GetAllPublicIds(std::list<std::string>& target, | |
116 OrthancPluginResourceType resourceType, | |
117 uint64_t since, | |
118 uint64_t limit) | |
119 { | |
120 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType), since, limit); | |
121 } | |
122 | |
123 virtual void GetChanges(bool& done /*out*/, | |
124 int64_t since, | |
125 uint32_t maxResults); | |
126 | |
127 virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/, | |
128 int64_t id) | |
129 { | |
130 base_.GetChildrenInternalId(target, id); | |
131 } | |
132 | |
133 virtual void GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
134 int64_t id) | |
135 { | |
136 base_.GetChildrenPublicId(target, id); | |
137 } | |
138 | |
139 virtual void GetExportedResources(bool& done /*out*/, | |
140 int64_t since, | |
141 uint32_t maxResults); | |
142 | |
143 virtual void GetLastChange(); | |
144 | |
145 virtual void GetLastExportedResource(); | |
146 | |
147 virtual void GetMainDicomTags(int64_t id); | |
148 | |
149 virtual std::string GetPublicId(int64_t resourceId); | |
150 | |
151 virtual uint64_t GetResourceCount(OrthancPluginResourceType resourceType) | |
152 { | |
153 return base_.GetResourceCount(Orthanc::Plugins::Convert(resourceType)); | |
154 } | |
155 | |
156 virtual OrthancPluginResourceType GetResourceType(int64_t resourceId); | |
157 | |
158 virtual uint64_t GetTotalCompressedSize() | |
159 { | |
160 return base_.GetTotalCompressedSize(); | |
161 } | |
162 | |
163 virtual uint64_t GetTotalUncompressedSize() | |
164 { | |
165 return base_.GetTotalUncompressedSize(); | |
166 } | |
167 | |
168 virtual bool IsExistingResource(int64_t internalId) | |
169 { | |
170 return base_.IsExistingResource(internalId); | |
171 } | |
172 | |
173 virtual bool IsProtectedPatient(int64_t internalId) | |
174 { | |
175 return base_.IsProtectedPatient(internalId); | |
176 } | |
177 | |
178 virtual void ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
179 int64_t id); | |
180 | |
181 virtual void ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
182 int64_t id); | |
183 | |
184 virtual void LogChange(const OrthancPluginChange& change); | |
185 | |
186 virtual void LogExportedResource(const OrthancPluginExportedResource& resource); | |
187 | |
188 virtual bool LookupAttachment(int64_t id, | |
189 int32_t contentType); | |
190 | |
191 virtual bool LookupGlobalProperty(std::string& target /*out*/, | |
192 int32_t property) | |
193 { | |
194 return base_.LookupGlobalProperty(target, static_cast<Orthanc::GlobalProperty>(property)); | |
195 } | |
196 | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
197 virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
198 OrthancPluginResourceType level, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
199 uint16_t group, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
200 uint16_t element, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
201 OrthancPluginIdentifierConstraint constraint, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
202 const char* value) |
1671 | 203 { |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
204 base_.LookupIdentifier(target, Orthanc::Plugins::Convert(level), |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
205 Orthanc::DicomTag(group, element), |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
206 Orthanc::Plugins::Convert(constraint), value); |
1671 | 207 } |
208 | |
209 virtual bool LookupMetadata(std::string& target /*out*/, | |
210 int64_t id, | |
211 int32_t metadataType) | |
212 { | |
213 return base_.LookupMetadata(target, id, static_cast<Orthanc::MetadataType>(metadataType)); | |
214 } | |
215 | |
216 virtual bool LookupParent(int64_t& parentId /*out*/, | |
217 int64_t resourceId); | |
218 | |
219 virtual bool LookupResource(int64_t& id /*out*/, | |
220 OrthancPluginResourceType& type /*out*/, | |
221 const char* publicId); | |
222 | |
223 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/) | |
224 { | |
225 return base_.SelectPatientToRecycle(internalId); | |
226 } | |
227 | |
228 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/, | |
229 int64_t patientIdToAvoid) | |
230 { | |
231 return base_.SelectPatientToRecycle(internalId, patientIdToAvoid); | |
232 } | |
233 | |
234 | |
235 virtual void SetGlobalProperty(int32_t property, | |
236 const char* value) | |
237 { | |
238 base_.SetGlobalProperty(static_cast<Orthanc::GlobalProperty>(property), value); | |
239 } | |
240 | |
241 virtual void SetMainDicomTag(int64_t id, | |
242 uint16_t group, | |
243 uint16_t element, | |
244 const char* value) | |
245 { | |
246 base_.SetMainDicomTag(id, Orthanc::DicomTag(group, element), value); | |
247 } | |
248 | |
249 virtual void SetIdentifierTag(int64_t id, | |
250 uint16_t group, | |
251 uint16_t element, | |
252 const char* value) | |
253 { | |
1714 | 254 base_.SetIdentifierTag(id, Orthanc::DicomTag(group, element), value); |
1671 | 255 } |
256 | |
257 virtual void SetMetadata(int64_t id, | |
258 int32_t metadataType, | |
259 const char* value) | |
260 { | |
261 base_.SetMetadata(id, static_cast<Orthanc::MetadataType>(metadataType), value); | |
262 } | |
263 | |
264 virtual void SetProtectedPatient(int64_t internalId, | |
265 bool isProtected) | |
266 { | |
267 base_.SetProtectedPatient(internalId, isProtected); | |
268 } | |
269 | |
270 virtual void StartTransaction(); | |
271 | |
272 virtual void RollbackTransaction(); | |
273 | |
274 virtual void CommitTransaction(); | |
275 | |
276 virtual uint32_t GetDatabaseVersion(); | |
277 | |
278 virtual void UpgradeDatabase(uint32_t targetVersion, | |
279 OrthancPluginStorageArea* storageArea); | |
280 | |
281 virtual void ClearMainDicomTags(int64_t internalId) | |
282 { | |
283 base_.ClearMainDicomTags(internalId); | |
284 } | |
285 }; |