1671
|
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 bool LookupMetadata(std::string& target /*out*/,
|
|
199 int64_t id,
|
|
200 int32_t metadataType)
|
|
201 {
|
|
202 return base_.LookupMetadata(target, id, static_cast<Orthanc::MetadataType>(metadataType));
|
|
203 }
|
|
204
|
|
205 virtual bool LookupParent(int64_t& parentId /*out*/,
|
|
206 int64_t resourceId);
|
|
207
|
|
208 virtual bool LookupResource(int64_t& id /*out*/,
|
|
209 OrthancPluginResourceType& type /*out*/,
|
|
210 const char* publicId);
|
|
211
|
|
212 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/)
|
|
213 {
|
|
214 return base_.SelectPatientToRecycle(internalId);
|
|
215 }
|
|
216
|
|
217 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/,
|
|
218 int64_t patientIdToAvoid)
|
|
219 {
|
|
220 return base_.SelectPatientToRecycle(internalId, patientIdToAvoid);
|
|
221 }
|
|
222
|
|
223
|
|
224 virtual void SetGlobalProperty(int32_t property,
|
|
225 const char* value)
|
|
226 {
|
|
227 base_.SetGlobalProperty(static_cast<Orthanc::GlobalProperty>(property), value);
|
|
228 }
|
|
229
|
|
230 virtual void SetMainDicomTag(int64_t id,
|
|
231 uint16_t group,
|
|
232 uint16_t element,
|
|
233 const char* value)
|
|
234 {
|
|
235 base_.SetMainDicomTag(id, Orthanc::DicomTag(group, element), value);
|
|
236 }
|
|
237
|
|
238 virtual void SetIdentifierTag(int64_t id,
|
|
239 uint16_t group,
|
|
240 uint16_t element,
|
|
241 const char* value)
|
|
242 {
|
1714
|
243 base_.SetIdentifierTag(id, Orthanc::DicomTag(group, element), value);
|
1671
|
244 }
|
|
245
|
|
246 virtual void SetMetadata(int64_t id,
|
|
247 int32_t metadataType,
|
|
248 const char* value)
|
|
249 {
|
|
250 base_.SetMetadata(id, static_cast<Orthanc::MetadataType>(metadataType), value);
|
|
251 }
|
|
252
|
|
253 virtual void SetProtectedPatient(int64_t internalId,
|
|
254 bool isProtected)
|
|
255 {
|
|
256 base_.SetProtectedPatient(internalId, isProtected);
|
|
257 }
|
|
258
|
|
259 virtual void StartTransaction();
|
|
260
|
|
261 virtual void RollbackTransaction();
|
|
262
|
|
263 virtual void CommitTransaction();
|
|
264
|
|
265 virtual uint32_t GetDatabaseVersion();
|
|
266
|
|
267 virtual void UpgradeDatabase(uint32_t targetVersion,
|
|
268 OrthancPluginStorageArea* storageArea);
|
|
269
|
|
270 virtual void ClearMainDicomTags(int64_t internalId)
|
|
271 {
|
|
272 base_.ClearMainDicomTags(internalId);
|
|
273 }
|
|
274 };
|